Skip to content

Commit

Permalink
WIP: Simplify extraction of binary of dynamic size
Browse files Browse the repository at this point in the history
Does not build for:

* jit/x86
* emu
  • Loading branch information
bjorng committed Oct 26, 2024
1 parent 9a194e9 commit f5efd7a
Show file tree
Hide file tree
Showing 5 changed files with 11 additions and 38 deletions.
2 changes: 1 addition & 1 deletion erts/emulator/beam/erl_bits.c
Original file line number Diff line number Diff line change
Expand Up @@ -511,7 +511,7 @@ Process *p, Uint num_bits, unsigned flags, ErlSubBits *sb)
}

Eterm
erts_bs_get_binary_2(Process *p, Uint num_bits, unsigned flags, ErlSubBits *sb)
erts_bs_get_binary_2(Process *p, Uint num_bits, ErlSubBits *sb)
{
Eterm result;

Expand Down
2 changes: 1 addition & 1 deletion erts/emulator/beam/erl_bits.h
Original file line number Diff line number Diff line change
Expand Up @@ -213,7 +213,7 @@ Eterm erts_bs_get_float_2(Process *p, Uint num_bits, unsigned flags, ErlSubBits*

/* These will create heap binaries when appropriate, so they require free space
* up to BUILD_SUB_BITSTRING_HEAP_NEED. */
Eterm erts_bs_get_binary_2(Process *p, Uint num_bits, unsigned flags, ErlSubBits* sb);
Eterm erts_bs_get_binary_2(Process *p, Uint num_bits, ErlSubBits* sb);
Eterm erts_bs_get_binary_all_2(Process *p, ErlSubBits* sb);

/* Binary construction, new instruction set. */
Expand Down
29 changes: 0 additions & 29 deletions erts/emulator/beam/jit/arm/generators.tab
Original file line number Diff line number Diff line change
Expand Up @@ -302,35 +302,6 @@ gen.new_small_map_lit(Dst, Live, Size, Rest) {
return op;
}

// Generate the fastest instruction to fetch a binary from a binary.
gen.get_binary2(Fail, Ms, Live, Size, Unit, Flags, Dst) {
BeamOp* op;

$NewBeamOp(S, op);
$NativeEndian(Flags);

if (Size.type == TAG_a && Size.val == am_all) {
$BeamOpNameArity(op, i_bs_get_binary_all2, 5);
op->a[0] = Ms;
op->a[1] = Fail;
op->a[2] = Live;
op->a[3] = Unit;
op->a[4] = Dst;
} else {
$BeamOpNameArity(op, i_bs_get_binary2, 6);
op->a[0] = Ms;
op->a[1] = Fail;
op->a[2] = Live;
op->a[3] = Size;
op->a[4].type = TAG_u;
op->a[4].val = (Unit.val << 3) | Flags.val;
op->a[5] = Dst;
}

op->next = NULL;
return op;
}

gen.skip_utf16(Fail, Ms, Flags) {
BeamOp* op;
$NewBeamOp(S, op);
Expand Down
9 changes: 4 additions & 5 deletions erts/emulator/beam/jit/arm/instr_bs.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -551,13 +551,13 @@ void BeamModuleAssembler::emit_i_bs_get_binary2(const ArgRegister &Ctx,
const ArgLabel &Fail,
const ArgWord &Live,
const ArgSource &Size,
const ArgWord &Flags,
const ArgWord &Unit,
const ArgRegister &Dst) {
Label fail;
int unit;

fail = resolve_beam_label(Fail, dispUnknown);
unit = Flags.get() >> 3;
unit = Unit.get();

if (emit_bs_get_field_size(Size, unit, fail, ARG2) >= 0) {
a.str(ARG2, TMP_MEM1q);
Expand All @@ -569,14 +569,13 @@ void BeamModuleAssembler::emit_i_bs_get_binary2(const ArgRegister &Ctx,
Ctx,
ARG4);

emit_untag_ptr(ARG4, ARG4);
emit_untag_ptr(ARG3, ARG4);

emit_enter_runtime<Update::eHeapOnlyAlloc>(Live.get());

a.mov(ARG1, c_p);
a.ldr(ARG2, TMP_MEM1q);
mov_imm(ARG3, Flags.get());
runtime_call<4>(erts_bs_get_binary_2);
runtime_call<3>(erts_bs_get_binary_2);

emit_leave_runtime<Update::eHeapOnlyAlloc>(Live.get());

Expand Down
7 changes: 5 additions & 2 deletions erts/emulator/beam/jit/arm/ops.tab
Original file line number Diff line number Diff line change
Expand Up @@ -974,8 +974,11 @@ i_bs_match_string S f W M
bs_get_integer2 f S t s t t d

# Fetching binaries from binaries.
bs_get_binary2 Fail=f Ms=xy Live=u Sz=sq Unit=u Flags=u Dst=d =>
get_binary2(Fail, Ms, Live, Sz, Unit, Flags, Dst)
bs_get_binary2 Fail=f Ms=xy Live=u _Sz=a==am_all Unit=u _Flags=u Dst=d =>
i_bs_get_binary_all2 Ms Fail Live Unit Dst

bs_get_binary2 Fail=f Ms=xy Live=u Sz=s Unit=u _Flags=u Dst=d =>
i_bs_get_binary2 Ms Fail Live Sz Unit Dst

i_bs_get_binary2 S f t s t d
i_bs_get_binary_all2 S f t t d
Expand Down

0 comments on commit f5efd7a

Please sign in to comment.