Re: [PATCH 2/6] bitops.h: add sign_extend16 function
Am 2014-12-15 um 17:18 schrieb Martin Kepplinger: > This adds sign_exten16 to sign extend any signed value shorter than 16 bits > to a s16. > > Signed-off-by: Martin Kepplinger > --- if you feel motivated, you can add this to the commit message: Suggested-by: Christoph Muellner -- To unsubscribe from this list: send the line "unsubscribe linux-kernel" in the body of a message to majord...@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html Please read the FAQ at http://www.tux.org/lkml/
[PATCH 2/6] bitops.h: add sign_extend16 function
This adds sign_exten16 to sign extend any signed value shorter than 16 bits to a s16. Signed-off-by: Martin Kepplinger --- include/linux/bitops.h | 11 +++ 1 file changed, 11 insertions(+) diff --git a/include/linux/bitops.h b/include/linux/bitops.h index 3c2a539..70190f4 100644 --- a/include/linux/bitops.h +++ b/include/linux/bitops.h @@ -172,6 +172,17 @@ static inline __s8 sign_extend8(__u8 value, int index) } /** + * sign_extend16 - sign extend a 16-bit value using specified bit as sign-bit + * @value: value to sign extend + * @index: 0 based bit index (0<=index<16) to sign bit + */ +static inline __s16 sign_extend16(__u16 value, int index) +{ + __u8 shift = 15 - index; + return (__s16)(value << shift) >> 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 -- 2.1.3 -- To unsubscribe from this list: send the line "unsubscribe linux-kernel" in the body of a message to majord...@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html Please read the FAQ at http://www.tux.org/lkml/
[PATCH 2/6] bitops.h: add sign_extend16 function
This adds sign_exten16 to sign extend any signed value shorter than 16 bits to a s16. Signed-off-by: Martin Kepplinger mart...@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 3c2a539..70190f4 100644 --- a/include/linux/bitops.h +++ b/include/linux/bitops.h @@ -172,6 +172,17 @@ static inline __s8 sign_extend8(__u8 value, int index) } /** + * sign_extend16 - sign extend a 16-bit value using specified bit as sign-bit + * @value: value to sign extend + * @index: 0 based bit index (0=index16) to sign bit + */ +static inline __s16 sign_extend16(__u16 value, int index) +{ + __u8 shift = 15 - index; + return (__s16)(value shift) 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=index32) to sign bit -- 2.1.3 -- To unsubscribe from this list: send the line unsubscribe linux-kernel in the body of a message to majord...@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html Please read the FAQ at http://www.tux.org/lkml/
Re: [PATCH 2/6] bitops.h: add sign_extend16 function
Am 2014-12-15 um 17:18 schrieb Martin Kepplinger: This adds sign_exten16 to sign extend any signed value shorter than 16 bits to a s16. Signed-off-by: Martin Kepplinger mart...@posteo.de --- if you feel motivated, you can add this to the commit message: Suggested-by: Christoph Muellner christoph.muell...@theobroma-systems.com -- To unsubscribe from this list: send the line unsubscribe linux-kernel in the body of a message to majord...@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html Please read the FAQ at http://www.tux.org/lkml/