unofficial mirror of bug-gnu-emacs@gnu.org 
 help / color / mirror / code / Atom feed
* bug#1334: 23.0.60; bug of bytecomp arithmetic operations
@ 2008-11-12 14:58 ` Shigeru Fukaya
  2008-11-21 19:05   ` bug#1334: marked as done (23.0.60; bug of bytecomp arithmetic operations) Emacs bug Tracking System
  0 siblings, 1 reply; 2+ messages in thread
From: Shigeru Fukaya @ 2008-11-12 14:58 UTC (permalink / raw)
  To: bug-gnu-emacs

[-- Attachment #1: Type: text/plain, Size: 2259 bytes --]

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

[-- Attachment #2: bc.tgz --]
[-- Type: application/x-gzip, Size: 75456 bytes --]

^ permalink raw reply	[flat|nested] 2+ messages in thread

* bug#1334: marked as done (23.0.60; bug of bytecomp arithmetic  operations)
  2008-11-12 14:58 ` bug#1334: 23.0.60; bug of bytecomp arithmetic operations Shigeru Fukaya
@ 2008-11-21 19:05   ` Emacs bug Tracking System
  0 siblings, 0 replies; 2+ messages in thread
From: Emacs bug Tracking System @ 2008-11-21 19:05 UTC (permalink / raw)
  To: Chong Yidong

[-- Attachment #1: Type: text/plain, Size: 854 bytes --]


Your message dated Fri, 21 Nov 2008 13:56:15 -0500
with message-id <871vx4aoxc.fsf@cyd.mit.edu>
and subject line Re: 23.0.60; bug of bytecomp arithmetic operations
has caused the Emacs bug report #1334,
regarding 23.0.60; bug of bytecomp arithmetic operations
to be marked as done.

This means that you claim that the problem has been dealt with.
If this is not the case it is now your responsibility to reopen the
bug report if necessary, and/or fix the problem forthwith.

(NB: If you are a system administrator and have no idea what this
message is talking about, this may indicate a serious mail system
misconfiguration somewhere. Please contact don@donarmstrong.com
immediately.)


-- 
1334: http://emacsbugs.donarmstrong.com/cgi-bin/bugreport.cgi?bug=1334
Emacs Bug Tracking System
Contact don@donarmstrong.com with problems

[-- Attachment #2: Type: message/rfc822, Size: 107435 bytes --]

[-- Attachment #2.1.1: Type: text/plain, Size: 2259 bytes --]

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

[-- Attachment #2.1.2: bc.tgz --]
[-- Type: application/x-gzip, Size: 75456 bytes --]

[-- Attachment #3: Type: message/rfc822, Size: 1907 bytes --]

From: Chong Yidong <cyd@stupidchicken.com>
To: "Shigeru Fukaya" <shigeru.fukaya@gmail.com>
Cc: 1334-done@emacsbugs.donarmstrong.com
Subject: Re: 23.0.60; bug of bytecomp arithmetic operations
Date: Fri, 21 Nov 2008 13:56:15 -0500
Message-ID: <871vx4aoxc.fsf@cyd.mit.edu>

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.


^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2008-11-21 19:05 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
     [not found] <871vx4aoxc.fsf@cyd.mit.edu>
2008-11-12 14:58 ` bug#1334: 23.0.60; bug of bytecomp arithmetic operations Shigeru Fukaya
2008-11-21 19:05   ` bug#1334: marked as done (23.0.60; bug of bytecomp arithmetic operations) Emacs bug Tracking System

Code repositories for project(s) associated with this public inbox

	https://git.savannah.gnu.org/cgit/emacs.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).