From 6732eb9eb5db7b4496c4421a5866476a8aefd981 Mon Sep 17 00:00:00 2001 From: Stefan Weil Date: Wed, 20 May 2020 20:06:23 +0200 Subject: [PATCH] Clean code for NEON support Include it only for NEON and remove unneeded code. Signed-off-by: Stefan Weil --- src/api/tesseractmain.cpp | 5 ++++- src/arch/intsimdmatrix.h | 5 +++-- src/arch/intsimdmatrixneon.cpp | 6 ++---- src/arch/simddetect.cpp | 9 +++++---- 4 files changed, 14 insertions(+), 11 deletions(-) diff --git a/src/api/tesseractmain.cpp b/src/api/tesseractmain.cpp index bbfc3b7e..8e5513e5 100644 --- a/src/api/tesseractmain.cpp +++ b/src/api/tesseractmain.cpp @@ -135,13 +135,16 @@ static void PrintVersionInfo() { } } #endif +#if defined(HAVE_NEON) + if (tesseract::SIMDDetect::IsNEONAvailable()) printf(" Found NEON\n"); +#else if (tesseract::SIMDDetect::IsAVX512BWAvailable()) printf(" Found AVX512BW\n"); if (tesseract::SIMDDetect::IsAVX512FAvailable()) printf(" Found AVX512F\n"); if (tesseract::SIMDDetect::IsAVX2Available()) printf(" Found AVX2\n"); if (tesseract::SIMDDetect::IsAVXAvailable()) printf(" Found AVX\n"); if (tesseract::SIMDDetect::IsFMAAvailable()) printf(" Found FMA\n"); if (tesseract::SIMDDetect::IsSSEAvailable()) printf(" Found SSE\n"); - if (tesseract::SIMDDetect::IsNEONAvailable()) printf(" Found NEON\n"); +#endif #ifdef _OPENMP printf(" Found OpenMP %d\n", _OPENMP); #endif diff --git a/src/arch/intsimdmatrix.h b/src/arch/intsimdmatrix.h index 41e78447..7f208aba 100644 --- a/src/arch/intsimdmatrix.h +++ b/src/arch/intsimdmatrix.h @@ -2,7 +2,6 @@ // File: intsimdmatrix.h // Description: Base class for 8-bit int SIMD matrix multipliers. // Author: Ray Smith -// Created: Tue Aug 15 07:37:20 PST 2017 // // (C) Copyright 2017, Google Inc. // Licensed under the Apache License, Version 2.0 (the "License"); @@ -114,9 +113,11 @@ struct IntSimdMatrix { // num_input_groups_ = num_inputs_per_register_ / num_inputs_per_group_ static const IntSimdMatrix* intSimdMatrix; + // Only available with NEON. + static const IntSimdMatrix intSimdMatrixNEON; + // Only available with AVX2 / SSE. static const IntSimdMatrix intSimdMatrixAVX2; static const IntSimdMatrix intSimdMatrixSSE; - static const IntSimdMatrix intSimdMatrixNEON; }; } // namespace tesseract diff --git a/src/arch/intsimdmatrixneon.cpp b/src/arch/intsimdmatrixneon.cpp index 220e1b7a..d1b6b8a3 100644 --- a/src/arch/intsimdmatrixneon.cpp +++ b/src/arch/intsimdmatrixneon.cpp @@ -16,9 +16,7 @@ // limitations under the License. /////////////////////////////////////////////////////////////////////// -#if !defined(__ARM_NEON) -//#error Implementation only for NEON capable architectures -#else +#if defined(__ARM_NEON) #include "intsimdmatrix.h" @@ -158,4 +156,4 @@ const IntSimdMatrix IntSimdMatrix::intSimdMatrixNEON = { } // namespace tesseract. -#endif +#endif /* __ARM_NEON */ diff --git a/src/arch/simddetect.cpp b/src/arch/simddetect.cpp index 22acd237..74919acf 100644 --- a/src/arch/simddetect.cpp +++ b/src/arch/simddetect.cpp @@ -66,6 +66,10 @@ static STRING_VAR(dotproduct, "auto", SIMDDetect SIMDDetect::detector; +#if defined(HAVE_NEON) +// If true, then Neon has been detected. +bool SIMDDetect::neon_available_; +#else // If true, then AVX has been detected. bool SIMDDetect::avx_available_; bool SIMDDetect::avx2_available_; @@ -75,8 +79,7 @@ bool SIMDDetect::avx512BW_available_; bool SIMDDetect::fma_available_; // If true, then SSe4.1 has been detected. bool SIMDDetect::sse_available_; -// If true, then Neon has been detected. -bool SIMDDetect::neon_available_; +#endif // Computes and returns the dot product of the two n-vectors u and v. static double DotProductGeneric(const double* u, const double* v, int n) { @@ -188,8 +191,6 @@ SIMDDetect::SIMDDetect() { neon_available_ = (android_getCpuFeatures() & ANDROID_CPU_ARM64_FEATURE_ASIMD); #endif - else - neon_available_ = false; } #else /* Assume linux */