hrm...

Bertram Felgenhauer bertram.felgenhauer at googlemail.com
Sun Jan 28 10:40:44 EST 2007


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


More information about the Glasgow-haskell-users mailing list