From b4cffe6445faab14b30569e54a6a6ef7aa0f8464 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bj=C3=B6rn=20Gustavsson?= Date: Fri, 15 Oct 2021 07:00:26 +0200 Subject: wip --- erts/emulator/beam/jit/arm/instr_bs.cpp | 11 ++++--- erts/emulator/beam/jit/beam_jit_common.cpp | 53 ++++++++++++++---------------- erts/emulator/beam/jit/beam_jit_common.hpp | 39 ++++++++++------------ erts/emulator/beam/jit/x86/instr_bs.cpp | 9 ++--- 4 files changed, 54 insertions(+), 58 deletions(-) diff --git a/erts/emulator/beam/jit/arm/instr_bs.cpp b/erts/emulator/beam/jit/arm/instr_bs.cpp index 0b2ae2100d..3de995fcd5 100644 --- a/erts/emulator/beam/jit/arm/instr_bs.cpp +++ b/erts/emulator/beam/jit/arm/instr_bs.cpp @@ -1361,9 +1361,11 @@ void BeamGlobalAssembler::emit_bs_create_bin_error_shared() { emit_enter_runtime(0); + /* ARG3 is already set by the caller */ a.mov(ARG2, ARG4); + a.mov(ARG4, ARG1); a.mov(ARG1, c_p); - runtime_call<3>(beam_jit_bs_construct_fail_info); + runtime_call<4>(beam_jit_bs_construct_fail_info); emit_leave_runtime(0); @@ -1529,13 +1531,12 @@ void BeamModuleAssembler::emit_i_bs_create_bin(const ArgVal &Fail, a.bind(error); { - comment("handle error"); - /* + * ARG1 = optional bad size value; valid if BSC_VALUE_ARG1 is set in ARG4 + * ARG3 = optional bad size value; valid if BSC_VALUE_ARG3 is set in ARG4 * ARG4 = packed error information - * ARG3 = optional bad size value; only valid if - * BSC_REASON_DEPENDS is set in ARG4 */ + comment("handle error"); fragment_call(ga->get_bs_create_bin_error_shared()); last_error_offset = getOffset() & -8; } diff --git a/erts/emulator/beam/jit/beam_jit_common.cpp b/erts/emulator/beam/jit/beam_jit_common.cpp index 0f3afc6536..b9a5024611 100644 --- a/erts/emulator/beam/jit/beam_jit_common.cpp +++ b/erts/emulator/beam/jit/beam_jit_common.cpp @@ -740,16 +740,17 @@ Eterm beam_jit_bs_get_integer(Process *c_p, void beam_jit_bs_construct_fail_info(Process *c_p, Uint packed_error_info, - Eterm bad_value) { + Eterm arg3, Eterm arg1) { Eterm *hp; Eterm cause_tuple; Eterm error_info; Uint segment = beam_jit_get_bsc_segment(packed_error_info); - Uint op = beam_jit_get_bsc_op(packed_error_info); - Uint info = beam_jit_get_bsc_info(packed_error_info); - Uint reason = beam_jit_get_bsc_reason(packed_error_info); - Uint value_location = beam_jit_get_bsc_value(packed_error_info); + JitBSCOp op = beam_jit_get_bsc_op(packed_error_info); + JitBSCInfo info = beam_jit_get_bsc_info(packed_error_info); + JitBSCReason reason = beam_jit_get_bsc_reason(packed_error_info); + JitBSCValue value_location = beam_jit_get_bsc_value(packed_error_info); Eterm Op = am_none; + Uint Reason; Eterm Info = am_none; Eterm value = am_undefined; @@ -774,39 +775,35 @@ void beam_jit_bs_construct_fail_info(Process *c_p, break; } - switch (reason) { - case BSC_REASON_FREASON: - reason = c_p->freason; + switch (value_location) { + case BSC_VALUE_ARG1: + value = arg1; break; + case BSC_VALUE_ARG3: + value = arg3; + break; + case BSC_VALUE_FVALUE: + value = c_p->fvalue; + break; + } + + switch (reason) { case BSC_REASON_BADARG: - reason = BADARG; + Reason = BADARG; break; case BSC_REASON_SYSTEM_LIMIT: - reason = SYSTEM_LIMIT; + Reason = SYSTEM_LIMIT; break; case BSC_REASON_DEPENDS: - if ((is_small(bad_value) && signed_val(bad_value) >= 0) || - (is_big(bad_value) && !big_sign(bad_value))) { - reason = SYSTEM_LIMIT; + if ((is_small(value) && signed_val(value) >= 0) || + (is_big(value) && !big_sign(value))) { + Reason = SYSTEM_LIMIT; } else { - reason = BADARG; + Reason = BADARG; } break; } - switch (value_location) { -#if defined(__aarch64__) - case BSC_VALUE_ARG3: -#else - case BSC_VALUE_ARG1: -#endif - value = bad_value; - break; - case BSC_VALUE_FVALUE: - value = c_p->fvalue; - break; - } - switch (info) { case BSC_INFO_FVALUE: Info = c_p->fvalue; @@ -837,7 +834,7 @@ void beam_jit_bs_construct_fail_info(Process *c_p, am_module, am_erl_erts_errors); c_p->fvalue = error_info; - c_p->freason = reason | EXF_HAS_EXT_INFO; + c_p->freason = Reason | EXF_HAS_EXT_INFO; } Sint beam_jit_bs_bit_size(Eterm term) { diff --git a/erts/emulator/beam/jit/beam_jit_common.hpp b/erts/emulator/beam/jit/beam_jit_common.hpp index ed508ee416..ad651330c3 100644 --- a/erts/emulator/beam/jit/beam_jit_common.hpp +++ b/erts/emulator/beam/jit/beam_jit_common.hpp @@ -235,7 +235,7 @@ public: } }; -static const Uint BSC_SEGMENT_OFFSET = 9; +static const Uint BSC_SEGMENT_OFFSET = 10; typedef enum : Uint { BSC_OP_BINARY = 0, @@ -244,10 +244,10 @@ typedef enum : Uint { BSC_OP_UTF8 = 3, BSC_OP_UTF16 = 4, BSC_OP_UTF32 = 5, - BSC_OP_LAST = 5, - BSC_OP_MASK = 0x07, - BSC_OP_OFFSET = 6 + BSC_OP_LAST = 5 } JitBSCOp; +static const Uint BSC_OP_MASK = 0x07; +static const Uint BSC_OP_OFFSET = 7; typedef enum : Uint { BSC_INFO_FVALUE = 0, @@ -256,30 +256,26 @@ typedef enum : Uint { BSC_INFO_UNIT = 3, BSC_INFO_DEPENDS = 4, BSC_INFO_LAST = 4, - BSC_INFO_MASK = 0x07, - BSC_INFO_OFFSET = 3, } JitBSCInfo; +static const Uint BSC_INFO_MASK = 0x07; +static const Uint BSC_INFO_OFFSET = 4; typedef enum : Uint { - BSC_REASON_FREASON = 0, - BSC_REASON_BADARG = 1, - BSC_REASON_SYSTEM_LIMIT = 2, - BSC_REASON_DEPENDS = 3, - BSC_REASON_LAST = 3, - BSC_REASON_MASK = 0x03 + BSC_REASON_BADARG = 0, + BSC_REASON_SYSTEM_LIMIT = 1, + BSC_REASON_DEPENDS = 2, + BSC_REASON_LAST = 2, } JitBSCReason; +static const Uint BSC_REASON_MASK = 0x03; typedef enum : Uint { -#if defined(__aarch64__) - BSC_VALUE_ARG3 = 0, -#else BSC_VALUE_ARG1 = 0, -#endif - BSC_VALUE_FVALUE = 1, - BSC_VALUE_LAST = 1, - BSC_VALUE_MASK = 0x01, - BSC_VALUE_OFFSET = 2 + BSC_VALUE_ARG3 = 1, + BSC_VALUE_FVALUE = 2, + BSC_VALUE_LAST = 2 } JitBSCValue; +static const Uint BSC_VALUE_MASK = 0x02; +static const Uint BSC_VALUE_OFFSET = 2; static constexpr Uint beam_jit_set_bsc_segment_op(Uint segment, JitBSCOp op) { return (segment << BSC_SEGMENT_OFFSET) | (op << BSC_OP_OFFSET); @@ -375,7 +371,8 @@ Sint beam_jit_remove_message(Process *c_p, void beam_jit_bs_construct_fail_info(Process *c_p, Uint packed_error_info, - Eterm value); + Eterm arg3, + Eterm arg1); Sint beam_jit_bs_bit_size(Eterm term); void beam_jit_take_receive_lock(Process *c_p); diff --git a/erts/emulator/beam/jit/x86/instr_bs.cpp b/erts/emulator/beam/jit/x86/instr_bs.cpp index 8d7ba7d1c7..47c9faa011 100644 --- a/erts/emulator/beam/jit/x86/instr_bs.cpp +++ b/erts/emulator/beam/jit/x86/instr_bs.cpp @@ -1563,10 +1563,11 @@ void BeamModuleAssembler::emit_bs_init_writable() { void BeamGlobalAssembler::emit_bs_create_bin_error_shared() { emit_enter_runtime(); - a.mov(ARG3, ARG1); + /* ARG3 is already set by the caller */ a.mov(ARG2, ARG4); + a.mov(ARG4, ARG1); a.mov(ARG1, c_p); - runtime_call<3>(beam_jit_bs_construct_fail_info); + runtime_call<4>(beam_jit_bs_construct_fail_info); emit_leave_runtime(); @@ -1713,9 +1714,9 @@ void BeamModuleAssembler::emit_i_bs_create_bin(const ArgVal &Fail, a.bind(error); { /* + * ARG1 = optional bad size value; valid if BSC_VALUE_ARG1 is set in ARG4 + * ARG3 = optional bad size value; valid if BSC_VALUE_ARG3 is set in ARG4 * ARG4 = packed error information - * ARG1 = optional bad size value; only valid if BSC_REASON_DEPENDS is - * set in ARG4 */ comment("handle error"); emit_leave_runtime