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: Making 'eq' == 'eql' in bignum branch Date: Fri, 3 Aug 2018 00:40:16 -0700 Organization: UCLA Computer Science Department Message-ID: References: <29f933ac-a6bf-8742-66a7-0a9d6d3e5a88@disroot.org> <8e0320d9-e0d0-2b57-57cc-2df4399f133c@cs.ucla.edu> <87lgaio7xd.fsf@tromey.com> <877em1cb0i.fsf@tromey.com> <765767b2-d2e5-a9a6-f724-d58ecf4847bb@cs.ucla.edu> <76081b5d-8c10-0a37-2c97-d4864c0faa80@cs.ucla.edu> <09153aed-361d-4f82-d9ac-b502314769ae@cs.ucla.edu> <83600yt8ih.fsf@gnu.org> <83h8kgpnir.fsf@gnu.org> <7dd71d44-69bc-3adf-576b-8b9e31184a24@cs.ucla.edu> <83d0v4p1si.fsf@gnu.org> <827beb76-3adf-f2f9-33b1-1baee55680cd@cs.ucla.edu> <83wotbo04h.fsf@gnu.org> <77d5f8b0-2277-b28e-8565-d3e00c411795@cs.ucla.edu> <83ftzyocry.fsf@gnu.org> <837elao4bo.fsf@gnu.org> NNTP-Posting-Host: blaine.gmane.org Mime-Version: 1.0 Content-Type: multipart/mixed; boundary="------------A8B13936397E16F2DB5A2D2F" X-Trace: blaine.gmane.org 1533281964 8921 195.159.176.226 (3 Aug 2018 07:39:24 GMT) X-Complaints-To: usenet@blaine.gmane.org NNTP-Posting-Date: Fri, 3 Aug 2018 07:39:24 +0000 (UTC) User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:52.0) Gecko/20100101 Thunderbird/52.9.1 Cc: monnier@iro.umontreal.ca, emacs-devel@gnu.org To: Eli Zaretskii Original-X-From: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Fri Aug 03 09:39:20 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 1flUgB-0002EL-1q for ged-emacs-devel@m.gmane.org; Fri, 03 Aug 2018 09:39:19 +0200 Original-Received: from localhost ([::1]:49406 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1flUiH-0005jW-G4 for ged-emacs-devel@m.gmane.org; Fri, 03 Aug 2018 03:41:29 -0400 Original-Received: from eggs.gnu.org ([2001:4830:134:3::10]:59600) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1flUhP-0005jF-Gi for emacs-devel@gnu.org; Fri, 03 Aug 2018 03:40:37 -0400 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1flUhM-0006xp-N4 for emacs-devel@gnu.org; Fri, 03 Aug 2018 03:40:35 -0400 Original-Received: from zimbra.cs.ucla.edu ([131.179.128.68]:44612) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1flUhH-0006ic-ID; Fri, 03 Aug 2018 03:40:28 -0400 Original-Received: from localhost (localhost [127.0.0.1]) by zimbra.cs.ucla.edu (Postfix) with ESMTP id CCDED16162D; Fri, 3 Aug 2018 00:40: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 Kv76Eg5H7a7M; Fri, 3 Aug 2018 00:40:17 -0700 (PDT) Original-Received: from localhost (localhost [127.0.0.1]) by zimbra.cs.ucla.edu (Postfix) with ESMTP id B9B2D16162E; Fri, 3 Aug 2018 00:40:17 -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 OILjq-UZSutE; Fri, 3 Aug 2018 00:40:17 -0700 (PDT) Original-Received: from [192.168.1.9] (unknown [47.154.30.119]) by zimbra.cs.ucla.edu (Postfix) with ESMTPSA id 5353D16162D; Fri, 3 Aug 2018 00:40:17 -0700 (PDT) Openpgp: preference=signencrypt Autocrypt: addr=eggert@cs.ucla.edu; prefer-encrypt=mutual; keydata= xsFNBEyAcmQBEADAAyH2xoTu7ppG5D3a8FMZEon74dCvc4+q1XA2J2tBy2pwaTqfhpxxdGA9 Jj50UJ3PD4bSUEgN8tLZ0san47l5XTAFLi2456ciSl5m8sKaHlGdt9XmAAtmXqeZVIYX/UFS 96fDzf4xhEmm/y7LbYEPQdUdxu47xA5KhTYp5bltF3WYDz1Ygd7gx07Auwp7iw7eNvnoDTAl KAl8KYDZzbDNCQGEbpY3efZIvPdeI+FWQN4W+kghy+P6au6PrIIhYraeua7XDdb2LS1en3Ss mE3QjqfRqI/A2ue8JMwsvXe/WK38Ezs6x74iTaqI3AFH6ilAhDqpMnd/msSESNFt76DiO1ZK QMr9amVPknjfPmJISqdhgB1DlEdw34sROf6V8mZw0xfqT6PKE46LcFefzs0kbg4GORf8vjG2 Sf1tk5eU8MBiyN/bZ03bKNjNYMpODDQQwuP84kYLkX2wBxxMAhBxwbDVZudzxDZJ1C2VXujC OJVxq2kljBM9ETYuUGqd75AW2LXrLw6+MuIsHFAYAgRr7+KcwDgBAfwhPBYX34nSSiHlmLC+ KaHLeCLF5ZI2vKm3HEeCTtlOg7xZEONgwzL+fdKo+D6SoC8RRxJKs8a3sVfI4t6CnrQzvJbB n6gxdgCu5i29J1QCYrCYvql2UyFPAK+do99/1jOXT4m2836j1wARAQABzSBQYXVsIEVnZ2Vy dCA8ZWdnZXJ0QGNzLnVjbGEuZWR1PsLBfgQTAQIAKAUCTIByZAIbAwUJEswDAAYLCQgHAwIG FQgCCQoLBBYCAwECH In-Reply-To: <837elao4bo.fsf@gnu.org> Content-Language: en-US X-detected-operating-system: by eggs.gnu.org: GNU/Linux 3.x [fuzzy] 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:228116 Archived-At: This is a multi-part message in MIME format. --------------A8B13936397E16F2DB5A2D2F Content-Type: text/plain; charset=utf-8; format=flowed Content-Transfer-Encoding: quoted-printable Eli Zaretskii wrote: > Well, the FP calculations in Lisp are certainly in places that get > used a lot: the line-move stuff and window.el stuff. OK, I constructed a little benchmark based on some of the window.el stuff= , and=20 timed it with immediate floats instead of the longstanding way of impleme= nting=20 floats as pointers into the heap, and on this benchmark Emacs was 82% fas= ter=20 with immediate floats, i.e., the CPU time on my usual 64-bit platform for= (bench=20 1000000) shrank from 10.776 now to 5.914 seconds with immediate floats. S= o it=20 looks promising. This was the only benchmark I tried. Patch to Emacs and benchmark source code attached. The benchmark was=20 byte-compiled. The Emacs patch is just a hack; it's not intended to be a = real=20 implementation. --------------A8B13936397E16F2DB5A2D2F Content-Type: text/x-patch; name="flo.diff" Content-Transfer-Encoding: quoted-printable Content-Disposition: attachment; filename="flo.diff" diff --git a/configure.ac b/configure.ac index b6918671e4..74200dd75b 100644 --- a/configure.ac +++ b/configure.ac @@ -1515,6 +1515,12 @@ AC_DEFUN CPPFLAGS=3D"$C_SWITCH_SYSTEM $C_SWITCH_MACHINE $CPPFLAGS" fi =20 +AC_CHECK_SIZEOF([int]) +AC_CHECK_SIZEOF([long int]) +AC_CHECK_SIZEOF([long long int]) +AC_CHECK_SIZEOF([float]) +AC_CHECK_SIZEOF([double]) + # Suppress obsolescent Autoconf test for size_t; Emacs assumes C99 or be= tter. AC_DEFUN([AC_TYPE_SIZE_T]) # Likewise for obsolescent test for uid_t, gid_t; Emacs assumes them. diff --git a/src/alloc.c b/src/alloc.c index ad716f543c..763df583ab 100644 --- a/src/alloc.c +++ b/src/alloc.c @@ -2643,12 +2643,14 @@ static int float_block_index =3D FLOAT_BLOCK_SIZE= ; =20 static struct Lisp_Float *float_free_list; =20 +#if FLOAT_REPR =3D=3D FLOAT_TAGGED + /* Return a new float object with value FLOAT_VALUE. */ =20 Lisp_Object -make_float (double float_value) +make_tagged_float (double float_value) { - register Lisp_Object val; + Lisp_Object val; =20 MALLOC_BLOCK_INPUT; =20 @@ -2685,6 +2687,7 @@ make_float (double float_value) return val; } =20 +#endif =20 =0C /***********************************************************************= @@ -5505,6 +5508,7 @@ static Lisp_Object purecopy (Lisp_Object obj) { if (INTEGERP (obj) + || (FLOAT_REPR !=3D FLOAT_TAGGED && FLOATP (obj)) || (! SYMBOLP (obj) && PURE_P (XPNTR (obj))) || SUBRP (obj)) return obj; /* Already pure. */ @@ -6600,8 +6604,11 @@ mark_object (Lisp_Object arg) } =20 case Lisp_Float: - CHECK_ALLOCATED_AND_LIVE (live_float_p); - FLOAT_MARK (XFLOAT (obj)); + if (FLOAT_REPR =3D=3D FLOAT_TAGGED) + { + CHECK_ALLOCATED_AND_LIVE (live_float_p); + FLOAT_MARK (XFLOAT (obj)); + } break; =20 case_Lisp_Int: @@ -6673,7 +6680,7 @@ survives_gc_p (Lisp_Object obj) break; =20 case Lisp_Float: - survives_p =3D FLOAT_MARKED_P (XFLOAT (obj)); + survives_p =3D FLOAT_REPR !=3D FLOAT_TAGGED || FLOAT_MARKED_P (XFL= OAT (obj)); break; =20 default: diff --git a/src/lisp.h b/src/lisp.h index bdece817bd..b4ee5656c7 100644 --- a/src/lisp.h +++ b/src/lisp.h @@ -81,18 +81,21 @@ DEFINE_GDB_SYMBOL_END (GCTYPEBITS) typedef int EMACS_INT; typedef unsigned int EMACS_UINT; enum { EMACS_INT_WIDTH =3D INT_WIDTH, EMACS_UINT_WIDTH =3D UINT_WIDTH };= +# define SIZEOF_EMACS_INT SIZEOF_INT # define EMACS_INT_MAX INT_MAX # define pI "" # elif INTPTR_MAX <=3D LONG_MAX && !defined WIDE_EMACS_INT typedef long int EMACS_INT; typedef unsigned long EMACS_UINT; enum { EMACS_INT_WIDTH =3D LONG_WIDTH, EMACS_UINT_WIDTH =3D ULONG_WIDTH = }; +# define SIZEOF_EMACS_INT SIZEOF_LONG_INT # define EMACS_INT_MAX LONG_MAX # define pI "l" # elif INTPTR_MAX <=3D LLONG_MAX typedef long long int EMACS_INT; typedef unsigned long long int EMACS_UINT; enum { EMACS_INT_WIDTH =3D LLONG_WIDTH, EMACS_UINT_WIDTH =3D ULLONG_WIDT= H }; +# define SIZEOF_EMACS_INT SIZEOF_LONG_LONG_INT # define EMACS_INT_MAX LLONG_MAX /* MinGW supports %lld only if __USE_MINGW_ANSI_STDIO is non-zero, which is arranged by config.h, and (for mingw.org) if GCC is 6.0 or @@ -618,6 +621,9 @@ enum CHECK_LISP_OBJECT_TYPE { CHECK_LISP_OBJECT_TYPE = =3D false }; INLINE void set_sub_char_table_contents (Lisp_Object, ptrdiff_t, Lisp_Object); =20 +/* Defined in alloc.c. */ +extern Lisp_Object make_tagged_float (double); + /* Defined in chartab.c. */ extern Lisp_Object char_table_ref (Lisp_Object, int); extern void char_table_set (Lisp_Object, int, Lisp_Object); @@ -2640,6 +2646,34 @@ XBUFFER_OBJFWD (union Lisp_Fwd *a) } =0C /* Lisp floating point type. */ + +/* Most hosts nowadays use IEEE floating point, so they use IEC 60559 + representations, have infinities and NaNs, and do not trap on + exceptions. Define IEEE_FLOATING_POINT to 1 if this host is one of t= he + typical ones. The C11 macro __STDC_IEC_559__ is close to what is + wanted here, but is not quite right because Emacs does not require + all the features of C11 Annex F (and does not require C11 at all, + for that matter). */ + +#define IEEE_FLOATING_POINT (FLT_RADIX =3D=3D 2 && FLT_MANT_DIG =3D=3D 2= 4 \ + && FLT_MIN_EXP =3D=3D -125 && FLT_MAX_EXP =3D=3D 128) + +/* Whether Lisp floats are represented directly in Lisp_Object values, + as opposed to tagged pointers to storage. */ +#define FLOAT_TAGGED 0 +#define FLOAT_FLOAT 1 +#define FLOAT_DOUBLE 2 +#define FLOAT_REPR (! (USE_LSB_TAG && IEEE_FLOATING_POINT) ? FLOAT_TAGGE= D \ + : SIZEOF_EMACS_INT =3D=3D SIZEOF_FLOAT ? FLOAT_FLOAT \ + : SIZEOF_EMACS_INT =3D=3D SIZEOF_DOUBLE ? FLOAT_DOUBLE \ + : FLOAT_TAGGED) +#if FLOAT_REPR =3D=3D FLOAT_FLOAT +typedef float emacs_float; +#elif FLOAT_REPR =3D=3D FLOAT_DOUBLE +typedef double emacs_float; +#endif + +/* If Lisp floats are tagged pointers, they point to this. */ struct Lisp_Float { union @@ -2655,9 +2689,21 @@ INLINE bool return lisp_h_FLOATP (x); } =20 +INLINE Lisp_Object +make_float (double d) +{ +#if FLOAT_REPR =3D=3D FLOAT_TAGGED + return make_tagged_float (d); +#else + return XIL (((union { emacs_float f; EMACS_INT i; }) {d} . i & VALMASK= ) + + Lisp_Float); +#endif +} + INLINE struct Lisp_Float * XFLOAT (Lisp_Object a) { + eassume (FLOAT_REPR =3D=3D FLOAT_TAGGED); eassert (FLOATP (a)); return XUNTAG (a, Lisp_Float, struct Lisp_Float); } @@ -2665,19 +2711,18 @@ XFLOAT (Lisp_Object a) INLINE double XFLOAT_DATA (Lisp_Object f) { - return XFLOAT (f)->u.data; -} - -/* Most hosts nowadays use IEEE floating point, so they use IEC 60559 - representations, have infinities and NaNs, and do not trap on - exceptions. Define IEEE_FLOATING_POINT to 1 if this host is one of t= he - typical ones. The C11 macro __STDC_IEC_559__ is close to what is - wanted here, but is not quite right because Emacs does not require - all the features of C11 Annex F (and does not require C11 at all, - for that matter). */ + union { EMACS_INT i; float f; double d; } u =3D { .i =3D XLI (f) - Lis= p_Float }; =20 -#define IEEE_FLOATING_POINT (FLT_RADIX =3D=3D 2 && FLT_MANT_DIG =3D=3D 2= 4 \ - && FLT_MIN_EXP =3D=3D -125 && FLT_MAX_EXP =3D=3D 128) + switch (FLOAT_REPR) + { + case FLOAT_FLOAT: + return u.f; + case FLOAT_DOUBLE: + return u.d; + default: + return XFLOAT (f)->u.data; + } +} =20 /* A character, declared with the following typedef, is a member of some character set associated with the current buffer. */ @@ -3696,7 +3741,6 @@ extern struct Lisp_Vector *allocate_pseudovector (i= nt, int, int, VECSIZE (type), tag)) =20 extern bool gc_in_progress; -extern Lisp_Object make_float (double); extern void display_malloc_warning (void); extern ptrdiff_t inhibit_garbage_collection (void); extern Lisp_Object build_overlay (Lisp_Object, Lisp_Object, Lisp_Object)= ; diff --git a/src/print.c b/src/print.c index 34c7fa12b6..c10bbc5ac2 100644 --- a/src/print.c +++ b/src/print.c @@ -39,6 +39,7 @@ along with GNU Emacs. If not, see . */ #include #include #include +#include =20 #if IEEE_FLOATING_POINT # include @@ -1029,7 +1030,26 @@ float_to_string (char *buf, double data) { /* Generate the fewest number of digits that represent the floating point value without losing information. */ - len =3D dtoastr (buf, FLOAT_TO_STRING_BUFSIZE - 2, 0, 0, data); + if (FLOAT_REPR =3D=3D FLOAT_TAGGED) + len =3D dtoastr (buf, FLOAT_TO_STRING_BUFSIZE - 2, 0, 0, data); + else + for (int prec =3D ((fabs (data) + < (FLOAT_REPR =3D=3D FLOAT_FLOAT + ? (double) FLT_MIN + : DBL_MIN)) + ? 1 + : ((FLOAT_REPR =3D=3D FLOAT_FLOAT ? FLT_DIG : DBL_DIG) + - 1)); + ; prec++) + { + len =3D snprintf (buf, FLOAT_TO_STRING_BUFSIZE - 2, + "%.*g", prec, data); + if (isnan (data)) + break; + if (XFLOAT_DATA (make_float (strtod (buf, NULL))) =3D=3D data) + break; + } + /* The decimal point must be printed, or the byte compiler can get confused (Bug#8033). */ width =3D 1; --------------A8B13936397E16F2DB5A2D2F Content-Type: text/x-emacs-lisp; name="bench-float.el" Content-Transfer-Encoding: quoted-printable Content-Disposition: attachment; filename="bench-float.el" ;;; -*- lexical-binding:t -*- ;; Inspired by window--resize-child-windows-normal (defvar this-delta 10) (defvar window-height 50) (defvar window-normal-size 0.5) (defvar my-subs '(0.1 0.2 0.3 0.4 0.5 0.6 0.7 0.8)) (defvar my-tmp nil) ; (defun bench-nth (n l) ; (while (and l (not (zerop n))) ; (setq l (cdr l)) ; (setq n (1- n))) ; (car l)) (defun bench-with (n) (let ((start (float-time (get-internal-run-time))) (i 0)) (while (< i n) (let* ((delta-normal (if (=3D (- this-delta) window-height) (- window-normal-size) (/ (float this-delta) window-height))) (parent-normal 0.0)) (dolist (sub my-subs) (setq parent-normal (+ parent-normal window-normal-size sub))) (dolist (sub my-subs) (let ((old-normal (+ sub window-normal-size))) (setq my-tmp (min 1.0 ; Don't get larger than 1. (max (- old-normal (* (/ old-normal parent-normal) delta-normal)) ;; Don't drop below 0. 0.0))))) (let ((sum 0)) (dolist (sub my-subs) (setq sum (+ sum window-normal-size sub)) (setq my-tmp (min 1.0 (max (- 1.0 sum) 0.0)))))) (setq i (1+ i))) (- (float-time (get-internal-run-time)) start))) (defun bench-without (n) (let ((start (float-time (get-internal-run-time))) (i 0)) (while (< i n) (setq i (1+ i))) (- (float-time (get-internal-run-time)) start))) (defun bench (n) (- (bench-with n) (bench-without n))) --------------A8B13936397E16F2DB5A2D2F--