Bit Extract Field

Encoding

EncodingOperand 1Operand 2Operand 3
rmvModRM.reg[w]ModRM.r/m[r]VEX.vvvv[r]
rmiModRM.reg[w]ModRM.r/m[r]imm32

Description

The BEXTR instruction extracts contiguous bits from the first source operand using using index and length values provided in the second source operand. The result is stored in the destination operand.

The control register contains 16 bits: the lower eight are the starting index into the slice, and the upper eight is the amount of bits to extract. In other words, the destination register will be filled least significant to most significant by copying from the source, beginning at the starting position (where 0 indicates the least significant bit). The length field determines how many bits are extracted. Bits 16.. of the control operand are ignored.

The operand size is always 32 bits if not in Long Mode. In other words, VEX.W1 and XOP.W1 are treated as VEX.W0 and XOP.W0 (respectively) outside Long Mode.

Operation

public void BEXTR(ref U32 dest, U32 src1, U32 src2)
{
    // both VEX and XOP forms
    U8 start = src2[0..7];
    U8 end = start + src2[8..15];
    dest = src1[start..end];
}

public void BEXTR(ref U64 dest, U64 src1, U32 src2)
{
    // XOP form
    BEXTR(ref dest, src1, (U64)src2);
}

public void BEXTR(ref U64 dest, U64 src1, U64 src2)
{
    // VEX form
    U8 start = src2[0..7];
    U8 end = start + src2[8..15];
    dest = src1[start..end]
}

Flags Affected

CF (carry flag)
Cleared.
PF (parity flag)
Undefined.
AF (auxiliary flag)
Undefined.
ZF (zero flag)
Set according to the result.
SF (sign flag)
Undefined.
OF (overflow flag)
Cleared.

Intrinsics

Exceptions

SIMD Floating-Point

None.

Other Exceptions

VEX Encoded Form: See Type 13 Exception Conditions.