1 /* Determine CPU support for SIMD on Power PC
2 * Copyright 2004 Phil Karn, KA9Q
3 */
4 #include <stdio.h>
5 #include "fec.h"
6 #ifdef __VEC__
7 #include <sys/sysctl.h>
8 #endif
9
10 /* Various SIMD instruction set names */
11 char *Cpu_modes[] = {"Unknown","Portable C","x86 Multi Media Extensions (MMX)",
12 "x86 Streaming SIMD Extensions (SSE)",
13 "x86 Streaming SIMD Extensions 2 (SSE2)",
14 "PowerPC G4/G5 Altivec/Velocity Engine"};
15
16 enum cpu_mode Cpu_mode;
17
find_cpu_mode(void)18 void find_cpu_mode(void){
19
20 if(Cpu_mode != UNKNOWN)
21 return;
22
23 #ifdef __VEC__
24 {
25 /* Ask the OS if we have Altivec support */
26 int selectors[2] = { CTL_HW, HW_VECTORUNIT };
27 int hasVectorUnit = 0;
28 size_t length = sizeof(hasVectorUnit);
29 int error = sysctl(selectors, 2, &hasVectorUnit, &length, NULL, 0);
30 if(0 == error && hasVectorUnit)
31 Cpu_mode = ALTIVEC;
32 else
33 Cpu_mode = PORT;
34 }
35 #else
36 Cpu_mode = PORT;
37 #endif
38
39 fprintf(stderr,"SIMD CPU detect: %s\n",Cpu_modes[Cpu_mode]);
40 }
41