From f993b20d0f4400d1b9e4c918f5cbbcb3cddbb8a0 Mon Sep 17 00:00:00 2001 From: dam Date: Sat, 29 Apr 2023 04:07:38 +0100 Subject: Comparing add_s64 implementations. --- ttt.jai | 28 +++++++++++++++++++++++++++- 1 file changed, 27 insertions(+), 1 deletion(-) (limited to 'ttt.jai') diff --git a/ttt.jai b/ttt.jai index 60db8b7..503c418 100644 --- a/ttt.jai +++ b/ttt.jai @@ -291,7 +291,7 @@ mvprintw_time :: (y: s32, x: s32, time: s64, space: s32) -> int { } } -add_int64 :: (x :s64, y: s64) -> s64 { +add_int64 :: (x :s64, y: s64) -> s64 #dump { // TODO Comparing implementations. return ifx (y > 0 && x > S64_MAX - y) then S64_MAX else ifx (y < 0 && x < S64_MIN - y) then S64_MIN else @@ -1164,6 +1164,32 @@ read_enter_confirmation :: inline (row: int, style: int, message: string) -> boo main :: () { + + add :: (value_a: s64, value_b: s64) -> s64, bool #dump { // TODO Comparing implementaitons using dump + result: s64 = ---; + flag: bool = ---; + #asm { + mov d: gpr === d, 9223372036854775807; + mov a: gpr === a, value_a; + mov b: gpr === b, value_b; + add a, b; + seto flag; // Signal overflow. + mov result, a; + mov a, value_a; + shr a, 63; + add a, d; + mov c: gpr, value_a; + xor c, b; + xor b, result; + not b; + or c, b; + test c, c; + cmovns result, a; + } + return result, flag; + } + + // value_a: s64 = 2; // value_b: s64 = S64_MAX-1; value_a: s64 = -2; -- cgit v1.2.3