From: Luis R. Rodriguez Date: Thu, 11 Nov 2010 00:28:48 +0000 (-0800) Subject: compat: backport sign_extend32() X-Git-Tag: v2.6.38-rc1-1~23 X-Git-Url: https://openfabrics.org/gitweb/?a=commitdiff_plain;h=ea54195721209a5cfc6ab4806e7fa1d61dc002ef;p=~emulex%2Ftmp%2Fcompat%2F.git compat: backport sign_extend32() commit 5faec21f3a6973219481394534ce0e5f17507d84 Author: Andreas Herrmann Date: Mon Aug 30 19:04:01 2010 +0000 bitops: Provide generic sign_extend32 function This patch moves code out from wireless drivers where two different functions are defined in three code locations for the same purpose and provides a common function to sign extend a 32-bit value. Signed-off-by: Andreas Herrmann Signed-off-by: John W. Linville Signed-off-by: Luis R. Rodriguez --- diff --git a/include/linux/bitops.h b/include/linux/bitops.h index 679369b..aa76af1 100644 --- a/include/linux/bitops.h +++ b/include/linux/bitops.h @@ -111,6 +111,17 @@ static inline __u8 ror8(__u8 word, unsigned int shift) return (word >> shift) | (word << (8 - shift)); } +/** + * sign_extend32 - sign extend a 32-bit value using specified bit as sign-bit + * @value: value to sign extend + * @index: 0 based bit index (0<=index<32) to sign bit + */ +static inline __s32 sign_extend32(__u32 value, int index) +{ + __u8 shift = 31 - index; + return (__s32)(value << shift) >> shift; +} + static inline unsigned fls_long(unsigned long l) { if (sizeof(l) == 4)