summaryrefslogtreecommitdiff
path: root/frontend/decode.h
diff options
context:
space:
mode:
Diffstat (limited to 'frontend/decode.h')
-rw-r--r--frontend/decode.h15
1 files changed, 12 insertions, 3 deletions
diff --git a/frontend/decode.h b/frontend/decode.h
index 717d0f6..cb7bedd 100644
--- a/frontend/decode.h
+++ b/frontend/decode.h
@@ -24,15 +24,20 @@ namespace frontend {
24 unsigned int generation_down = 0; 24 unsigned int generation_down = 0;
25 std::uint64_t pc = 0; 25 std::uint64_t pc = 0;
26 26
27 std::uint64_t indirect_jump_origin = ~(std::uint64_t)0;
28 std::uint64_t indirect_jump_destination = ~(std::uint64_t)0;
29
27 static constexpr unsigned int MAX_INST_SIZE = 64; 30 static constexpr unsigned int MAX_INST_SIZE = 64;
28 static constexpr unsigned int BYTES_PER_CYCLE = 4; 31 static constexpr unsigned int BYTES_PER_CYCLE = 1;
29 32
30 void clock() { 33 void clock() {
31 if (restartp.can_read()) { 34 if (restartp.can_read()) {
32 auto r = restartp.read(); 35 auto r = restartp.read();
33 generation_down = r.new_generation; 36 generation_down = r.new_generation;
34 pc = r.new_pc; 37 next_inst.init_pc = pc = r.new_pc;
35 next_inst.size = 0; 38 next_inst.size = 0;
39 indirect_jump_origin = r.from_pc;
40 indirect_jump_destination = r.new_pc;
36 for (auto &f : next_inst.field) 41 for (auto &f : next_inst.field)
37 f = 0; 42 f = 0;
38 fetch::restart fr; 43 fetch::restart fr;
@@ -95,7 +100,10 @@ namespace frontend {
95 redirect = target; 100 redirect = target;
96 } 101 }
97 } else if (!taken.has_value() || taken.value()) { 102 } else if (!taken.has_value() || taken.value()) {
98 unpredictable = true; 103 if (next_inst.init_pc == indirect_jump_origin)
104 redirect = indirect_jump_destination;
105 else
106 unpredictable = true;
99 } 107 }
100 } 108 }
101 if (redirect.has_value()) { 109 if (redirect.has_value()) {
@@ -106,6 +114,7 @@ namespace frontend {
106 next_inst.predicted_next_pc.reset(); 114 next_inst.predicted_next_pc.reset();
107 } 115 }
108 instp->write(std::move(next_inst)); 116 instp->write(std::move(next_inst));
117 next_inst.init_pc = pc;
109 next_inst.size = unpredictable ? MAX_INST_SIZE : 0; 118 next_inst.size = unpredictable ? MAX_INST_SIZE : 0;
110 for (auto &f : next_inst.field) 119 for (auto &f : next_inst.field)
111 f = 0; 120 f = 0;