Zero High Bits From Index

Encoding

EncodingOperand 1Operand 2Operand 3
rmvModRM.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

Exceptions

SIMD Floating-Point

None.

Other Exceptions

VEX Encoded Form: See Type 13 Exception Conditions.