]> code.delx.au - gnu-emacs/commitdiff
Fix performance regression with gcc -O0
authorPaul Eggert <eggert@cs.ucla.edu>
Sun, 13 Dec 2015 03:27:51 +0000 (19:27 -0800)
committerPaul Eggert <eggert@cs.ucla.edu>
Sun, 13 Dec 2015 03:28:53 +0000 (19:28 -0800)
This fixes the smaller performance hit that I noted in:
https://lists.gnu.org/archive/html/emacs-devel/2015-12/msg00357.html
* src/alloc.c (macro_XPNTR_OR_SYMBOL_OFFSET, macro_XPNTR):
* src/puresize.h (puresize_h_PURE_P)
(puresize_h_CHECK_IMPURE):
New macros, with the old contents of the functions.
* src/alloc.c (XPNTR_OR_SYMBOL_OFFSET, XPNTR):
* src/puresize.h (PURE_P, CHECK_IMPURE):
Use the new macros.  Also macros, if DEFINE_KEY_OPS_AS_MACROS.
* src/conf_post.h (ATTRIBUTE_UNUSED):
* src/lisp.h (DEFINE_KEY_OPS_AS_MACROS): New macros.

src/alloc.c
src/conf_post.h
src/lisp.h
src/puresize.h

index ea44c51d162ef31c1713a3b614636e3dc567f9e8..23ddd83d7d655223812b6df6cebd946cb19f4a20 100644 (file)
@@ -406,24 +406,37 @@ ALIGN (void *ptr, int alignment)
    If A is a symbol, extract the hidden pointer's offset from lispsym,
    converted to void *.  */
 
-static void *
-XPNTR_OR_SYMBOL_OFFSET (Lisp_Object a)
-{
-  intptr_t i = USE_LSB_TAG ? XLI (a) - XTYPE (a) : XLI (a) & VALMASK;
-  return (void *) i;
-}
+#define macro_XPNTR_OR_SYMBOL_OFFSET(a) \
+  ((void *) (intptr_t) (USE_LSB_TAG ? XLI (a) - XTYPE (a) : XLI (a) & VALMASK))
 
 /* Extract the pointer hidden within A.  */
 
-static void *
+#define macro_XPNTR(a) \
+  ((void *) ((intptr_t) XPNTR_OR_SYMBOL_OFFSET (a) \
+            + (SYMBOLP (a) ? (char *) lispsym : NULL)))
+
+/* For pointer access, define XPNTR and XPNTR_OR_SYMBOL_OFFSET as
+   functions, as functions are cleaner and can be used in debuggers.
+   Also, define them as macros if being compiled with GCC without
+   optimization, for performance in that case.  The macro_* names are
+   private to this section of code.  */
+
+static ATTRIBUTE_UNUSED void *
+XPNTR_OR_SYMBOL_OFFSET (Lisp_Object a)
+{
+  return macro_XPNTR_OR_SYMBOL_OFFSET (a);
+}
+static ATTRIBUTE_UNUSED void *
 XPNTR (Lisp_Object a)
 {
-  void *p = XPNTR_OR_SYMBOL_OFFSET (a);
-  if (SYMBOLP (a))
-    p = (intptr_t) p + (char *) lispsym;
-  return p;
+  return macro_XPNTR (a);
 }
 
+#if DEFINE_KEY_OPS_AS_MACROS
+# define XPNTR_OR_SYMBOL_OFFSET(a) macro_XPNTR_OR_SYMBOL_OFFSET (a)
+# define XPNTR(a) macro_XPNTR (a)
+#endif
+
 static void
 XFLOAT_INIT (Lisp_Object f, double n)
 {
index 2c3eee59b772be5d754dc6891487e89f12f1eb04..b629e8d3df7dcb513bd067acbc1f87c56bb09b3d 100644 (file)
@@ -245,6 +245,7 @@ extern int emacs_setenv_TZ (char const *);
 #endif
 
 #define ATTRIBUTE_CONST _GL_ATTRIBUTE_CONST
+#define ATTRIBUTE_UNUSED _GL_UNUSED
 
 #if 3 <= __GNUC__
 # define ATTRIBUTE_MALLOC __attribute__ ((__malloc__))
index ee9b7b62bf41a8cd98b9e80d66b2ce8b8b182cab..995760a50198a07339916b711a9e1b31e2134aea 100644 (file)
@@ -369,6 +369,12 @@ error !;
 #if (defined __NO_INLINE__ \
      && ! defined __OPTIMIZE__ && ! defined __OPTIMIZE_SIZE__ \
      && ! (defined INLINING && ! INLINING))
+# define DEFINE_KEY_OPS_AS_MACROS true
+#else
+# define DEFINE_KEY_OPS_AS_MACROS false
+#endif
+
+#if DEFINE_KEY_OPS_AS_MACROS
 # define XLI(o) lisp_h_XLI (o)
 # define XIL(i) lisp_h_XIL (i)
 # define CHECK_LIST_CONS(x, y) lisp_h_CHECK_LIST_CONS (x, y)
index f07562429d53d831b3626b36ef4eeb2e64029f28..96ddcde24a6652c532f25d22581c353b59e07196 100644 (file)
@@ -81,21 +81,35 @@ extern _Noreturn void pure_write_error (Lisp_Object);
 
 extern EMACS_INT pure[];
 
+/* The puresize_h_* macros are private to this include file.  */
+
 /* True if PTR is pure.  */
+
+#define puresize_h_PURE_P(ptr) \
+  ((uintptr_t) (ptr) - (uintptr_t) pure <= PURESIZE)
+
 INLINE bool
 PURE_P (void *ptr)
 {
-  return (uintptr_t) (ptr) - (uintptr_t) pure <= PURESIZE;
+  return puresize_h_PURE_P (ptr);
 }
 
 /* Signal an error if OBJ is pure.  PTR is OBJ untagged.  */
+
+#define puresize_h_CHECK_IMPURE(obj, ptr) \
+  (PURE_P (ptr) ? pure_write_error (obj) : (void) 0)
+
 INLINE void
 CHECK_IMPURE (Lisp_Object obj, void *ptr)
 {
-  if (PURE_P (ptr))
-    pure_write_error (obj);
+  puresize_h_CHECK_IMPURE (obj, ptr);
 }
 
+#if DEFINE_KEY_OPS_AS_MACROS
+# define PURE_P(ptr) puresize_h_PURE_P (ptr)
+# define CHECK_IMPURE(obj, ptr) puresize_h_CHECK_IMPURE (obj, ptr)
+#endif
+
 INLINE_HEADER_END
 
 #endif /* EMACS_PURESIZE_H */