[Haskell-cafe] Re: Optimization fun

Matthew Brecknell haskell at brecknell.org
Mon Feb 12 21:57:22 EST 2007

Lennart Augustsson said:
> Many architectures gives both the quotient and remainder when you use
> the division instruction, so divMod (quotRem) shouldn't cost more  
> than a div or mod.  But if the code generator takes advantage of that
> is another matter.

You're quite right.

Bulat Ziganshin said:
> qoutRem# is primitive operation in GHC

I can see quotRemInteger# and divModInteger#, as well as quotInt#,
remInt#, divInt# and modInt#, but not quotRemInt# nor divModInt#. For

$ ghc --show-iface Num.hi

divModInt :: GHC.Base.Int -> GHC.Base.Int -> (GHC.Base.Int,
  {- Arity: 2 HasNoCafRefs Strictness: U(L)U(L)m
     (\ x :: GHC.Base.Int y :: GHC.Base.Int ->
      case @ (GHC.Base.Int, GHC.Base.Int) x of wild { I# ds ->
      case @ (GHC.Base.Int, GHC.Base.Int) y of wild1 { I# ds1 ->
      (GHC.Base.I# (GHC.Base.divInt#{1} ds ds1),
       GHC.Base.I# (GHC.Base.modInt#{1} ds ds1)) } }) -}

More information about the Haskell-Cafe mailing list