Skip to content
Snippets Groups Projects
  1. May 21, 2018
    • Jeff Epler's avatar
      py/mpz: Avoid undefined behavior at integer overflow in mpz_hash. · c4dafcef
      Jeff Epler authored
      Before this, ubsan would detect a problem when executing
      hash(006699999999999999999999999999999999999999999999999999999999999999999999)
      
          ../../py/mpz.c:1539:20: runtime error: left shift of 1067371580458 by
          32 places cannot be represented in type 'mp_int_t' (aka 'long')
      
      When the overflow does occur it now happens as defined by the rules of
      unsigned arithmetic.
      c4dafcef
  2. Feb 25, 2018
    • Damien George's avatar
      py/mpz: In mpz_clone, remove unused check for NULL dig. · f75c7ad1
      Damien George authored
      This path for src->deg==NULL is never used because mpz_clone() is always
      called with an argument that has a non-zero integer value, and hence has
      some digits allocated to it (mpz_clone() is a static function private to
      mpz.c all callers of this function first check if the integer value is zero
      and if so take a special-case path, bypassing the call to mpz_clone()).
      
      There is some unused and commented-out functions that may actually pass a
      zero-valued mpz to mpz_clone(), so some TODOs are added to these function
      in case they are needed in the future.
      f75c7ad1
  3. Dec 29, 2017
    • Damien George's avatar
      py/mpz: In mpz_as_str_inpl, convert always-false checks to assertions. · e7842744
      Damien George authored
      There are two checks that are always false so can be converted to (negated)
      assertions to save code space and execution time.  They are:
      
      1. The check of the str parameter, which is required to be non-NULL as per
         the original comment that it has enough space in it as calculated by
         mp_int_format_size.  And for all uses of this function str is indeed
         non-NULL.
      
      2. The check of the base parameter, which is already required to be between
         2 and 16 (inclusive) via the assertion in mp_int_format_size.
      e7842744
    • Damien George's avatar
      py/mpz: Simplify handling of borrow and quo adjustment in mpn_div. · 9766fddc
      Damien George authored
      The motivation behind this patch is to remove unreachable code in mpn_div.
      This unreachable code was added some time ago in
      9a21d2e0, when a loop in mpn_div was copied
      and adjusted to work when mpz_dig_t was exactly half of the size of
      mpz_dbl_dig_t (a common case).  The loop was copied correctly but it wasn't
      noticed at the time that the final part of the calculation of num-quo*den
      could be optimised, and hence unreachable code was left for a case that
      never occurred.
      
      The observation for the optimisation is that the initial value of quo in
      mpn_div is either exact or too large (never too small), and therefore the
      subtraction of quo*den from num may subtract exactly enough or too much
      (but never too little).  Using this observation the part of the algorithm
      that handles the borrow value can be simplified, and most importantly this
      eliminates the unreachable code.
      
      The new code has been tested with DIG_SIZE=3 and DIG_SIZE=4 by dividing all
      possible combinations of non-negative integers with between 0 and 3
      (inclusive) mpz digits.
      9766fddc
  4. Dec 19, 2017
  5. Jul 31, 2017
  6. Jul 25, 2017
  7. Apr 25, 2017
  8. Feb 16, 2017
  9. Feb 02, 2017
  10. Jan 21, 2017
  11. Dec 28, 2016
  12. Dec 13, 2016
  13. Oct 31, 2016
  14. Oct 11, 2016
  15. May 09, 2016
    • Damien George's avatar
      py/mpz: Fix mpn_div so that it doesn't modify memory of denominator. · 460b0863
      Damien George authored
      Previous to this patch bignum division and modulo would temporarily
      modify the RHS argument to the operation (eg x/y would modify y), but on
      return the RHS would be restored to its original value.  This is not
      allowed because arguments to binary operations are const, and in
      particular might live in ROM.  The modification was to normalise the arg
      (and then unnormalise before returning), and this patch makes it so the
      normalisation is done on the fly and the arg is now accessed as read-only.
      
      This change doesn't increase the order complexity of the operation, and
      actually reduces code size.
      460b0863
  16. May 08, 2016
  17. Feb 03, 2016
    • Damien George's avatar
      py/mpz: Add commented-out mpz_pow3_inpl function, to compute (x**y)%z. · ff1a96ce
      Damien George authored
      This function computes (x**y)%z in an efficient way.  For large arguments
      this operation is otherwise not computable by doing x**y and then %z.
      
      It's currently not used, but is added in case it's useful one day.
      ff1a96ce
    • Doug Currie's avatar
      py/mpz: Complete implementation of mpz_{and,or,xor} for negative args. · 2e2e15ce
      Doug Currie authored
      For these 3 bitwise operations there are now fast functions for
      positive-only arguments, and general functions for arbitrary sign
      arguments (the fast functions are the existing implementation).
      
      By default the fast functions are not used (to save space) and instead
      the general functions are used for all operations.
      
      Enable MICROPY_OPT_MPZ_BITWISE to use the fast functions for positive
      arguments.
      2e2e15ce
  18. Jan 08, 2016
  19. Nov 22, 2015
  20. Oct 01, 2015
  21. Apr 25, 2015
  22. Apr 22, 2015
  23. Apr 09, 2015
  24. Mar 12, 2015
  25. Mar 02, 2015
  26. Jan 27, 2015
  27. Jan 24, 2015
Loading