Skip to content

Commit

Permalink
instr_bs.cpp: Improve coverage
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
bjorng committed Mar 4, 2025
1 parent 3f4c643 commit 14c8b7c
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 44 deletions.
29 changes: 7 additions & 22 deletions erts/emulator/beam/jit/arm/instr_bs.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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<ArgWord>().get();
Uint flags = seg.flags;
auto bits = seg.size;
Expand All @@ -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<Update::eHeapOnlyAlloc>(live);
} else {
emit_enter_runtime(live);
}

emit_enter_runtime<Update::eHeapOnlyAlloc>(live);
runtime_call<Eterm (*)(Process *, Uint, unsigned, ErlSubBits *),
erts_bs_get_integer_2>();

if (bits >= SMALL_BITS) {
emit_leave_runtime<Update::eHeapOnlyAlloc>(live);
} else {
emit_leave_runtime(live);
}
emit_leave_runtime<Update::eHeapOnlyAlloc>(live);

mov_arg(Dst, ARG1);

Expand All @@ -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");
Expand Down
28 changes: 6 additions & 22 deletions erts/emulator/beam/jit/x86/instr_bs.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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;
Expand All @@ -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<Update::eReductions |
Update::eHeapOnlyAlloc>();
} else {
emit_enter_runtime();
}
emit_enter_runtime<Update::eReductions | Update::eHeapOnlyAlloc>();

a.mov(ARG1, c_p);
a.mov(ARG2, bits);
Expand All @@ -3816,12 +3809,7 @@ void BeamModuleAssembler::emit_i_bs_match_test_heap(ArgLabel const &Fail,
runtime_call<Eterm (*)(Process *, Uint, unsigned, ErlSubBits *),
erts_bs_get_integer_2>();

if (bits >= SMALL_BITS) {
emit_leave_runtime<Update::eReductions |
Update::eHeapOnlyAlloc>();
} else {
emit_leave_runtime();
}
emit_leave_runtime<Update::eReductions | Update::eHeapOnlyAlloc>();

mov_arg(Dst, RET);

Expand All @@ -3837,11 +3825,7 @@ void BeamModuleAssembler::emit_i_bs_match_test_heap(ArgLabel const &Fail,
mov_arg(RET, Ctx);
}
emit_enter_runtime<Update::eHeapOnlyAlloc>();
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");
Expand Down

0 comments on commit 14c8b7c

Please sign in to comment.