File 0965-emulator-Document-the-futility-of-aligning-opcode-la.patch of Package erlang

From 013eaf3ea872048db1ffa5da5c6dcfba07b4141b Mon Sep 17 00:00:00 2001
From: Frej Drejhammar <frej.drejhammar@gmail.com>
Date: Fri, 28 Aug 2020 10:15:45 +0200
Subject: [PATCH] emulator: Document the futility of aligning opcode labels

The x86 and AMD64 optimization guides recommend that branch targets
are paragraph aligned (16 bytes). Neither GCC nor Clang align the
addresses of first class labels as used by the OpCase construction
when the jump table is enabled. Aligning the OpCase labels looks like
a worthwhile optimization, but despite the recommendation in the
optimization guides, forcing alignment leads to a ~5% slowdown of the
emulator. Therefore alignment of OpCase labels are not attempted.

As at least two OTP developers have independently attempted this
optimization and measured the same slowdown, this patch adds a comment
documenting this fact. The comment is placed where the OpCase macro is
defined, as a person trying to implement alignment will likely look
there.
---
 erts/emulator/beam/beam_emu.c | 9 +++++++++
 1 file changed, 9 insertions(+)

diff --git a/erts/emulator/beam/beam_emu.c b/erts/emulator/beam/beam_emu.c
index 2ed144b9b6..b6b19b686b 100644
--- a/erts/emulator/beam/beam_emu.c
+++ b/erts/emulator/beam/beam_emu.c
@@ -48,6 +48,15 @@
 
 /* #define HARDDEBUG 1 */
 
+/* The x86 and AMD64 optimization guides recommend that branch targets are
+ * paragraph aligned (16 bytes). Neither GCC nor Clang align the addresses of
+ * first class labels as used by the OpCase construction when the jump table is
+ * enabled. Aligning the OpCase labels looks like a worthwhile optimization, but
+ * despite the recommendation in the optimization guides, forcing alignment
+ * leads to a ~5% slowdown of the emulator. Therefore alignment of OpCase labels
+ * are not attempted.
+ */
+
 #if defined(NO_JUMP_TABLE)
 #  define OpCase(OpCode)    case op_##OpCode
 #  define CountCase(OpCode) case op_count_##OpCode
-- 
2.26.2

openSUSE Build Service is sponsored by