]> CyberLeo.Net >> Repos - FreeBSD/FreeBSD.git/blob - contrib/llvm/tools/clang/lib/Headers/lwpintrin.h
Merge clang trunk r338150 (just before the 7.0.0 branch point), and
[FreeBSD/FreeBSD.git] / contrib / llvm / tools / clang / lib / Headers / lwpintrin.h
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
24 #ifndef __X86INTRIN_H
25 #error "Never use <lwpintrin.h> directly; include <x86intrin.h> instead."
26 #endif
27
28 #ifndef __LWPINTRIN_H
29 #define __LWPINTRIN_H
30
31 /* Define the default attributes for the functions in this file. */
32 #define __DEFAULT_FN_ATTRS __attribute__((__always_inline__, __nodebug__, __target__("lwp")))
33
34 /// Parses the LWPCB at the specified address and enables
35 ///        profiling if valid.
36 ///
37 /// \headerfile <x86intrin.h>
38 ///
39 /// This intrinsic corresponds to the <c> LLWPCB </c> instruction.
40 ///
41 /// \param __addr
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)
47 {
48   __builtin_ia32_llwpcb(__addr);
49 }
50
51 /// Flushes the LWP state to memory and returns the address of the LWPCB.
52 ///
53 /// \headerfile <x86intrin.h>
54 ///
55 /// This intrinsic corresponds to the <c> SLWPCB </c> instruction.
56 ///
57 /// \return
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
61 __slwpcb (void)
62 {
63   return __builtin_ia32_slwpcb();
64 }
65
66 /// Inserts programmed event record into the LWP event ring buffer
67 ///        and advances the ring buffer pointer.
68 ///
69 /// \headerfile <x86intrin.h>
70 ///
71 /// This intrinsic corresponds to the <c> LWPINS </c> instruction.
72 ///
73 /// \param DATA2
74 ///    A 32-bit value is zero-extended and inserted into the 64-bit Data2 field.
75 /// \param DATA1
76 ///    A 32-bit value is inserted into the 32-bit Data1 field.
77 /// \param FLAGS
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)))
86
87 /// 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.
90 ///
91 /// \headerfile <x86intrin.h>
92 ///
93 /// This intrinsic corresponds to the <c> LWPVAL </c> instruction.
94 ///
95 /// \param DATA2
96 ///    A 32-bit value is zero-extended and inserted into the 64-bit Data2 field.
97 /// \param DATA1
98 ///    A 32-bit value is inserted into the 32-bit Data1 field.
99 /// \param FLAGS
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)))
104
105 #ifdef __x86_64__
106
107 /// Inserts programmed event record into the LWP event ring buffer
108 ///        and advances the ring buffer pointer.
109 ///
110 /// \headerfile <x86intrin.h>
111 ///
112 /// This intrinsic corresponds to the <c> LWPINS </c> instruction.
113 ///
114 /// \param DATA2
115 ///    A 64-bit value is inserted into the 64-bit Data2 field.
116 /// \param DATA1
117 ///    A 32-bit value is inserted into the 32-bit Data1 field.
118 /// \param FLAGS
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)))
127
128 /// 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.
131 ///
132 /// \headerfile <x86intrin.h>
133 ///
134 /// This intrinsic corresponds to the <c> LWPVAL </c> instruction.
135 ///
136 /// \param DATA2
137 ///    A 64-bit value is and inserted into the 64-bit Data2 field.
138 /// \param DATA1
139 ///    A 32-bit value is inserted into the 32-bit Data1 field.
140 /// \param FLAGS
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)))
145
146 #endif
147
148 #undef __DEFAULT_FN_ATTRS
149
150 #endif /* __LWPINTRIN_H */