Fast operations on floating point numbers?

Rupert Wood me@rupey.net
Thu Dec 4 14:52:00 GMT 2003


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.



More information about the Gcc mailing list