Fix incorrect calculation for 16 bit half carry flag

old-bit-manip
Nick Krichevsky 2023-11-12 18:13:38 -05:00
parent f703d195f9
commit a658fbde1c
1 changed files with 2 additions and 1 deletions

View File

@ -241,7 +241,7 @@ fn did_8bit_add_full_carry_including_carry_bit<L: Into<u16>, R: Into<u16>>(
}
fn did_16bit_add_half_carry(lhs: u16, rhs: u16) -> bool {
(lhs & 0x0fff).wrapping_add(rhs & 0x0fff) > 0x0f00
(lhs & 0x0fff).wrapping_add(rhs & 0x0fff) > 0x0fff
}
fn twos_comp_abs(n: i8) -> u8 {
@ -361,6 +361,7 @@ mod tests {
}
#[test_case(0x0002, 0x0001, (0x0003, false, false); "simple add")]
#[test_case(0x0CDF, 0x0293, (3954, false, false); "simple add, big numbers")]
#[test_case(0x00FF, 0x0001, (0x0100, false, false); "8 bit overflow case does not overflow")]
#[test_case(0x8000, 0x8001, (0x0001, false, true); "full carry only")]
#[test_case(0x0F00, 0x0100, (0x1000, true, false); "half carry only")]