-
Notifications
You must be signed in to change notification settings - Fork 38
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
jets: refactors and optimizes tree-math jets (#397)
Building on urbit/urbit#6592, this PR adds jets for `+pin` and `+hub`. Additionally, it fixes some unsafe `c3_w` -> `u3_atom` conversions and optimizes `+peg` and `+mas`. This is a draft PR as further testing of these changes is still needed. /cc @eamsden
- Loading branch information
Showing
5 changed files
with
185 additions
and
92 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,45 +1,48 @@ | ||
/// @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 - 1); | ||
|
||
b_w -= 2; | ||
sab_u.buf_w[(b_w >> 5)] |= ((c3_w)1 << (b_w & 31)); | ||
|
||
return u3i_slab_mint(&sab_u); | ||
} | ||
} | ||
} | ||
|
||
u3_noun | ||
u3wc_mas(u3_noun cor) | ||
{ | ||
return u3qc_mas(u3x_atom(u3x_at(u3x_sam, cor))); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters