Instruction
LWPVAL
Counts a programmed value sample event of Lightweight Profiling and records it when its counter runs out; LWP.
An AMD extension: Intel processors do not have this instruction.
- Extensions
- Forms
- 2 (2 XOP)
- Data
- Intel XED v2026.08.23
Forms
Latency and throughput
| Model | r32/64, m32, imm32 | r32/64, r32, imm32 |
|---|---|---|
| Piledriver | 100 / 0.5EX0 EX1 | 100 / 0.5EX0 EX1 |
Operation
What the forms do, in pseudocode that our tests run against results recorded on real processors. How to read.
features = cpuid_leaf(0x80000001, 0)[2]
if not features >> 15 & 1:
fault(UD) # CPUID: no LWP
if not xcr0 >> 62 & 1: # LWP's state not enabled by the
fault(UD) # OS
a = lwp_cbaddr
if a and load(a, 32) >> 1 & 1: # running, with LWPVAL's event on
c = lwp_count[1] - 1
if c >= 0: # counted; src2 is not read
lwp_count[1] = c
else: # below 0: a record of event 1
opts = load(a, 32)
t = ptsc() if opts >> 30 & 1 else 0
r = 1 | (lwp_cfg >> 32 & 0xFF) << 8 # CoreId
r |= (imm & 0xFFFF) << 16 # imm's low 16 bits, src2,
r |= src2 << 32 | this_rip << 64 # the address,
r |= src1 << 128 | t << 192 # src1, the time stamp
size = load(a + 4, 32) & 0xFFFFFFF
size -= size % 32
h = lwp_head
store(load(a + 8, 64) + h, 256, r)
nh = (h + 32) % size
if nh == load(a + 64, 32): # full
missed = load(a + 24, 64)
store(a + 24, 64, missed + 1)
if opts >> 29 & 1: # continuous mode only
lwp_head = nh
else:
lwp_head = nh
e = cpuid_leaf(0x8000001C, 0)
v = load(a + (e[1] >> 24), 32) # EventInterval1, and its
v &= 0x3FFFFFF # low bits random as the LWPCB's
k = load(a + 7, 8) >> 4 # Random (byte 7, bits 7:4) asks
if k:
v = v >> k << k | random(k)
lwp_count[1] = v # counting down again
# no register or flag changes, so that LWPVAL can go anywhere. XED
# lists src1 as written: the APM has LWPVAL only read itRun on AMD Zen 5 (EPYC 9645): 4 cases. Its cases ran where CPUID reported no LWP, and every one raised an exception.
Operands
| Operand | Kind | Action |
|---|---|---|
LWPVAL r32/64, r/m32, imm32 | ||
r32/64 | explicit | write |
r/m32 | explicit | read |
imm32 | explicit | read |
Flags
None: XED records no flag that the forms test or change.
Intrinsics
The C intrinsics of Clang 23.1.2 that compile to LWPVAL, each with the form it compiles to and the Clang options it needs. The forms come from compiling every intrinsic and decoding the result with Intel XED; all intrinsics A–Z explains the method.
| Intrinsic | Compiles to |
|---|---|
__lwpval32
void __lwpval32(unsigned int DATA2, unsigned int DATA1, const unsigned int FLAGS) |
|
__lwpval64
void __lwpval64(unsigned long long DATA2, unsigned int DATA1, const unsigned int FLAGS) |
|
CPUID and processors
Each form belongs to an XED ISA set. A form can be used when the processor reports every CPUID bit of one of its ISA set's alternatives.
| ISA set | CPUID | Processors |
|---|---|---|
LWP | LWP | Bulldozer, Piledriver |
More LWP instructions
Sources
- Intel XED v2026.08.23 (commit
0bcb6237345c): forms, encodings, operands, flags, exception classes, attributes, ISA sets, CPUID bits and chip model. - Clang's x86 intrinsic headers, LLVM 23.1.2 (commit
85ac56026243): the intrinsics, their signatures and doc comments, and the Clang of that release, which compiled each of them. - LLVM 23.1.2's x86 scheduling models (commit
85ac56026243): the latency, reciprocal throughput and ports of each form, as llvm-mca reports them. - AMD64 Architecture Programmer's Manual, Volume 3: General-Purpose and System Instructions (24594, rev. 3.38, July 2026)
- AMD64 Architecture Programmer's Manual, Volume 2: System Programming (24593, rev. 3.45, July 2026)
The tables are derived from Intel XED, Copyright Intel Corporation, licensed under the Apache License 2.0; x86-64.net converted and reformatted them. The intrinsics and their signatures come from Clang and the timings from LLVM's scheduling models, both part of the LLVM Project, licensed under the Apache License 2.0 with LLVM Exceptions. The text is our own.