VLFeat.org

API docs

  • Home
    • Download and Install
    • API docs
    • Matlab docs
    • About VLFeat
  • Tutorials
    • SIFT
    • MSER
    • IKM
    • HIKM
    • AIB
    • Utils
  • Main Page
  • Related Pages
  • Data Structures
  • Files
  • Examples

host.c

Go to the documentation of this file.
00001 
00006 /* AUTORIGHTS
00007  Copyright 2007 (c) Andrea Vedaldi and Brian Fulkerson
00008  
00009  This file is part of VLFeat, available in the terms of the GNU
00010  General Public License version 2.
00011  */
00012 
00013 #include "host.h"
00014 #include "generic.h"
00015 
00319 #if defined(VL_ARCH_IX86) || defined(VL_ARCH_IA64)
00320 #define HAS_CPUID
00321 #endif
00322 
00323 #if defined(HAS_CPUID) & defined(VL_COMPILER_MSC)
00324 #include <intrin.h>
00325 VL_INLINE
00326 void _vl_cpuid (vl_int32* info, int function) 
00327 {
00328   __cpuid(info, function) ;
00329 }
00330 #endif
00331 
00332 #if defined(HAS_CPUID) & defined(VL_COMPILER_GNUC)
00333 VL_INLINE
00334 void _vl_cpuid (vl_int32* info, int function)
00335 {
00336   /* this version is compatible with -fPIC */
00337   __asm__ __volatile__ 
00338   ("pushl %%ebx      \n\t" /* save %ebx */
00339    "cpuid            \n\t"
00340    "movl %%ebx, %1   \n\t" /* save what cpuid just put in %ebx */
00341    "popl %%ebx       \n\t" /* restore the old %ebx */
00342    : "=a"(info[0]), "=r"(info[1]), "=c"(info[2]), "=d"(info[3])
00343    : "a"(function)
00344    : "cc") ;
00345 }
00346 #endif
00347 
00348 #ifdef HAS_CPUID
00349 struct x86cpu_
00350 {
00351   char vendor_string [0x20] ;
00352   vl_bool has_sse42 ;
00353   vl_bool has_sse41 ;
00354   vl_bool has_sse3 ;
00355   vl_bool has_sse2 ;
00356   vl_bool has_sse ;
00357   vl_bool has_mmx ;
00358 } x86cpu ;
00359 
00360 vl_bool x86cpu_initialized = 0 ;
00361 
00362 void _vl_x86cpu_init () 
00363 {
00364   vl_int32 info [4] ;
00365   int max_func = 0 ;
00366   _vl_cpuid(info, 0) ;
00367   max_func = info[0] ;
00368   *((vl_int32*)x86cpu.vendor_string+0) = info[1] ;
00369   *((vl_int32*)x86cpu.vendor_string+1) = info[3] ;
00370   *((vl_int32*)x86cpu.vendor_string+2) = info[2] ;
00371 
00372   if (max_func >= 1) {
00373     _vl_cpuid(info, 1) ;
00374     x86cpu.has_mmx   = info[3] & (1 << 23) ;
00375     x86cpu.has_sse   = info[3] & (1 << 25) ;
00376     x86cpu.has_sse2  = info[3] & (1 << 26) ;
00377     x86cpu.has_sse3  = info[2] & (1 <<  0) ;
00378     x86cpu.has_sse41 = info[2] & (1 << 19) ;
00379     x86cpu.has_sse42 = info[2] & (1 << 20) ;
00380   }
00381 }
00382 
00383 VL_INLINE
00384 struct x86cpu_ const* _vl_x86cpu_get() 
00385 {
00386   if (!x86cpu_initialized) _vl_x86cpu_init() ;
00387   return &x86cpu ;
00388 }
00389 #endif
00390  
00393 vl_bool simd_enabled = 1 ;
00394 
00403 void vl_set_simd_enabled (vl_bool x)
00404 {
00405   simd_enabled = x ;
00406 }
00407 
00411 vl_bool vl_get_simd_enabled ()
00412 {
00413   return simd_enabled ;
00414 }
00415 
00419 vl_bool vl_cpu_has_sse3 ()
00420 {
00421 #ifdef HAS_CPUID
00422   return _vl_x86cpu_get()->has_sse3 ;
00423 #else
00424   return 0 ;
00425 #endif
00426 }
00427 
00431 vl_bool vl_cpu_has_sse2 ()
00432 {
00433 #ifdef HAS_CPUID
00434   return _vl_x86cpu_get()->has_sse2 ;
00435 #else
00436   return 0 ;
00437 #endif
00438 }
00439 
00444 void vl_print_host_info ()
00445 {
00446   char const *arch = 0, *endian = 0, *comp = 0, *dm = 0 ;
00447   int compver ;
00448 #ifdef VL_ARCH_IA6
00449   arch = "IA64" ;
00450 #endif
00451 #ifdef VL_ARCH_IX86
00452   arch = "IX86" ;
00453 #endif
00454 #ifdef VL_ARCH_PPC
00455   arch = "PPC" ;
00456 #endif
00457   
00458 #ifdef VL_ARCH_BIN_ENDIAN
00459   endian = "big endian" ;
00460 #endif
00461 #ifdef VL_ARCH_LITTLE_ENDIAN
00462   endian = "little endian" ;
00463 #endif
00464   
00465 #ifdef VL_COMPILER_MSC
00466   comp = "Microsoft Visual C++" ;
00467   compver = VL_COMPILER_MSC ;
00468 #endif
00469 #ifdef VL_COMPILER_GNUC
00470   comp = "GNU C" ;
00471   compver = VL_COMPILER_GNUC ;
00472 #endif
00473 
00474 #ifdef VL_COMPILER_LP64
00475   dm = "LP64" ;
00476 #endif
00477 #ifdef VL_COMPILER_LLP64
00478   dm = "LP64" ;
00479 #endif
00480 #ifdef VL_COMPILER_ILP32
00481   dm = "ILP32" ;
00482 #endif
00483   
00484 #define YESNO(x) ((x)?"yes":"no")
00485 
00486   VL_PRINTF("Host: Compiler: %s %d\n", comp, compver) ;
00487   VL_PRINTF("      Compiler data model: %s\n", dm) ;
00488   VL_PRINTF("      CPU architecture: %s\n", arch) ;
00489   VL_PRINTF("      CPU endianness: %s\n", endian) ;
00490   
00491 #ifdef HAS_CPUID
00492   {
00493     struct x86cpu_ const* c = _vl_x86cpu_get() ;
00494     VL_PRINTF("      CPU vendor string: %s\n", c->vendor_string) ;
00495     VL_PRINTF("      CPU has MMX: %s\n",    YESNO(c->has_mmx)) ;
00496     VL_PRINTF("      CPU has SSE: %s\n",    YESNO(c->has_sse)) ;
00497     VL_PRINTF("      CPU has SSE2: %s\n",   YESNO(c->has_sse2)) ;
00498     VL_PRINTF("      CPU has SSE3: %s\n",   YESNO(c->has_sse3)) ;
00499     VL_PRINTF("      CPU has SSE4.1: %s\n", YESNO(c->has_sse41)) ;
00500     VL_PRINTF("      CPU has SSE4.2: %s\n", YESNO(c->has_sse42)) ;
00501     VL_PRINTF("VLFeat uses SIMD: %s\n", YESNO(vl_get_simd_enabled())) ;
00502   }        
00503 #endif
00504 }
00505 
00506 
00507 
Copyright © 2008 Andrea Vedaldi and Brian Fulkerson