From: Paul Eggert <eggert@cs.ucla.edu>
To: Tom Tromey <tom@tromey.com>
Cc: Karl Fogel <kfogel@red-bean.com>, Pip Cet <pipcet@gmail.com>,
emacs-devel@gnu.org
Subject: Re: Some vars now limited to fixnum size.
Date: Tue, 21 Aug 2018 11:46:21 -0700 [thread overview]
Message-ID: <ada4b78d-c53e-4224-ca26-788d4d14d676@cs.ucla.edu> (raw)
In-Reply-To: <876003rcfn.fsf@tromey.com>
[-- Attachment #1: Type: text/plain, Size: 545 bytes --]
Tom Tromey wrote:
>>> It would be better to fix nthcdr so that it works on bignums
> Paul> ... and I did that by installing the attached patch.
>
> I think the bytecode interpreter needs a similar update.
I don't see any problems with the Bnthcdr implementation in the bytecode
interpreter, as it simply calls Fnthcdr.
Perhaps you are thinking of some other bignum problems in the bytecode
interpreter? I just now took a quick look and found some problems, and fixed the
ones that I found by installing the attached patch. Did I miss any?
[-- Attachment #2: 0001-Fix-bignum-bugs-with-nth-elt.patch --]
[-- Type: text/x-patch, Size: 3898 bytes --]
From 1244713462569240bd25f0e4bbb3a2af9ac3c52d Mon Sep 17 00:00:00 2001
From: Paul Eggert <eggert@cs.ucla.edu>
Date: Tue, 21 Aug 2018 11:40:23 -0700
Subject: [PATCH] Fix bignum bugs with nth, elt, =
* src/bytecode.c (exec_byte_code): Support bignums
when implementing nth, elt, and =.
* src/lisp.h (SMALL_LIST_LEN_MAX): New constant.
* src/fns.c (Fnthcdr): Use it.
(Felt): Do not reject bignum indexes.
---
src/bytecode.c | 39 +++++++++++++--------------------------
src/fns.c | 5 ++---
src/lisp.h | 5 +++++
3 files changed, 20 insertions(+), 29 deletions(-)
diff --git a/src/bytecode.c b/src/bytecode.c
index b27fa7c5c6..17457fc574 100644
--- a/src/bytecode.c
+++ b/src/bytecode.c
@@ -832,13 +832,14 @@ exec_byte_code (Lisp_Object bytestr, Lisp_Object vector, Lisp_Object maxdepth,
CASE (Bnth):
{
Lisp_Object v2 = POP, v1 = TOP;
- CHECK_FIXNUM (v1);
- for (EMACS_INT n = XFIXNUM (v1); 0 < n && CONSP (v2); n--)
+ if (RANGED_FIXNUMP (0, v1, SMALL_LIST_LEN_MAX))
{
- v2 = XCDR (v2);
- rarely_quit (n);
+ for (EMACS_INT n = XFIXNUM (v1); 0 < n && CONSP (v2); n--)
+ v2 = XCDR (v2);
+ TOP = CAR (v2);
}
- TOP = CAR (v2);
+ else
+ TOP = Fnth (v1, v2);
NEXT;
}
@@ -985,15 +986,8 @@ exec_byte_code (Lisp_Object bytestr, Lisp_Object vector, Lisp_Object maxdepth,
CASE (Beqlsign):
{
- Lisp_Object v2 = POP, v1 = TOP;
- if (FLOATP (v1) || FLOATP (v2))
- TOP = arithcompare (v1, v2, ARITH_EQUAL);
- else
- {
- CHECK_FIXNUM_OR_FLOAT_COERCE_MARKER (v1);
- CHECK_FIXNUM_OR_FLOAT_COERCE_MARKER (v2);
- TOP = EQ (v1, v2) ? Qt : Qnil;
- }
+ Lisp_Object v1 = POP;
+ TOP = arithcompare (TOP, v1, ARITH_EQUAL);
NEXT;
}
@@ -1264,23 +1258,16 @@ exec_byte_code (Lisp_Object bytestr, Lisp_Object vector, Lisp_Object maxdepth,
CASE (Belt):
{
- if (CONSP (TOP))
+ Lisp_Object v2 = POP, v1 = TOP;
+ if (CONSP (v1) && RANGED_FIXNUMP (0, v2, SMALL_LIST_LEN_MAX))
{
- /* Exchange args and then do nth. */
- Lisp_Object v2 = POP, v1 = TOP;
- CHECK_FIXNUM (v2);
+ /* Like the fast case for Bnth, but with args reversed. */
for (EMACS_INT n = XFIXNUM (v2); 0 < n && CONSP (v1); n--)
- {
- v1 = XCDR (v1);
- rarely_quit (n);
- }
+ v1 = XCDR (v1);
TOP = CAR (v1);
}
else
- {
- Lisp_Object v1 = POP;
- TOP = Felt (TOP, v1);
- }
+ TOP = Felt (v1, v2);
NEXT;
}
diff --git a/src/fns.c b/src/fns.c
index 9d681017c1..b368ffd58f 100644
--- a/src/fns.c
+++ b/src/fns.c
@@ -1418,7 +1418,7 @@ DEFUN ("nthcdr", Fnthcdr, Snthcdr, 2, 2, 0,
num = XFIXNUM (n);
/* Speed up small lists by omitting circularity and quit checking. */
- if (num < 128)
+ if (num <= SMALL_LIST_LEN_MAX)
{
for (; 0 < num; num--, tail = XCDR (tail))
if (! CONSP (tail))
@@ -1503,9 +1503,8 @@ N counts from zero. If LIST is not that long, nil is returned. */)
DEFUN ("elt", Felt, Selt, 2, 2, 0,
doc: /* Return element of SEQUENCE at index N. */)
- (register Lisp_Object sequence, Lisp_Object n)
+ (Lisp_Object sequence, Lisp_Object n)
{
- CHECK_FIXNUM (n);
if (CONSP (sequence) || NILP (sequence))
return Fcar (Fnthcdr (n, sequence));
diff --git a/src/lisp.h b/src/lisp.h
index 8f48a33484..c5593b2100 100644
--- a/src/lisp.h
+++ b/src/lisp.h
@@ -4694,6 +4694,11 @@ enum
Lisp_String)) \
: make_unibyte_string (str, len))
+/* The maximum length of "small" lists, as a heuristic. These lists
+ are so short that code need not check for cycles or quits while
+ traversing. */
+enum { SMALL_LIST_LEN_MAX = 127 };
+
/* Loop over conses of the list TAIL, signaling if a cycle is found,
and possibly quitting after each loop iteration. In the loop body,
set TAIL to the current cons. If the loop exits normally,
--
2.17.1
next prev parent reply other threads:[~2018-08-21 18:46 UTC|newest]
Thread overview: 58+ messages / expand[flat|nested] mbox.gz Atom feed top
2018-08-11 19:47 Merging bignum to master Tom Tromey
2018-08-11 21:28 ` Basil L. Contovounesios
2018-08-12 16:34 ` Tom Tromey
2018-08-13 12:21 ` Basil L. Contovounesios
2018-08-14 0:21 ` Andy Moreton
2018-08-15 23:41 ` Andy Moreton
2018-08-16 15:38 ` Basil L. Contovounesios
2018-08-19 8:26 ` Paul Eggert
2018-08-17 14:58 ` Eli Zaretskii
2018-08-12 6:29 ` Ulrich Mueller
2018-08-12 8:09 ` Paul Eggert
2018-08-12 17:21 ` Ulrich Mueller
2018-08-12 18:20 ` Eli Zaretskii
2018-08-12 19:30 ` Ulrich Mueller
2018-08-13 0:15 ` Paul Eggert
2018-08-12 18:05 ` Eli Zaretskii
2018-08-12 23:53 ` Paul Eggert
2018-08-13 0:20 ` Tom Tromey
2018-08-13 7:51 ` Andreas Schwab
2018-08-13 8:06 ` Ulrich Mueller
2018-08-13 9:14 ` Paul Eggert
2018-08-14 23:09 ` Paul Eggert
2018-08-16 2:46 ` Richard Stallman
2018-08-13 23:31 ` Richard Stallman
2018-08-14 1:41 ` Paul Eggert
2018-08-16 2:41 ` Richard Stallman
2018-08-16 19:31 ` Paul Eggert
2018-08-16 22:02 ` Stefan Monnier
2018-08-12 7:37 ` John Wiegley
2018-08-12 18:21 ` Eli Zaretskii
2018-08-12 11:48 ` Pip Cet
2018-08-12 16:02 ` Tom Tromey
2018-08-13 22:58 ` Paul Eggert
2018-08-14 1:12 ` Noam Postavsky
2018-08-14 13:04 ` Pip Cet
2018-08-14 18:01 ` Paul Eggert
2018-08-15 15:20 ` Pip Cet
2018-08-15 16:17 ` Paul Eggert
2018-08-15 23:57 ` Andy Moreton
2018-08-16 22:00 ` Stefan Monnier
2018-08-20 16:28 ` Some vars now limited to fixnum size. (Was: Merging bignum to master) Karl Fogel
2018-08-20 16:54 ` Paul Eggert
2018-08-20 17:27 ` Eli Zaretskii
2018-08-20 17:27 ` Paul Eggert
2018-08-20 18:00 ` Eli Zaretskii
2018-08-20 19:55 ` Pip Cet
2018-08-20 23:15 ` Paul Eggert
2018-08-21 15:01 ` Some vars now limited to fixnum size Tom Tromey
2018-08-21 16:36 ` Andy Moreton
2018-08-21 18:46 ` Paul Eggert [this message]
2018-08-22 15:39 ` Tom Tromey
2018-08-21 3:38 ` Some vars now limited to fixnum size. (Was: Merging bignum to master) Richard Stallman
2018-08-21 4:09 ` Paul Eggert
2018-08-22 4:03 ` Richard Stallman
2018-08-22 4:53 ` Paul Eggert
2018-08-20 17:25 ` Eli Zaretskii
2018-08-14 0:51 ` Merging bignum to master Andy Moreton
2018-08-15 15:46 ` Andy Moreton
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=ada4b78d-c53e-4224-ca26-788d4d14d676@cs.ucla.edu \
--to=eggert@cs.ucla.edu \
--cc=emacs-devel@gnu.org \
--cc=kfogel@red-bean.com \
--cc=pipcet@gmail.com \
--cc=tom@tromey.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
Code repositories for project(s) associated with this external index
https://git.savannah.gnu.org/cgit/emacs.git
https://git.savannah.gnu.org/cgit/emacs/org-mode.git
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.