ur: refactors ur_met, deduplicating and using bloq-conversion macros

This commit is contained in:
Joe Bryan 2020-09-15 14:06:46 -07:00
parent 76f1b78218
commit 6477f63045

View File

@ -505,40 +505,16 @@ ur_bytes(ur_root_t *r, ur_nref ref, uint8_t **byt, uint64_t *len)
uint64_t uint64_t
ur_met(ur_root_t *r, uint8_t bloq, ur_nref ref) ur_met(ur_root_t *r, uint8_t bloq, ur_nref ref)
{ {
assert( !ur_deep(ref) );
// these cases are the same, except for the
// bit-width calculation and the width of their operands
//
switch ( ur_nref_tag(ref) ) {
default: assert(0);
case ur_direct: {
uint8_t m_bit = ur_met0_64(ref);
switch ( bloq ) {
case 0: return m_bit;
case 1: return (m_bit + 1) >> 1;
case 2: return (m_bit + 3) >> 2;
{
// hand-inline of ur_met3_64
//
uint8_t m_byt = (m_bit >> 3) + !!ur_mask_3(m_bit);
case 3: return m_byt;
default: {
uint8_t off = (bloq - 3);
return (m_byt + ((1 << off) - 1)) >> off;
}
}
}
} break;
case ur_iatom: {
uint64_t m_bit; uint64_t m_bit;
{ // XX return bool for cells, length in out parameter
//
assert( !ur_deep(ref) );
if ( ur_direct == ur_nref_tag(ref) ) {
m_bit = ur_met0_64(ref);
}
else {
uint64_t idx = ur_nref_idx(ref); uint64_t idx = ur_nref_idx(ref);
uint64_t len = r->atoms.lens[idx]; uint64_t len = r->atoms.lens[idx];
uint8_t *byt = r->atoms.bytes[idx]; uint8_t *byt = r->atoms.bytes[idx];
@ -548,13 +524,11 @@ ur_met(ur_root_t *r, uint8_t bloq, ur_nref ref)
switch ( bloq ) { switch ( bloq ) {
case 0: return m_bit; case 0: return m_bit;
case 1: return (m_bit + 1) >> 1; case 1: return ur_bloq_up1(m_bit);
case 2: return (m_bit + 3) >> 2; case 2: return ur_bloq_up2(m_bit);
{ {
// hand-inline of ur_met3_64 uint64_t m_byt = ur_bloq_up3(m_bit);
//
uint64_t m_byt = (m_bit >> 3) + !!ur_mask_3(m_bit);
case 3: return m_byt; case 3: return m_byt;
default: { default: {
@ -563,8 +537,6 @@ ur_met(ur_root_t *r, uint8_t bloq, ur_nref ref)
} }
} }
} }
} break;
}
} }
static ur_nref static ur_nref