ia32intrin.h 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101
  1. /* ===-------- ia32intrin.h ---------------------------------------------------===
  2. *
  3. * Permission is hereby granted, free of charge, to any person obtaining a copy
  4. * of this software and associated documentation files (the "Software"), to deal
  5. * in the Software without restriction, including without limitation the rights
  6. * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
  7. * copies of the Software, and to permit persons to whom the Software is
  8. * furnished to do so, subject to the following conditions:
  9. *
  10. * The above copyright notice and this permission notice shall be included in
  11. * all copies or substantial portions of the Software.
  12. *
  13. * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  14. * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  15. * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  16. * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  17. * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
  18. * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
  19. * THE SOFTWARE.
  20. *
  21. *===-----------------------------------------------------------------------===
  22. */
  23. #ifndef __X86INTRIN_H
  24. #error "Never use <ia32intrin.h> directly; include <x86intrin.h> instead."
  25. #endif
  26. #ifndef __IA32INTRIN_H
  27. #define __IA32INTRIN_H
  28. #ifdef __x86_64__
  29. static __inline__ unsigned long long __attribute__((__always_inline__, __nodebug__))
  30. __readeflags(void)
  31. {
  32. unsigned long long __res = 0;
  33. __asm__ __volatile__ ("pushf\n\t"
  34. "popq %0\n"
  35. :"=r"(__res)
  36. :
  37. :
  38. );
  39. return __res;
  40. }
  41. static __inline__ void __attribute__((__always_inline__, __nodebug__))
  42. __writeeflags(unsigned long long __f)
  43. {
  44. __asm__ __volatile__ ("pushq %0\n\t"
  45. "popf\n"
  46. :
  47. :"r"(__f)
  48. :"flags"
  49. );
  50. }
  51. #else /* !__x86_64__ */
  52. static __inline__ unsigned int __attribute__((__always_inline__, __nodebug__))
  53. __readeflags(void)
  54. {
  55. unsigned int __res = 0;
  56. __asm__ __volatile__ ("pushf\n\t"
  57. "popl %0\n"
  58. :"=r"(__res)
  59. :
  60. :
  61. );
  62. return __res;
  63. }
  64. static __inline__ void __attribute__((__always_inline__, __nodebug__))
  65. __writeeflags(unsigned int __f)
  66. {
  67. __asm__ __volatile__ ("pushl %0\n\t"
  68. "popf\n"
  69. :
  70. :"r"(__f)
  71. :"flags"
  72. );
  73. }
  74. #endif /* !__x86_64__ */
  75. static __inline__ unsigned long long __attribute__((__always_inline__, __nodebug__))
  76. __rdpmc(int __A) {
  77. return __builtin_ia32_rdpmc(__A);
  78. }
  79. /* __rdtsc */
  80. static __inline__ unsigned long long __attribute__((__always_inline__, __nodebug__))
  81. __rdtsc(void) {
  82. return __builtin_ia32_rdtsc();
  83. }
  84. /* __rdtscp */
  85. static __inline__ unsigned long long __attribute__((__always_inline__, __nodebug__))
  86. __rdtscp(unsigned int *__A) {
  87. return __builtin_ia32_rdtscp(__A);
  88. }
  89. #define _rdtsc() __rdtsc()
  90. #endif /* __IA32INTRIN_H */