From 853015da8517983ea0105237d969f8a1b67815f4 Mon Sep 17 00:00:00 2001 From: Ian Jackson Date: Wed, 8 Oct 2008 00:58:24 +0100 Subject: [PATCH] memoise edge_end2 now performance is good --- interpolate.c | 2 ++ mgraph.c | 11 ++++++++++- mgraph.h | 6 ++++-- minimise.c | 1 + output.c | 1 + primer.c | 2 ++ view.c | 1 + 7 files changed, 21 insertions(+), 3 deletions(-) diff --git a/interpolate.c b/interpolate.c index a2d1caf..f162fc0 100644 --- a/interpolate.c +++ b/interpolate.c @@ -302,6 +302,8 @@ int main(int argc, const char **argv) { } if (!freopen(argv[2],"rb",stdin)) diee("open input"); + + mgraph_prepare(); characterise_input(); read_input(); diff --git a/mgraph.c b/mgraph.c index 46c7533..1e9cef0 100644 --- a/mgraph.c +++ b/mgraph.c @@ -8,7 +8,7 @@ static const unsigned dx[2][V6]= {{ +1, 0, -1, -1, -1, 0 }, { +1, +1, 0, -1, 0, +1 }}, dy[V6]= { 0, -Y1, -Y1, 0, +Y1, +Y1 }; -int edge_end2(unsigned v1, int e) { +static int edge_end2(unsigned v1, int e) { unsigned x, y; y= (v1 & ~XMASK) + dy[e]; @@ -25,6 +25,15 @@ int edge_end2(unsigned v1, int e) { return x | y; } +short edge_end2_memo[N][V6]; + +void mgraph_prepare(void) { + int v, e; + FOR_VERTEX(v, INNER) + FOR_VPEDGE(e) + edge_end2_memo[v][e]= edge_end2(v,e); +} + static const unsigned reverse[2][V6]= {{ 3, 4, 5, 0, 1, 2 }, { 3, 2, 1, 0, 5, 4 }}; diff --git a/mgraph.h b/mgraph.h index 2ac57c7..2267fdb 100644 --- a/mgraph.h +++ b/mgraph.h @@ -103,8 +103,8 @@ #define FOR_VPEDGE(e) \ for ((e)=0; (e)= 0, * returns eprime s.t. v1==EDGE_END2(v2,eprime) */ @@ -138,4 +138,6 @@ int vertices_span_join_p(int v0, int v1); typedef double Vertices[N][D3]; struct Vertices { Vertices a; }; +void mgraph_prepare(void); + #endif /*MGRAPH_H*/ diff --git a/minimise.c b/minimise.c index 430517f..60f2d64 100644 --- a/minimise.c +++ b/minimise.c @@ -101,6 +101,7 @@ int main(int argc, const char *const *argv) { r= sigaction(SIGINT,&sa,0); if (r) diee("sigaction SIGINT"); + mgraph_prepare(); graph_layout_prepare(); printing_init(); energy_init(); diff --git a/output.c b/output.c index 3367e43..f64b22c 100644 --- a/output.c +++ b/output.c @@ -498,6 +498,7 @@ int main(int argc, const char *const *argv) { errno= 0; r= fread(&in,sizeof(in),1,stdin); if (r!=1) diee("fread"); + mgraph_prepare(); blank_outvertices(); compute_outvertices(); transform_outvertices(); diff --git a/primer.c b/primer.c index 76939a6..b030ac5 100644 --- a/primer.c +++ b/primer.c @@ -13,6 +13,8 @@ int main(int argc, const char **argv) { if (argc!=1) { fputs("need no args\n",stderr); exit(8); } + mgraph_prepare(); + printf("%d %d %d %d %d\n%%-%d.%dg\n", X*Y, N, X, Y, D3, prec+5,prec); diff --git a/view.c b/view.c index 4f052c1..a395c8c 100644 --- a/view.c +++ b/view.c @@ -679,6 +679,7 @@ int main(int argc, const char *const *argv) { struct pollfd *polls=0; int motion_deferred=0, motion_x=-1, motion_y=-1; + mgraph_prepare(); topocheck(); if (argc==1) { printf("topology self-consistent, ok\n"); exit(0); } -- 2.30.2