@@ -117,71 +117,90 @@ DEF_COND(AL) = CondAL;
117
117
118
118
namespace {
119
119
120
- DEF_SEM (DoDirectBranch, PC target_pc) {
121
- Write (REG_PC, Read (target_pc));
120
+ DEF_SEM (DoDirectBranch, PC target_pc, R64W pc_dst) {
121
+ const auto new_pc = Read (target_pc);
122
+ Write (REG_PC, new_pc);
123
+ Write (pc_dst, new_pc);
122
124
return memory;
123
125
}
124
126
125
127
template <typename S>
126
- DEF_SEM (DoIndirectBranch, S dst) {
127
- Write (REG_PC, Read (dst));
128
+ DEF_SEM (DoIndirectBranch, S dst, R64W pc_dst) {
129
+ const auto new_pc = Read (dst);
130
+ Write (REG_PC, new_pc);
131
+ Write (pc_dst, new_pc);
128
132
return memory;
129
133
}
130
134
131
135
template <bool (*check_cond)(const State &)>
132
- DEF_SEM (DirectCondBranch, R8W cond, PC taken, PC not_taken) {
136
+ DEF_SEM (DirectCondBranch, R8W cond, PC taken, PC not_taken, R64W pc_dst ) {
133
137
addr_t taken_pc = Read (taken);
134
138
addr_t not_taken_pc = Read (not_taken);
135
139
uint8_t take_branch = check_cond (state);
136
140
Write (cond, take_branch);
137
- Write (REG_PC, Select<addr_t >(take_branch, taken_pc, not_taken_pc));
141
+
142
+ const auto new_pc = Select<addr_t >(take_branch, taken_pc, not_taken_pc);
143
+ Write (REG_PC, new_pc);
144
+ Write (pc_dst, new_pc);
138
145
return memory;
139
146
}
140
147
141
148
template <typename S>
142
- DEF_SEM (CBZ, R8W cond, PC taken, PC not_taken, S src) {
149
+ DEF_SEM (CBZ, R8W cond, PC taken, PC not_taken, S src, R64W pc_dst ) {
143
150
addr_t taken_pc = Read (taken);
144
151
addr_t not_taken_pc = Read (not_taken);
145
152
uint8_t take_branch = UCmpEq (Read (src), 0 );
146
153
Write (cond, take_branch);
147
- Write (REG_PC, Select<addr_t >(take_branch, taken_pc, not_taken_pc));
154
+
155
+ const auto new_pc = Select<addr_t >(take_branch, taken_pc, not_taken_pc);
156
+ Write (REG_PC, new_pc);
157
+ Write (pc_dst, new_pc);
148
158
return memory;
149
159
}
150
160
151
161
template <typename S>
152
- DEF_SEM (CBNZ, R8W cond, PC taken, PC not_taken, S src) {
162
+ DEF_SEM (CBNZ, R8W cond, PC taken, PC not_taken, S src, R64W pc_dst ) {
153
163
addr_t taken_pc = Read (taken);
154
164
addr_t not_taken_pc = Read (not_taken);
155
165
uint8_t take_branch = UCmpNeq (Read (src), 0 );
156
166
Write (cond, take_branch);
157
- Write (REG_PC, Select<addr_t >(take_branch, taken_pc, not_taken_pc));
167
+
168
+ const auto new_pc = Select<addr_t >(take_branch, taken_pc, not_taken_pc);
169
+ Write (REG_PC, new_pc);
170
+ Write (pc_dst, new_pc);
158
171
return memory;
159
172
}
160
173
161
174
162
175
template <typename S>
163
- DEF_SEM (TBZ, I8 bit_pos, R8W cond, PC taken, PC not_taken, S src) {
176
+ DEF_SEM (TBZ, I8 bit_pos, R8W cond, PC taken, PC not_taken, S src, R64W pc_dst ) {
164
177
addr_t taken_pc = Read (taken);
165
178
addr_t not_taken_pc = Read (not_taken);
166
179
auto bit_n = ZExtTo<S>(Read (bit_pos));
167
180
auto reg_val = ZExtTo<S>(Read (src));
168
181
auto bit_set = UAnd (reg_val, UShl (ZExtTo<S>(1 ), bit_n));
169
182
auto take_branch = UCmpEq (bit_set, 0 );
170
183
Write (cond, take_branch);
171
- Write (REG_PC, Select<addr_t >(take_branch, taken_pc, not_taken_pc));
184
+
185
+ const auto new_pc = Select<addr_t >(take_branch, taken_pc, not_taken_pc);
186
+ Write (REG_PC, new_pc);
187
+ Write (pc_dst, new_pc);
172
188
return memory;
173
189
}
174
190
175
191
template <typename S>
176
- DEF_SEM (TBNZ, I8 bit_pos, R8W cond, PC taken, PC not_taken, S src) {
192
+ DEF_SEM (TBNZ, I8 bit_pos, R8W cond, PC taken, PC not_taken, S src, R64W pc_dst ) {
177
193
addr_t taken_pc = Read (taken);
178
194
addr_t not_taken_pc = Read (not_taken);
179
195
auto bit_n = ZExtTo<S>(Read (bit_pos));
180
196
auto reg_val = ZExtTo<S>(Read (src));
181
197
auto bit_set = UAnd (reg_val, UShl (ZExtTo<S>(1 ), bit_n));
182
198
auto take_branch = UCmpNeq (bit_set, 0 );
183
199
Write (cond, take_branch);
184
- Write (REG_PC, Select<addr_t >(take_branch, taken_pc, not_taken_pc));
200
+
201
+ const auto new_pc = Select<addr_t >(take_branch, taken_pc, not_taken_pc);
202
+ Write (REG_PC, new_pc);
203
+ Write (pc_dst, new_pc);
185
204
return memory;
186
205
}
187
206
0 commit comments