git: 7b822dde35ab - main - math/py-numpy: fix runtime on powerpc64*

From: Piotr Kubaj <pkubaj_at_FreeBSD.org>
Date: Thu, 29 Dec 2022 00:41:33 UTC
The branch main has been updated by pkubaj:

URL: https://cgit.FreeBSD.org/ports/commit/?id=7b822dde35aba238c5975a3c1fc33ebca75d71b5

commit 7b822dde35aba238c5975a3c1fc33ebca75d71b5
Author:     Piotr Kubaj <pkubaj@FreeBSD.org>
AuthorDate: 2022-12-29 00:41:28 +0000
Commit:     Piotr Kubaj <pkubaj@FreeBSD.org>
CommitDate: 2022-12-29 00:41:28 +0000

    math/py-numpy: fix runtime on powerpc64*
    
    Currently powerpc64* is not properly detected by numpy, due to python
    returning just "powerpc" as architecture name. This commit fixes architecture
    detection with numpy and properly checks for CPU features on FreeBSD.
---
 math/py-numpy/Makefile                             |  1 +
 ...atch-numpy_core_src_common_npy__cpu__features.c | 49 ++++++++++++++++++++++
 .../files/patch-numpy_distutils_ccompiler__opt.py  | 17 ++++++++
 3 files changed, 67 insertions(+)

diff --git a/math/py-numpy/Makefile b/math/py-numpy/Makefile
index c909f6bf034b..1cebcf5eb698 100644
--- a/math/py-numpy/Makefile
+++ b/math/py-numpy/Makefile
@@ -1,5 +1,6 @@
 PORTNAME=	numpy
 PORTVERSION=	1.23.5
+PORTREVISION=	1
 PORTEPOCH=	1
 CATEGORIES=	math python
 MASTER_SITES=	CHEESESHOP \
diff --git a/math/py-numpy/files/patch-numpy_core_src_common_npy__cpu__features.c b/math/py-numpy/files/patch-numpy_core_src_common_npy__cpu__features.c
new file mode 100644
index 000000000000..7119bfb88896
--- /dev/null
+++ b/math/py-numpy/files/patch-numpy_core_src_common_npy__cpu__features.c
@@ -0,0 +1,49 @@
+--- numpy/core/src/common/npy_cpu_features.c.orig	2022-11-19 22:40:58 UTC
++++ numpy/core/src/common/npy_cpu_features.c
+@@ -527,6 +527,18 @@ npy__cpu_init_features(void)
+     #ifndef PPC_FEATURE2_ARCH_3_1
+         #define PPC_FEATURE2_ARCH_3_1  0x00040000
+     #endif
++#elif defined(__FreeBSD__)
++    #include <machine/cpu.h>
++    #include <sys/auxv.h>
++    #ifndef PPC_FEATURE2_ARCH_2_07
++        #define PPC_FEATURE2_ARCH_2_07 0x80000000
++    #endif
++    #ifndef PPC_FEATURE2_ARCH_3_00
++        #define PPC_FEATURE2_ARCH_3_00 0x00800000
++    #endif
++    #ifndef PPC_FEATURE2_ARCH_3_1
++        #define PPC_FEATURE2_ARCH_3_1  0x00040000
++    #endif
+ #endif
+ 
+ static void
+@@ -551,7 +563,26 @@ npy__cpu_init_features(void)
+     npy__cpu_have[NPY_CPU_FEATURE_VSX2] = (hwcap & PPC_FEATURE2_ARCH_2_07) != 0;
+     npy__cpu_have[NPY_CPU_FEATURE_VSX3] = (hwcap & PPC_FEATURE2_ARCH_3_00) != 0;
+     npy__cpu_have[NPY_CPU_FEATURE_VSX4] = (hwcap & PPC_FEATURE2_ARCH_3_1) != 0;
+-// TODO: AIX, FreeBSD
++#elif defined(__FreeBSD__)
++    unsigned long hwcap;
++    elf_aux_info(AT_HWCAP, &hwcap, sizeof(hwcap));
++    if ((hwcap & PPC_FEATURE_HAS_VSX) == 0)
++        return;
++
++    elf_aux_info(AT_HWCAP2, &hwcap, sizeof(hwcap));
++    if (hwcap & PPC_FEATURE2_ARCH_3_1)
++    {
++        npy__cpu_have[NPY_CPU_FEATURE_VSX]  =
++        npy__cpu_have[NPY_CPU_FEATURE_VSX2] =
++        npy__cpu_have[NPY_CPU_FEATURE_VSX3] =
++        npy__cpu_have[NPY_CPU_FEATURE_VSX4] = 1;
++        return;
++    }
++    npy__cpu_have[NPY_CPU_FEATURE_VSX]  = 1;
++    npy__cpu_have[NPY_CPU_FEATURE_VSX2] = (hwcap & PPC_FEATURE2_ARCH_2_07) != 0;
++    npy__cpu_have[NPY_CPU_FEATURE_VSX3] = (hwcap & PPC_FEATURE2_ARCH_3_00) != 0;
++    npy__cpu_have[NPY_CPU_FEATURE_VSX4] = (hwcap & PPC_FEATURE2_ARCH_3_1) != 0;
++// TODO: AIX, OpenBSD
+ #else
+     npy__cpu_have[NPY_CPU_FEATURE_VSX]  = 1;
+     #if defined(NPY_CPU_PPC64LE) || defined(NPY_HAVE_VSX2)
diff --git a/math/py-numpy/files/patch-numpy_distutils_ccompiler__opt.py b/math/py-numpy/files/patch-numpy_distutils_ccompiler__opt.py
new file mode 100644
index 000000000000..d8a0abca53bd
--- /dev/null
+++ b/math/py-numpy/files/patch-numpy_distutils_ccompiler__opt.py
@@ -0,0 +1,17 @@
+--- numpy/distutils/ccompiler_opt.py.orig	2022-11-19 22:40:58 UTC
++++ numpy/distutils/ccompiler_opt.py
+@@ -959,8 +959,12 @@ class _CCompiler:
+         detect_arch = (
+             ("cc_on_x64",      ".*(x|x86_|amd)64.*", ""),
+             ("cc_on_x86",      ".*(win32|x86|i386|i686).*", ""),
+-            ("cc_on_ppc64le",  ".*(powerpc|ppc)64(el|le).*", ""),
+-            ("cc_on_ppc64",    ".*(powerpc|ppc)64.*", ""),
++            ("cc_on_ppc64le",  ".*(powerpc|ppc)64(el|le).*|.*powerpc.*", ""
++                                          "defined(__LP64__) && "
++                                          "defined(__LITTLE_ENDIAN__)"),
++            ("cc_on_ppc64",    ".*(powerpc|ppc).*|.*powerpc.*", ""
++                                          "defined(__LP64__) && "
++                                          "defined(__BIG_ENDIAN__)"),
+             ("cc_on_aarch64",  ".*(aarch64|arm64).*", ""),
+             ("cc_on_armhf",    ".*arm.*", "defined(__ARM_ARCH_7__) || "
+                                           "defined(__ARM_ARCH_7A__)"),