[Haskell-cafe] Int is broken [Was: Different answers on different machines]

Tommy Thorn tt1729 at yahoo.com
Mon Jun 3 10:19:39 CEST 2013

On Jun 3, 2013, at 00:23 , Carter Schonwald <carter.schonwald at gmail.com> wrote:

> Int is "native register sized integer"

Actually it's not. Read the definition. Int is only guaranteed to be 29 bits.

Here's *one* _actual_ data point (from a 2.8 GHz i7, 64-bit code):

time ./fib
fib(43) = 701408733
        3.27 real         3.27 user         0.00 sys
time ./fib-safe
fib(43) = 701408733
        3.45 real         3.45 user         0.00 sys

(NB: I do not check the n-1 and n-2 as it's trivial to see from a data flow analysis
that the proceeding conditional guarantees that those can't overflow.
The empty asm() is necessary to get GCC to generate comparable code).

-------------- next part --------------
A non-text attachment was scrubbed...
Name: fib.c
Type: application/octet-stream
Size: 440 bytes
Desc: not available
URL: <http://www.haskell.org/pipermail/haskell-cafe/attachments/20130603/1e99390e/attachment.obj>
-------------- next part --------------

Obviously, for some examples this will be much worse, for others, much better, but without
this implemented in GHC it will be difficult to measure.


More information about the Haskell-Cafe mailing list