chiark / gitweb /
memoise edge_end2 now performance is good
authorIan Jackson <ian@turbine>
Tue, 7 Oct 2008 23:58:24 +0000 (00:58 +0100)
committerIan Jackson <ian@turbine>
Tue, 7 Oct 2008 23:58:24 +0000 (00:58 +0100)
interpolate.c
mgraph.c
mgraph.h
minimise.c
output.c
primer.c
view.c

index a2d1cafd48de65ad50b943f92afd6495a11de0c7..f162fc040981b12f97864ec8169792db3b64cf3f 100644 (file)
@@ -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();
 
index 46c7533827b1445c2498773106301e2898a94f47..1e9cef0786e16c3fc6cafa464dfa4e67cb1922e8 100644 (file)
--- 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 }};
 
index 2ac57c7f6e7b71e333a9190c4653481a81a4c838..2267fdbda1ffcf59bbf7a9919c651bee46ffa6b0 100644 (file)
--- a/mgraph.h
+++ b/mgraph.h
 #define FOR_VPEDGE(e) \
   for ((e)=0; (e)<V6; (e)++)
 
-int edge_end2(unsigned v1, int e);
-#define EDGE_END2 edge_end2
+extern short edge_end2_memo[][V6];
+#define EDGE_END2(v1,e) edge_end2_memo[v1][e]
 
 /* given    v1,e     s.t.  v2==EDGE_END2(v1,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*/
index 430517f6fd80dfc16a32c43437d4fdaff106a864..60f2d646e08d5495f72829ee8513dfaba3011ffd 100644 (file)
@@ -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();
index 3367e43f941e971b71042383cd3556677160bf91..f64b22cedc1623cc6769c5b5ad57580a0f00bd8c 100644 (file)
--- 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();
index 76939a6356b9911dc59e29913603cf8af5ee671b..b030ac58a5622f3e66639f1cb54b11c17bd83fba 100644 (file)
--- 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 4f052c176cb414a757798c3b3a7704230ab19560..a395c8c513eef6da2e4a861fd03fc95f492aeb5e 100644 (file)
--- 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); }