aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--Math_Ext.jai88
1 files changed, 42 insertions, 46 deletions
diff --git a/Math_Ext.jai b/Math_Ext.jai
index e9b3ab9..bfa64fa 100644
--- a/Math_Ext.jai
+++ b/Math_Ext.jai
@@ -270,15 +270,15 @@ add :: (x: $Tx, y: $Ty) -> result: $Tr, saturated: bool #modify { #insert INTEGE
S_ADD_ASM :: #string DONE
#asm {
// Calculate limit based on x's sign.
- mov limit: gpr, MAX;
- mov sign: gpr, x;
- shr.SIZE sign, BITS;
- add.SIZE limit, sign;
-
- mov result, x;
- add.SIZE result, y;
- seto saturated;
- cmovo result, limit;
+ mov limit: gpr, MAX;
+ mov sign: gpr, x;
+ shr.SIZE sign, BITS;
+ add.SIZE limit, sign;
+
+ mov result, x;
+ add.SIZE result, y;
+ seto saturated;
+ cmovo result, limit;
}
DONE
@@ -294,11 +294,11 @@ add :: (x: $Tx, y: $Ty) -> result: $Tr, saturated: bool #modify { #insert INTEGE
U_ADD_ASM :: #string DONE
#asm {
- mov limit: gpr, MAX;
- mov result, x;
+ mov limit: gpr, MAX;
+ mov result, x;
add.SIZE result, y;
- setc saturated;
- cmovc result, limit;
+ setc saturated;
+ cmovc result, limit;
}
DONE
@@ -349,15 +349,15 @@ sub :: (x: $Tx, y: $Ty) -> result: $Tr, overflow: bool #modify { #insert INTEGER
S_SUB_ASM :: #string DONE
#asm {
// Calculate limit based on x's sign.
- mov limit: gpr, MAX;
- mov sign: gpr, x;
- shr.SIZE sign, BITS;
- add.SIZE limit, sign;
-
- mov result, x;
- sub.SIZE result, y;
- seto saturated;
- cmovo result, limit;
+ mov limit: gpr, MAX;
+ mov sign: gpr, x;
+ shr.SIZE sign, BITS;
+ add.SIZE limit, sign;
+
+ mov result, x;
+ sub.SIZE result, y;
+ seto saturated;
+ cmovo result, limit;
}
DONE
@@ -373,11 +373,11 @@ sub :: (x: $Tx, y: $Ty) -> result: $Tr, overflow: bool #modify { #insert INTEGER
U_SUB_ASM :: #string DONE
#asm {
- mov limit: gpr, 0;
- mov result, x;
+ mov limit: gpr, 0;
+ mov result, x;
sub.SIZE result, y;
- setc saturated;
- cmovc result, limit;
+ setc saturated;
+ cmovc result, limit;
}
DONE
@@ -434,16 +434,16 @@ mul :: (x: $Tx, y: $Ty) -> result: $Tr, overflow: bool #modify { #insert INTEGER
result === a;
// Calculate limit based on (x^y)'s sign.
- mov limit: gpr, MAX;
- mov sign: gpr, x;
- xor sign, y;
- shr.SIZE sign, BITS;
- add.SIZE limit, sign;
+ mov limit: gpr, MAX;
+ mov sign: gpr, x;
+ xor sign, y;
+ shr.SIZE sign, BITS;
+ add.SIZE limit, sign;
- mov result, x;
+ mov result, x;
imul.SIZE result, y;
- seto saturated;
- cmovo result, limit;
+ seto saturated;
+ cmovo result, limit;
}
DONE
@@ -460,27 +460,23 @@ mul :: (x: $Tx, y: $Ty) -> result: $Tr, overflow: bool #modify { #insert INTEGER
U_MUL_ASM :: #string DONE
#asm {
result === a;
- result_h: gpr === d;
-
- mov tmp: gpr, x;
- mov result, x;
- mul.SIZE result_h, result, y;
- setc saturated;
- sbb tmp, tmp; // SBB performs: dst = dst - (src + CF). Thus, max = 0xFF...FF if CF is 1, otherwise 0x00...00. TODO Improve comment.
- or result, tmp;
+
+ mov result, x;
+ mul.SIZE r_d:, result, y;
+ setc saturated;
+ sbb max:, max; // SBB performs: dst = dst - (src + CF). Thus, max = 0xFF...FF if CF is 1, otherwise 0x00...00. TODO Improve comment.
+ or result, max;
}
DONE
U_MUL_ASM_8BITS :: #string DONE
#asm {
result === a;
- max: gpr;
-
- mov tmp: gpr, x;
+
mov result, x;
mul.SIZE result, y;
setc saturated;
- sbb max, max; // SBB performs: dst = dst - (src + CF). Thus, max = 0xFF...FF if CF is 1, otherwise 0x00...00. TODO Improve comment.
+ sbb max:, max; // SBB performs: dst = dst - (src + CF). Thus, max = 0xFF...FF if CF is 1, otherwise 0x00...00. TODO Improve comment.
or result, max;
}
DONE