diff options
author | Damien George <damien.p.george@gmail.com> | 2018-09-14 13:39:17 +1000 |
---|---|---|
committer | Damien George <damien.p.george@gmail.com> | 2018-09-14 13:39:17 +1000 |
commit | 9f241ef398cb0a7fbccc93b36a0fe032f89221e4 (patch) | |
tree | 2cad97a08e3860ca9dff1ff7ae3718a2f6bce616 /py/argcheck.c | |
parent | 0f4d595bebb82cfdd6264e1d18455faa0502ff31 (diff) |
py: Optimise call to mp_arg_check_num by compressing fun signature.
With 5 arguments to mp_arg_check_num(), some architectures need to pass
values on the stack. So compressing n_args_min, n_args_max, takes_kw into
a single word and passing only 3 arguments makes the call more efficient,
because almost all calls to this function pass in constant values. Code
size is also reduced by a decent amount:
bare-arm: -116
minimal x86: -64
unix x64: -256
unix nanbox: -112
stm32: -324
cc3200: -192
esp8266: -192
esp32: -144
Diffstat (limited to 'py/argcheck.c')
-rw-r--r-- | py/argcheck.c | 7 |
1 files changed, 6 insertions, 1 deletions
diff --git a/py/argcheck.c b/py/argcheck.c index d53bca73a..c018f3fe7 100644 --- a/py/argcheck.c +++ b/py/argcheck.c @@ -29,9 +29,14 @@ #include "py/runtime.h" -void mp_arg_check_num(size_t n_args, size_t n_kw, size_t n_args_min, size_t n_args_max, bool takes_kw) { +void mp_arg_check_num_sig(size_t n_args, size_t n_kw, uint32_t sig) { // TODO maybe take the function name as an argument so we can print nicer error messages + // The reverse of MP_OBJ_FUN_MAKE_SIG + bool takes_kw = sig & 1; + size_t n_args_min = sig >> 17; + size_t n_args_max = (sig >> 1) & 0xffff; + if (n_kw && !takes_kw) { if (MICROPY_ERROR_REPORTING == MICROPY_ERROR_REPORTING_TERSE) { mp_arg_error_terse_mismatch(); |