File 2472-Optimize-multiplication-in-binary-matching-instructi.patch of Package erlang

From 9e18956fcb279d33ae00d82db7382b81bad7dcc2 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Bj=C3=B6rn=20Gustavsson?= <bjorn@erlang.org>
Date: Tue, 5 Mar 2019 10:20:33 +0100
Subject: [PATCH 12/15] Optimize multiplication in binary matching instructions

---
 erts/emulator/beam/bs_instrs.tab | 9 ++++++++-
 1 file changed, 8 insertions(+), 1 deletion(-)

diff --git a/erts/emulator/beam/bs_instrs.tab b/erts/emulator/beam/bs_instrs.tab
index 10f43cd786..493ec10222 100644
--- a/erts/emulator/beam/bs_instrs.tab
+++ b/erts/emulator/beam/bs_instrs.tab
@@ -23,10 +23,17 @@
 BS_SAFE_MUL(A, B, Fail, Dst) {
     Uint a = $A;
     Uint b = $B;
-    Uint res = a * b;
+    Uint res;
+#ifdef HAVE_OVERFLOW_CHECK_BUILTINS
+    if (__builtin_mul_overflow(a, b, &res)) {
+        $Fail;
+    }
+#else
+    res = a * b;
     if (res / b != a) {
         $Fail;
     }
+#endif
     $Dst = res;
 }
 
-- 
2.16.4

openSUSE Build Service is sponsored by