This is the mail archive of the gcc@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]

Re: Volatile




OK, I'll come out and say it.  Volatile doesn't appeal to me
because I don't want to use C if I can avoid it.

At the risk of repetition, I'll say that I haven't seen a better way to
express Kahan's scheme for solving the quadratic formula on
architectures like hppa2.0 and PowerPC where one needs to
calculate both a product with intermediate rounding and the one
which the machine does with a fused multiply-accumulate.  It
works with gcc and with the hardware vendors' C compilers.  But
it's no way to write portable code or code which isn't about to be
tested thoroughly.  I'm not prepared to advocate Kahan's
suggestion about the extra meaning of parentheses either.

>If you want to guarantee a value will be written out to memory,
>you can simply declare the memory variable to be "volatile."
>Then the compiler cannot continue to ignore you.  The reason
>this works, and must work on all compilers that optimize, is that
>you would not be able to write hardware device drivers if
"volatile"
>did not work.  Software people seem to find this solution
unappealing.
>I do not understand why.

Because `volatile' has nothing to do with getting consistent
numerical
results.  "Writing to memory" is a meaningless phrase in
numerical
programming.  Numerical programmers should not have to
worry whether
the compiler places a value in a register, in memory, in a
temporary
file, or whatever.  They should be able to just focus on the
minimum
precision they need for variables, operations, and so on, and get
consistent behavior from the code generators they use.

If they *don't* get the consistent behavior, they'll use better
code generators that *do* give them consistent behavior.

Further, `volatile' is basically completely useless in getting f(x) <
f(y)
to imply that f(y) > f(x), AFAICT.

        tq vm, (burley)

Dr. Timothy C. Prince
Consulting Engineer
Solar Turbines, a Caterpillar Company
alternate e-mail: tprince@computer.org

           To:                                              INTERNET - IBMMAIL
                                                            N3356140 - IBMMAIL


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]