Subversion Repositories Games.Chess Giants

Rev

Rev 154 | Go to most recent revision | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 154 Rev 169
Line 4... Line 4...
4
  Copyright (C) 2008-2015 Marco Costalba, Joona Kiiski, Tord Romstad
4
  Copyright (C) 2008-2015 Marco Costalba, Joona Kiiski, Tord Romstad
5
  Copyright (C) 2015-2016 Marco Costalba, Joona Kiiski, Gary Linscott, Tord Romstad
5
  Copyright (C) 2015-2018 Marco Costalba, Joona Kiiski, Gary Linscott, Tord Romstad
6
 
6
 
7
  Stockfish is free software: you can redistribute it and/or modify
7
  Stockfish is free software: you can redistribute it and/or modify
8
  it under the terms of the GNU General Public License as published by
8
  it under the terms of the GNU General Public License as published by
9
  the Free Software Foundation, either version 3 of the License, or
9
  the Free Software Foundation, either version 3 of the License, or
10
  (at your option) any later version.
10
  (at your option) any later version.
Line 31... Line 31...
31
/// measured in megabytes. Transposition table consists of a power of 2 number
31
/// measured in megabytes. Transposition table consists of a power of 2 number
32
/// of clusters and each cluster consists of ClusterSize number of TTEntry.
32
/// of clusters and each cluster consists of ClusterSize number of TTEntry.
33
 
33
 
34
void TranspositionTable::resize(size_t mbSize) {
34
void TranspositionTable::resize(size_t mbSize) {
35
 
35
 
36
  size_t newClusterCount = size_t(1) << msb((mbSize * 1024 * 1024) / sizeof(Cluster));
36
  size_t newClusterCount = mbSize * 1024 * 1024 / sizeof(Cluster);
37
 
37
 
38
  if (newClusterCount == clusterCount)
38
  if (newClusterCount == clusterCount)
39
      return;
39
      return;
40
 
40
 
41
  clusterCount = newClusterCount;
41
  clusterCount = newClusterCount;
42
 
42
 
43
  free(mem);
43
  free(mem);
44
  mem = calloc(clusterCount * sizeof(Cluster) + CacheLineSize - 1, 1);
44
  mem = malloc(clusterCount * sizeof(Cluster) + CacheLineSize - 1);
45
 
45
 
46
  if (!mem)
46
  if (!mem)
47
  {
47
  {
48
      std::cerr << "Failed to allocate " << mbSize
48
      std::cerr << "Failed to allocate " << mbSize
49
                << "MB for transposition table." << std::endl;
49
                << "MB for transposition table." << std::endl;
50
      exit(EXIT_FAILURE);
50
      exit(EXIT_FAILURE);
51
  }
51
  }
52
 
52
 
53
  table = (Cluster*)((uintptr_t(mem) + CacheLineSize - 1) & ~(CacheLineSize - 1));
53
  table = (Cluster*)((uintptr_t(mem) + CacheLineSize - 1) & ~(CacheLineSize - 1));
-
 
54
  clear();
54
}
55
}
55
 
56
 
56
 
57
 
57
/// TranspositionTable::clear() overwrites the entire transposition table
58
/// TranspositionTable::clear() overwrites the entire transposition table
58
/// with zeros. It is called whenever the table is resized, or when the
59
/// with zeros. It is called whenever the table is resized, or when the