c.lhu
Load unsigned halfword, 16-bit encoding
This instruction is defined by:
-
anyOf:
-
Zcb, version >= 0
-
Zce, version >= 0
-
This instruction is included in the following profiles:
Synopsis
Loads a 16-bit value from memory into register rd.
It computes an effective address by adding the zero-extended offset, to the base address in register rs1.
It expands to lhu rd, offset(rs1)
.
Decode Variables
Bits<2> imm = {$encoding[5], 1'd0};
Bits<3> rd = $encoding[4:2];
Bits<3> rs1 = $encoding[9:7];
Execution
-
IDL
-
Sail
if (implemented?(ExtensionName::C) && (CSR[misa].C == 1'b0)) {
raise(ExceptionCode::IllegalInstruction, mode(), $encoding);
}
XReg virtual_address = X[rs1 + 8] + imm;
X[rd + 8] = zext(read_memory<16>(virtual_address, $encoding), 16);
{
let offset : xlenbits = zero_extend(imm);
/* Get the address, X(rs1c) + offset.
Some extensions perform additional checks on address validity. */
match ext_data_get_addr(rs1c, offset, Read(Data), width) {
Ext_DataAddr_Error(e) => { ext_handle_data_check_error(e); RETIRE_FAIL },
Ext_DataAddr_OK(vaddr) =>
if check_misaligned(vaddr, width)
then { handle_mem_exception(vaddr, E_Load_Addr_Align()); RETIRE_FAIL }
else match translateAddr(vaddr, Read(Data)) {
TR_Failure(e, _) => { handle_mem_exception(vaddr, e); RETIRE_FAIL },
TR_Address(paddr, _) =>
match (width) {
BYTE =>
process_load(rdc, vaddr, mem_read(Read(Data), paddr, 1, aq, rl, false), is_unsigned),
HALF =>
process_load(rdc, vaddr, mem_read(Read(Data), paddr, 2, aq, rl, false), is_unsigned),
WORD =>
process_load(rdc, vaddr, mem_read(Read(Data), paddr, 4, aq, rl, false), is_unsigned),
DOUBLE if sizeof(xlen) >= 64 =>
process_load(rdc, vaddr, mem_read(Read(Data), paddr, 8, aq, rl, false), is_unsigned),
_ => report_invalid_width(__FILE__, __LINE__, width, "load")
}
}
}
}