Skip to content

Commit

Permalink
Simplify an instruction only found in unoptimized code
Browse files Browse the repository at this point in the history
The `bs_get_tail2` instruction is only found in unoptimized code and
in code compiled by Erlang/OTP 25 and earlier. Simplify the
implementation by utilizing the code generation for `bs_match`.
  • Loading branch information
bjorng committed Nov 4, 2024
1 parent 8d92b40 commit d089e8e
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 30 deletions.
21 changes: 5 additions & 16 deletions erts/emulator/beam/jit/arm/instr_bs.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -351,23 +351,12 @@ void BeamModuleAssembler::emit_bs_get_integer2(const ArgLabel &Fail,
void BeamModuleAssembler::emit_bs_test_tail2(const ArgLabel &Fail,
const ArgRegister &Ctx,
const ArgWord &Offset) {
const int start_offset = offsetof(ErlSubBits, start);
const int end_offset = offsetof(ErlSubBits, end);

auto ctx_reg = load_source(Ctx, TMP1);

ASSERT(Offset.isWord());

a.ldur(TMP2, emit_boxed_val(ctx_reg.reg, end_offset));
a.ldur(TMP3, emit_boxed_val(ctx_reg.reg, start_offset));
a.sub(TMP2, TMP2, TMP3);
/* This instruction is only found in unoptimized code and in code
* compiled for Erlang/OTP 25 and earlier. */
const ArgVal match[] = {ArgAtom(am_ensure_exactly), Offset};
const Span<ArgVal> args(match, sizeof(match) / sizeof(match[0]));

if (Offset.get() != 0) {
cmp(TMP2, Offset.get());
a.b_ne(resolve_beam_label(Fail, disp1MB));
} else {
a.cbnz(TMP2, resolve_beam_label(Fail, disp1MB));
}
emit_i_bs_match(Fail, Ctx, args);
}

void BeamModuleAssembler::emit_bs_set_position(const ArgRegister &Ctx,
Expand Down
19 changes: 5 additions & 14 deletions erts/emulator/beam/jit/x86/instr_bs.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -370,21 +370,12 @@ void BeamModuleAssembler::emit_bs_get_integer2(const ArgLabel &Fail,
void BeamModuleAssembler::emit_bs_test_tail2(const ArgLabel &Fail,
const ArgRegister &Ctx,
const ArgWord &Offset) {
mov_arg(ARG1, Ctx);

a.mov(ARG2, emit_boxed_val(ARG1, offsetof(ErlSubBits, end)));
a.sub(ARG2, emit_boxed_val(ARG1, offsetof(ErlSubBits, start)));

if (Offset.get() != 0) {
if (Support::isInt32(Offset.get())) {
a.cmp(ARG2, imm(Offset.get()));
} else {
mov_imm(RET, Offset.get());
a.cmp(ARG2, RET);
}
}
/* This instruction is only found in unoptimized code and in code
* compiled for Erlang/OTP 25 and earlier. */
const ArgVal match[] = {ArgAtom(am_ensure_exactly), Offset};
const Span<ArgVal> args(match, sizeof(match) / sizeof(match[0]));

a.jne(resolve_beam_label(Fail));
emit_i_bs_match(Fail, Ctx, args);
}

void BeamModuleAssembler::emit_bs_set_position(const ArgRegister &Ctx,
Expand Down

0 comments on commit d089e8e

Please sign in to comment.