diff options
| author | Damien George | 2016-10-18 11:49:27 +1100 |
|---|---|---|
| committer | Damien George | 2016-10-21 16:26:01 +1100 |
| commit | 571e6f26dbd7e0e38441bc402f76d293303063b2 (patch) | |
| tree | d720bcd32665e9cdcc9e2e00513f3b5e894da992 /py/runtime.c | |
| parent | 4ebdb1f2b217410cdc1cee0e0c0da8fceb7627f2 (diff) | |
py: Specialise builtin funcs to use separate type for fixed arg count.
Builtin functions with a fixed number of arguments (0, 1, 2 or 3) are
quite common. Before this patch the wrapper for such a function cost
3 machine words. After this patch it only takes 2, which can reduce the
code size by quite a bit (and pays off even more, the more functions are
added). It also makes function dispatch slightly more efficient in CPU
usage, and furthermore reduces stack usage for these cases. On x86 and
Thumb archs the dispatch functions are now tail-call optimised by the
compiler.
The bare-arm port has its code size increase by 76 bytes, but stmhal drops
by 904 bytes. Stack usage by these builtin functions is decreased by 48
bytes on Thumb2 archs.
Diffstat (limited to 'py/runtime.c')
| -rw-r--r-- | py/runtime.c | 8 |
1 files changed, 7 insertions, 1 deletions
diff --git a/py/runtime.c b/py/runtime.c index 6eda77ee9..c25557464 100644 --- a/py/runtime.c +++ b/py/runtime.c @@ -972,7 +972,13 @@ void mp_convert_member_lookup(mp_obj_t self, const mp_obj_type_t *type, mp_obj_t || ((mp_obj_base_t*)MP_OBJ_TO_PTR(member))->type->name == MP_QSTR_generator))) { // only functions, closures and generators objects can be bound to self #if MICROPY_BUILTIN_METHOD_CHECK_SELF_ARG - if (self == MP_OBJ_NULL && mp_obj_get_type(member) == &mp_type_fun_builtin) { + const mp_obj_type_t *m_type = ((mp_obj_base_t*)MP_OBJ_TO_PTR(member))->type; + if (self == MP_OBJ_NULL + && (m_type == &mp_type_fun_builtin_0 + || m_type == &mp_type_fun_builtin_1 + || m_type == &mp_type_fun_builtin_2 + || m_type == &mp_type_fun_builtin_3 + || m_type == &mp_type_fun_builtin_var)) { // we extracted a builtin method without a first argument, so we must // wrap this function in a type checker dest[0] = mp_obj_new_checked_fun(type, member); |
