aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authordam <dam@gudinoff>2023-05-06 09:40:50 +0100
committerdam <dam@gudinoff>2023-05-06 09:40:50 +0100
commita219c3c1ef3d9cc5479426ef48035c44282b3cd2 (patch)
treeabfa8e7adaa323c79db1e75e7c97f298238c9b98
parent73a5595f19f7190e65d6338f828d80343dedd378 (diff)
downloadtask-time-tracker-a219c3c1ef3d9cc5479426ef48035c44282b3cd2.tar.zst
task-time-tracker-a219c3c1ef3d9cc5479426ef48035c44282b3cd2.zip
Using generic ASM code for signed integer add.
-rw-r--r--Math_Ext.jai76
1 files changed, 68 insertions, 8 deletions
diff --git a/Math_Ext.jai b/Math_Ext.jai
index bf1e8d6..44c4d44 100644
--- a/Math_Ext.jai
+++ b/Math_Ext.jai
@@ -34,7 +34,10 @@ main :: () {
// add_test(cast(u8)1, cast(u8)2, 3, u8, false);
// add_test(cast(u8)255, cast(u8)1, 255, u8, true);
- add_test(cast(s8)S8_MAX, cast(s8)1, S8_MAX, s8, true);
+ add_test(cast( s8) S8_MAX, cast( s8)1, S8_MAX, s8, true);
+ add_test(cast(s16)S16_MAX, cast(s16)1, S16_MAX, s16, true);
+ add_test(cast(s32)S32_MAX, cast(s32)1, S32_MAX, s32, true);
+ add_test(cast(s64)S64_MAX, cast(s64)1, S64_MAX, s64, true);
// add_test(cast(s32)66, cast(s64)-2, 64, s64, false);
// add_test(cast(u32)66, cast(s64)4, 70, s64, false);
// add_test(cast(s32)S32_MAX, cast(s64)1, 2147483648, s64, false);
@@ -51,7 +54,7 @@ main :: () {
return;
-
+/*
best_generic: float;
best_asm: float;
for 0..100 {
@@ -88,6 +91,7 @@ main :: () {
return SUM_SIZE, time, time_asm;
}
+ */
}
@@ -140,7 +144,7 @@ old_add :: (x: $Tx, y: $Ty) -> result: $Tr, overflow: bool // #dump
return x + y, false;
}
-add :: (x: $Tx, y: $Ty) -> result: $Tr, overflow: bool // #dump
+add :: (x: $Tx, y: $Ty) -> result: $Tr, overflow: bool #dump
#modify {
type_info_x := cast(*Type_Info)Tx;
type_info_y := cast(*Type_Info)Ty;
@@ -193,20 +197,75 @@ add :: (x: $Tx, y: $Ty) -> result: $Tr, overflow: bool // #dump
result: Tr = ---;
overflow: bool = ---;
- #if Tr == s8 {
+#import "String";
+
+ ADD_ASM :: #string DONE
#asm { // s8
x === a;
y === b;
- mov d: gpr === d, MAX;
- mov.b c: gpr === c, x; // TODO Not using .b was erroing.
+ mov max: gpr === d, MAX;
+ mov.SIZE c: gpr === c, x; // TODO Not using .b was erroing.
shr c, BITS;
- add c, d;
- add.b x, y; // add.b for 8bits
+ add c, max;
+ add.SIZE x, y; // add.b for 8bits
cmovo x, c;
seto overflow;
mov result, x;
}
+ DONE
+
+ #if Tr == s8
+ #insert #run replace(replace(replace(ADD_ASM, ".SIZE", ".b"), "MAX", "127"), "BITS", "7");
+ #if Tr == s16
+ #insert #run replace(replace(replace(ADD_ASM, ".SIZE", ".w"), "MAX", "32767"), "BITS", "15");
+ #if Tr == s32
+ #insert #run replace(replace(replace(ADD_ASM, ".SIZE", ".d"), "MAX", "2147483647"), "BITS", "31");
+ #if Tr == s64
+ #insert #run replace(replace(replace(ADD_ASM, ".SIZE", ".q"), "MAX", "9223372036854775807"), "BITS", "63");
+
+
+ // TODO
+ // WIP - doing a similar process for unsigned saturation add
+ else #if Tr == u8 {
+ #asm { // u8
+ x === a;
+ y === b;
+ d: gpr;
+ add.b x, y; // add.b for 8bits
+ setc overflow;
+ sbb d, d;
+ or d, x;
+ mov result, d;
+ }
}
+ else #if Tr == u16 {
+ #asm { // u16
+ x === a;
+ y === b;
+ d: gpr;
+ add.w x, y; // add.w for 16bits
+ setc overflow;
+ sbb d, d;
+ or d, x;
+ mov result, d;
+ }
+ }
+
+
+ // #asm { // s8
+ // x === a;
+ // y === b;
+ // mov d: gpr === d, MAX;
+ // mov.b c: gpr === c, x; // TODO Not using .b was erroing.
+ // shr c, BITS;
+ // add c, d;
+ // add.b x, y; // add.b for 8bits
+ // cmovo x, c;
+ // seto overflow;
+ // mov result, x;
+ // }
+ // }
+ /*
else #if Tr == s32 {
#asm { // s32
x === a;
@@ -263,6 +322,7 @@ add :: (x: $Tx, y: $Ty) -> result: $Tr, overflow: bool // #dump
mov result, d;
}
}
+ */
return result, overflow;
}
}