[PATCH 18/20] MIPS/GAS: Simplify sign-extension tests

Richard Sandiford rdsandiford@googlemail.com
Tue Dec 7 11:16:00 GMT 2010


Patches 14-17 are OK.

"Maciej W. Rozycki" <macro@codesourcery.com> writes:
>  /* Is the given value a sign-extended 32-bit value?  */
>  #define IS_SEXT_32BIT_NUM(x)						\
> -  (((x) &~ (offsetT) 0x7fffffff) == 0					\
> -   || (((x) &~ (offsetT) 0x7fffffff) == ~ (offsetT) 0x7fffffff))
> +  (((((x) & 0xffffffffLL) ^ 0x80000000LL) - 0x80000000LL) == (x))
>  
>  /* Is the given value a sign-extended 16-bit value?  */
>  #define IS_SEXT_16BIT_NUM(x)						\
> -  (((x) &~ (offsetT) 0x7fff) == 0					\
> -   || (((x) &~ (offsetT) 0x7fff) == ~ (offsetT) 0x7fff))
> +  (((((x) & 0xffffLL) ^ 0x8000LL) - 0x8000LL) == (x))
>  
>  /* Is the given value a zero-extended 32-bit value?  Or a negated one?  */
>  #define IS_ZEXT_32BIT_NUM(x)						\
> -  (((x) &~ (offsetT) 0xffffffff) == 0					\
> -   || (((x) &~ (offsetT) 0xffffffff) == ~ (offsetT) 0xffffffff))
> +  (((((x) & 0x1ffffffffLL) ^ 0x100000000LL) - 0x100000000LL) == (x))

Although I realise some ports have transgressed (ia64 for one), we shouldn't
use LL.

Richard



More information about the Binutils mailing list