Subversion Repositories Games.Chess Giants

Rev

Blame | Last modification | View Log | Download | RSS feed

  1. /*
  2.     Texel - A UCI chess engine.
  3.     Copyright (C) 2012-2014  Peter Ă–sterlund, peterosterlund2@gmail.com
  4.  
  5.     This program is free software: you can redistribute it and/or modify
  6.     it under the terms of the GNU General Public License as published by
  7.     the Free Software Foundation, either version 3 of the License, or
  8.     (at your option) any later version.
  9.  
  10.     This program is distributed in the hope that it will be useful,
  11.     but WITHOUT ANY WARRANTY; without even the implied warranty of
  12.     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  13.     GNU General Public License for more details.
  14.  
  15.     You should have received a copy of the GNU General Public License
  16.     along with this program.  If not, see <http://www.gnu.org/licenses/>.
  17. */
  18.  
  19. /*
  20.  * util.cpp
  21.  *
  22.  *  Created on: Mar 2, 2012
  23.  *      Author: petero
  24.  */
  25.  
  26. #include "util.hpp"
  27.  
  28. static const int firstBitTable[32] = {
  29.     0, 9, 1, 10, 13, 21, 2, 29, 11, 14, 16, 18, 22, 25, 3, 30,
  30.     8, 12, 20, 28, 15, 17, 24, 7, 19, 27, 23, 6, 26, 5, 4, 31
  31. };
  32.  
  33. int floorLog2(U32 x) {
  34.     x |= x >> 1;
  35.     x |= x >> 2;
  36.     x |= x >> 4;
  37.     x |= x >> 8;
  38.     x |= x >> 16;
  39.     return firstBitTable[(x * (U32)0x07c4acdd) >> 27];
  40. }
  41.