From 98a34454a4556130b4c24bf768a1ef5e718c6ec5 Mon Sep 17 00:00:00 2001 From: Stefan Monnier Date: Tue, 23 Jan 2024 23:35:22 -0800 Subject: [PATCH] Remove too-tricky make_lisp_symbol optimization MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit Simplify optimization for make_lisp_symbol, so that it’s less tricky and works well enough for gcc -Og or -O2. * src/lisp.h (lisp_h_builtin_lisp_symbol): Remove. (builtin_lisp_symbol) [DEFINE_KEY_OPS_AS_MACROS]: Remove. (make_lisp_symbol_nodebug): New internal static function, which is like the old make_lisp_symbol but without the eassert. (make_lisp_symbol, builtin_lisp_symbol): Use it, so that make_lisp_symbol has the eassert but builtin_lisp_symbol doesn’t. Co-authored-by: Paul Eggert (cherry picked from commit 802821b81ac5ad0dee7f26caa519326251b262c1) --- src/lisp.h | 24 ++++++++++++++---------- 1 file changed, 14 insertions(+), 10 deletions(-) diff --git a/src/lisp.h b/src/lisp.h index 54d2f4d3dd1..09fcd6689bf 100644 --- a/src/lisp.h +++ b/src/lisp.h @@ -409,10 +409,6 @@ typedef EMACS_INT Lisp_Word; & ((1 << INTTYPEBITS) - 1))) #define lisp_h_FLOATP(x) TAGGEDP (x, Lisp_Float) #define lisp_h_NILP(x) BASE_EQ (x, Qnil) -/* Equivalent to "make_lisp_symbol (&lispsym[INDEX])", - and typically faster when compiling without optimization. */ -#define lisp_h_builtin_lisp_symbol(index) \ - TAG_PTR (Lisp_Symbol, (index) * sizeof *lispsym) #define lisp_h_SET_SYMBOL_VAL(sym, v) \ (eassert ((sym)->u.s.redirect == SYMBOL_PLAINVAL), \ (sym)->u.s.val.value = (v)) @@ -479,7 +475,6 @@ typedef EMACS_INT Lisp_Word; # define FLOATP(x) lisp_h_FLOATP (x) # define FIXNUMP(x) lisp_h_FIXNUMP (x) # define NILP(x) lisp_h_NILP (x) -# define builtin_lisp_symbol(index) lisp_h_builtin_lisp_symbol (index) # define SET_SYMBOL_VAL(sym, v) lisp_h_SET_SYMBOL_VAL (sym, v) # define SYMBOL_CONSTANT_P(sym) lisp_h_SYMBOL_CONSTANT_P (sym) # define SYMBOL_TRAPPED_WRITE_P(sym) lisp_h_SYMBOL_TRAPPED_WRITE_P (sym) @@ -1169,21 +1164,30 @@ XSYMBOL (Lisp_Object a) return XBARE_SYMBOL (a); } +/* Internal use only. */ INLINE Lisp_Object -make_lisp_symbol (struct Lisp_Symbol *sym) +make_lisp_symbol_internal (struct Lisp_Symbol *sym) { /* GCC 7 x86-64 generates faster code if lispsym is - cast to char * rather than to intptr_t. */ + cast to char * rather than to intptr_t. + Do not use eassert here, so that builtin symbols like Qnil compile to + constants; this is needed for some circa-2024 GCCs even with -O2. */ char *symoffset = (char *) ((char *) sym - (char *) lispsym); - Lisp_Object a = TAG_PTR (Lisp_Symbol, symoffset); + return TAG_PTR (Lisp_Symbol, symoffset); +} + +INLINE Lisp_Object +make_lisp_symbol (struct Lisp_Symbol *sym) +{ + Lisp_Object a = make_lisp_symbol_internal (sym); eassert (XBARE_SYMBOL (a) == sym); return a; } INLINE Lisp_Object -(builtin_lisp_symbol) (int index) +builtin_lisp_symbol (int index) { - return lisp_h_builtin_lisp_symbol (index); + return make_lisp_symbol_internal (&lispsym[index]); } INLINE bool -- 2.39.5