2b540b
From 2f0a7153460acc3f21462236f470ec3471fa2ee1 Mon Sep 17 00:00:00 2001
2b540b
From: Boris Ranto <branto@redhat.com>
2b540b
Date: Mon, 31 Jul 2017 19:50:23 +0200
2b540b
Subject: [PATCH] cmake: Support ppc64
2b540b
2b540b
The ppc64 support requires a couple of changes:
2b540b
- adding the ppc64 support to cmake
2b540b
- changing optimized crc32 code to compile on ppc64le only
2b540b
- moving ifdef condition before crc32_align to avoid defined but not
2b540b
used warning
2b540b
2b540b
Signed-off-by: Boris Ranto <branto@redhat.com>
2b540b
---
2b540b
 cmake/modules/SIMDExt.cmake | 15 ++++++++++++++-
2b540b
 src/CMakeLists.txt          |  4 +++-
2b540b
 src/arch/ppc.c              |  8 ++++----
2b540b
 src/common/crc32c_ppc.c     |  6 +++---
2b540b
 4 files changed, 24 insertions(+), 9 deletions(-)
2b540b
2b540b
diff --git a/cmake/modules/SIMDExt.cmake b/cmake/modules/SIMDExt.cmake
2b540b
index 5330835..c47667d 100644
2b540b
--- a/cmake/modules/SIMDExt.cmake
2b540b
+++ b/cmake/modules/SIMDExt.cmake
2b540b
@@ -109,7 +109,20 @@ elseif(CMAKE_SYSTEM_PROCESSOR MATCHES "i386|i686|amd64|x86_64|AMD64")
2b540b
   endif(CMAKE_SYSTEM_PROCESSOR MATCHES "i686|amd64|x86_64|AMD64")
2b540b
 elseif(CMAKE_SYSTEM_PROCESSOR MATCHES "(powerpc|ppc)64le")
2b540b
   set(HAVE_PPC64LE 1)
2b540b
-  message(STATUS " we are ppc64le")
2b540b
+  message(STATUS " we are ppc64")
2b540b
+  CHECK_C_COMPILER_FLAG("-maltivec" HAS_ALTIVEC)
2b540b
+  if(HAS_ALTIVEC)
2b540b
+    message(STATUS " HAS_ALTIVEC yes")
2b540b
+    set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -maltivec")
2b540b
+    set(CMAKE_CXX_FLAGS "${CMAKE_C_FLAGS} -maltivec")
2b540b
+  endif()
2b540b
+  CHECK_C_COMPILER_FLAG("-mcpu=power8" HAVE_POWER8)
2b540b
+  if(HAVE_POWER8)
2b540b
+    message(STATUS " HAVE_POWER8 yes")
2b540b
+  endif()
2b540b
+elseif(CMAKE_SYSTEM_PROCESSOR MATCHES "(power|ppc)64")
2b540b
+  set(HAVE_PPC64 1)
2b540b
+  message(STATUS " we are ppc64")
2b540b
   CHECK_C_COMPILER_FLAG("-maltivec" HAS_ALTIVEC)
2b540b
   if(HAS_ALTIVEC)
2b540b
     message(STATUS " HAS_ALTIVEC yes")
2b540b
diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt
2b540b
index 66f0c14..38d1913 100644
2b540b
--- a/src/CMakeLists.txt
2b540b
+++ b/src/CMakeLists.txt
2b540b
@@ -568,7 +568,9 @@ if(HAVE_INTEL)
2b540b
   endif(HAVE_GOOD_YASM_ELF64)
2b540b
 elseif(HAVE_POWER8)
2b540b
   list(APPEND libcommon_files
2b540b
-    common/crc32c_ppc.c
2b540b
+    common/crc32c_ppc.c)
2b540b
+elseif(HAVE_PPC64LE)
2b540b
+  list(APPEND libcommon_files
2b540b
     common/crc32c_ppc_asm.S
2b540b
     common/crc32c_ppc_fast_zero_asm.S)
2b540b
 endif(HAVE_INTEL)
2b540b
diff --git a/src/arch/ppc.c b/src/arch/ppc.c
2b540b
index f21e2fe..11d3a49 100644
2b540b
--- a/src/arch/ppc.c
2b540b
+++ b/src/arch/ppc.c
2b540b
@@ -14,10 +14,10 @@ int ceph_arch_ppc_crc32 = 0;
2b540b
 
2b540b
 #include <stdio.h>
2b540b
 
2b540b
-#if __linux__ && __powerpc64__
2b540b
+#ifdef HAVE_PPC64LE
2b540b
 #include <sys/auxv.h>
2b540b
 #include <asm/cputable.h>
2b540b
-#endif /* __linux__ && __powerpc64__ */
2b540b
+#endif /* HAVE_PPC64LE */
2b540b
 
2b540b
 #ifndef PPC_FEATURE2_VEC_CRYPTO
2b540b
 #define PPC_FEATURE2_VEC_CRYPTO		0x02000000
2b540b
@@ -31,9 +31,9 @@ int ceph_arch_ppc_probe(void)
2b540b
 {
2b540b
   ceph_arch_ppc_crc32 = 0;
2b540b
 
2b540b
-#if __linux__ && __powerpc64__
2b540b
+#ifdef HAVE_PPC64LE
2b540b
   if (getauxval(AT_HWCAP2) & PPC_FEATURE2_VEC_CRYPTO) ceph_arch_ppc_crc32 = 1;
2b540b
-#endif /* __linux__ && __powerpc64__ */
2b540b
+#endif /* HAVE_PPC64LE */
2b540b
 
2b540b
   return 0;
2b540b
 }
2b540b
diff --git a/src/common/crc32c_ppc.c b/src/common/crc32c_ppc.c
2b540b
index 43756e2..52fd1c4 100644
2b540b
--- a/src/common/crc32c_ppc.c
2b540b
+++ b/src/common/crc32c_ppc.c
2b540b
@@ -20,6 +20,7 @@
2b540b
 #define VMX_ALIGN	16
2b540b
 #define VMX_ALIGN_MASK	(VMX_ALIGN-1)
2b540b
 
2b540b
+#ifdef HAVE_PPC64LE
2b540b
 #ifdef REFLECT
2b540b
 static unsigned int crc32_align(unsigned int crc, unsigned char const *p,
2b540b
                                 unsigned long len)
2b540b
@@ -38,7 +39,6 @@ static unsigned int crc32_align(unsigned int crc, unsigned char const *p,
2b540b
 }
2b540b
 #endif
2b540b
 
2b540b
-#ifdef HAVE_POWER8
2b540b
 static inline unsigned long polynomial_multiply(unsigned int a, unsigned int b) {
2b540b
         vector unsigned int va = {a, 0, 0, 0};
2b540b
         vector unsigned int vb = {b, 0, 0, 0};
2b540b
@@ -134,7 +134,7 @@ uint32_t ceph_crc32c_ppc(uint32_t crc, unsigned char const *data, unsigned len)
2b540b
   return crc;
2b540b
 }
2b540b
 
2b540b
-#else /* HAVE_POWER8 */
2b540b
+#else /* HAVE_PPC64LE */
2b540b
 
2b540b
 /* This symbol has to exist on non-ppc architectures (and on legacy
2b540b
  * ppc systems using power7 or below) in order to compile properly
2b540b
@@ -145,4 +145,4 @@ uint32_t ceph_crc32c_ppc(uint32_t crc, unsigned char const *data, unsigned len)
2b540b
   return 0;
2b540b
 }
2b540b
 
2b540b
-#endif /* HAVE_POWER8 */
2b540b
+#endif /* HAVE_PPC64LE */
2b540b
-- 
2b540b
2.9.4
2b540b