diff options
author | Martin Kepplinger <martink@posteo.de> | 2015-11-06 16:31:02 -0800 |
---|---|---|
committer | Sasha Levin <alexander.levin@microsoft.com> | 2018-01-17 12:55:42 -0500 |
commit | feedfe2129e348e075b72a5e3e1c7c52d0c769e4 (patch) | |
tree | c9bcdaf8958fc87b1233fdbea7f702bc1a3bc0a0 | |
parent | ba00cc7686f6df5ca08a2a40d5c80ef744368d23 (diff) |
bitops.h: add sign_extend64()
[ Upstream commit 48e203e21b29cd4b2c58403fe8bca68e2e854895 ]
Months back, this was discussed, see https://lkml.org/lkml/2015/1/18/289
The result was the 64-bit version being "likely fine", "valuable" and
"correct". The discussion fell asleep but since there are possible users,
let's add it.
Signed-off-by: Martin Kepplinger <martin.kepplinger@theobroma-systems.com>
Cc: Peter Zijlstra <a.p.zijlstra@chello.nl>
Cc: Ingo Molnar <mingo@redhat.com>
Cc: Arnaldo Carvalho de Melo <acme@kernel.org>
Cc: Thomas Gleixner <tglx@linutronix.de>
Cc: "H. Peter Anvin" <hpa@zytor.com>
Cc: George Spelvin <linux@horizon.com>
Cc: Rasmus Villemoes <linux@rasmusvillemoes.dk>
Cc: Maxime Coquelin <maxime.coquelin@st.com>
Cc: Denys Vlasenko <dvlasenk@redhat.com>
Cc: Yury Norov <yury.norov@gmail.com>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
Signed-off-by: Sasha Levin <alexander.levin@microsoft.com>
-rw-r--r-- | include/linux/bitops.h | 11 |
1 files changed, 11 insertions, 0 deletions
diff --git a/include/linux/bitops.h b/include/linux/bitops.h index 297f5bda4fdf..858020682ac8 100644 --- a/include/linux/bitops.h +++ b/include/linux/bitops.h @@ -171,6 +171,17 @@ static inline __s32 sign_extend32(__u32 value, int index) return (__s32)(value << shift) >> shift; } +/** + * sign_extend64 - sign extend a 64-bit value using specified bit as sign-bit + * @value: value to sign extend + * @index: 0 based bit index (0<=index<64) to sign bit + */ +static inline __s64 sign_extend64(__u64 value, int index) +{ + __u8 shift = 63 - index; + return (__s64)(value << shift) >> shift; +} + static inline unsigned fls_long(unsigned long l) { if (sizeof(l) == 4) |