rs6000: floating point cast oddities?
David Edelsohn
dje@watson.ibm.com
Mon Dec 17 10:36:00 GMT 2001
>>>>> degger writes:
degger> Consider:
degger> float
degger> foo (float a, float b)
degger> {
degger> return b+1.0;
degger> }
degger> What I expect it do to is:
degger> Load a single precision 1.0 and add it to the register
degger> of the second parameter.
degger> What I get with current gcc is:
degger> .LC0:
degger> .long 0x3ff00000
degger> .long 0x0
degger> .section ".text"
degger> .align 2
degger> .globl foo
degger> .type foo,@function
degger> foo:
degger> lis 9,.LC0@ha
degger> la 9,.LC0@l(9)
degger> lfd 0,0(9)
degger> fadd 2,2,0
degger> frsp 2,2
degger> fmr 1,2
degger> blr
degger> So it loads a double 1.0, adds it using full precision and then converts
degger> it back to single precision (not without having a superfluous float
degger> register move as mentioned in the other mail).
degger> I can prevent gcc from doing it in double precision by adding a cast but
degger> this is not a good reason for being stupid in the first place I guess.
degger> :)
This is completely correct code. If you do not want the
intermediate double, use 1.0f. By default 1.0 is a double.
David
More information about the Gcc
mailing list