Skip to content

Commit 70d88e2

Browse files
committed
fix: correcting handling of fence.i
1 parent 07eb914 commit 70d88e2

File tree

5 files changed

+38
-7
lines changed

5 files changed

+38
-7
lines changed

backends/cpp_hart_gen/cpp/include/udb/bits.hpp

Lines changed: 25 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2976,7 +2976,31 @@ namespace udb {
29762976
}
29772977
}
29782978

2979-
void apply_mask() { m_val = m_val & _RuntimeBits<MaxN, false>{mask(), m_width}; }
2979+
bool needs_mask() const {
2980+
if constexpr (MaxN > BitsMaxNativePrecision) {
2981+
if (m_width == BitsInfinitePrecision) {
2982+
// special case: we store infinite numbers with their sign
2983+
return false;
2984+
} else {
2985+
// gmp storage, without upper bound, so everything needs masked
2986+
return true;
2987+
}
2988+
} else {
2989+
if (m_width == (sizeof(StorageType) * 8)) {
2990+
// we fit exactly in our native storage
2991+
return false;
2992+
} else {
2993+
// using native storage, but there are unused bits
2994+
return true;
2995+
}
2996+
}
2997+
}
2998+
2999+
void apply_mask() {
3000+
if(needs_mask()) {
3001+
m_val = m_val & _RuntimeBits<MaxN, false>{mask(), m_width};
3002+
}
3003+
}
29803004

29813005
public:
29823006
// used for template concept resolution

backends/cpp_hart_gen/cpp/include/udb/hart.hpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -169,7 +169,8 @@ namespace udb {
169169
m_soc.fence(pi, pr, po, pw, si, sr, so, sw);
170170
}
171171
void fence_tso() { m_soc.fence_tso(); }
172-
void ifence() { m_soc.ifence(); }
172+
virtual void ifence() { m_soc.ifence(); }
173+
173174
template <typename... Args>
174175
void order_pgtbl_writes_before_vmafence(Args...) {
175176
// TODO: pass along order info (not easy now because VmaOrderType is

backends/cpp_hart_gen/templates/hart.hxx.erb

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -464,6 +464,11 @@ namespace udb {
464464

465465
uint64_t fetch() override { return _fetch().get(); }
466466
PossiblyUnknownBits<INSTR_ENC_SIZE.get()> _fetch();
467+
void ifence() override {
468+
m_bb_cache.invalidate();
469+
HartBase<SocType>::ifence();
470+
this->m_exit_requested = true;
471+
}
467472

468473
<%= name_of(:struct, cfg_arch, "CachedTranslationResult") %> cached_translation(const PossiblyUnknownBits<64>& vaddr, const MemoryOperation& op) const {
469474
<%- if cfg_arch.symtab.get("CachedTranslationResult").runtime? -%>

backends/cpp_hart_gen/templates/hart_impl.hxx.erb

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -142,11 +142,12 @@ namespace udb {
142142
m_next_pc = m_pc + Bits<MXLEN>{inst->enc_len()};
143143
144144
inst->execute();
145+
146+
advance_pc();
145147
if (this->m_exit_requested) {
146-
this->m_exit_requested = false; // reset the request
148+
this->m_exit_requested = false; // reset the request
147149
break;
148150
}
149-
advance_pc();
150151
}
151152
} else {
152153
// miss, need to create the bb
@@ -174,12 +175,11 @@ namespace udb {
174175
fmt::print("R= {} {:x}\n", r.to_string(), _xreg(r.get_num()));
175176
}
176177
178+
advance_pc();
177179
if (this->m_exit_requested) {
178180
this->m_exit_requested = false; // reset the request
179181
break;
180182
}
181-
182-
advance_pc();
183183
} while (!(current_bb->full() || inst->control_flow()));
184184
}
185185
} catch (const AbortInstruction& e) {

cfgs/mc100-32-riscv-tests.yaml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
$schema: https://riscv.org/udb/schemas/config_schema-0.1.0.json
44
kind: architecture configuration
55
type: fully configured
6-
name: MC100-32-Full
6+
name: MC100-32-riscv-tests
77
description: An example MC100-32-compliant full config for riscv-tests
88
implemented_extensions:
99
- [Sm, "1.11.0"]
@@ -16,6 +16,7 @@ implemented_extensions:
1616
- [S, "1.11.0"]
1717
- [Smpmp, "1.11.0"]
1818
- [U, "1.0.0"]
19+
- [Zifencei, "2.0.0"]
1920

2021
params:
2122
MXLEN: 32

0 commit comments

Comments
 (0)