File 3372-Attempt-to-address-Big-Endian-system.patch of Package erlang

From 8b9d974cbf7ed370e6885fff7ea985273a438e91 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Jos=C3=A9=20Valim?= <jose.valim@dashbit.co>
Date: Thu, 11 Feb 2021 15:21:59 +0100
Subject: [PATCH 2/2] Attempt to address Big Endian system

---
 erts/emulator/beam/erl_bits.c             | 44 +++++++++++++----------
 erts/emulator/test/bs_construct_SUITE.erl | 24 ++++++-------
 2 files changed, 38 insertions(+), 30 deletions(-)

diff --git a/erts/emulator/beam/erl_bits.c b/erts/emulator/beam/erl_bits.c
index d6eaf508d3..2990f4e775 100644
--- a/erts/emulator/beam/erl_bits.c
+++ b/erts/emulator/beam/erl_bits.c
@@ -1176,17 +1176,21 @@ erts_new_bs_put_float(Process *c_p, Eterm arg, Uint num_bits, int flags)
 	if (BIT_IS_MACHINE_ENDIAN(flags)) {
 	    byte* t = erts_current_bin+BYTE_OFFSET(erts_bin_offset);
 #ifdef WORDS_BIGENDIAN
-	    t[0] = a >> 24;
-	    t[1] = a >> 16;
-	    if (num_bits >= 32) {
+	    if (num_bits == 16) {
+		t[0] = a >> 8;
+		t[1] = a;
+	    } else if (num_bits >= 32) {
+		t[0] = a >> 24;
+		t[1] = a >> 16;
 		t[2] = a >> 8;
 		t[3] = a;
-	    }
-	    if (num_bits == 64) {
-		t[4] = b >> 24;
-		t[5] = b >> 16;
-		t[6] = b >> 8;
-		t[7] = b;
+
+		if (num_bits == 64) {
+		    t[4] = b >> 24;
+		    t[5] = b >> 16;
+		    t[6] = b >> 8;
+		    t[7] = b;
+		}
 	    }
 #else
 	    if (num_bits >= 32) {
@@ -1205,17 +1209,21 @@ erts_new_bs_put_float(Process *c_p, Eterm arg, Uint num_bits, int flags)
 	} else {
 	    byte* t = erts_current_bin+BYTE_OFFSET(erts_bin_offset) + NBYTES(num_bits);
 #ifdef WORDS_BIGENDIAN
-	    t[-1] = a >> 24;
-	    t[-2] = a >> 16;
-	    if (num_bits >= 32) {
+	    if (num_bits == 16) {
+		t[-1] = a >> 8;
+		t[-2] = a;
+	    } else if (num_bits >= 32) {
+		t[-1] = a >> 24;
+		t[-2] = a >> 16;
 	        t[-3] = a >> 8;
 	        t[-4] = a;
-	    }
-	    if (num_bits == 64) {
-		t[-5] = b >> 24;
-		t[-6] = b >> 16;
-		t[-7] = b >> 8;
-		t[-8] = b;
+
+		if (num_bits == 64) {
+		    t[-5] = b >> 24;
+		    t[-6] = b >> 16;
+		    t[-7] = b >> 8;
+		    t[-8] = b;
+		}
 	    }
 #else
 	    t[-1] = a;
diff --git a/erts/emulator/test/bs_construct_SUITE.erl b/erts/emulator/test/bs_construct_SUITE.erl
index 288d878d44..81107c5644 100644
--- a/erts/emulator/test/bs_construct_SUITE.erl
+++ b/erts/emulator/test/bs_construct_SUITE.erl
@@ -945,19 +945,19 @@ memsize() ->
 
 -define(FP16(EncodedInt, Float),
         (fun(NlInt, NlFloat) ->
-                 true = <<NlInt:16>> =:= <<NlFloat:16/float>>,
-                 true = <<(NlInt+16#8000):16>> =:= <<-NlFloat:16/float>>,
-                 true = <<NlInt:16/little>> =:= <<NlFloat:16/float-little>>,
-                 true = <<(NlInt+16#8000):16/little>> =:= <<-NlFloat:16/float-little>>,
-                 true = <<NlInt:16/native>> =:= <<NlFloat:16/float-native>>,
-                 true = <<(NlInt+16#8000):16/native>> =:= <<-NlFloat:16/float-native>>
+                 {0, true} = {0, <<NlInt:16>> =:= <<NlFloat:16/float>>},
+                 {1, true} = {1, <<(NlInt+16#8000):16>> =:= <<-NlFloat:16/float>>},
+                 {2, true} = {2, <<NlInt:16/little>> =:= <<NlFloat:16/float-little>>},
+                 {3, true} = {3, <<(NlInt+16#8000):16/little>> =:= <<-NlFloat:16/float-little>>},
+                 {4, true} = {4, <<NlInt:16/native>> =:= <<NlFloat:16/float-native>>},
+                 {5, true} = {5, <<(NlInt+16#8000):16/native>> =:= <<-NlFloat:16/float-native>>}
          end)(nonliteral(EncodedInt), nonliteral(Float)),
-        true = <<EncodedInt:16>> =:= <<Float:16/float>>,
-        true = <<(EncodedInt+16#8000):16>> =:= <<-Float:16/float>>,
-        true = <<EncodedInt:16/little>> =:= <<Float:16/float-little>>,
-        true = <<(EncodedInt+16#8000):16/little>> =:= <<-Float:16/float-little>>,
-        true = <<EncodedInt:16/native>> =:= <<Float:16/float-native>>,
-        true = <<(EncodedInt+16#8000):16/native>> =:= <<-Float:16/float-native>>).
+        {a, true} = {a, <<EncodedInt:16>> =:= <<Float:16/float>>},
+        {b, true} = {b, <<(EncodedInt+16#8000):16>> =:= <<-Float:16/float>>},
+        {c, true} = {c, <<EncodedInt:16/little>> =:= <<Float:16/float-little>>},
+        {d, true} = {d, <<(EncodedInt+16#8000):16/little>> =:= <<-Float:16/float-little>>},
+        {e, true} = {e, <<EncodedInt:16/native>> =:= <<Float:16/float-native>>},
+        {f, true} = {f, <<(EncodedInt+16#8000):16/native>> =:= <<-Float:16/float-native>>}).
 
 fp16(_Config) ->
     %% smallest positive subnormal number
-- 
2.26.2

openSUSE Build Service is sponsored by