diff options
author | Nick Foster <nick@ettus.com> | 2012-04-16 17:18:36 -0700 |
---|---|---|
committer | Josh Blum <josh@joshknows.com> | 2012-04-19 18:13:22 -0700 |
commit | 0595b7f2283e0aa1cdebefdac2d3a2702324727d (patch) | |
tree | 739fb6d1e5801a7583f84eff0c2f2fb8ad08f7a8 /volk/tmpl | |
parent | 63809a2c71ea1d50aca6165a73b13fee0eae1d84 (diff) |
Volk: redo the archs.xml language to make checks generic. no more "type", no more piles of #if crap in the template.
Diffstat (limited to 'volk/tmpl')
-rw-r--r-- | volk/tmpl/volk_cpu.tmpl.c | 96 |
1 files changed, 27 insertions, 69 deletions
diff --git a/volk/tmpl/volk_cpu.tmpl.c b/volk/tmpl/volk_cpu.tmpl.c index 1bd1ad2118..b050d8aea5 100644 --- a/volk/tmpl/volk_cpu.tmpl.c +++ b/volk/tmpl/volk_cpu.tmpl.c @@ -64,40 +64,39 @@ struct VOLK_CPU volk_cpu; #else #error "A get cpuid for volk is not available on this compiler..." -#endif +#endif //defined(__GNUC__) -static inline unsigned int cpuid_eax(unsigned int op) { - int regs[4]; - cpuid_x86 (op, regs); - return regs[0]; -} +#endif //defined(VOLK_CPU_x86) -static inline unsigned int cpuid_ebx(unsigned int op) { - int regs[4]; - cpuid_x86 (op, regs); - return regs[1]; -} - -static inline unsigned int cpuid_ecx(unsigned int op) { - int regs[4]; - cpuid_x86 (op, regs); - return regs[2]; +static inline unsigned int cpuid_x86_bit(unsigned int reg, unsigned int op, unsigned int bit) { +#if defined(VOLK_CPU_x86) + unsigned int regs[4]; + cpuid_x86(op, regs); + return regs[reg] >> bit & 0x01; +#else + return 0; +#endif } -static inline unsigned int cpuid_edx(unsigned int op) { - int regs[4]; - cpuid_x86 (op, regs); - return regs[3]; +static inline unsigned int check_extended_cpuid(unsigned int val) { +#if defined(VOLK_CPU_x86) + unsigned int regs[4]; + cpuid_x86(0x80000000, regs); + return regs[0] >= val; +#else + return 0; +#endif } -static inline unsigned int xgetbv(void) { +static inline unsigned int get_avx_enabled(void) { +#if defined(VOLK_CPU_x86) //check to make sure that xgetbv is enabled in OS - int xgetbv_enabled = cpuid_ecx(1) >> 27 & 0x01; - if (xgetbv_enabled == 0) return 0; + if(!cpuid_x86_bit(2, 1, 27)) return 0; return __xgetbv() & 0x6; -} - +#else + return 0; #endif +} //neon detection is linux specific #if defined(__arm__) && defined(__linux__) @@ -140,51 +139,10 @@ static int has_ppc(void){ #for $arch in $archs static int i_can_has_$arch.name (void) { -######################################################################## - #if $arch.type == "x86" and $arch.no_test -#if defined(VOLK_CPU_x86) - return 1; -#else - return 0; -#endif -######################################################################## - #else if $arch.op == 1 -#if defined(VOLK_CPU_x86) - #set $op = hex($arch.op) - unsigned int e$(arch.reg)x = cpuid_e$(arch.reg)x ($op); - unsigned int hwcap = ((e$(arch.reg)x >> $arch.shift) & 1) == $arch.val; - #if $arch.check - if ($(arch.check)() == 0) return 0; - #end if - return hwcap; -#else - return 0; -#endif -######################################################################## - #else if $arch.op == 0x80000001 -#if defined(VOLK_CPU_x86) - #set $op = hex($arch.op) - unsigned int extended_fct_count = cpuid_eax(0x80000000); - if (extended_fct_count < 0x80000001) - return $(arch.val)^1; - unsigned int extended_features = cpuid_e$(arch.reg)x ($op); - return ((extended_features >> $arch.shift) & 1) == $arch.val; -#else - return 0; -#endif -######################################################################## - #else if $arch.type == "powerpc" - return has_ppc(); -######################################################################## - #else if $arch.type == "arm" - return has_neon(); -######################################################################## - #else if $arch.type == "all" + #for $check, $params in $arch.checks + if ($(check)($(', '.join($params))) == 0) return 0; + #end for return 1; -######################################################################## - #else ##$ - return 0; - #end if } #end for |