mirror of
https://github.com/ilyakooo0/urbit.git
synced 2024-12-14 17:41:33 +03:00
ur: refactors ur_met, deduplicating and using bloq-conversion macros
This commit is contained in:
parent
76f1b78218
commit
6477f63045
@ -505,65 +505,37 @@ 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)
|
||||
{
|
||||
uint64_t m_bit;
|
||||
|
||||
// XX return bool for cells, length in out parameter
|
||||
//
|
||||
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);
|
||||
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];
|
||||
|
||||
case ur_direct: {
|
||||
uint8_t m_bit = ur_met0_64(ref);
|
||||
m_bit = ur_met0_bytes_unsafe(len, byt);
|
||||
}
|
||||
|
||||
switch ( bloq ) {
|
||||
case 0: return m_bit;
|
||||
case 1: return (m_bit + 1) >> 1;
|
||||
case 2: return (m_bit + 3) >> 2;
|
||||
switch ( bloq ) {
|
||||
case 0: return m_bit;
|
||||
case 1: return ur_bloq_up1(m_bit);
|
||||
case 2: return ur_bloq_up2(m_bit);
|
||||
|
||||
{
|
||||
// hand-inline of ur_met3_64
|
||||
//
|
||||
uint8_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: {
|
||||
uint8_t off = (bloq - 3);
|
||||
return (m_byt + ((1 << off) - 1)) >> off;
|
||||
}
|
||||
}
|
||||
case 3: return m_byt;
|
||||
default: {
|
||||
uint8_t off = (bloq - 3);
|
||||
return (m_byt + ((1ULL << off) - 1)) >> off;
|
||||
}
|
||||
} break;
|
||||
|
||||
case ur_iatom: {
|
||||
uint64_t m_bit;
|
||||
|
||||
{
|
||||
uint64_t idx = ur_nref_idx(ref);
|
||||
uint64_t len = r->atoms.lens[idx];
|
||||
uint8_t *byt = r->atoms.bytes[idx];
|
||||
|
||||
m_bit = ur_met0_bytes_unsafe(len, byt);
|
||||
}
|
||||
|
||||
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
|
||||
//
|
||||
uint64_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 + ((1ULL << off) - 1)) >> off;
|
||||
}
|
||||
}
|
||||
}
|
||||
} break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user