lkml.org 
[lkml]   [2015]   [Jan]   [20]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
 
Messages in this thread
Patch in this message
/
From
Subject[PATCH 2/2] bitops.h: Add sign_extend64() API
Date
Add sign_extend64() for sign extending any (hardware-)given signed value
greater than 32 bits to s64.

Suggested-by: Christoph Muellner <christoph.muellner@theobroma-systems.com>
Suggested-by: Peter Zijlstra <peterz@infradead.org>
Signed-off-by: Martin Kepplinger <martink@posteo.de>
---
include/linux/bitops.h | 11 +++++++++++
1 file changed, 11 insertions(+)

diff --git a/include/linux/bitops.h b/include/linux/bitops.h
index 336f22b..2fd47c8 100644
--- a/include/linux/bitops.h
+++ b/include/linux/bitops.h
@@ -173,6 +173,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)
--
2.1.4


\
 
 \ /
  Last update: 2015-01-20 13:41    [W:2.582 / U:0.004 seconds]
©2003-2020 Jasper Spaans|hosted at Digital Ocean and TransIP|Read the blog|Advertise on this site