diff options
| author | Ingo Molnar <mingo@kernel.org> | 2014-02-09 13:13:45 +0100 |
|---|---|---|
| committer | Ingo Molnar <mingo@kernel.org> | 2014-02-09 13:13:45 +0100 |
| commit | 3c3d7cb1db4af176dab843f22ea092a4ef1eb989 (patch) | |
| tree | 9c1b2951432ed10d0654a8e13cbe57b51260d06b /include/linux/kernel.h | |
| parent | 0e9f2204cfa6d79abe3e525ddf7c4ab5792cc751 (diff) | |
| parent | 494479038d97f1b9f76fc633a360a681acdf035c (diff) | |
Merge branch 'linus' into perf/core
Refresh the branch to a v3.14-rc base before queueing up new devel patches.
Signed-off-by: Ingo Molnar <mingo@kernel.org>
Diffstat (limited to 'include/linux/kernel.h')
| -rw-r--r-- | include/linux/kernel.h | 32 |
1 files changed, 32 insertions, 0 deletions
diff --git a/include/linux/kernel.h b/include/linux/kernel.h index 2aa3d4b000e6..196d1ea86df0 100644 --- a/include/linux/kernel.h +++ b/include/linux/kernel.h @@ -29,6 +29,19 @@ #define ULLONG_MAX (~0ULL) #define SIZE_MAX (~(size_t)0) +#define U8_MAX ((u8)~0U) +#define S8_MAX ((s8)(U8_MAX>>1)) +#define S8_MIN ((s8)(-S8_MAX - 1)) +#define U16_MAX ((u16)~0U) +#define S16_MAX ((s16)(U16_MAX>>1)) +#define S16_MIN ((s16)(-S16_MAX - 1)) +#define U32_MAX ((u32)~0U) +#define S32_MAX ((s32)(U32_MAX>>1)) +#define S32_MIN ((s32)(-S32_MAX - 1)) +#define U64_MAX ((u64)~0ULL) +#define S64_MAX ((s64)(U64_MAX>>1)) +#define S64_MIN ((s64)(-S64_MAX - 1)) + #define STACK_MAGIC 0xdeadbeef #define REPEAT_BYTE(x) ((~0ul / 0xff) * (x)) @@ -193,6 +206,25 @@ extern int _cond_resched(void); (__x < 0) ? -__x : __x; \ }) +/** + * reciprocal_scale - "scale" a value into range [0, ep_ro) + * @val: value + * @ep_ro: right open interval endpoint + * + * Perform a "reciprocal multiplication" in order to "scale" a value into + * range [0, ep_ro), where the upper interval endpoint is right-open. + * This is useful, e.g. for accessing a index of an array containing + * ep_ro elements, for example. Think of it as sort of modulus, only that + * the result isn't that of modulo. ;) Note that if initial input is a + * small value, then result will return 0. + * + * Return: a result based on val in interval [0, ep_ro). + */ +static inline u32 reciprocal_scale(u32 val, u32 ep_ro) +{ + return (u32)(((u64) val * ep_ro) >> 32); +} + #if defined(CONFIG_MMU) && \ (defined(CONFIG_PROVE_LOCKING) || defined(CONFIG_DEBUG_ATOMIC_SLEEP)) void might_fault(void); |
