diff options
| author | Paul Eggert | 2018-08-25 13:39:18 -0700 |
|---|---|---|
| committer | Paul Eggert | 2018-08-25 14:17:30 -0700 |
| commit | ccdb08ef4ed8f96e79aa06cf5e806c9c487d58ad (patch) | |
| tree | 6f8da0d69742307dc7bf8a6c59a7544b389203a0 /src | |
| parent | 161139a42c02cce051c51fb80c6ae00c9e6beaa6 (diff) | |
| download | emacs-ccdb08ef4ed8f96e79aa06cf5e806c9c487d58ad.tar.gz emacs-ccdb08ef4ed8f96e79aa06cf5e806c9c487d58ad.zip | |
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.
Diffstat (limited to 'src')
| -rw-r--r-- | src/lisp.h | 31 |
1 files changed, 24 insertions, 7 deletions
diff --git a/src/lisp.h b/src/lisp.h index bca4dfbb603..fb11a11fda3 100644 --- a/src/lisp.h +++ b/src/lisp.h | |||
| @@ -362,10 +362,13 @@ typedef EMACS_INT Lisp_Word; | |||
| 362 | #define lisp_h_CHECK_SYMBOL(x) CHECK_TYPE (SYMBOLP (x), Qsymbolp, x) | 362 | #define lisp_h_CHECK_SYMBOL(x) CHECK_TYPE (SYMBOLP (x), Qsymbolp, x) |
| 363 | #define lisp_h_CHECK_TYPE(ok, predicate, x) \ | 363 | #define lisp_h_CHECK_TYPE(ok, predicate, x) \ |
| 364 | ((ok) ? (void) 0 : wrong_type_argument (predicate, x)) | 364 | ((ok) ? (void) 0 : wrong_type_argument (predicate, x)) |
| 365 | #define lisp_h_CONSP(x) (XTYPE (x) == Lisp_Cons) | 365 | #define lisp_h_CONSP(x) TAGGEDP (x, Lisp_Cons) |
| 366 | #define lisp_h_EQ(x, y) (XLI (x) == XLI (y)) | 366 | #define lisp_h_EQ(x, y) (XLI (x) == XLI (y)) |
| 367 | #define lisp_h_FLOATP(x) (XTYPE (x) == Lisp_Float) | 367 | #define lisp_h_FIXNUMP(x) \ |
| 368 | #define lisp_h_FIXNUMP(x) ((XTYPE (x) & (Lisp_Int0 | ~Lisp_Int1)) == Lisp_Int0) | 368 | (! (((unsigned) (XLI (x) >> (USE_LSB_TAG ? 0 : FIXNUM_BITS)) \ |
| 369 | - (unsigned) (Lisp_Int0 >> !USE_LSB_TAG)) \ | ||
| 370 | & ((1 << INTTYPEBITS) - 1))) | ||
| 371 | #define lisp_h_FLOATP(x) TAGGEDP (x, Lisp_Float) | ||
| 369 | #define lisp_h_NILP(x) EQ (x, Qnil) | 372 | #define lisp_h_NILP(x) EQ (x, Qnil) |
| 370 | #define lisp_h_SET_SYMBOL_VAL(sym, v) \ | 373 | #define lisp_h_SET_SYMBOL_VAL(sym, v) \ |
| 371 | (eassert ((sym)->u.s.redirect == SYMBOL_PLAINVAL), \ | 374 | (eassert ((sym)->u.s.redirect == SYMBOL_PLAINVAL), \ |
| @@ -375,8 +378,12 @@ typedef EMACS_INT Lisp_Word; | |||
| 375 | #define lisp_h_SYMBOL_TRAPPED_WRITE_P(sym) (XSYMBOL (sym)->u.s.trapped_write) | 378 | #define lisp_h_SYMBOL_TRAPPED_WRITE_P(sym) (XSYMBOL (sym)->u.s.trapped_write) |
| 376 | #define lisp_h_SYMBOL_VAL(sym) \ | 379 | #define lisp_h_SYMBOL_VAL(sym) \ |
| 377 | (eassert ((sym)->u.s.redirect == SYMBOL_PLAINVAL), (sym)->u.s.val.value) | 380 | (eassert ((sym)->u.s.redirect == SYMBOL_PLAINVAL), (sym)->u.s.val.value) |
| 378 | #define lisp_h_SYMBOLP(x) (XTYPE (x) == Lisp_Symbol) | 381 | #define lisp_h_SYMBOLP(x) TAGGEDP (x, Lisp_Symbol) |
| 379 | #define lisp_h_VECTORLIKEP(x) (XTYPE (x) == Lisp_Vectorlike) | 382 | #define lisp_h_TAGGEDP(a, tag) \ |
| 383 | (! (((unsigned) (XLI (a) >> (USE_LSB_TAG ? 0 : VALBITS)) \ | ||
| 384 | - (unsigned) (tag)) \ | ||
| 385 | & ((1 << GCTYPEBITS) - 1))) | ||
| 386 | #define lisp_h_VECTORLIKEP(x) TAGGEDP (x, Lisp_Vectorlike) | ||
| 380 | #define lisp_h_XCAR(c) XCONS (c)->u.s.car | 387 | #define lisp_h_XCAR(c) XCONS (c)->u.s.car |
| 381 | #define lisp_h_XCDR(c) XCONS (c)->u.s.u.cdr | 388 | #define lisp_h_XCDR(c) XCONS (c)->u.s.u.cdr |
| 382 | #define lisp_h_XCONS(a) \ | 389 | #define lisp_h_XCONS(a) \ |
| @@ -435,6 +442,7 @@ typedef EMACS_INT Lisp_Word; | |||
| 435 | # define SYMBOL_TRAPPED_WRITE_P(sym) lisp_h_SYMBOL_TRAPPED_WRITE_P (sym) | 442 | # define SYMBOL_TRAPPED_WRITE_P(sym) lisp_h_SYMBOL_TRAPPED_WRITE_P (sym) |
| 436 | # define SYMBOL_VAL(sym) lisp_h_SYMBOL_VAL (sym) | 443 | # define SYMBOL_VAL(sym) lisp_h_SYMBOL_VAL (sym) |
| 437 | # define SYMBOLP(x) lisp_h_SYMBOLP (x) | 444 | # define SYMBOLP(x) lisp_h_SYMBOLP (x) |
| 445 | # define TAGGEDP(a, tag) lisp_h_TAGGEDP (a, tag) | ||
| 438 | # define VECTORLIKEP(x) lisp_h_VECTORLIKEP (x) | 446 | # define VECTORLIKEP(x) lisp_h_VECTORLIKEP (x) |
| 439 | # define XCAR(c) lisp_h_XCAR (c) | 447 | # define XCAR(c) lisp_h_XCAR (c) |
| 440 | # define XCDR(c) lisp_h_XCDR (c) | 448 | # define XCDR(c) lisp_h_XCDR (c) |
| @@ -647,6 +655,15 @@ INLINE enum Lisp_Type | |||
| 647 | #endif | 655 | #endif |
| 648 | } | 656 | } |
| 649 | 657 | ||
| 658 | /* True if A has type tag TAG. | ||
| 659 | Equivalent to XTYPE (a) == TAG, but often faster. */ | ||
| 660 | |||
| 661 | INLINE bool | ||
| 662 | (TAGGEDP) (Lisp_Object a, enum Lisp_Type tag) | ||
| 663 | { | ||
| 664 | return lisp_h_TAGGEDP (a, tag); | ||
| 665 | } | ||
| 666 | |||
| 650 | INLINE void | 667 | INLINE void |
| 651 | (CHECK_TYPE) (int ok, Lisp_Object predicate, Lisp_Object x) | 668 | (CHECK_TYPE) (int ok, Lisp_Object predicate, Lisp_Object x) |
| 652 | { | 669 | { |
| @@ -1131,7 +1148,7 @@ INLINE Lisp_Object | |||
| 1131 | make_lisp_ptr (void *ptr, enum Lisp_Type type) | 1148 | make_lisp_ptr (void *ptr, enum Lisp_Type type) |
| 1132 | { | 1149 | { |
| 1133 | Lisp_Object a = TAG_PTR (type, ptr); | 1150 | Lisp_Object a = TAG_PTR (type, ptr); |
| 1134 | eassert (XTYPE (a) == type && XUNTAG (a, type, char) == ptr); | 1151 | eassert (TAGGEDP (a, type) && XUNTAG (a, type, char) == ptr); |
| 1135 | return a; | 1152 | return a; |
| 1136 | } | 1153 | } |
| 1137 | 1154 | ||
| @@ -1364,7 +1381,7 @@ verify (alignof (struct Lisp_String) % GCALIGNMENT == 0); | |||
| 1364 | INLINE bool | 1381 | INLINE bool |
| 1365 | STRINGP (Lisp_Object x) | 1382 | STRINGP (Lisp_Object x) |
| 1366 | { | 1383 | { |
| 1367 | return XTYPE (x) == Lisp_String; | 1384 | return TAGGEDP (x, Lisp_String); |
| 1368 | } | 1385 | } |
| 1369 | 1386 | ||
| 1370 | INLINE void | 1387 | INLINE void |