Ticket #145: cache.h.patch

File cache.h.patch, 4.5 kB (added by draqo, 2 years ago)
  • gnugo/engine/cache.h

    RCS file: /sources/gnugo/gnugo/engine/cache.h,v
    retrieving revision 1.54
    diff -u -r1.54 cache.h
     
    3232 * (Reading/Hashing) for more information.   
    3333 */ 
    3434 
     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 
    3544 
    3645/* Hashnode: a node stored in the transposition table. 
    3746 * 
    3847 * In addition to the position, the hash lock encodes the following data, 
    3948 * all hashed: 
    40  *   komaster 
    41  *   kom_pos 
     49 *   ko 
     50 *   komaster (look in doc) 
     51 *   kom_pos (look in doc) 
    4252 *   routine 
    43  *   str1 
    44  *   str2 
     53 *   target1 
     54 *   target2 
    4555 *   extra hashvalue, optional (e.g. encoding a goal array) 
    4656 * 
    4757 * The data field packs into 32 bits the following 
     
    5464 *   cost           :  4 bits 
    5565 *   remaining_depth:  5 bits (depth - stackp)  NOTE: HN_MAX_REMAINING_DEPTH 
    5666 * 
    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.) 
    5870 */ 
    5971typedef struct { 
    6072  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 */ 
    6274} Hashnode; 
    6375 
    6476#define HN_MAX_REMAINING_DEPTH 31 
     
    6779/* Hashentry: an entry, with two nodes of the hash_table 
    6880 */ 
    6981typedef struct { 
    70   Hashnode deepest; 
     82  Hashnode most_reliable; 
    7183  Hashnode newest; 
    7284} Hashentry; 
    7385 
     
    7688#define hn_get_value2(hn)           ((hn >> 19) & 0x0f) 
    7789#define hn_get_move(hn)             ((hn >>  9) & 0x3ff) 
    7890#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) 
    8193 
    8294#define hn_create_data(remaining_depth, value1, value2, move, cost) \ 
    8395    ((((value1)         & 0x0f)  << 23) \ 
    8496   | (((value2)         & 0x0f)  << 19) \ 
    8597   | (((move)           & 0x3ff) <<  9) \ 
    8698   | (((cost)           & 0x0f)  <<  5) \ 
    87    | (((remaining_depth & 0x1f)  <<  0))) 
     99   | (((remaining_depth & 0x1f)/*<<  0*/))) 
    88100 
    89101 
    90102/* Transposition_table: transposition table used for caching. */ 
    91103typedef struct { 
    92104  unsigned int num_entries; 
    93105  Hashentry *entries; 
    94   int is_clean; 
    95106} Transposition_table; 
    96107 
    97108extern Transposition_table ttable; 
     
    101112 */ 
    102113#define DEFAULT_NUMBER_OF_CACHE_ENTRIES 350000 
    103114 
    104 void tt_free(Transposition_table *table); 
     115inline void tt_free(Transposition_table *table); 
    105116int  tt_get(Transposition_table *table, enum routine_id routine, 
    106117            int target1, int target2, int remaining_depth, 
    107118            Hash_data *extra_hash, 
     
    212223  do { \ 
    213224    tt_update(&ttable, routine, str, NO_MOVE, remaining_depth, NULL,\ 
    214225              value, 0, move);\ 
    215     if ((value) != 0 && (point) != 0) *(point) = (move); \ 
     226    if ((point) != NULL && (value) != 0) \ 
     227          *(point) = (move); \ 
    216228    return (value); \ 
    217229  } while (0) 
    218230 
     
    220232  do { \ 
    221233    tt_update(&ttable, routine, str1, str2, remaining_depth, NULL, \ 
    222234              value1, value2, move); \ 
    223     if ((value1) != 0 && (point) != 0) *(point) = (move); \ 
     235    if ((point) != NULL && (value1) != 0) \ 
     236          *(point) = (move); \ 
    224237    return; \ 
    225238  } while (0) 
    226239 
     
    228241  do { \ 
    229242    tt_update(&ttable, routine, str1, str2, remaining_depth, NULL,\ 
    230243              value, 0, move);\ 
    231     if ((value) != 0 && (point) != 0) *(point) = (move); \ 
     244    if ((point) != NULL && (value) != 0) \ 
     245          *(point) = (move); \ 
    232246    return (value); \ 
    233247  } while (0) 
    234248 
     
    236250  do { \ 
    237251    tt_update(&ttable, routine, str, NO_MOVE, remaining_depth, hash,\ 
    238252              value, 0, move);\ 
    239     if ((value) != 0 && (point) != 0) *(point) = (move); \ 
     253    if ((point) != NULL && (value) != 0) \ 
     254          *(point) = (move); \ 
    240255    return (value); \ 
    241256  } while (0) 
    242257 
     
    244259  do { \ 
    245260    tt_update(&ttable, routine, str, NO_MOVE, remaining_depth, NULL,\ 
    246261              value1, value2, move);\ 
    247     if ((value1) != 0 && (point) != 0) *(point) = (move); \ 
     262    if ((point) != NULL && (value1) != 0) \ 
     263          *(point) = (move); \ 
    248264    return (value1); \ 
    249265  } while (0) 
    250266