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]
Other format: [Raw text]

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.


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