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