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 Encoding

31..25
funct7
24..20
rs2
19..15
rs1
14..12
funct3
11..7
rd
6..0
opcode

PACK uses opcode 0110011 (0x33), funct3 100, funct7 0000100. The rs1 and rs2 fields select the two source registers, and rd selects the destination register.

Format: R-type
opcode: 0110011 (0x33)
funct3: 100 (0x4)
funct7: 0000100 (0x04)

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].

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

Crypto & Security

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

Logical Operations

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

Pre-Use Checklist

Syntax Check
  • Confirm the current instruction format is R-type.
  • Confirm the operand order matches the example.
Semantic Check
  • Ensure the destination register usage is compatible with the calling convention.
  • Confirm this is not the lower-level form of a pseudo-instruction expansion.

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.