mirror of
https://github.com/TomHarte/CLK.git
synced 2024-10-11 08:23:43 +00:00
Fix overflow test for ASL.
This commit is contained in:
parent
a1ae7c28b2
commit
5560a0ed39
@ -361,10 +361,16 @@ template <Operation operation, typename IntT, typename FlowController> void shif
|
|||||||
if(type == Type::LSL) {
|
if(type == Type::LSL) {
|
||||||
status.overflow_flag = 0;
|
status.overflow_flag = 0;
|
||||||
} else {
|
} else {
|
||||||
|
// Overflow records whether the top bit changed at any point during the operation.
|
||||||
if(shift >= size) {
|
if(shift >= size) {
|
||||||
status.overflow_flag = destination & top_bit<IntT>();
|
// The result is going to be all bits evacuated through the top giving a net
|
||||||
|
// result of 0, so overflow is set if any bit was originally set.
|
||||||
|
status.overflow_flag = destination;
|
||||||
} else {
|
} else {
|
||||||
status.overflow_flag = (destination ^ (destination << shift)) & top_bit<IntT>();
|
// For a shift of n places, overflow will be set if the top n bits were not
|
||||||
|
// all the same value.
|
||||||
|
const auto affected_bits = IntT(~0 << shift);
|
||||||
|
status.overflow_flag = (destination & affected_bits) && (destination & affected_bits) != affected_bits;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -382,7 +388,7 @@ template <Operation operation, typename IntT, typename FlowController> void shif
|
|||||||
} else {
|
} else {
|
||||||
status.carry_flag = status.extend_flag = (destination >> (shift - 1)) & 1;
|
status.carry_flag = status.extend_flag = (destination >> (shift - 1)) & 1;
|
||||||
}
|
}
|
||||||
status.overflow_flag = 0;
|
status.overflow_flag = 0; // The top bit can't change during an ASR, and LSR always clears overflow.
|
||||||
|
|
||||||
const IntT sign_word =
|
const IntT sign_word =
|
||||||
type == Type::LSR ?
|
type == Type::LSR ?
|
||||||
|
Loading…
Reference in New Issue
Block a user