<feed xmlns='http://www.w3.org/2005/Atom'>
<title>suspect-devices/circuitpython/py/mpz.c, branch 5.1.0</title>
<subtitle>CircuitPython - a Python implementation for teaching coding with microcontrollers</subtitle>
<id>https://git.suspectdevices.com/suspect-devices/circuitpython/atom?h=5.1.0</id>
<link rel='self' href='https://git.suspectdevices.com/suspect-devices/circuitpython/atom?h=5.1.0'/>
<link rel='alternate' type='text/html' href='https://git.suspectdevices.com/suspect-devices/circuitpython/'/>
<updated>2018-05-21T02:48:26+00:00</updated>
<entry>
<title>py/mpz: Avoid undefined behavior at integer overflow in mpz_hash.</title>
<updated>2018-05-21T02:48:26+00:00</updated>
<author>
<name>Jeff Epler</name>
<email>jepler@gmail.com</email>
</author>
<published>2018-05-19T16:20:29+00:00</published>
<link rel='alternate' type='text/html' href='https://git.suspectdevices.com/suspect-devices/circuitpython/commit/?id=c4dafcef4fe9edaacaeeb16c412c298cbab3b414'/>
<id>urn:sha1:c4dafcef4fe9edaacaeeb16c412c298cbab3b414</id>
<content type='text'>
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.
</content>
</entry>
<entry>
<title>py/mpz: In mpz_clone, remove unused check for NULL dig.</title>
<updated>2018-02-25T11:59:19+00:00</updated>
<author>
<name>Damien George</name>
<email>damien.p.george@gmail.com</email>
</author>
<published>2018-02-25T11:59:19+00:00</published>
<link rel='alternate' type='text/html' href='https://git.suspectdevices.com/suspect-devices/circuitpython/commit/?id=f75c7ad1a9dcfa2cfe5ccd12dda7c396a6bd973c'/>
<id>urn:sha1:f75c7ad1a9dcfa2cfe5ccd12dda7c396a6bd973c</id>
<content type='text'>
This path for src-&gt;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.
</content>
</entry>
<entry>
<title>py/mpz: In mpz_as_str_inpl, convert always-false checks to assertions.</title>
<updated>2017-12-29T03:17:55+00:00</updated>
<author>
<name>Damien George</name>
<email>damien.p.george@gmail.com</email>
</author>
<published>2017-12-28T03:14:06+00:00</published>
<link rel='alternate' type='text/html' href='https://git.suspectdevices.com/suspect-devices/circuitpython/commit/?id=e78427443094163d1839387a2470fd22612ca8d1'/>
<id>urn:sha1:e78427443094163d1839387a2470fd22612ca8d1</id>
<content type='text'>
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.
</content>
</entry>
<entry>
<title>py/mpz: Simplify handling of borrow and quo adjustment in mpn_div.</title>
<updated>2017-12-29T03:05:48+00:00</updated>
<author>
<name>Damien George</name>
<email>damien.p.george@gmail.com</email>
</author>
<published>2017-12-28T03:02:36+00:00</published>
<link rel='alternate' type='text/html' href='https://git.suspectdevices.com/suspect-devices/circuitpython/commit/?id=9766fddcdc29cb2b5a8657389b870703580a6e57'/>
<id>urn:sha1:9766fddcdc29cb2b5a8657389b870703580a6e57</id>
<content type='text'>
The motivation behind this patch is to remove unreachable code in mpn_div.
This unreachable code was added some time ago in
9a21d2e070c9ee0ef2c003f3a668e635c6ae4401, 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.
</content>
</entry>
<entry>
<title>py/mpz: Apply a small code-size optimisation.</title>
<updated>2017-12-19T04:45:56+00:00</updated>
<author>
<name>Damien George</name>
<email>damien.p.george@gmail.com</email>
</author>
<published>2017-12-19T04:45:56+00:00</published>
<link rel='alternate' type='text/html' href='https://git.suspectdevices.com/suspect-devices/circuitpython/commit/?id=ae1be76d4063997b2703ba1ac9d009b31bc06eca'/>
<id>urn:sha1:ae1be76d4063997b2703ba1ac9d009b31bc06eca</id>
<content type='text'>
</content>
</entry>
<entry>
<title>py/mpz: Fix pow3 function so it handles the case when 3rd arg is 1.</title>
<updated>2017-12-19T04:42:58+00:00</updated>
<author>
<name>Damien George</name>
<email>damien.p.george@gmail.com</email>
</author>
<published>2017-12-19T04:42:58+00:00</published>
<link rel='alternate' type='text/html' href='https://git.suspectdevices.com/suspect-devices/circuitpython/commit/?id=374eaf5271c9bfc63b5aa1139de55753ad67cc9a'/>
<id>urn:sha1:374eaf5271c9bfc63b5aa1139de55753ad67cc9a</id>
<content type='text'>
In this case the result should always be 0, even if 2nd arg is 0.
</content>
</entry>
<entry>
<title>all: Use the name MicroPython consistently in comments</title>
<updated>2017-07-31T08:35:40+00:00</updated>
<author>
<name>Alexander Steffen</name>
<email>devel.20.webmeister@spamgourmet.com</email>
</author>
<published>2017-06-30T07:22:17+00:00</published>
<link rel='alternate' type='text/html' href='https://git.suspectdevices.com/suspect-devices/circuitpython/commit/?id=55f33240f3d7051d4213629e92437a36f1fac50e'/>
<id>urn:sha1:55f33240f3d7051d4213629e92437a36f1fac50e</id>
<content type='text'>
There were several different spellings of MicroPython present in comments,
when there should be only one.
</content>
</entry>
<entry>
<title>py: Implement raising a big-int to a negative power.</title>
<updated>2017-07-25T01:49:22+00:00</updated>
<author>
<name>Damien George</name>
<email>damien.p.george@gmail.com</email>
</author>
<published>2017-07-25T01:49:22+00:00</published>
<link rel='alternate' type='text/html' href='https://git.suspectdevices.com/suspect-devices/circuitpython/commit/?id=04552ff71b6c722b21597d93481f024c72457cef'/>
<id>urn:sha1:04552ff71b6c722b21597d93481f024c72457cef</id>
<content type='text'>
Before this patch raising a big-int to a negative power would just return
0.  Now it returns a floating-point number with the correct value.
</content>
</entry>
<entry>
<title>py/mpz: Make mpz_is_zero() an inline function.</title>
<updated>2017-07-25T01:32:04+00:00</updated>
<author>
<name>Damien George</name>
<email>damien.p.george@gmail.com</email>
</author>
<published>2017-07-25T01:32:04+00:00</published>
<link rel='alternate' type='text/html' href='https://git.suspectdevices.com/suspect-devices/circuitpython/commit/?id=4d1fb6107fdedb0dda8dfb1491c033bf731222c6'/>
<id>urn:sha1:4d1fb6107fdedb0dda8dfb1491c033bf731222c6</id>
<content type='text'>
It's more efficient as an inline function, and saves code size.
</content>
</entry>
<entry>
<title>py/mpz: In mpn_sub, use existing function to remove trailing zeros.</title>
<updated>2017-04-25T02:22:04+00:00</updated>
<author>
<name>Damien George</name>
<email>damien.p.george@gmail.com</email>
</author>
<published>2017-04-25T02:22:04+00:00</published>
<link rel='alternate' type='text/html' href='https://git.suspectdevices.com/suspect-devices/circuitpython/commit/?id=f85fd79c6c37cdbd32d9edc37efc985f1f4bc3bb'/>
<id>urn:sha1:f85fd79c6c37cdbd32d9edc37efc985f1f4bc3bb</id>
<content type='text'>
</content>
</entry>
</feed>
