diff -r -U3 ../Src5.1.7-orig/pangen1.h ./pangen1.h
--- ../Src5.1.7-orig/pangen1.h	2008-09-03 18:09:22.000000000 -0400
+++ ./pangen1.h	2009-03-10 18:53:53.000000000 -0400
@@ -54,6 +54,10 @@
 	"#if defined(FULLSTACK) && defined(BITSTATE)",
 	"	onstack_init();",
 	"#endif",
+	"#ifdef TABLESTACK",
+	"	LL = (uchar *) emalloc((ts_mask + 1) * sizeof(tsptr_t));",
+	"	{ unsigned long i; for (i = 0; i <= ts_mask; i++) TS[i] = BEYONDMAXDEPTH; }",
+	"#endif",
 	"#if defined(CNTRSTACK) && !defined(BFS)",
 	"	LL = (uchar *) emalloc(ONE_L<<(ssize-3));",
 	"#endif",
@@ -87,6 +91,9 @@
 	"		wrap_stats();",
 	"		printf(\"\\n\");",
 	"		memset(SS, 0, ONE_L<<(ssize-3));",
+		"#ifdef TABLESTACK",
+	"		{ unsigned long i; for (i = 0; i <= ts_mask; i++) TS[i] = BEYONDMAXDEPTH; }",
+		"#endif",
 		"#ifdef CNTRSTACK",
 	"		memset(LL, 0, ONE_L<<(ssize-3));",
 		"#endif",
@@ -2114,6 +2121,31 @@
 	"}",
 	"#endif",
 	"",
+	"#ifdef TABLESTACK",
+	"static inline int onstack_now_table() {",
+	"	unsigned long loc = trpt->k2 & ts_mask;",
+	"	loc = TS[loc];",
+	"	for (;;) {",
+	"		if (loc == BEYONDMAXDEPTH) return 0;",
+	/*"if (loc > maxdepth) abort();",*/
+	"		if (trail[loc].k1 == trpt->k1 && trail[loc].k2 == trpt->k2) return 1;",
+	"		loc = trail[loc].ts_next;",
+	"	}",
+	"}",
+	"static inline void onstack_put_table() {",
+	"	tsptr_t stateloc = (tsptr_t) depth;",
+	/*"if (stateloc != trpt - trail) abort();",*/
+	"	unsigned long loc = trpt->k2 & ts_mask;",
+	"	trpt->ts_next = TS[loc];",
+	"	TS[loc] = stateloc;",
+	"}",
+	"static inline void onstack_zap_table() {",
+	"	unsigned long loc = trpt->k2 & ts_mask;",
+	/*"if (TS[loc] != depth) abort();",*/ /* it's FIFO! */
+	"	TS[loc] = trpt->ts_next;",
+	"}",
+	"#endif",
+	"",
 	"void",
 	"new_state(void)",
 	"{	Trans *t;",
@@ -2248,10 +2280,15 @@
 	"		if (!(trpt->tau&8)) /* if no atomic move */",
 	"		{",
 	"#ifdef BITSTATE",
-		"#ifdef CNTRSTACK",	/* -> bitstate, reduced, safety */
+		"#if defined(CNTRSTACK) || defined(TABLESTACK)",
 	"			II = bstore((char *)&now, vsize);",
+			"#ifdef CNTRSTACK",	/* -> bitstate, reduced, safety */
 	"			trpt->j6 = j1; trpt->j7 = j2;",
-	"			JJ = LL[j1] && LL[j2];",
+			"#endif",
+			"#ifdef TABLESTACK",
+	"			trpt->k1 = K1; trpt->k2 = K2;",
+			"#endif",
+	"			JJ = onstack_now();",
 		"#else",
 			"#ifdef FULLSTACK",
 	"			JJ = onstack_now();",		    /* sets j1 */
@@ -2430,7 +2467,7 @@
 	"#endif",
 	"			}",
 
-	"#if defined(FULLSTACK) || defined(CNTRSTACK)",
+	"#if defined(FULLSTACK) || defined(CNTRSTACK) || defined(TABLESTACK)",
 	"			onstack_put();",
 		"#ifdef DEBUG2",
 		"#if defined(FULLSTACK) && !defined(MA)",
@@ -3391,7 +3428,7 @@
 	"		}",
 	"#endif",
 "#ifndef MA",
-	"#if defined(FULLSTACK) || defined(CNTRSTACK)",
+	"#if defined(FULLSTACK) || defined(CNTRSTACK) || defined(TABLESTACK)",
 	"#ifdef VERI",
 	"		if (boq == -1",
 	"		&&  (((trpt->tau&4) && !(trpt->tau&128))",
@@ -3611,14 +3648,17 @@
 	"	printf(\"	  Restarted from checkpoint %%s.xpt\\n\", PanSource);",
 	"  #endif",
 	"#endif",
-	"#ifdef CHECK",
+	/*"#ifdef CHECK",*/
 	"  #ifdef FULLSTACK",
 	"	printf(\"	+ FullStack Matching\\n\");",
 	"  #endif",
+	"  #ifdef TABLESTACK",
+	"	printf(\"	+ TableStack Matching\\n\");",
+	"  #endif",
 	"  #ifdef CNTRSTACK",
 	"	printf(\"	+ CntrStack Matching\\n\");",
 	"  #endif",
-	"#endif",
+	/*"#endif",*/
 	"#ifdef BITSTATE",
 	"	printf(\"\\nBit statespace search for:\\n\");",
 	"#else",
@@ -3732,6 +3772,9 @@
 			"#ifdef CNTRSTACK",
 	"	nr5 = (double) (ONE_L<<(ssize-3));",
 			"#endif",
+			"#ifdef TABLESTACK",
+	"	nr5 = (double) ((ts_mask+1) * sizeof(tsptr_t));",
+			"#endif",
 			"#ifdef FULLSTACK",
 	"	nr5 = (double) (maxdepth*sizeof(struct H_el *));",
 			"#endif",
@@ -4363,6 +4406,14 @@
 	"	}",
 	"#endif",
 	"	omaxdepth = maxdepth;",
+	"#ifdef TABLESTACK",
+	"	if (maxdepth >= BEYONDMAXDEPTH) {",
+	"		fprintf(efd, \"error: maxdepth greater than TABLESTACK max of %%u\\n\", (unsigned) BEYONDMAXDEPTH);",
+	"		pan_exit(1);",
+	"	}",
+	"	ts_mask = 1;",
+	"	while (ts_mask < (maxdepth + (maxdepth >> 1))) ts_mask = (ts_mask << 1) + 1;",
+	"#endif",
 	"#ifdef BITSTATE",
 	"	if (WS == 4 && ssize > 34)",	/* 32-bit word size */
 	"	{	ssize = 34;",
@@ -4541,6 +4592,12 @@
 	"#if defined(MA) && defined(REACH)",
 	"	#warning -DREACH is voided by -DMA",
 	"#endif",
+	"#if defined(FULLSTACK) && defined(TABLESTACK)",
+	"	#error cannot combine -DFULLSTACK and -DTABLESTACK",
+	"#endif",
+	"#if defined(CNTRSTACK) && defined(TABLESTACK)",
+	"	#error cannot combine -DCNTRSTACK and -DTABLESTACK",
+	"#endif",
 	"#if defined(FULLSTACK) && defined(CNTRSTACK)",
 	"	#error cannot combine -DFULLSTACK and -DCNTRSTACK",
 	"#endif",
diff -r -U3 ../Src5.1.7-orig/pangen2.h ./pangen2.h
--- ../Src5.1.7-orig/pangen2.h	2008-04-25 13:51:26.000000000 -0400
+++ ./pangen2.h	2009-03-10 19:22:41.000000000 -0400
@@ -31,6 +31,7 @@
 	"#include <stdio.h>",
 	"#include <signal.h>",
 	"#include <stdlib.h>",
+	"#include <stdint.h>",
 	"#include <stdarg.h>",
 	"#include <string.h>",
 	"#include <ctype.h>",
@@ -57,6 +58,21 @@
 
 static char *Preamble[] = {
 
+	"#ifdef TABLESTACK",
+	"#if TABLESTACK==16",
+	"typedef uint16_t tsptr_t;",
+	"#define BEYONDMAXDEPTH UINT16_MAX", /* for null ptr */
+	"#else",
+	"typedef uint32_t tsptr_t;",
+	"#define BEYONDMAXDEPTH UINT32_MAX", /* for null ptr */
+	"#endif",
+/*	"int onstack_now_table();",
+	"void onstack_put_table();",
+	"void onstack_zap_table();",*/
+	"#define onstack_now() onstack_now_table()",
+	"#define onstack_put() onstack_put_table()",
+	"#define onstack_zap() onstack_zap_table()",
+	"#endif",
 	"#ifdef CNTRSTACK",
 	"#define onstack_now()	(LL[trpt->j6] && LL[trpt->j7])",
 	"#define onstack_put()	 LL[trpt->j6]++; LL[trpt->j7]++",
@@ -191,6 +207,10 @@
 	"#if (defined(FULLSTACK) && !defined(MA)) || defined(BFS) || (NCORE>1)",
 	"	struct H_el *ostate;	/* pointer to stored state */",
 	"#endif",
+	"#ifdef TABLESTACK",
+        "       tsptr_t ts_next;  /* for linked list */",
+        "       unsigned long k1, k2;  /* to store hash value */",
+	"#endif",
 	/* CNTRSTACK when !NOREDUCE && BITSTATE && SAFETY, uses LL[] */
 	"#if defined(CNTRSTACK) && !defined(BFS)",
 	"	long	j6, j7;",
@@ -233,6 +253,10 @@
 	"char	*stackfile;",
  	"#endif",
 	"uchar	*SS, *LL;",
+	"#ifdef TABLESTACK",
+	"#define TS ((tsptr_t *)LL)",
+	"unsigned long ts_mask;",
+	"#endif",
 	"uchar	HASH_NR = 0;",
 	"",
 	"double memcnt = (double) 0;",
diff -r -U3 ../Src5.1.7-orig/pangen3.h ./pangen3.h
--- ../Src5.1.7-orig/pangen3.h	2008-04-18 13:39:48.000000000 -0400
+++ ./pangen3.h	2009-03-10 18:55:44.000000000 -0400
@@ -73,8 +73,14 @@
 		"#endif",
 	"#else",
 		"#ifdef BITSTATE",
-			"#if defined(SAFETY) && !defined(HASH64)",
-				"#define CNTRSTACK",
+			"#ifdef SAFETY",
+				"#if !defined(CNTRSTACK) && !defined(TABLESTACK) && !defined(FULLSTACK)",
+					"#ifdef SC", /* unbounded stack */
+						"#define CNTRSTACK",
+					"#else",
+						"#define TABLESTACK",
+					"#endif",
+				"#endif",
 			"#else",
 				"#define FULLSTACK",
 			"#endif",
@@ -82,6 +88,11 @@
 			"#define FULLSTACK",
 		"#endif",
 	"#endif",
+	"#ifdef TABLESTACK",
+	"#ifdef SC",
+	"#error Cannot combine TABLESTACK and SC",
+	"#endif",
+	"#endif",
 	"#ifdef BITSTATE",
 		"#ifndef NOCOMP",
 		"#define NOCOMP",
