[Mesa-dev] [PATCH] mesa: Fix test for big-endian architecture in compiler.h

Roland Scheidegger sroland at vmware.com
Sat Feb 13 00:39:12 UTC 2016


Am 12.02.2016 um 10:01 schrieb Jochen Rollwagen:
> Hi,
> 
> i think i found & fixed a bug in mesa concerning tests for big-endian
> machines. The defines tested don't exist or are wrongly defined so the
> test (probably) never fires. The gcc defines on my machine concerning
> big-endian are
> 
> jochen at mac-mini:~/sources/mesa$ gcc -dM -E - < /dev/null | grep BIG
> #define __BIGGEST_ALIGNMENT__ 16
> #define __BIG_ENDIAN__ 1
> #define __FLOAT_WORD_ORDER__ __ORDER_BIG_ENDIAN__
> #define _BIG_ENDIAN 1
> #define __ORDER_BIG_ENDIAN__ 4321
> #define __BYTE_ORDER__ __ORDER_BIG_ENDIAN__
> 
> The tested values in current mesa are quite different :-)
> 
> The following patch fixes this.
> 
> diff --git a/src/mesa/main/compiler.h b/src/mesa/main/compiler.h
> index c5ee741..99c63cb 100644
> --- a/src/mesa/main/compiler.h
> +++ b/src/mesa/main/compiler.h
> @@ -52,7 +52,7 @@ extern "C" {
>   * Try to use a runtime test instead.
>   * For now, only used by some DRI hardware drivers for color/texel
> packing.
>   */
> -#if defined(BYTE_ORDER) && defined(BIG_ENDIAN) && BYTE_ORDER == BIG_ENDIAN
> +#if defined(__BYTE_ORDER__) && defined(__BIG_ENDIAN__) &&
> __BYTE_ORDER__ == __ORDER_BIG_ENDIAN__
>  #if defined(__linux__)
>  #include <byteswap.h>
>  #define CPU_TO_LE32( x )       bswap_32( x )
> 

Note that on some platforms this file would include endian.h - which
defines those BYTE_ORDER etc. values. Albeit it includes this _after_
these ifdefs...
But don't ask me how this is really supposed to work...

Roland




More information about the mesa-dev mailing list