lwpintrin.h revision 341825
1317951Sdim/*===---- lwpintrin.h - LWP intrinsics -------------------------------------===
2317951Sdim *
3317951Sdim * Permission is hereby granted, free of charge, to any person obtaining a copy
4317951Sdim * of this software and associated documentation files (the "Software"), to deal
5317951Sdim * in the Software without restriction, including without limitation the rights
6317951Sdim * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
7317951Sdim * copies of the Software, and to permit persons to whom the Software is
8317951Sdim * furnished to do so, subject to the following conditions:
9317951Sdim *
10317951Sdim * The above copyright notice and this permission notice shall be included in
11317951Sdim * all copies or substantial portions of the Software.
12317951Sdim *
13317951Sdim * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
14317951Sdim * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
15317951Sdim * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
16317951Sdim * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
17317951Sdim * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
18317951Sdim * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
19317951Sdim * THE SOFTWARE.
20317951Sdim *
21317951Sdim *===-----------------------------------------------------------------------===
22317951Sdim */
23317951Sdim
24317951Sdim#ifndef __X86INTRIN_H
25317951Sdim#error "Never use <lwpintrin.h> directly; include <x86intrin.h> instead."
26317951Sdim#endif
27317951Sdim
28317951Sdim#ifndef __LWPINTRIN_H
29317951Sdim#define __LWPINTRIN_H
30317951Sdim
31317951Sdim/* Define the default attributes for the functions in this file. */
32317951Sdim#define __DEFAULT_FN_ATTRS __attribute__((__always_inline__, __nodebug__, __target__("lwp")))
33317951Sdim
34341825Sdim/// Parses the LWPCB at the specified address and enables
35317951Sdim///        profiling if valid.
36317951Sdim///
37317951Sdim/// \headerfile <x86intrin.h>
38317951Sdim///
39317951Sdim/// This intrinsic corresponds to the <c> LLWPCB </c> instruction.
40317951Sdim///
41317951Sdim/// \param __addr
42317951Sdim///    Address to the new Lightweight Profiling Control Block (LWPCB). If the
43317951Sdim///    LWPCB is valid, writes the address into the LWP_CBADDR MSR and enables
44317951Sdim///    Lightweight Profiling.
45317951Sdimstatic __inline__ void __DEFAULT_FN_ATTRS
46317951Sdim__llwpcb (void *__addr)
47317951Sdim{
48317951Sdim  __builtin_ia32_llwpcb(__addr);
49317951Sdim}
50317951Sdim
51341825Sdim/// Flushes the LWP state to memory and returns the address of the LWPCB.
52317951Sdim///
53317951Sdim/// \headerfile <x86intrin.h>
54317951Sdim///
55317951Sdim/// This intrinsic corresponds to the <c> SLWPCB </c> instruction.
56317951Sdim///
57317951Sdim/// \return
58317951Sdim///    Address to the current Lightweight Profiling Control Block (LWPCB).
59317951Sdim///    If LWP is not currently enabled, returns NULL.
60317951Sdimstatic __inline__ void* __DEFAULT_FN_ATTRS
61341825Sdim__slwpcb (void)
62317951Sdim{
63317951Sdim  return __builtin_ia32_slwpcb();
64317951Sdim}
65317951Sdim
66341825Sdim/// Inserts programmed event record into the LWP event ring buffer
67317951Sdim///        and advances the ring buffer pointer.
68317951Sdim///
69317951Sdim/// \headerfile <x86intrin.h>
70317951Sdim///
71317951Sdim/// This intrinsic corresponds to the <c> LWPINS </c> instruction.
72317951Sdim///
73317951Sdim/// \param DATA2
74317951Sdim///    A 32-bit value is zero-extended and inserted into the 64-bit Data2 field.
75317951Sdim/// \param DATA1
76317951Sdim///    A 32-bit value is inserted into the 32-bit Data1 field.
77317951Sdim/// \param FLAGS
78317951Sdim///    A 32-bit immediate value is inserted into the 32-bit Flags field.
79317951Sdim/// \returns If the ring buffer is full and LWP is running in Synchronized Mode,
80317951Sdim///    the event record overwrites the last record in the buffer, the MissedEvents
81317951Sdim///    counter in the LWPCB is incremented, the head pointer is not advanced, and
82317951Sdim///    1 is returned. Otherwise 0 is returned.
83317951Sdim#define __lwpins32(DATA2, DATA1, FLAGS) \
84317951Sdim  (__builtin_ia32_lwpins32((unsigned int) (DATA2), (unsigned int) (DATA1), \
85317951Sdim                           (unsigned int) (FLAGS)))
86317951Sdim
87341825Sdim/// Decrements the LWP programmed value sample event counter. If the result is
88317951Sdim///        negative, inserts an event record into the LWP event ring buffer in memory
89317951Sdim///        and advances the ring buffer pointer.
90317951Sdim///
91317951Sdim/// \headerfile <x86intrin.h>
92317951Sdim///
93317951Sdim/// This intrinsic corresponds to the <c> LWPVAL </c> instruction.
94317951Sdim///
95317951Sdim/// \param DATA2
96317951Sdim///    A 32-bit value is zero-extended and inserted into the 64-bit Data2 field.
97317951Sdim/// \param DATA1
98317951Sdim///    A 32-bit value is inserted into the 32-bit Data1 field.
99317951Sdim/// \param FLAGS
100317951Sdim///    A 32-bit immediate value is inserted into the 32-bit Flags field.
101317951Sdim#define __lwpval32(DATA2, DATA1, FLAGS) \
102317951Sdim  (__builtin_ia32_lwpval32((unsigned int) (DATA2), (unsigned int) (DATA1), \
103317951Sdim                           (unsigned int) (FLAGS)))
104317951Sdim
105317951Sdim#ifdef __x86_64__
106317951Sdim
107341825Sdim/// Inserts programmed event record into the LWP event ring buffer
108317951Sdim///        and advances the ring buffer pointer.
109317951Sdim///
110317951Sdim/// \headerfile <x86intrin.h>
111317951Sdim///
112317951Sdim/// This intrinsic corresponds to the <c> LWPINS </c> instruction.
113317951Sdim///
114317951Sdim/// \param DATA2
115317951Sdim///    A 64-bit value is inserted into the 64-bit Data2 field.
116317951Sdim/// \param DATA1
117317951Sdim///    A 32-bit value is inserted into the 32-bit Data1 field.
118317951Sdim/// \param FLAGS
119317951Sdim///    A 32-bit immediate value is inserted into the 32-bit Flags field.
120317951Sdim/// \returns If the ring buffer is full and LWP is running in Synchronized Mode,
121317951Sdim///    the event record overwrites the last record in the buffer, the MissedEvents
122317951Sdim///    counter in the LWPCB is incremented, the head pointer is not advanced, and
123317951Sdim///    1 is returned. Otherwise 0 is returned.
124317951Sdim#define __lwpins64(DATA2, DATA1, FLAGS) \
125317951Sdim  (__builtin_ia32_lwpins64((unsigned long long) (DATA2), (unsigned int) (DATA1), \
126317951Sdim                           (unsigned int) (FLAGS)))
127317951Sdim
128341825Sdim/// Decrements the LWP programmed value sample event counter. If the result is
129317951Sdim///        negative, inserts an event record into the LWP event ring buffer in memory
130317951Sdim///        and advances the ring buffer pointer.
131317951Sdim///
132317951Sdim/// \headerfile <x86intrin.h>
133317951Sdim///
134317951Sdim/// This intrinsic corresponds to the <c> LWPVAL </c> instruction.
135317951Sdim///
136317951Sdim/// \param DATA2
137317951Sdim///    A 64-bit value is and inserted into the 64-bit Data2 field.
138317951Sdim/// \param DATA1
139317951Sdim///    A 32-bit value is inserted into the 32-bit Data1 field.
140317951Sdim/// \param FLAGS
141317951Sdim///    A 32-bit immediate value is inserted into the 32-bit Flags field.
142317951Sdim#define __lwpval64(DATA2, DATA1, FLAGS) \
143317951Sdim  (__builtin_ia32_lwpval64((unsigned long long) (DATA2), (unsigned int) (DATA1), \
144317951Sdim                           (unsigned int) (FLAGS)))
145317951Sdim
146317951Sdim#endif
147317951Sdim
148317951Sdim#undef __DEFAULT_FN_ATTRS
149317951Sdim
150317951Sdim#endif /* __LWPINTRIN_H */
151