-
Notifications
You must be signed in to change notification settings - Fork 39
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
Changes from 14 commits
b256c87
af6adb8
9d42e0d
b1d7d26
8fea31e
30279b8
76ce839
0b114c5
2f4c64e
e1adbfb
2d696e3
de74b25
b58e4c7
562bfac
45f30fc
817fac4
c64d626
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
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--; | ||
sab_u.buf_w[(b_w >> 5)] |= ((c3_w)1 << (b_w & 31)); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 There was a problem hiding this comment. Choose a reason for hiding this commentThe 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))); | ||
} |
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); | ||
} | ||
} |
There was a problem hiding this comment.
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.