Skip to content

Commit

Permalink
Define sets of opcodes per versions of OTP compiler
Browse files Browse the repository at this point in the history
Signed-off-by: Paul Guyot <[email protected]>
  • Loading branch information
pguyot committed Sep 2, 2023
1 parent 7b2678e commit be6c4d2
Showing 1 changed file with 38 additions and 14 deletions.
52 changes: 38 additions & 14 deletions src/libAtomVM/opcodesswitch.h
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -2096,6 +2095,7 @@ HOT_FUNC int scheduler_entry_point(GlobalContext *glb)
#endif
break;
}
#endif

case OP_TEST_HEAP: {
uint32_t heap_need;
Expand Down Expand Up @@ -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);
Expand All @@ -3072,6 +3073,7 @@ HOT_FUNC int scheduler_entry_point(GlobalContext *glb)
#endif
break;
}
#endif

case OP_PUT_LIST: {

Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -3138,6 +3141,7 @@ HOT_FUNC int scheduler_entry_point(GlobalContext *glb)
}
break;
}
#endif

case OP_BADMATCH: {
#ifdef IMPL_EXECUTE_LOOP
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -3694,6 +3699,7 @@ HOT_FUNC int scheduler_entry_point(GlobalContext *glb)
#endif
break;
}
#endif

case OP_BS_GET_UTF8: {
uint32_t fail;
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -3829,6 +3836,7 @@ HOT_FUNC int scheduler_entry_point(GlobalContext *glb)
#endif
break;
}
#endif

case OP_BS_GET_UTF16: {
uint32_t fail;
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -3940,6 +3949,7 @@ HOT_FUNC int scheduler_entry_point(GlobalContext *glb)
#endif
break;
}
#endif

case OP_BS_GET_UTF32: {
uint32_t fail;
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -4560,6 +4579,7 @@ HOT_FUNC int scheduler_entry_point(GlobalContext *glb)
#endif
break;
}
#endif

case OP_BS_SKIP_BITS2: {
uint32_t fail;
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -4655,6 +4676,7 @@ HOT_FUNC int scheduler_entry_point(GlobalContext *glb)
#endif
break;
}
#endif

case OP_BS_GET_INTEGER2: {
uint32_t fail;
Expand Down Expand Up @@ -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: {
Expand All @@ -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
Expand Down Expand Up @@ -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");
Expand All @@ -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)) {
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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");
Expand Down

0 comments on commit be6c4d2

Please sign in to comment.