[GHC] #7041: GHC.Real.gcdInt is no longer optimized.
GHC
cvs-ghc at haskell.org
Sat Jul 14 00:12:58 CEST 2012
#7041: GHC.Real.gcdInt is no longer optimized.
-------------------------------+--------------------------------------------
Reporter: int-e | Owner:
Type: bug | Status: new
Priority: high | Milestone: 7.6.1
Component: libraries/base | Version: 7.5
Resolution: | Keywords:
Os: Unknown/Multiple | Architecture: Unknown/Multiple
Failure: None/Unknown | Difficulty: Unknown
Testcase: | Blockedby:
Blocking: | Related:
-------------------------------+--------------------------------------------
Changes (by simonpj):
* owner: igloo =>
* status: closed => new
* resolution: fixed =>
Comment:
1. There is no mention of `smallInteger` in the wiki page.
[http://hackage.haskell.org/trac/ghc/wiki/Commentary/Libraries/Integer]
It took me a while, but I got there, and augmented the page. Can you
check I’m right?
2. There are ''some'' rules in `PrelRules` with a (correct) comment saying
{{{
-- These rules below don't actually have to be built in, but if we
-- put them in the Haskell source then we'd have to duplicate them
-- between all Integer implementations
}}}
But then in `integer-gmp:GHC/Integer/Type.hs` we have other RULES that
also should be duplicated in other integer packages (but aren’t). One of
these is the gcd rule altered in this patch. Why did you decide to do one
thing for some rules and another for the others?
3. Also what is special about GCD here? What about
{{{
integerToInt (plusInteger (smallInteger a) (smallInteger b))
}}}
Maybe it’s just that the result of gcd is guaranteed to be small? Even in
the case, presumably integerToInt is undefined if the result doesn’t fit
in an Int, so we could indeed say that
{{{
integerToInt (plusInteger (smallInteger a) (smallInteger b)) = plusInt
a b
}}}
But is this common enough to worry about? It seems most odd to have a
RULE like this for GCD but not for +!!
4. Coming back to this ticket #7041 it seems utterly bonkers that in
`base:GHC.Real` we have
{{{
gcdInt :: Int -> Int -> Int
gcdInt a b = fromIntegral (gcdInteger (fromIntegral a) (fromIntegral b))
}}}
This is then laboriously converted (by the new RULE ) to, guess what, a
call to
`ghc-integer:GHC.Integer.Type.gcdInt`, which is defined (in that module)
{{{
gcdInt :: Int# -> Int# -> Int#
gcdInt 0# y = absInt y
gcdInt x 0# = absInt x
gcdInt x y = gcdInt# (absInt x) (absInt y)
}}}
This is madness. Why don’t we define `gcdInt` in that way in
`base:GHC.Real`, and get rid of the bizarre special treatment of GCD.
Which we only needed because its definition in `GHC.Real` stupidly went
via Integer.
Simon
--
Ticket URL: <http://hackage.haskell.org/trac/ghc/ticket/7041#comment:5>
GHC <http://www.haskell.org/ghc/>
The Glasgow Haskell Compiler
More information about the Glasgow-haskell-bugs
mailing list