add info in pos_print, start perft TT testing
This commit is contained in:
73
src/hash.c
73
src/hash.c
@@ -206,7 +206,7 @@ int tt_create(s32 sizemb)
|
||||
hash_tt.nbits = nbits;
|
||||
|
||||
hash_tt.nbuckets = BIT(hash_tt.nbits);
|
||||
hash_tt.nkeys = hash_tt.nbuckets * NBUCKETS;
|
||||
hash_tt.nkeys = hash_tt.nbuckets * ENTRIES_PER_BUCKET;
|
||||
|
||||
hash_tt.bytes = hash_tt.nbuckets * sizeof(bucket_t);
|
||||
hash_tt.mb = hash_tt.bytes / 1024 / 1024;
|
||||
@@ -238,9 +238,10 @@ void tt_clear()
|
||||
if (hash_tt.keys)
|
||||
memset(hash_tt.keys, 0, hash_tt.bytes);
|
||||
|
||||
hash_tt.used_buckets = 0;
|
||||
hash_tt.used_keys = 0;
|
||||
hash_tt.collisions = 0;
|
||||
hash_tt.hits = 0;
|
||||
hash_tt.misses = 0;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -270,12 +271,12 @@ hentry_t *tt_probe(hkey_t key)
|
||||
bucket = hash_tt.keys + (key & hash_tt.mask);
|
||||
|
||||
/* find key in buckets */
|
||||
for (i = 0; i < NBUCKETS; ++i) {
|
||||
for (i = 0; i < ENTRIES_PER_BUCKET; ++i) {
|
||||
entry = bucket->entry + i;
|
||||
if (key == entry->key)
|
||||
break;
|
||||
}
|
||||
if (i < NBUCKETS)
|
||||
if (i < ENTRIES_PER_BUCKET)
|
||||
return entry;
|
||||
return NULL;
|
||||
}
|
||||
@@ -299,18 +300,18 @@ hentry_t *tt_probe_perft(const hkey_t key, const u16 depth)
|
||||
bucket = hash_tt.keys + (key & hash_tt.mask);
|
||||
|
||||
/* find key in buckets */
|
||||
for (i = 0; i < NBUCKETS; ++i) {
|
||||
for (i = 0; i < ENTRIES_PER_BUCKET; ++i) {
|
||||
entry = bucket->entry + i;
|
||||
if (key == entry->key && HASH_PERFT_DEPTH(entry->data) == depth) {
|
||||
printf("tt hit: key=%lx bucket=%lu entry=%d!\n",
|
||||
key, bucket - hash_tt.keys, i);
|
||||
break;
|
||||
hash_tt.hits++;
|
||||
//printf("tt hit: key=%lx bucket=%lu entry=%d!\n",
|
||||
// key, bucket - hash_tt.keys, i);
|
||||
return entry;
|
||||
}
|
||||
}
|
||||
if (i < NBUCKETS)
|
||||
return entry;
|
||||
printf("tt miss: key=%lx bucket=%lu\n",
|
||||
key, bucket - hash_tt.keys);
|
||||
//printf("tt miss: key=%lx bucket=%lu\n",
|
||||
// key, bucket - hash_tt.keys);
|
||||
hash_tt.misses++;
|
||||
return TT_MISS;
|
||||
}
|
||||
|
||||
@@ -325,24 +326,36 @@ hentry_t *tt_store_perft(const hkey_t key, const u16 depth, const u64 nodes)
|
||||
{
|
||||
bucket_t *bucket;
|
||||
hentry_t *entry;
|
||||
int replace = -1, i;
|
||||
// uint mindepth = 0;
|
||||
int replace = -1, newkey = 0;
|
||||
uint mindepth = 1024;
|
||||
u64 data = HASH_PERFT(depth, nodes);
|
||||
printf("tt_store: key=%lx data=%lx depth=%d=%d nodes=%lu=%lu\n",
|
||||
key, data, depth, HASH_PERFT_DEPTH(data), nodes, HASH_PERFT_VAL(data));
|
||||
|
||||
//printf("tt_store: key=%lx data=%lx depth=%d=%d nodes=%lu=%lu\n",
|
||||
// key, data, depth, HASH_PERFT_DEPTH(data), nodes, HASH_PERFT_VAL(data));
|
||||
printf("tt_store: key=%lx depth=%d nodes=%lu ",
|
||||
key, depth, nodes);
|
||||
bug_on(!hash_tt.keys);
|
||||
bucket = hash_tt.keys + (key & hash_tt.mask);
|
||||
|
||||
/* find key in buckets */
|
||||
for (i = 0; i < NBUCKETS; ++i) {
|
||||
for (int i = 0; i < ENTRIES_PER_BUCKET; ++i) {
|
||||
entry = bucket->entry + i;
|
||||
if (key == entry->key && HASH_PERFT_DEPTH(entry->data)) {
|
||||
printf("tt_store: sup key/depth, this should not happen!\n");
|
||||
return NULL;
|
||||
}
|
||||
if (!entry->key) {
|
||||
replace = i;
|
||||
break;
|
||||
}
|
||||
/* we replace hash if we are higher in tree */
|
||||
if (HASH_PERFT_DEPTH(entry->data) < mindepth) {
|
||||
mindepth = HASH_PERFT_DEPTH(entry->data);
|
||||
replace = i;
|
||||
}
|
||||
/*
|
||||
* else {
|
||||
* /\* we replace hash if we are higher in tree *\/
|
||||
*
|
||||
* if (key == entry->key && HASH_PERFT_DEPTH(entry->data) > mindepth) {
|
||||
* mindepth = HASH_PERFT_DEPTH(entry->data);
|
||||
* replace = i;
|
||||
@@ -351,12 +364,32 @@ hentry_t *tt_store_perft(const hkey_t key, const u16 depth, const u64 nodes)
|
||||
*/
|
||||
}
|
||||
if (replace >= 0) {
|
||||
printf("replacing key=%lx=%lx bucket=%lu idx=%d val=%lu\n",
|
||||
key, entry->key, bucket - hash_tt.keys, replace, nodes);
|
||||
entry = bucket->entry + replace;
|
||||
if (HASH_PERFT_VAL(entry->data)) {
|
||||
printf("REPL entry=%lu[%d] key=%lx->%lx val=%lu->%lu\n",
|
||||
bucket - hash_tt.keys, replace,
|
||||
entry->key, key,
|
||||
HASH_PERFT_VAL(entry->data), nodes);
|
||||
} else {
|
||||
printf("NEW entry=%lu[%d] key=%lx val=%lu\n",
|
||||
bucket - hash_tt.keys, replace,
|
||||
entry->key, nodes);
|
||||
}
|
||||
entry->key = key;
|
||||
entry->data = data;
|
||||
return entry;
|
||||
} else {
|
||||
printf("TT full, skip\n");
|
||||
}
|
||||
return NULL;
|
||||
}
|
||||
|
||||
void tt_stats()
|
||||
{
|
||||
printf("TT: sz=%u bits=%u bcks=%'lu entries=%'lu mask=%10x"
|
||||
"used=%lu hits/miss=%'lu/%'lu\n",
|
||||
hash_tt.mb, hash_tt.nbits, hash_tt.nbuckets, hash_tt.nkeys, hash_tt.mask,
|
||||
hash_tt.used_keys, hash_tt.hits, hash_tt.misses);
|
||||
//printf("\tused=%lu hits/miss=%lu/%lu\n",
|
||||
// hash_tt.used_keys, hash_tt.hits, hash_tt.misses);
|
||||
}
|
||||
|
Reference in New Issue
Block a user