From 6ef5c14e4800cb756cb6d0e65f3a54943d9d69cd Mon Sep 17 00:00:00 2001 From: Iain Buclaw Date: Tue, 6 Jul 2021 22:34:13 +0000 Subject: [PATCH] Revert "core.checkedint.addu: Faster (like subu: only one compare-and-branch)." This reverts commit 3ed15ad1b8d76d048b426ed9dacf6378cdf5167f. --- src/core/checkedint.d | 20 +++----------------- 1 file changed, 3 insertions(+), 17 deletions(-) diff --git a/src/core/checkedint.d b/src/core/checkedint.d index b474e141ce..99096fa1c4 100644 --- a/src/core/checkedint.d +++ b/src/core/checkedint.d @@ -168,9 +168,7 @@ pragma(inline, true) uint addu()(uint x, uint y, ref bool overflow) { immutable uint r = x + y; - immutable bool o = r < x; - assert(o == (r < y)); - if (o) + if (r < x || r < y) overflow = true; return r; } @@ -179,14 +177,6 @@ uint addu()(uint x, uint y, ref bool overflow) @betterC unittest { - for (uint i = 0; i < 10; ++i) - { - bool overflow; - immutable uint r = addu (uint.max - i, uint.max - i, overflow); - assert (r == 2 * (uint.max - i)); - assert (overflow); - } - bool overflow; assert(addu(2, 3, overflow) == 5); assert(!overflow); @@ -213,9 +203,7 @@ pragma(inline, true) ulong addu()(ulong x, ulong y, ref bool overflow) { immutable ulong r = x + y; - immutable bool o = r < x; - assert(o == (r < y)); - if (o) + if (r < x || r < y) overflow = true; return r; } @@ -252,9 +240,7 @@ pragma(inline, true) ucent addu()(ucent x, ucent y, ref bool overflow) { immutable ucent r = x + y; - immutable bool o = r < x; - assert(o == (r < y)); - if (o) + if (r < x || r < y) overflow = true; return r; }