performance issues in simple arithmetic code

Tyson Whitehead twhitehead at gmail.com
Thu Apr 28 06:30:11 CEST 2011


On April 27, 2011 23:01:50 Denys Rtveliashvili wrote:
> Question 1: what is the meaning of those magic numbers
> -9223372036854775808, -6677706553, -7418931981405, -8257271295304186?
> Question 2: under which circumstances those strange branches of
> execution will be used and what those results would mean?
> Question 3: why is the Core for 'foo' so different to 'bar'?

The largest representable 64bit negative number in twos complement is 
-9223372036854775808.  It doesn't have a positive counter part as 0 eats one 
out of the range of positive numbers.

The code for "quot x y" therefore checks for the special case "x==minBound" 
and "y==-1" in order to be able to thrown an overFlowError.  I suspect what 
you are seeing is a specialization for this branch.

That is, the start of the overflow case check introduced a branch for 
x==-9223372036854775808.  The compiler then notices that it know both x and y 
here, so it just puts in the answer, resulting in a permanent special case.

Your foo and bar code is so different as direct use of the quotInt# primitive 
avoids this check and hence the resulting specialization for it.

Cheers!  -Tyson
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 490 bytes
Desc: This is a digitally signed message part.
URL: <http://www.haskell.org/pipermail/glasgow-haskell-users/attachments/20110428/c0c6817c/attachment.pgp>


More information about the Glasgow-haskell-users mailing list