lwpintrin.h 5.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150
  1. /*===---- lwpintrin.h - LWP intrinsics -------------------------------------===
  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 <lwpintrin.h> directly; include <x86intrin.h> instead."
  25. #endif
  26. #ifndef __LWPINTRIN_H
  27. #define __LWPINTRIN_H
  28. /* Define the default attributes for the functions in this file. */
  29. #define __DEFAULT_FN_ATTRS __attribute__((__always_inline__, __nodebug__, __target__("lwp")))
  30. /// \brief Parses the LWPCB at the specified address and enables
  31. /// profiling if valid.
  32. ///
  33. /// \headerfile <x86intrin.h>
  34. ///
  35. /// This intrinsic corresponds to the <c> LLWPCB </c> instruction.
  36. ///
  37. /// \param __addr
  38. /// Address to the new Lightweight Profiling Control Block (LWPCB). If the
  39. /// LWPCB is valid, writes the address into the LWP_CBADDR MSR and enables
  40. /// Lightweight Profiling.
  41. static __inline__ void __DEFAULT_FN_ATTRS
  42. __llwpcb (void *__addr)
  43. {
  44. __builtin_ia32_llwpcb(__addr);
  45. }
  46. /// \brief Flushes the LWP state to memory and returns the address of the LWPCB.
  47. ///
  48. /// \headerfile <x86intrin.h>
  49. ///
  50. /// This intrinsic corresponds to the <c> SLWPCB </c> instruction.
  51. ///
  52. /// \return
  53. /// Address to the current Lightweight Profiling Control Block (LWPCB).
  54. /// If LWP is not currently enabled, returns NULL.
  55. static __inline__ void* __DEFAULT_FN_ATTRS
  56. __slwpcb ()
  57. {
  58. return __builtin_ia32_slwpcb();
  59. }
  60. /// \brief Inserts programmed event record into the LWP event ring buffer
  61. /// and advances the ring buffer pointer.
  62. ///
  63. /// \headerfile <x86intrin.h>
  64. ///
  65. /// This intrinsic corresponds to the <c> LWPINS </c> instruction.
  66. ///
  67. /// \param DATA2
  68. /// A 32-bit value is zero-extended and inserted into the 64-bit Data2 field.
  69. /// \param DATA1
  70. /// A 32-bit value is inserted into the 32-bit Data1 field.
  71. /// \param FLAGS
  72. /// A 32-bit immediate value is inserted into the 32-bit Flags field.
  73. /// \returns If the ring buffer is full and LWP is running in Synchronized Mode,
  74. /// the event record overwrites the last record in the buffer, the MissedEvents
  75. /// counter in the LWPCB is incremented, the head pointer is not advanced, and
  76. /// 1 is returned. Otherwise 0 is returned.
  77. #define __lwpins32(DATA2, DATA1, FLAGS) \
  78. (__builtin_ia32_lwpins32((unsigned int) (DATA2), (unsigned int) (DATA1), \
  79. (unsigned int) (FLAGS)))
  80. /// \brief Decrements the LWP programmed value sample event counter. If the result is
  81. /// negative, inserts an event record into the LWP event ring buffer in memory
  82. /// and advances the ring buffer pointer.
  83. ///
  84. /// \headerfile <x86intrin.h>
  85. ///
  86. /// This intrinsic corresponds to the <c> LWPVAL </c> instruction.
  87. ///
  88. /// \param DATA2
  89. /// A 32-bit value is zero-extended and inserted into the 64-bit Data2 field.
  90. /// \param DATA1
  91. /// A 32-bit value is inserted into the 32-bit Data1 field.
  92. /// \param FLAGS
  93. /// A 32-bit immediate value is inserted into the 32-bit Flags field.
  94. #define __lwpval32(DATA2, DATA1, FLAGS) \
  95. (__builtin_ia32_lwpval32((unsigned int) (DATA2), (unsigned int) (DATA1), \
  96. (unsigned int) (FLAGS)))
  97. #ifdef __x86_64__
  98. /// \brief Inserts programmed event record into the LWP event ring buffer
  99. /// and advances the ring buffer pointer.
  100. ///
  101. /// \headerfile <x86intrin.h>
  102. ///
  103. /// This intrinsic corresponds to the <c> LWPINS </c> instruction.
  104. ///
  105. /// \param DATA2
  106. /// A 64-bit value is inserted into the 64-bit Data2 field.
  107. /// \param DATA1
  108. /// A 32-bit value is inserted into the 32-bit Data1 field.
  109. /// \param FLAGS
  110. /// A 32-bit immediate value is inserted into the 32-bit Flags field.
  111. /// \returns If the ring buffer is full and LWP is running in Synchronized Mode,
  112. /// the event record overwrites the last record in the buffer, the MissedEvents
  113. /// counter in the LWPCB is incremented, the head pointer is not advanced, and
  114. /// 1 is returned. Otherwise 0 is returned.
  115. #define __lwpins64(DATA2, DATA1, FLAGS) \
  116. (__builtin_ia32_lwpins64((unsigned long long) (DATA2), (unsigned int) (DATA1), \
  117. (unsigned int) (FLAGS)))
  118. /// \brief Decrements the LWP programmed value sample event counter. If the result is
  119. /// negative, inserts an event record into the LWP event ring buffer in memory
  120. /// and advances the ring buffer pointer.
  121. ///
  122. /// \headerfile <x86intrin.h>
  123. ///
  124. /// This intrinsic corresponds to the <c> LWPVAL </c> instruction.
  125. ///
  126. /// \param DATA2
  127. /// A 64-bit value is and inserted into the 64-bit Data2 field.
  128. /// \param DATA1
  129. /// A 32-bit value is inserted into the 32-bit Data1 field.
  130. /// \param FLAGS
  131. /// A 32-bit immediate value is inserted into the 32-bit Flags field.
  132. #define __lwpval64(DATA2, DATA1, FLAGS) \
  133. (__builtin_ia32_lwpval64((unsigned long long) (DATA2), (unsigned int) (DATA1), \
  134. (unsigned int) (FLAGS)))
  135. #endif
  136. #undef __DEFAULT_FN_ATTRS
  137. #endif /* __LWPINTRIN_H */