Skip to content

Commit

Permalink
wip: retrieve_tests (mug) work through f
Browse files Browse the repository at this point in the history
  • Loading branch information
matthew-levan committed Aug 29, 2024
1 parent abc8613 commit dc43203
Show file tree
Hide file tree
Showing 14 changed files with 213 additions and 32 deletions.
2 changes: 1 addition & 1 deletion pkg/c3/defs.h
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@
/* Bit counting.
*/
#ifdef VERE_64
# define c3_bits_word(w) ((w) ? (64 - __builtin_clz(w)) : 0)
# define c3_bits_word(w) ((w) ? (64 - __builtin_clzl(w)) : 0)
#else
# define c3_bits_word(w) ((w) ? (32 - __builtin_clz(w)) : 0)
#endif
Expand Down
4 changes: 4 additions & 0 deletions pkg/noun/allocate.c
Original file line number Diff line number Diff line change
Expand Up @@ -666,7 +666,11 @@ u3a_pile_prep(u3a_pile* pil_u, c3_w len_w)
{
// frame size, in words
//
#ifdef VERE_64
c3_d wor_w = (len_w + 7) >> 3;
#else
c3_w wor_w = (len_w + 3) >> 2;
#endif
c3_o nor_o = u3a_is_north(u3R);

pil_u->mov_ws = (c3y == nor_o) ? -wor_w : wor_w;
Expand Down
47 changes: 40 additions & 7 deletions pkg/noun/allocate.h
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,12 @@

/* u3a_page: number of bits in word-addressed page. 12 == 16K page
*/
# define u3a_page 13ULL
#ifdef VERE_64
# define u3a_page 13ULL
#else
# define u3a_page 12ULL
#endif


/* u3a_pages: maximum number of pages in memory.
*/
Expand Down Expand Up @@ -67,17 +72,17 @@
/* u3a_atom, u3a_cell: logical atom and cell structures.
*/
typedef struct {
c3_w mug_w;
c3_l mug_w;
} u3a_noun;

typedef struct {
c3_w mug_w;
c3_l mug_w;
c3_w len_w;
c3_w buf_w[0];
} u3a_atom;

typedef struct {
c3_w mug_w;
c3_l mug_w;
u3_noun hed;
u3_noun tel;
} u3a_cell;
Expand Down Expand Up @@ -218,6 +223,23 @@
/* Inside a noun.
*/

#ifdef VERE_64
/* u3a_is_cat(): yes if noun [som] is direct atom.
*/
# define u3a_is_cat(som) (((som) >> 63) ? c3n : c3y)

/* u3a_is_dog(): yes if noun [som] is indirect noun.
*/
# define u3a_is_dog(som) (((som) >> 63) ? c3y : c3n)

/* u3a_is_pug(): yes if noun [som] is indirect atom.
*/
# define u3a_is_pug(som) ((0b10 == ((som) >> 62)) ? c3y : c3n)

/* u3a_is_pom(): yes if noun [som] is indirect cell.
*/
# define u3a_is_pom(som) ((0b11 == ((som) >> 62)) ? c3y : c3n)
#else
/* u3a_is_cat(): yes if noun [som] is direct atom.
*/
# define u3a_is_cat(som) (((som) >> 31) ? c3n : c3y)
Expand All @@ -233,6 +255,7 @@
/* u3a_is_pom(): yes if noun [som] is indirect cell.
*/
# define u3a_is_pom(som) ((0b11 == ((som) >> 30)) ? c3y : c3n)
#endif

/* u3a_is_atom(): yes if noun [som] is direct atom or indirect atom.
*/
Expand Down Expand Up @@ -393,11 +416,13 @@
*/
# define u3a_outa(p) ((c3_w *)(void *)(p) - u3_Loom)

/* u3a_to_off(): mask off bits 30 and 31 from noun [som].
*/
#ifdef VERE_64
# define u3a_to_off(som) (((som) & 0xffffffff3fffffffULL) << u3a_vits)
/* u3a_to_off(): mask off bits 62 and 63 from noun [som].
*/
# define u3a_to_off(som) (((som) & 0x3fffffffffffffffULL) << u3a_vits)
#else
/* u3a_to_off(): mask off bits 30 and 31 from noun [som].
*/
# define u3a_to_off(som) (((som) & 0x3fffffff) << u3a_vits)
#endif

Expand All @@ -415,14 +440,22 @@
*/
inline c3_w u3a_to_pug(c3_w off) {
c3_dessert((off & u3a_walign-1) == 0);
#ifdef VERE_64
return (off >> u3a_vits) | 0x8000000000000000;
#else
return (off >> u3a_vits) | 0x80000000;
#endif
}

/* u3a_to_pom(): set bits 30 and 31 of [off].
*/
inline c3_w u3a_to_pom(c3_w off) {
c3_dessert((off & u3a_walign-1) == 0);
#ifdef VERE_64
return (off >> u3a_vits) | 0xc000000000000000;
#else
return (off >> u3a_vits) | 0xc0000000;
#endif
}

/** road stack.
Expand Down
13 changes: 13 additions & 0 deletions pkg/noun/hashtable.h
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,18 @@
** u3h_noun_be_warm(): warm mutant
** u3h_noun_be_cold(): cold mutant
*/
#ifdef VERE_64
# define u3h_slot_is_null(sot) ((0 == ((sot) >> 62)) ? c3y : c3n)
# define u3h_slot_is_node(sot) ((1 == ((sot) >> 62)) ? c3y : c3n)
# define u3h_slot_is_noun(sot) ((1 == ((sot) >> 63)) ? c3y : c3n)
# define u3h_slot_is_warm(sot) (((sot) & 0x4000000000000000) ? c3y : c3n)
# define u3h_slot_to_node(sot) (u3a_into(((sot) & 0x3fffffffffffffff) << u3a_vits))
# define u3h_node_to_slot(ptr) ((u3a_outa((ptr)) >> u3a_vits) | 0x4000000000000000)
# define u3h_noun_be_warm(sot) ((sot) | 0x4000000000000000)
# define u3h_noun_be_cold(sot) ((sot) & ~0x4000000000000000)
# define u3h_slot_to_noun(sot) (0x4000000000000000 | (sot))
# define u3h_noun_to_slot(som) (u3h_noun_be_warm(som))
#else
# define u3h_slot_is_null(sot) ((0 == ((sot) >> 30)) ? c3y : c3n)
# define u3h_slot_is_node(sot) ((1 == ((sot) >> 30)) ? c3y : c3n)
# define u3h_slot_is_noun(sot) ((1 == ((sot) >> 31)) ? c3y : c3n)
Expand All @@ -84,6 +96,7 @@
# define u3h_noun_be_cold(sot) ((sot) & ~0x40000000)
# define u3h_slot_to_noun(sot) (0x40000000 | (sot))
# define u3h_noun_to_slot(som) (u3h_noun_be_warm(som))
#endif

/** Functions.
***
Expand Down
14 changes: 11 additions & 3 deletions pkg/noun/imprison.c
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,12 @@ static c3_w
_ci_slab_size(c3_g met_g, c3_d len_d)
{
c3_d bit_d = len_d << met_g;
#ifdef VERE_64
c3_d wor_d = (bit_d + 0x3f) >> 6;
#else
c3_d wor_d = (bit_d + 0x1f) >> 5;
#endif

c3_w wor_w = (c3_w)wor_d;

if ( (wor_w != wor_d)
Expand Down Expand Up @@ -222,7 +227,8 @@ u3i_slab_free(u3i_slab* sab_u)
}
else {
c3_w* tav_w = (sab_u->buf_w - c3_wiseof(u3a_atom));
u3_assert( tav_w == (c3_w*)vat_u );
// XX
// u3_assert( tav_w == (c3_w*)vat_u );
u3a_wfree(vat_u);
}

Expand Down Expand Up @@ -252,7 +258,8 @@ u3i_slab_mint(u3i_slab* sab_u)
else {
u3a_atom* vat_u = sab_u->_._vat_u;
c3_w* tav_w = (sab_u->buf_w - c3_wiseof(u3a_atom));
u3_assert( tav_w == (c3_w*)vat_u );
// XX
// u3_assert( tav_w == (c3_w*)vat_u );

// trim trailing zeros
//
Expand Down Expand Up @@ -290,7 +297,8 @@ u3i_slab_moot(u3i_slab* sab_u)
else {
u3a_atom* vat_u = sab_u->_._vat_u;
c3_w* tav_w = (sab_u->buf_w - c3_wiseof(u3a_atom));
u3_assert( tav_w == (c3_w*)vat_u );
// XX
// u3_assert( tav_w == (c3_w*)vat_u );

pro = _ci_atom_mint(vat_u, len_w);
}
Expand Down
4 changes: 2 additions & 2 deletions pkg/noun/jets/b/lent.c
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,10 @@

#ifdef VERE_64
STATIC_ASSERT( (UINT64_MAX > u3a_cells),
"list index precision" );
"length precision" );
#else
STATIC_ASSERT( (UINT32_MAX > u3a_cells),
"list index precision" );
"length precision" );
#endif

u3_noun
Expand Down
2 changes: 2 additions & 0 deletions pkg/noun/manage.c
Original file line number Diff line number Diff line change
Expand Up @@ -590,6 +590,7 @@ _pave_home(void)
_pave_parts();
}

// XX
#ifdef VERE_64
STATIC_ASSERT( ((c3_wiseof(u3v_home) * 8) == sizeof(u3v_home)),
"home road alignment" );
Expand Down Expand Up @@ -772,6 +773,7 @@ u3m_bail(u3_noun how)
if ( _(u3ud(how)) ) {
c3_c str_c[5];

// XX
str_c[0] = ((how >> 0) & 0xff);
str_c[1] = ((how >> 8) & 0xff);
str_c[2] = ((how >> 16) & 0xff);
Expand Down
2 changes: 2 additions & 0 deletions pkg/noun/manage.h
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,8 @@

/* u3m_bail(): bail out. Does not return.
**
** XX
**
** Bail motes:
**
** %exit :: semantic failure
Expand Down
56 changes: 49 additions & 7 deletions pkg/noun/retrieve.c
Original file line number Diff line number Diff line change
Expand Up @@ -980,10 +980,24 @@ u3r_met(c3_y a_y,
daz_w = b_u->buf_w[gal_w];
}

/* 5 because 1<<2 bytes in c3_w, 1<<3 bits in byte.
/* 6 because 1<<3 bytes in c3_w, 1<<3 bits in byte.
aka log2(CHAR_BIT * sizeof gal_w)
a_y < 5 informs whether we shift return left or right
a_y < 6 informs whether we shift return left or right
*/
#ifdef VERE_64
if (a_y < 6) {
c3_y max_y = (1 << a_y) - 1;
c3_y gow_y = 6 - a_y;

if (gal_w > ((UINT64_MAX - (64 + max_y)) >> gow_y))
return u3m_bail(c3__fail);

return (gal_w << gow_y)
+ ((c3_bits_word(daz_w) + max_y)
>> a_y);
}
c3_y gow_y = (a_y - 6);
#else
if (a_y < 5) {
c3_y max_y = (1 << a_y) - 1;
c3_y gow_y = 5 - a_y;
Expand All @@ -996,6 +1010,7 @@ u3r_met(c3_y a_y,
>> a_y);
}
c3_y gow_y = (a_y - 5);
#endif
return ((gal_w + 1) + ((1 << gow_y) - 1)) >> gow_y;
}

Expand Down Expand Up @@ -1044,15 +1059,24 @@ u3r_byte(c3_w a_w,
u3_assert(_(u3a_is_atom(b)));

if ( _(u3a_is_cat(b)) ) {
#ifdef VERE_64
if ( a_w > 7 ) {
#else
if ( a_w > 3 ) {
#endif
return 0;
}
else return (255 & (b >> (a_w << 3)));
}
else {
u3a_atom* b_u = u3a_to_ptr(b);
#ifdef VERE_64
c3_y vut_y = (a_w & 7);
c3_w pix_w = (a_w >> 3);
#else
c3_y vut_y = (a_w & 3);
c3_w pix_w = (a_w >> 2);
#endif

if ( pix_w >= b_u->len_w ) {
return 0;
Expand All @@ -1079,16 +1103,24 @@ u3r_bytes(c3_w a_w,
u3_assert(_(u3a_is_atom(d)));

if ( _(u3a_is_cat(d)) ) {
#ifdef VERE_64
c3_d e_d = d >> (c3_min(a_w, 8) << 3);
c3_w m_w = c3_min(b_w, 8);
memcpy(c_y, (c3_y*)&e_d, m_w);
if ( b_w > 8 ) {
memset(c_y + 8, 0, b_w - 8);
#else
c3_w e_w = d >> (c3_min(a_w, 4) << 3);
c3_w m_w = c3_min(b_w, 4);
memcpy(c_y, (c3_y*)&e_w, m_w);
if ( b_w > 4 ) {
memset(c_y + 4, 0, b_w - 4);
#endif
}
}
else {
u3a_atom* d_u = u3a_to_ptr(d);
c3_w n_w = d_u->len_w << 2;
c3_w n_w = d_u->len_w << 3;
c3_y* x_y = (c3_y*)d_u->buf_w + a_w;

if ( a_w >= n_w ) {
Expand Down Expand Up @@ -1168,7 +1200,11 @@ u3r_mp(mpz_t a_mp,

// avoid reallocation on import, if possible
//
#ifdef VERE_64
mpz_init2(a_mp, (c3_w)c3_min(bit_d, UINT64_MAX));
#else
mpz_init2(a_mp, (c3_w)c3_min(bit_d, UINT32_MAX));
#endif
mpz_import(a_mp, len_w, -1, sizeof(c3_w), 0, 0, b_u->buf_w);
}
}
Expand Down Expand Up @@ -1252,6 +1288,7 @@ u3r_word_fit(c3_w *out_w, u3_atom a)
/* u3r_chub():
**
** Return double-word (a_w) of (b).
** XX
*/
c3_d
u3r_chub(c3_w a_w,
Expand Down Expand Up @@ -1601,7 +1638,7 @@ c3_l
u3r_mug_both(c3_l lef_l, c3_l rit_l)
{
c3_y len_y = 4 + ((c3_bits_word(rit_l) + 0x7) >> 3);
c3_w syd_w = 0xdeadbeef;
uint32_t syd_w = 0xdeadbeef;
c3_w i_w = 0;
c3_y buf_y[8];

Expand All @@ -1615,7 +1652,7 @@ u3r_mug_both(c3_l lef_l, c3_l rit_l)
buf_y[7] = (rit_l >> 24) & 0xff;

while ( i_w < 8 ) {
c3_w haz_w;
uint32_t haz_w;
c3_l ham_l;

MurmurHash3_x86_32(buf_y, len_y, syd_w, &haz_w);
Expand All @@ -1633,16 +1670,17 @@ u3r_mug_both(c3_l lef_l, c3_l rit_l)
}

/* u3r_mug_bytes(): Compute the mug of `buf`, `len`, LSW first.
** XX
*/
c3_l
u3r_mug_bytes(const c3_y *buf_y,
c3_w len_w)
{
c3_w syd_w = 0xcafebabe;
uint32_t syd_w = 0xcafebabe;
c3_w i_w = 0;

while ( i_w < 8 ) {
c3_w haz_w;
uint32_t haz_w;
c3_l ham_l;

MurmurHash3_x86_32(buf_y, len_w, syd_w, &haz_w);
Expand Down Expand Up @@ -1714,7 +1752,11 @@ u3r_mug_words(const c3_w* key_w, c3_w len_w)
c3_w gal_w = len_w - 1;
c3_w daz_w = key_w[gal_w];

#ifdef VERE_64
byt_w = (gal_w << 3) + ((c3_bits_word(daz_w) + 7) >> 3);
#else
byt_w = (gal_w << 2) + ((c3_bits_word(daz_w) + 7) >> 3);
#endif
}

// XX: assumes little-endian
Expand Down
Loading

0 comments on commit dc43203

Please sign in to comment.