aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorJukka Jylänki <jujjyl@gmail.com>2013-04-23 20:24:09 +0300
committerJukka Jylänki <jujjyl@gmail.com>2013-04-23 20:24:09 +0300
commitb43cbd876910598e1ca7aeaa58c8a41f5878a417 (patch)
tree809d81ba588353474b974d4e26cc49f21831fcda /src
parent9a37f4ce7d3a36d106a04f2555f02e2e38e25ac5 (diff)
Remove 'if()' branches from i64 add and subtract code.
Diffstat (limited to 'src')
-rw-r--r--src/library.js17
1 files changed, 4 insertions, 13 deletions
diff --git a/src/library.js b/src/library.js
index 939da8b1..5b58b47f 100644
--- a/src/library.js
+++ b/src/library.js
@@ -7551,10 +7551,7 @@ LibraryManager.library = {
a = a|0; b = b|0; c = c|0; d = d|0;
var l = 0, h = 0;
l = (a + c)>>>0;
- h = (b + d)>>>0;
- if ((l>>>0) < (a>>>0)) { // iff we overflowed
- h = (h+1)>>>0;
- }
+ h = (((b + d)>>>0) + (((l>>>0) < (a>>>0))>>>0))>>>0; // Add carry from low word to high word on overflow.
{{{ makeStructuralReturn(['l|0', 'h'], true) }}};
},
llvm_uadd_with_overflow_i64__asm: true,
@@ -7563,12 +7560,8 @@ LibraryManager.library = {
a = a|0; b = b|0; c = c|0; d = d|0;
var l = 0, h = 0, overflow = 0;
l = (a + c)>>>0;
- h = (b + d)>>>0;
- if ((h>>>0) < (b>>>0)) overflow = 1;
- if ((l>>>0) < (a>>>0)) {
- h = (h+1)>>>0;
- if ((h>>>0) == 0) overflow = 1; // two possibilities to overflow here
- }
+ h = (((b + d)>>>0) + (((l>>>0) < (a>>>0))>>>0))>>>0; // Add carry from low word to high word on overflow.
+ overflow = (((h>>>0) < (b>>>0))>>>0); // Return whether addition overflowed even the high word.
{{{ makeStructuralReturn(['l|0', 'h', 'overflow'], true) }}};
},
@@ -7579,9 +7572,7 @@ LibraryManager.library = {
var l = 0, h = 0;
l = (a - c)>>>0;
h = (b - d)>>>0;
- if ((l>>>0) > (a>>>0)) { // iff we overflowed
- h = (h-1)>>>0;
- }
+ h = (((b - d)>>>0) - (((c>>>0) > (a>>>0))>>>0))>>>0; // Borrow one from high word to low word on underflow.
{{{ makeStructuralReturn(['l|0', 'h'], true) }}};
},