Re: [PATCH] bitops: Provide generic sign_extend function (moving it out from wireless code)

From: Andi Kleen
Date: Fri Aug 27 2010 - 06:28:08 EST


Andreas Herrmann <herrmann.der.user@xxxxxxxxxxxxxx> writes:
>
> +/**
> + * sign_extend - Sign extend a 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_extend(__u32 value, int index)
> +{
> + __u8 shift = 31 - index;
> + return (__s32)(value << shift) >> shift;
> +}

If it only handles 32bit please call it sign_extend32

-Andi

--
ak@xxxxxxxxxxxxxxx -- Speaking for myself only.
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/