diff options
author | Angus Gratton <angus@redyak.com.au> | 2025-05-02 15:39:35 +1000 |
---|---|---|
committer | Damien George <damien@micropython.org> | 2025-07-18 00:12:13 +1000 |
commit | e9845ab20ec798c1d5bf00bd3b64ff5d96d94500 (patch) | |
tree | a3cb1999eac4270ca29d1f8556be8491595e5b62 /py/smallint.h | |
parent | 516aa02104c3344903bdda078b7c87f71f94938d (diff) |
py/smallint: Update mp_small_int_mul_overflow() to perform the multiply.
Makes it compatible with the __builtin_mul_overflow() syntax, used in
follow-up commit.
Includes optimisation in runtime.c to minimise the code size impact from
additional param.
Signed-off-by: Damien George <damien@micropython.org>
Signed-off-by: Angus Gratton <angus@redyak.com.au>
Diffstat (limited to 'py/smallint.h')
-rw-r--r-- | py/smallint.h | 5 |
1 files changed, 4 insertions, 1 deletions
diff --git a/py/smallint.h b/py/smallint.h index 584e0018d..e50f98651 100644 --- a/py/smallint.h +++ b/py/smallint.h @@ -68,7 +68,10 @@ // The number of bits in a MP_SMALL_INT including the sign bit. #define MP_SMALL_INT_BITS (MP_IMAX_BITS(MP_SMALL_INT_MAX) + 1) -bool mp_small_int_mul_overflow(mp_int_t x, mp_int_t y); +// Multiply two small ints. +// If returns false, the correct result is stored in 'res' +// If returns true, the multiplication would have overflowed. 'res' is unchanged. +bool mp_small_int_mul_overflow(mp_int_t x, mp_int_t y, mp_int_t *res); mp_int_t mp_small_int_modulo(mp_int_t dividend, mp_int_t divisor); mp_int_t mp_small_int_floor_divide(mp_int_t num, mp_int_t denom); |