Improve performance of CONSP, FIXNUMP, etc.
Optimization opportunity noted by Pip Cet in: https://lists.gnu.org/r/emacs-devel/2018-08/msg00828.html On my platform (Fedora 28 x86-64, AMD Phenom II X4 910e, user+system time), this improved ‘make compile-always’ performance by 0.4% and shrank text size by a similar amount. * src/lisp.h (TAGGEDP, lisp_h_TAGGEDP): New macros and function. (lisp_h_CONSP, lisp_h_FLOATP, lisp_h_SYMBOLP) (lisp_h_VECTORLIKEP, make_lisp_ptr, STRINGP): Use them. (lisp_h_FIXNUMP): Use the same idea that lisp_h_TAGGEDP uses.
This commit is contained in:
parent
161139a42c
commit
ccdb08ef4e
1 changed files with 24 additions and 7 deletions
31
src/lisp.h
31
src/lisp.h
|
@ -362,10 +362,13 @@ typedef EMACS_INT Lisp_Word;
|
|||
#define lisp_h_CHECK_SYMBOL(x) CHECK_TYPE (SYMBOLP (x), Qsymbolp, x)
|
||||
#define lisp_h_CHECK_TYPE(ok, predicate, x) \
|
||||
((ok) ? (void) 0 : wrong_type_argument (predicate, x))
|
||||
#define lisp_h_CONSP(x) (XTYPE (x) == Lisp_Cons)
|
||||
#define lisp_h_CONSP(x) TAGGEDP (x, Lisp_Cons)
|
||||
#define lisp_h_EQ(x, y) (XLI (x) == XLI (y))
|
||||
#define lisp_h_FLOATP(x) (XTYPE (x) == Lisp_Float)
|
||||
#define lisp_h_FIXNUMP(x) ((XTYPE (x) & (Lisp_Int0 | ~Lisp_Int1)) == Lisp_Int0)
|
||||
#define lisp_h_FIXNUMP(x) \
|
||||
(! (((unsigned) (XLI (x) >> (USE_LSB_TAG ? 0 : FIXNUM_BITS)) \
|
||||
- (unsigned) (Lisp_Int0 >> !USE_LSB_TAG)) \
|
||||
& ((1 << INTTYPEBITS) - 1)))
|
||||
#define lisp_h_FLOATP(x) TAGGEDP (x, Lisp_Float)
|
||||
#define lisp_h_NILP(x) EQ (x, Qnil)
|
||||
#define lisp_h_SET_SYMBOL_VAL(sym, v) \
|
||||
(eassert ((sym)->u.s.redirect == SYMBOL_PLAINVAL), \
|
||||
|
@ -375,8 +378,12 @@ typedef EMACS_INT Lisp_Word;
|
|||
#define lisp_h_SYMBOL_TRAPPED_WRITE_P(sym) (XSYMBOL (sym)->u.s.trapped_write)
|
||||
#define lisp_h_SYMBOL_VAL(sym) \
|
||||
(eassert ((sym)->u.s.redirect == SYMBOL_PLAINVAL), (sym)->u.s.val.value)
|
||||
#define lisp_h_SYMBOLP(x) (XTYPE (x) == Lisp_Symbol)
|
||||
#define lisp_h_VECTORLIKEP(x) (XTYPE (x) == Lisp_Vectorlike)
|
||||
#define lisp_h_SYMBOLP(x) TAGGEDP (x, Lisp_Symbol)
|
||||
#define lisp_h_TAGGEDP(a, tag) \
|
||||
(! (((unsigned) (XLI (a) >> (USE_LSB_TAG ? 0 : VALBITS)) \
|
||||
- (unsigned) (tag)) \
|
||||
& ((1 << GCTYPEBITS) - 1)))
|
||||
#define lisp_h_VECTORLIKEP(x) TAGGEDP (x, Lisp_Vectorlike)
|
||||
#define lisp_h_XCAR(c) XCONS (c)->u.s.car
|
||||
#define lisp_h_XCDR(c) XCONS (c)->u.s.u.cdr
|
||||
#define lisp_h_XCONS(a) \
|
||||
|
@ -435,6 +442,7 @@ typedef EMACS_INT Lisp_Word;
|
|||
# define SYMBOL_TRAPPED_WRITE_P(sym) lisp_h_SYMBOL_TRAPPED_WRITE_P (sym)
|
||||
# define SYMBOL_VAL(sym) lisp_h_SYMBOL_VAL (sym)
|
||||
# define SYMBOLP(x) lisp_h_SYMBOLP (x)
|
||||
# define TAGGEDP(a, tag) lisp_h_TAGGEDP (a, tag)
|
||||
# define VECTORLIKEP(x) lisp_h_VECTORLIKEP (x)
|
||||
# define XCAR(c) lisp_h_XCAR (c)
|
||||
# define XCDR(c) lisp_h_XCDR (c)
|
||||
|
@ -647,6 +655,15 @@ INLINE enum Lisp_Type
|
|||
#endif
|
||||
}
|
||||
|
||||
/* True if A has type tag TAG.
|
||||
Equivalent to XTYPE (a) == TAG, but often faster. */
|
||||
|
||||
INLINE bool
|
||||
(TAGGEDP) (Lisp_Object a, enum Lisp_Type tag)
|
||||
{
|
||||
return lisp_h_TAGGEDP (a, tag);
|
||||
}
|
||||
|
||||
INLINE void
|
||||
(CHECK_TYPE) (int ok, Lisp_Object predicate, Lisp_Object x)
|
||||
{
|
||||
|
@ -1131,7 +1148,7 @@ INLINE Lisp_Object
|
|||
make_lisp_ptr (void *ptr, enum Lisp_Type type)
|
||||
{
|
||||
Lisp_Object a = TAG_PTR (type, ptr);
|
||||
eassert (XTYPE (a) == type && XUNTAG (a, type, char) == ptr);
|
||||
eassert (TAGGEDP (a, type) && XUNTAG (a, type, char) == ptr);
|
||||
return a;
|
||||
}
|
||||
|
||||
|
@ -1364,7 +1381,7 @@ verify (alignof (struct Lisp_String) % GCALIGNMENT == 0);
|
|||
INLINE bool
|
||||
STRINGP (Lisp_Object x)
|
||||
{
|
||||
return XTYPE (x) == Lisp_String;
|
||||
return TAGGEDP (x, Lisp_String);
|
||||
}
|
||||
|
||||
INLINE void
|
||||
|
|
Loading…
Add table
Reference in a new issue