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>
This commit is contained in:
Angus Gratton
2025-05-02 15:39:35 +10:00
committed by Damien George
parent 516aa02104
commit e9845ab20e
4 changed files with 17 additions and 10 deletions

View File

@@ -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;
}