00001
00006
00007
00008
00009
00010
00011
00012
00013 #include "host.h"
00014 #include "generic.h"
00015 #include <stdio.h>
00016
00341 #if defined(VL_ARCH_IX86) || defined(VL_ARCH_IA64) || defined(VL_ARCH_X64)
00342 #define HAS_CPUID
00343 #else
00344 #undef HAS_CPUID
00345 #endif
00346
00347 #if defined(HAS_CPUID) & defined(VL_COMPILER_MSC)
00348 #include <intrin.h>
00349 VL_INLINE void
00350 _vl_cpuid (vl_int32* info, int function)
00351 {
00352 __cpuid(info, function) ;
00353 }
00354 #endif
00355
00356 #if defined(HAS_CPUID) & defined(VL_COMPILER_GNUC)
00357 VL_INLINE void
00358 _vl_cpuid (vl_int32* info, int function)
00359 {
00360 #if defined(VL_ARCH_IX86) && (defined(__PIC__) || defined(__pic__))
00361
00362
00363
00364
00365
00366 __asm__ __volatile__
00367 ("pushl %%ebx \n"
00368 "cpuid \n"
00369 "movl %%ebx, %1 \n"
00370 "popl %%ebx \n"
00371 : "=a"(info[0]), "=r"(info[1]), "=c"(info[2]), "=d"(info[3])
00372 : "a"(function)
00373 : "cc") ;
00374 #else
00375 __asm__ __volatile__
00376 ("cpuid"
00377 : "=a"(info[0]), "=b"(info[1]), "=c"(info[2]), "=d"(info[3])
00378 : "a"(function)
00379 : "cc") ;
00380 #endif
00381 }
00382
00383 #endif
00384
00385 void
00386 _vl_x86cpu_info_init (VlX86CpuInfo *self)
00387 {
00388 vl_int32 info [4] ;
00389 int max_func = 0 ;
00390 _vl_cpuid(info, 0) ;
00391 max_func = info[0] ;
00392 self->vendor.words[0] = info[1] ;
00393 self->vendor.words[1] = info[3] ;
00394 self->vendor.words[2] = info[2] ;
00395
00396 if (max_func >= 1) {
00397 _vl_cpuid(info, 1) ;
00398 self->hasMMX = info[3] & (1 << 23) ;
00399 self->hasSSE = info[3] & (1 << 25) ;
00400 self->hasSSE2 = info[3] & (1 << 26) ;
00401 self->hasSSE3 = info[2] & (1 << 0) ;
00402 self->hasSSE41 = info[2] & (1 << 19) ;
00403 self->hasSSE42 = info[2] & (1 << 20) ;
00404 }
00405 }
00406
00407 char *
00408 _vl_x86cpu_info_to_string_copy (VlX86CpuInfo const *self)
00409 {
00410 char * string = 0 ;
00411 int length = 0 ;
00412 while (string == 0) {
00413 if (length > 0) {
00414 string = vl_malloc(sizeof(char) * length) ;
00415 if (string == NULL) break ;
00416 }
00417 length = snprintf(string, length, "%s%s%s%s%s%s%s",
00418 self->vendor.string,
00419 self->hasMMX ? " MMX" : "",
00420 self->hasSSE ? " SSE" : "",
00421 self->hasSSE2 ? " SSE2" : "",
00422 self->hasSSE3 ? " SSE3" : "",
00423 self->hasSSE41 ? " SSE41" : "",
00424 self->hasSSE42 ? " SSE42" : "") ;
00425 length += 1 ;
00426 }
00427 return string ;
00428 }
00429
00439 VL_EXPORT char *
00440 vl_static_configuration_to_string_copy ()
00441 {
00442 char const * hostString =
00443 #ifdef VL_ARCH_X64
00444 "X64"
00445 #endif
00446 #ifdef VL_ARCH_IA64
00447 "IA64"
00448 #endif
00449 #ifdef VL_ARCH_IX86
00450 "IX86"
00451 #endif
00452 #ifdef VL_ARCH_PPC
00453 "PPC"
00454 #endif
00455 ", "
00456 #ifdef VL_ARCH_BIG_ENDIAN
00457 "big_endian"
00458 #endif
00459 #ifdef VL_ARCH_LITTLE_ENDIAN
00460 "little_endian"
00461 #endif
00462 ;
00463
00464 char compilerString [1024] ;
00465
00466 char const * libraryString =
00467 #ifndef VL_DISABLE_THREADS
00468 #ifdef VL_THREADS_WIN
00469 "Windows_threads"
00470 #elif VL_THREADS_POSIX
00471 "POSIX_threads"
00472 #endif
00473 #else
00474 "No_threads"
00475 #endif
00476 #ifndef VL_DISABLE_SSE2
00477 ", SSE2"
00478 #endif
00479 ;
00480
00481 snprintf(compilerString, 1024,
00482 #ifdef VL_COMPILER_MSC
00483 "Microsoft Visual C++ %d"
00484 #define v VL_COMPILER_MSC
00485 #endif
00486 #ifdef VL_COMPILER_GNUC
00487 "GNU C %d"
00488 #define v VL_COMPILER_GNUC
00489 #endif
00490 " "
00491 #ifdef VL_COMPILER_LP64
00492 "LP64"
00493 #endif
00494 #ifdef VL_COMPILER_LLP64
00495 "LP64"
00496 #endif
00497 #ifdef VL_COMPILER_ILP32
00498 "ILP32"
00499 #endif
00500 , v) ;
00501
00502 {
00503 char * string = 0 ;
00504 int length = 0 ;
00505 while (string == 0) {
00506 if (length > 0) {
00507 string = vl_malloc(sizeof(char) * length) ;
00508 if (string == NULL) break ;
00509 }
00510 length = snprintf(string, length, "%s, %s, %s",
00511 hostString,
00512 compilerString,
00513 libraryString) ;
00514 length += 1 ;
00515 }
00516 return string ;
00517 }
00518 }
00519
00520
00521