RCS file: /sources/gnugo/gnugo/engine/cache.h,v
retrieving revision 1.54
diff -u -r1.54 cache.h
|
|
|
|
| 32 | 32 | * (Reading/Hashing) for more information. |
| 33 | 33 | */ |
| 34 | 34 | |
| | 35 | #if SIZEOF_INT == 4 |
| | 36 | typedef unsigned int HASHNODE_DATATYPE; |
| | 37 | #elif SIZEOF_LONG == 4 |
| | 38 | typedef unsigned long HASHNODE_DATATYPE; |
| | 39 | #elif SIZEOF_INT > 4 |
| | 40 | typedef unsigned short HASHNODE_DATATYPE; |
| | 41 | #elif |
| | 42 | #error Long type size has to be at least 4 bytes. |
| | 43 | #endif |
| 35 | 44 | |
| 36 | 45 | /* Hashnode: a node stored in the transposition table. |
| 37 | 46 | * |
| 38 | 47 | * In addition to the position, the hash lock encodes the following data, |
| 39 | 48 | * all hashed: |
| 40 | | * komaster |
| 41 | | * kom_pos |
| | 49 | * ko |
| | 50 | * komaster (look in doc) |
| | 51 | * kom_pos (look in doc) |
| 42 | 52 | * routine |
| 43 | | * str1 |
| 44 | | * str2 |
| | 53 | * target1 |
| | 54 | * target2 |
| 45 | 55 | * extra hashvalue, optional (e.g. encoding a goal array) |
| 46 | 56 | * |
| 47 | 57 | * The data field packs into 32 bits the following |
| … |
… |
|
| 54 | 64 | * cost : 4 bits |
| 55 | 65 | * remaining_depth: 5 bits (depth - stackp) NOTE: HN_MAX_REMAINING_DEPTH |
| 56 | 66 | * |
| 57 | | * The last 9 bits together give an index for the total costs. |
| | 67 | * The last 9 bits together give a reliability index (bigger index means |
| | 68 | * more reliable result). |
| | 69 | * Values are results of analyzed position (WIN, LOSE, etc.) |
| 58 | 70 | */ |
| 59 | 71 | typedef struct { |
| 60 | 72 | Hash_data key; |
| 61 | | unsigned int data; /* Should be 32 bits, but only wastes 25% if 64 bits. */ |
| | 73 | HASHNODE_DATATYPE data; /* 32-bit value */ |
| 62 | 74 | } Hashnode; |
| 63 | 75 | |
| 64 | 76 | #define HN_MAX_REMAINING_DEPTH 31 |
| … |
… |
|
| 67 | 79 | /* Hashentry: an entry, with two nodes of the hash_table |
| 68 | 80 | */ |
| 69 | 81 | typedef struct { |
| 70 | | Hashnode deepest; |
| | 82 | Hashnode most_reliable; |
| 71 | 83 | Hashnode newest; |
| 72 | 84 | } Hashentry; |
| 73 | 85 | |
| … |
… |
|
| 76 | 88 | #define hn_get_value2(hn) ((hn >> 19) & 0x0f) |
| 77 | 89 | #define hn_get_move(hn) ((hn >> 9) & 0x3ff) |
| 78 | 90 | #define hn_get_cost(hn) ((hn >> 5) & 0x0f) |
| 79 | | #define hn_get_remaining_depth(hn) ((hn >> 0) & 0x1f) |
| 80 | | #define hn_get_total_cost(hn) ((hn >> 0) & 0x1ff) |
| | 91 | #define hn_get_remaining_depth(hn) ((hn/*>> 0*/) & 0x1f) |
| | 92 | #define hn_get_reliability(hn) ((hn/*>> 0*/) & 0x1ff) |
| 81 | 93 | |
| 82 | 94 | #define hn_create_data(remaining_depth, value1, value2, move, cost) \ |
| 83 | 95 | ((((value1) & 0x0f) << 23) \ |
| 84 | 96 | | (((value2) & 0x0f) << 19) \ |
| 85 | 97 | | (((move) & 0x3ff) << 9) \ |
| 86 | 98 | | (((cost) & 0x0f) << 5) \ |
| 87 | | | (((remaining_depth & 0x1f) << 0))) |
| | 99 | | (((remaining_depth & 0x1f)/*<< 0*/))) |
| 88 | 100 | |
| 89 | 101 | |
| 90 | 102 | /* Transposition_table: transposition table used for caching. */ |
| 91 | 103 | typedef struct { |
| 92 | 104 | unsigned int num_entries; |
| 93 | 105 | Hashentry *entries; |
| 94 | | int is_clean; |
| 95 | 106 | } Transposition_table; |
| 96 | 107 | |
| 97 | 108 | extern Transposition_table ttable; |
| … |
… |
|
| 101 | 112 | */ |
| 102 | 113 | #define DEFAULT_NUMBER_OF_CACHE_ENTRIES 350000 |
| 103 | 114 | |
| 104 | | void tt_free(Transposition_table *table); |
| | 115 | inline void tt_free(Transposition_table *table); |
| 105 | 116 | int tt_get(Transposition_table *table, enum routine_id routine, |
| 106 | 117 | int target1, int target2, int remaining_depth, |
| 107 | 118 | Hash_data *extra_hash, |
| … |
… |
|
| 212 | 223 | do { \ |
| 213 | 224 | tt_update(&ttable, routine, str, NO_MOVE, remaining_depth, NULL,\ |
| 214 | 225 | value, 0, move);\ |
| 215 | | if ((value) != 0 && (point) != 0) *(point) = (move); \ |
| | 226 | if ((point) != NULL && (value) != 0) \ |
| | 227 | *(point) = (move); \ |
| 216 | 228 | return (value); \ |
| 217 | 229 | } while (0) |
| 218 | 230 | |
| … |
… |
|
| 220 | 232 | do { \ |
| 221 | 233 | tt_update(&ttable, routine, str1, str2, remaining_depth, NULL, \ |
| 222 | 234 | value1, value2, move); \ |
| 223 | | if ((value1) != 0 && (point) != 0) *(point) = (move); \ |
| | 235 | if ((point) != NULL && (value1) != 0) \ |
| | 236 | *(point) = (move); \ |
| 224 | 237 | return; \ |
| 225 | 238 | } while (0) |
| 226 | 239 | |
| … |
… |
|
| 228 | 241 | do { \ |
| 229 | 242 | tt_update(&ttable, routine, str1, str2, remaining_depth, NULL,\ |
| 230 | 243 | value, 0, move);\ |
| 231 | | if ((value) != 0 && (point) != 0) *(point) = (move); \ |
| | 244 | if ((point) != NULL && (value) != 0) \ |
| | 245 | *(point) = (move); \ |
| 232 | 246 | return (value); \ |
| 233 | 247 | } while (0) |
| 234 | 248 | |
| … |
… |
|
| 236 | 250 | do { \ |
| 237 | 251 | tt_update(&ttable, routine, str, NO_MOVE, remaining_depth, hash,\ |
| 238 | 252 | value, 0, move);\ |
| 239 | | if ((value) != 0 && (point) != 0) *(point) = (move); \ |
| | 253 | if ((point) != NULL && (value) != 0) \ |
| | 254 | *(point) = (move); \ |
| 240 | 255 | return (value); \ |
| 241 | 256 | } while (0) |
| 242 | 257 | |
| … |
… |
|
| 244 | 259 | do { \ |
| 245 | 260 | tt_update(&ttable, routine, str, NO_MOVE, remaining_depth, NULL,\ |
| 246 | 261 | value1, value2, move);\ |
| 247 | | if ((value1) != 0 && (point) != 0) *(point) = (move); \ |
| | 262 | if ((point) != NULL && (value1) != 0) \ |
| | 263 | *(point) = (move); \ |
| 248 | 264 | return (value1); \ |
| 249 | 265 | } while (0) |
| 250 | 266 | |