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