[Mesa-dev] [PATCH 1/3] u_cpu_detect: make arch and little_endian constants, add abi and x86-64

José Fonseca jfonseca at vmware.com
Fri Aug 13 13:41:00 PDT 2010


On Fri, 2010-08-13 at 06:47 -0700, Luca Barbieri wrote:
> A few related changes:
> 1. Make x86-64 its own architecture (nothing was using so
>    util_cpu_caps.arch, so nothing can be affected)

Just remove util_cpu_caps.arch. It's there simply due to its historical
ancestry. We have PIPE_ARCH already.

> 2. Turn the CPU arch and endianness into macros, so that the compiler
>    can evaluate that at constant time and eliminate dead code

Ditto. We have PIPE_ENDIAN or something already.

> 3. Add util_cpu_abi to know about non-standard ABIs like Win64

That's not really prescribed by the CPU. We have PIPE_OS_* already. 

There's no merit in duplicating in util_caps what's already provided by
p_config.h / p_compiler.h 

Jose

> ---
>  src/gallium/auxiliary/gallivm/lp_bld_pack.c       |    2 +-
>  src/gallium/auxiliary/gallivm/lp_bld_sample_soa.c |    2 +-
>  src/gallium/auxiliary/util/u_cpu_detect.c         |   19 +---------
>  src/gallium/auxiliary/util/u_cpu_detect.h         |   39 ++++++++++++++++++--
>  4 files changed, 38 insertions(+), 24 deletions(-)
> 
> diff --git a/src/gallium/auxiliary/gallivm/lp_bld_pack.c b/src/gallium/auxiliary/gallivm/lp_bld_pack.c
> index ecfb13a..8ab742a 100644
> --- a/src/gallium/auxiliary/gallivm/lp_bld_pack.c
> +++ b/src/gallium/auxiliary/gallivm/lp_bld_pack.c
> @@ -171,7 +171,7 @@ lp_build_unpack2(LLVMBuilderRef builder,
>        msb = lp_build_zero(src_type);
>  
>     /* Interleave bits */
> -   if(util_cpu_caps.little_endian) {
> +   if(util_cpu_little_endian) {
>        *dst_lo = lp_build_interleave2(builder, src_type, src, msb, 0);
>        *dst_hi = lp_build_interleave2(builder, src_type, src, msb, 1);
>     }
> diff --git a/src/gallium/auxiliary/gallivm/lp_bld_sample_soa.c b/src/gallium/auxiliary/gallivm/lp_bld_sample_soa.c
> index 3075065..d4b8b4f 100644
> --- a/src/gallium/auxiliary/gallivm/lp_bld_sample_soa.c
> +++ b/src/gallium/auxiliary/gallivm/lp_bld_sample_soa.c
> @@ -1840,7 +1840,7 @@ lp_build_sample_2d_linear_aos(struct lp_build_sample_context *bld,
>        unsigned i, j;
>  
>        for(j = 0; j < h16.type.length; j += 4) {
> -         unsigned subindex = util_cpu_caps.little_endian ? 0 : 1;
> +         unsigned subindex = util_cpu_little_endian ? 0 : 1;
>           LLVMValueRef index;
>  
>           index = LLVMConstInt(elem_type, j/2 + subindex, 0);
> diff --git a/src/gallium/auxiliary/util/u_cpu_detect.c b/src/gallium/auxiliary/util/u_cpu_detect.c
> index b1a8c75..73ce146 100644
> --- a/src/gallium/auxiliary/util/u_cpu_detect.c
> +++ b/src/gallium/auxiliary/util/u_cpu_detect.c
> @@ -391,23 +391,6 @@ util_cpu_detect(void)
>  
>     memset(&util_cpu_caps, 0, sizeof util_cpu_caps);
>  
> -   /* Check for arch type */
> -#if defined(PIPE_ARCH_MIPS)
> -   util_cpu_caps.arch = UTIL_CPU_ARCH_MIPS;
> -#elif defined(PIPE_ARCH_ALPHA)
> -   util_cpu_caps.arch = UTIL_CPU_ARCH_ALPHA;
> -#elif defined(PIPE_ARCH_SPARC)
> -   util_cpu_caps.arch = UTIL_CPU_ARCH_SPARC;
> -#elif defined(PIPE_ARCH_X86) || defined(PIPE_ARCH_X86_64)
> -   util_cpu_caps.arch = UTIL_CPU_ARCH_X86;
> -   util_cpu_caps.little_endian = 1;
> -#elif defined(PIPE_ARCH_PPC)
> -   util_cpu_caps.arch = UTIL_CPU_ARCH_POWERPC;
> -   util_cpu_caps.little_endian = 0;
> -#else
> -   util_cpu_caps.arch = UTIL_CPU_ARCH_UNKNOWN;
> -#endif
> -
>     /* Count the number of CPUs in system */
>  #if defined(PIPE_OS_WINDOWS)
>     {
> @@ -504,7 +487,7 @@ util_cpu_detect(void)
>  
>  #ifdef DEBUG
>     if (debug_get_option_dump_cpu()) {
> -      debug_printf("util_cpu_caps.arch = %i\n", util_cpu_caps.arch);
> +      debug_printf("util_cpu_caps.arch = %i\n", util_cpu_arch);
>        debug_printf("util_cpu_caps.nr_cpus = %u\n", util_cpu_caps.nr_cpus);
>  
>        debug_printf("util_cpu_caps.x86_cpu_type = %u\n", util_cpu_caps.x86_cpu_type);
> diff --git a/src/gallium/auxiliary/util/u_cpu_detect.h b/src/gallium/auxiliary/util/u_cpu_detect.h
> index 4b3dc39..e81e4b5 100644
> --- a/src/gallium/auxiliary/util/u_cpu_detect.h
> +++ b/src/gallium/auxiliary/util/u_cpu_detect.h
> @@ -36,6 +36,7 @@
>  #define _UTIL_CPU_DETECT_H
>  
>  #include "pipe/p_compiler.h"
> +#include "pipe/p_config.h"
>  
>  enum util_cpu_arch {
>     UTIL_CPU_ARCH_UNKNOWN = 0,
> @@ -43,19 +44,49 @@ enum util_cpu_arch {
>     UTIL_CPU_ARCH_ALPHA,
>     UTIL_CPU_ARCH_SPARC,
>     UTIL_CPU_ARCH_X86,
> -   UTIL_CPU_ARCH_POWERPC
> +   UTIL_CPU_ARCH_X86_64,
> +   UTIL_CPU_ARCH_POWERPC,
> +
> +   /* non-standard ABIs, only used in util_cpu_abi */
> +   UTIL_CPU_ABI_WIN64
>  };
>  
> +/* Check for arch type */
> +#if defined(PIPE_ARCH_MIPS)
> +#define util_cpu_arch UTIL_CPU_ARCH_MIPS
> +#elif defined(PIPE_ARCH_ALPHA)
> +#define util_cpu_arch UTIL_CPU_ARCH_ALPHA
> +#elif defined(PIPE_ARCH_SPARC)
> +#define util_cpu_arch UTIL_CPU_ARCH_SPARC
> +#elif defined(PIPE_ARCH_X86)
> +#define util_cpu_arch UTIL_CPU_ARCH_X86
> +#elif defined(PIPE_ARCH_X86_64)
> +#define util_cpu_arch UTIL_CPU_ARCH_X86_64
> +#elif defined(PIPE_ARCH_PPC)
> +#define util_cpu_arch UTIL_CPU_ARCH_POWERPC
> +#else
> +#define util_cpu_arch UTIL_CPU_ARCH_UNKNOWN
> +#endif
> +
> +#ifdef WIN64
> +#define util_cpu_abi UTIL_CPU_ABI_WIN64
> +#else
> +#define util_cpu_abi util_cpu_arch
> +#endif
> +
> +#if defined(PIPE_ARCH_X86) || defined(PIPE_ARCH_X86_64) || !defined(WORDS_BIGENDIAN)
> +#define util_cpu_little_endian 1
> +#else
> +#define util_cpu_little_endian 0
> +#endif
> +
>  struct util_cpu_caps {
> -   enum util_cpu_arch arch;
>     unsigned nr_cpus;
>  
>     /* Feature flags */
>     int x86_cpu_type;
>     unsigned cacheline;
>  
> -   unsigned little_endian:1;
> -
>     unsigned has_tsc:1;
>     unsigned has_mmx:1;
>     unsigned has_mmx2:1;




More information about the mesa-dev mailing list