Home/Instructions/Pack Low 16-Bit Fields
PACKW

RISC-V PACKW Instruction Details

Instruction ManualR-type

RV64 pack low 16-bit fields (Zbkb), RV64-only.

Instruction Syntax

packw rd, rs1, rs2

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

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

rd sign-extends the concatenation of rs2[15:0] above rs1[15:0], extending bit31 to 64 bits.

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

PACKW (Zbkb, RV64) places rs1[15:0] into result bits [15:0], rs2[15:0] into bits [31:16], then sign-extends bit 31 into the upper 32 bits of rd.

PACKW Decode & Execute Animation

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

packw 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
0111011 (OP-32)
Decode fixed fields
Fixed encoding fields identify the instruction and operand roles.
x[a0] <- 0xFFFFFFFFFF807788
Architectural state has not been committed.

Quick Understanding & Search Notes

PACKW (Zbkb, RV64) places rs1[15:0] into result bits [15:0], rs2[15:0] into bits [31:16], then sign-extends bit 31 into the upper 32 bits of rd.

RV64 only; sign-extend the packed 32-bit result to 64 bits.
Sources and destination are integer registers; no memory access or table lookup occurs.

Common Usage Scenarios

Packing low register fields

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

Cryptographic bit manipulation

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

Pre-Use Checklist

Syntax Check
  • RV64 only Zbkb 1.0; syntax packw rd, rs1, rs2, selecting integer x0–x31 or ABI names, with no immediate.
  • 32-bit R-type: funct7=0000100, funct3=100, opcode=0111011.
Semantic Check
  • rd sign-extends the concatenation of rs2[15:0] above rs1[15:0], extending bit31 to 64 bits.
  • 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

PACKW is defined only for RV64.
The result is the sign-extension of the packed 32-bit value, not zero-extension.

FAQ

Does PACKW access memory?

No. It concatenates low fields from rs1 and rs2 into rd, without a table lookup.

Which extension contains PACKW?

It belongs to the Zbkb cryptographic bit-manipulation extension.