From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!.POSTED!not-for-mail From: Paul Eggert Newsgroups: gmane.emacs.devel Subject: Re: Some vars now limited to fixnum size. Date: Tue, 21 Aug 2018 11:46:21 -0700 Organization: UCLA Computer Science Department Message-ID: References: <877ekwu1mn.fsf@tromey.com> <611579fd-52f2-0104-ef82-a7a4a3929700@cs.ucla.edu> <878t51t32a.fsf_-_@red-bean.com> <28fcabff-d102-d67f-442f-f59eab5040c9@cs.ucla.edu> <31ba6457-6428-efc7-8423-1d6134c8e747@cs.ucla.edu> <876003rcfn.fsf@tromey.com> NNTP-Posting-Host: blaine.gmane.org Mime-Version: 1.0 Content-Type: multipart/mixed; boundary="------------0832F4CF1D74CB3475D5814C" X-Trace: blaine.gmane.org 1534877149 32658 195.159.176.226 (21 Aug 2018 18:45:49 GMT) X-Complaints-To: usenet@blaine.gmane.org NNTP-Posting-Date: Tue, 21 Aug 2018 18:45:49 +0000 (UTC) User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:52.0) Gecko/20100101 Thunderbird/52.9.1 Cc: Karl Fogel , Pip Cet , emacs-devel@gnu.org To: Tom Tromey Original-X-From: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Tue Aug 21 20:45:45 2018 Return-path: Envelope-to: ged-emacs-devel@m.gmane.org Original-Received: from lists.gnu.org ([208.118.235.17]) by blaine.gmane.org with esmtp (Exim 4.84_2) (envelope-from ) id 1fsBex-0008Ky-AC for ged-emacs-devel@m.gmane.org; Tue, 21 Aug 2018 20:45:43 +0200 Original-Received: from localhost ([::1]:55504 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fsBh3-0000Tu-KC for ged-emacs-devel@m.gmane.org; Tue, 21 Aug 2018 14:47:53 -0400 Original-Received: from eggs.gnu.org ([2001:4830:134:3::10]:43374) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fsBfm-0008LF-PQ for emacs-devel@gnu.org; Tue, 21 Aug 2018 14:46:37 -0400 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1fsBff-0007sA-9N for emacs-devel@gnu.org; Tue, 21 Aug 2018 14:46:33 -0400 Original-Received: from zimbra.cs.ucla.edu ([131.179.128.68]:33502) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1fsBfe-0007qv-To for emacs-devel@gnu.org; Tue, 21 Aug 2018 14:46:27 -0400 Original-Received: from localhost (localhost [127.0.0.1]) by zimbra.cs.ucla.edu (Postfix) with ESMTP id D110E160E71; Tue, 21 Aug 2018 11:46:24 -0700 (PDT) Original-Received: from zimbra.cs.ucla.edu ([127.0.0.1]) by localhost (zimbra.cs.ucla.edu [127.0.0.1]) (amavisd-new, port 10032) with ESMTP id 5fRLvSsv5yew; Tue, 21 Aug 2018 11:46:23 -0700 (PDT) Original-Received: from localhost (localhost [127.0.0.1]) by zimbra.cs.ucla.edu (Postfix) with ESMTP id 5914D160E48; Tue, 21 Aug 2018 11:46:23 -0700 (PDT) X-Virus-Scanned: amavisd-new at zimbra.cs.ucla.edu Original-Received: from zimbra.cs.ucla.edu ([127.0.0.1]) by localhost (zimbra.cs.ucla.edu [127.0.0.1]) (amavisd-new, port 10026) with ESMTP id b9mkqNZhhdfb; Tue, 21 Aug 2018 11:46:23 -0700 (PDT) Original-Received: from [192.168.1.9] (unknown [47.154.30.119]) by zimbra.cs.ucla.edu (Postfix) with ESMTPSA id DC01D160E47; Tue, 21 Aug 2018 11:46:22 -0700 (PDT) In-Reply-To: <876003rcfn.fsf@tromey.com> Content-Language: en-US X-detected-operating-system: by eggs.gnu.org: GNU/Linux 3.x X-Received-From: 131.179.128.68 X-BeenThere: emacs-devel@gnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: "Emacs development discussions." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Original-Sender: "Emacs-devel" Xref: news.gmane.org gmane.emacs.devel:228791 Archived-At: This is a multi-part message in MIME format. --------------0832F4CF1D74CB3475D5814C Content-Type: text/plain; charset=utf-8; format=flowed Content-Transfer-Encoding: 7bit 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? --------------0832F4CF1D74CB3475D5814C Content-Type: text/x-patch; name="0001-Fix-bignum-bugs-with-nth-elt.patch" Content-Transfer-Encoding: 7bit Content-Disposition: attachment; filename="0001-Fix-bignum-bugs-with-nth-elt.patch" >From 1244713462569240bd25f0e4bbb3a2af9ac3c52d Mon Sep 17 00:00:00 2001 From: Paul Eggert 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 --------------0832F4CF1D74CB3475D5814C--