Skip to content

Commit

Permalink
Merge pull request erlang#8211 from bjorng/bjorn/erts/eliminate-halfw…
Browse files Browse the repository at this point in the history
…ord-vestiges

Eliminate vestiges of the half-word runtime system
  • Loading branch information
bjorng authored Mar 8, 2024
2 parents b9306c7 + f8c8dc9 commit 015fab5
Show file tree
Hide file tree
Showing 11 changed files with 78 additions and 99 deletions.
12 changes: 6 additions & 6 deletions erts/emulator/beam/big.c
Original file line number Diff line number Diff line change
Expand Up @@ -1934,7 +1934,7 @@ erts_uint64_array_to_big(Uint **hpp, int neg, int len, Uint64 *array)
** Convert a bignum to a double float
*/
int
big_to_double(Wterm x, double* resp)
big_to_double(Eterm x, double* resp)
{
double d = 0.0;
Eterm* xp = big_val(x);
Expand Down Expand Up @@ -2013,7 +2013,7 @@ double_to_big(double x, Eterm *heap, Uint hsz)
/*
** Estimate the number of digits in given base (include sign)
*/
int big_integer_estimate(Wterm x, Uint base)
int big_integer_estimate(Eterm x, Uint base)
{
Eterm* xp = big_val(x);
int lg = I_lg(BIG_V(xp), BIG_SIZE(xp));
Expand All @@ -2026,7 +2026,7 @@ int big_integer_estimate(Wterm x, Uint base)
/*
** Convert a bignum into a string of numbers in given base
*/
static Uint write_big(Wterm x, int base, void (*write_func)(void *, char),
static Uint write_big(Eterm x, int base, void (*write_func)(void *, char),
void *arg)
{
Eterm* xp = big_val(x);
Expand Down Expand Up @@ -2133,7 +2133,7 @@ write_string(void *arg, char c)
*(--(*((char **) arg))) = c;
}

char *erts_big_to_string(Wterm x, int base, char *buf, Uint buf_sz)
char *erts_big_to_string(Eterm x, int base, char *buf, Uint buf_sz)
{
char *big_str = buf + buf_sz - 1;
*big_str = '\0';
Expand Down Expand Up @@ -2191,7 +2191,7 @@ static Eterm big_norm(Eterm *x, dsize_t xl, short sign)
/*
** Compare bignums
*/
int big_comp(Wterm x, Wterm y)
int big_comp(Eterm x, Eterm y)
{
Eterm* xp = big_val(x);
Eterm* yp = big_val(y);
Expand Down Expand Up @@ -2582,7 +2582,7 @@ static Eterm B_plus_minus(ErtsDigit *x, dsize_t xl, short xsgn,
/*
** Add bignums
*/
Eterm big_plus(Wterm x, Wterm y, Eterm *r)
Eterm big_plus(Eterm x, Eterm y, Eterm *r)
{
Eterm* xp = big_val(x);
Eterm* yp = big_val(y);
Expand Down
10 changes: 5 additions & 5 deletions erts/emulator/beam/big.h
Original file line number Diff line number Diff line change
Expand Up @@ -125,14 +125,14 @@ typedef Uint dsize_t; /* Vector size type */

#endif

int big_integer_estimate(Wterm, Uint base);
int big_integer_estimate(Eterm, Uint base);
Eterm erts_big_to_list(Eterm, int base, Eterm**);
char *erts_big_to_string(Wterm x, int base, char *buf, Uint buf_sz);
char *erts_big_to_string(Eterm x, int base, char *buf, Uint buf_sz);
Uint erts_big_to_binary_bytes(Eterm x, int base, char *buf, Uint buf_sz);

Eterm small_times(Sint, Sint, Eterm*);

Eterm big_plus(Wterm, Wterm, Eterm*);
Eterm big_plus(Eterm, Eterm, Eterm*);
Eterm big_minus(Eterm, Eterm, Eterm*);
Eterm big_times(Eterm, Eterm, Eterm*);
Eterm big_mul_add(Eterm x, Eterm y, Eterm z, Eterm *r);
Expand All @@ -152,9 +152,9 @@ Eterm big_bxor(Eterm, Eterm, Eterm*);
Eterm big_bnot(Eterm, Eterm*);

Eterm big_lshift(Eterm, Sint, Eterm*);
int big_comp (Wterm, Wterm);
int big_comp (Eterm, Eterm);
int big_ucomp (Eterm, Eterm);
int big_to_double(Wterm x, double* resp);
int big_to_double(Eterm x, double* resp);
Eterm double_to_big(double, Eterm*, Uint hsz);
Eterm small_to_big(Sint, Eterm*);
Eterm uint_to_big(Uint, Eterm*);
Expand Down
43 changes: 12 additions & 31 deletions erts/emulator/beam/erl_arith.c
Original file line number Diff line number Diff line change
Expand Up @@ -38,13 +38,6 @@
#include "big.h"
#include "atom.h"

#ifndef MAX
# define MAX(x, y) (((x) > (y)) ? (x) : (y))
#endif

#define DECLARE_TMP(VariableName,N,P) Eterm VariableName[2]
#define ARG_IS_NOT_TMP(Arg,Tmp) ((Arg) != make_big((Tmp)))

static ERTS_INLINE void maybe_shrink(Process* p, Eterm* hp, Eterm res, Uint alloc)
{
Uint actual;
Expand Down Expand Up @@ -154,7 +147,7 @@ erts_shift(Process* p, Eterm arg1, Eterm arg2, int right)
{
Sint i;
Sint ires;
DECLARE_TMP(tmp_big1,0,p);
Eterm tmp_big1[2];
Eterm* bigp;
Uint need;

Expand Down Expand Up @@ -319,8 +312,7 @@ BIF_RETTYPE bnot_1(BIF_ALIST_1)
Eterm
erts_mixed_plus(Process* p, Eterm arg1, Eterm arg2)
{
DECLARE_TMP(tmp_big1,0,p);
DECLARE_TMP(tmp_big2,1,p);
Eterm tmp_big1[2], tmp_big2[2];
Eterm res;
Eterm hdr;
FloatDef f1, f2;
Expand Down Expand Up @@ -529,8 +521,7 @@ erts_unary_minus(Process* p, Eterm arg)
Eterm
erts_mixed_minus(Process* p, Eterm arg1, Eterm arg2)
{
DECLARE_TMP(tmp_big1,0,p);
DECLARE_TMP(tmp_big2,1,p);
Eterm tmp_big1[2], tmp_big2[2];
Eterm hdr;
Eterm res;
FloatDef f1, f2;
Expand Down Expand Up @@ -672,8 +663,7 @@ erts_mixed_minus(Process* p, Eterm arg1, Eterm arg2)
Eterm
erts_mixed_times(Process* p, Eterm arg1, Eterm arg2)
{
DECLARE_TMP(tmp_big1,0,p);
DECLARE_TMP(tmp_big2,1,p);
Eterm tmp_big1[2], tmp_big2[2];
Eterm hdr;
Eterm res;
FloatDef f1, f2;
Expand All @@ -697,16 +687,15 @@ erts_mixed_times(Process* p, Eterm arg1, Eterm arg2)
} else if (arg2 == SMALL_ONE) {
return(arg1);
} else {
DeclareTmpHeap(big_res,3,p);
UseTmpHeap(3,p);
Eterm big_res[3];

/*
* The following code is optimized for the case that
* result is small (which should be the most common case
* in practice).
*/
res = small_times(signed_val(arg1), signed_val(arg2), big_res);
if (is_small(res)) {
UnUseTmpHeap(3,p);
return res;
} else {
/*
Expand All @@ -728,7 +717,6 @@ erts_mixed_times(Process* p, Eterm arg1, Eterm arg2)
if (arity > 1) {
*hp = big_res[2];
}
UnUseTmpHeap(3,p);
return res;
}
}
Expand Down Expand Up @@ -1120,9 +1108,7 @@ int erts_int_div_rem(Process* p, Eterm arg1, Eterm arg2, Eterm *q, Eterm *r)
Eterm quotient, remainder;
Eterm lhs, rhs;
int cmp;

DECLARE_TMP(tmp_big1,0,p);
DECLARE_TMP(tmp_big2,1,p);
Eterm tmp_big1[2], tmp_big2[2];

lhs = arg1;
rhs = arg2;
Expand Down Expand Up @@ -1202,8 +1188,7 @@ int erts_int_div_rem(Process* p, Eterm arg1, Eterm arg2, Eterm *q, Eterm *r)
Eterm
erts_int_div(Process* p, Eterm arg1, Eterm arg2)
{
DECLARE_TMP(tmp_big1,0,p);
DECLARE_TMP(tmp_big2,1,p);
Eterm tmp_big1[2], tmp_big2[2];
int ires;

switch (NUMBER_CODE(arg1, arg2)) {
Expand Down Expand Up @@ -1254,8 +1239,7 @@ erts_int_div(Process* p, Eterm arg1, Eterm arg2)
Eterm
erts_int_rem(Process* p, Eterm arg1, Eterm arg2)
{
DECLARE_TMP(tmp_big1,0,p);
DECLARE_TMP(tmp_big2,1,p);
Eterm tmp_big1[2], tmp_big2[2];
int ires;

switch (NUMBER_CODE(arg1, arg2)) {
Expand Down Expand Up @@ -1306,8 +1290,7 @@ erts_int_rem(Process* p, Eterm arg1, Eterm arg2)

Eterm erts_band(Process* p, Eterm arg1, Eterm arg2)
{
DECLARE_TMP(tmp_big1,0,p);
DECLARE_TMP(tmp_big2,1,p);
Eterm tmp_big1[2], tmp_big2[2];
Eterm* hp;
int need;

Expand All @@ -1334,8 +1317,7 @@ Eterm erts_band(Process* p, Eterm arg1, Eterm arg2)

Eterm erts_bor(Process* p, Eterm arg1, Eterm arg2)
{
DECLARE_TMP(tmp_big1,0,p);
DECLARE_TMP(tmp_big2,1,p);
Eterm tmp_big1[2], tmp_big2[2];
Eterm* hp;
int need;

Expand All @@ -1362,8 +1344,7 @@ Eterm erts_bor(Process* p, Eterm arg1, Eterm arg2)

Eterm erts_bxor(Process* p, Eterm arg1, Eterm arg2)
{
DECLARE_TMP(tmp_big1,0,p);
DECLARE_TMP(tmp_big2,1,p);
Eterm tmp_big1[2], tmp_big2[2];
Eterm* hp;
int need;

Expand Down
4 changes: 2 additions & 2 deletions erts/emulator/beam/erl_db.c
Original file line number Diff line number Diff line change
Expand Up @@ -1468,7 +1468,7 @@ do_update_counter(Process *p, DbTable* tb,
Eterm* tpl;
Sint position;
Eterm incr, warp;
Wterm oldcnt;
Eterm oldcnt;

if (is_not_list(iter)) {
goto finalize;
Expand Down Expand Up @@ -1552,7 +1552,7 @@ do_update_counter(Process *p, DbTable* tb,
Eterm* tpl = tuple_val(CAR(list_val(iter)));
Sint position = signed_val(tpl[1]);
Eterm incr = tpl[2];
Wterm oldcnt = db_do_read_element(&handle,position);
Eterm oldcnt = db_do_read_element(&handle,position);
Eterm newcnt = db_add_counter(&htop, oldcnt, incr);

if (newcnt == NIL) {
Expand Down
8 changes: 4 additions & 4 deletions erts/emulator/beam/erl_db_util.c
Original file line number Diff line number Diff line change
Expand Up @@ -3147,13 +3147,13 @@ void db_free_dmc_err_info(DMCErrInfo *ei){
** Store bignum in *hpp and increase *hpp accordingly.
** *hpp is assumed to be large enough to hold the result.
*/
Eterm db_add_counter(Eterm** hpp, Wterm counter, Eterm incr)
Eterm db_add_counter(Eterm** hpp, Eterm counter, Eterm incr)
{
DeclareTmpHeapNoproc(big_tmp,2);
Eterm res;
Sint ires;
Wterm arg1;
Wterm arg2;
Eterm arg1;
Eterm arg2;

if (is_both_small(counter,incr)) {
ires = signed_val(counter) + signed_val(incr);
Expand Down Expand Up @@ -3197,7 +3197,7 @@ Eterm db_add_counter(Eterm** hpp, Wterm counter, Eterm incr)
/* Must be called to read elements after db_lookup_dbterm.
** Will decompress if needed.
*/
Wterm db_do_read_element(DbUpdateHandle* handle, Sint position)
Eterm db_do_read_element(DbUpdateHandle* handle, Sint position)
{
Eterm elem = handle->dbterm->tpl[position];
if (!is_header(elem)) {
Expand Down
4 changes: 2 additions & 2 deletions erts/emulator/beam/erl_db_util.h
Original file line number Diff line number Diff line change
Expand Up @@ -400,7 +400,7 @@ void db_free_tmp_uncompressed(DbTerm* obj);
ERTS_GLB_INLINE Eterm db_copy_object_from_ets(DbTableCommon* tb, DbTerm* bp,
Eterm** hpp, ErlOffHeap* off_heap);
ERTS_GLB_INLINE int db_eq(DbTableCommon* tb, Eterm a, DbTerm* b);
Wterm db_do_read_element(DbUpdateHandle* handle, Sint position);
Eterm db_do_read_element(DbUpdateHandle* handle, Sint position);

#if ERTS_GLB_INLINE_INCL_FUNC_DEF

Expand Down Expand Up @@ -478,7 +478,7 @@ void db_do_update_element(DbUpdateHandle* handle,
Sint position,
Eterm newval);
void db_finalize_resize(DbUpdateHandle* handle, Uint offset);
Eterm db_add_counter(Eterm** hpp, Wterm counter, Eterm incr);
Eterm db_add_counter(Eterm** hpp, Eterm counter, Eterm incr);
Binary *db_match_set_compile(Process *p, Eterm matchexpr,
Uint flags, Uint *freasonp);
int db_match_keeps_key(int keypos, Eterm match, Eterm guard, Eterm body);
Expand Down
4 changes: 2 additions & 2 deletions erts/emulator/beam/erl_lock_check.c
Original file line number Diff line number Diff line change
Expand Up @@ -426,7 +426,7 @@ new_locked_lock(lc_thread_t* thr,
}

static void
raw_print_lock(char *prefix, Sint16 id, Wterm extra, erts_lock_flags_t flags,
raw_print_lock(char *prefix, Sint16 id, Eterm extra, erts_lock_flags_t flags,
const char* file, unsigned int line, char *suffix)
{
char *lname = (1 <= id && id < ERTS_LOCK_ORDER_SIZE
Expand All @@ -447,7 +447,7 @@ raw_print_lock(char *prefix, Sint16 id, Wterm extra, erts_lock_flags_t flags,
}

static void
print_lock2(char *prefix, Sint16 id, Wterm extra, erts_lock_flags_t flags, char *suffix)
print_lock2(char *prefix, Sint16 id, Eterm extra, erts_lock_flags_t flags, char *suffix)
{
raw_print_lock(prefix, id, extra, flags, NULL, 0, suffix);
}
Expand Down
4 changes: 2 additions & 2 deletions erts/emulator/beam/erl_printf_term.c
Original file line number Diff line number Diff line change
Expand Up @@ -372,7 +372,7 @@ print_term(fmtfn_t fn, void* arg, Eterm obj, long *dcount) {
Eterm* ptr;
}popped;
Eterm* nobj;
Wterm wobj;
Eterm wobj;

res = 0;

Expand Down Expand Up @@ -462,7 +462,7 @@ print_term(fmtfn_t fn, void* arg, Eterm obj, long *dcount) {
}
goto L_done;
}
wobj = (Wterm)obj;
wobj = (Eterm)obj;
switch (tag_val_def(wobj)) {
case NIL_DEF:
PRINT_STRING(res, fn, arg, "[]");
Expand Down
38 changes: 19 additions & 19 deletions erts/emulator/beam/erl_term.c
Original file line number Diff line number Diff line change
Expand Up @@ -166,40 +166,40 @@ FUNTY checked_##FUN(ARGTY x, const char *file, unsigned line) \

ET_DEFINE_CHECKED(Eterm,make_boxed,const Eterm*,_is_taggable_pointer);
ET_DEFINE_CHECKED(int,is_boxed,Eterm,!is_header);
ET_DEFINE_CHECKED(Eterm*,boxed_val,Wterm,_boxed_precond);
ET_DEFINE_CHECKED(Eterm*,boxed_val,Eterm,_boxed_precond);
ET_DEFINE_CHECKED(Eterm,make_list,const Eterm*,_is_taggable_pointer);
ET_DEFINE_CHECKED(int,is_not_list,Eterm,!is_header);
ET_DEFINE_CHECKED(Eterm*,list_val,Wterm,_list_precond);
ET_DEFINE_CHECKED(Eterm*,list_val,Eterm,_list_precond);
ET_DEFINE_CHECKED(Uint,unsigned_val,Eterm,is_small);
ET_DEFINE_CHECKED(Sint,signed_val,Eterm,is_small);
ET_DEFINE_CHECKED(Uint,atom_val,Eterm,is_atom);
ET_DEFINE_CHECKED(Uint,header_arity,Eterm,is_header);
ET_DEFINE_CHECKED(Uint,arityval,Eterm,is_sane_arity_value);
ET_DEFINE_CHECKED(Uint,thing_arityval,Eterm,is_thing);
ET_DEFINE_CHECKED(Uint,thing_subtag,Eterm,is_thing);
ET_DEFINE_CHECKED(Eterm*,bitstring_val,Wterm,is_bitstring);
ET_DEFINE_CHECKED(Eterm*,fun_val,Wterm,is_any_fun);
ET_DEFINE_CHECKED(Eterm*,bitstring_val,Eterm,is_bitstring);
ET_DEFINE_CHECKED(Eterm*,fun_val,Eterm,is_any_fun);
ET_DEFINE_CHECKED(int,bignum_header_is_neg,Eterm,_is_bignum_header);
ET_DEFINE_CHECKED(Eterm,bignum_header_neg,Eterm,_is_bignum_header);
ET_DEFINE_CHECKED(Uint,bignum_header_arity,Eterm,_is_bignum_header);
ET_DEFINE_CHECKED(Eterm*,big_val,Wterm,is_big);
ET_DEFINE_CHECKED(Eterm*,float_val,Wterm,is_float);
ET_DEFINE_CHECKED(Eterm*,tuple_val,Wterm,is_tuple);
ET_DEFINE_CHECKED(Eterm*,big_val,Eterm,is_big);
ET_DEFINE_CHECKED(Eterm*,float_val,Eterm,is_float);
ET_DEFINE_CHECKED(Eterm*,tuple_val,Eterm,is_tuple);
ET_DEFINE_CHECKED(struct erl_node_*,internal_pid_node,Eterm,is_internal_pid);
ET_DEFINE_CHECKED(struct erl_node_*,internal_port_node,Eterm,is_internal_port);
ET_DEFINE_CHECKED(Eterm*,internal_ref_val,Wterm,is_internal_ref);
ET_DEFINE_CHECKED(Uint32*,internal_magic_ref_numbers,Wterm,is_internal_magic_ref);
ET_DEFINE_CHECKED(Uint32*,internal_non_magic_ref_numbers,Wterm,is_internal_non_magic_ref);
ET_DEFINE_CHECKED(Eterm*,internal_ref_val,Eterm,is_internal_ref);
ET_DEFINE_CHECKED(Uint32*,internal_magic_ref_numbers,Eterm,is_internal_magic_ref);
ET_DEFINE_CHECKED(Uint32*,internal_non_magic_ref_numbers,Eterm,is_internal_non_magic_ref);
ET_DEFINE_CHECKED(struct erl_node_*,internal_ref_node,Eterm,is_internal_ref);
ET_DEFINE_CHECKED(Eterm*,external_val,Wterm,is_external);
ET_DEFINE_CHECKED(Uint,external_data_words,Wterm,is_external);
ET_DEFINE_CHECKED(Uint,external_pid_data_words,Wterm,is_external_pid);
ET_DEFINE_CHECKED(struct erl_node_*,external_pid_node,Wterm,is_external_pid);
ET_DEFINE_CHECKED(Uint,external_port_data_words,Wterm,is_external_port);
ET_DEFINE_CHECKED(Uint*,external_port_data,Wterm,is_external_port);
ET_DEFINE_CHECKED(struct erl_node_*,external_port_node,Wterm,is_external_port);
ET_DEFINE_CHECKED(Uint,external_ref_data_words,Wterm,is_external_ref);
ET_DEFINE_CHECKED(Uint32*,external_ref_data,Wterm,is_external_ref);
ET_DEFINE_CHECKED(Eterm*,external_val,Eterm,is_external);
ET_DEFINE_CHECKED(Uint,external_data_words,Eterm,is_external);
ET_DEFINE_CHECKED(Uint,external_pid_data_words,Eterm,is_external_pid);
ET_DEFINE_CHECKED(struct erl_node_*,external_pid_node,Eterm,is_external_pid);
ET_DEFINE_CHECKED(Uint,external_port_data_words,Eterm,is_external_port);
ET_DEFINE_CHECKED(Uint*,external_port_data,Eterm,is_external_port);
ET_DEFINE_CHECKED(struct erl_node_*,external_port_node,Eterm,is_external_port);
ET_DEFINE_CHECKED(Uint,external_ref_data_words,Eterm,is_external_ref);
ET_DEFINE_CHECKED(Uint32*,external_ref_data,Eterm,is_external_ref);
ET_DEFINE_CHECKED(struct erl_node_*,external_ref_node,Eterm,is_external_ref);
ET_DEFINE_CHECKED(Uint,external_thing_data_words,const ExternalThing*,is_thing_ptr);

Expand Down
Loading

0 comments on commit 015fab5

Please sign in to comment.