comp.lang.ada
 help / color / mirror / Atom feed
* Can compilers do this?
@ 1996-02-22  0:00 BWBurnsed
  1996-02-23  0:00 ` Cordes MJ
                   ` (5 more replies)
  0 siblings, 6 replies; 12+ messages in thread
From: BWBurnsed @ 1996-02-22  0:00 UTC (permalink / raw)


I came across some very strange looking code that someone else wrote,
long, long ago, and (apparently) in a universe far, far away. But before I

make too many critical comments, I want to be sure I'm not missing
something.

Repeatedly in this code (in many files), there are places where a floating
point variable is tested to see if it is negative. However, the way it is
done is:

     if  X * abs(X)  <  0.0  then  ...

Is there (or was there ever) some pathological anomaly about floating
point 
implementations that would make a conversion (abs) and floating point
multiply 
preferable to testing a sign bit? Can, and will, optimizing compilers
recognize the
real test desired in such constructs, i.e. reduce it to a sign bit test?

Also, suppose Y and X are floating point variables, and M and B are 
CONSTANT floating point variables (not named numbers) initialized to
1.0  and  0.0  respectively. If one writes

     Y := M * X  +  B ;

can (and will) any compiler reduce this to

     Y := X ;

If not, could it do so if M and B were named numbers?

Thanks,
BwB




^ permalink raw reply	[flat|nested] 12+ messages in thread
* Re: Can compilers do this?
@ 1996-02-26  0:00 Marin David Condic, 407.796.8997, M/S 731-93
  0 siblings, 0 replies; 12+ messages in thread
From: Marin David Condic, 407.796.8997, M/S 731-93 @ 1996-02-26  0:00 UTC (permalink / raw)


Robert Dewar <dewar@CS.NYU.EDU> writes:
>Subject: Re: Can compilers do this?
>
>BwB says
>
>"Also, suppose Y and X are floating point variables, and M and B are
>CONSTANT floating point variables (not named numbers) initialized to
>1.0  and  0.0  respectively. If one writes
>
>     Y := M * X  +  B ;
>
>can (and will) any compiler reduce this to
>
>     Y := X ;
>
>
>Sure, this is just standard constant propagation, a very common
>optimization.
>
    Except that you might not always want to. Constant folding can be
    a "good" optimization from a speed standpoint, but a "bad"
    optimization from a test standpoint.

    When we build control systems, we typically like to keep tables
    and assorted "constants" as "rubber constants". They are declared
    constants so that the program can't change the values, but when
    they're loaded into the box, we can change them with test
    equipment in order to affect "trim" on the control or accomplish
    other test stuff. If they were optimized away, you couldn't do
    this.

    The EDS-Scicon compiler we are working with gives us a "pragma
    VOLATILE" command to make sure that the constants aren't optimized
    away. I personally think anyone making a compiler for embedded
    systems should provide a similar option

    Pax,
    MDC

Marin David Condic, Senior Computer Engineer    ATT:        407.796.8997
M/S 731-93                                      Technet:    796.8997
Pratt & Whitney, GESP                           Fax:        407.796.4669
P.O. Box 109600                                 Internet:   CONDICMA@PWFL.COM
West Palm Beach, FL 33410-9600                  Internet:   MDCONDIC@AOL.COM
===============================================================================
    "Nobody shot me."

        --  Last words of Frank Gusenberg when asked by police who
            shot him fourteen times with a machine gun in the Saint
            Valentine's Day Massacre.
===============================================================================




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

end of thread, other threads:[~1996-02-26  0:00 UTC | newest]

Thread overview: 12+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
1996-02-22  0:00 Can compilers do this? BWBurnsed
1996-02-23  0:00 ` Cordes MJ
1996-02-23  0:00 ` Robert Dewar
1996-02-23  0:00 ` Stuart Palin
1996-02-23  0:00 ` Mark A Biggar
1996-02-24  0:00   ` Robert A Duff
1996-02-23  0:00     ` Robert Dewar
1996-02-25  0:00   ` Robert Dewar
1996-02-23  0:00 ` Robert Dewar
1996-02-26  0:00 ` Robert I. Eachus
1996-02-26  0:00   ` BWBurnsed
  -- strict thread matches above, loose matches on Subject: below --
1996-02-26  0:00 Marin David Condic, 407.796.8997, M/S 731-93

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox