/media/libjpeg/simd/jsimdcpu.asm

http://github.com/zpao/v8monkey · Assembly · 105 lines · 56 code · 15 blank · 34 comment · 0 complexity · 81b82ffcfcc55fecba9c4d5dfa85b42a MD5 · raw file

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