1. 26 Feb, 2014 1 commit
    • Austin Seipp's avatar
      Fix GMP v4 compatibility. · d7bff4dd
      Austin Seipp authored
      
      
      We had started relying on GMP 5.x (for usage of mpz_powm_sec), but this
      is pretty painful on RHEL-esque targets, which still use GMP 4.x.
      
      In the mean time while we're still supporting this, it's easier to just
      fallback to mpz_powm when _sec is unavailable, and emit a WARNING for
      using the primitive.
      
      This also installs a header, HsIntegerGmp.h, which clients could use for
      a fallback.
      
      As a side note, this will probably also help Debian oldstable users who
      might have outdated GMP versions (which I believe is the cause for #8666.)
      Reviewed-by: Herbert Valerio Riedel's avatarHerbert Valerio Riedel <hvr@gnu.org>
      Signed-off-by: default avatarAustin Seipp <austin@well-typed.com>
      d7bff4dd
  2. 02 Feb, 2014 1 commit
    • Herbert Valerio Riedel's avatar
      Fix negation of `divMod`/`quotRem` results (fixes #8726) · 2f841fdf
      Herbert Valerio Riedel authored
      
      
      High-level pseudo code of what the code was supposed to implement:
      
          quotRem' :: Integer -> Integer -> (Integer,Integer)
          quotRem' a b@(S# _)
            | b < 0     = negFst . uncurry quotRem' . negSnd $ (a,b)
            | otherwise = quotRemUI a (fromIntegral (abs b))
      
          divMod' :: Integer -> Integer -> (Integer,Integer)
          divMod' a b@(S# _)
            | b < 0      = negSnd . uncurry divMod' . negBoth $ (a,b)
            | otherwise  = divModUI a (fromIntegral b)
      
          negFst  (q,r) = (-q,r)
          negSnd  (q,r) = ( q,-r)
          negBoth (q,r) = (-q,-r)
      
          -- quotRemUI and divModUI represent GMP's `mpz_{f,t}div_qr_ui()`
          quotRemUI, divModUI :: Integer -> Word -> (Integer,Integer)
      Signed-off-by: Herbert Valerio Riedel's avatarHerbert Valerio Riedel <hvr@gnu.org>
      2f841fdf
  3. 01 Feb, 2014 2 commits
  4. 31 Jan, 2014 1 commit
  5. 16 Jan, 2014 2 commits
  6. 14 Jan, 2014 2 commits
  7. 13 Jan, 2014 2 commits
    • Herbert Valerio Riedel's avatar
      Wrap `gmpz_fdiv_{q,r,qr}_ui` to optimize `div`/`mod` · cbde8627
      Herbert Valerio Riedel authored
      This is similiar to what has been done in [af2ba9c8
      
      /integer-gmp] for
      `gmpz_tdiv_{q,r,qr}_ui` (re #8647); However, the gain is more modest
      here, as performance-conscious code tends to use `quot`/`rem` rather
      than `div`/`mod`:
      
           Program    Size    Allocs   Runtime   Elapsed  TotalMem
       -------------------------------------------------------------
         primetest   +0.3%     -2.4%      0.06      0.06     +0.0%
               rsa   +0.2%     -3.3%      0.02      0.02     +0.0%
      Signed-off-by: Herbert Valerio Riedel's avatarHerbert Valerio Riedel <hvr@gnu.org>
      cbde8627
    • Herbert Valerio Riedel's avatar
      Allocate initial 1-limb mpz_t on the Stack and introduce MPZ# type · 7bdcadda
      Herbert Valerio Riedel authored
      
      
      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's avatarHerbert Valerio Riedel <hvr@gnu.org>
      7bdcadda
  8. 10 Jan, 2014 3 commits
  9. 08 Jan, 2014 2 commits
  10. 07 Jan, 2014 1 commit
    • Austin Seipp's avatar
      Hackishly fix parallel build failure with in-tree GMP · 8ed8ac58
      Austin Seipp authored
      
      
      See the comments and #8102. The basic gist of it seems to be that the
      build system follows an implied rule from somewhere to directly build a
      C file, which doesn't have a dependency on the in-tree gmp.h that we
      build. As a result, the C file compilation races against the GMP build,
      causing an error.
      
      This is a pretty unsatisfactory hack, but for Windows and OS X machines
      where we more often build in-tree GMPs, it's quite important.
      Authored-by: kazu-yamamoto's avatarKazu Yamamoto <kazu@iij.ad.jp>
      Signed-off-by: default avatarAustin Seipp <austin@well-typed.com>
      8ed8ac58
  11. 04 Jan, 2014 3 commits
    • Herbert Valerio Riedel's avatar
      Add new `mpz_{sub,add}_ui`-based primop (re #8647) · 8bf95419
      Herbert Valerio Riedel authored
      This adds `{plus,minus}IntegerInt#` which help to reduce temporary
      allocations in `plusInteger` and `minusInteger`.
      
      This and the previous commit introducing `timesIntegerInt#` (i.e. baeeef7a
      
      )
      result in reduced allocations for the following nofib benchmarks on Linux/amd64:
      
               Program      Size    Allocs   Runtime   Elapsed  TotalMem
        ------------------------------------------------------------------
            bernouilli     +0.0%     -4.2%      0.12      0.12     +0.0%
                 kahan     +0.1%    -12.6%      0.17      0.17     +0.0%
              pidigits     +0.0%     -0.5%     -4.7%     -4.5%     +0.0%
                 power     +0.0%     -2.7%     +3.1%     +3.1%     +9.1%
             primetest     +0.0%     -4.2%      0.07      0.07     +0.0%
                   rsa     +0.0%     -4.1%      0.02      0.02     +0.0%
                   scs     +0.0%     -2.6%     -0.8%     -0.7%     +0.0%
        ------------------------------------------------------------------
                   Min     +0.0%    -12.6%     -4.7%     -4.5%     -5.0%
                   Max     +0.1%     +0.2%     +3.1%     +3.1%     +9.1%
        Geometric Mean     +0.1%     -0.3%     -0.0%     +0.0%     +0.1%
        ------------------------------------------------------------------
      Signed-off-by: Herbert Valerio Riedel's avatarHerbert Valerio Riedel <hvr@gnu.org>
      8bf95419
    • Herbert Valerio Riedel's avatar
      Add new `mpz_mul_si`-based primop (re #8647) · baeeef7a
      Herbert Valerio Riedel authored
      
      
      This primop helps reducing allocation by being able to pass one `S#`
      argument directly to the GMP multiplication primitive without needing to
      promote (and thus allocate a `ByteArray#` as well) the `J#` first.
      
      This benefits a few nofib benchmarks wrt to allocations (having most
      impact on `kahan` resulting in about 10% less allocations)
      Signed-off-by: Herbert Valerio Riedel's avatarHerbert Valerio Riedel <hvr@gnu.org>
      baeeef7a
    • Herbert Valerio Riedel's avatar
      Refactor C-- wrappers to use macros for mpz_t access · ebec3089
      Herbert Valerio Riedel authored
      
      
      This factors out the recurring task of converting mpz_t structures
      to/from Int#/ByteArrays# pairs and makes the code more readable.
      Signed-off-by: Herbert Valerio Riedel's avatarHerbert Valerio Riedel <hvr@gnu.org>
      ebec3089
  12. 03 Jan, 2014 3 commits
  13. 02 Jan, 2014 1 commit
  14. 24 Nov, 2013 1 commit
  15. 07 Nov, 2013 4 commits
  16. 05 Nov, 2013 2 commits
  17. 28 Oct, 2013 1 commit
  18. 27 Oct, 2013 1 commit
  19. 24 Oct, 2013 3 commits
  20. 29 Sep, 2013 2 commits
  21. 16 Sep, 2013 1 commit
  22. 11 Sep, 2013 1 commit