Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

jets: refactors and optimizes tree-math jets #397

Merged
merged 17 commits into from
Nov 13, 2023
Merged
Show file tree
Hide file tree
Changes from 14 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
39 changes: 14 additions & 25 deletions pkg/noun/jets/c/cap.c
Original file line number Diff line number Diff line change
Expand Up @@ -5,32 +5,21 @@

#include "noun.h"

u3_noun
u3qc_cap(u3_atom a)
{
c3_w met_w = u3r_met(0, a);

u3_noun
u3qc_cap(u3_atom a)
{
c3_w met_w = u3r_met(0, a);

if ( met_w < 2 ) {
return u3m_bail(c3__exit);
}
else if ( (1 == u3r_bit((met_w - 2), a)) ) {
return 3;
} else {
return 2;
}
if ( 2 > met_w ) {
return u3m_bail(c3__exit);
}
u3_noun
u3wc_cap(u3_noun cor)
{
u3_noun a;

if ( (u3_none == (a = u3r_at(u3x_sam, cor))) ||
(c3n == u3ud(a)) )
{
return u3m_bail(c3__exit);
} else {
return u3qc_cap(a);
}
else {
return 2 + u3r_bit((met_w - 2), a);
}
}

u3_noun
u3wc_cap(u3_noun cor)
{
return u3qc_cap(u3x_atom(u3x_at(u3x_sam, cor)));
}
64 changes: 34 additions & 30 deletions pkg/noun/jets/c/mas.c
Original file line number Diff line number Diff line change
@@ -1,45 +1,49 @@
/// @file

#include "jets/q.h"
#include "jets/w.h"

#include "noun.h"

u3_noun
u3qc_mas(u3_atom a)
{
c3_w b_w;

u3_noun
u3qc_mas(u3_atom a)
{
c3_w b_w;
u3_atom c, d, e, f;
if ( c3y == u3a_is_cat(a) ) {
b_w = c3_bits_word(a);

b_w = u3r_met(0, a);
if ( b_w < 2 ) {
if ( 2 > b_w ) {
return u3m_bail(c3__exit);
}
else {
c = u3qc_bex((b_w - 1));
d = u3qc_bex((b_w - 2));
e = u3qa_sub(a, c);
f = u3qc_con(e, d);

u3z(c);
u3z(d);
u3z(e);

return f;
a &= ~((c3_w)1 << (b_w - 1));
a |= ((c3_w)1 << (b_w - 2));
return a;
}
}
u3_noun
u3wc_mas(u3_noun cor)
{
u3_noun a;

if ( (u3_none == (a = u3r_at(u3x_sam, cor))) ||
(c3n == u3ud(a)) )
{
return u3m_bail(c3__exit);
} else {
return u3qc_mas(a);
else {
b_w = u3r_met(0, a);

if ( 64 > b_w ) {
c3_d a_d = u3r_chub(0, a);
a_d &= ~((c3_d)1 << (b_w - 1));
a_d |= ((c3_d)1 << (b_w - 2));
return u3i_chub(a_d);
}
else {
u3i_slab sab_u;
u3i_slab_from(&sab_u, a, 0, --b_w);

sab_u.buf_w[(b_w >> 5)] &= ((c3_w)1 << (b_w & 31)) - 1;
b_w--;
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

NB: slab_from rounds up to word boundaries in the slice specified, so we need to mask off any more significant bits than we want.

sab_u.buf_w[(b_w >> 5)] |= ((c3_w)1 << (b_w & 31));

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This mask and store logic is wrong in the boundary condition. @joemfb is going to put masking logic for sub-word blocksizes in u3i_slab_from()

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks, this was a great catch

return u3i_slab_mint(&sab_u);
}
}
}

u3_noun
u3wc_mas(u3_noun cor)
{
return u3qc_mas(u3x_atom(u3x_at(u3x_sam, cor)));
}
90 changes: 53 additions & 37 deletions pkg/noun/jets/c/peg.c
Original file line number Diff line number Diff line change
@@ -1,50 +1,66 @@
/// @file

#include "jets/q.h"
#include "jets/w.h"

#include "noun.h"

u3_noun
u3qc_peg(u3_atom a, u3_atom b)
{
if ( (0 == a) || (0 == b) ) {
return u3m_bail(c3__exit);
}
else if ( 1 == b ) {
return u3k(a);
}

u3_noun
u3qc_peg(u3_atom a,
u3_atom b)
{
if ( 1 == b ) {
return u3k(a);
}
c3_d a_d, b_d;
c3_w c_w;

u3_atom c, d, e, f, g, h;
if ( (c3y == u3a_is_cat(a)) && (c3y == u3a_is_cat(b)) ) {
c_w = c3_bits_word(b) - 1;
a_d = a;
b_d = b;
}
else {
c3_w d_w = u3r_met(0, a);
c3_d e_d;

c = u3r_met(0, b);
d = u3qa_dec(c);
e = u3qc_lsh(0, d, 1);
f = u3qa_sub(b, e);
g = u3qc_lsh(0, d, a);
h = u3qa_add(f, g);
c_w = u3r_met(0, b) - 1;
e_d = (c3_d)c_w + d_w;

u3z(c);
u3z(d);
u3z(e);
u3z(f);
u3z(g);
if ( 64 <= e_d ) {
u3i_slab sab_u;
u3i_slab_init(&sab_u, 0, e_d);

return h;
}
u3_noun
u3wc_peg(u3_noun cor)
{
u3_noun a, b;

if ( (c3n == u3r_mean(cor, u3x_sam_2, &a, u3x_sam_3, &b, 0)) ||
(0 == a) ||
(0 == b) ||
(c3n == u3ud(b)) ||
(c3n == u3ud(a) && b != 1) )
{
return u3m_bail(c3__exit);
} else {
return u3qc_peg(a, b);
u3r_chop(0, 0, c_w, 0, sab_u.buf_w, b);
u3r_chop(0, 0, d_w, c_w, sab_u.buf_w, a);

return u3i_slab_moot(&sab_u);
}

a_d = u3r_chub(0, a);
b_d = u3r_chub(0, b);
}

b_d &= ((c3_d)1 << c_w) - 1;
a_d <<= c_w;
a_d ^= b_d;

return u3i_chub(a_d);
}

u3_noun
u3wc_peg(u3_noun cor)
{
u3_noun a, b;

if ( (c3n == u3r_mean(cor, u3x_sam_2, &a, u3x_sam_3, &b, 0)) ||
(c3n == u3ud(b)) ||
(c3n == u3ud(a) && b != 1) )
{
return u3m_bail(c3__exit);
}
else {
return u3qc_peg(a, b);
}
}
Loading