[GHC] #9281: Rewrite `integer-gmp` to use only non-allocating GMP functions

GHC ghc-devs at haskell.org
Sun Jul 20 17:43:14 UTC 2014


#9281: Rewrite `integer-gmp` to use only non-allocating GMP functions
-------------------------------------+-------------------------------------
              Reporter:  hvr         |             Owner:  hvr
                  Type:  task        |            Status:  patch
              Priority:  normal      |         Milestone:  7.10.1
             Component:  libraries   |           Version:
  (other)                            |          Keywords:  integer-gmp
            Resolution:              |  Operating System:  Unknown/Multiple
Differential Revisions:  Phab:D82    |   Type of failure:  None/Unknown
          Architecture:              |         Test Case:
  Unknown/Multiple                   |          Blocking:
            Difficulty:  Unknown     |
            Blocked By:              |
       Related Tickets:  #8647       |
-------------------------------------+-------------------------------------
Changes (by hvr):

 * status:  new => patch
 * differential:   => Phab:D82
 * related:   => #8647


Comment:

 Here's a first [Phab:D82 draft version]. The number of library calls going
 into GMP (via `ltrace -c`, which btw is a wonderful tool for that) is
 essentially the same (in some cases slightly lower, as the new code is a
 bit more clever in some ways). However, I'm seeing improvements as well as
 regressions in the Nofib results (see Phab:P6). I still need to figure out
 what the reason is for the rather visible allocation increase in
 `primetest` (and maybe `kahan` and `bernouilli`).

 It could be this different approach undoes part of #8647, as we can't so
 easily optimistically allocate temporary single-limbs on the stack (on the
 bright side, we've got almost no Cmm code anymore...)


 Btw, while implementing the code, I would have wanted to write

 {{{#!hs

 foreign import ccall unsafe "integer_gmp_mpn_tdiv_q"
   c_mpn_tdiv_q :: MutableByteArray# s -> ByteArray# -> GmpSize# ->
 ByteArray# -> GmpSize# -> State# s -> State# s

 foreign import ccall unsafe "gmp.h __gmpn_divrem_1"
   c_mpn_divrem_1 :: MutableByteArray# s -> GmpSize# -> ByteArray# ->
 GmpSize# -> GmpLimb# -> State# s -> (# s, Word# #)
 }}}

 However, GHC insisted on having me to write `... -> IO ()` and `... -> IO
 Word` respectively, thus forcing a boxed/lifted `Word` even though `{-#
 LANGUAGE UnliftedFFITypes #-}` was in effect. Any chance to have unlifted
 types allowed for `IO`-like FFI ccalls to reduce the overhead?

--
Ticket URL: <http://ghc.haskell.org/trac/ghc/ticket/9281#comment:4>
GHC <http://www.haskell.org/ghc/>
The Glasgow Haskell Compiler


More information about the ghc-tickets mailing list