emacs-devel
[Top][All Lists]
Advanced

[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.



reply via email to

[Prev in Thread] Current Thread [Next in Thread]