pike.git / src / pike_cpulib.c

version» Context lines:

pike.git/src/pike_cpulib.c:7:   #include "global.h"   #include "pike_cpulib.h"   #include "svalue.h"      #ifdef HAVE_X86_ASM      #if !defined (CL_X86_ASM_STYLE) && !defined (GCC_X86_ASM_STYLE)   #error Dont know how to inline assembler with this compiler   #endif    + /** Query the x86 CPU for features using the CPUID opcode. +  * +  * @param oper +  * The main category selected, now named CPUID leaf. +  * +  * @param cpuid_ptr +  * Pointer to INT32[4] where the response is written from registers +  * eax, ebx, edx, and ecx, in that order. +  * +  */   PMOD_EXPORT void x86_get_cpuid(int oper, INT32 *cpuid_ptr)   /* eax -> cpuid_ptr[0]    * ebx -> cpuid_ptr[1]    * edx -> cpuid_ptr[2]    * ecx -> cpuid_ptr[3] */   {   #ifdef CL_X86_ASM_STYLE    __asm {    mov eax, oper;    mov edi, cpuid_ptr;
pike.git/src/pike_cpulib.c:52:    "=r"(cpuid_ptr[1]),    "=d"(cpuid_ptr[2]),    "=c"(cpuid_ptr[3])    : "0"(oper)    : "cc");   #endif /* SIZEOF_CHAR_P == 4 */   #endif /* CL_X86_ASM_STYLE */   }      #endif /* HAVE_IA32_ASM */ +  + /* Number of log2 per second: +  +  log(x)/log(2.0) 50,000,000 +  log2(x) 75,000,000 +  Table lookup 3,000,000,000 +  Intrinsic 30,000,000,000,000,000 + */ +  + /** Same thing as (int)floor(log((double)x) / log(2.0)), except a bit +  * quicker. +  */ + PMOD_EXPORT int my_log2(UINT64 x) + { +  if( x == 0 ) return 0; +  if(x & ~((UINT64)0xffffffffUL)) { +  return 32 + log2_u32((unsigned INT32)(x>>32)); +  } +  return log2_u32((unsigned INT32)x); + }