File 2761-erts-Make-NIL-positive.patch of Package erlang

From 8b8c7a63030360436f2ee6d6390d120199260823 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?John=20H=C3=B6gberg?= <john@erlang.org>
Date: Tue, 10 Nov 2020 15:05:23 +0100
Subject: [PATCH] erts: Make NIL positive

This makes generated x86 code more compact as we don't need to
sign-extend it everywhere.

Before:
    ; 48 c7 c0 fb ff ff ff
    mov rax, 0xfffffffffffffffb

After:
    ; b8 3b 00 00 00
    mov eax, 0x3b
---
 erts/emulator/beam/erl_term.h | 2 +-
 erts/etc/unix/etp-commands.in | 3 +--
 2 files changed, 2 insertions(+), 3 deletions(-)

diff --git a/erts/emulator/beam/erl_term.h b/erts/emulator/beam/erl_term.h
index eb41f1515a..14e0355a6b 100644
--- a/erts/emulator/beam/erl_term.h
+++ b/erts/emulator/beam/erl_term.h
@@ -283,7 +283,7 @@ _ET_DECLARE_CHECKED(Sint,signed_val,Eterm)
 #endif
 
 /* NIL access methods */
-#define NIL		((~((Uint) 0) << _TAG_IMMED2_SIZE) | _TAG_IMMED2_NIL)
+#define NIL		_TAG_IMMED2_NIL
 #define is_nil(x)	((x) == NIL)
 #define is_not_nil(x)	((x) != NIL)
 
diff --git a/erts/etc/unix/etp-commands.in b/erts/etc/unix/etp-commands.in
index 21eae00e27..d9c8eb278a 100644
--- a/erts/etc/unix/etp-commands.in
+++ b/erts/etc/unix/etp-commands.in
@@ -4712,12 +4712,11 @@ end
 define etp-init
   set $etp_arch64 = (sizeof(void *) == 8)
   if $etp_arch64
-    set $etp_nil = 0xfffffffffffffffb
     set $etp_MBC_ABLK_OFFSET_BITS = 23
   else
-    set $etp_nil = 0xfffffffb
     set $etp_MBC_ABLK_OFFSET_BITS = 8
   end
+  set $etp_nil = 0x3b
   set $etp_MBC_ABLK_OFFSET_SHIFT = (sizeof(UWord)*8 - 1 - $etp_MBC_ABLK_OFFSET_BITS)
   set $etp_MBC_ABLK_OFFSET_MASK = ((((UWord)1 << $etp_MBC_ABLK_OFFSET_BITS) - 1) << $etp_MBC_ABLK_OFFSET_SHIFT)
   set $etp_MBC_ABLK_SZ_MASK = ((UWord)1 << $etp_MBC_ABLK_OFFSET_SHIFT) - 1 - 7
-- 
2.26.2

openSUSE Build Service is sponsored by