Go to the documentation of this file.00001
00007
00008
00009
00010
00011
00012
00013
00014
00396 #include "host.h"
00397 #include "generic.h"
00398 #include <stdio.h>
00399
00400 #if defined(VL_ARCH_IX86) || defined(VL_ARCH_IA64) || defined(VL_ARCH_X64)
00401 #define HAS_CPUID
00402 #else
00403 #undef HAS_CPUID
00404 #endif
00405
00406 #if defined(HAS_CPUID) & defined(VL_COMPILER_MSC)
00407 #include <intrin.h>
00408 VL_INLINE void
00409 _vl_cpuid (vl_int32* info, int function)
00410 {
00411 __cpuid(info, function) ;
00412 }
00413 #endif
00414
00415 #if defined(HAS_CPUID) & defined(VL_COMPILER_GNUC)
00416 VL_INLINE void
00417 _vl_cpuid (vl_int32* info, int function)
00418 {
00419 #if defined(VL_ARCH_IX86) && (defined(__PIC__) || defined(__pic__))
00420
00421
00422
00423
00424
00425 __asm__ __volatile__
00426 ("pushl %%ebx \n"
00427 "cpuid \n"
00428 "movl %%ebx, %1 \n"
00429 "popl %%ebx \n"
00430 : "=a"(info[0]), "=r"(info[1]), "=c"(info[2]), "=d"(info[3])
00431 : "a"(function)
00432 : "cc") ;
00433 #else
00434 __asm__ __volatile__
00435 ("cpuid"
00436 : "=a"(info[0]), "=b"(info[1]), "=c"(info[2]), "=d"(info[3])
00437 : "a"(function)
00438 : "cc") ;
00439 #endif
00440 }
00441
00442 #endif
00443
00444 void
00445 _vl_x86cpu_info_init (VlX86CpuInfo *self)
00446 {
00447 vl_int32 info [4] ;
00448 int max_func = 0 ;
00449 _vl_cpuid(info, 0) ;
00450 max_func = info[0] ;
00451 self->vendor.words[0] = info[1] ;
00452 self->vendor.words[1] = info[3] ;
00453 self->vendor.words[2] = info[2] ;
00454
00455 if (max_func >= 1) {
00456 _vl_cpuid(info, 1) ;
00457 self->hasMMX = info[3] & (1 << 23) ;
00458 self->hasSSE = info[3] & (1 << 25) ;
00459 self->hasSSE2 = info[3] & (1 << 26) ;
00460 self->hasSSE3 = info[2] & (1 << 0) ;
00461 self->hasSSE41 = info[2] & (1 << 19) ;
00462 self->hasSSE42 = info[2] & (1 << 20) ;
00463 self->hasAVX = info[2] & (1 << 28) ;
00464 }
00465 }
00466
00467 char *
00468 _vl_x86cpu_info_to_string_copy (VlX86CpuInfo const *self)
00469 {
00470 char * string = 0 ;
00471 int length = 0 ;
00472 while (string == 0) {
00473 if (length > 0) {
00474 string = vl_malloc(sizeof(char) * length) ;
00475 if (string == NULL) break ;
00476 }
00477 length = snprintf(string, length, "%s%s%s%s%s%s%s%s",
00478 self->vendor.string,
00479 self->hasMMX ? " MMX" : "",
00480 self->hasSSE ? " SSE" : "",
00481 self->hasSSE2 ? " SSE2" : "",
00482 self->hasSSE3 ? " SSE3" : "",
00483 self->hasSSE41 ? " SSE41" : "",
00484 self->hasSSE42 ? " SSE42" : "",
00485 self->hasAVX ? " AVX" : "") ;
00486 length += 1 ;
00487 }
00488 return string ;
00489 }
00490
00500 VL_EXPORT char *
00501 vl_static_configuration_to_string_copy ()
00502 {
00503 char const * hostString =
00504 #ifdef VL_ARCH_X64
00505 "X64"
00506 #endif
00507 #ifdef VL_ARCH_IA64
00508 "IA64"
00509 #endif
00510 #ifdef VL_ARCH_IX86
00511 "IX86"
00512 #endif
00513 #ifdef VL_ARCH_PPC
00514 "PPC"
00515 #endif
00516 ", "
00517 #ifdef VL_ARCH_BIG_ENDIAN
00518 "big_endian"
00519 #endif
00520 #ifdef VL_ARCH_LITTLE_ENDIAN
00521 "little_endian"
00522 #endif
00523 ;
00524
00525 char compilerString [1024] ;
00526
00527 char const * libraryString =
00528 #ifndef VL_DISABLE_THREADS
00529 #ifdef VL_THREADS_WIN
00530 "Windows_threads"
00531 #elif VL_THREADS_POSIX
00532 "POSIX_threads"
00533 #endif
00534 #else
00535 "No_threads"
00536 #endif
00537 #ifndef VL_DISABLE_SSE2
00538 ", SSE2"
00539 #endif
00540 #if defined(_OPENMP)
00541 ", OpenMP"
00542 #endif
00543 ;
00544
00545 snprintf(compilerString, 1024,
00546 #ifdef VL_COMPILER_MSC
00547 "Microsoft Visual C++ %d"
00548 #define v VL_COMPILER_MSC
00549 #endif
00550 #ifdef VL_COMPILER_GNUC
00551 "GNU C %d"
00552 #define v VL_COMPILER_GNUC
00553 #endif
00554 " "
00555 #ifdef VL_COMPILER_LP64
00556 "LP64"
00557 #endif
00558 #ifdef VL_COMPILER_LLP64
00559 "LP64"
00560 #endif
00561 #ifdef VL_COMPILER_ILP32
00562 "ILP32"
00563 #endif
00564 , v) ;
00565
00566 {
00567 char * string = 0 ;
00568 int length = 0 ;
00569 while (string == 0) {
00570 if (length > 0) {
00571 string = vl_malloc(sizeof(char) * length) ;
00572 if (string == NULL) break ;
00573 }
00574 length = snprintf(string, length, "%s, %s, %s",
00575 hostString,
00576 compilerString,
00577 libraryString) ;
00578 length += 1 ;
00579 }
00580 return string ;
00581 }
00582 }