[PATCH, i386]: Rewrite x87 sqrt patterns
Uros Bizjak
ubizjak@gmail.com
Tue Nov 21 21:36:00 GMT 2006
Hello!
The i386 sqrt patterns doesn't truncate the result of fsqrt x87
instruction. This could be annoying due to the fact that these patterns
are also used outside -ffast-math. Proposed patch solves this problem by
expanding SFmode/DFmode argument to sqrt instruction to XFmode, further,
XFmode sqrt (this is what x87 _really_ does) is emmitted and the result
is truncated back to SFmode or DFmode.
The testcase:
double test(float a)
{
return sqrt(a + 2.0);
}
is compiled (gcc -O2 -fomit-frame-pointer -fno-math-errno) to:
test:
subl $12, %esp
flds .LC0
fadds 16(%esp)
fsqrt
fstpl (%esp)
fldl (%esp)
addl $12, %esp
ret
In addition to the truncation, no extra register moves are introduced,
due to the way float_extend patterns for x87 are written. This patch
also removes fsqrt patterns that implicitly extend operators, and
removes "mixed" fsqrt patterns which were wrong anyway (x87 fsqrt
operates in XFmode, where SSE sqrt operates in DFmode or SFmode).
Patch was bootstrapped on x86_64-pc-linux-gnu. A regression test on both
x86_64 and i686 (c, c++ and fortran) will finish over night. OK for
mainline if the tests pass?
BTW: I'd like to implement above approach for transcendental functions
(sin, cos, exp, etc). Some of them are already implemented as proposed
above, but trigonometric patterns still include implicit extend operators.
test:
subl $12, %esp
flds .LC0
fadds 16(%esp)
fsqrt
fstpl (%esp)
fldl (%esp)
addl $12, %esp
ret
Uros.
-------------- next part --------------
A non-text attachment was scrubbed...
Name: i386-sqrt.diff
Type: text/x-patch
Size: 4789 bytes
Desc: not available
URL: <http://gcc.gnu.org/pipermail/gcc-patches/attachments/20061121/be21cbe7/attachment.bin>
More information about the Gcc-patches
mailing list