cpu-a.asm 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153
  1. ;*****************************************************************************
  2. ;* cpu-a.asm: x86 cpu utilities
  3. ;*****************************************************************************
  4. ;* Copyright (C) 2003-2018 x264 project
  5. ;*
  6. ;* Authors: Laurent Aimar <fenrir@via.ecp.fr>
  7. ;* Loren Merritt <lorenm@u.washington.edu>
  8. ;* Fiona Glaser <fiona@x264.com>
  9. ;*
  10. ;* This program is free software; you can redistribute it and/or modify
  11. ;* it under the terms of the GNU General Public License as published by
  12. ;* the Free Software Foundation; either version 2 of the License, or
  13. ;* (at your option) any later version.
  14. ;*
  15. ;* This program is distributed in the hope that it will be useful,
  16. ;* but WITHOUT ANY WARRANTY; without even the implied warranty of
  17. ;* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  18. ;* GNU General Public License for more details.
  19. ;*
  20. ;* You should have received a copy of the GNU General Public License
  21. ;* along with this program; if not, write to the Free Software
  22. ;* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02111, USA.
  23. ;*
  24. ;* This program is also available under a commercial proprietary license.
  25. ;* For more information, contact us at licensing@x264.com.
  26. ;*****************************************************************************
  27. %include "x86inc.asm"
  28. SECTION .text
  29. ;-----------------------------------------------------------------------------
  30. ; void cpu_cpuid( int op, int *eax, int *ebx, int *ecx, int *edx )
  31. ;-----------------------------------------------------------------------------
  32. cglobal cpu_cpuid, 5,7
  33. push rbx
  34. push r4
  35. push r3
  36. push r2
  37. push r1
  38. mov eax, r0d
  39. xor ecx, ecx
  40. cpuid
  41. pop r4
  42. mov [r4], eax
  43. pop r4
  44. mov [r4], ebx
  45. pop r4
  46. mov [r4], ecx
  47. pop r4
  48. mov [r4], edx
  49. pop rbx
  50. RET
  51. ;-----------------------------------------------------------------------------
  52. ; uint64_t cpu_xgetbv( int xcr )
  53. ;-----------------------------------------------------------------------------
  54. cglobal cpu_xgetbv
  55. movifnidn ecx, r0m
  56. xgetbv
  57. %if ARCH_X86_64
  58. shl rdx, 32
  59. or rax, rdx
  60. %endif
  61. ret
  62. ;-----------------------------------------------------------------------------
  63. ; void cpu_emms( void )
  64. ;-----------------------------------------------------------------------------
  65. cglobal cpu_emms
  66. emms
  67. ret
  68. ;-----------------------------------------------------------------------------
  69. ; void cpu_sfence( void )
  70. ;-----------------------------------------------------------------------------
  71. cglobal cpu_sfence
  72. sfence
  73. ret
  74. %if ARCH_X86_64
  75. ;-----------------------------------------------------------------------------
  76. ; intptr_t stack_align( void (*func)(void*), ... ); (up to 5 args)
  77. ;-----------------------------------------------------------------------------
  78. cvisible stack_align
  79. mov rax, r0mp
  80. mov r0, r1mp
  81. mov r1, r2mp
  82. mov r2, r3mp
  83. mov r3, r4mp
  84. mov r4, r5mp
  85. push rbp
  86. mov rbp, rsp
  87. %if WIN64
  88. sub rsp, 40 ; shadow space + r4
  89. %endif
  90. and rsp, ~(STACK_ALIGNMENT-1)
  91. %if WIN64
  92. mov [rsp+32], r4
  93. %endif
  94. call rax
  95. leave
  96. ret
  97. %else
  98. ;-----------------------------------------------------------------------------
  99. ; int cpu_cpuid_test( void )
  100. ; return 0 if unsupported
  101. ;-----------------------------------------------------------------------------
  102. cglobal cpu_cpuid_test
  103. pushfd
  104. push ebx
  105. push ebp
  106. push esi
  107. push edi
  108. pushfd
  109. pop eax
  110. mov ebx, eax
  111. xor eax, 0x200000
  112. push eax
  113. popfd
  114. pushfd
  115. pop eax
  116. xor eax, ebx
  117. pop edi
  118. pop esi
  119. pop ebp
  120. pop ebx
  121. popfd
  122. ret
  123. cvisible stack_align
  124. push ebp
  125. mov ebp, esp
  126. sub esp, 20
  127. and esp, ~(STACK_ALIGNMENT-1)
  128. mov r0, [ebp+12]
  129. mov r1, [ebp+16]
  130. mov r2, [ebp+20]
  131. mov [esp+ 0], r0
  132. mov [esp+ 4], r1
  133. mov [esp+ 8], r2
  134. mov r0, [ebp+24]
  135. mov r1, [ebp+28]
  136. mov [esp+12], r0
  137. mov [esp+16], r1
  138. call [ebp+ 8]
  139. leave
  140. ret
  141. %endif