This is the mail archive of the
gcc@gcc.gnu.org
mailing list for the GCC project.
RE: Fast operations on floating point numbers?
- From: "Rupert Wood" <me at rupey dot net>
- To: "'Scott Robert Ladd'" <coyote at coyotegulch dot com>,"'Martin Reinecke'" <martin at MPA-Garching dot MPG dot DE>
- Cc: <gcc at gcc dot gnu dot org>
- Date: Thu, 4 Dec 2003 14:44:11 -0000
- Subject: RE: Fast operations on floating point numbers?
Scott Robert Ladd wrote:
> Your problem is architecture-specific. For example, modern Intel
> architecture processors support the FCHS instruction to flip the
> sign of the floating-point value in ST(0), by performing a simple
> bit flip. I haven't run any tests, but I suspect GCC is smart
> enough to use that instruction.
Yeah, e.g.
/* floating-point in a register */
double f(double a, int b)
{
if (b) a *= -1;
return a;
}
/* floating-point in memory */
void g(double *p)
{
*p *= -1;
}
The register case generates the floating point change sign operation:
fchs
and the second the xor as you'd hope:
movl 4(%esp), %eax
xorb $-128, 7(%eax)
Rup.