You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
#%# IMPORTANT: the buildings must be linked in the order shown here
@@ -113,12 +120,14 @@ check_interrupts__machine:
113
120
set mcause 0x80000007 # machine timer interrupt
114
121
jump trap_without_mtval notEqual mie.mtie 0
115
122
123
+
# cost:
124
+
# base: 17
125
+
# fast path: 42 (base + 9 + 16)
126
+
# slow path: 35 (base + 13 + 5) + dynamic
116
127
main:
117
128
# store the pc for the following instruction in a separate variable, so jumps and traps don't need to account for the pc being incremented at the end of an instruction
118
129
op add next_pc pc 4
119
130
120
-
set mtval pc
121
-
122
131
# get the current instruction cache processor and variable
123
132
jump main__read_icache notEqual icache_var null
124
133
@@ -129,14 +138,28 @@ main:
129
138
jump main__access_icache lessThan pc ICACHE_SIZE
130
139
131
140
main__slow_instruction_fetch:
141
+
# update accumulator in case we take a trap while loading
142
+
# 13 (instructions between main and the below comment) + 5 (load_word static cost)
143
+
op sub accumulator accumulator 18
144
+
132
145
jump default_mtvec_handler equal pc {{SYSCON}}
133
146
147
+
set mtval pc
134
148
set mcause 1 # instruction access fault
135
149
jump trap greaterThanEq pc RAM_END # prevent executing from MMIO
136
150
137
151
set address pc
138
152
op add ret @counter 1
139
153
jump load_word always
154
+
# ^ above accumulator count ends here
155
+
156
+
# a trap cannot occur between now and the lookup table fetch
157
+
# so modify accumulator to take base_instruction_cost into account
158
+
# base_instruction_cost assumes we take the fast path
159
+
# at this point, we've double-counted 5 instructions on the base path
160
+
# also, the static cost of the slow path is 7 instructions fewer than the fast path
161
+
# so we can safely add 12 instructions back into the accumulator
0 commit comments