Skip to content

Commit b1d02fc

Browse files
replace spdlog::trace with SPDLOG_TRACE that can be disabled at compile time
1 parent bc2c319 commit b1d02fc

11 files changed

Lines changed: 54 additions & 24 deletions

File tree

flags/CMakeLists.txt

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,3 +68,7 @@ target_link_options(sim-flags
6868
>
6969
)
7070

71+
target_compile_definitions(sim-flags INTERFACE
72+
$<$<CONFIG:Release>:SPDLOG_ACTIVE_LEVEL=SPDLOG_LEVEL_INFO>
73+
$<$<CONFIG:Debug>:SPDLOG_ACTIVE_LEVEL=SPDLOG_LEVEL_TRACE>
74+
)

src/helpers/include/helpers/trace_calls.hpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77

88
namespace hlp {
99

10-
inline void trace_call(std::source_location loc = std::source_location::current()) {
10+
inline void trace_call([[maybe_unused]] std::source_location loc = std::source_location::current()) {
1111
#if !defined(NDEBUG)
1212
// spdlog::debug("Function call: {}, {}:{}", loc.function_name(), loc.file_name(), loc.line());
1313
spdlog::debug("Function call: {}", loc.function_name());

src/isa/include/isa/rv_insn.hpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ class RvInsn {
3737
constexpr uint32_t kRdShift = 7;
3838
constexpr uint32_t kRdMask = 0x1Fu;
3939
auto rd = (raw_insn_ >> kRdShift) & kRdMask;
40-
spdlog::trace("Rd(): rd = {}", rd);
40+
SPDLOG_TRACE("Rd(): rd = {}", rd);
4141
return rd;
4242
}
4343

@@ -51,7 +51,7 @@ class RvInsn {
5151
constexpr uint32_t kRs1Shift = 15;
5252
constexpr uint32_t kRs1Mask = 0x1Fu;
5353
auto rs1 = (raw_insn_ >> kRs1Shift) & kRs1Mask;
54-
spdlog::trace("Rs1(): rs1 = {}", rs1);
54+
SPDLOG_TRACE("Rs1(): rs1 = {}", rs1);
5555
return rs1;
5656
}
5757

@@ -78,7 +78,7 @@ class RvInsn {
7878
constexpr unsigned kImmBits = 12;
7979
uint32_t imm = raw_insn_ >> kImmShift;
8080
auto sext = SignExtend(imm, kImmBits);
81-
spdlog::trace("i immid: {}", sext);
81+
SPDLOG_TRACE("i immid: {}", sext);
8282
return sext;
8383
}
8484

@@ -139,7 +139,7 @@ class RvInsn {
139139
);
140140

141141
auto sext = SignExtend(imm, kImmBits);
142-
spdlog::trace("j immid: {}", sext);
142+
SPDLOG_TRACE("j immid: {}", sext);
143143
return sext;
144144
}
145145
};} // namespace isa

src/isa/source/ext_i_cb.cpp

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,9 +18,7 @@ namespace {
1818

1919
constexpr uint32_t ArithmRightShift(uint32_t x, unsigned shift) {
2020
constexpr unsigned num_bits = sizeof(x) * CHAR_BIT;
21-
constexpr uint32_t one = uint32_t{1};
2221
constexpr unsigned sign_bit = num_bits - 1;
23-
constexpr uint32_t sign_bit_mask = one << sign_bit;
2422
constexpr uint32_t all_ones = std::numeric_limits<uint32_t>::max();
2523
constexpr uint32_t zero = uint32_t{0};
2624

src/sim/include/sim/rv_sim.hpp

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ class RVSim {
6363
void SetXReg(size_t index, isa::Register value) {
6464
assert(index < isa::kNumXRegisters);
6565

66-
spdlog::trace("set x reg: index {}, value {}", index, value);
66+
SPDLOG_TRACE("set x reg: index {}, value {}", index, value);
6767

6868
if (index == hlp::FromEnum(isa::XRegAlias::zero)) { return; }
6969

@@ -88,7 +88,7 @@ class RVSim {
8888

8989
void SetFReg(size_t index, isa::FRegister value) {
9090
assert(index < isa::kNumFRegisters);
91-
spdlog::trace("set f reg: index {}, value {:#x}", index, value.v);
91+
SPDLOG_TRACE("set f reg: index {}, value {:#x}", index, value.v);
9292

9393
fregs_[index] = value;
9494
}
@@ -97,12 +97,12 @@ class RVSim {
9797
assert(index < isa::kNumFRegisters);
9898

9999
auto fval = fregs_[index];
100-
spdlog::trace("get f reg: index {}, value {:#x}", index, fval.v);
100+
SPDLOG_TRACE("get f reg: index {}, value {:#x}", index, fval.v);
101101
return fval;
102102
}
103103

104104
void SetCSR(size_t index, isa::Register value) {
105-
spdlog::debug("set csr called: index {}, value {}", index, value);
105+
SPDLOG_TRACE("set csr called: index {}, value {}", index, value);
106106

107107
switch (hlp::ToEnum<isa::CSR>(index)) {
108108
case isa::CSR::fflags:
@@ -125,7 +125,7 @@ class RVSim {
125125
}
126126

127127
isa::Register GetCSR(size_t index) {
128-
spdlog::debug("get csr called: index {}", index);
128+
SPDLOG_TRACE("get csr called: index {}", index);
129129

130130
switch (hlp::ToEnum<isa::CSR>(index)) {
131131
case isa::CSR::fflags:
@@ -165,9 +165,9 @@ class RVSim {
165165
}
166166

167167
void Trace() {
168-
spdlog::trace("trace sim:");
168+
SPDLOG_TRACE("trace sim:");
169169
for (size_t i = 0; i < isa::kNumXRegisters; i++) {
170-
spdlog::trace("Reg {}: {}", i, xregs_[i]);
170+
SPDLOG_TRACE("Reg {}: {}", i, xregs_[i]);
171171
}
172172
}
173173
};

src/sim/source/decode.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ constexpr DecodeTable InsnDecodeTable {{
2525
#undef MNEMONIC
2626
}};
2727

28+
// FIXME fix decode
2829
isa::InsnMnemonic Decode(isa::UndecodedInsn insn) {
2930
for (auto& entry: InsnDecodeTable) {
3031
if ((insn & entry.mask) == entry.match) {

src/sim/source/memory.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ bool IsAddrInSegment(isa::Address addr, const MemorySegm& segm);
1818
} // namespace
1919

2020
uint32_t Memory::LoadU32(isa::Address addr) {
21-
spdlog::trace("Memory u32 read: addr {}", addr);
21+
SPDLOG_TRACE("Memory u32 read: addr {}", addr);
2222

2323
for (const auto& segm: memory_) {
2424
if (!IsAddrInSegment(addr, segm)) { continue; }

src/sim/source/rv_sim.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,10 +18,10 @@ int RVSim::Execute() {
1818
// Trace();
1919

2020
isa::UndecodedInsn undecoded_insn = memory_.Fetch(ip_);
21-
spdlog::trace("undecoded insn: {:#04x}", undecoded_insn);
21+
SPDLOG_TRACE("undecoded insn: {:#04x}", undecoded_insn);
2222

2323
isa::InsnMnemonic mnem = Decode(undecoded_insn);
24-
spdlog::trace("Mnemonic: {}", isa::MnemonicToStr(mnem));
24+
SPDLOG_TRACE("Mnemonic: {}", isa::MnemonicToStr(mnem));
2525
if (mnem == isa::InsnMnemonic::kInvalid) {
2626
throw hlp::TraceableException{"Unkown instuction encountered"};
2727
}

tests/compute_heavy_test/api.s

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
.global read
2+
.global write
3+
.global exit
4+
.global _start
5+
6+
.section .text
7+
8+
read:
9+
li a7, 63
10+
ecall
11+
ret
12+
13+
write:
14+
li a7, 64
15+
ecall
16+
ret
17+
18+
exit:
19+
li a7, 93
20+
ecall
21+
22+
_start:
23+
# passing argc, argv[]
24+
lw a0, 0(sp)
25+
addi a1, sp, 4 # 8 for 64-bit mode
26+
call main
27+
j exit

tests/compute_heavy_test/build.sh

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,20 @@
11
#!/bin/bash
22

33
riscv64-unknown-elf-gcc \
4-
-march=rv32im \
5-
-mabi=ilp32 \
4+
-march=rv32imf_zbb \
5+
-mabi=ilp32f \
66
-nostdlib \
77
-ffreestanding \
88
$1 -o $1.s -S -O2
99

1010
riscv64-unknown-elf-as \
11-
-march=rv32im \
12-
-mabi=ilp32 \
11+
-march=rv32imf_zbb \
12+
-mabi=ilp32f \
1313
-o $1.o $1.s
1414

1515
riscv64-unknown-elf-as \
16-
-march=rv32im \
17-
-mabi=ilp32 \
16+
-march=rv32imf_zbb \
17+
-mabi=ilp32f \
1818
-o api.o api.s
1919

2020
riscv64-unknown-elf-ld \

0 commit comments

Comments
 (0)