Counter Strike : Global Offensive Source Code
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

80 lines
1.6 KiB

  1. //========= Copyright � 1996-2005, Valve Corporation, All rights reserved. ============//
  2. //
  3. // Purpose: linux dependant ASM code for CPU capability detection
  4. //
  5. // $Workfile: $
  6. // $NoKeywords: $
  7. //=============================================================================//
  8. // NOTE: This has to be the last file included! (turned off below, since this is included like a header)
  9. #include "tier0/memdbgon.h"
  10. // Turn off memdbg macros (turned on up top) since this is included like a header
  11. #include "tier0/memdbgoff.h"
  12. static void cpuid(uint32 function, uint32& out_eax, uint32& out_ebx, uint32& out_ecx, uint32& out_edx)
  13. {
  14. #if defined(PLATFORM_64BITS)
  15. asm("mov %%rbx, %%rsi\n\t"
  16. "cpuid\n\t"
  17. "xchg %%rsi, %%rbx"
  18. : "=a" (out_eax),
  19. "=S" (out_ebx),
  20. "=c" (out_ecx),
  21. "=d" (out_edx)
  22. : "a" (function)
  23. );
  24. #else
  25. asm("mov %%ebx, %%esi\n\t"
  26. "cpuid\n\t"
  27. "xchg %%esi, %%ebx"
  28. : "=a" (out_eax),
  29. "=S" (out_ebx),
  30. "=c" (out_ecx),
  31. "=d" (out_edx)
  32. : "a" (function)
  33. );
  34. #endif
  35. }
  36. bool CheckMMXTechnology(void)
  37. {
  38. uint32 eax,ebx,edx,unused;
  39. cpuid(1,eax,ebx,unused,edx);
  40. return edx & 0x800000;
  41. }
  42. bool CheckSSETechnology(void)
  43. {
  44. uint32 eax,ebx,edx,unused;
  45. cpuid(1,eax,ebx,unused,edx);
  46. return edx & 0x2000000L;
  47. }
  48. bool CheckSSE2Technology(void)
  49. {
  50. uint32 eax,ebx,edx,unused;
  51. cpuid(1,eax,ebx,unused,edx);
  52. return edx & 0x04000000;
  53. }
  54. bool Check3DNowTechnology(void)
  55. {
  56. uint32 eax, unused;
  57. cpuid(0x80000000,eax,unused,unused,unused);
  58. if ( eax > 0x80000000L )
  59. {
  60. cpuid(0x80000001,unused,unused,unused,eax);
  61. return ( eax & 1<<31 );
  62. }
  63. return false;
  64. }