[commit: packages/integer-gmp] wip/T8647: Allocate initial 1-limb mpz_t on the Stack and introduce MPZ# type (20d7bfd)

classic Classic list List threaded Threaded
1 message Options
Reply | Threaded
Open this post in threaded view
|

[commit: packages/integer-gmp] wip/T8647: Allocate initial 1-limb mpz_t on the Stack and introduce MPZ# type (20d7bfd)

Simon Peyton Jones
Would it be worth adding some info from the commit message to the comment with type MPZ#?  In particular, the little table you give in the commit message is helpful, but someone looking at the code won't see it.  This is subtle stuff.

Simon

| -----Original Message-----
| From: ghc-commits [mailto:ghc-commits-bounces at haskell.org] On Behalf Of
| git at git.haskell.org
| Sent: 12 January 2014 23:37
| To: ghc-commits at haskell.org
| Subject: [commit: packages/integer-gmp] wip/T8647: Allocate initial 1-
| limb mpz_t on the Stack and introduce MPZ# type (20d7bfd)
|
| Repository : ssh://git at git.haskell.org/integer-gmp
|
| On branch  : wip/T8647
| Link       :
| http://ghc.haskell.org/trac/ghc/changeset/20d7bfdd29917f5a8b8937fba9b724
| f7e71cd8dd/integer-gmp
|
| >---------------------------------------------------------------
|
| commit 20d7bfdd29917f5a8b8937fba9b724f7e71cd8dd
| Author: Herbert Valerio Riedel <hvr at gnu.org>
| Date:   Thu Jan 9 00:19:31 2014 +0100
|
|     Allocate initial 1-limb mpz_t on the Stack and introduce MPZ# type
|
|     We now allocate a 1-limb mpz_t on the stack instead of doing a more
|     expensive heap-allocation (especially if the heap-allocated copy
| becomes
|     garbage right away); this addresses #8647.
|
|     In order to delay heap allocations of 1-limb `ByteArray#`s instead
| of
|     the previous `(# Int#, ByteArray# #)` pair, a 3-tuple
|     `(# Int#, ByteArray#, Word# #)` is returned now. This tuple is given
| the
|     type-synonym `MPZ#`.
|
|     This 3-tuple representation uses either the 1st and the 2nd element,
| or
|     the 1st and the 3rd element to represent the limb(s) (NB: undefined
|     `ByteArray#` elements must not be accessed as they don't point to a
|     proper `ByteArray#`, see also `DUMMY_BYTE_ARR`); more specifically,
| the
|     following encoding is used (where `?` means undefined/unused):
|
|      -  (#  0#, ?, 0## #) -> value = 0
|      -  (#  1#, ?, w   #) -> value = w
|      -  (# -1#, ?, w   #) -> value = -w
|      -  (#  s#, d, 0## #) -> value = J# s d
|
|     The `mpzToInteger` helper takes care of converting `MPZ#` into an
|     `Integer`, and allocating a 1-limb `ByteArray#` in case the
|     value (`w`/`-w`) doesn't fit the `S# Int#` representation).
|
|     The following nofib benchmarks benefit from this optimization:
|
|             Program      Size    Allocs   Runtime   Elapsed  TotalMem
|      ------------------------------------------------------------------
|          bernouilli     +0.2%     -5.2%      0.12      0.12     +0.0%
|              gamteb     +0.2%     -1.7%      0.03      0.03     +0.0%
|               kahan     +0.3%    -13.2%      0.17      0.17     +0.0%
|              mandel     +0.2%    -24.6%      0.04      0.04     +0.0%
|               power     +0.2%     -2.6%     -2.0%     -2.0%     -8.3%
|           primetest     +0.1%    -17.3%      0.06      0.06     +0.0%
|                 rsa     +0.2%    -18.5%      0.02      0.02     +0.0%
|                 scs     +0.1%     -2.9%     -0.1%     -0.1%     +0.0%
|              sphere     +0.3%     -0.8%      0.03      0.03     +0.0%
|              symalg     +0.2%     -3.1%      0.01      0.01     +0.0%
|      ------------------------------------------------------------------
|                 Min     +0.1%    -24.6%     -4.6%     -4.6%     -8.3%
|                 Max     +0.3%     +0.0%     +5.9%     +5.9%     +4.5%
|      Geometric Mean     +0.2%     -1.0%     +0.2%     +0.2%     -0.0%
|
|     Signed-off-by: Herbert Valerio Riedel <hvr at gnu.org>
|
|
| >---------------------------------------------------------------
|
| 20d7bfdd29917f5a8b8937fba9b724f7e71cd8dd
|  GHC/Integer/GMP/Prim.hs |   88 ++++++++++++-------
|  GHC/Integer/Type.lhs    |  160 +++++++++++++++------------------
|  cbits/gmp-wrappers.cmm  |  224 +++++++++++++++++++++++++++++++++-------
| -------
|  3 files changed, 285 insertions(+), 187 deletions(-)
|
| Diff suppressed because of size. To see it, use:
|
|     git diff-tree --root --patch-with-stat --no-color --find-copies-
| harder --ignore-space-at-eol --cc
| 20d7bfdd29917f5a8b8937fba9b724f7e71cd8dd
| _______________________________________________
| ghc-commits mailing list
| ghc-commits at haskell.org
| http://www.haskell.org/mailman/listinfo/ghc-commits