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

vere64 #715

Draft
wants to merge 9 commits into
base: develop
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all 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
3 changes: 3 additions & 0 deletions .bazelrc
Original file line number Diff line number Diff line change
Expand Up @@ -47,5 +47,8 @@ build:mem_dbg --per_file_copt='pkg/.*@-DU3_MEMORY_DEBUG'
build:cpu_dbg --per_file_copt='pkg/.*@-DU3_CPU_DEBUG'
build:snp_dbg --per_file_copt='pkg/.*@-DU3_SNAPSHOT_VALIDATION'

# Enable 64-bit mode for Vere by default.
build --copt='-DVERE_64'

# Any personal configuration should go in .user.bazelrc.
try-import %workspace%/.user.bazelrc
12 changes: 6 additions & 6 deletions bazel/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,12 @@ refresh_compile_commands(

# Specify the targets of interest.
# For example, specify a dict of targets and any flags required to build.
targets = [
"//pkg/ent",
"//pkg/noun",
"//pkg/ur",
"//pkg/vere:urbit",
],
targets = {
"//pkg/ent": "--copt=-DVERE_64",
"//pkg/noun": "--copt=-DVERE_64",
"//pkg/ur": "--copt=-DVERE_64",
"//pkg/vere:urbit": "--copt=-DVERE_64",
},
# No need to add flags already in .bazelrc. They're automatically picked up.
# If you don't need flags, a list of targets is also okay, as is a single target string.
# Wildcard patterns, like //... for everything, *are* allowed here, just like a build.
Expand Down
17 changes: 17 additions & 0 deletions pkg/c3/defs.h
Original file line number Diff line number Diff line change
Expand Up @@ -47,11 +47,20 @@

/* Size in words.
*/
#ifdef VERE_64
# define c3_wiseof(x) (((sizeof (x)) + 7) >> 3)
#else
# define c3_wiseof(x) (((sizeof (x)) + 3) >> 2)
#endif


/* Bit counting.
*/
#ifdef VERE_64
# define c3_bits_word(w) ((w) ? (64 - __builtin_clzl(w)) : 0)
#else
# define c3_bits_word(w) ((w) ? (32 - __builtin_clz(w)) : 0)
#endif

/* Min and max.
*/
Expand Down Expand Up @@ -224,12 +233,20 @@

unless effective type of x is c3_w or c3_d, assumes x is a pointer.
*/
#ifdef VERE_64
#define c3_align(x, al, hilo) \
_Generic((x), \
c3_d : c3_align_d, \
default : c3_align_p) \
(x, al, hilo)
#else
#define c3_align(x, al, hilo) \
_Generic((x), \
c3_w : c3_align_w, \
c3_d : c3_align_d, \
default : c3_align_p) \
(x, al, hilo)
#endif
typedef enum { C3_ALGHI=1, C3_ALGLO=0 } align_dir;
inline c3_w
c3_align_w(c3_w x, c3_w al, align_dir hilo) {
Expand Down
5 changes: 5 additions & 0 deletions pkg/c3/types.h
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,13 @@
typedef ssize_t c3_zs;
typedef uint64_t c3_d;
typedef int64_t c3_ds;
#ifdef VERE_64
typedef uint64_t c3_w;
typedef int64_t c3_ws;
#else
typedef uint32_t c3_w;
typedef int32_t c3_ws;
#endif
typedef uint16_t c3_s;
typedef int16_t c3_ss;
typedef uint8_t c3_y; // byte
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
49 changes: 45 additions & 4 deletions pkg/noun/allocate.h
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,11 @@

/* u3a_walign: references into the loom are guaranteed to be word-aligned to:
*/
#ifdef VERE_64
# define u3a_walign (4 << u3a_vits)
#else
# define u3a_walign (1 << u3a_vits)
#endif

/* u3a_balign: u3a_walign in bytes
*/
Expand All @@ -28,7 +32,12 @@

/* u3a_page: number of bits in word-addressed page. 12 == 16K page
*/
# define u3a_page 12ULL
#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 @@ -63,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 @@ -214,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 @@ -229,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 @@ -389,9 +416,15 @@
*/
# define u3a_outa(p) ((c3_w *)(void *)(p) - u3_Loom)

#ifdef VERE_64
/* 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

/* u3a_to_ptr(): convert noun [som] into generic pointer into loom.
*/
Expand All @@ -407,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
28 changes: 27 additions & 1 deletion 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 @@ -110,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);
}

Expand Down Expand Up @@ -153,12 +158,21 @@ u3i_slab_from(u3i_slab* sab_u, u3_atom a, c3_g met_g, c3_d len_d)
// if necessary, mask off extra most-significant bits
// from most-significant word
//
#ifdef VERE_64
if ( (6 > met_g) && (u3r_met(6, a) >= sab_u->len_w) ) {
#else
if ( (5 > met_g) && (u3r_met(5, a) >= sab_u->len_w) ) {
#endif
// NB: overflow already checked in _ci_slab_size()
//
c3_d bit_d = len_d << met_g;
#ifdef VERE_64
c3_w wor_w = bit_d >> 6;
c3_w bit_w = bit_d & 0x3f;
#else
c3_w wor_w = bit_d >> 5;
c3_w bit_w = bit_d & 0x1f;
#endif

if ( bit_w ) {
sab_u->buf_w[wor_w] &= ((c3_w)1 << bit_w) - 1;
Expand Down Expand Up @@ -333,6 +347,9 @@ u3i_word(c3_w dat_w)
u3_atom
u3i_chub(c3_d dat_d)
{
#ifdef VERE_64
return u3i_word(dat_d);
#else
if ( c3y == u3a_is_cat(dat_d) ) {
return (u3_atom)dat_d;
}
Expand All @@ -344,6 +361,7 @@ u3i_chub(c3_d dat_d)

return u3i_words(2, dat_w);
}
#endif
}

/* u3i_bytes(): Copy [a] bytes from [b] to an LSB first atom.
Expand Down Expand Up @@ -396,10 +414,18 @@ u3i_words(c3_w a_w,
}
else {
u3i_slab sab_u;
#ifdef VERE_64
u3i_slab_bare(&sab_u, 6, a_w);
#else
u3i_slab_bare(&sab_u, 5, a_w);
#endif

u3t_on(mal_o);
#ifdef VERE_64
memcpy(sab_u.buf_w, b_w, (size_t)8 * a_w);
#else
memcpy(sab_u.buf_w, b_w, (size_t)4 * a_w);
#endif
u3t_off(mal_o);

return u3i_slab_moot(&sab_u);
Expand Down
1 change: 1 addition & 0 deletions pkg/noun/jets.c
Original file line number Diff line number Diff line change
Expand Up @@ -816,6 +816,7 @@ u3j_boot(c3_o nuu_o)
u3h_free(u3R->jed.hot_p);
}
u3R->jed.hot_p = u3h_new();
fprintf(stderr, "jets: hot state init done\r\n");

return _cj_install(u3D.ray_u, 1,
(c3_l) (long long) u3D.dev_u[0].par_u,
Expand Down
5 changes: 5 additions & 0 deletions pkg/noun/jets/b/find.c
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,13 @@

#include "noun.h"

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

u3_noun
u3qb_find(u3_noun nedl, u3_noun hstk)
Expand Down
5 changes: 5 additions & 0 deletions pkg/noun/jets/b/lent.c
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,13 @@

#include "noun.h"

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

u3_noun
u3qb_lent(u3_noun a)
Expand Down
10 changes: 10 additions & 0 deletions pkg/noun/jets/c/bex.c
Original file line number Diff line number Diff line change
Expand Up @@ -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) ) {
Expand All @@ -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 ) {
Expand All @@ -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);
}
Expand Down
Loading
Loading