Subject: bug#1334 closed by Chong Yidong <[email-masked]> (Re: 23.0.60; bug of bytecomp arithmetic operations)

From: [email-masked] (Emacs bug Tracking System)

This is an automatic notification regarding your bug report
which was filed against the emacs package:

#1334: 23.0.60; bug of bytecomp arithmetic operations

It has been closed by Chong Yidong <[email-masked]>.

Their explanation is attached below along with your original report.
If this explanation is unsatisfactory and you have not received a
better one in a separate message then please contact Chong Yidong <[email-masked]> by
replying to this email.

-- 
1334: http://debbugs.gnu.org/cgi/bugreport.cgi?bug=1334
Emacs Bug Tracking System
Contact [email-masked] with problems
>From [email-masked] Fri Nov 21 10:56:01 2008
From: Chong Yidong <[email-masked]>
To: "Shigeru Fukaya" <[email-masked]>
Cc: [email-masked]
Subject: Re: 23.0.60; bug of bytecomp arithmetic operations
Date: Fri, 21 Nov 2008 13:56:15 -0500

I've reviewed your patch, and checked most of it into CVS (I took the
liberty of rewording some comments, plus some minor edits).

> *** Optimize addtion/subtraction where their last operand is 1 or
> -1 to use `1+', `1-' funcitons. This pattern often appears and
> more effective at least in size (byte-add1 vs constant 1).

Let's leave this till after the release.  It's not clear to me that
there is a significant speed increase from it, and we should try to
restrict the changes to bug fixes for the moment.

Thanks very much for working on this.

>From [email-masked] Wed Nov 12 06:58:54 2008
Date: Wed, 12 Nov 2008 23:58:43 +0900
From: "Shigeru Fukaya" <[email-masked]>
To: [email-masked]
Subject: 23.0.60; bug of bytecomp arithmetic operations

------=_Part_6262_3736143.1226501923421
Content-Type: text/plain; charset=ISO-8859-1
Content-Transfer-Encoding: 7bit
Content-Disposition: inline

Hello,

Current byte compiler has potential problems in arithmetic operations.
Examples are all on Intel 32-bit. Result may occur in other
environments.

1. Operations are all compiled to binary operations. It may cause
overflows or truncations in floating point data operations.

   Examples.
      (upper result is by interpreter, lower is by code after compile)

    (let ((a most-positive-fixnum) (b 1) (c 1.0))  (+ a b c))
         --> 268435457.0
         --> -268435455.0

    (let ((a most-positive-fixnum) (b -2) (c 1.0)) (- a b c))
         --> 268435456.0
         --> -268435456.0

    (let ((a most-positive-fixnum) (b 2) (c 1.0))  (* a b c))
         --> 536870910.0
         --> -2.0

    (let ((a 3) (b 2) (c 1.0)) (/ a b c))
         --> 1.5
         --> 1.0

2. Most integer constants are moved to the end of expressions and
pre-calculated at compile time. Changing of order may cause different
result from original expressions.
(In other words, `byte-optimize-delay-constants-math' should not be called)

   Examples.

      (let ((a (+ 1 (expt 2 -52))) (b (expt 2 -53))) (+ a -1 b))
         --> 3.3306690738754696e-016
         --> 4.440892098500626e-016

      (let ((a (expt 2 -1074)) (b 0.25)) (* a 4 b))
         --> 5e-324
         --> 0.0

3. Mulitiplication/Division optimization sometimes don't consider
floating point operators.

   Examples.

      (let ((a 1.0)) (* a 0))
         --> 0.0
         --> 0

      (let ((a 1.0)) (* a 2.0 0))
         --> 0.0
         --> 0

      (let ((a 1.0)) (/ 0 a))
         --> 0.0
         --> 0

      (let ((a 1.0)) (/ 3 a 2))
         --> 1.5
         --> 1.0

4. In division, optimizing -1 twice and cause erroneous results.

   Examples.

      (/ 3 -1)
         --> -3
         --> 3

Attached files are rewrittren version and too much changed, so it is
possibly just for references (At least, alias functions are not
treated well, and not comprehensively tested).

   bytecomp-patch.el -- contain only new and modified symbols/functions.
   byte-opt-test.el  -- test function that shows interpreter/original/revised
                        results.
   test.log          -- test result using above files.
   byte-opt.el bytecomp.el -- changed files to replace.

Regards,
Shigeru

------=_Part_6262_3736143.1226501923421
Content-Type: application/x-gzip; name=bc.tgz
Content-Transfer-Encoding: base64
X-Attachment-Id: f_fng3epw20
Content-Disposition: attachment; filename=bc.tgz

------=_Part_6262_3736143.1226501923421--