[Haskell-cafe] Very fast loops. Now!

Felipe Almeida Lessa felipe.lessa at gmail.com
Sat Feb 10 12:46:47 EST 2007


On 2/10/07, Rafael Almeida <almeidaraf at gmail.com> wrote:
> While the haskell program took so long, the C program went really faster
> than the haskell version:
>   $ gcc -O3 -ffast-math -mfpmath=sse -msse2 -std=c99 loop.c -o c_loop
>   $ time ./c_loop
>   3.333333
>
>   real    0m0.001s
>   user    0m0.000s
>   sys     0m0.000s
>   $ gcc --version
>   gcc (GCC) 4.1.2 20061115 (prerelease) (Debian 4.1.1-21)

Under gcc (GCC) 4.1.2 20060928 (prerelease) (Ubuntu 4.1.1-13ubuntu5),
the following asm code is generated for part of the main function:

mov         dword ptr [esp+4], 0aaaaaaabh
mov         dword ptr [esp+8], 400aaaaah
mov         dword ptr [esp], data_804858c
call        wrapper_8049688_80482b4

where data_804858c is "%f\n" and wrapper_8049688_80482b4 is printf.
Needless to say that the other argument is exactly the double
3.3333333333333335. In the OP's words, "newer gcc's will statically
compute that loop".

-- 
Felipe.


More information about the Haskell-Cafe mailing list