From d603e9f310b95bc06afd9b5f6805b722fb133027 Mon Sep 17 00:00:00 2001 From: "C. Guy Yarvin" Date: Tue, 6 Jan 2015 17:27:02 -0800 Subject: [PATCH 1/4] Various fixes and improvements. --- Makefile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Makefile b/Makefile index c525a4ba3e..ac58e1cabf 100644 --- a/Makefile +++ b/Makefile @@ -64,7 +64,7 @@ INCLUDE=i MDEFINES=-DU3_OS_$(OS) -DU3_OS_ENDIAN_$(ENDIAN) -D U3_LIB=\"$(LIB)\" # NOTFORCHECKIN - restore -O3 -CFLAGS= $(COSFLAGS) -O3 -msse3 -ffast-math \ +CFLAGS= $(COSFLAGS) -g -O3 -msse3 -ffast-math \ -funsigned-char \ -I/usr/local/include \ -I/opt/local/include \ From 7a61f3aaa8e0b325df17c035c26a97c019d5d4ef Mon Sep 17 00:00:00 2001 From: "C. Guy Yarvin" Date: Wed, 7 Jan 2015 13:26:05 -0800 Subject: [PATCH 2/4] About to do some performance testing. --- v/temp.c | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/v/temp.c b/v/temp.c index 6d8a3e31c2..3a7d19125b 100644 --- a/v/temp.c +++ b/v/temp.c @@ -72,6 +72,10 @@ u3_temp_io_poll(void) { c3_d gap_d = u3_time_gap_ms(u3k(u3A->now), u3k(u3t(wen))); +#if 0 + fprintf(stderr, "gap_d %llu, plus %llu\r\n", + gap_d, gap_d + (c3_d)teh_u->run_w); +#endif gap_d += teh_u->run_w; if ( c3y == teh_u->alm ) { From b2dc513d6ad63f7c85eb8a1bf2cbda9502f6fcb9 Mon Sep 17 00:00:00 2001 From: "C. Guy Yarvin" Date: Mon, 12 Jan 2015 17:49:31 -0800 Subject: [PATCH 3/4] Add cache to ++song, etc. --- Makefile | 2 +- n/j.c | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/Makefile b/Makefile index ac58e1cabf..c525a4ba3e 100644 --- a/Makefile +++ b/Makefile @@ -64,7 +64,7 @@ INCLUDE=i MDEFINES=-DU3_OS_$(OS) -DU3_OS_ENDIAN_$(ENDIAN) -D U3_LIB=\"$(LIB)\" # NOTFORCHECKIN - restore -O3 -CFLAGS= $(COSFLAGS) -g -O3 -msse3 -ffast-math \ +CFLAGS= $(COSFLAGS) -O3 -msse3 -ffast-math \ -funsigned-char \ -I/usr/local/include \ -I/opt/local/include \ diff --git a/n/j.c b/n/j.c index 2056b872af..470d20f8f4 100644 --- a/n/j.c +++ b/n/j.c @@ -305,8 +305,7 @@ _cj_hot_mean(c3_l par_l, u3_noun mop, u3_noun bat) return 0; } - -/* _cj_hot_mine(): in hoting state, declare a core. RETAINS. +/* _cj_hot_mine(): in hot state, declare a core. RETAINS. */ static c3_l _cj_hot_mine(u3_noun mop, u3_noun cor) @@ -909,6 +908,7 @@ _cj_warm_reap(u3_noun kev) if ( !_(u3a_is_junior(u3R, bat)) && (u3_none != u3h_git(u3R->jed.har_p, bat)) ) { fprintf(stderr, "reap: promote collision (bat %x)\r\n", u3r_mug(bat)); + u3m_p("collision", u3h(u3t(u3t(u3h(cax))))); } else { u3_noun tab = u3a_take(bat); From 8a4ab744ebe95dc10a88fb4f3b732f783be91ac5 Mon Sep 17 00:00:00 2001 From: "C. Guy Yarvin" Date: Thu, 15 Jan 2015 11:10:29 -0800 Subject: [PATCH 4/4] Memory and other optimizations. --- i/n/a.h | 8 +++++- i/n/t.h | 4 ++- j/e/mink.c | 6 ++++- n/a.c | 73 ++++++++++++++++++++++++++++++++++-------------------- n/e.c | 6 +++-- n/i.c | 3 ++- n/m.c | 39 ++++++++++++++--------------- n/r.c | 8 +++++- n/t.c | 8 ++++++ v/loop.c | 5 +++- 10 files changed, 105 insertions(+), 55 deletions(-) diff --git a/i/n/a.h b/i/n/a.h index 9a42bdcc48..541e24e5fe 100644 --- a/i/n/a.h +++ b/i/n/a.h @@ -41,7 +41,7 @@ /* u3a_fbox_no: number of free lists per size. */ -# define u3a_fbox_no 28 +# define u3a_fbox_no 27 /** Structures. @@ -125,6 +125,7 @@ struct { // allocation pools u3p(u3a_fbox) fre_p[u3a_fbox_no]; // heap by node size log + u3p(u3a_fbox) cel_p; // custom cell allocator c3_w fre_w; // number of free words } all; @@ -276,6 +277,11 @@ void* u3a_walloc(c3_w len_w); + /* u3a_celloc(): allocate a cell. Faster, sometimes. + */ + c3_w* + u3a_celloc(void); + /* u3a_wfree(): free storage. */ void diff --git a/i/n/t.h b/i/n/t.h index 2fa0f00620..e629639c80 100644 --- a/i/n/t.h +++ b/i/n/t.h @@ -16,7 +16,9 @@ c3_o noc_o; // now executing in nock interpreter c3_o glu_o; // now executing in jet glue c3_o mal_o; // now executing in allocator - c3_o far_o; // now executing in fragmentor. + c3_o far_o; // now executing in fragmentor + c3_o coy_o; // now executing in copy + c3_o euq_o; // now executing in equal } u3t_trace; /** Macros. diff --git a/j/e/mink.c b/j/e/mink.c index 1b30c2d3a0..2d30d1e3ad 100644 --- a/j/e/mink.c +++ b/j/e/mink.c @@ -18,6 +18,10 @@ return u3m_bail(c3__exit); } else { - return u3n_nock_in(u3k(fly), u3k(bus), u3k(fol)); + u3_noun som; + + som = u3n_nock_in(u3k(fly), u3k(bus), u3k(fol)); + + return som; } } diff --git a/n/a.c b/n/a.c index 0848e1767b..68a102b0b3 100644 --- a/n/a.c +++ b/n/a.c @@ -529,28 +529,6 @@ u3a_calloc(size_t num_i, size_t len_i) return out_w; } -#if 0 -/* u3a_malloc(): allocate storage measured in bytes. -*/ -void* -u3a_malloc(size_t len_i) -{ - c3_w len_w = (c3_w)len_i; - - return u3a_walloc((len_w + 3) >> 2); -} - -/* u3a_realloc(): realloc in bytes. -*/ -void* -u3a_realloc(void* lag_v, size_t len_i) -{ - c3_w len_w = (c3_w)len_i; - - return u3a_wealloc(lag_v, (len_w + 3) >> 2); -} - -#else /* u3a_malloc(): aligned storage measured in bytes. */ void* @@ -576,6 +554,43 @@ u3a_malloc(size_t len_i) return out_w; } +/* u3a_celloc(): allocate a cell. +*/ +c3_w* +u3a_celloc(void) +{ + u3p(u3a_fbox) cel_p; + + if ( (u3R == &(u3H->rod_u)) || !(cel_p = u3R->all.cel_p) ) { + return u3a_walloc(c3_wiseof(u3a_cell)); + } + else { + u3a_box* box_u = &(u3to(u3a_fbox, cel_p)->box_u); + + box_u->use_w = 1; + u3R->all.cel_p = u3to(u3a_fbox, cel_p)->nex_p; + + return u3a_boxto(box_u); + } +} + +/* u3a_cfree(): free a cell. +*/ +void +u3a_cfree(c3_w* cel_w) +{ + if ( u3R == &(u3H->rod_u) ) { + return u3a_wfree(cel_w); + } + else { + u3a_box* box_u = u3a_botox(cel_w); + u3p(u3a_fbox) fre_p = u3of(u3a_fbox, box_u); + + u3to(u3a_fbox, fre_p)->nex_p = u3R->all.cel_p; + u3R->all.cel_p = fre_p; + } +} + /* u3a_realloc(): aligned realloc in bytes. */ void* @@ -639,7 +654,6 @@ u3a_free2(void* tox_v, size_t siz_i) { return u3a_free(tox_v); } -#endif #if 1 /* _me_wash_north(): clean up mug slots after copy. @@ -1045,9 +1059,14 @@ u3a_take(u3_noun som) return som; } else { - return _(u3a_is_north(u3R)) + u3t_on(coy_o); + + som = _(u3a_is_north(u3R)) ? _me_take_north(som) : _me_take_south(som); + + u3t_off(coy_o); + return som; } } @@ -1138,7 +1157,7 @@ top: if ( !_(u3a_is_cat(h_dog)) ) { _me_lose_north(h_dog); } - u3a_wfree(dog_w); + u3a_cfree(dog_w); if ( !_(u3a_is_cat(t_dog)) ) { dog = t_dog; goto top; @@ -1178,7 +1197,7 @@ top: if ( !_(u3a_is_cat(h_dog)) ) { _me_lose_south(h_dog); } - u3a_wfree(dog_w); + u3a_cfree(dog_w); if ( !_(u3a_is_cat(t_dog)) ) { dog = t_dog; goto top; @@ -1512,7 +1531,7 @@ u3a_sweep(void) c3_w* u3a_slab(c3_w len_w) { - c3_w* nov_w = u3a_walloc(len_w + c3_wiseof(u3a_atom)); + c3_w* nov_w = u3a_walloc(len_w + c3_wiseof(u3a_atom)); u3a_atom* pug_u = (void *)nov_w; pug_u->mug_w = 0; diff --git a/n/e.c b/n/e.c index 25022767c3..4d165ce843 100644 --- a/n/e.c +++ b/n/e.c @@ -820,10 +820,12 @@ u3e_live(c3_o nuu_o, c3_c* dir_c) u3P.nor_u.nam_c = "north"; u3P.sou_u.nam_c = "south"; +#if 0 if ( u3C.wag_w & u3o_dryrun ) { return c3y; - } - else { + } else +#endif + { /* Open and apply any patches. */ if ( _(nuu_o) ) { diff --git a/n/i.c b/n/i.c index 3c96ec00df..cfc010e03e 100644 --- a/n/i.c +++ b/n/i.c @@ -208,7 +208,8 @@ u3i_cell(u3_noun a, u3_noun b) c3_assert(!_(u3a_is_junior(u3R, b))); { - c3_w* nov_w = u3a_walloc(c3_wiseof(u3a_cell)); + // c3_w* nov_w = u3a_walloc(c3_wiseof(u3a_cell)); + c3_w* nov_w = u3a_celloc(); u3a_cell* nov_u = (void *)nov_w; u3_noun pro; diff --git a/n/m.c b/n/m.c index b17a4b2660..08a09326ca 100644 --- a/n/m.c +++ b/n/m.c @@ -18,7 +18,7 @@ c3_o u3m_trap(void); #else -# define u3m_trap() (u3_noun)(setjmp(u3R->esc.buf)) +# define u3m_trap() (u3_noun)(_setjmp(u3R->esc.buf)) #endif /* u3m_signal(): treat a nock-level exception as a signal interrupt. @@ -725,18 +725,19 @@ u3m_hate(c3_w pad_w) u3_noun u3m_love(u3_noun pro) { - u3_noun das = u3R->jed.das; - u3p(u3h_root) har_p = u3R->jed.har_p; + { + u3_noun das = u3R->jed.das; + u3p(u3h_root) har_p = u3R->jed.har_p; - u3m_fall(); + u3m_fall(); - pro = u3a_take(pro); + pro = u3a_take(pro); - u3j_reap(das, har_p); - - u3R->cap_p = u3R->ear_p; - u3R->ear_p = 0; + u3j_reap(das, har_p); + u3R->cap_p = u3R->ear_p; + u3R->ear_p = 0; + } return pro; } @@ -822,7 +823,7 @@ u3m_soft_top(c3_w sec_w, // timer seconds /* Trap for ordinary nock exceptions. */ - if ( 0 == (why = (u3_noun)setjmp(u3R->esc.buf)) ) { + if ( 0 == (why = (u3_noun)_setjmp(u3R->esc.buf)) ) { pro = fun_f(arg); /* Make sure the inner routine did not create garbage. @@ -894,11 +895,11 @@ u3m_soft_nock(u3_noun bus, u3_noun fol) */ u3_noun u3m_soft_run(u3_noun fly, - u3_funq fun_f, - u3_noun aga, - u3_noun agb) + u3_funq fun_f, + u3_noun aga, + u3_noun agb) { - u3_noun why, pro; + u3_noun why = 0, pro; /* Record the cap, and leap. */ @@ -911,16 +912,14 @@ u3m_soft_run(u3_noun fly, u3R->pro.don = u3R->par_u->pro.don; u3R->bug.tax = 0; } + u3t_on(coy_o); /* Trap for exceptions. */ - if ( 0 == (why = (u3_noun)setjmp(u3R->esc.buf)) ) { + if ( 0 == (why = (u3_noun)_setjmp(u3R->esc.buf)) ) { + u3t_off(coy_o); pro = fun_f(aga, agb); - if ( u3C.wag_w & u3o_debug_ram ) { - u3m_grab(pro, u3_none); - } - /* Produce success, on the old road. */ pro = u3nc(0, u3m_love(pro)); @@ -1004,7 +1003,7 @@ u3m_soft_esc(u3_noun sam) /* Trap for exceptions. */ - if ( 0 == (why = (u3_noun)setjmp(u3R->esc.buf)) ) { + if ( 0 == (why = (u3_noun)_setjmp(u3R->esc.buf)) ) { pro = u3n_slam_on(fly, sam); /* Fall back to the old road, leaving temporary memory intact. diff --git a/n/r.c b/n/r.c index c0e46d71f3..5c7f1dff84 100644 --- a/n/r.c +++ b/n/r.c @@ -711,7 +711,13 @@ c3_o u3r_sing(u3_noun a, u3_noun b) { - return _sing_x(a, b); + c3_o ret_o; + + u3t_on(euq_o); + ret_o = _sing_x(a, b); + u3t_off(euq_o); + + return ret_o; } /* u3r_sung(): yes iff (a) and (b) are the same noun, unifying equals. diff --git a/n/t.c b/n/t.c index f111510d31..a2e8dc3a9f 100644 --- a/n/t.c +++ b/n/t.c @@ -196,6 +196,12 @@ u3t_samp(void) if ( _(u3T.mal_o) ) { mot_l = c3_s3('m','a','l'); } + else if ( _(u3T.coy_o) ) { + mot_l = c3_s3('c','o','y'); + } + else if ( _(u3T.euq_o) ) { + mot_l = c3_s3('e','u','q'); + } else if ( _(u3T.far_o) ) { mot_l = c3_s3('f','a','r'); } @@ -285,6 +291,8 @@ u3t_init(void) u3T.glu_o = c3n; u3T.mal_o = c3n; u3T.far_o = c3n; + u3T.coy_o = c3n; + u3T.euq_o = c3n; } /* u3t_boot(): turn sampling on. diff --git a/v/loop.c b/v/loop.c index 9f3e477e88..f0c5326cb6 100644 --- a/v/loop.c +++ b/v/loop.c @@ -646,6 +646,7 @@ u3_lo_loop() u3_raft_init(); +#if 1 if ( _(u3_Host.ops_u.dry) ) { u3t_boff(); u3t_damp(); @@ -654,7 +655,9 @@ u3_lo_loop() fprintf(stderr, "dry run: exit\r\n"); exit(0); } - else { + else +#endif + { if ( c3n == u3_Host.ops_u.bat ) { uv_run(u3L, UV_RUN_DEFAULT); }