hrm...

Simon Peyton-Jones simonpj at microsoft.com
Mon Jan 29 10:52:44 EST 2007


Bertram, Don, John

You are hot on the trail.  Indeed you can probably find out what is going on, and how to fix it, as fast as we can, since this is all paged out of my brain.

One plausible place to look would be Inst.shortCutIntLit; add a case for Word similar to that for Int and Integer.  The only downside of this is that it works when it's clear *at the moment the literal is seen* that it's a Word.  In principle, this knowledge might arise later in type inference.  But in practice I think it'll do just what you want.

It'd be possible to do something cleverer later, but I'm not sure it'd be necessary.

I don't think it's an off-by-one thing John.

If you guys can come up with a patch, I'll check it over.

Simon

| -----Original Message-----
| From: glasgow-haskell-users-bounces at haskell.org [mailto:glasgow-haskell-users-bounces at haskell.org] On
| Behalf Of Bertram Felgenhauer
| Sent: 28 January 2007 15:41
| To: glasgow-haskell-users at haskell.org
| Subject: Re: hrm...
|
| Donald Bruce Stewart wrote:
| > john:
| > > so I have this simple bit of code, which should be fast but seems to be
| > > being compiled to something very slow.
| > >
| > > > import Data.Word
| > > > import Data.Bits
| > > >
| > > > fhb :: Word -> Word
| > > > fhb w = b1 .|. b2  where
| > > >     b2 = if 0xFFFF0000 .&. w /= 0 then 0x2 else 0
| > > >     b1 = if 0xFF00FF00 .&. w /= 0 then 0x1 else 0
|
| >     M.lit =
| >       case GHC.Prim.addIntC# 2147418113 2147483647
|
| If I understand the code correctly this happens in the desugaring pass
| already. The literal 0xFFFF0000 exceeds the range of Int so it's expressed
| with smaller numbers (see deSugar/DsUtils.lhs, mkIntegerExpr); in this
| case it becomes  fromInteger (0x70000001 + 0x7FFFFFFF), which matches
| the above line exactly.
|
| Btw, the comment in rename/RnTypes about this
| ("Big integer literals are built [...]") is wrong, as it refers to
| mkIntegerLit instead of mkIntegerExpr.
|
| This suggests that as a workaround, using -0x00010000 and -0x00FF0100
| should help (but the code will depend on the word size then).
|
| Bertram
| _______________________________________________
| Glasgow-haskell-users mailing list
| Glasgow-haskell-users at haskell.org
| http://www.haskell.org/mailman/listinfo/glasgow-haskell-users


More information about the Glasgow-haskell-users mailing list