mirror of
https://github.com/ilyakooo0/urbit.git
synced 2024-12-15 10:02:47 +03:00
ur: refactors ur_met, deduplicating and using bloq-conversion macros
This commit is contained in:
parent
76f1b78218
commit
6477f63045
@ -505,40 +505,16 @@ ur_bytes(ur_root_t *r, ur_nref ref, uint8_t **byt, uint64_t *len)
|
||||
uint64_t
|
||||
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;
|
||||
|
||||
{
|
||||
// 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 len = r->atoms.lens[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 ) {
|
||||
case 0: return m_bit;
|
||||
case 1: return (m_bit + 1) >> 1;
|
||||
case 2: return (m_bit + 3) >> 2;
|
||||
case 1: return ur_bloq_up1(m_bit);
|
||||
case 2: return ur_bloq_up2(m_bit);
|
||||
|
||||
{
|
||||
// hand-inline of ur_met3_64
|
||||
//
|
||||
uint64_t m_byt = (m_bit >> 3) + !!ur_mask_3(m_bit);
|
||||
uint64_t m_byt = ur_bloq_up3(m_bit);
|
||||
|
||||
case 3: return m_byt;
|
||||
default: {
|
||||
@ -563,8 +537,6 @@ ur_met(ur_root_t *r, uint8_t bloq, ur_nref ref)
|
||||
}
|
||||
}
|
||||
}
|
||||
} break;
|
||||
}
|
||||
}
|
||||
|
||||
static ur_nref
|
||||
|
Loading…
Reference in New Issue
Block a user