<snip>
>
> // --- do float testing ---
>
> =A0 =A0 =A0 =A0 a_f =3D 1.6;
> =A0 =A0 =A0 =A0 b_f =3D -0.33;
> =A0 =A0 =A0 =A0 for (n=3D0; n<num_iter; n++) {
> =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 c_f =3D a_f + b_f;
> =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 d_f =3D a_f - b_f;
> =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 e_f =3D a_f * b_f;
> =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 f_f =3D a_f / b_f;
> =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 a_f +=3D 3.2;
> =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 b_f -=3D 1.05;
>
<snip>
> // --- do double testing ---
>
> =A0 =A0 =A0 =A0 a_d =3D 1.6;
> =A0 =A0 =A0 =A0 b_d =3D -0.33;
> =A0 =A0 =A0 =A0 for (n=3D0; n<num_iter; n++) {
> =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 c_d =3D a_d + b_d;
> =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 d_d =3D a_d - b_d;
> =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 e_d =3D a_d * b_d;
> =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 f_d =3D a_d / b_d;
> =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 a_d +=3D 3.2;
> =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 b_d -=3D 1.05; }
>
Sorry - stupid mistake. I took a look at the ASM code - the compiler
optimizer was smart enough to figure out that the variables inside
these loops aren't used for anything, and deleted them. However, the
optimizer wasn't smart enough to figure out that the resulting empty
FOR loops aren't doing anything, either, so it left these in.
I added some printf() calls to be bottom of the function, making all
of the variables above 'relevant' and thus forcing the optimizer to
leave the FOR loop contents intact:
printf("a_f b_f c_f d_f e_f f_f =3D %f %f %f %f %f %f
\n",a_f,b_f,c_f,d_f,e_f,f_f);
printf("a_d b_d c_d d_d e_d f_d =3D %lf %lf %lf %lf %lf %lf
\n",a_d,b_d,c_d,d_d,e_d,f_d);
I then verified that the compiler is now doing the requested
mathematical operations with floats and doubles.
The new results:
Number of iterations? 50000000
Duration float, double =3D 643 361 ms
a_f b_f c_f d_f e_f f_f =3D 67108864.000000 -33554432.000000
33554432.000000 100663296.000000 -2251799813685248.000000 -2.000000
a_d b_d c_d d_d e_d f_d =3D 160000001.592189 -52500000.293033
107499999.149156 212499997.635222 -8399999794475229.000000 -3.047619
I don't know why double would be twice as fast as float, considering
that the ASM code shows a separate instruction for +,-,*,/ for both
floats and doubles. Perhaps the double math instructions take few
internal processor cycles than the float instructions. In any case, my
original conclusion still holds: I should upgrade to double.
-Steve


|