PACK

RISC-V PACK Instruction Details

Instruction ManualR-type

pack low halves (Zbkb).

Instruction Syntax

pack rd, rs1, rs2

RV32/RV64 Zbkb 1.0; syntax pack rd, rs1, rs2, selecting integer x0–x31 or ABI names, with no immediate.

32-bit R-type: funct7=0000100, funct3=100, opcode=0110011.

rd concatenates low XLEN/2 bits of rs2 above low XLEN/2 bits of rs1.

Read sources before writeback; equal sources have one old value, x0 sources are zero, and rd=x0 discards writeback. No memory access occurs.

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
01100 (a2)
19..15
rs1
01011 (a1)
14..12
funct3
100
11..7
rd
01010 (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 (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].

Available on RV32/RV64; PACK takes low XLEN/2-bit halves, while PACKH takes low bytes.
Sources and destination are integer registers; no memory access or table lookup occurs.

Common Usage Scenarios

Packing low register halves

Assume RV64 Zbkb, a1=0x1122334455667788 and a2=0x99AABBCCDDEEFF80; pack a0, a1, a2 produces a0=0xDDEEFF8055667788, leaving sources and memory unchanged.

Cryptographic bit manipulation

Assume RV64 Zbkb, a1=0x1122334455667788 and a2=0x99AABBCCDDEEFF80; pack a0, a1, a2 produces a0=0xDDEEFF8055667788, leaving sources and memory unchanged.

Pre-Use Checklist

Syntax Check
  • RV32/RV64 Zbkb 1.0; syntax pack rd, rs1, rs2, selecting integer x0–x31 or ABI names, with no immediate.
  • 32-bit R-type: funct7=0000100, funct3=100, opcode=0110011.
Semantic Check
  • rd concatenates low XLEN/2 bits of rs2 above low XLEN/2 bits of rs1.
  • Read sources before writeback; equal sources have one old value, x0 sources are zero, and rd=x0 discards writeback. No memory access occurs.

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 concatenates low fields from rs1 and rs2 into rd, without a table lookup.

Which extension contains PACK?

It belongs to the Zbkb cryptographic bit-manipulation extension.