1 |
commit: ca58a4b159282f564f046e035a17f7ce0bd30f01 |
2 |
Author: Sam James <sam <AT> gentoo <DOT> org> |
3 |
AuthorDate: Mon May 24 22:08:17 2021 +0000 |
4 |
Commit: Sam James <sam <AT> gentoo <DOT> org> |
5 |
CommitDate: Mon May 24 22:08:55 2021 +0000 |
6 |
URL: https://gitweb.gentoo.org/repo/gentoo.git/commit/?id=ca58a4b1 |
7 |
|
8 |
dev-python/numpy: add popcnt patch |
9 |
|
10 |
Closes: https://bugs.gentoo.org/788184 |
11 |
Signed-off-by: Sam James <sam <AT> gentoo.org> |
12 |
|
13 |
.../files/numpy-1.20.2-fix-popcnt-detection.patch | 103 +++++++++++++++++++++ |
14 |
...{numpy-1.20.2.ebuild => numpy-1.20.2-r1.ebuild} | 1 + |
15 |
dev-python/numpy/numpy-1.20.3.ebuild | 1 + |
16 |
3 files changed, 105 insertions(+) |
17 |
|
18 |
diff --git a/dev-python/numpy/files/numpy-1.20.2-fix-popcnt-detection.patch b/dev-python/numpy/files/numpy-1.20.2-fix-popcnt-detection.patch |
19 |
new file mode 100644 |
20 |
index 00000000000..85f4bb11b76 |
21 |
--- /dev/null |
22 |
+++ b/dev-python/numpy/files/numpy-1.20.2-fix-popcnt-detection.patch |
23 |
@@ -0,0 +1,103 @@ |
24 |
+https://github.com/numpy/numpy/pull/19074 |
25 |
+https://bugs.gentoo.org/788184 |
26 |
+ |
27 |
+From 8dc768964b5578a8aa9db1ef2c55134a00731e10 Mon Sep 17 00:00:00 2001 |
28 |
+From: Carl Michal <michal@×××××××××××.ca> |
29 |
+Date: Sat, 22 May 2021 20:43:10 -0700 |
30 |
+Subject: [PATCH 1/2] Fix compile-time test of POPCNT |
31 |
+ |
32 |
+The compile-time test of POPCNT, cpu_popcnt.c produced code that would |
33 |
+execute without error even if the machine didn't support the popcnt |
34 |
+instruction. This patch attempts to use popcnt on random numbers so the |
35 |
+compiler can't substitute the answer at compile time. |
36 |
+--- |
37 |
+ numpy/distutils/checks/cpu_popcnt.c | 14 ++++++++++---- |
38 |
+ 1 file changed, 10 insertions(+), 4 deletions(-) |
39 |
+ |
40 |
+diff --git a/numpy/distutils/checks/cpu_popcnt.c b/numpy/distutils/checks/cpu_popcnt.c |
41 |
+index e6a80fb40be4..f6c785dd2a97 100644 |
42 |
+--- a/numpy/distutils/checks/cpu_popcnt.c |
43 |
++++ b/numpy/distutils/checks/cpu_popcnt.c |
44 |
+@@ -4,20 +4,26 @@ |
45 |
+ #include <popcntintrin.h> |
46 |
+ #endif |
47 |
+ |
48 |
++#include <stdlib.h> |
49 |
++ |
50 |
+ int main(void) |
51 |
+ { |
52 |
+ long long a = 0; |
53 |
+ int b; |
54 |
++ |
55 |
++ a = random(); |
56 |
++ b = random(); |
57 |
++ |
58 |
+ #ifdef _MSC_VER |
59 |
+ #ifdef _M_X64 |
60 |
+- a = _mm_popcnt_u64(1); |
61 |
++ a = _mm_popcnt_u64(a); |
62 |
+ #endif |
63 |
+- b = _mm_popcnt_u32(1); |
64 |
++ b = _mm_popcnt_u32(b); |
65 |
+ #else |
66 |
+ #ifdef __x86_64__ |
67 |
+- a = __builtin_popcountll(1); |
68 |
++ a = __builtin_popcountll(a); |
69 |
+ #endif |
70 |
+- b = __builtin_popcount(1); |
71 |
++ b = __builtin_popcount(b); |
72 |
+ #endif |
73 |
+ return (int)a + b; |
74 |
+ } |
75 |
+ |
76 |
+From 52d5fe1ede45083d0783c3e2bbaee5c44df9d553 Mon Sep 17 00:00:00 2001 |
77 |
+From: Carl Michal <michal@×××××××××××.ca> |
78 |
+Date: Sun, 23 May 2021 08:24:52 -0700 |
79 |
+Subject: [PATCH 2/2] Change fix of cpu_popcnt.c to use |
80 |
+ _mm_popcnt_u64/_mm_popcnt_u32 on GCC |
81 |
+ |
82 |
+_builtin_popcount is always available, so the compile-time check always |
83 |
+succeeds. |
84 |
+--- |
85 |
+ numpy/distutils/checks/cpu_popcnt.c | 26 ++++++++------------------ |
86 |
+ 1 file changed, 8 insertions(+), 18 deletions(-) |
87 |
+ |
88 |
+diff --git a/numpy/distutils/checks/cpu_popcnt.c b/numpy/distutils/checks/cpu_popcnt.c |
89 |
+index f6c785dd2a97..540c98dab05d 100644 |
90 |
+--- a/numpy/distutils/checks/cpu_popcnt.c |
91 |
++++ b/numpy/distutils/checks/cpu_popcnt.c |
92 |
+@@ -4,26 +4,16 @@ |
93 |
+ #include <popcntintrin.h> |
94 |
+ #endif |
95 |
+ |
96 |
+-#include <stdlib.h> |
97 |
+- |
98 |
+-int main(void) |
99 |
++int main(int argc, char **argv) |
100 |
+ { |
101 |
+- long long a = 0; |
102 |
+- int b; |
103 |
+- |
104 |
+- a = random(); |
105 |
+- b = random(); |
106 |
+- |
107 |
+-#ifdef _MSC_VER |
108 |
+- #ifdef _M_X64 |
109 |
++ // To make sure popcnt instructions are generated |
110 |
++ // and been tested against the assembler |
111 |
++ unsigned long long a = *((unsigned long long*)argv[argc-1]); |
112 |
++ unsigned int b = *((unsigned int*)argv[argc-2]); |
113 |
++ |
114 |
++#if defined(_M_X64) || defined(__x86_64__) |
115 |
+ a = _mm_popcnt_u64(a); |
116 |
+- #endif |
117 |
+- b = _mm_popcnt_u32(b); |
118 |
+-#else |
119 |
+- #ifdef __x86_64__ |
120 |
+- a = __builtin_popcountll(a); |
121 |
+- #endif |
122 |
+- b = __builtin_popcount(b); |
123 |
+ #endif |
124 |
++ b = _mm_popcnt_u32(b); |
125 |
+ return (int)a + b; |
126 |
+ } |
127 |
|
128 |
diff --git a/dev-python/numpy/numpy-1.20.2.ebuild b/dev-python/numpy/numpy-1.20.2-r1.ebuild |
129 |
similarity index 98% |
130 |
rename from dev-python/numpy/numpy-1.20.2.ebuild |
131 |
rename to dev-python/numpy/numpy-1.20.2-r1.ebuild |
132 |
index 234a0932bb9..2e16936ea19 100644 |
133 |
--- a/dev-python/numpy/numpy-1.20.2.ebuild |
134 |
+++ b/dev-python/numpy/numpy-1.20.2-r1.ebuild |
135 |
@@ -48,6 +48,7 @@ BDEPEND=" |
136 |
PATCHES=( |
137 |
"${FILESDIR}"/numpy-1.20.1-no-hardcode-blasv2.patch |
138 |
"${FILESDIR}"/numpy-1.20.2-fix-ccompiler-tests.patch |
139 |
+ "${FILESDIR}"/numpy-1.20.2-fix-popcnt-detection.patch |
140 |
) |
141 |
|
142 |
distutils_enable_tests pytest |
143 |
|
144 |
diff --git a/dev-python/numpy/numpy-1.20.3.ebuild b/dev-python/numpy/numpy-1.20.3.ebuild |
145 |
index 5b772a58a6f..6604eb23a4e 100644 |
146 |
--- a/dev-python/numpy/numpy-1.20.3.ebuild |
147 |
+++ b/dev-python/numpy/numpy-1.20.3.ebuild |
148 |
@@ -46,6 +46,7 @@ BDEPEND=" |
149 |
PATCHES=( |
150 |
"${FILESDIR}"/numpy-1.20.1-no-hardcode-blasv2.patch |
151 |
"${FILESDIR}"/numpy-1.20.2-fix-ccompiler-tests.patch |
152 |
+ "${FILESDIR}"/numpy-1.20.2-fix-popcnt-detection.patch |
153 |
"${FILESDIR}"/numpy-1.20.3-float-hashing-py310.patch |
154 |
) |