Skip to content

Commit 639ebe6

Browse files
authored
m68000: fix CHK instruction timing and flags (#1776)
1 parent 9be2f9b commit 639ebe6

File tree

1 file changed

+13
-14
lines changed

1 file changed

+13
-14
lines changed

ares/component/processor/m68000/instructions.cpp

Lines changed: 13 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -338,28 +338,27 @@ template<u32 Size> auto M68000::instructionBTST(EffectiveAddress with) -> void {
338338
}
339339

340340
auto M68000::instructionCHK(DataRegister compare, EffectiveAddress maximum) -> void {
341-
auto source = read<Word>(maximum);
342-
auto target = read<Word>(compare);
343-
auto result = (n64)target - source;
344-
r.c = sign<Word>(result >> 1) < 0;
345-
r.v = sign<Word>((target ^ source) & (target ^ result)) < 0;
346-
r.z = clip<Word>(result) == 0;
347-
r.n = sign<Word>(result) < 0;
348-
r.n ^= r.v;
349-
prefetch();
341+
auto source = read<Word>(compare);
342+
auto target = read<Word>(maximum);
343+
CMP<Word>(source, target);
344+
idle(2);
345+
bool bound = r.n || r.v;
346+
CMP<Word>(0, source);
347+
idle(2);
350348

351-
if(!r.n && !r.z) {
349+
if(bound) {
350+
prefetched();
352351
return exception(Exception::BoundsCheck, Vector::BoundsCheck);
353352
}
354353

355-
r.z = clip<Word>(target) == 0;
356-
r.n = sign<Word>(target) < 0;
354+
idle(2);
355+
357356
if(r.n) {
358-
idle(2);
357+
prefetched();
359358
return exception(Exception::BoundsCheck, Vector::BoundsCheck);
360359
}
361360

362-
idle(6);
361+
prefetch();
363362
}
364363

365364
template<u32 Size> auto M68000::instructionCLR(EffectiveAddress with) -> void {

0 commit comments

Comments
 (0)