From: Pip Cet <pipcet@gmail.com>
To: Paul Eggert <eggert@cs.ucla.edu>
Cc: Robert Pluim <rpluim@gmail.com>, emacs-devel@gnu.org
Subject: Re: Floating-point constant folding in Emacs byte compiler
Date: Fri, 30 Mar 2018 16:26:52 +0000 [thread overview]
Message-ID: <CAOqdjBfOSJ+aP4OnEBw2njV2H6_PzC87BVbDjazU+2h2PERbdQ@mail.gmail.com> (raw)
In-Reply-To: <7a4f10ec-c1b9-953d-7a95-b2f1ff762735@cs.ucla.edu>
Here's another interesting case of machine-dependent byte compliation:
(defun f (x) (* (+ x 1024.0) (- x 1024.0)))
(byte-compile 'f)
The resulting constvec is [x 1024.0 1024.0] on this machine, but using
NaN-boxed-doubles-as-Lisp-Objects, it's [x 1024.0]. It's easy enough
to see why (identical float values aren't eq on standard Emacs), but
it results in bytecode that's not only machine-dependent, but depends
on details that aren't visible in the form's read syntax:
(setq v 1024.0)
(setq form1 '(lambda (x) (* (+ x 1024.0) (- x 1024.0))))
(setq form2 `(lambda (x) (* (+ x ,v) (- x ,v))))
(message "%S %S" form1 (byte-compile form1))
(message "%S %S" form2 (byte-compile form2))
produces:
(lambda (x) (* (+ x 1024.0) (- x 1024.0))) #[(x) " \301\\ \302Z_\207"
[x 1024.0 1024.0] 3]
(lambda (x) (* (+ x 1024.0) (- x 1024.0))) #[(x) " \301\\ \301Z_\207"
[x 1024.0] 3]
It's easy to fix this by merging the constvec based on eql rather than
eq, but that makes the byte compiler inconsistent: with optimization,
(lambda () (eq 1024.0 1024.0)) will still be false, but without
optimization, it will turn into bytecode that always returns true.
This is biting me because I want bytecode to be exactly the same as on
standard Emacs.
next prev parent reply other threads:[~2018-03-30 16:26 UTC|newest]
Thread overview: 39+ messages / expand[flat|nested] mbox.gz Atom feed top
2018-03-22 23:04 Floating-point constant folding in Emacs byte compiler Paul Eggert
2018-03-23 1:26 ` Stefan Monnier
2018-03-23 5:22 ` Paul Eggert
2018-03-23 8:24 ` Eli Zaretskii
2018-03-23 20:00 ` Paul Eggert
2018-03-23 8:15 ` Eli Zaretskii
2018-03-23 20:52 ` Pip Cet
2018-03-24 6:25 ` Eli Zaretskii
2018-03-26 9:39 ` Robert Pluim
2018-03-26 15:13 ` Eli Zaretskii
2018-03-26 15:57 ` Robert Pluim
2018-03-26 16:02 ` Eli Zaretskii
2018-03-26 18:23 ` Pip Cet
2018-03-26 18:29 ` Eli Zaretskii
2018-03-27 0:28 ` Paul Eggert
2018-03-27 23:28 ` Paul Eggert
2018-03-30 16:26 ` Pip Cet [this message]
2018-03-30 16:31 ` Noam Postavsky
2018-03-30 16:39 ` Paul Eggert
2018-04-02 10:56 ` Pip Cet
2018-04-02 11:22 ` Eli Zaretskii
2018-04-02 11:42 ` Pip Cet
2018-04-02 12:50 ` Eli Zaretskii
2018-04-02 14:50 ` Stefan Monnier
2018-04-02 15:02 ` Pip Cet
2018-04-02 12:57 ` Noam Postavsky
2018-04-02 13:30 ` Eli Zaretskii
2018-04-02 14:48 ` Stefan Monnier
2018-04-02 19:20 ` Paul Eggert
2018-04-02 19:39 ` Pip Cet
2018-04-02 19:58 ` Eli Zaretskii
2018-04-02 20:55 ` Pip Cet
[not found] ` <<83y3i568i0.fsf@gnu.org>
2018-04-02 13:37 ` Drew Adams
2018-04-02 14:05 ` Eli Zaretskii
2018-04-02 14:54 ` Pip Cet
2018-04-02 15:02 ` Drew Adams
2018-03-26 17:52 ` Stefan Monnier
2018-03-26 18:30 ` Eli Zaretskii
2018-03-27 0:08 ` Paul Eggert
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=CAOqdjBfOSJ+aP4OnEBw2njV2H6_PzC87BVbDjazU+2h2PERbdQ@mail.gmail.com \
--to=pipcet@gmail.com \
--cc=eggert@cs.ucla.edu \
--cc=emacs-devel@gnu.org \
--cc=rpluim@gmail.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.