aboutsummaryrefslogtreecommitdiffstats
path: root/include/linux/kernel.h
diff options
context:
space:
mode:
Diffstat (limited to 'include/linux/kernel.h')
-rw-r--r--include/linux/kernel.h35
1 files changed, 34 insertions, 1 deletions
diff --git a/include/linux/kernel.h b/include/linux/kernel.h
index 941dc0a5a877..d6aac75b51ba 100644
--- a/include/linux/kernel.h
+++ b/include/linux/kernel.h
@@ -85,7 +85,23 @@
85 * arguments just once each. 85 * arguments just once each.
86 */ 86 */
87#define __round_mask(x, y) ((__typeof__(x))((y)-1)) 87#define __round_mask(x, y) ((__typeof__(x))((y)-1))
88/**
89 * round_up - round up to next specified power of 2
90 * @x: the value to round
91 * @y: multiple to round up to (must be a power of 2)
92 *
93 * Rounds @x up to next multiple of @y (which must be a power of 2).
94 * To perform arbitrary rounding up, use roundup() below.
95 */
88#define round_up(x, y) ((((x)-1) | __round_mask(x, y))+1) 96#define round_up(x, y) ((((x)-1) | __round_mask(x, y))+1)
97/**
98 * round_down - round down to next specified power of 2
99 * @x: the value to round
100 * @y: multiple to round down to (must be a power of 2)
101 *
102 * Rounds @x down to next multiple of @y (which must be a power of 2).
103 * To perform arbitrary rounding down, use rounddown() below.
104 */
89#define round_down(x, y) ((x) & ~__round_mask(x, y)) 105#define round_down(x, y) ((x) & ~__round_mask(x, y))
90 106
91/** 107/**
@@ -110,13 +126,30 @@
110# define DIV_ROUND_UP_SECTOR_T(ll,d) DIV_ROUND_UP(ll,d) 126# define DIV_ROUND_UP_SECTOR_T(ll,d) DIV_ROUND_UP(ll,d)
111#endif 127#endif
112 128
113/* The `const' in roundup() prevents gcc-3.3 from calling __divdi3 */ 129/**
130 * roundup - round up to the next specified multiple
131 * @x: the value to up
132 * @y: multiple to round up to
133 *
134 * Rounds @x up to next multiple of @y. If @y will always be a power
135 * of 2, consider using the faster round_up().
136 *
137 * The `const' here prevents gcc-3.3 from calling __divdi3
138 */
114#define roundup(x, y) ( \ 139#define roundup(x, y) ( \
115{ \ 140{ \
116 const typeof(y) __y = y; \ 141 const typeof(y) __y = y; \
117 (((x) + (__y - 1)) / __y) * __y; \ 142 (((x) + (__y - 1)) / __y) * __y; \
118} \ 143} \
119) 144)
145/**
146 * rounddown - round down to next specified multiple
147 * @x: the value to round
148 * @y: multiple to round down to
149 *
150 * Rounds @x down to next multiple of @y. If @y will always be a power
151 * of 2, consider using the faster round_down().
152 */
120#define rounddown(x, y) ( \ 153#define rounddown(x, y) ( \
121{ \ 154{ \
122 typeof(x) __x = (x); \ 155 typeof(x) __x = (x); \