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.
This commit is contained in:
parent
1084b0f9c2
commit
8456cc017b
152
py/bc0.h
152
py/bc0.h
|
@ -31,92 +31,90 @@
|
|||
#define MP_BC_LOAD_CONST_NONE (0x11)
|
||||
#define MP_BC_LOAD_CONST_TRUE (0x12)
|
||||
#define MP_BC_LOAD_CONST_ELLIPSIS (0x13)
|
||||
#define MP_BC_LOAD_CONST_SMALL_INT (0x14) // 24-bit, in excess
|
||||
#define MP_BC_LOAD_CONST_SMALL_INT (0x14) // signed var-int
|
||||
#define MP_BC_LOAD_CONST_INT (0x15) // qstr
|
||||
#define MP_BC_LOAD_CONST_DEC (0x16) // qstr
|
||||
#define MP_BC_LOAD_CONST_BYTES (0x18) // qstr
|
||||
#define MP_BC_LOAD_CONST_STRING (0x19) // qstr
|
||||
#define MP_BC_LOAD_NULL (0x1a)
|
||||
#define MP_BC_LOAD_CONST_BYTES (0x17) // qstr
|
||||
#define MP_BC_LOAD_CONST_STRING (0x18) // qstr
|
||||
#define MP_BC_LOAD_NULL (0x19)
|
||||
|
||||
#define MP_BC_LOAD_FAST_0 (0x20)
|
||||
#define MP_BC_LOAD_FAST_1 (0x21)
|
||||
#define MP_BC_LOAD_FAST_2 (0x22)
|
||||
#define MP_BC_LOAD_FAST_N (0x23) // uint
|
||||
#define MP_BC_LOAD_DEREF (0x25) // uint
|
||||
#define MP_BC_LOAD_NAME (0x26) // qstr
|
||||
#define MP_BC_LOAD_GLOBAL (0x27) // qstr
|
||||
#define MP_BC_LOAD_ATTR (0x28) // qstr
|
||||
#define MP_BC_LOAD_METHOD (0x29) // qstr
|
||||
#define MP_BC_LOAD_BUILD_CLASS (0x2a)
|
||||
#define MP_BC_LOAD_SUBSCR (0x2b)
|
||||
#define MP_BC_LOAD_FAST_N (0x1a) // uint
|
||||
#define MP_BC_LOAD_DEREF (0x1b) // uint
|
||||
#define MP_BC_LOAD_NAME (0x1c) // qstr
|
||||
#define MP_BC_LOAD_GLOBAL (0x1d) // qstr
|
||||
#define MP_BC_LOAD_ATTR (0x1e) // qstr
|
||||
#define MP_BC_LOAD_METHOD (0x1f) // qstr
|
||||
#define MP_BC_LOAD_BUILD_CLASS (0x20)
|
||||
#define MP_BC_LOAD_SUBSCR (0x21)
|
||||
|
||||
#define MP_BC_STORE_FAST_0 (0x30)
|
||||
#define MP_BC_STORE_FAST_1 (0x31)
|
||||
#define MP_BC_STORE_FAST_2 (0x32)
|
||||
#define MP_BC_STORE_FAST_N (0x33) // uint
|
||||
#define MP_BC_STORE_DEREF (0x34) // uint
|
||||
#define MP_BC_STORE_NAME (0x35) // qstr
|
||||
#define MP_BC_STORE_GLOBAL (0x36) // qstr
|
||||
#define MP_BC_STORE_ATTR (0x37) // qstr
|
||||
#define MP_BC_STORE_SUBSCR (0x38)
|
||||
#define MP_BC_STORE_FAST_N (0x22) // uint
|
||||
#define MP_BC_STORE_DEREF (0x23) // uint
|
||||
#define MP_BC_STORE_NAME (0x24) // qstr
|
||||
#define MP_BC_STORE_GLOBAL (0x25) // qstr
|
||||
#define MP_BC_STORE_ATTR (0x26) // qstr
|
||||
#define MP_BC_STORE_SUBSCR (0x27)
|
||||
|
||||
#define MP_BC_DELETE_FAST (0x39) // uint
|
||||
#define MP_BC_DELETE_DEREF (0x3a) // uint
|
||||
#define MP_BC_DELETE_NAME (0x3b) // qstr
|
||||
#define MP_BC_DELETE_GLOBAL (0x3c) // qstr
|
||||
#define MP_BC_DELETE_FAST (0x28) // uint
|
||||
#define MP_BC_DELETE_DEREF (0x29) // uint
|
||||
#define MP_BC_DELETE_NAME (0x2a) // qstr
|
||||
#define MP_BC_DELETE_GLOBAL (0x2b) // qstr
|
||||
|
||||
#define MP_BC_DUP_TOP (0x40)
|
||||
#define MP_BC_DUP_TOP_TWO (0x41)
|
||||
#define MP_BC_POP_TOP (0x42)
|
||||
#define MP_BC_ROT_TWO (0x43)
|
||||
#define MP_BC_ROT_THREE (0x44)
|
||||
#define MP_BC_DUP_TOP (0x30)
|
||||
#define MP_BC_DUP_TOP_TWO (0x31)
|
||||
#define MP_BC_POP_TOP (0x32)
|
||||
#define MP_BC_ROT_TWO (0x33)
|
||||
#define MP_BC_ROT_THREE (0x34)
|
||||
|
||||
#define MP_BC_JUMP (0x45) // rel byte code offset, 16-bit signed, in excess
|
||||
#define MP_BC_POP_JUMP_IF_TRUE (0x46) // rel byte code offset, 16-bit signed, in excess
|
||||
#define MP_BC_POP_JUMP_IF_FALSE (0x47) // rel byte code offset, 16-bit signed, in excess
|
||||
#define MP_BC_JUMP_IF_TRUE_OR_POP (0x48) // rel byte code offset, 16-bit signed, in excess
|
||||
#define MP_BC_JUMP_IF_FALSE_OR_POP (0x49) // rel byte code offset, 16-bit signed, in excess
|
||||
#define MP_BC_SETUP_WITH (0x4d) // rel byte code offset, 16-bit unsigned
|
||||
#define MP_BC_WITH_CLEANUP (0x4e)
|
||||
#define MP_BC_SETUP_EXCEPT (0x4f) // rel byte code offset, 16-bit unsigned
|
||||
#define MP_BC_SETUP_FINALLY (0x50) // rel byte code offset, 16-bit unsigned
|
||||
#define MP_BC_END_FINALLY (0x51)
|
||||
#define MP_BC_GET_ITER (0x52)
|
||||
#define MP_BC_FOR_ITER (0x53) // rel byte code offset, 16-bit unsigned
|
||||
#define MP_BC_POP_BLOCK (0x54)
|
||||
#define MP_BC_POP_EXCEPT (0x55)
|
||||
#define MP_BC_UNWIND_JUMP (0x56) // rel byte code offset, 16-bit signed, in excess; then a byte
|
||||
#define MP_BC_JUMP (0x35) // rel byte code offset, 16-bit signed, in excess
|
||||
#define MP_BC_POP_JUMP_IF_TRUE (0x36) // rel byte code offset, 16-bit signed, in excess
|
||||
#define MP_BC_POP_JUMP_IF_FALSE (0x37) // rel byte code offset, 16-bit signed, in excess
|
||||
#define MP_BC_JUMP_IF_TRUE_OR_POP (0x38) // rel byte code offset, 16-bit signed, in excess
|
||||
#define MP_BC_JUMP_IF_FALSE_OR_POP (0x39) // rel byte code offset, 16-bit signed, in excess
|
||||
#define MP_BC_SETUP_WITH (0x3d) // rel byte code offset, 16-bit unsigned
|
||||
#define MP_BC_WITH_CLEANUP (0x3e)
|
||||
#define MP_BC_SETUP_EXCEPT (0x3f) // rel byte code offset, 16-bit unsigned
|
||||
#define MP_BC_SETUP_FINALLY (0x40) // rel byte code offset, 16-bit unsigned
|
||||
#define MP_BC_END_FINALLY (0x41)
|
||||
#define MP_BC_GET_ITER (0x42)
|
||||
#define MP_BC_FOR_ITER (0x43) // rel byte code offset, 16-bit unsigned
|
||||
#define MP_BC_POP_BLOCK (0x44)
|
||||
#define MP_BC_POP_EXCEPT (0x45)
|
||||
#define MP_BC_UNWIND_JUMP (0x46) // rel byte code offset, 16-bit signed, in excess; then a byte
|
||||
|
||||
#define MP_BC_NOT (0x60)
|
||||
#define MP_BC_UNARY_OP (0x61) // byte
|
||||
#define MP_BC_BINARY_OP (0x62) // byte
|
||||
#define MP_BC_NOT (0x47)
|
||||
|
||||
#define MP_BC_BUILD_TUPLE (0x70) // uint
|
||||
#define MP_BC_BUILD_LIST (0x71) // uint
|
||||
#define MP_BC_LIST_APPEND (0x72) // uint
|
||||
#define MP_BC_BUILD_MAP (0x73) // uint
|
||||
#define MP_BC_STORE_MAP (0x74)
|
||||
#define MP_BC_MAP_ADD (0x75) // uint
|
||||
#define MP_BC_BUILD_SET (0x76) // uint
|
||||
#define MP_BC_SET_ADD (0x77) // uint
|
||||
#define MP_BC_BUILD_SLICE (0x78) // uint
|
||||
#define MP_BC_UNPACK_SEQUENCE (0x79) // uint
|
||||
#define MP_BC_UNPACK_EX (0x7a) // uint
|
||||
#define MP_BC_BUILD_TUPLE (0x50) // uint
|
||||
#define MP_BC_BUILD_LIST (0x51) // uint
|
||||
#define MP_BC_LIST_APPEND (0x52) // uint
|
||||
#define MP_BC_BUILD_MAP (0x53) // uint
|
||||
#define MP_BC_STORE_MAP (0x54)
|
||||
#define MP_BC_MAP_ADD (0x55) // uint
|
||||
#define MP_BC_BUILD_SET (0x56) // uint
|
||||
#define MP_BC_SET_ADD (0x57) // uint
|
||||
#define MP_BC_BUILD_SLICE (0x58) // uint
|
||||
#define MP_BC_UNPACK_SEQUENCE (0x59) // uint
|
||||
#define MP_BC_UNPACK_EX (0x5a) // uint
|
||||
|
||||
#define MP_BC_RETURN_VALUE (0x80)
|
||||
#define MP_BC_RAISE_VARARGS (0x81) // byte
|
||||
#define MP_BC_YIELD_VALUE (0x82)
|
||||
#define MP_BC_YIELD_FROM (0x83)
|
||||
#define MP_BC_RETURN_VALUE (0x5b)
|
||||
#define MP_BC_RAISE_VARARGS (0x5c) // byte
|
||||
#define MP_BC_YIELD_VALUE (0x5d)
|
||||
#define MP_BC_YIELD_FROM (0x5e)
|
||||
|
||||
#define MP_BC_MAKE_FUNCTION (0x90) // uint
|
||||
#define MP_BC_MAKE_FUNCTION_DEFARGS (0x91) // uint
|
||||
#define MP_BC_MAKE_CLOSURE (0x92) // uint
|
||||
#define MP_BC_MAKE_CLOSURE_DEFARGS (0x93) // uint
|
||||
#define MP_BC_CALL_FUNCTION (0x94) // uint
|
||||
#define MP_BC_CALL_FUNCTION_VAR_KW (0x95) // uint
|
||||
#define MP_BC_CALL_METHOD (0x96) // uint
|
||||
#define MP_BC_CALL_METHOD_VAR_KW (0x97) // uint
|
||||
#define MP_BC_MAKE_FUNCTION (0x60) // uint
|
||||
#define MP_BC_MAKE_FUNCTION_DEFARGS (0x61) // uint
|
||||
#define MP_BC_MAKE_CLOSURE (0x62) // uint
|
||||
#define MP_BC_MAKE_CLOSURE_DEFARGS (0x63) // uint
|
||||
#define MP_BC_CALL_FUNCTION (0x64) // uint
|
||||
#define MP_BC_CALL_FUNCTION_VAR_KW (0x65) // uint
|
||||
#define MP_BC_CALL_METHOD (0x66) // uint
|
||||
#define MP_BC_CALL_METHOD_VAR_KW (0x67) // uint
|
||||
|
||||
#define MP_BC_IMPORT_NAME (0xe0) // qstr
|
||||
#define MP_BC_IMPORT_FROM (0xe1) // qstr
|
||||
#define MP_BC_IMPORT_STAR (0xe2)
|
||||
#define MP_BC_IMPORT_NAME (0x68) // qstr
|
||||
#define MP_BC_IMPORT_FROM (0x69) // qstr
|
||||
#define MP_BC_IMPORT_STAR (0x6a)
|
||||
|
||||
#define MP_BC_LOAD_CONST_SMALL_INT_MULTI (0x70) // + N(64)
|
||||
#define MP_BC_LOAD_FAST_MULTI (0xb0) // + N(16)
|
||||
#define MP_BC_STORE_FAST_MULTI (0xc0) // + N(16)
|
||||
#define MP_BC_UNARY_OP_MULTI (0xd0) // + op(5)
|
||||
#define MP_BC_BINARY_OP_MULTI (0xd5) // + op(35)
|
||||
|
|
30
py/emitbc.c
30
py/emitbc.c
|
@ -469,7 +469,11 @@ STATIC void emit_bc_load_const_tok(emit_t *emit, mp_token_kind_t tok) {
|
|||
|
||||
STATIC void emit_bc_load_const_small_int(emit_t *emit, mp_int_t arg) {
|
||||
emit_bc_pre(emit, 1);
|
||||
emit_write_bytecode_byte_int(emit, MP_BC_LOAD_CONST_SMALL_INT, arg);
|
||||
if (-16 <= arg && arg <= 47) {
|
||||
emit_write_bytecode_byte(emit, MP_BC_LOAD_CONST_SMALL_INT_MULTI + 16 + arg);
|
||||
} else {
|
||||
emit_write_bytecode_byte_int(emit, MP_BC_LOAD_CONST_SMALL_INT, arg);
|
||||
}
|
||||
}
|
||||
|
||||
STATIC void emit_bc_load_const_int(emit_t *emit, qstr qst) {
|
||||
|
@ -499,11 +503,10 @@ STATIC void emit_bc_load_null(emit_t *emit) {
|
|||
STATIC void emit_bc_load_fast(emit_t *emit, qstr qst, mp_uint_t id_flags, mp_uint_t local_num) {
|
||||
assert(local_num >= 0);
|
||||
emit_bc_pre(emit, 1);
|
||||
switch (local_num) {
|
||||
case 0: emit_write_bytecode_byte(emit, MP_BC_LOAD_FAST_0); break;
|
||||
case 1: emit_write_bytecode_byte(emit, MP_BC_LOAD_FAST_1); break;
|
||||
case 2: emit_write_bytecode_byte(emit, MP_BC_LOAD_FAST_2); break;
|
||||
default: emit_write_bytecode_byte_uint(emit, MP_BC_LOAD_FAST_N, local_num); break;
|
||||
if (local_num <= 15) {
|
||||
emit_write_bytecode_byte(emit, MP_BC_LOAD_FAST_MULTI + local_num);
|
||||
} else {
|
||||
emit_write_bytecode_byte_uint(emit, MP_BC_LOAD_FAST_N, local_num);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -545,11 +548,10 @@ STATIC void emit_bc_load_subscr(emit_t *emit) {
|
|||
STATIC void emit_bc_store_fast(emit_t *emit, qstr qst, mp_uint_t local_num) {
|
||||
assert(local_num >= 0);
|
||||
emit_bc_pre(emit, -1);
|
||||
switch (local_num) {
|
||||
case 0: emit_write_bytecode_byte(emit, MP_BC_STORE_FAST_0); break;
|
||||
case 1: emit_write_bytecode_byte(emit, MP_BC_STORE_FAST_1); break;
|
||||
case 2: emit_write_bytecode_byte(emit, MP_BC_STORE_FAST_2); break;
|
||||
default: emit_write_bytecode_byte_uint(emit, MP_BC_STORE_FAST_N, local_num); break;
|
||||
if (local_num <= 15) {
|
||||
emit_write_bytecode_byte(emit, MP_BC_STORE_FAST_MULTI + local_num);
|
||||
} else {
|
||||
emit_write_bytecode_byte_uint(emit, MP_BC_STORE_FAST_N, local_num);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -724,12 +726,12 @@ STATIC void emit_bc_pop_except(emit_t *emit) {
|
|||
STATIC void emit_bc_unary_op(emit_t *emit, mp_unary_op_t op) {
|
||||
if (op == MP_UNARY_OP_NOT) {
|
||||
emit_bc_pre(emit, 0);
|
||||
emit_write_bytecode_byte_byte(emit, MP_BC_UNARY_OP, MP_UNARY_OP_BOOL);
|
||||
emit_write_bytecode_byte(emit, MP_BC_UNARY_OP_MULTI + MP_UNARY_OP_BOOL);
|
||||
emit_bc_pre(emit, 0);
|
||||
emit_write_bytecode_byte(emit, MP_BC_NOT);
|
||||
} else {
|
||||
emit_bc_pre(emit, 0);
|
||||
emit_write_bytecode_byte_byte(emit, MP_BC_UNARY_OP, op);
|
||||
emit_write_bytecode_byte(emit, MP_BC_UNARY_OP_MULTI + op);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -743,7 +745,7 @@ STATIC void emit_bc_binary_op(emit_t *emit, mp_binary_op_t op) {
|
|||
op = MP_BINARY_OP_IS;
|
||||
}
|
||||
emit_bc_pre(emit, -1);
|
||||
emit_write_bytecode_byte_byte(emit, MP_BC_BINARY_OP, op);
|
||||
emit_write_bytecode_byte(emit, MP_BC_BINARY_OP_MULTI + op);
|
||||
if (invert) {
|
||||
emit_bc_pre(emit, 0);
|
||||
emit_write_bytecode_byte(emit, MP_BC_NOT);
|
||||
|
|
53
py/showbc.c
53
py/showbc.c
|
@ -190,18 +190,6 @@ void mp_bytecode_print2(const byte *ip, mp_uint_t len) {
|
|||
printf("LOAD_NULL");
|
||||
break;
|
||||
|
||||
case MP_BC_LOAD_FAST_0:
|
||||
printf("LOAD_FAST_0");
|
||||
break;
|
||||
|
||||
case MP_BC_LOAD_FAST_1:
|
||||
printf("LOAD_FAST_1");
|
||||
break;
|
||||
|
||||
case MP_BC_LOAD_FAST_2:
|
||||
printf("LOAD_FAST_2");
|
||||
break;
|
||||
|
||||
case MP_BC_LOAD_FAST_N:
|
||||
DECODE_UINT;
|
||||
printf("LOAD_FAST_N " UINT_FMT, unum);
|
||||
|
@ -240,18 +228,6 @@ void mp_bytecode_print2(const byte *ip, mp_uint_t len) {
|
|||
printf("LOAD_SUBSCR");
|
||||
break;
|
||||
|
||||
case MP_BC_STORE_FAST_0:
|
||||
printf("STORE_FAST_0");
|
||||
break;
|
||||
|
||||
case MP_BC_STORE_FAST_1:
|
||||
printf("STORE_FAST_1");
|
||||
break;
|
||||
|
||||
case MP_BC_STORE_FAST_2:
|
||||
printf("STORE_FAST_2");
|
||||
break;
|
||||
|
||||
case MP_BC_STORE_FAST_N:
|
||||
DECODE_UINT;
|
||||
printf("STORE_FAST_N " UINT_FMT, unum);
|
||||
|
@ -397,16 +373,6 @@ void mp_bytecode_print2(const byte *ip, mp_uint_t len) {
|
|||
printf("NOT");
|
||||
break;
|
||||
|
||||
case MP_BC_UNARY_OP:
|
||||
unum = *ip++;
|
||||
printf("UNARY_OP " UINT_FMT, unum);
|
||||
break;
|
||||
|
||||
case MP_BC_BINARY_OP:
|
||||
unum = *ip++;
|
||||
printf("BINARY_OP " UINT_FMT, unum);
|
||||
break;
|
||||
|
||||
case MP_BC_BUILD_TUPLE:
|
||||
DECODE_UINT;
|
||||
printf("BUILD_TUPLE " UINT_FMT, unum);
|
||||
|
@ -534,9 +500,22 @@ void mp_bytecode_print2(const byte *ip, mp_uint_t len) {
|
|||
break;
|
||||
|
||||
default:
|
||||
printf("code %p, byte code 0x%02x not implemented\n", ip, ip[-1]);
|
||||
assert(0);
|
||||
return;
|
||||
if (ip[-1] < MP_BC_LOAD_CONST_SMALL_INT_MULTI + 64) {
|
||||
printf("LOAD_CONST_SMALL_INT " INT_FMT, (mp_int_t)ip[-1] - MP_BC_LOAD_CONST_SMALL_INT_MULTI - 16);
|
||||
} else if (ip[-1] < MP_BC_LOAD_FAST_MULTI + 16) {
|
||||
printf("LOAD_FAST " UINT_FMT, (mp_uint_t)ip[-1] - MP_BC_LOAD_FAST_MULTI);
|
||||
} else if (ip[-1] < MP_BC_STORE_FAST_MULTI + 16) {
|
||||
printf("STORE_FAST " UINT_FMT, (mp_uint_t)ip[-1] - MP_BC_STORE_FAST_MULTI);
|
||||
} else if (ip[-1] < MP_BC_UNARY_OP_MULTI + 5) {
|
||||
printf("UNARY_OP " UINT_FMT, (mp_uint_t)ip[-1] - MP_BC_UNARY_OP_MULTI);
|
||||
} else if (ip[-1] < MP_BC_BINARY_OP_MULTI + 35) {
|
||||
printf("BINARY_OP " UINT_FMT, (mp_uint_t)ip[-1] - MP_BC_BINARY_OP_MULTI);
|
||||
} else {
|
||||
printf("code %p, byte code 0x%02x not implemented\n", ip, ip[-1]);
|
||||
assert(0);
|
||||
return;
|
||||
}
|
||||
break;
|
||||
}
|
||||
printf("\n");
|
||||
}
|
||||
|
|
85
py/vm.c
85
py/vm.c
|
@ -223,18 +223,6 @@ dispatch_loop:
|
|||
PUSH(MP_OBJ_NULL);
|
||||
DISPATCH();
|
||||
|
||||
ENTRY(MP_BC_LOAD_FAST_0):
|
||||
obj_shared = fastn[0];
|
||||
goto load_check;
|
||||
|
||||
ENTRY(MP_BC_LOAD_FAST_1):
|
||||
obj_shared = fastn[-1];
|
||||
goto load_check;
|
||||
|
||||
ENTRY(MP_BC_LOAD_FAST_2):
|
||||
obj_shared = fastn[-2];
|
||||
goto load_check;
|
||||
|
||||
ENTRY(MP_BC_LOAD_FAST_N):
|
||||
DECODE_UINT;
|
||||
obj_shared = fastn[-unum];
|
||||
|
@ -288,18 +276,6 @@ dispatch_loop:
|
|||
DISPATCH();
|
||||
}
|
||||
|
||||
ENTRY(MP_BC_STORE_FAST_0):
|
||||
fastn[0] = POP();
|
||||
DISPATCH();
|
||||
|
||||
ENTRY(MP_BC_STORE_FAST_1):
|
||||
fastn[-1] = POP();
|
||||
DISPATCH();
|
||||
|
||||
ENTRY(MP_BC_STORE_FAST_2):
|
||||
fastn[-2] = POP();
|
||||
DISPATCH();
|
||||
|
||||
ENTRY(MP_BC_STORE_FAST_N):
|
||||
DECODE_UINT;
|
||||
fastn[-unum] = POP();
|
||||
|
@ -606,19 +582,6 @@ unwind_jump:
|
|||
}
|
||||
DISPATCH();
|
||||
|
||||
ENTRY(MP_BC_UNARY_OP):
|
||||
unum = *ip++;
|
||||
SET_TOP(mp_unary_op(unum, TOP()));
|
||||
DISPATCH();
|
||||
|
||||
ENTRY(MP_BC_BINARY_OP): {
|
||||
unum = *ip++;
|
||||
mp_obj_t rhs = POP();
|
||||
mp_obj_t lhs = TOP();
|
||||
SET_TOP(mp_binary_op(unum, lhs, rhs));
|
||||
DISPATCH();
|
||||
}
|
||||
|
||||
ENTRY(MP_BC_BUILD_TUPLE):
|
||||
DECODE_UINT;
|
||||
sp -= unum - 1;
|
||||
|
@ -890,7 +853,53 @@ yield:
|
|||
mp_import_all(POP());
|
||||
DISPATCH();
|
||||
|
||||
ENTRY_DEFAULT: {
|
||||
#if MICROPY_OPT_COMPUTED_GOTO
|
||||
ENTRY(MP_BC_LOAD_CONST_SMALL_INT_MULTI):
|
||||
PUSH(MP_OBJ_NEW_SMALL_INT((mp_int_t)ip[-1] - MP_BC_LOAD_CONST_SMALL_INT_MULTI - 16));
|
||||
DISPATCH();
|
||||
|
||||
ENTRY(MP_BC_LOAD_FAST_MULTI):
|
||||
obj_shared = fastn[MP_BC_LOAD_FAST_MULTI - (mp_int_t)ip[-1]];
|
||||
goto load_check;
|
||||
|
||||
ENTRY(MP_BC_STORE_FAST_MULTI):
|
||||
fastn[MP_BC_STORE_FAST_MULTI - (mp_int_t)ip[-1]] = POP();
|
||||
DISPATCH();
|
||||
|
||||
ENTRY(MP_BC_UNARY_OP_MULTI):
|
||||
SET_TOP(mp_unary_op(ip[-1] - MP_BC_UNARY_OP_MULTI, TOP()));
|
||||
DISPATCH();
|
||||
|
||||
ENTRY(MP_BC_BINARY_OP_MULTI): {
|
||||
mp_obj_t rhs = POP();
|
||||
mp_obj_t lhs = TOP();
|
||||
SET_TOP(mp_binary_op(ip[-1] - MP_BC_BINARY_OP_MULTI, lhs, rhs));
|
||||
DISPATCH();
|
||||
}
|
||||
|
||||
ENTRY_DEFAULT:
|
||||
#else
|
||||
ENTRY_DEFAULT:
|
||||
if (ip[-1] < MP_BC_LOAD_CONST_SMALL_INT_MULTI + 64) {
|
||||
PUSH(MP_OBJ_NEW_SMALL_INT((mp_int_t)ip[-1] - MP_BC_LOAD_CONST_SMALL_INT_MULTI - 16));
|
||||
DISPATCH();
|
||||
} else if (ip[-1] < MP_BC_LOAD_FAST_MULTI + 16) {
|
||||
obj_shared = fastn[MP_BC_LOAD_FAST_MULTI - (mp_int_t)ip[-1]];
|
||||
goto load_check;
|
||||
} else if (ip[-1] < MP_BC_STORE_FAST_MULTI + 16) {
|
||||
fastn[MP_BC_STORE_FAST_MULTI - (mp_int_t)ip[-1]] = POP();
|
||||
DISPATCH();
|
||||
} else if (ip[-1] < MP_BC_UNARY_OP_MULTI + 5) {
|
||||
SET_TOP(mp_unary_op(ip[-1] - MP_BC_UNARY_OP_MULTI, TOP()));
|
||||
DISPATCH();
|
||||
} else if (ip[-1] < MP_BC_BINARY_OP_MULTI + 35) {
|
||||
mp_obj_t rhs = POP();
|
||||
mp_obj_t lhs = TOP();
|
||||
SET_TOP(mp_binary_op(ip[-1] - MP_BC_BINARY_OP_MULTI, lhs, rhs));
|
||||
DISPATCH();
|
||||
} else
|
||||
#endif
|
||||
{
|
||||
mp_obj_t obj = mp_obj_new_exception_msg(&mp_type_NotImplementedError, "byte code not implemented");
|
||||
nlr_pop();
|
||||
fastn[0] = obj;
|
||||
|
|
|
@ -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__
|
||||
|
|
Loading…
Reference in New Issue