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]

ColdFire softfloat optimization


I'm thinking about trying to optimize the following for softfloat:

    if (ffabs(X) < 1.0f)
      foo();

in cases where I know that X is well-formed (not a NaN).  I'd like to
subreg X into an integer, shift it left one bit(to remove the sign
bit), as well as shift the integer representation of the constant 1.0f
left one bit, and *then* do an unsigned compare/branch:

     move.l X,%d0
     add.l %d0,%d0
     cmp.l #0xff000000,%d0
     bhi L1
     jsr foo
L1:     

I believe this optimization is valid for all well-formed values and
constants, and would be keyed off of -funsafe-math-optimzations.

Another optimization for well-formed float values is for a subset of
compares and constants such that both zero and -zero are are on the
same side of the comparison.

    if (X < 1.0f)
      foo();

can be represented as a ineger compare and *signed* branch less-than:

    move.l #0x7f800000,%d0
    cmpi X,%d0
    blt L1
    jsr foo
L1:

but the following:

    if (Y < -1.0f)
      foo();

requires an unsigned branch(and a reversed condition):

    move.l #0xff800000,%d0
    cmp.l Y,%d0
    bcc L1
    jsr foo
L1:


Any suggestions on the best approach for these type of optimizations?

I'm not sure if I want a peephole since I need a temp register to hold
the shifted version of X, as well as I have to modify the type of
branch(signed vs unsigned).

These optimizations are not restricted to the 68k/ColdFire, but can be
applied to all IEEE targets.  I'd like to try them out on 68k, and
then see about migrating them to other targets.

All comments are appreciated.

-- 
Peter Barada
peter@the-baradas.com


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