diff options
author | Damien George <damien.p.george@gmail.com> | 2014-10-25 16:43:46 +0100 |
---|---|---|
committer | Damien George <damien.p.george@gmail.com> | 2014-10-25 20:23:13 +0100 |
commit | 8456cc017bc2e4a9fe063f485c3f2aa410435015 (patch) | |
tree | e0c8055f6de2c7975b6b7b31e80beb622ce9b3ad /py/vmentrytable.h | |
parent | 1084b0f9c21b093618da4494508dec9ca8467e35 (diff) |
py: Compress load-int, load-fast, store-fast, unop, binop bytecodes.
There is a lot potential in compress bytecodes and make more use of the
coding space. This patch introduces "multi" bytecodes which have their
argument included in the bytecode (by addition).
UNARY_OP and BINARY_OP now no longer take a 1 byte argument for the
opcode. Rather, the opcode is included in the first byte itself.
LOAD_FAST_[0,1,2] and STORE_FAST_[0,1,2] are removed in favour of their
multi versions, which can take an argument between 0 and 15 inclusive.
The majority of LOAD_FAST/STORE_FAST codes fit in this range and so this
saves a byte for each of these.
LOAD_CONST_SMALL_INT_MULTI is used to load small ints between -16 and 47
inclusive. Such ints are quite common and now only need 1 byte to
store, and now have much faster decoding.
In all this patch saves about 2% RAM for typically bytecode (1.8% on
64-bit test, 2.5% on pyboard test). It also reduces the binary size
(because bytecodes are simplified) and doesn't harm performance.
Diffstat (limited to 'py/vmentrytable.h')
-rw-r--r-- | py/vmentrytable.h | 13 |
1 files changed, 5 insertions, 8 deletions
diff --git a/py/vmentrytable.h b/py/vmentrytable.h index 598b5b872..29cfdce4e 100644 --- a/py/vmentrytable.h +++ b/py/vmentrytable.h @@ -41,9 +41,6 @@ static void* entry_table[256] = { [MP_BC_LOAD_CONST_BYTES] = &&entry_MP_BC_LOAD_CONST_BYTES, [MP_BC_LOAD_CONST_STRING] = &&entry_MP_BC_LOAD_CONST_STRING, [MP_BC_LOAD_NULL] = &&entry_MP_BC_LOAD_NULL, - [MP_BC_LOAD_FAST_0] = &&entry_MP_BC_LOAD_FAST_0, - [MP_BC_LOAD_FAST_1] = &&entry_MP_BC_LOAD_FAST_1, - [MP_BC_LOAD_FAST_2] = &&entry_MP_BC_LOAD_FAST_2, [MP_BC_LOAD_FAST_N] = &&entry_MP_BC_LOAD_FAST_N, [MP_BC_LOAD_DEREF] = &&entry_MP_BC_LOAD_DEREF, [MP_BC_LOAD_NAME] = &&entry_MP_BC_LOAD_NAME, @@ -52,9 +49,6 @@ static void* entry_table[256] = { [MP_BC_LOAD_METHOD] = &&entry_MP_BC_LOAD_METHOD, [MP_BC_LOAD_BUILD_CLASS] = &&entry_MP_BC_LOAD_BUILD_CLASS, [MP_BC_LOAD_SUBSCR] = &&entry_MP_BC_LOAD_SUBSCR, - [MP_BC_STORE_FAST_0] = &&entry_MP_BC_STORE_FAST_0, - [MP_BC_STORE_FAST_1] = &&entry_MP_BC_STORE_FAST_1, - [MP_BC_STORE_FAST_2] = &&entry_MP_BC_STORE_FAST_2, [MP_BC_STORE_FAST_N] = &&entry_MP_BC_STORE_FAST_N, [MP_BC_STORE_DEREF] = &&entry_MP_BC_STORE_DEREF, [MP_BC_STORE_NAME] = &&entry_MP_BC_STORE_NAME, @@ -86,8 +80,6 @@ static void* entry_table[256] = { [MP_BC_POP_BLOCK] = &&entry_MP_BC_POP_BLOCK, [MP_BC_POP_EXCEPT] = &&entry_MP_BC_POP_EXCEPT, [MP_BC_NOT] = &&entry_MP_BC_NOT, - [MP_BC_UNARY_OP] = &&entry_MP_BC_UNARY_OP, - [MP_BC_BINARY_OP] = &&entry_MP_BC_BINARY_OP, [MP_BC_BUILD_TUPLE] = &&entry_MP_BC_BUILD_TUPLE, [MP_BC_BUILD_LIST] = &&entry_MP_BC_BUILD_LIST, [MP_BC_LIST_APPEND] = &&entry_MP_BC_LIST_APPEND, @@ -114,6 +106,11 @@ static void* entry_table[256] = { [MP_BC_IMPORT_NAME] = &&entry_MP_BC_IMPORT_NAME, [MP_BC_IMPORT_FROM] = &&entry_MP_BC_IMPORT_FROM, [MP_BC_IMPORT_STAR] = &&entry_MP_BC_IMPORT_STAR, + [MP_BC_LOAD_CONST_SMALL_INT_MULTI ... MP_BC_LOAD_CONST_SMALL_INT_MULTI + 63] = &&entry_MP_BC_LOAD_CONST_SMALL_INT_MULTI, + [MP_BC_LOAD_FAST_MULTI ... MP_BC_LOAD_FAST_MULTI + 15] = &&entry_MP_BC_LOAD_FAST_MULTI, + [MP_BC_STORE_FAST_MULTI ... MP_BC_STORE_FAST_MULTI + 15] = &&entry_MP_BC_STORE_FAST_MULTI, + [MP_BC_UNARY_OP_MULTI ... MP_BC_UNARY_OP_MULTI + 4] = &&entry_MP_BC_UNARY_OP_MULTI, + [MP_BC_BINARY_OP_MULTI ... MP_BC_BINARY_OP_MULTI + 34] = &&entry_MP_BC_BINARY_OP_MULTI, }; #if __clang__ |