1 /*===---- lwpintrin.h - LWP intrinsics -------------------------------------===
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:
10 * The above copyright notice and this permission notice shall be included in
11 * all copies or substantial portions of the Software.
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
21 *===-----------------------------------------------------------------------===
25 #error "Never use <lwpintrin.h> directly; include <x86intrin.h> instead."
31 /* Define the default attributes for the functions in this file. */
32 #define __DEFAULT_FN_ATTRS __attribute__((__always_inline__, __nodebug__, __target__("lwp")))
34 /// \brief Parses the LWPCB at the specified address and enables
35 /// profiling if valid.
37 /// \headerfile <x86intrin.h>
39 /// This intrinsic corresponds to the <c> LLWPCB </c> instruction.
42 /// Address to the new Lightweight Profiling Control Block (LWPCB). If the
43 /// LWPCB is valid, writes the address into the LWP_CBADDR MSR and enables
44 /// Lightweight Profiling.
45 static __inline__ void __DEFAULT_FN_ATTRS
46 __llwpcb (void *__addr)
48 __builtin_ia32_llwpcb(__addr);
51 /// \brief Flushes the LWP state to memory and returns the address of the LWPCB.
53 /// \headerfile <x86intrin.h>
55 /// This intrinsic corresponds to the <c> SLWPCB </c> instruction.
58 /// Address to the current Lightweight Profiling Control Block (LWPCB).
59 /// If LWP is not currently enabled, returns NULL.
60 static __inline__ void* __DEFAULT_FN_ATTRS
63 return __builtin_ia32_slwpcb();
66 /// \brief Inserts programmed event record into the LWP event ring buffer
67 /// and advances the ring buffer pointer.
69 /// \headerfile <x86intrin.h>
71 /// This intrinsic corresponds to the <c> LWPINS </c> instruction.
74 /// A 32-bit value is zero-extended and inserted into the 64-bit Data2 field.
76 /// A 32-bit value is inserted into the 32-bit Data1 field.
78 /// A 32-bit immediate value is inserted into the 32-bit Flags field.
79 /// \returns If the ring buffer is full and LWP is running in Synchronized Mode,
80 /// the event record overwrites the last record in the buffer, the MissedEvents
81 /// counter in the LWPCB is incremented, the head pointer is not advanced, and
82 /// 1 is returned. Otherwise 0 is returned.
83 #define __lwpins32(DATA2, DATA1, FLAGS) \
84 (__builtin_ia32_lwpins32((unsigned int) (DATA2), (unsigned int) (DATA1), \
85 (unsigned int) (FLAGS)))
87 /// \brief Decrements the LWP programmed value sample event counter. If the result is
88 /// negative, inserts an event record into the LWP event ring buffer in memory
89 /// and advances the ring buffer pointer.
91 /// \headerfile <x86intrin.h>
93 /// This intrinsic corresponds to the <c> LWPVAL </c> instruction.
96 /// A 32-bit value is zero-extended and inserted into the 64-bit Data2 field.
98 /// A 32-bit value is inserted into the 32-bit Data1 field.
100 /// A 32-bit immediate value is inserted into the 32-bit Flags field.
101 #define __lwpval32(DATA2, DATA1, FLAGS) \
102 (__builtin_ia32_lwpval32((unsigned int) (DATA2), (unsigned int) (DATA1), \
103 (unsigned int) (FLAGS)))
107 /// \brief Inserts programmed event record into the LWP event ring buffer
108 /// and advances the ring buffer pointer.
110 /// \headerfile <x86intrin.h>
112 /// This intrinsic corresponds to the <c> LWPINS </c> instruction.
115 /// A 64-bit value is inserted into the 64-bit Data2 field.
117 /// A 32-bit value is inserted into the 32-bit Data1 field.
119 /// A 32-bit immediate value is inserted into the 32-bit Flags field.
120 /// \returns If the ring buffer is full and LWP is running in Synchronized Mode,
121 /// the event record overwrites the last record in the buffer, the MissedEvents
122 /// counter in the LWPCB is incremented, the head pointer is not advanced, and
123 /// 1 is returned. Otherwise 0 is returned.
124 #define __lwpins64(DATA2, DATA1, FLAGS) \
125 (__builtin_ia32_lwpins64((unsigned long long) (DATA2), (unsigned int) (DATA1), \
126 (unsigned int) (FLAGS)))
128 /// \brief Decrements the LWP programmed value sample event counter. If the result is
129 /// negative, inserts an event record into the LWP event ring buffer in memory
130 /// and advances the ring buffer pointer.
132 /// \headerfile <x86intrin.h>
134 /// This intrinsic corresponds to the <c> LWPVAL </c> instruction.
137 /// A 64-bit value is and inserted into the 64-bit Data2 field.
139 /// A 32-bit value is inserted into the 32-bit Data1 field.
141 /// A 32-bit immediate value is inserted into the 32-bit Flags field.
142 #define __lwpval64(DATA2, DATA1, FLAGS) \
143 (__builtin_ia32_lwpval64((unsigned long long) (DATA2), (unsigned int) (DATA1), \
144 (unsigned int) (FLAGS)))
148 #undef __DEFAULT_FN_ATTRS
150 #endif /* __LWPINTRIN_H */