31 #define DEBUG_INDEX_INITIALIZATION_AND_RANGE_CHECK 0 33 #if DEBUG_INDEX_INITIALIZATION_AND_RANGE_CHECK 192 #if DEBUG_INDEX_INITIALIZATION_AND_RANGE_CHECK 193 uint64_t
const index_initialization_magic = CW_MASK_T_CONST(1515151515151515151);
194 uint64_t
const index_destruction_magic = CW_MASK_T_CONST(6666666666666666666);
212 #if DEBUG_INDEX_INITIALIZATION_AND_RANGE_CHECK 214 uint64_t M_initialized;
218 #if DEBUG_INDEX_INITIALIZATION_AND_RANGE_CHECK 219 Index(
void) : M_initialized(0) { }
220 ~
Index() { M_initialized = index_destruction_magic; }
222 bool is_initialized(
void)
const {
return M_initialized == index_initialization_magic; }
234 #if DEBUG_INDEX_INITIALIZATION_AND_RANGE_CHECK 235 assert(index.is_initialized());
236 M_initialized = index_initialization_magic;
244 #if DEBUG_INDEX_INITIALIZATION_AND_RANGE_CHECK 245 assert(index.
M_bits < 64 || index == index_end || index == index_pre_begin);
246 M_initialized = index_initialization_magic;
254 #if DEBUG_INDEX_INITIALIZATION_AND_RANGE_CHECK 255 assert(col >= 0 && col <= 7 && row >= 0 && row <= 7);
256 M_initialized = index_initialization_magic;
258 M_bits = ((uint8_t)row << 3) | (uint8_t)col;
268 #if DEBUG_INDEX_INITIALIZATION_AND_RANGE_CHECK 269 assert(index.is_initialized());
270 M_initialized = index_initialization_magic;
278 #if DEBUG_INDEX_INITIALIZATION_AND_RANGE_CHECK 279 assert(index.
M_bits < 64 || index == index_end || index == index_pre_begin);
280 M_initialized = index_initialization_magic;
301 friend bool operator<=(
Index const& index1,
Index const& index2) {
return index1.
M_bits <= index2.
M_bits; }
307 friend bool operator>=(
Index const& index1,
Index const& index2) {
return index1.
M_bits >= index2.
M_bits; }
316 Index const& operator+=(
int offset) {
M_bits += offset;
return*
this; }
317 friend Index operator+(
Index const& index,
int offset) {
Index result(index);
return result += offset; }
318 friend Index operator+(
int offset,
Index const& index) {
Index result(index);
return result += offset; }
319 Index const& operator-=(
int offset) {
M_bits -= offset;
return*
this; }
320 friend Index operator-(
Index const& index,
int offset) {
Index result(index);
return result -= offset; }
321 friend Index operator-(
int offset,
Index const& index) {
Index result(index);
return result -= offset; }
323 Index& operator++(
void) { ++
M_bits;
return*
this; }
324 Index operator++(
int) {
Index result(*
this); operator++();
return result; }
325 Index& operator--(
void) { ++
M_bits;
return*
this; }
326 Index operator--(
int) {
Index result(*
this); operator--();
return result; }
362 #if DEBUG_INDEX_INITIALIZATION_AND_RANGE_CHECK 363 assert(is_initialized());
366 if (__builtin_expect(++
M_bits == 64, 0))
370 uint64_t indx = 64 -
M_bits;
371 __asm__ __volatile__(
374 :
"r" (mask),
"0" (indx)
391 __asm__ __volatile__(
394 :
"r" (tmp.low),
"0" (indx)
402 __asm__ __volatile__(
405 :
"r" (tmp.high),
"0" (indx)
411 #if DEBUG_INDEX_INITIALIZATION_AND_RANGE_CHECK 434 #if DEBUG_INDEX_INITIALIZATION_AND_RANGE_CHECK 435 assert(is_initialized());
441 uint64_t indx = 0xff +
M_bits;
442 __asm__ __volatile__(
445 :
"r" (mask),
"0" (indx)
462 __asm__ __volatile__(
465 :
"r" (tmp.high),
"0" (indx)
468 M_bits = indx - M_bits + 32;
473 __asm__ __volatile__(
476 :
"r" (tmp.low),
"0" (indx)
482 #if DEBUG_INDEX_INITIALIZATION_AND_RANGE_CHECK 483 assert(M_bits < 64 || M_bits == index_pre_begin.
M_bits);
490 #if DEBUG_INDEX_INITIALIZATION_AND_RANGE_CHECK 491 assert(is_initialized());
493 return (int8_t)
M_bits > 0;
IndexData const ie2
A constant representing the index to square e2.
IndexData const index_begin
A constant representing the& #39;first' index.
A namespace for all chess related objects that are not related to the GUI.
IndexData const ia7
A constant representing the index to square a7.
IndexData const id3
A constant representing the index to square d3.
IndexData const ig8
A constant representing the index to square g8.
IndexData const ig3
A constant representing the index to square g3.
IndexData const id4
A constant representing the index to square d4.
IndexData const ih3
A constant representing the index to square h3.
void prev_bit_in(uint64_t mask)
Retreat Index to the previous bit that is set.
IndexData const ie3
A constant representing the index to square e3.
Index(void)
Construct an uninitialized Index object.
IndexData const ia3
A constant representing the index to square a3.
IndexData const id8
A constant representing the index to square d8.
IndexData const if1
A constant representing the index to square f1.
IndexData const if3
A constant representing the index to square f3.
IndexData const ic7
A constant representing the index to square c7.
IndexData const ig1
A constant representing the index to square g1.
uint8_t const row_mask
A mask for the bits used for the row in IndexData.
IndexData const ia4
A constant representing the index to square a4.
IndexData const if4
A constant representing the index to square f4.
IndexData const ia1
A constant representing the index to square a1.
IndexData const ih1
A constant representing the index to square h1.
IndexData const ic3
A constant representing the index to square c3.
IndexData const ib5
A constant representing the index to square b5.
IndexData const ih4
A constant representing the index to square h4.
IndexData const ib1
A constant representing the index to square b1.
void next_bit_in(uint64_t mask)
Advance the index to the next bit that is set in mask.
IndexData const ih5
A constant representing the index to square h5.
IndexData const if2
A constant representing the index to square f2.
Index(IndexData index)
Construct an Index object from a constant.
IndexData const ih8
A constant representing the index to square h8.
IndexData const if8
A constant representing the index to square f8.
IndexData const ie4
A constant representing the index to square e4.
IndexData const ia8
A constant representing the index to square a8.
The POD base type of class Index.
IndexData const ib8
A constant representing the index to square b8.
IndexData const ic1
A constant representing the index to square c1.
Index(Index const& index)
Copy-constructor.
IndexData const ib3
A constant representing the index to square b3.
IndexData const id1
A constant representing the index to square d1.
The index of a chess square.
uint8_t operator()(void) const
Return the unlaying integral value.
IndexData const ih2
A constant representing the index to square h2.
IndexData const ie5
A constant representing the index to square e5.
IndexData const ih7
A constant representing the index to square h7.
int col(void) const
Returns the column.
IndexData const ia5
A constant representing the index to square a5.
IndexData const ig5
A constant representing the index to square g5.
IndexData const ic6
A constant representing the index to square c6.
IndexData const ig7
A constant representing the index to square g7.
IndexData const ih6
A constant representing the index to square h6.
IndexData const ig2
A constant representing the index to square g2.
IndexData const id7
A constant representing the index to square d7.
IndexData const ic4
A constant representing the index to square c4.
IndexData const ib2
A constant representing the index to square b2.
IndexData const ie6
A constant representing the index to square e6.
IndexData const ie7
A constant representing the index to square e7.
int row(void) const
Returns the row.
IndexData const ic5
A constant representing the index to square c5.
IndexData const ia2
A constant representing the index to square a2.
IndexData const id2
A constant representing the index to square d2.
IndexData const id6
A constant representing the index to square d6.
IndexData const ic2
A constant representing the index to square c2.
IndexData const ig4
A constant representing the index to square g4.
bool may_call_prev_bit_in(void) const
Return TRUE if index is not index_pre_begin and also not 0.
IndexData const ic8
A constant representing the index to square c8.
IndexData const ig6
A constant representing the index to square g6.
IndexData const if5
A constant representing the index to square f5.
IndexData const id5
A constant representing the index to square d5.
IndexData const index_pre_begin
A constant representing& #39;one before the start'.
uint8_t M_bits
00RRRCCC, where RRR is the row and CCC the column.
IndexData const ib4
A constant representing the index to square b4.
IndexData const index_end
A constant representing& #39;one past the end'.
IndexData const ie8
A constant representing the index to square e8.
IndexData const if6
A constant representing the index to square f6.
IndexData const if7
A constant representing the index to square f7.
Index(int col, int row)
Construct an Index for column col and row row.
uint8_t const col_mask
A mask for the bits used for the column in IndexData.
IndexData const ib6
A constant representing the index to square b6.
IndexData const ie1
A constant representing the index to square e1.
IndexData const ia6
A constant representing the index to square a6.
IndexData const ib7
A constant representing the index to square b7.