cpu_feat.nas 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107
  1. ;
  2. ;
  3. ; assembler routines to detect CPU-features
  4. ;
  5. ; MMX / 3DNow! / SSE / SSE2
  6. ;
  7. ; for the LAME project
  8. ; Frank Klemm, Robert Hegemann 2000-10-12
  9. ;
  10. %include "nasm.h"
  11. globaldef has_MMX_nasm
  12. globaldef has_3DNow_nasm
  13. globaldef has_SSE_nasm
  14. globaldef has_SSE2_nasm
  15. segment_code
  16. testCPUID:
  17. pushfd
  18. pop eax
  19. mov ecx,eax
  20. xor eax,0x200000
  21. push eax
  22. popfd
  23. pushfd
  24. pop eax
  25. cmp eax,ecx
  26. ret
  27. ;---------------------------------------
  28. ; int has_MMX_nasm (void)
  29. ;---------------------------------------
  30. has_MMX_nasm:
  31. pushad
  32. call testCPUID
  33. jz return0 ; no CPUID command, so no MMX
  34. mov eax,0x1
  35. CPUID
  36. test edx,0x800000
  37. jz return0 ; no MMX support
  38. jmp return1 ; MMX support
  39. ;---------------------------------------
  40. ; int has_SSE_nasm (void)
  41. ;---------------------------------------
  42. has_SSE_nasm:
  43. pushad
  44. call testCPUID
  45. jz return0 ; no CPUID command, so no SSE
  46. mov eax,0x1
  47. CPUID
  48. test edx,0x02000000
  49. jz return0 ; no SSE support
  50. jmp return1 ; SSE support
  51. ;---------------------------------------
  52. ; int has_SSE2_nasm (void)
  53. ;---------------------------------------
  54. has_SSE2_nasm:
  55. pushad
  56. call testCPUID
  57. jz return0 ; no CPUID command, so no SSE2
  58. mov eax,0x1
  59. CPUID
  60. test edx,0x04000000
  61. jz return0 ; no SSE2 support
  62. jmp return1 ; SSE2 support
  63. ;---------------------------------------
  64. ; int has_3DNow_nasm (void)
  65. ;---------------------------------------
  66. has_3DNow_nasm:
  67. pushad
  68. call testCPUID
  69. jz return0 ; no CPUID command, so no 3DNow!
  70. mov eax,0x80000000
  71. CPUID
  72. cmp eax,0x80000000
  73. jbe return0 ; no extended MSR(1), so no 3DNow!
  74. mov eax,0x80000001
  75. CPUID
  76. test edx,0x80000000
  77. jz return0 ; no 3DNow! support
  78. ; 3DNow! support
  79. return1:
  80. popad
  81. xor eax,eax
  82. inc eax
  83. ret
  84. return0:
  85. popad
  86. xor eax,eax
  87. ret
  88. end