cpu_mode_ppc.c

来自「FEC Optimized viterbi code」· C语言 代码 · 共 41 行

C
41
字号
/* Determine CPU support for SIMD on Power PC * 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){  if(Cpu_mode != UNKNOWN)    return;#ifdef __VEC__  {  /* 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;  else    Cpu_mode = PORT;  }#else  Cpu_mode = PORT;#endif  fprintf(stderr,"SIMD CPU detect: %s\n",Cpu_modes[Cpu_mode]);}

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?