diff options
| author | Mattias EngdegÄrd | 2024-07-20 13:12:19 +0200 |
|---|---|---|
| committer | Mattias EngdegÄrd | 2024-07-27 12:04:09 +0200 |
| commit | 2fd38e5c496a2351a25e95df37a7900f6f80f22f (patch) | |
| tree | 8b4bb30916da084175a880e285ed8656e0641b70 /src/bytecode.c | |
| parent | 156a3ba4f9ef9f7a401cfd3ca118152169f0ddcf (diff) | |
| download | emacs-2fd38e5c496a2351a25e95df37a7900f6f80f22f.tar.gz emacs-2fd38e5c496a2351a25e95df37a7900f6f80f22f.zip | |
Simplify and speed up numeric comparisons
This makes comparison functions (=, /=, <, <=, >, >=, min, max) quite
a bit faster (10-20 %). Bytecode ops on fixnums are not affected,
nor is `value<`.
* src/data.c (arithcompare): Simplify the code to reduce the number of
branches. Remove the comparison code argument; instead, return the
relation encoded as bits, which can be tested cheaply. All callers
adapted.
* src/lisp.h (enum Arith_Comparison): Remove.
(Cmp_Bit_*, cmp_bits_t): New.
Diffstat (limited to 'src/bytecode.c')
| -rw-r--r-- | src/bytecode.c | 10 |
1 files changed, 5 insertions, 5 deletions
diff --git a/src/bytecode.c b/src/bytecode.c index 75f9f1d0ac7..ce075c86afd 100644 --- a/src/bytecode.c +++ b/src/bytecode.c | |||
| @@ -1242,7 +1242,7 @@ exec_byte_code (Lisp_Object fun, ptrdiff_t args_template, | |||
| 1242 | if (FIXNUMP (v1) && FIXNUMP (v2)) | 1242 | if (FIXNUMP (v1) && FIXNUMP (v2)) |
| 1243 | TOP = BASE_EQ (v1, v2) ? Qt : Qnil; | 1243 | TOP = BASE_EQ (v1, v2) ? Qt : Qnil; |
| 1244 | else | 1244 | else |
| 1245 | TOP = arithcompare (v1, v2, ARITH_EQUAL); | 1245 | TOP = arithcompare (v1, v2) & Cmp_EQ ? Qt : Qnil; |
| 1246 | NEXT; | 1246 | NEXT; |
| 1247 | } | 1247 | } |
| 1248 | 1248 | ||
| @@ -1253,7 +1253,7 @@ exec_byte_code (Lisp_Object fun, ptrdiff_t args_template, | |||
| 1253 | if (FIXNUMP (v1) && FIXNUMP (v2)) | 1253 | if (FIXNUMP (v1) && FIXNUMP (v2)) |
| 1254 | TOP = XFIXNUM (v1) > XFIXNUM (v2) ? Qt : Qnil; | 1254 | TOP = XFIXNUM (v1) > XFIXNUM (v2) ? Qt : Qnil; |
| 1255 | else | 1255 | else |
| 1256 | TOP = arithcompare (v1, v2, ARITH_GRTR); | 1256 | TOP = arithcompare (v1, v2) & Cmp_GT ? Qt : Qnil; |
| 1257 | NEXT; | 1257 | NEXT; |
| 1258 | } | 1258 | } |
| 1259 | 1259 | ||
| @@ -1264,7 +1264,7 @@ exec_byte_code (Lisp_Object fun, ptrdiff_t args_template, | |||
| 1264 | if (FIXNUMP (v1) && FIXNUMP (v2)) | 1264 | if (FIXNUMP (v1) && FIXNUMP (v2)) |
| 1265 | TOP = XFIXNUM (v1) < XFIXNUM (v2) ? Qt : Qnil; | 1265 | TOP = XFIXNUM (v1) < XFIXNUM (v2) ? Qt : Qnil; |
| 1266 | else | 1266 | else |
| 1267 | TOP = arithcompare (v1, v2, ARITH_LESS); | 1267 | TOP = arithcompare (v1, v2) & Cmp_LT ? Qt : Qnil; |
| 1268 | NEXT; | 1268 | NEXT; |
| 1269 | } | 1269 | } |
| 1270 | 1270 | ||
| @@ -1275,7 +1275,7 @@ exec_byte_code (Lisp_Object fun, ptrdiff_t args_template, | |||
| 1275 | if (FIXNUMP (v1) && FIXNUMP (v2)) | 1275 | if (FIXNUMP (v1) && FIXNUMP (v2)) |
| 1276 | TOP = XFIXNUM (v1) <= XFIXNUM (v2) ? Qt : Qnil; | 1276 | TOP = XFIXNUM (v1) <= XFIXNUM (v2) ? Qt : Qnil; |
| 1277 | else | 1277 | else |
| 1278 | TOP = arithcompare (v1, v2, ARITH_LESS_OR_EQUAL); | 1278 | TOP = arithcompare (v1, v2) & (Cmp_LT | Cmp_EQ) ? Qt : Qnil; |
| 1279 | NEXT; | 1279 | NEXT; |
| 1280 | } | 1280 | } |
| 1281 | 1281 | ||
| @@ -1286,7 +1286,7 @@ exec_byte_code (Lisp_Object fun, ptrdiff_t args_template, | |||
| 1286 | if (FIXNUMP (v1) && FIXNUMP (v2)) | 1286 | if (FIXNUMP (v1) && FIXNUMP (v2)) |
| 1287 | TOP = XFIXNUM (v1) >= XFIXNUM (v2) ? Qt : Qnil; | 1287 | TOP = XFIXNUM (v1) >= XFIXNUM (v2) ? Qt : Qnil; |
| 1288 | else | 1288 | else |
| 1289 | TOP = arithcompare (v1, v2, ARITH_GRTR_OR_EQUAL); | 1289 | TOP = arithcompare (v1, v2) & (Cmp_GT | Cmp_EQ) ? Qt : Qnil; |
| 1290 | NEXT; | 1290 | NEXT; |
| 1291 | } | 1291 | } |
| 1292 | 1292 | ||