Skip to content

Commit

Permalink
Update
Browse files Browse the repository at this point in the history
* Renamed __popcount_use_table to __popcount_table.
* [PPC] Added PowerPC support from ppc32 to Power10.
  • Loading branch information
MinetaS committed Sep 20, 2024
1 parent 8beb019 commit d3f0db1
Show file tree
Hide file tree
Showing 5 changed files with 127 additions and 6 deletions.
6 changes: 5 additions & 1 deletion src/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -198,7 +198,7 @@ ifeq ($(COMP),gcc)
-Wshadow
else ifeq ($(COMP),clang)
SF_CXXFLAGS += -pedantic -Wextra -Wcast-qual -Wconditional-uninitialized \
-Wmissing-prototypes -Wshadow
-Wmissing-prototypes -Wshadow
else ifeq ($(COMP),icx)
SF_CXXFLAGS += -Wabi -Wmissing-declarations -Wmissing-prototypes -Wshadow
endif
Expand Down Expand Up @@ -274,13 +274,17 @@ ifeq ($(ARCH),)
endif

ifeq ($(ARCH),native)
# -march=native is not available on some architectures.
# Need some automatic detection here.
ARCH_NATIVE := y
SF_CXXFLAGS += -march=native -DARCH_NATIVE
else
ifneq ($(filter x86%,$(ARCH)),)
ARCH_FAMILY := i386
else ifneq ($(filter arm%,$(ARCH)),)
ARCH_FAMILY := arm
else ifneq ($(filter ppc%,$(ARCH)),)
ARCH_FAMILY := ppc
else
ARCH_FAMILY := generic
endif
Expand Down
2 changes: 1 addition & 1 deletion src/arch/i386/arch.h
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,7 @@ inline unsigned int ArchImpl::popcount(T n) {
return _mm_popcnt_u32(std::uint32_t(n));
#else
if constexpr (!is_64bit() && sizeof(T) == 8)
return __popcount_use_table(n);
return __popcount_table(n);
else
return __popcount_value(n);
#endif
Expand Down
48 changes: 48 additions & 0 deletions src/arch/ppc/Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
define HELP_STRING_PPC
To build Stockfish, run the following command:

make <build-target> [ARCH=<preset>]

Build presets for PowerPC architecture:

ppc-power10 > Power10
ppc-power9 > Power9
ppc-power8 > Power8
ppc-power7 > Power7
ppc-64 > PowerPC 64-bit
ppc-32 > PowerPC 32-bit

endef
export HELP_STRING_PPC

ifneq ($(filter $(COMP),gcc clang icx),)

ifeq ($(ARCH),ppc-power10)
SF_CXXFLAGS += -mcpu=power10
else ifeq ($(ARCH),ppc-power9)
SF_CXXFLAGS += -mcpu=power9
else ifeq ($(ARCH),ppc-power8)
SF_CXXFLAGS += -mcpu=power8
else ifeq ($(ARCH),ppc-power7)
SF_CXXFLAGS += -mcpu=power7
else ifeq ($(ARCH),ppc-64)
SF_CXXFLAGS += -mcpu=powerpc64
else ifeq ($(ARCH),ppc-32)
SF_CXXFLAGS += -mcpu=powerpc
endif

endif # gcc clang icx

.PHONY: help-arch config-sanity-arch

help-arch:
@echo "$${HELP_STRING_PPC}"

config-sanity-arch:
@[ "$(ARCH)" = "ppc-power10" -o \
"$(ARCH)" = "ppc-power9" -o \
"$(ARCH)" = "ppc-power8" -o \
"$(ARCH)" = "ppc-power7" -o \
"$(ARCH)" = "ppc-64" -o \
"$(ARCH)" = "ppc-32" \
]
66 changes: 66 additions & 0 deletions src/arch/ppc/arch.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
/*
Stockfish, a UCI chess playing engine derived from Glaurung 2.1
Copyright (C) 2004-2024 The Stockfish developers (see AUTHORS file)
Stockfish is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
Stockfish is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/

#ifndef PPC_ARCH_H_INCLUDED
#define PPC_ARCH_H_INCLUDED

#if !defined(__PPC__)
#error "Not supported in the current architecture."
#endif

#include <cassert>
#include <cstdint>
#include <type_traits>

#include "common.h"

#if STOCKFISH_COMPILER == STOCKFISH_COMPILER_GCC
#include <ppu_intrinsics.h>
#endif

namespace Stockfish {

#ifdef __PPC64__
inline constexpr bool ArchImpl::Is64Bit = true;
#else
inline constexpr bool ArchImpl::Is64Bit = false;
#endif

inline constexpr bool ArchImpl::UsePEXT = false;

template<int Hint>
inline void ArchImpl::prefetch(const void* m) {
__dcbt(m);
}

template<typename T>
inline unsigned int ArchImpl::popcount(T n) {
static_assert(std::is_integral_v<T> && sizeof(T) <= 8);

// This will generate POPCNTD instruction on PWR7 and later.
return __popcount_value(n);
}

template<typename T>
inline T ArchImpl::pext([[maybe_unused]] T n, [[maybe_unused]] T mask) {
return 0;
}

} // namespace Stockfish

#endif // I386_ARCH_H_INCLUDED
11 changes: 7 additions & 4 deletions src/common.h
Original file line number Diff line number Diff line change
Expand Up @@ -100,10 +100,9 @@ enum class PrefetchHint;

// This struct is used to provide generalized functionalities that might have
// different implementations depending on the target architecture. Each
// function defined in this struct is specialized in arch.h file respectively.
// member and function defined in this struct is specialized in arch.h file
// respectively.
struct ArchImpl {
/// Does the struct name fit to its purpose?

static const bool Is64Bit;

static const bool UsePEXT; // used in Bitboard
Expand All @@ -130,7 +129,7 @@ constexpr bool use_pext() { return ArchImpl::UsePEXT; }
// 32-bit environment. Therefore we provide two versions of it and leave it
// for each platform to decide which one to use.
template<typename T>
inline int __popcount_use_table(T n) {
inline int __popcount_table(T n) {
static_assert(std::is_integral_v<T> && sizeof(T) % 2 == 0);

static const std::array<std::uint8_t, 1 << 16> popcntTable = [] {
Expand Down Expand Up @@ -196,6 +195,10 @@ inline T pext(T n, T mask) {

#include "arch/arm/arch.h"

#elif defined(__PPC__)

#include "arch/ppc/arch.h"

#else

#include "arch/generic/arch.h"
Expand Down

0 comments on commit d3f0db1

Please sign in to comment.