jsimdcpu.asm 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105
  1. ;
  2. ; jsimdcpu.asm - SIMD instruction support check
  3. ;
  4. ; Copyright 2009 Pierre Ossman <ossman@cendio.se> for Cendio AB
  5. ;
  6. ; Based on the x86 SIMD extension for IJG JPEG library
  7. ; Copyright (C) 1999-2006, MIYASAKA Masaru.
  8. ; For conditions of distribution and use, see copyright notice in jsimdext.inc
  9. ;
  10. ; This file should be assembled with NASM (Netwide Assembler),
  11. ; can *not* be assembled with Microsoft's MASM or any compatible
  12. ; assembler (including Borland's Turbo Assembler).
  13. ; NASM is available from http://nasm.sourceforge.net/ or
  14. ; http://sourceforge.net/project/showfiles.php?group_id=6208
  15. ;
  16. ; [TAB8]
  17. %include "jsimdext.inc"
  18. ; --------------------------------------------------------------------------
  19. SECTION SEG_TEXT
  20. BITS 32
  21. ;
  22. ; Check if the CPU supports SIMD instructions
  23. ;
  24. ; GLOBAL(unsigned int)
  25. ; jpeg_simd_cpu_support (void)
  26. ;
  27. align 16
  28. global EXTN(jpeg_simd_cpu_support)
  29. EXTN(jpeg_simd_cpu_support):
  30. push ebx
  31. ; push ecx ; need not be preserved
  32. ; push edx ; need not be preserved
  33. ; push esi ; unused
  34. push edi
  35. xor edi,edi ; simd support flag
  36. pushfd
  37. pop eax
  38. mov edx,eax
  39. xor eax, 1<<21 ; flip ID bit in EFLAGS
  40. push eax
  41. popfd
  42. pushfd
  43. pop eax
  44. xor eax,edx
  45. jz short .return ; CPUID is not supported
  46. ; Check for MMX instruction support
  47. xor eax,eax
  48. cpuid
  49. test eax,eax
  50. jz short .return
  51. xor eax,eax
  52. inc eax
  53. cpuid
  54. mov eax,edx ; eax = Standard feature flags
  55. test eax, 1<<23 ; bit23:MMX
  56. jz short .no_mmx
  57. or edi, byte JSIMD_MMX
  58. .no_mmx:
  59. test eax, 1<<25 ; bit25:SSE
  60. jz short .no_sse
  61. or edi, byte JSIMD_SSE
  62. .no_sse:
  63. test eax, 1<<26 ; bit26:SSE2
  64. jz short .no_sse2
  65. or edi, byte JSIMD_SSE2
  66. .no_sse2:
  67. ; Check for 3DNow! instruction support
  68. mov eax, 0x80000000
  69. cpuid
  70. cmp eax, 0x80000000
  71. jbe short .return
  72. mov eax, 0x80000001
  73. cpuid
  74. mov eax,edx ; eax = Extended feature flags
  75. test eax, 1<<31 ; bit31:3DNow!(vendor independent)
  76. jz short .no_3dnow
  77. or edi, byte JSIMD_3DNOW
  78. .no_3dnow:
  79. .return:
  80. mov eax,edi
  81. pop edi
  82. ; pop esi ; unused
  83. ; pop edx ; need not be preserved
  84. ; pop ecx ; need not be preserved
  85. pop ebx
  86. ret
  87. ; For some reason, the OS X linker does not honor the request to align the
  88. ; segment unless we do this.
  89. align 16