From b3545737fa573dec230e5395f36b86a4c1de0510 Mon Sep 17 00:00:00 2001 From: Marco Costalba Date: Fri, 7 Jan 2011 16:33:15 +0100 Subject: [PATCH] Force inlining of move generation functions MSVC (and possibly other compilers) does not inline as requested, so force it to do so. No functional change. Signed-off-by: Marco Costalba --- src/movegen.cpp | 21 +++++++++++---------- src/types.h | 9 +++++++++ 2 files changed, 20 insertions(+), 10 deletions(-) diff --git a/src/movegen.cpp b/src/movegen.cpp index 5f7ffb35..6f932cd0 100644 --- a/src/movegen.cpp +++ b/src/movegen.cpp @@ -26,6 +26,7 @@ #include "bitcount.h" #include "movegen.h" +#include "types.h" // Simple macro to wrap a very common while loop, no facny, no flexibility, // hardcoded list name 'mlist' and from square 'from'. @@ -99,14 +100,14 @@ namespace { } template<> - inline MoveStack* generate_direct_checks(const Position& p, MoveStack* m, Color us, Bitboard dc, Square ksq) { + FORCE_INLINE MoveStack* generate_direct_checks(const Position& p, MoveStack* m, Color us, Bitboard dc, Square ksq) { return (us == WHITE ? generate_pawn_moves(p, m, dc, ksq) : generate_pawn_moves(p, m, dc, ksq)); } template - inline MoveStack* generate_piece_moves(const Position& p, MoveStack* m, Color us, Bitboard t) { + FORCE_INLINE MoveStack* generate_piece_moves(const Position& p, MoveStack* m, Color us, Bitboard t) { assert(Piece == PAWN); assert(Type == MV_CAPTURE || Type == MV_NON_CAPTURE || Type == MV_EVASION); @@ -116,7 +117,7 @@ namespace { } template - inline MoveStack* generate_piece_moves(const Position& pos, MoveStack* mlist, Color us, Bitboard target) { + FORCE_INLINE MoveStack* generate_piece_moves(const Position& pos, MoveStack* mlist, Color us, Bitboard target) { Bitboard b; Square from; @@ -134,7 +135,7 @@ namespace { } template<> - inline MoveStack* generate_piece_moves(const Position& pos, MoveStack* mlist, Color us, Bitboard target) { + FORCE_INLINE MoveStack* generate_piece_moves(const Position& pos, MoveStack* mlist, Color us, Bitboard target) { Bitboard b; Square from = pos.king_square(us); @@ -160,7 +161,7 @@ namespace { /// generate generates all pseudo-legal captures and /// non-captures. Returns a pointer to the end of the move list. -template +template MoveStack* generate(const Position& pos, MoveStack* mlist) { assert(pos.is_ok()); @@ -169,21 +170,21 @@ MoveStack* generate(const Position& pos, MoveStack* mlist) { Color us = pos.side_to_move(); Bitboard target; - if (T == MV_CAPTURE || T == MV_NON_EVASION) + if (Type == MV_CAPTURE || Type == MV_NON_EVASION) target = pos.pieces_of_color(opposite_color(us)); - else if (T == MV_NON_CAPTURE) + else if (Type == MV_NON_CAPTURE) target = pos.empty_squares(); else assert(false); - if (T == MV_NON_EVASION) + if (Type == MV_NON_EVASION) { mlist = generate_piece_moves(pos, mlist, us, target); mlist = generate_piece_moves(pos, mlist, us, pos.empty_squares()); target |= pos.empty_squares(); } else - mlist = generate_piece_moves(pos, mlist, us, target); + mlist = generate_piece_moves(pos, mlist, us, target); mlist = generate_piece_moves(pos, mlist, us, target); mlist = generate_piece_moves(pos, mlist, us, target); @@ -191,7 +192,7 @@ MoveStack* generate(const Position& pos, MoveStack* mlist) { mlist = generate_piece_moves(pos, mlist, us, target); mlist = generate_piece_moves(pos, mlist, us, target); - if (T != MV_CAPTURE) + if (Type != MV_CAPTURE) { if (pos.can_castle_kingside(us)) mlist = generate_castle_moves(pos, mlist, us); diff --git a/src/types.h b/src/types.h index 31e73bfb..1a9dab7e 100644 --- a/src/types.h +++ b/src/types.h @@ -119,6 +119,15 @@ inline void __cpuid(int CPUInfo[4], int) } #endif +// Define FORCE_INLINE macro to force inlining overriding compiler choice +#if defined(_MSC_VER) +#define FORCE_INLINE __forceinline +#elif defined(__GNUC__) +#define FORCE_INLINE inline __attribute__((always_inline)) +#elif +#define FORCE_INLINE inline +#endif + // Operators used by enum types like Depth, Piece, Square and so on. #define ENABLE_OPERATORS_ON(T) \ -- 2.39.2