File 1105-Optimize-helper-macro-used-for-bignum-arithmetic.patch of Package erlang

From 8cab1c60f52ca9377899abbfeda0be83525df1b2 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Bj=C3=B6rn=20Gustavsson?= <bjorn@erlang.org>
Date: Sun, 6 Aug 2023 10:12:20 +0200
Subject: [PATCH 5/7] Optimize helper macro used for bignum arithmetic

---
 erts/emulator/beam/big.c | 41 ++++++++++++++++++++++------------------
 1 file changed, 23 insertions(+), 18 deletions(-)

diff --git a/erts/emulator/beam/big.c b/erts/emulator/beam/big.c
index e41444979e..102ebd46dc 100644
--- a/erts/emulator/beam/big.c
+++ b/erts/emulator/beam/big.c
@@ -52,18 +52,6 @@
         }							\
     } while(0)
 
-/* add a and b with carry in + out */
-#define DSUMc(a,b,c,s) do {						\
-	ErtsDigit ___cr = (c);						\
-	ErtsDigit ___xr = (a)+(___cr);					\
-	ErtsDigit ___yr = (b);						\
-	___cr = (___xr < ___cr);					\
-	___xr = ___yr + ___xr;						\
-	___cr += (___xr < ___yr);					\
-	s = ___xr;							\
-	c = ___cr;							\
-    }  while(0)
-
 /* add a and b with carry out */
 #define DSUM(a,b,c,s) do {					\
 	ErtsDigit ___xr = (a);					\
@@ -136,6 +124,13 @@
 	r = _t % (b);					\
     } while(0)
 
+/* add a and b with carry in + out */
+#define DSUMc(a,b,c,s) do {                                     \
+        ErtsDoubleDigit _t = (ErtsDoubleDigit)(a) + (b) + (c);  \
+        s = DLOW(_t);                                           \
+        c = DHIGH(_t);                                          \
+    }  while(0)
+
 #else
 
 /* If we do not have double digit then we have some more work to do */
@@ -422,6 +417,18 @@
 	D2DIVREM(a1,a0,b1,b0,q,_tmp_r1,_tmp_r0); \
     } while(0)
 
+/* add a and b with carry in + out */
+#define DSUMc(a,b,c,s) do {                     \
+        ErtsDigit ___cr = (c);                  \
+        ErtsDigit ___xr = (a)+(___cr);          \
+        ErtsDigit ___yr = (b);                  \
+        ___cr = (___xr < ___cr);                \
+        ___xr = ___yr + ___xr;                  \
+        ___cr += (___xr < ___yr);               \
+        s = ___xr;                              \
+        c = ___cr;                              \
+    } while(0)
+
 #endif
 
 /* Forward declaration of lookup tables (See below in this file) used in list to
@@ -487,12 +494,10 @@ static dsize_t I_add(ErtsDigit* x, dsize_t xl, ErtsDigit* y, dsize_t yl, ErtsDig
 
     xl -= yl;
     do {
-	xr = *x++ + c;
-	yr = *y++;
-	c = (xr < c);
-	xr = yr + xr;
-	c += (xr < yr);
-	*r++ = xr;
+        xr = *x++;
+        yr = *y++;
+        DSUMc(xr, yr, c, xr);
+        *r++ = xr;
     } while(--yl);
 
     while(xl--) {
-- 
2.35.3

openSUSE Build Service is sponsored by