]> git.eshelyaron.com Git - emacs.git/commitdiff
Remove too-tricky make_lisp_symbol optimization
authorStefan Monnier <monnier@iro.umontreal.ca>
Wed, 24 Jan 2024 07:35:22 +0000 (23:35 -0800)
committerEshel Yaron <me@eshelyaron.com>
Wed, 24 Jan 2024 18:31:53 +0000 (19:31 +0100)
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 <eggert@cs.ucla.edu>
(cherry picked from commit 802821b81ac5ad0dee7f26caa519326251b262c1)

src/lisp.h

index 54d2f4d3dd1690134a4d0926acd21aad593a9ce7..09fcd6689bfc0d2e0c54789572b4cc8b99402ff2 100644 (file)
@@ -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