http://gcc.gnu.org/bugzilla/show_bug.cgi?id=52933
--- Comment #4 from Oleg Endo <olegendo at gcc dot gnu.org> ---
The div0s insn can also be used to do floating point sign comparisons. For
example:
bool test3 (float x, float y)
{
return __builtin_signbitf (x) ^ __builtin_signbitf (y);
}
currently compiles to:
flds fr4,fpul
sts fpul,r2
flds fr5,fpul
sts fpul,r3
mov.l .L7,r1
and r1,r2
and r3,r1
cmp/eq r1,r2
movt r0
rts
xor #1,r0
.L8:
.align 2
.L7:
.long -2147483648
better:
flds fr4,fpul
sts fpul,r2
flds fr5,fpul
sts fpul,r3
div0s r2,r3
rts
movt r0
The same goes for negated result value of the sign comparison:
bool test3_1 (float x, float y)
{
return !(__builtin_signbitf (x) ^ __builtin_signbitf (y));
}
Currently compiles to:
flds fr4,fpul
sts fpul,r2
flds fr5,fpul
sts fpul,r3
mov.l .L11,r1
and r1,r2
and r3,r1
cmp/eq r1,r2
rts
movt r0
.L12:
.align 2
.L11:
.long -2147483648
better:
flds fr4,fpul
sts fpul,r2
flds fr5,fpul
sts fpul,r3
div0s r2,r3
mov #-1,r0 // on SH2A should use movrt
rts
negc r0,r0