From f8cd976b9f404edc907c53f42aab833f93c7ab15 Mon Sep 17 00:00:00 2001 From: Matthew LeVan Date: Thu, 5 Sep 2024 15:50:51 -0400 Subject: [PATCH] retrieve_tests work through `h` --- pkg/noun/imprison.c | 11 ++++------- pkg/noun/jets/c/bex.c | 10 ++++++++++ pkg/noun/jets/c/lsh.c | 4 ++++ pkg/noun/jets/c/mix.c | 5 +++++ pkg/noun/retrieve.c | 38 ++++++++++++++++++++++++++++++++++++++ pkg/noun/retrieve_tests.c | 28 +++++++++++++++++----------- pkg/noun/serial.c | 20 ++++++++++++++++---- 7 files changed, 94 insertions(+), 22 deletions(-) diff --git a/pkg/noun/imprison.c b/pkg/noun/imprison.c index c84ee358a5..1509f58a28 100644 --- a/pkg/noun/imprison.c +++ b/pkg/noun/imprison.c @@ -115,7 +115,7 @@ u3i_slab_init(u3i_slab* sab_u, c3_g met_g, c3_d len_d) u3i_slab_bare(sab_u, met_g, len_d); u3t_on(mal_o); - memset(sab_u->buf_y, 0, (size_t)sab_u->len_w * 4); + memset(sab_u->buf_y, 0, (size_t)sab_u->len_w * sizeof(c3_w)); u3t_off(mal_o); } @@ -227,8 +227,7 @@ u3i_slab_free(u3i_slab* sab_u) } else { c3_w* tav_w = (sab_u->buf_w - c3_wiseof(u3a_atom)); - // XX - // u3_assert( tav_w == (c3_w*)vat_u ); + u3_assert( tav_w == (c3_w*)vat_u ); u3a_wfree(vat_u); } @@ -258,8 +257,7 @@ 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)); - // XX - // u3_assert( tav_w == (c3_w*)vat_u ); + u3_assert( tav_w == (c3_w*)vat_u ); // trim trailing zeros // @@ -297,8 +295,7 @@ 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)); - // XX - // u3_assert( tav_w == (c3_w*)vat_u ); + u3_assert( tav_w == (c3_w*)vat_u ); pro = _ci_atom_mint(vat_u, len_w); } diff --git a/pkg/noun/jets/c/bex.c b/pkg/noun/jets/c/bex.c index f064dc7a79..958c8176ec 100644 --- a/pkg/noun/jets/c/bex.c +++ b/pkg/noun/jets/c/bex.c @@ -12,8 +12,13 @@ u3qc_bex(u3_atom a) c3_d a_d; u3i_slab sab_u; +#ifdef VERE_64 + if ( a < 63 ) { + return 1ULL << a; +#else if ( a < 31 ) { return 1 << a; +#endif } if ( c3y == u3a_is_cat(a) ) { @@ -24,6 +29,7 @@ u3qc_bex(u3_atom a) return u3m_bail(c3__fail); } + // XX // We don't currently support atoms 2GB or larger (fails while // mugging). The extra term of 16 is experimentally determined. if ( a_d >= ((c3_d)1 << (c3_d)34) - 16 ) { @@ -34,7 +40,11 @@ u3qc_bex(u3_atom a) u3i_slab_init(&sab_u, 0, a_d + 1); +#ifdef VERE_64 + sab_u.buf_w[a_d >> 6] = 1 << (a_d & 63); +#else sab_u.buf_w[a_d >> 5] = 1 << (a_d & 31); +#endif return u3i_slab_moot(&sab_u); } diff --git a/pkg/noun/jets/c/lsh.c b/pkg/noun/jets/c/lsh.c index 09a97e6738..032f94413f 100644 --- a/pkg/noun/jets/c/lsh.c +++ b/pkg/noun/jets/c/lsh.c @@ -11,7 +11,11 @@ u3qc_lsh(u3_atom a, u3_atom b, u3_atom c) { +#ifdef VERE_64 + if ( !_(u3a_is_cat(a)) || (a >= 64) ) { +#else if ( !_(u3a_is_cat(a)) || (a >= 32) ) { +#endif return u3m_bail(c3__fail); } else if ( !_(u3a_is_cat(b)) ) { diff --git a/pkg/noun/jets/c/mix.c b/pkg/noun/jets/c/mix.c index b497c3fd3a..bbdd3fae45 100644 --- a/pkg/noun/jets/c/mix.c +++ b/pkg/noun/jets/c/mix.c @@ -11,8 +11,13 @@ u3qc_mix(u3_atom a, u3_atom b) { + #ifdef VERE_64 + c3_w lna_w = u3r_met(6, a); + c3_w lnb_w = u3r_met(6, b); + #else c3_w lna_w = u3r_met(5, a); c3_w lnb_w = u3r_met(5, b); + #endif if ( (lna_w == 0) && (lnb_w == 0) ) { return 0; diff --git a/pkg/noun/retrieve.c b/pkg/noun/retrieve.c index db43faee9f..34d631804d 100644 --- a/pkg/noun/retrieve.c +++ b/pkg/noun/retrieve.c @@ -1414,8 +1414,13 @@ u3r_chop_bits(c3_g bif_g, c3_w* dst_w, const c3_w* src_w) { +#ifdef VERE_64 + c3_y fib_y = 64 - bif_g; + c3_y tib_y = 64 - bit_g; +#else c3_y fib_y = 32 - bif_g; c3_y tib_y = 32 - bit_g; +#endif // we need to chop words // @@ -1433,13 +1438,23 @@ u3r_chop_bits(c3_g bif_g, wid_d -= tib_y; bif_g += tib_y; +#ifdef VERE_64 + src_w += !!(bif_g >> 6); + bif_g &= 63; + fib_y = 64 - bif_g; +#else src_w += !!(bif_g >> 5); bif_g &= 31; fib_y = 32 - bif_g; +#endif } { +#ifdef VERE_64 + size_t i_i, byt_i = wid_d >> 6; +#else size_t i_i, byt_i = wid_d >> 5; +#endif if ( !bif_g ) { for ( i_i = 0; i_i < byt_i; i_i++ ) { @@ -1454,7 +1469,11 @@ u3r_chop_bits(c3_g bif_g, src_w += byt_i; dst_w += byt_i; +#ifdef VERE_64 + wid_d &= 63; +#else wid_d &= 31; +#endif bit_g = 0; } } @@ -1491,11 +1510,19 @@ u3r_chop_words(c3_g met_g, { // operate on words // +#ifdef VERE_64 + if ( met_g >= 6 ) { +#else if ( met_g >= 5 ) { +#endif size_t i_i, wid_i; { +#ifdef VERE_64 + c3_g hut_g = met_g - 6; +#else c3_g hut_g = met_g - 5; +#endif size_t fum_i = (size_t)fum_w << hut_g; size_t tou_i = (size_t)tou_w << hut_g; size_t tot_i; @@ -1533,7 +1560,11 @@ u3r_chop_words(c3_g met_g, c3_g bif_g, bit_g; { +#ifdef VERE_64 + c3_d len_d = (c3_d)len_w << 6; +#else c3_d len_d = (c3_d)len_w << 5; +#endif c3_d fum_d = (c3_d)fum_w << met_g; c3_d tou_d = (c3_d)tou_w << met_g; c3_d tot_d = fum_d + wid_d; @@ -1552,10 +1583,17 @@ u3r_chop_words(c3_g met_g, wid_d -= tot_d - len_d; } +#ifdef VERE_64 + src_w += fum_d >> 6; + dst_w += tou_d >> 6; + bif_g = fum_d & 63; + bit_g = tou_d & 63; +#else src_w += fum_d >> 5; dst_w += tou_d >> 5; bif_g = fum_d & 31; bit_g = tou_d & 31; +#endif } u3r_chop_bits(bif_g, wid_d, bit_g, dst_w, src_w); diff --git a/pkg/noun/retrieve_tests.c b/pkg/noun/retrieve_tests.c index 3651c53c54..cf8814406b 100644 --- a/pkg/noun/retrieve_tests.c +++ b/pkg/noun/retrieve_tests.c @@ -99,7 +99,6 @@ _test_mug(void) } } - fprintf(stderr, "f\r\n"); { u3_noun a = u3i_string("xxxxxxxxxxxxxxxxxxxxxxxxxxxx"); @@ -110,19 +109,19 @@ _test_mug(void) u3z(a); } - fprintf(stderr, "g\r\n"); { u3_noun a = u3qc_bex(32); - if ( 0x7cefb7f != u3r_mug_cell(0, a) ) { - fprintf(stderr, "fail (g)\r\n"); + gud = 0x7cefb7f; + res = u3r_mug_cell(0, a); + if ( gud != res ) { + fprintf(stderr, "fail (g) %x %x\r\n", gud, res); ret_i = 0; } u3z(a); } - fprintf(stderr, "h\r\n"); { u3_noun a = u3ka_dec(u3qc_bex(128)); @@ -134,19 +133,26 @@ _test_mug(void) u3z(a); } - fprintf(stderr, "i\r\n"); { // stick some zero bytes in a string // + u3m_p("(bex 212)", u3qc_bex(212)); + u3m_p("u3i_string", u3i_string("abcdefjhijklmnopqrstuvwxyz")); u3_noun str = u3kc_lsh(3, 1, u3kc_mix(u3qc_bex(212), u3i_string("abcdefjhijklmnopqrstuvwxyz"))); + u3m_p("lsh", str); c3_w byt_w = u3r_met(3, str); +#ifdef VERE_64 + c3_w wor_w = u3r_met(6, str); + c3_w* str_w = c3_malloc(8 * wor_w); +#else c3_w wor_w = u3r_met(5, str); - c3_y* str_y = c3_malloc(byt_w); c3_w* str_w = c3_malloc(4 * wor_w); +#endif + c3_y* str_y = c3_malloc(byt_w); c3_d str_d = 0; u3r_bytes(0, byt_w, str_y, str); @@ -155,8 +161,10 @@ _test_mug(void) str_d |= str_w[0]; str_d |= ((c3_d)str_w[1] << 32ULL); - if ( 0x34d08717 != u3r_mug(str) ) { - fprintf(stderr, "fail (i) (1) \r\n"); + gud = 0x34d08717; + res = u3r_mug(str); + if ( gud != res ) { + fprintf(stderr, "fail (i) (1) %x %x\r\n", gud, res); ret_i = 0; } if ( 0x34d08717 != u3r_mug_bytes(str_y, byt_w) ) { @@ -176,7 +184,6 @@ _test_mug(void) c3_free(str_w); u3z(str); } - fprintf(stderr, "j\r\n"); { c3_w som_w[4] = { 0, 0, 0, 1 }; @@ -194,7 +201,6 @@ _test_mug(void) u3z(som); } - fprintf(stderr, "k\r\n"); { c3_w som_w[4] = { 0, 1, 0, 1 }; diff --git a/pkg/noun/serial.c b/pkg/noun/serial.c index d0ffa595b4..f019aea350 100644 --- a/pkg/noun/serial.c +++ b/pkg/noun/serial.c @@ -118,11 +118,7 @@ _cs_jam_fib_mat(struct _cs_jam_fib* fib_u, u3_noun a) { c3_d dat_d = (c3_d)1 << b_w; src_w[0] = (c3_w)dat_d; -#ifdef VERE_64 - src_w[1] = dat_d >> 64; -#else src_w[1] = dat_d >> 32; -#endif u3r_chop_words(0, 0, b_w + 1, bit_w, buf_w, 2, src_w); bit_w += b_w + 1; @@ -503,7 +499,11 @@ typedef struct _cue_frame_s { static inline ur_cue_res_e _cs_cue_xeno_next(u3a_pile* pil_u, ur_bsr_t* red_u, +#ifdef VERE_64 + ur_dict64_t* dic_u, +#else ur_dict32_t* dic_u, +#endif u3_noun* out) { ur_root_t* rot_u = 0; @@ -539,7 +539,11 @@ _cs_cue_xeno_next(u3a_pile* pil_u, c3_d bak_d = ur_bsr64_any(red_u, len_d); c3_w bak_w; +#ifdef VERE_64 + if ( !ur_dict64_get(rot_u, dic_u, bak_d, &bak_w) ) { +#else if ( !ur_dict32_get(rot_u, dic_u, bak_d, &bak_w) ) { +#endif return ur_cue_back; } @@ -560,7 +564,11 @@ _cs_cue_xeno_next(u3a_pile* pil_u, c3_d byt_d = (len_d + 0x7) >> 3; u3i_slab sab_u; +#ifdef VERE_64 + if ( 0xffffffffffffffffULL < byt_d) { +#else if ( 0xffffffffULL < byt_d) { +#endif return ur_cue_meme; } else { @@ -570,7 +578,11 @@ _cs_cue_xeno_next(u3a_pile* pil_u, } } +#ifdef VERE_64 + ur_dict64_put(rot_u, dic_u, bit_d, *out); +#else ur_dict32_put(rot_u, dic_u, bit_d, *out); +#endif return ur_cue_good; } }