changeset 645:595763d38ee7

*** empty log message ***
author kono
date Sat, 04 Nov 2006 22:38:18 +0900
parents ac1285a0f69f
children 0d7baf338fc2
files mc-switch.c
diffstat 1 files changed, 31 insertions(+), 0 deletions(-) [+]
line wrap: on
line diff
--- a/mc-switch.c	Sat Nov 04 20:23:23 2006 +0900
+++ b/mc-switch.c	Sat Nov 04 22:38:18 2006 +0900
@@ -40,6 +40,24 @@
       merge:   list4(continuous number of chunk,next,delta,case_count);
   index list
       index:   list4(label,next,max,min);
+
+
+
+  A list of value label pair is generated in do_case, in sorted list.
+
+  The list is separated in continous cslists which has a same
+  delta in make_chunk(int cslist).
+
+  merge_chunk(int chunks) tries to findout possible merge of continous
+  cslist. If merge_chunk_p() accepts reasonably densed switch talbe,
+  the cslists are merged.
+
+  switch_index() makes hierachical indexed branches, using switch_leaf().
+  switch_leaf(). switch_leaf() generates table jump if it is suitable.
+  Otherwise it generates multi-stage cascading jump. siwtch_make_index()
+  generates multi-stage index in a recursive way.
+
+
  */
 
 #define chunk_max(chunks) caddr(cadddr(chunks))
@@ -183,6 +201,10 @@
     return merge;
 }
 
+/*
+    Generates series of compare immideate. It is suitable for
+    small amount of jump and random value.
+ */
 static int
 cascade_compare(int count,int cslist)
 {
@@ -205,6 +227,10 @@
     return cslist;
 }
 
+/*
+    Make table jump code, suitable for fixed delta and large size
+    table.
+ */
 static int
 table_jump(int count,int delta,int chunks)
 {
@@ -296,6 +322,7 @@
 	fwddef(cslabel);
 	switch_make_index_leaf(-1,index0,level);
     } else {
+	// too large index, make hihger index
 	while (index0) {
 	    check_djmp();
 	    l = backdef();
@@ -310,6 +337,7 @@
 	    count-=CASE_INDEX_COUNT;
 	    icount++;
 	}
+	// process higher indexes in a recursive way
 	switch_make_index(reverse0(index),icount,cslabel,gmax,level+1);
     }
 }
@@ -356,6 +384,8 @@
         chnkcnt++;
 	count += cadddr(m);
 	if (count > CASE_INDEX_COUNT || (index && !cadr(m))) {
+	    // too large for single stage cascading or
+	    // we already have indexies and this is the last one.
 	    icount++;
 	    min = car(car(chunks));
 	    check_djmp();
@@ -367,6 +397,7 @@
 	}
     }
     if (index) {
+	// yes we have indexes
 	index = reverse0(index);
         // check lower bound
 	// switch_index_jmp(index,dlabel?dlabel:blabel);