Skip to content

Commit

Permalink
Fix immediate width of ImmJ and ImmB
Browse files Browse the repository at this point in the history
  • Loading branch information
freshLiver committed Jan 26, 2024
1 parent 85e406b commit cbf75be
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 10 deletions.
8 changes: 4 additions & 4 deletions src/isa/rv_i_ext.h
Original file line number Diff line number Diff line change
Expand Up @@ -309,7 +309,7 @@ struct Lui : public Instr<Lui, RVISA::OpcodeID::LUI> {

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:
Expand All @@ -321,7 +321,7 @@ namespace TypeJ {
/// - Imm[0] = 0
constexpr static unsigned VALID_INDEX = 1;
template <unsigned index>
struct ImmJ : public ImmSym<index, 21, Repr::Signed,
struct ImmJ : public ImmSym<index, 20, Repr::Signed,
ImmPartSet<ImmPart<20, 31, 31>, ImmPart<12, 12, 19>,
ImmPart<11, 20, 20>, ImmPart<1, 21, 30>>,
SymbolType::Relative> {
Expand Down Expand Up @@ -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:
Expand All @@ -500,7 +500,7 @@ enum class Funct3 {
/// - Imm[0] = 0
constexpr static unsigned VALID_INDEX = 2;
template <unsigned index>
struct ImmB : public ImmSym<index, 13, Repr::Signed,
struct ImmB : public ImmSym<index, 12, Repr::Signed,
ImmPartSet<ImmPart<12, 31, 31>, ImmPart<11, 7, 7>,
ImmPart<5, 25, 30>, ImmPart<1, 8, 11>>,
SymbolType::Relative> {
Expand Down
12 changes: 6 additions & 6 deletions test/tst_assembler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down

0 comments on commit cbf75be

Please sign in to comment.