From fd23962fc4fc03206ecadea12b214d0231f18637 Mon Sep 17 00:00:00 2001 From: Peter Osterlund Date: Sun, 25 Feb 2024 20:41:45 +0100 Subject: [PATCH] Use NEON dotprod instructions in Stockfish if supported by CPU --- DroidFishApp/src/main/cpp/nativeutil/Android.mk | 6 +++--- DroidFishApp/src/main/cpp/nativeutil/nativeutil.cpp | 8 +++++++- DroidFishApp/src/main/cpp/stockfish/Android.mk | 11 ++++++++++- 3 files changed, 20 insertions(+), 5 deletions(-) diff --git a/DroidFishApp/src/main/cpp/nativeutil/Android.mk b/DroidFishApp/src/main/cpp/nativeutil/Android.mk index e96081d..d07cfce 100644 --- a/DroidFishApp/src/main/cpp/nativeutil/Android.mk +++ b/DroidFishApp/src/main/cpp/nativeutil/Android.mk @@ -15,9 +15,9 @@ ifeq ($(TARGET_ARCH_ABI),armeabi-v7a) UTIL_SRC_FILES += $(CPU_FEATS_SRC_FILES) $(CPU_FEATS)/src/cpuinfo_arm.c LOCAL_ARM_NEON := false endif -#ifeq ($(TARGET_ARCH_ABI),arm64-v8a) -# UTIL_SRC_FILES += $(CPU_FEATS_SRC_FILES) $(CPU_FEATS)/src/cpuinfo_aarch64.c -#endif +ifeq ($(TARGET_ARCH_ABI),arm64-v8a) + UTIL_SRC_FILES += $(CPU_FEATS_SRC_FILES) $(CPU_FEATS)/src/cpuinfo_aarch64.c +endif ifeq ($(TARGET_ARCH_ABI),x86) UTIL_SRC_FILES += $(CPU_FEATS_SRC_FILES) $(CPU_FEATS)/src/cpuinfo_x86.c endif diff --git a/DroidFishApp/src/main/cpp/nativeutil/nativeutil.cpp b/DroidFishApp/src/main/cpp/nativeutil/nativeutil.cpp index 09c327c..e3cbd47 100644 --- a/DroidFishApp/src/main/cpp/nativeutil/nativeutil.cpp +++ b/DroidFishApp/src/main/cpp/nativeutil/nativeutil.cpp @@ -25,6 +25,8 @@ #if defined(__arm__) #include "cpuinfo_arm.h" +#elif defined(__aarch64__) + #include "cpuinfo_aarch64.h" #elif defined(__i386__) #include "cpuinfo_x86.h" #endif @@ -65,10 +67,14 @@ extern "C" JNIEXPORT jboolean JNICALL Java_org_petero_droidfish_engine_EngineUti using namespace cpu_features; ArmFeatures features = GetArmInfo().features; return features.neon ? JNI_TRUE : JNI_FALSE; +#elif defined(__aarch64__) + using namespace cpu_features; + Aarch64Features features = GetAarch64Info().features; + return features.asimddp ? JNI_TRUE : JNI_FALSE; #elif defined(__i386__) using namespace cpu_features; X86Features features = GetX86Info().features; return features.sse4_1 ? JNI_TRUE : JNI_FALSE; #endif - return true; + return JNI_TRUE; } diff --git a/DroidFishApp/src/main/cpp/stockfish/Android.mk b/DroidFishApp/src/main/cpp/stockfish/Android.mk index 3e8a9f2..5645487 100644 --- a/DroidFishApp/src/main/cpp/stockfish/Android.mk +++ b/DroidFishApp/src/main/cpp/stockfish/Android.mk @@ -12,7 +12,7 @@ ifeq ($(TARGET_ARCH_ABI),armeabi-v7a) LOCAL_ARM_NEON := true endif ifeq ($(TARGET_ARCH_ABI),arm64-v8a) - MY_ARCH_DEF += -DIS_64BIT -DUSE_POPCNT -DUSE_NEON + MY_ARCH_DEF += -DIS_64BIT -DUSE_POPCNT -DUSE_NEON -march=armv8.2-a+dotprod -DUSE_NEON_DOTPROD endif ifeq ($(TARGET_ARCH_ABI),x86_64) MY_ARCH_DEF += -DIS_64BIT -DUSE_SSE41 -msse4.1 @@ -25,6 +25,15 @@ include $(CLEAR_VARS) LOCAL_MODULE := stockfish include $(LOCAL_PATH)/build_sf.mk +ifeq ($(TARGET_ARCH_ABI),arm64-v8a) + MY_ARCH_DEF := -DIS_64BIT -DUSE_POPCNT -DUSE_NEON + include $(CLEAR_VARS) + LOCAL_ARM_NEON := true + LOCAL_MODULE := stockfish_nosimd + include $(LOCAL_PATH)/build_sf.mk + stockfish : stockfish_nosimd +endif + ifeq ($(TARGET_ARCH_ABI),armeabi-v7a) MY_ARCH_DEF := -mthumb -march=armv7-a -mfloat-abi=softfp include $(CLEAR_VARS)