From be6c4d2125d025bdce470319c763db4607458c4a Mon Sep 17 00:00:00 2001 From: Paul Guyot Date: Wed, 23 Aug 2023 22:50:18 +0200 Subject: [PATCH] Define sets of opcodes per versions of OTP compiler Signed-off-by: Paul Guyot --- src/libAtomVM/opcodesswitch.h | 52 +++++++++++++++++++++++++---------- 1 file changed, 38 insertions(+), 14 deletions(-) diff --git a/src/libAtomVM/opcodesswitch.h b/src/libAtomVM/opcodesswitch.h index 3ad711fc8..0feaf10e1 100644 --- a/src/libAtomVM/opcodesswitch.h +++ b/src/libAtomVM/opcodesswitch.h @@ -41,12 +41,10 @@ #include "stacktrace.h" #endif -#define ENABLE_OTP21 -#define ENABLE_OTP22 -#define ENABLE_OTP23 -#define ENABLE_OTP24 -#define ENABLE_OTP25 -#define ENABLE_OTP26 +// These constants can be used to reduce the size of the VM for a specific +// range of compiler versions +#define MINIMUM_OTP_COMPILER_VERSION 21 +#define MAXIMUM_OTP_COMPILER_VERSION 26 //#define ENABLE_TRACE @@ -2061,6 +2059,7 @@ HOT_FUNC int scheduler_entry_point(GlobalContext *glb) break; } +#if MINIMUM_OTP_COMPILER_VERSION <= 23 case OP_ALLOCATE_HEAP_ZERO: { uint32_t stack_need; DECODE_LITERAL(stack_need, pc); @@ -2096,6 +2095,7 @@ HOT_FUNC int scheduler_entry_point(GlobalContext *glb) #endif break; } +#endif case OP_TEST_HEAP: { uint32_t heap_need; @@ -3047,6 +3047,7 @@ HOT_FUNC int scheduler_entry_point(GlobalContext *glb) break; } +#if MINIMUM_OTP_COMPILER_VERSION <= 25 case OP_SET_TUPLE_ELEMENT: { term new_element; DECODE_COMPACT_TERM(new_element, pc); @@ -3072,6 +3073,7 @@ HOT_FUNC int scheduler_entry_point(GlobalContext *glb) #endif break; } +#endif case OP_PUT_LIST: { @@ -3101,6 +3103,7 @@ HOT_FUNC int scheduler_entry_point(GlobalContext *glb) break; } +#if MINIMUM_OTP_COMPILER_VERSION <= 21 case OP_PUT_TUPLE: { uint32_t size; DECODE_LITERAL(size, pc); @@ -3138,6 +3141,7 @@ HOT_FUNC int scheduler_entry_point(GlobalContext *glb) } break; } +#endif case OP_BADMATCH: { #ifdef IMPL_EXECUTE_LOOP @@ -3547,6 +3551,7 @@ HOT_FUNC int scheduler_entry_point(GlobalContext *glb) break; } +#if MINIMUM_OTP_COMPILER_VERSION <= 24 case OP_BS_INIT2: { uint32_t fail; DECODE_LABEL(fail, pc) @@ -3694,6 +3699,7 @@ HOT_FUNC int scheduler_entry_point(GlobalContext *glb) #endif break; } +#endif case OP_BS_GET_UTF8: { uint32_t fail; @@ -3770,7 +3776,8 @@ HOT_FUNC int scheduler_entry_point(GlobalContext *glb) break; } - case OP_BS_UTF16_SIZE: { +#if MINIMUM_OTP_COMPILER_VERSION <= 24 + case OP_BS_UTF16_SIZE: { uint32_t fail; DECODE_LABEL(fail, pc) term src; @@ -3829,6 +3836,7 @@ HOT_FUNC int scheduler_entry_point(GlobalContext *glb) #endif break; } +#endif case OP_BS_GET_UTF16: { uint32_t fail; @@ -3905,6 +3913,7 @@ HOT_FUNC int scheduler_entry_point(GlobalContext *glb) break; } +#if MINIMUM_OTP_COMPILER_VERSION <= 24 case OP_BS_PUT_UTF32: { uint32_t fail; DECODE_LABEL(fail, pc) @@ -3940,6 +3949,7 @@ HOT_FUNC int scheduler_entry_point(GlobalContext *glb) #endif break; } +#endif case OP_BS_GET_UTF32: { uint32_t fail; @@ -4031,6 +4041,7 @@ HOT_FUNC int scheduler_entry_point(GlobalContext *glb) break; } +#if MINIMUM_OTP_COMPILER_VERSION <= 24 case OP_BS_APPEND: { uint32_t fail; DECODE_LABEL(fail, pc) @@ -4278,7 +4289,9 @@ HOT_FUNC int scheduler_entry_point(GlobalContext *glb) #endif break; } +#endif +#if MINIMUM_OTP_COMPILER_VERSION <= 21 case OP_BS_START_MATCH2: { uint32_t fail; DECODE_LABEL(fail, pc) @@ -4322,7 +4335,9 @@ HOT_FUNC int scheduler_entry_point(GlobalContext *glb) #endif break; } +#endif +#if MAXIMUM_OTP_COMPILER_VERSION >= 22 case OP_BS_START_MATCH3: { // MEMORY_CAN_SHRINK because bs_start_match is classified as gc in beam_ssa_codegen.erl #ifdef IMPL_EXECUTE_LOOP @@ -4454,7 +4469,9 @@ HOT_FUNC int scheduler_entry_point(GlobalContext *glb) #endif break; } +#endif +#if MINIMUM_OTP_COMPILER_VERSION <= 25 case OP_BS_MATCH_STRING: { uint32_t fail; DECODE_LABEL(fail, pc) @@ -4503,7 +4520,9 @@ HOT_FUNC int scheduler_entry_point(GlobalContext *glb) #endif break; } +#endif +#if MINIMUM_OTP_COMPILER_VERSION <= 21 case OP_BS_SAVE2: { term src; DECODE_COMPACT_TERM(src, pc); @@ -4560,6 +4579,7 @@ HOT_FUNC int scheduler_entry_point(GlobalContext *glb) #endif break; } +#endif case OP_BS_SKIP_BITS2: { uint32_t fail; @@ -4602,6 +4622,7 @@ HOT_FUNC int scheduler_entry_point(GlobalContext *glb) break; } +#if MINIMUM_OTP_COMPILER_VERSION <= 24 case OP_BS_TEST_UNIT: { uint32_t fail; DECODE_LABEL(fail, pc) @@ -4655,6 +4676,7 @@ HOT_FUNC int scheduler_entry_point(GlobalContext *glb) #endif break; } +#endif case OP_BS_GET_INTEGER2: { uint32_t fail; @@ -5175,6 +5197,7 @@ HOT_FUNC int scheduler_entry_point(GlobalContext *glb) break; } +#if MINIMUM_OTP_COMPILER_VERSION <= 23 //TODO: stub, implement recv_mark/1 //it looks like it can be safely left unimplemented case OP_RECV_MARK: { @@ -5196,6 +5219,7 @@ HOT_FUNC int scheduler_entry_point(GlobalContext *glb) USED_BY_TRACE(label); break; } +#endif case OP_LINE: { #ifdef IMPL_CODE_LOADER @@ -5536,6 +5560,7 @@ HOT_FUNC int scheduler_entry_point(GlobalContext *glb) break; } +#if MINIMUM_OTP_COMPILER_VERSION <= 23 case OP_FCLEARERROR: { // This can be a noop as we raise from bifs TRACE("fclearerror/0\n"); @@ -5548,6 +5573,7 @@ HOT_FUNC int scheduler_entry_point(GlobalContext *glb) DECODE_LABEL(fail_label, pc); break; } +#endif case OP_FMOVE: { if (IS_EXTENDED_FP_REGISTER(pc)) { @@ -5786,7 +5812,6 @@ HOT_FUNC int scheduler_entry_point(GlobalContext *glb) break; } -#ifdef ENABLE_OTP21 case OP_GET_HD: { term src_value; DECODE_COMPACT_TERM(src_value, pc) @@ -5828,9 +5853,8 @@ HOT_FUNC int scheduler_entry_point(GlobalContext *glb) #endif break; } -#endif -#ifdef ENABLE_OTP22 +#if MAXIMUM_OTP_COMPILER_VERSION >= 22 case OP_PUT_TUPLE2: { dreg_unsafe_t dreg; DECODE_DEST_REGISTER_UNSAFE(dreg, pc); @@ -5869,7 +5893,7 @@ HOT_FUNC int scheduler_entry_point(GlobalContext *glb) } #endif -#ifdef ENABLE_OTP23 +#if MAXIMUM_OTP_COMPILER_VERSION >= 23 case OP_SWAP: { dreg_t reg_a; DECODE_DEST_REGISTER(reg_a, pc); @@ -5927,7 +5951,7 @@ HOT_FUNC int scheduler_entry_point(GlobalContext *glb) } #endif -#ifdef ENABLE_OTP24 +#if MAXIMUM_OTP_COMPILER_VERSION >= 24 case OP_MAKE_FUN3: { uint32_t fun_index; DECODE_LITERAL(fun_index, pc); @@ -6011,7 +6035,7 @@ HOT_FUNC int scheduler_entry_point(GlobalContext *glb) } #endif -#ifdef ENABLE_OTP25 +#if MAXIMUM_OTP_COMPILER_VERSION >= 25 case OP_BS_CREATE_BIN: { uint32_t fail; DECODE_LABEL(fail, pc); @@ -6333,7 +6357,7 @@ HOT_FUNC int scheduler_entry_point(GlobalContext *glb) } #endif -#ifdef ENABLE_OTP26 +#if MAXIMUM_OTP_COMPILER_VERSION >= 26 case OP_UPDATE_RECORD: { #ifdef IMPL_CODE_LOADER TRACE("update_record/5\n");