Opcode | Encoding | 16-bit | 32-bit | 64-bit | CPUID Feature Flag(s) | Description |
---|---|---|---|---|---|---|
VEX.L0.NP.0F38.W0 F5 /r BZHI r32a, r/m32, r32b | rmv | Invalid | Valid | Valid | bmi2 | Zero bits in r/m32 beginning at the bit index specified in r32b. Store the result in r32a. |
VEX.L0.NP.0F38.W1 F5 /r BZHI r64a, r/m64, r64b | rmv | Invalid | Invalid | Valid | bmi2 | Zero bits in r/m64 beginning at the bit index specified in r64b. Store the result in r64a. |
Encoding
Encoding | Operand 1 | Operand 2 | Operand 3 |
---|---|---|---|
rmv | ModRM.reg[w] | ModRM.r/m[r] | VEX.vvvv[r] |
Description
The BZHI
instruction zeros (clears) bits from the first source operand beginning at the bit position provided in the second source operand. The result is stored in the destination operand.
From the second source operand, only the lowest eight bits are used in the operation. If those eight bits contain a value greater than the operand size, the destination operand will be set to 0
and EFLAGS.CF
set.
The operand size is always 32 bits if not in Long Mode. In other words, VEX.W1
is treated as VEX.W0
outside Long Mode.
Operation
public void BZHI(ref U32 dest, U32 src, U32 idx)
{
U32 n = idx & 0xFF;
if (n < 32)
dest.Bit[n..31] = 0;
else
dest = 0.
}
public void BZHI(ref U64 dest, U64 src, U64 idx)
{
U64 n = idx & 0xFF;
if (n < 64)
dest.Bit[n..63] = 0;
else
dest = 0.
}
Flags Affected
CF
(carry flag)- Set if the beginning index is out of range. Cleared otherwise.
PF
(parity flag)- Undefined.
AF
(auxiliary flag)- Undefined.
ZF
(zero flag)- Set according to the result.
SF
(sign flag)- Set according to the result.
OF
(overflow flag)- Cleared.
Intrinsics
uint32_t _bzhi_u32(uint32_t src, uint32_t index)
uint64_t _bzhi_u64(uint64_t src, uint64_t index)
Exceptions
SIMD Floating-Point
None.Other Exceptions
VEX Encoded Form: See Type 13 Exception Conditions.