Merge tag 'trace-printf-v6.13' of git://git.kernel.org/pub/scm/linux/kernel/git/trace...
[drm/drm-misc.git] / tools / include / linux / math.h
blob4e7af99ec9eb42c60f32dadf69612cc265c8b4b4
1 #ifndef _TOOLS_MATH_H
2 #define _TOOLS_MATH_H
4 /*
5 * This looks more complex than it should be. But we need to
6 * get the type for the ~ right in round_down (it needs to be
7 * as wide as the result!), and we want to evaluate the macro
8 * arguments just once each.
9 */
10 #define __round_mask(x, y) ((__typeof__(x))((y)-1))
11 #define round_up(x, y) ((((x)-1) | __round_mask(x, y))+1)
12 #define round_down(x, y) ((x) & ~__round_mask(x, y))
14 #define DIV_ROUND_UP(n,d) (((n) + (d) - 1) / (d))
16 #ifndef roundup
17 #define roundup(x, y) ( \
18 { \
19 const typeof(y) __y = y; \
20 (((x) + (__y - 1)) / __y) * __y; \
21 } \
23 #endif
25 #endif