]> git.eshelyaron.com Git - emacs.git/commitdiff
Faster bytecode immediate argument fetching
authorMattias Engdegård <mattiase@acm.org>
Thu, 3 Mar 2022 12:57:26 +0000 (13:57 +0100)
committerMattias Engdegård <mattiase@acm.org>
Sat, 12 Mar 2022 16:32:31 +0000 (17:32 +0100)
* src/bytecode.c (FETCH2):
Use `|` instead of `+` to combine the bytes forming a 16-bit immediate
argument so that GCC (prior to version 12) recognises the idiom and
generates a 16-bit load.  This applies for little-endian machines with
cheap unaligned accesses such as x86[-64], arm64 and power64le.

This 1-character change results in a measurable speed gain on many
kinds of Lisp code, as 16-bit immediates are used by all jump
instructions.

Clang performs this optimisation for both `+` and `|` from version 10.

src/bytecode.c

index 96f1f90581291dabce223205abeacfb9914995ea..c5cc6590121d1f5a296ca6a15fcd504e6c4cf1ca 100644 (file)
@@ -291,7 +291,7 @@ enum byte_code_op
 /* Fetch two bytes from the bytecode stream and make a 16-bit number
    out of them.  */
 
-#define FETCH2 (op = FETCH, op + (FETCH << 8))
+#define FETCH2 (op = FETCH, op | (FETCH << 8))
 
 /* Push X onto the execution stack.  The expression X should not
    contain TOP, to avoid competing side effects.  */