[Mesa-dev] [PATCH 1/3] u_cpu_detect: make arch and little_endian constants, add abi and x86-64
Brian Paul
brianp at vmware.com
Fri Aug 13 06:56:57 PDT 2010
On 08/13/2010 07:47 AM, 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)
> 2. Turn the CPU arch and endianness into macros, so that the compiler
> can evaluate that at constant time and eliminate dead code
> 3. Add util_cpu_abi to know about non-standard ABIs like Win64
> ---
> 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
#define symbols are usually uppercase. Is there a reason why you're
using lowercase? I'd prefer the code to follow typical conventions.
-Brian
More information about the mesa-dev
mailing list