std::pow implementation
Steven Bosscher
s.bosscher@student.tudelft.nl
Tue Jul 29 13:36:00 GMT 2003
Op di 29-07-2003, om 14:55 schreef Richard Guenther:
> double foo2(double x)
> {
> pow(x, 2);
> }
>
> gets to (with gcc3.4, __cmath_power declared inline, -O2 -funroll-loops
> -ffast-math)
>
> _Z4foo2d:
> .LFB12:
> pushl %ebp #
> .LCFI4:
> movl %esp, %ebp #,
> .LCFI5:
> fldl 8(%ebp) # x
> fld1
> movl $1, %eax #, __n
> jmp .L62 #
> .p2align 4,,7
> .L73:
> fxch %st(1) #
> .L62:
> fxch %st(1) #
> testb $1, %al #, __n
> fmul %st(0), %st #,
> je .L59 #,
> fmul %st, %st(1) #,
> .L59:
> shrl %eax # __n
> jne .L73 #,
> fstp %st(0) #
> popl %ebp #
> ret
>
> yay!
Not that it didn't even unroll the loop at all.
I have no idea if it makes any difference, I'm just curious: What
happens if you replace
while (__n >>= 1)
with
while (__n = __n / 2)
?
Maybe the loop stuff can't handle shifts...
Gr.
Steven
More information about the Gcc
mailing list