mirror of
https://github.com/micropython/micropython.git
synced 2026-01-06 12:10:13 +01:00
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:
committed by
Damien George
parent
516aa02104
commit
e9845ab20e
@@ -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;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user