-
Notifications
You must be signed in to change notification settings - Fork 2.2k
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
Small cleanups 04 #2584
Small cleanups 04 #2584
Conversation
Starting with an empty PR to collect suggestions for small cleanups. No functional change.
Line 322 in movegen.cpp should change from sliderAttacks |= LineBB[checksq][ksq] ^ checksq; to sliderAttacks |= LineBB[ksq][checksq] ^ checksq; because ksq doesn't change but checksq does so it's more efficient. |
https://github.com/official-stockfish/Stockfish/blob/master/src/evaluate.cpp#L316 |
We can compact some initialization in bitboard.cpp. |
evaluate.cpp lines94-102, remove the "s" to Knight, Bishop, Rook, Queen rewrite comment position.cpp line 669 (no capital letters for chess pieces in general in comments) |
There is an extra space after depth in movepick.cpp, Line 62. |
Very minor nit pick but similar to the LineBB[][] change line 306 in evaluate.cpp |
It looks like the Cuckoo tables go through all of the pieces and use PseudoAttacks[pt]. It might be better for position.cpp line 139 to say: for (Piece pc : {ROOK, KNIGHT, BISHOP, QUEEN, KING}) or similar. |
https://github.com/official-stockfish/Stockfish/blob/master/src/search.cpp#L870 |
@protonspring that would require a longer list (Piece vs PieceType), so don't think this is worthwhile? |
I agree. . perhaps just a comment that pawns are ignored in the cuckoo tables. |
yeah, that comment is somewhat hidden (at the declaration of the arrays, only reversible moves) |
I just realized that line 322 in movegen.cpp which I commented about above doesn't need to be xoring each checksq inside the loop one at a time. Instead the whole block while (sliders)
{
Square checksq = pop_lsb(&sliders);
sliderAttacks |= LineBB[checksq][ksq] ^ checksq;
} can be simplified to while (sliders)
sliderAttacks |= LineBB[ksq][pop_lsb(&sliders)];
sliderAttacks &= ~pos.checkers(); removing all the checkers at once at the end. I verified bench is the same up to depth 28 774011575. |
Since (sliders) is empty most of the time, I believe that on average |
@mstembera Your change to movegen.cpp line 322 is a little slower on my machines. |
@Rocky640 You are right. On average the code inside of the while loop executes only 80% of the time generate() is called. Do you think the following is a better way to simplify? while (sliders)
sliderAttacks |= LineBB[ksq][pop_lsb(&sliders)] & ~pos.checkers(); or while (sliders)
sliderAttacks |= ~sliders & LineBB[ksq][pop_lsb(&sliders)]; @protonspring Thanks. I can't measure any real speed difference between any of the versions. |
Lines 258 and 259 in bitboard.h edge_distance(File f) and edge_distance(Rank r) return File and Rank respectively. Would it make more sense to have them return int or name them better w/o using the word distance? All of our other distance methods return int. |
@mstembera Then, all of the calls would have be edge_distance(file_of(x)), which might be kinda ugly ? EDIT: After looking at it, it's not that bad. How about? |
@protonspring I don't see any reason to add file_of(x) when passing parameters to edge_distance(). |
Just wanna nudge a decision on possible specialization for Are these cases required for anything (testing, tuning, invalid positions)? Otherwise it may (?) be a good idea to specialize, remove or delete them. |
@Lolligerhans you refer to this code, I assume, but I'm not quite sure what your observation is: Lines 246 to 252 in f2430bf
|
@vondele I found myself use the member
to obtain best speed or
to prevent usage or to remove the instantiation entirely. I think it makes sense to specialize, allowing |
I see ... |
pieceCount[W_KING] is well defined, and is 1 I cannot test at this moment but I believe So what is the problem ? Specializing? Definitively not, If you want to speedup Remove/Delete? It would make things uglier, and less consistent... |
I prefer master on this one In many place we use things such as this, for readability and we let the compiler optimize all this |
@vondele Ah yes, the @Rocky640 I do believe |
official-stockfish#2584 No functional change.
merged |
sorry for late reply
|
Starting with an empty PR to collect suggestions for small cleanups.
No functional change.