<div class="gmail_quote">On Tue, Aug 9, 2011 at 9:47 AM, Chris Yuen <span dir="ltr">&lt;<a href="mailto:kizzx2%2Bhaskell@gmail.com">kizzx2+haskell@gmail.com</a>&gt;</span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex;">
<br>- I was using GHC 32-bit. Int is 32-bit there, so I needed Int64. It turns out 64-bit operations in 32-bit programs are just darn slow. Maybe it&#39;s a Windows problem.</blockquote><div><br></div><div>No, GHC calls out to C for 64-bit integer ops on all 32-bit platforms.</div>
<div> </div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex;"> On Linux 64 bit GHC Int is 64 bit so everything just works. Changing Int64 to Int liberates me from many `fromIntegral` which saved 20%<br>
</blockquote><div><br></div><div>Actually, fromIntegral is usually a no-op, so chances are you&#39;re seeing the effect of something else.</div><div> </div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex;">


- Changing `divMod` to `quotRem` saved another 20%<br></blockquote><div><br></div><div>It&#39;s cheaper again to use quotInt# and remInt# as I did in my code.</div><div> </div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex;">
1. Why are bangs needed on the length arrays?</blockquote><div><br></div><div>GHC has to deconstruct the Vector in order to get at the real underlying array, so that unsafeIndex can perform the actual index into the real underlying array.</div>
<div><br></div><div>Without bang patterns, the code performs at least one deconstruction on every iteration through the loop. Each deconstruction has a cost. With the bang patterns, they&#39;re all hoisted out and performed just once.</div>
</div>