bpermd

Bit Permute Doubleword

bpermd RA, RS, RB

Permutes bits from RS based on the index values in RB. Highly optimized for bit shuffling.

Details

The bpermd instruction performs a bit permutation on the contents of two registers (RS and RB) and places the result in another register (RA). Each byte of RS specifies an index into RB, and the corresponding bits from RB are placed into RA. If the index exceeds 63, the permuted bit is set to 0.

Pseudocode Operation

do i = 0 to 7
    index ← (RS)8×i:8×i+7
    if index < 64 then
        permi ← (RB)index
    else
        permi ← 0
RA ← perm0:7 || 560

Programming Note

The fact that the permuted bit is 0 if the corresponding index value exceeds 63 permits the permuted bits to be selected from a 128-bit quantity, using a single index register.

Example

bpermd r3, r4, r5

Encoding

Binary Layout
31
0
RS
6
RA
11
RB
16
252
/
 
Format X-form
Opcode 0x7C0001F8
Extension Base

Operands

  • RA
    Target Register
  • RS
    Source Register (Data)
  • RB
    Permute Control Byte Selects