[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: Floating-point constant folding in Emacs byte compiler
From: |
Pip Cet |
Subject: |
Re: Floating-point constant folding in Emacs byte compiler |
Date: |
Fri, 30 Mar 2018 16:26:52 +0000 |
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.
- Re: Floating-point constant folding in Emacs byte compiler, (continued)
- Re: Floating-point constant folding in Emacs byte compiler, Pip Cet, 2018/03/23
- Re: Floating-point constant folding in Emacs byte compiler, Eli Zaretskii, 2018/03/24
- Re: Floating-point constant folding in Emacs byte compiler, Robert Pluim, 2018/03/26
- Re: Floating-point constant folding in Emacs byte compiler, Eli Zaretskii, 2018/03/26
- Re: Floating-point constant folding in Emacs byte compiler, Robert Pluim, 2018/03/26
- Re: Floating-point constant folding in Emacs byte compiler, Eli Zaretskii, 2018/03/26
- Re: Floating-point constant folding in Emacs byte compiler, Pip Cet, 2018/03/26
- Re: Floating-point constant folding in Emacs byte compiler, Eli Zaretskii, 2018/03/26
- Re: Floating-point constant folding in Emacs byte compiler, Paul Eggert, 2018/03/26
- Re: Floating-point constant folding in Emacs byte compiler, Paul Eggert, 2018/03/27
- Re: Floating-point constant folding in Emacs byte compiler,
Pip Cet <=
- Re: Floating-point constant folding in Emacs byte compiler, Noam Postavsky, 2018/03/30
- Re: Floating-point constant folding in Emacs byte compiler, Paul Eggert, 2018/03/30
- Re: Floating-point constant folding in Emacs byte compiler, Stefan Monnier, 2018/03/26
- Re: Floating-point constant folding in Emacs byte compiler, Eli Zaretskii, 2018/03/26
- Re: Floating-point constant folding in Emacs byte compiler, Paul Eggert, 2018/03/26