Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make casting styles consistent #4793

Closed
wants to merge 1 commit into from

Conversation

cj5716
Copy link
Contributor

@cj5716 cj5716 commented Sep 19, 2023

Make casting styles consistent with the rest of the code.

closes #4793

No functional change

@locutus2
Copy link
Member

I have generated with grep command and some further manual cleanup a list of old C style casts. Here all files are checked not only search.cpp and tt.cpp.

So par example you had overlook in tt.cpp line 47 and in search.cpp line 1865.

bitboard.h:267:  return (int)_mm_popcnt_u64(b);
misc.cpp:101:    return last = logBuf->sputc((char)c);
misc.cpp:218:      compiler += (char)'.'; \
misc.cpp:219:      compiler += (char)('0' + (n) / 10); \
misc.cpp:220:      compiler += (char)('0' + (n) % 10);
misc.cpp:493:  auto fun6 = (fun6_t)(void(*)())GetProcAddress(hAdvapi32, "OpenProcessToken");
misc.cpp:496:  auto fun7 = (fun7_t)(void(*)())GetProcAddress(hAdvapi32, "LookupPrivilegeValueA");
misc.cpp:499:  auto fun8 = (fun8_t)(void(*)())GetProcAddress(hAdvapi32, "AdjustTokenPrivileges");
misc.cpp:624:  auto fun1 = (fun1_t)(void(*)())GetProcAddress(k32, "GetLogicalProcessorInformationEx");
misc.cpp:694:  auto fun2 = (fun2_t)(void(*)())GetProcAddress(k32, "GetNumaNodeProcessorMaskEx");
misc.cpp:695:  auto fun3 = (fun3_t)(void(*)())GetProcAddress(k32, "SetThreadGroupAffinity");
misc.cpp:696:  auto fun4 = (fun4_t)(void(*)())GetProcAddress(k32, "GetNumaNodeProcessorMask2");
misc.cpp:697:  auto fun5 = (fun5_t)(void(*)())GetProcAddress(k32, "GetMaximumProcessorGroupCount");
misc.cpp:88:  int overflow(int c) override { return log(buf->sputc((char)c), "<< "); }
misc.h:136:    return ((uint128)a * (uint128)b) >> 64;
misc.h:138:    uint64_t aL = (uint32_t)a, aH = a >> 32;
misc.h:139:    uint64_t bL = (uint32_t)b, bH = b >> 32;
misc.h:142:    uint64_t c3 = aL * bH + (uint32_t)c2;
movegen.cpp:249:  assert((Type == EVASIONS) == (bool)pos.checkers());
nnue/evaluate_nnue.cpp:142:    return (bool)stream;
nnue/evaluate_nnue.cpp:284:      const int x = ((int)file) * 8;
nnue/evaluate_nnue.cpp:285:      const int y = (7 - (int)rank) * 3;
nnue/layers/affine_transform.h:305:        for (int j = 0; j < (int)NumChunks; ++j)
nnue/layers/affine_transform_sparse_input.h:105:        nnz |= (unsigned)vec_nnz(inputChunk) << (j * InputSimdWidth);
search.cpp:1865:      || (Limits.nodes && Threads.nodes_searched() >= (uint64_t)Limits.nodes))
search.cpp:1879:  size_t multiPV = std::min((size_t)Options["MultiPV"], rootMoves.size());
search.cpp:319:      multiPV = std::max(multiPV, (size_t)4);
syzygy/tbprobe.cpp:1057:                data += (uintptr_t)data & 1;  // Word alignment, we may have a mixed table
syzygy/tbprobe.cpp:1059:                    e.get(0, f)->map_idx[i] = (uint16_t)((uint16_t *)data - (uint16_t *)e.map + 1);
syzygy/tbprobe.cpp:1065:                    e.get(0, f)->map_idx[i] = (uint16_t)(data - e.map + 1);
syzygy/tbprobe.cpp:1072:    return data += (uintptr_t)data & 1; // Word alignment
syzygy/tbprobe.cpp:1113:    data += (uintptr_t)data & 1; // Word alignment
syzygy/tbprobe.cpp:1135:            data = (uint8_t*)(((uintptr_t)data + 0x3F) & ~0x3F); // 64 byte alignment
syzygy/tbprobe.cpp:117:    if ((uintptr_t)addr & (alignof(T) - 1)) // Unaligned pointer (very rare)
syzygy/tbprobe.cpp:266:        *mapping = (uint64_t)mmap;
syzygy/tbprobe.cpp:432:        uint32_t homeBucket = (uint32_t)key & (Size - 1);
syzygy/tbprobe.cpp:445:            uint32_t otherHomeBucket = (uint32_t)otherKey & (Size - 1);
syzygy/tbprobe.cpp:459:        for (const Entry* entry = &hashTable[(uint32_t)key & (Size - 1)]; ; ++entry) {
syzygy/tbprobe.cpp:492:    MaxCardinality = std::max((int)pieces.size(), MaxCardinality);
syzygy/tbprobe.cpp:563:    uint32_t* ptr = (uint32_t*)(d->data + ((uint64_t)block * d->sizeofBlock));
syzygy/tbprobe.cpp:603:            buf64 |= (uint64_t)number<uint32_t, BigEndian>(ptr++) << (64 - buf64Size);
tt.cpp:126:  const uint16_t key16 = (uint16_t)key;  // Use the low 16 bits as key inside the cluster
tt.cpp:133:          return found = (bool)tte[i].depth8, &tte[i];
tt.cpp:42:  if (m || (uint16_t)k != key16)
tt.cpp:43:      move16 = (uint16_t)m;
tt.cpp:47:      || (uint16_t)k != key16
tt.cpp:53:      key16     = (uint16_t)k;
tt.cpp:54:      depth8    = (uint8_t)(d - DEPTH_OFFSET);
tt.cpp:55:      genBound8 = (uint8_t)(TT.generation8 | uint8_t(pv) << 2 | b);
tt.cpp:56:      value16   = (int16_t)v;
tt.cpp:57:      eval16    = (int16_t)ev;
tt.h:47:  bool is_pv()  const { return (bool)(genBound8 & 0x4); }

cj5716 added a commit to cj5716/Stockfish that referenced this pull request Sep 22, 2023
Make casting styles consistent with the rest of the code.

closes official-stockfish#4793

No functional change
@cj5716 cj5716 force-pushed the cast_consistency_pr branch from bf6009e to 7a5ba19 Compare September 22, 2023 05:33
@cj5716
Copy link
Contributor Author

cj5716 commented Sep 22, 2023

updated, thanks
btw, some of the casts listed there have not been changed as it would not compile. Thanks

@locutus2
Copy link
Member

you forgot some, here the updated list:

misc.cpp:493:  auto fun6 = (fun6_t)(void(*)())GetProcAddress(hAdvapi32, "OpenProcessToken");
misc.cpp:496:  auto fun7 = (fun7_t)(void(*)())GetProcAddress(hAdvapi32, "LookupPrivilegeValueA");
misc.cpp:499:  auto fun8 = (fun8_t)(void(*)())GetProcAddress(hAdvapi32, "AdjustTokenPrivileges");
misc.cpp:624:  auto fun1 = (fun1_t)(void(*)())GetProcAddress(k32, "GetLogicalProcessorInformationEx");
misc.cpp:694:  auto fun2 = (fun2_t)(void(*)())GetProcAddress(k32, "GetNumaNodeProcessorMaskEx");
misc.cpp:695:  auto fun3 = (fun3_t)(void(*)())GetProcAddress(k32, "SetThreadGroupAffinity");
misc.cpp:696:  auto fun4 = (fun4_t)(void(*)())GetProcAddress(k32, "GetNumaNodeProcessorMask2");
misc.cpp:697:  auto fun5 = (fun5_t)(void(*)())GetProcAddress(k32, "GetMaximumProcessorGroupCount");
tt.cpp:47:      || (uint16_t)k != key16
syzygy/tbprobe.cpp:1057:                data += (uintptr_t)data & 1;  // Word alignment, we may have a mixed table
syzygy/tbprobe.cpp:1113:    data += (uintptr_t)data & 1; // Word alignment

In misc.cpp are always two function casts per line, but if you change only the first it compiles. Here is a diff with all the additional changes to your PR which works for me.
locutus2/Stockfish@cast_consistency_pr...locutus2:Stockfish:cast_consistency_pr2

cj5716 added a commit to cj5716/Stockfish that referenced this pull request Sep 22, 2023
Make casting styles consistent with the rest of the code.

closes official-stockfish#4793

No functional change
@cj5716 cj5716 force-pushed the cast_consistency_pr branch from 7a5ba19 to 6f56130 Compare September 22, 2023 14:04
Make casting styles consistent with the rest of the code.

closes official-stockfish#4793

No functional change
@cj5716 cj5716 force-pushed the cast_consistency_pr branch from 6f56130 to bd6890a Compare September 22, 2023 14:05
@cj5716
Copy link
Contributor Author

cj5716 commented Sep 22, 2023

fixed, thanks

@vondele vondele added the to be merged Will be merged shortly label Sep 22, 2023
@vondele vondele closed this in fce4cc1 Sep 22, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
no-bench-change to be merged Will be merged shortly
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants