gnugo-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[gnugo-devel] finishing the cache transition


From: Gunnar Farnebäck
Subject: [gnugo-devel] finishing the cache transition
Date: Wed, 19 May 2004 05:42:51 +0200
User-agent: EMH/1.14.1 SEMI/1.14.3 (Ushinoya) FLIM/1.14.2 (Yagi-Nishiguchi) APEL/10.3 Emacs/21.3 (sparc-sun-solaris2.9) MULE/5.0 (SAKAKI)

This patch finishes the cache transition by implementing
TRACE_CACHED_RESULT macros and doing some preparations for removing
the old cache implementation. The actual removal will come in a
separate patch.

- TRACE_CACHED_RESULT* macros implemented for new caching scheme
- old cache implementation commented out

/Gunnar

Index: engine/cache.c
===================================================================
RCS file: /cvsroot/gnugo/gnugo/engine/cache.c,v
retrieving revision 1.40
diff -u -r1.40 cache.c
--- engine/cache.c      12 Apr 2004 15:28:22 -0000      1.40
+++ engine/cache.c      19 May 2004 00:50:44 -0000
@@ -302,6 +302,7 @@
   table->is_clean = 0;
 }
 
+
 static const char *routine_names[] = {
   ROUTINE_NAMES
 };
@@ -319,6 +320,8 @@
 /*                    The old transposition table                   */
 
 
+#if !USE_HASHTABLE_NG
+
 static Hashtable *movehash;
 
 static int hashtable_init(Hashtable *table, int tablesize, int num_nodes,
@@ -897,7 +900,7 @@
   stats.read_result_entered++;
   return result;
 }
-
+#endif
 
 /* Initialize the cache for read results, using at most the given
  * number of bytes of memory. If the memory isn't sufficient to
@@ -944,10 +947,15 @@
 void
 reading_cache_clear()
 {
-  hashtable_clear(movehash);
+#if USE_HASHTABLE_NG
   tt_clear(&ttable);
+#else
+  hashtable_clear(movehash);
+#endif
 }
 
+#if !USE_HASHTABLE_NG
+
 int
 get_read_result_hash_modified(enum routine_id routine,
                              int *str, Hash_data *hashmodifier,
@@ -1099,6 +1107,7 @@
   return 0;
 }
 
+#endif
 
 /* Write reading trace data to an SGF file. Normally called through the
  * macro SGFTRACE in cache.h.
Index: engine/cache.h
===================================================================
RCS file: /cvsroot/gnugo/gnugo/engine/cache.h,v
retrieving revision 1.47
diff -u -r1.47 cache.h
--- engine/cache.h      15 Apr 2004 13:39:38 -0000      1.47
+++ engine/cache.h      19 May 2004 00:50:44 -0000
@@ -111,6 +111,7 @@
               int value1, int value2, int move);
 
 
+#if !USE_HASHTABLE_NG
 /* ================================================================ */
 /*                    The old transposition table                   */
 
@@ -250,7 +251,7 @@
 void read_result_dump(Read_result *result, FILE *outfile);
 void hashtable_dump(Hashtable *table, FILE *outfile);
 void hashnode_dump(Hashnode *node, FILE *outfile);
-
+#endif
 
 /* ================================================================ */
 
@@ -261,6 +262,19 @@
 
 #if TRACE_READ_RESULTS
 
+#if USE_HASHTABLE_NG
+
+#define TRACE_CACHED_RESULT_NG(result, move) \
+      gprintf("%o%s %1m %d %d %1m (cached) ", read_function_name, \
+             q, stackp, result, move); \
+      dump_stack();
+
+#define TRACE_CACHED_RESULT2_NG(result1, result2, move) \
+      gprintf("%o%s %1m %1m %d %d %d %1m (cached) ", read_function_name, \
+             q1, q2, stackp, result1, result2, move); \
+      dump_stack();
+
+#else
 #define TRACE_CACHED_RESULT(rr) \
       gprintf("%o%s %1m %d %d %1m (cached) ", read_function_name, \
              q, stackp, \
@@ -275,6 +289,7 @@
              rr_get_result2(rr), \
              rr_get_move(rr)); \
       dump_stack();
+#endif
 
 #define SETUP_TRACE_INFO(name, str) \
   const char *read_function_name = name; \
@@ -287,8 +302,13 @@
 
 #else
 
+#if USE_HASHTABLE_NG
+#define TRACE_CACHED_RESULT_NG(result, move)
+#define TRACE_CACHED_RESULT2_NG(result1, result2, move)
+#else
 #define TRACE_CACHED_RESULT(rr)
 #define TRACE_CACHED_RESULT2(rr)
+#endif
 
 #define SETUP_TRACE_INFO(name, str) \
   const char *read_function_name = name; \
@@ -335,6 +355,7 @@
                     result1, result2, message)
 
 
+#if !USE_HASHTABLE_NG
 int get_read_result(enum routine_id routine,
                    int *str, Read_result **read_result);
 int get_read_result_hash_modified(enum routine_id routine,
@@ -342,7 +363,7 @@
                                  Read_result **read_result);
 int get_read_result2(enum routine_id routine,
                     int *str1, int *str2, Read_result **read_result);
-
+#endif
 
 /* ================================================================ */
 
@@ -352,12 +373,15 @@
  * store the result in the hash table at the same time.
  */
 
+#if !TRACE_READ_RESULTS
+
+#if USE_HASHTABLE_NG
 #define READ_RETURN0_NG(routine, str, remaining_depth) \
   do { \
     tt_update(&ttable, routine, str, NO_MOVE, \
               remaining_depth, NULL,\
              0, 0, NO_MOVE);\
-   return 0; \
+    return 0; \
   } while (0)
 
 #define READ_RETURN_NG(routine, str, remaining_depth, point, move, value) \
@@ -405,7 +429,7 @@
     return (value1); \
   } while (0)
 
-#if !TRACE_READ_RESULTS
+#else
 
 #define READ_RETURN0(read_result) \
   do { \
@@ -451,8 +475,84 @@
     return (value_a); \
   } while (0)
 
+#endif
+
 #else /* !TRACE_READ_RESULTS */
 
+#if USE_HASHTABLE_NG
+
+#define READ_RETURN0_NG(routine, str, remaining_depth) \
+  do { \
+    tt_update(&ttable, routine, str, NO_MOVE, \
+              remaining_depth, NULL,\
+             0, 0, NO_MOVE);\
+    gprintf("%o%s %1m %d 0 0 ", read_function_name, q, stackp); \
+    dump_stack(); \
+    return 0; \
+  } while (0)
+
+#define READ_RETURN_NG(routine, str, remaining_depth, point, move, value) \
+  do { \
+    tt_update(&ttable, routine, str, NO_MOVE, \
+              remaining_depth, NULL,\
+              value, 0, move);\
+    if ((value) != 0 && (point) != 0) *(point) = (move); \
+    gprintf("%o%s %1m %d %d %1m ", read_function_name, q, stackp, \
+           (value), (move)); \
+    dump_stack(); \
+    return (value); \
+  } while (0)
+
+#define READ_RETURN_SEMEAI_NG(routine, str1, str2, remaining_depth, point, 
move, value1, value2) \
+  do { \
+    tt_update(&ttable, routine, str1, str2, \
+              remaining_depth, NULL, \
+              value1, value2, move); \
+    if ((value1) != 0 && (point) != 0) *(point) = (move); \
+    gprintf("%o%s %1m %1m %d %d %d %1m ", read_function_name, q1, q2, stackp, \
+           (value1), (value2), (move)); \
+    dump_stack(); \
+    return; \
+  } while (0)
+
+#define READ_RETURN_CONN_NG(routine, str1, str2, remaining_depth, point, move, 
value) \
+  do { \
+    tt_update(&ttable, routine, str1, str2, \
+              remaining_depth, NULL,\
+              value, 0, move);\
+    if ((value) != 0 && (point) != 0) *(point) = (move); \
+    gprintf("%o%s %1m %1m %d %d %1m ", read_function_name, q1, q2, stackp, \
+           (value), (move)); \
+    dump_stack(); \
+    return (value); \
+  } while (0)
+
+#define READ_RETURN_HASH_NG(routine, str, remaining_depth, hash, point, move, 
value) \
+  do { \
+    tt_update(&ttable, routine, str, NO_MOVE, \
+              remaining_depth, hash,\
+              value, 0, move);\
+    if ((value) != 0 && (point) != 0) *(point) = (move); \
+    gprintf("%o%s %1m %d %d %1m ", read_function_name, q, stackp, \
+           (value), (move)); \
+    dump_stack(); \
+    return (value); \
+  } while (0)
+
+#define READ_RETURN2_NG(routine, str, remaining_depth, point, move, value1, 
value2) \
+  do { \
+    tt_update(&ttable, routine, str, NO_MOVE, \
+              remaining_depth, NULL,\
+              value1, value2, move);\
+    if ((value1) != 0 && (point) != 0) *(point) = (move); \
+    gprintf("%o%s %1m %d %d %1m ", read_function_name, q, stackp, \
+           (value1), (move)); \
+    dump_stack(); \
+    return (value1); \
+  } while (0)
+
+#else
+
 #define READ_RETURN0(read_result) \
   do { \
     if (read_result) { \
@@ -505,12 +605,13 @@
     if (read_result) { \
       rr_set_result_move2(*(read_result), (value_a), (value_b), (move)); \
     } \
-    gprintf("%o%s %1m %d %d %d ", read_function_name, q, stackp, \
+    gprintf("%o%s %1m %d %d %1m ", read_function_name, q, stackp, \
            (value_a), (move)); \
     dump_stack(); \
     return (value_a); \
   } while (0)
 
+#endif
 
 #endif
 
Index: engine/hash.h
===================================================================
RCS file: /cvsroot/gnugo/gnugo/engine/hash.h,v
retrieving revision 1.26
diff -u -r1.26 hash.h
--- engine/hash.h       15 Apr 2004 13:39:38 -0000      1.26
+++ engine/hash.h       19 May 2004 00:50:45 -0000
@@ -38,7 +38,7 @@
  * Typically this would be a 32 bit integer on a 32 bit platform and a
  * 64 bit integer on a 64 bit platform.
  *
- * Our preliminary assumption is that unsigned long has this
+ * Our current assumption is that unsigned long has this
  * characteristic. Should it turn out to be false for some platform
  * we'll add conditional code to choose some other type.
  *
@@ -67,12 +67,11 @@
  * With 64 bits, there should be less than one such mistake in 10^9 games.
  * Set this to 96 if this is not safe enough for you.
  */
-#define MIN_HASHBITS   64              
+#define MIN_HASHBITS   64
 
 #define NUM_HASHVALUES (1 + (MIN_HASHBITS - 1) / (CHAR_BIT * SIZEOF_HASHVALUE))
 
-/*
- * This struct is maintained by the machinery that updates the board
+/* This struct is maintained by the machinery that updates the board
  * to provide incremental hashing. Examples: trymove(), play_move(), ...
  */
 
@@ -91,7 +90,6 @@
 int  hashdata_compare(Hash_data *hd1, Hash_data *hd2);
 void hashdata_invert_ko(Hash_data *hd, int pos);
 void hashdata_invert_stone(Hash_data *hd, int pos, int color);
-void hashdata_set_tomove(Hash_data *hd, int to_move);
 
 int hashdata_diff_dump(Hash_data *key1, Hash_data *key2);
 
@@ -102,12 +100,6 @@
 /* ---------------------------------------------------------------- */
 
 
-/* Next generation hash implementation.  
- * 
- * FIXME: Once this is the standard, remove all the _ng suffixes
- *        and clean it up.
- */
-
 #if NUM_HASHVALUES == 1
 
 #define hashdata_NULL  {{0}}
@@ -128,17 +120,10 @@
     (hd1).hashval[0] ^= (hd2).hashval[0]; \
    } while (0)
 
-/* FIXME: This is only an approximation. 
- *        The real remainder can be calculated by 
- *            (ax+y)%z = (a%z)(x%z)+(y%z)
- *        but this probably is good enough for the cache.
- */
 #define hashdata_remainder(hd, num) \
   ((hd).hashval[0] % (num))
 
-#endif
-
-#if NUM_HASHVALUES == 2
+#elif NUM_HASHVALUES == 2
 
 #define hashdata_NULL  {{0, 0}}
 #define hashdata_clear(hd) \
@@ -161,18 +146,19 @@
     (hd1).hashval[1] ^= (hd2).hashval[1]; \
    } while (0)
 
-/* FIXME: This is only an approximation. 
- *        The real remainder can be calculated by 
- *            (ax+y)%z = (a%z)(x%z)+(y%z)
- *        but this probably is good enough for the cache.
+/* This is only an approximation. 
+ * The real remainder can be calculated by 
+ *     (ax+y)%z = (a%z)(x%z)+(y%z)
+ * but this is good enough for use in the cache.
  */
 #define hashdata_remainder(hd, num) \
   (((hd).hashval[0] + (hd).hashval[1]) % (num))
 
-#endif
+#else
 
-void hash_ng_init(void);
+#error NUM_HASHVALUES > 2 not implemented yet
 
+#endif
 
 #endif
 
Index: engine/owl.c
===================================================================
RCS file: /cvsroot/gnugo/gnugo/engine/owl.c,v
retrieving revision 1.210
diff -u -r1.210 owl.c
--- engine/owl.c        29 Apr 2004 23:59:21 -0000      1.210
+++ engine/owl.c        19 May 2004 00:50:45 -0000
@@ -587,7 +587,7 @@
       && tt_get(&ttable, SEMEAI, apos, bpos,
                depth - stackp, NULL,
                &value1, &value2, &xpos)) {
-    /* TRACE_CACHED_RESULT2(*read_result);*/
+    TRACE_CACHED_RESULT2_NG(value1, value2, xpos);
     if (value1 != 0)
       *move = xpos;
       
@@ -1790,28 +1790,28 @@
                depth - stackp, NULL, 
                &value1, &value2, &xpos) == 2) {
 
-    /*      TRACE_CACHED_RESULT(*read_result);*/
-      if (value1 != 0) {
-       if (move)
-         *move = xpos;
-      }
-      if (value1 == GAIN) {
-       if (wormid) {
-         if (goal_worms_computed)
-           *wormid = value2;
-         else
-           *wormid = MAX_GOAL_WORMS;
-       }
+    TRACE_CACHED_RESULT_NG(value1, xpos);
+    if (value1 != 0) {
+      if (move)
+       *move = xpos;
+    }
+    if (value1 == GAIN) {
+      if (wormid) {
+       if (goal_worms_computed)
+         *wormid = value2;
+       else
+         *wormid = MAX_GOAL_WORMS;
       }
-
-      if (value1 == WIN)
-       TRACE("%oVariation %d: DEAD (cached)\n", this_variation_number);
-      else
-       TRACE("%oVariation %d: ALIVE (cached)\n", this_variation_number);
-
-      SGFTRACE(xpos, value1, "cached");
-
-      return value1;
+    }
+    
+    if (value1 == WIN)
+      TRACE("%oVariation %d: DEAD (cached)\n", this_variation_number);
+    else
+      TRACE("%oVariation %d: ALIVE (cached)\n", this_variation_number);
+    
+    SGFTRACE(xpos, value1, "cached");
+    
+    return value1;
   }
 
 
@@ -2512,9 +2512,8 @@
       && tt_get(&ttable, OWL_DEFEND, str, NO_MOVE,
                depth - stackp, NULL, 
                &value1, &value2, &xpos) == 2) {
-
-    /* TRACE_CACHED_RESULT(*read_result);*/
-
+    
+    TRACE_CACHED_RESULT_NG(value1, xpos);
     if (value1 != 0) {
       if (move)
        *move = xpos;
@@ -2842,8 +2841,8 @@
     else {
       SGFTRACE(savemove, savecode, "defense effective (ko) - B");
 #if USE_HASHTABLE_NG
-    READ_RETURN_NG(OWL_DEFEND, str, depth - stackp,
-                  move, savemove, savecode);
+      READ_RETURN_NG(OWL_DEFEND, str, depth - stackp,
+                    move, savemove, savecode);
 #else
       READ_RETURN(read_result, move, savemove, savecode);
 #endif
Index: engine/readconnect.c
===================================================================
RCS file: /cvsroot/gnugo/gnugo/engine/readconnect.c,v
retrieving revision 1.78
diff -u -r1.78 readconnect.c
--- engine/readconnect.c        15 May 2004 17:15:24 -0000      1.78
+++ engine/readconnect.c        19 May 2004 00:50:45 -0000
@@ -1980,7 +1980,7 @@
       && tt_get(&ttable, CONNECT, str1, str2,
                depth - stackp, NULL,
                &value, NULL, &xpos) == 2) {
-    /*TRACE_CACHED_RESULT2(*read_result);*/
+    TRACE_CACHED_RESULT2_NG(value, value, xpos);
     if (value != 0)
       if (move)
        *move = xpos;
@@ -2204,7 +2204,7 @@
       && tt_get(&ttable, DISCONNECT, str1, str2,
                depth - stackp, NULL,
                &value, NULL, &xpos) == 2) {
-    /*TRACE_CACHED_RESULT2(*read_result);*/
+    TRACE_CACHED_RESULT2_NG(value, value, xpos);
     if (value != 0)
       if (move)
        *move = xpos;
@@ -2927,6 +2927,7 @@
                depth - stackp, goal_hash,
                &retval, NULL, &xpos) == 2) {
     /* FIXME: Use move for move ordering if tt_get() returned 1 */
+    TRACE_CACHED_RESULT_NG(retval, xpos);
     SGFTRACE(xpos, retval, "cached");
     if (move)
       *move = xpos;
@@ -3090,6 +3091,7 @@
       && (hashflags & HASH_BLOCK_OFF)
       && (tt_get(&ttable, BLOCK_OFF, str, NO_MOVE, 
                  depth - stackp, goal_hash, &retval, NULL, &xpos) == 2)) {
+    TRACE_CACHED_RESULT_NG(retval, xpos);
     SGFTRACE(xpos, retval, "cached");
     if (move)
       *move = xpos;
Index: engine/reading.c
===================================================================
RCS file: /cvsroot/gnugo/gnugo/engine/reading.c,v
retrieving revision 1.140
diff -u -r1.140 reading.c
--- engine/reading.c    12 Apr 2004 15:22:43 -0000      1.140
+++ engine/reading.c    19 May 2004 00:50:46 -0000
@@ -1208,6 +1208,7 @@
     /* Note that if return value is 1 (too small depth), the move will
      * still be used for move ordering.
      */
+    TRACE_CACHED_RESULT_NG(retval, xpos);
     SGFTRACE(xpos, retval, "cached");
     if (move)
       *move = xpos;
@@ -3000,6 +3001,7 @@
       && tt_get(&ttable, ATTACK, str, NO_MOVE, 
                depth - stackp, NULL, 
                &retval, NULL, &xpos) == 2) {
+    TRACE_CACHED_RESULT_NG(retval, xpos);
     SGFTRACE(xpos, retval, "cached");
     if (move)
       *move = xpos;




reply via email to

[Prev in Thread] Current Thread [Next in Thread]