From 14c8b7ce9e24a3db397788147c566bf784960f56 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bj=C3=B6rn=20Gustavsson?= Date: Tue, 4 Mar 2025 07:29:44 +0100 Subject: [PATCH] instr_bs.cpp: Improve coverage The `i_bs_validate_unicode_retract` always has a non-zero label, so there is no need to handle a zero label. In the `BsmSegment::action::GET_INTEGER` action, the segment size is always more than 64 bits. In the `BsmSegment::action::GET_BITSTRING` action, the position can never be valid. --- erts/emulator/beam/jit/arm/instr_bs.cpp | 29 ++++++------------------- erts/emulator/beam/jit/x86/instr_bs.cpp | 28 +++++------------------- 2 files changed, 13 insertions(+), 44 deletions(-) diff --git a/erts/emulator/beam/jit/arm/instr_bs.cpp b/erts/emulator/beam/jit/arm/instr_bs.cpp index b542c4e20b75..9e186bcff9ef 100644 --- a/erts/emulator/beam/jit/arm/instr_bs.cpp +++ b/erts/emulator/beam/jit/arm/instr_bs.cpp @@ -972,11 +972,8 @@ void BeamModuleAssembler::emit_i_bs_validate_unicode_retract( a.sub(TMP1, TMP1, imm(32)); a.stur(TMP1, emit_boxed_val(ctx_reg.reg, start_offset)); - if (Fail.get() != 0) { - a.b(resolve_beam_label(Fail, disp128MB)); - } else { - emit_error(BADARG); - } + ASSERT(Fail.get() != 0); + a.b(resolve_beam_label(Fail, disp128MB)); } a.bind(next); @@ -3519,6 +3516,7 @@ void BeamModuleAssembler::emit_i_bs_match_test_heap(ArgLabel const &Fail, break; } case BsmSegment::action::GET_INTEGER: { + /* Match integer segments with more than 64 bits. */ Uint live = seg.live.as().get(); Uint flags = seg.flags; auto bits = seg.size; @@ -3532,20 +3530,10 @@ void BeamModuleAssembler::emit_i_bs_match_test_heap(ArgLabel const &Fail, a.mov(ARG3, flags); emit_untag_ptr(ARG4, ctx.reg); - if (bits >= SMALL_BITS) { - emit_enter_runtime(live); - } else { - emit_enter_runtime(live); - } - + emit_enter_runtime(live); runtime_call(); - - if (bits >= SMALL_BITS) { - emit_leave_runtime(live); - } else { - emit_leave_runtime(live); - } + emit_leave_runtime(live); mov_arg(Dst, ARG1); @@ -3559,11 +3547,8 @@ void BeamModuleAssembler::emit_i_bs_match_test_heap(ArgLabel const &Fail, comment("get binary %ld", seg.size); auto ctx = load_source(Ctx, TMP1); - if (position_is_valid) { - a.mov(ARG5, bin_position); - } else { - a.ldur(ARG5, emit_boxed_val(ctx.reg, start_offset)); - } + a.ldur(ARG5, emit_boxed_val(ctx.reg, start_offset)); + lea(ARG1, arm::Mem(c_p, offsetof(Process, htop))); if (seg.size <= ERL_ONHEAP_BITS_LIMIT) { comment("skipped setting registers not used for heap binary"); diff --git a/erts/emulator/beam/jit/x86/instr_bs.cpp b/erts/emulator/beam/jit/x86/instr_bs.cpp index adef43e1b870..d907a499e941 100644 --- a/erts/emulator/beam/jit/x86/instr_bs.cpp +++ b/erts/emulator/beam/jit/x86/instr_bs.cpp @@ -1055,11 +1055,8 @@ void BeamModuleAssembler::emit_i_bs_validate_unicode_retract( a.sub(emit_boxed_val(ARG1, offsetof(ErlSubBits, start)), imm(32)); - if (Fail.get() != 0) { - a.jmp(resolve_beam_label(Fail)); - } else { - emit_error(BADARG); - } + ASSERT(Fail.get() != 0); + a.jmp(resolve_beam_label(Fail)); } a.bind(next); @@ -3791,6 +3788,7 @@ void BeamModuleAssembler::emit_i_bs_match_test_heap(ArgLabel const &Fail, break; } case BsmSegment::action::GET_INTEGER: { + /* Match integer segments with more than 64 bits. */ Uint flags = seg.flags; auto bits = seg.size; auto Dst = seg.dst; @@ -3802,12 +3800,7 @@ void BeamModuleAssembler::emit_i_bs_match_test_heap(ArgLabel const &Fail, a.mov(ARG4, ctx); } - if (bits >= SMALL_BITS) { - emit_enter_runtime(); - } else { - emit_enter_runtime(); - } + emit_enter_runtime(); a.mov(ARG1, c_p); a.mov(ARG2, bits); @@ -3816,12 +3809,7 @@ void BeamModuleAssembler::emit_i_bs_match_test_heap(ArgLabel const &Fail, runtime_call(); - if (bits >= SMALL_BITS) { - emit_leave_runtime(); - } else { - emit_leave_runtime(); - } + emit_leave_runtime(); mov_arg(Dst, RET); @@ -3837,11 +3825,7 @@ void BeamModuleAssembler::emit_i_bs_match_test_heap(ArgLabel const &Fail, mov_arg(RET, Ctx); } emit_enter_runtime(); - if (is_position_valid) { - a.mov(ARG5, bin_position); - } else { - a.mov(ARG5, emit_boxed_val(RET, start_offset)); - } + a.mov(ARG5, emit_boxed_val(RET, start_offset)); a.lea(ARG1, x86::qword_ptr(c_p, offsetof(Process, htop))); if (seg.size <= ERL_ONHEAP_BITS_LIMIT) { comment("skipped setting registers not used for heap binary");