[Ffmpeg-devel] int vs. float: Hard Numbers

matthieu castet castet.matthieu
Fri May 20 21:12:15 CEST 2005


Mike Melanson wrote:
> Hi,
>     Persuant to the discussion about whether int or float ops were more 
> efficient on today's production CPUs, I performed some empirical tests.
> 
>     Tests written using gcc+nasm and clocked using the Intel timestamp 
> counter register (TSC) found in Pentium+ CPUs. I compared additions and 
> multiplications. Results:
> 
> integer_adder() (10 adds) returned 50, 36 cycles used
> float_adder() (10 adds) returned 50.000000, 36 cycles used
> integer_mult() (10 mults) returned 9765625, 115 cycles used
> float_mult() (10 mults) returned 9765625.000000, 36 cycles used
> 
I have try to do an 'portable' test and I have strange result :
gcc t1.c -O3

r1+=r2 11
r1*=r2 44
f1+=f2 4652
f1*=f2 15

and

r1+=2 11
r1*=2 14
f1+=2.0 3241
f1*=2.0 14

gcc does some optimisation for interger add and mult (in second case), 
but as you can see the float add is very expensive.

asm op code for the first case :

         #start ops r1+=r2
#NO_APP
         movl    r2, %eax
         leal    0(,%eax,8), %edx
         addl    r1, %edx
         leal    (%edx,%eax,2), %eax
         movl    %eax, r1
#APP
         #end ops r1+=r2
         #start ops r1*=r2
#NO_APP
         movl    r2, %edx
         movl    r1, %eax
         imull   %edx, %eax
         imull   %edx, %eax
         imull   %edx, %eax
         imull   %edx, %eax
         imull   %edx, %eax
         imull   %edx, %eax
         imull   %edx, %eax
         imull   %edx, %eax
         imull   %edx, %eax
         imull   %edx, %eax
         movl    %eax, r1
#APP
         #end ops r1*=r2
        #start ops f1+=f2
#NO_APP
         fldl    f2
         fldl    f1
         fadd    %st(1), %st
         fadd    %st(1), %st
         fadd    %st(1), %st
         fadd    %st(1), %st
         fadd    %st(1), %st
         fadd    %st(1), %st
         fadd    %st(1), %st
         fadd    %st(1), %st
         fadd    %st(1), %st
         faddp   %st, %st(1)
         fstpl   f1
#APP
         #end ops f1+=f2
        #start ops f1*=f2
#NO_APP
         fldl    f2
         fldl    f1
         fmul    %st(1), %st
         fmul    %st(1), %st
         fmul    %st(1), %st
         fmul    %st(1), %st
         fmul    %st(1), %st
         fmul    %st(1), %st
         fmul    %st(1), %st
         fmul    %st(1), %st
         fmul    %st(1), %st
         fmulp   %st, %st(1)
         fstpl   f1
#APP
         #end ops f1*=f2

and the second :
         #start ops r1+=2
#NO_APP
         addl    $20, r1
#APP
         #end ops r1+=2
         #start ops r1*=2
#NO_APP
         sall    $10, r1
#APP
         #end ops r1*=2
         #start ops f1+=2.0
#NO_APP
         flds    .LC2
         fldl    f1
         fadd    %st(1), %st
         fadd    %st(1), %st
         fadd    %st(1), %st
         fadd    %st(1), %st
         fadd    %st(1), %st
         fadd    %st(1), %st
         fadd    %st(1), %st
         fadd    %st(1), %st
         fadd    %st(1), %st
         faddp   %st, %st(1)
         fstpl   f1
#APP
         #end ops f1+=2.0
         #start ops f1*=2.0
#NO_APP
         fldl    f1
         fadd    %st(0), %st
         fadd    %st(0), %st
         fadd    %st(0), %st
         fadd    %st(0), %st
         fadd    %st(0), %st
         fadd    %st(0), %st
         fadd    %st(0), %st
         fadd    %st(0), %st
         fadd    %st(0), %st
         fadd    %st(0), %st
         fstpl   f1
#APP
         #end ops f1*=2.0
-------------- next part --------------
A non-text attachment was scrubbed...
Name: t1.c
Type: text/x-csrc
Size: 435 bytes
Desc: not available
URL: <http://lists.mplayerhq.hu/pipermail/ffmpeg-devel/attachments/20050520/95fe1c5c/attachment.c>



More information about the ffmpeg-devel mailing list