Webcentive RISC-V Reference

sext.h

Sign-extend halfword

Extension
Zbb
XLEN
RV32 and RV64
Assembly (riscv-unified-db)
sext.h xd, xs1
Length
32-bit

Encoding

3120191514121176210
011000000101rs1001rd0010011

Match 0x60501013, mask 0xfff0707f. Source: sext.h rd rs1 31..20=0x605 14..12=1 6..2=0x04 1..0=3 in riscv-opcodes/extensions/rv_zbb.

FieldBitsriscv-opcodes name
rs119:15rs1
rd11:7rd

Description

Sign-extends the least-significant halfword in the source to XLEN by copying the most-significant bit in the halfword (i.e., bit 15) to all of the more-significant bits.

Description from riscv-unified-db, reformatted.

Operation

if (xlen() == 32) {
  X[xd] = {{16{X[xs1][15]}}, X[xs1][15:0]};
} else if (xlen() == 64) {
  X[xd] = {{48{X[xs1][15]}}, X[xs1][15:0]};
}

Pseudocode in riscv-unified-db’s IDL, quoted unchanged.

Specification and related pages