summaryrefslogtreecommitdiff
path: root/py/smallint.c
diff options
context:
space:
mode:
authorAngus Gratton <angus@redyak.com.au>2025-05-02 15:39:35 +1000
committerDamien George <damien@micropython.org>2025-07-18 00:12:13 +1000
commite9845ab20ec798c1d5bf00bd3b64ff5d96d94500 (patch)
treea3cb1999eac4270ca29d1f8556be8491595e5b62 /py/smallint.c
parent516aa02104c3344903bdda078b7c87f71f94938d (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.c')
-rw-r--r--py/smallint.c5
1 files changed, 4 insertions, 1 deletions
diff --git a/py/smallint.c b/py/smallint.c
index aa542ca7b..a494093d6 100644
--- a/py/smallint.c
+++ b/py/smallint.c
@@ -26,7 +26,7 @@
#include "py/smallint.h"
-bool mp_small_int_mul_overflow(mp_int_t x, mp_int_t y) {
+bool mp_small_int_mul_overflow(mp_int_t x, mp_int_t y, mp_int_t *res) {
// Check for multiply overflow; see CERT INT32-C
if (x > 0) { // x is positive
if (y > 0) { // x and y are positive
@@ -49,6 +49,9 @@ bool mp_small_int_mul_overflow(mp_int_t x, mp_int_t y) {
}
} // End if x and y are nonpositive
} // End if x is nonpositive
+
+ // Result doesn't overflow
+ *res = x * y;
return false;
}