PACK

RISC-V PACK Instruction Details

Instruction ManualR-type

pack low halves (Zbkb).

Instruction Syntax

pack rd, rs1, rs2
Operand Breakdown
Destination rd: register receiving the operation result.
Source rs1: register holding the first operand.
Source rs2: register holding the second operand.
ZbkbBit Manipulation

Instruction Behavior

PACK (Zbkb) places the low XLEN/2 bits of rs1 into the low half of rd and the low XLEN/2 bits of rs2 into the high half of rd. On RV32, rd[15:0]=rs1[15:0] and rd[31:16]=rs2[15:0]; on RV64, rd[31:0]=rs1[31:0] and rd[63:32]=rs2[31:0].

PACK Decode & Execute Animation

Shows only specification-defined encodings, conditions, and architectural state; it does not model pipelines, cache coherence, or platform policy.

pack a0, a1, a2
Execution Context
Instruction Encoding
31..25
funct7
0000100
24..20
rs2
a2
19..15
rs1
a1
14..12
funct3
100
11..7
rd
a0
6..0
opcode
0110011 (OP)
Decode fixed fields
Fixed encoding fields identify the instruction and operand roles.
x[a0] <- 0xDDEEFF8055667788
Architectural state has not been committed.

Quick Understanding & Search Notes

PACK is a Zbkb cryptographic bit-manipulation instruction; this page follows the official B-extension operation.

When available on RV32/RV64, operation width follows XLEN.
These instructions rearrange bit/byte fields and do not access memory.

Common Usage Scenarios

Bit Manipulation

Understand this scenario with real code like «pack a0, a1, a2».

Register Bit Interleave

Understand this scenario with real code like «pack a0, a1, a2».

Pre-Use Checklist

Syntax Check
  • Verify rd, rs1, rs2 (and rs3) are valid GPRs.
  • Confirm funct3 and funct7 encoding is correct.
Semantic Check
  • Check if the result affects subsequent branches or address calculations.
  • Ensure the rd register is not overwritten by another instruction.

Pitfalls / Common Confusions

On RV32 this is not an OR alias; it packs two low 16-bit halves.
PACKH and PACKW use different granularities: PACKH packs low bytes, while PACKW on RV64 packs low 16-bit halves and sign-extends.

FAQ

Does PACK access memory?

No. It only rearranges bit fields or performs register lookup within integer registers.

Which extension contains PACK?

It belongs to the Zbkb cryptographic bit-manipulation extension.