Home/Instructions/Pack Halfword
PACKH

RISC-V PACKH Instruction Details

Instruction ManualR-type

pack low bytes (Zbkb).

Instruction Syntax

packh 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

PACKH uses opcode 0110011 (0x33), funct3 111, 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: 111 (0x7)
funct7: 0000100 (0x04)

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.

Quick Understanding & Search Notes

PACKH 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 «packh a0, a1, a2».

Logical Operations

Understand this scenario with real code like «packh 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

The H in PACKH refers to the halfword-sized result, not the high half of the source registers.
Bits above bit 15 of the result are zeroed.

FAQ

Does PACKH access memory?

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

Which extension contains PACKH?

It belongs to the Zbkb cryptographic bit-manipulation extension.