aboutsummaryrefslogtreecommitdiff
path: root/src/library.js
diff options
context:
space:
mode:
Diffstat (limited to 'src/library.js')
-rw-r--r--src/library.js17
1 files changed, 5 insertions, 12 deletions
diff --git a/src/library.js b/src/library.js
index ae0c845c..5bbf4204 100644
--- a/src/library.js
+++ b/src/library.js
@@ -7511,10 +7511,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,
@@ -7524,11 +7521,9 @@ LibraryManager.library = {
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
- }
+ overflow = ((h>>>0) < (b>>>0))>>>0; // Return whether addition overflowed even the high word.
+ h = h + (((l>>>0) < (a>>>0))>>>0)>>>0; // Add carry from low word to high word on overflow.
+ overflow = overflow | (h == 0); // Check again for overflow.
{{{ makeStructuralReturn(['l|0', 'h', 'overflow'], true) }}};
},
@@ -7539,9 +7534,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) }}};
},