25'ten fazla konu seçemezsiniz Konular bir harf veya rakamla başlamalı, kısa çizgiler ('-') içerebilir ve en fazla 35 karakter uzunluğunda olabilir.

143 satır
2.6 KiB

  1. {
  2. TextSuite (C) Steffen Xonna (aka Lossy eX)
  3. http://www.opengl24.de/
  4. -----------------------------------------------------------------------
  5. For copyright informations see file copyright.txt.
  6. }
  7. {$I TextSuiteOptions.inc}
  8. unit TextSuiteCPUUtils;
  9. {$ifdef TS_PURE_PASCAL}
  10. {$message fatal 'This unit is''t compatible to the flag TS_PURE_PASCAL.'}
  11. {$endif}
  12. interface
  13. var
  14. supportFPU,
  15. supportCMOV,
  16. supportMMX,
  17. supportMMX_EXT,
  18. supportSSE,
  19. supportSSE2,
  20. support3DNow,
  21. support3DNow_EXT,
  22. supportSSE3,
  23. supportSSSE3
  24. : ByteBool;
  25. procedure ReadCPUFlags;
  26. function GetSSESafeMem(Size: Cardinal): Pointer;
  27. function GetSSESafeAddr(Addr: Pointer): Pointer;
  28. implementation
  29. const
  30. BIT_FPU = 1 shl 0;
  31. BIT_CMOV = 1 shl 15;
  32. BIT_MMX = 1 shl 23;
  33. BIT_SSE = 1 shl 25;
  34. BIT_SSE2 = 1 shl 26;
  35. BIT_3DNOW_EXT = 1 shl 30;
  36. BIT_3DNOW = 1 shl 31;
  37. BIT_SSE3 = 1 shl 0;
  38. BIT_SSSE3 = 1 shl 9;
  39. procedure ReadCPUFlags;
  40. asm
  41. pushfd
  42. pop eax // copy EEFlags to eax
  43. mov edx, eax // copy to edx
  44. xor eax, $00200000 // clear bit 21
  45. push eax
  46. popfd // restore to EEFlags
  47. pushfd
  48. pop eax // copy EEFlags to eax
  49. xor eax, edx // test if flags hav changed
  50. jnz @@supportCPUID
  51. ret
  52. @@supportCPUID:
  53. push ebx // save ebx
  54. mov eax, 1 // function 1
  55. cpuid
  56. // test flags
  57. test edx, BIT_FPU
  58. setnz [supportFPU] // FPU supported
  59. test edx, BIT_CMOV
  60. setnz [supportCMOV] // CMOV supported
  61. test edx, BIT_MMX
  62. setnz [supportMMX] // MMX supported
  63. test edx, BIT_SSE
  64. setnz [supportSSE] // SSE supported
  65. test edx, BIT_SSE2
  66. setnz [supportSSE2] // SSE2 supported
  67. test ecx, BIT_SSE3
  68. setnz [supportSSE3] // SSE3 supported
  69. test ecx, BIT_SSSE3
  70. setnz [supportSSSE3] // SSSE3 supported
  71. // test extended functions
  72. mov eax, $80000000
  73. cpuid
  74. cmp eax, $80000000
  75. jbe @@no_ext_functions
  76. mov eax, $80000001
  77. cpuid
  78. test edx, BIT_3DNOW
  79. setnz [support3DNow] // 3DNow supported
  80. test edx, BIT_3DNOW_EXT
  81. setnz [support3DNow_EXT] // 3DNowExt supported
  82. @@no_ext_functions:
  83. pop ebx // restore ebx
  84. @@end:
  85. end;
  86. function GetSSESafeMem(Size: Cardinal): Pointer;
  87. begin
  88. GetMem(Result, Size + $F);
  89. end;
  90. function GetSSESafeAddr(Addr: Pointer): Pointer;
  91. asm
  92. test eax, $F // test if one of the last bits are set
  93. jz @@end // address is allways 16 Byte aligned
  94. or eax, $F // fill the last 4 bits
  95. inc eax // add 1
  96. @@end:
  97. end;
  98. end.