Home/Instructions/Pack Low Bytes
PACKH

RISC-V PACKH Instruction Details

Instruction ManualR-type

pack low bytes (Zbkb).

Instruction Syntax

packh rd, rs1, rs2

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

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

rd[15:0] concatenates rs2[7:0] above rs1[7:0], zero-extending all upper 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

PACKH (Zbkb) places the low byte of rs1 into rd[7:0], the low byte of rs2 into rd[15:8], and clears all remaining high bits of rd. It does not pack the high halves of the source registers.

PACKH Decode & Execute Animation

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

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

Quick Understanding & Search Notes

PACKH (Zbkb) places the low byte of rs1 into rd[7:0], the low byte of rs2 into rd[15:8], and clears all remaining high bits of rd. It does not pack the high halves of the source registers.

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 fields

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

Cryptographic bit manipulation

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

Pre-Use Checklist

Syntax Check
  • RV32/RV64 Zbkb 1.0; syntax packh rd, rs1, rs2, selecting integer x0–x31 or ABI names, with no immediate.
  • 32-bit R-type: funct7=0000100, funct3=111, opcode=0110011.
Semantic Check
  • rd[15:0] concatenates rs2[7:0] above rs1[7:0], zero-extending all upper 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

PACKH takes the low byte from each source, rather than the high source halves.
Bits above bit 15 of the result are zeroed.

FAQ

Does PACKH access memory?

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

Which extension contains PACKH?

It belongs to the Zbkb cryptographic bit-manipulation extension.