From cbf75be7ee77a3600d948e86476dba323a32b2c1 Mon Sep 17 00:00:00 2001 From: Yuanhsi Chung Date: Thu, 25 Jan 2024 15:38:15 +0800 Subject: [PATCH] Fix immediate width of ImmJ and ImmB --- src/isa/rv_i_ext.h | 8 ++++---- test/tst_assembler.cpp | 12 ++++++------ 2 files changed, 10 insertions(+), 10 deletions(-) diff --git a/src/isa/rv_i_ext.h b/src/isa/rv_i_ext.h index 9d9bc202..302b446e 100644 --- a/src/isa/rv_i_ext.h +++ b/src/isa/rv_i_ext.h @@ -309,7 +309,7 @@ struct Lui : public Instr { namespace TypeJ { -/// A RISC-V signed immediate field with an input width of 21 bits. +/// A RISC-V signed immediate field with an input width of 20 bits. /// Used in J-Type instructions. /// /// It is defined as: @@ -321,7 +321,7 @@ namespace TypeJ { /// - Imm[0] = 0 constexpr static unsigned VALID_INDEX = 1; template -struct ImmJ : public ImmSym, ImmPart<12, 12, 19>, ImmPart<11, 20, 20>, ImmPart<1, 21, 30>>, SymbolType::Relative> { @@ -489,7 +489,7 @@ enum class Funct3 { BGEU = 0b111 }; -/// A RISC-V signed immediate field with an input width of 13 bits. +/// A RISC-V signed immediate field with an input width of 12 bits. /// Used in B-Type instructions. /// /// It is defined as: @@ -500,7 +500,7 @@ enum class Funct3 { /// - Imm[0] = 0 constexpr static unsigned VALID_INDEX = 2; template -struct ImmB : public ImmSym, ImmPart<11, 7, 7>, ImmPart<5, 25, 30>, ImmPart<1, 8, 11>>, SymbolType::Relative> { diff --git a/test/tst_assembler.cpp b/test/tst_assembler.cpp index fac4d8a8..654bbd84 100644 --- a/test/tst_assembler.cpp +++ b/test/tst_assembler.cpp @@ -270,12 +270,12 @@ void tst_Assembler::tst_immBitRange() { testAssemble(QStringList() << "lui a0 0x100000", Expect::Fail); testAssemble(QStringList() << "auipc a0 0x0FFFFF", Expect::Success); testAssemble(QStringList() << "auipc a0 0x100000", Expect::Fail); - // J-type: 21 bits imm (ImmJ) - testAssemble(QStringList() << "jal x0 0x1FFFFF", Expect::Success); - testAssemble(QStringList() << "jal x0 0x200000", Expect::Fail); - // B-type: 13 bits imm (ImmB) - testAssemble(QStringList() << "beq a0 x0 0x1FFF", Expect::Success); - testAssemble(QStringList() << "beq a0 x0 0x2000", Expect::Fail); + // J-type: 20 bits imm (ImmJ) + testAssemble(QStringList() << "jal x0 0x0FFFFF", Expect::Success); + testAssemble(QStringList() << "jal x0 0x100000", Expect::Fail); + // B-type: 12 bits imm (ImmB) + testAssemble(QStringList() << "beq a0 x0 0x0FFF", Expect::Success); + testAssemble(QStringList() << "beq a0 x0 0x1000", Expect::Fail); // pseudo: 32 bits imm testAssemble(QStringList() << "li a0 0xFFFFFFFF", Expect::Success); testAssemble(QStringList() << "li a0 0x100000000", Expect::Fail);