diff options
author | Diane Bruce <db@FreeBSD.org> | 2016-04-25 19:45:33 +0000 |
---|---|---|
committer | Diane Bruce <db@FreeBSD.org> | 2016-04-25 19:45:33 +0000 |
commit | de90917e70005e420543e712e5dae4469b436967 (patch) | |
tree | 2419f35b533fde81eecd9ab34de7f6738b711719 /comms/libfec/files/cpu_mode.c | |
parent | 258bf30db61a416beeb76c5d8396dbedfa8956bd (diff) | |
download | ports-de90917e70005e420543e712e5dae4469b436967.tar.gz ports-de90917e70005e420543e712e5dae4469b436967.zip |
Notes
Diffstat (limited to 'comms/libfec/files/cpu_mode.c')
-rw-r--r-- | comms/libfec/files/cpu_mode.c | 50 |
1 files changed, 50 insertions, 0 deletions
diff --git a/comms/libfec/files/cpu_mode.c b/comms/libfec/files/cpu_mode.c new file mode 100644 index 000000000000..089c416c2e9c --- /dev/null +++ b/comms/libfec/files/cpu_mode.c @@ -0,0 +1,50 @@ +/* Determine CPU support for SIMD + * Copyright 2004 Phil Karn, KA9Q + */ +#include <stdio.h> +#include "fec.h" +#ifdef __VEC__ +#include <sys/sysctl.h> +#endif + +/* Various SIMD instruction set names */ +char *Cpu_modes[] = {"Unknown","Portable C","x86 Multi Media Extensions (MMX)", + "x86 Streaming SIMD Extensions (SSE)", + "x86 Streaming SIMD Extensions 2 (SSE2)", + "PowerPC G4/G5 Altivec/Velocity Engine"}; + +enum cpu_mode Cpu_mode; + +void find_cpu_mode(void){ + + int f; + if(Cpu_mode != UNKNOWN) + return; + else + Cpu_mode = PORT; +#ifdef __i386__ + /* Figure out what kind of CPU we have */ + f = cpu_features(); + if(f & (1<<26)){ /* SSE2 is present */ + Cpu_mode = SSE2; + } else if(f & (1<<25)){ /* SSE is present */ + Cpu_mode = SSE; + } else if(f & (1<<23)){ /* MMX is present */ + Cpu_mode = MMX; + } +#endif +//#ifdef __VEC__ +#if 0 +// This looks very Linux specific + { + /* Ask the OS if we have Altivec support */ + int selectors[2] = { CTL_HW, HW_VECTORUNIT }; + int hasVectorUnit = 0; + size_t length = sizeof(hasVectorUnit); + int error = sysctl(selectors, 2, &hasVectorUnit, &length, NULL, 0); + if(0 == error && hasVectorUnit) + Cpu_mode = ALTIVEC; + } +#endif + fprintf(stderr,"SIMD CPU detect: %s\n",Cpu_modes[Cpu_mode]); +} |