From 77eae301b33b63d3d3840a0abe651285bc52ce41 Mon Sep 17 00:00:00 2001 From: Kaz Kylheku Date: Mon, 12 Sep 2022 23:10:32 -0700 Subject: Reduce proliferation of TAG_SHIFT. * arith.c (num_to_buffer, c_unum, c_dbl_num, c_dbl_unum, c_num, c_fixnum): Use c_n inline function instead of open coding exactly the same thing. * lib.c (c_chr): Likewise. * struct.c (make_struct_type, lookup_slot, lookup_static_slot_desc, static_slot_p): Likewise. --- arith.c | 12 ++++++------ lib.c | 2 +- struct.c | 10 +++++----- 3 files changed, 12 insertions(+), 12 deletions(-) diff --git a/arith.c b/arith.c index 05edf13f..a9418943 100644 --- a/arith.c +++ b/arith.c @@ -139,7 +139,7 @@ int num_to_buffer(val num, mem_t *buf, int bytes) switch (type(num)) { case CHR: case NUM: { - cnum n = coerce(cnum, num) >> TAG_SHIFT; + cnum n = c_n(num); mem_t *ptr = buf + bytes; for (; n != 0; n >>= 8) { @@ -192,7 +192,7 @@ ucnum c_unum(val num, val self) switch (type(num)) { case CHR: case NUM: { - cnum n = coerce(cnum, num) >> TAG_SHIFT; + cnum n = c_n(num); if (n >= 0) return n; } @@ -229,7 +229,7 @@ dbl_cnum c_dbl_num(val n) { switch (type(n)) { case CHR: case NUM: - return coerce(cnum, n) >> TAG_SHIFT; + return c_n(n); case BGNUM: if (mp_in_double_intptr_range(mp(n))) { double_intptr_t out; @@ -248,7 +248,7 @@ dbl_ucnum c_dbl_unum(val n) switch (type(n)) { case CHR: case NUM: { - dbl_cnum cn = coerce(cnum, n) >> TAG_SHIFT; + dbl_cnum cn = c_n(n); if (cn >= 0) return cn; break; @@ -4133,7 +4133,7 @@ cnum c_num(val n, val self) { switch (type(n)) { case CHR: case NUM: - return coerce(cnum, n) >> TAG_SHIFT; + return c_n(n); case BGNUM: if (mp_in_intptr_range(mp(n))) { int_ptr_t out; @@ -4151,7 +4151,7 @@ cnum c_fixnum(val num, val self) { switch (type(num)) { case CHR: case NUM: - return coerce(cnum, num) >> TAG_SHIFT; + return c_n(num); default: type_mismatch(lit("~a: ~s is not fixnum integer or character"), self, num, nao); diff --git a/lib.c b/lib.c index 9e220f10..464cab79 100644 --- a/lib.c +++ b/lib.c @@ -6654,7 +6654,7 @@ wchar_t c_chr(val chr) { if (!is_chr(chr)) type_mismatch(lit("~s is not a character"), chr, nao); - return convert(wchar_t, coerce(cnum, chr) >> TAG_SHIFT); + return convert(wchar_t, c_n(chr)); } val chr_isalnum(val ch) diff --git a/struct.c b/struct.c index 9fcfd2ad..8adf6323 100644 --- a/struct.c +++ b/struct.c @@ -538,7 +538,7 @@ val make_struct_type(val name, val supers, struct stslot *ss = &st->stslot[n]; val key = if2(su, cons(slot, num_fast(su->id))); val msl = if2(su, gethash(slot_hash, key)); - cnum m = (coerce(cnum, msl) >> TAG_SHIFT) - STATIC_SLOT_BASE; + cnum m = c_n(msl) - STATIC_SLOT_BASE; if (!inherited_p || (opt_compat && opt_compat <= 151)) { ss->home_type = stype; @@ -1123,7 +1123,7 @@ static loc lookup_slot(val inst, struct struct_inst *si, val sym) } else { val key = cons(sym, num_fast(id)); val sl = gethash(slot_hash, key); - cnum slnum = coerce(cnum, sl) >> TAG_SHIFT; + cnum slnum = c_n(sl); rcyc_cons(key); @@ -1157,7 +1157,7 @@ static struct stslot *lookup_static_slot_desc(struct struct_type *st, val sym) } else if (slot < 0) { val key = cons(sym, num_fast(id)); val sl = gethash(slot_hash, key); - cnum slnum = coerce(cnum, sl) >> TAG_SHIFT; + cnum slnum = c_n(sl); rcyc_cons(key); @@ -1174,7 +1174,7 @@ static struct stslot *lookup_static_slot_desc(struct struct_type *st, val sym) slot_cache_set_t *set = &slot_cache[id % SLOT_CACHE_SIZE]; val key = cons(sym, num_fast(id)); val sl = gethash(slot_hash, key); - cnum slnum = coerce(cnum, sl) >> TAG_SHIFT; + cnum slnum = c_n(sl); sym->s.slot_cache = slot_cache; @@ -1574,7 +1574,7 @@ val static_slot_p(val type, val sym) if (memq(sym, st->slots)) { val key = cons(sym, num_fast(st->id)); val sl = gethash(slot_hash, key); - cnum slnum = coerce(cnum, sl) >> TAG_SHIFT; + cnum slnum = c_n(sl); rcyc_cons(key); -- cgit v1.2.3