GeezerVison is showing github.com — Merge pull request #24648 from charris/backport-24461 · numpy/numpy@bbd7561
File treeExpand file treeCollapse file tree Open diff view settings Expand file treeCollapse file tree Open diff view settings Collapse file Copy file name to clipboardExpand all lines: meson.build +27-5Lines changed: 27 additions & 5 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -55,11 +55,33 @@ add_project_arguments( | 55 | 55 | # | 56 | 56 | # Clang defaults to a non-strict floating error point model, but we need strict | 57 | 57 | # behavior. `-ftrapping-math` is equivalent to `-ffp-exception-behavior=strict`. | 58 | | -# Note that this is only supported on macOS arm64 as of XCode 14.3 | 59 | | -if cc.get_id() == 'clang' | 60 | | - add_project_arguments( | 61 | | - cc.get_supported_arguments('-ftrapping-math'), language: ['c', 'cpp'], | 62 | | - ) | | 58 | +# This flag is also required to prevent the activation of SIMD partial load workarounds. | | 59 | +# For further clarification, refer to gh-24461. | | 60 | +cc_id = cc.get_id() | | 61 | +if cc_id.startswith('clang') | | 62 | + # Determine the compiler flags for trapping math exceptions. | | 63 | + trapping_math = { | | 64 | + 'clang-cl': '/clang:-ftrapping-math', | | 65 | + }.get(cc_id, '-ftrapping-math') | | 66 | + # Check if the compiler supports the trapping math flag. | | 67 | + if cc.has_argument(trapping_math) | | 68 | + # TODO: Consider upgrading the vendored Meson to 1.3.0 to support the parameter `werror` | | 69 | + # Detect whether the compiler actually supports strict handling of floating-point exceptions | | 70 | + # by treating warnings as errors. | | 71 | + if cc.compiles('int main() { return 0; }', args: [trapping_math, '-Werror']) | | 72 | + trapping_math = [trapping_math, '-DNPY_HAVE_CLANG_FPSTRICT'] | | 73 | + else | | 74 | + # Suppress warnings about unsupported floating-point optimization. | | 75 | + trapping_math = [trapping_math, '-Wno-unsupported-floating-point-opt'] | | 76 | + # Inform the user about the workaround. | | 77 | + message( | | 78 | + 'NumPy is being built against a version of Clang that does not strictly enforce ' + | | 79 | + 'floating-point exception handling. Workarounds will be used, which may impact performance.\n' + | | 80 | + 'Consider upgrading Clang to the latest version.' | | 81 | + ) | | 82 | + endif | | 83 | + add_project_arguments(trapping_math, language: ['c', 'cpp']) | | 84 | + endif | 63 | 85 | endif | 64 | 86 |
| 65 | 87 | subdir('meson_cpu') | |
Collapse file Copy file name to clipboardExpand all lines: numpy/core/meson.build +2-6Lines changed: 2 additions & 6 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -838,9 +838,7 @@ foreach gen_mtargets : [ | 838 | 838 | [ | 839 | 839 | 'loops_exponent_log.dispatch.h', | 840 | 840 | src_file.process('src/umath/loops_exponent_log.dispatch.c.src'), | 841 | | - # Enabling SIMD on clang-cl raises spurious FP exceptions | 842 | | - # TODO (seiko2plus): debug spurious FP exceptions for single-precision log/exp | 843 | | - compiler_id == 'clang-cl' ? [] : [ | | 841 | + [ | 844 | 842 | AVX512_SKX, AVX512F, [AVX2, FMA3] | 845 | 843 | ] | 846 | 844 | ], | @@ -884,9 +882,7 @@ foreach gen_mtargets : [ | 884 | 882 | [ | 885 | 883 | 'loops_trigonometric.dispatch.h', | 886 | 884 | src_file.process('src/umath/loops_trigonometric.dispatch.c.src'), | 887 | | - # Enabling SIMD on clang-cl raises spurious FP exceptions | 888 | | - # TODO (seiko2plus): debug spurious FP exceptions for single-precision sin/cos | 889 | | - compiler_id == 'clang-cl' ? [] : [ | | 885 | + [ | 890 | 886 | AVX512F, [AVX2, FMA3], | 891 | 887 | VSX4, VSX3, VSX2, | 892 | 888 | NEON_VFPV4, | |
Collapse file Copy file name to clipboardExpand all lines: numpy/core/src/common/simd/avx2/memory.h +76-21Lines changed: 76 additions & 21 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -196,7 +196,12 @@ NPY_FINLINE npyv_s32 npyv_load_till_s32(const npy_int32 *ptr, npy_uintp nlane, n | 196 | 196 | __m256i vnlane = _mm256_set1_epi32(nlane > 8 ? 8 : (int)nlane); | 197 | 197 | __m256i mask = _mm256_cmpgt_epi32(vnlane, steps); | 198 | 198 | __m256i payload = _mm256_maskload_epi32((const int*)ptr, mask); | 199 | | - return _mm256_blendv_epi8(vfill, payload, mask); | | 199 | + __m256i ret = _mm256_blendv_epi8(vfill, payload, mask); | | 200 | +#if NPY_SIMD_GUARD_PARTIAL_LOAD | | 201 | + volatile __m256i workaround = ret; | | 202 | + ret = _mm256_or_si256(workaround, ret); | | 203 | +#endif | | 204 | + return ret; | 200 | 205 | } | 201 | 206 | // fill zero to rest lanes | 202 | 207 | NPY_FINLINE npyv_s32 npyv_load_tillz_s32(const npy_int32 *ptr, npy_uintp nlane) | @@ -205,7 +210,12 @@ NPY_FINLINE npyv_s32 npyv_load_tillz_s32(const npy_int32 *ptr, npy_uintp nlane) | 205 | 210 | const __m256i steps = _mm256_setr_epi32(0, 1, 2, 3, 4, 5, 6, 7); | 206 | 211 | __m256i vnlane = _mm256_set1_epi32(nlane > 8 ? 8 : (int)nlane); | 207 | 212 | __m256i mask = _mm256_cmpgt_epi32(vnlane, steps); | 208 | | - return _mm256_maskload_epi32((const int*)ptr, mask); | | 213 | + __m256i ret = _mm256_maskload_epi32((const int*)ptr, mask); | | 214 | +#if NPY_SIMD_GUARD_PARTIAL_LOAD | | 215 | + volatile __m256i workaround = ret; | | 216 | + ret = _mm256_or_si256(workaround, ret); | | 217 | +#endif | | 218 | + return ret; | 209 | 219 | } | 210 | 220 | //// 64 | 211 | 221 | NPY_FINLINE npyv_s64 npyv_load_till_s64(const npy_int64 *ptr, npy_uintp nlane, npy_int64 fill) | @@ -216,7 +226,12 @@ NPY_FINLINE npyv_s64 npyv_load_till_s64(const npy_int64 *ptr, npy_uintp nlane, n | 216 | 226 | __m256i vnlane = npyv_setall_s64(nlane > 4 ? 4 : (int)nlane); | 217 | 227 | __m256i mask = _mm256_cmpgt_epi64(vnlane, steps); | 218 | 228 | __m256i payload = _mm256_maskload_epi64((const long long*)ptr, mask); | 219 | | - return _mm256_blendv_epi8(vfill, payload, mask); | | 229 | + __m256i ret = _mm256_blendv_epi8(vfill, payload, mask); | | 230 | +#if NPY_SIMD_GUARD_PARTIAL_LOAD | | 231 | + volatile __m256i workaround = ret; | | 232 | + ret = _mm256_or_si256(workaround, ret); | | 233 | +#endif | | 234 | + return ret; | 220 | 235 | } | 221 | 236 | // fill zero to rest lanes | 222 | 237 | NPY_FINLINE npyv_s64 npyv_load_tillz_s64(const npy_int64 *ptr, npy_uintp nlane) | @@ -225,7 +240,12 @@ NPY_FINLINE npyv_s64 npyv_load_tillz_s64(const npy_int64 *ptr, npy_uintp nlane) | 225 | 240 | const __m256i steps = npyv_set_s64(0, 1, 2, 3); | 226 | 241 | __m256i vnlane = npyv_setall_s64(nlane > 4 ? 4 : (int)nlane); | 227 | 242 | __m256i mask = _mm256_cmpgt_epi64(vnlane, steps); | 228 | | - return _mm256_maskload_epi64((const long long*)ptr, mask); | | 243 | + __m256i ret = _mm256_maskload_epi64((const long long*)ptr, mask); | | 244 | +#if NPY_SIMD_GUARD_PARTIAL_LOAD | | 245 | + volatile __m256i workaround = ret; | | 246 | + ret = _mm256_or_si256(workaround, ret); | | 247 | +#endif | | 248 | + return ret; | 229 | 249 | } | 230 | 250 |
| 231 | 251 | //// 64-bit nlane | @@ -241,7 +261,12 @@ NPY_FINLINE npyv_s32 npyv_load2_till_s32(const npy_int32 *ptr, npy_uintp nlane, | 241 | 261 | __m256i vnlane = npyv_setall_s64(nlane > 4 ? 4 : (int)nlane); | 242 | 262 | __m256i mask = _mm256_cmpgt_epi64(vnlane, steps); | 243 | 263 | __m256i payload = _mm256_maskload_epi64((const long long*)ptr, mask); | 244 | | - return _mm256_blendv_epi8(vfill, payload, mask); | | 264 | + __m256i ret = _mm256_blendv_epi8(vfill, payload, mask); | | 265 | +#if NPY_SIMD_GUARD_PARTIAL_LOAD | | 266 | + volatile __m256i workaround = ret; | | 267 | + ret = _mm256_or_si256(workaround, ret); | | 268 | +#endif | | 269 | + return ret; | 245 | 270 | } | 246 | 271 | // fill zero to rest lanes | 247 | 272 | NPY_FINLINE npyv_s32 npyv_load2_tillz_s32(const npy_int32 *ptr, npy_uintp nlane) | @@ -251,19 +276,29 @@ NPY_FINLINE npyv_s32 npyv_load2_tillz_s32(const npy_int32 *ptr, npy_uintp nlane) | 251 | 276 | NPY_FINLINE npyv_u64 npyv_load2_tillz_s64(const npy_int64 *ptr, npy_uintp nlane) | 252 | 277 | { | 253 | 278 | assert(nlane > 0); | 254 | | - npy_int64 m = -((npy_int64)(nlane > 1)); | | 279 | + npy_int64 m = -((npy_int64)(nlane > 1)); | 255 | 280 | __m256i mask = npyv_set_s64(-1, -1, m, m); | 256 | | - return _mm256_maskload_epi64((const long long*)ptr, mask); | | 281 | + __m256i ret = _mm256_maskload_epi64((const long long*)ptr, mask); | | 282 | +#if NPY_SIMD_GUARD_PARTIAL_LOAD | | 283 | + volatile __m256i workaround = ret; | | 284 | + ret = _mm256_or_si256(workaround, ret); | | 285 | +#endif | | 286 | + return ret; | 257 | 287 | } | 258 | 288 | // fill zero to rest lanes | 259 | 289 | NPY_FINLINE npyv_u64 npyv_load2_till_s64(const npy_int64 *ptr, npy_uintp nlane, | 260 | 290 | npy_int64 fill_lo, npy_int64 fill_hi) | 261 | 291 | { | 262 | 292 | const __m256i vfill = npyv_set_s64(0, 0, fill_lo, fill_hi); | 263 | | - npy_int64 m = -((npy_int64)(nlane > 1)); | 264 | | - __m256i mask = npyv_set_s64(-1, -1, m, m); | | 293 | + npy_int64 m = -((npy_int64)(nlane > 1)); | | 294 | + __m256i mask = npyv_set_s64(-1, -1, m, m); | 265 | 295 | __m256i payload = _mm256_maskload_epi64((const long long*)ptr, mask); | 266 | | - return _mm256_blendv_epi8(vfill, payload, mask); | | 296 | + __m256i ret =_mm256_blendv_epi8(vfill, payload, mask); | | 297 | +#if NPY_SIMD_GUARD_PARTIAL_LOAD | | 298 | + volatile __m256i workaround = ret; | | 299 | + ret = _mm256_or_si256(workaround, ret); | | 300 | +#endif | | 301 | + return ret; | 267 | 302 | } | 268 | 303 | /********************************* | 269 | 304 | * Non-contiguous partial load | @@ -277,9 +312,14 @@ npyv_loadn_till_s32(const npy_int32 *ptr, npy_intp stride, npy_uintp nlane, npy_ | 277 | 312 | const __m256i vfill = _mm256_set1_epi32(fill); | 278 | 313 | const __m256i steps = _mm256_setr_epi32(0, 1, 2, 3, 4, 5, 6, 7); | 279 | 314 | const __m256i idx = _mm256_mullo_epi32(_mm256_set1_epi32((int)stride), steps); | 280 | | - __m256i vnlane = _mm256_set1_epi32(nlane > 8 ? 8 : (int)nlane); | 281 | | - __m256i mask = _mm256_cmpgt_epi32(vnlane, steps); | 282 | | - return _mm256_mask_i32gather_epi32(vfill, (const int*)ptr, idx, mask, 4); | | 315 | + __m256i vnlane = _mm256_set1_epi32(nlane > 8 ? 8 : (int)nlane); | | 316 | + __m256i mask = _mm256_cmpgt_epi32(vnlane, steps); | | 317 | + __m256i ret = _mm256_mask_i32gather_epi32(vfill, (const int*)ptr, idx, mask, 4); | | 318 | +#if NPY_SIMD_GUARD_PARTIAL_LOAD | | 319 | + volatile __m256i workaround = ret; | | 320 | + ret = _mm256_or_si256(workaround, ret); | | 321 | +#endif | | 322 | + return ret; | 283 | 323 | } | 284 | 324 | // fill zero to rest lanes | 285 | 325 | NPY_FINLINE npyv_s32 | @@ -293,9 +333,14 @@ npyv_loadn_till_s64(const npy_int64 *ptr, npy_intp stride, npy_uintp nlane, npy_ | 293 | 333 | const __m256i vfill = npyv_setall_s64(fill); | 294 | 334 | const __m256i idx = npyv_set_s64(0, 1*stride, 2*stride, 3*stride); | 295 | 335 | const __m256i steps = npyv_set_s64(0, 1, 2, 3); | 296 | | - __m256i vnlane = npyv_setall_s64(nlane > 4 ? 4 : (int)nlane); | 297 | | - __m256i mask = _mm256_cmpgt_epi64(vnlane, steps); | 298 | | - return _mm256_mask_i64gather_epi64(vfill, (const long long*)ptr, idx, mask, 8); | | 336 | + __m256i vnlane = npyv_setall_s64(nlane > 4 ? 4 : (int)nlane); | | 337 | + __m256i mask = _mm256_cmpgt_epi64(vnlane, steps); | | 338 | + __m256i ret = _mm256_mask_i64gather_epi64(vfill, (const long long*)ptr, idx, mask, 8); | | 339 | +#if NPY_SIMD_GUARD_PARTIAL_LOAD | | 340 | + volatile __m256i workaround = ret; | | 341 | + ret = _mm256_or_si256(workaround, ret); | | 342 | +#endif | | 343 | + return ret; | 299 | 344 | } | 300 | 345 | // fill zero to rest lanes | 301 | 346 | NPY_FINLINE npyv_s64 | @@ -313,17 +358,22 @@ NPY_FINLINE npyv_s64 npyv_loadn2_till_s32(const npy_int32 *ptr, npy_intp stride, | 313 | 358 | ); | 314 | 359 | const __m256i idx = npyv_set_s64(0, 1*stride, 2*stride, 3*stride); | 315 | 360 | const __m256i steps = npyv_set_s64(0, 1, 2, 3); | 316 | | - __m256i vnlane = npyv_setall_s64(nlane > 4 ? 4 : (int)nlane); | 317 | | - __m256i mask = _mm256_cmpgt_epi64(vnlane, steps); | 318 | | - return _mm256_mask_i64gather_epi64(vfill, (const long long*)ptr, idx, mask, 4); | | 361 | + __m256i vnlane = npyv_setall_s64(nlane > 4 ? 4 : (int)nlane); | | 362 | + __m256i mask = _mm256_cmpgt_epi64(vnlane, steps); | | 363 | + __m256i ret = _mm256_mask_i64gather_epi64(vfill, (const long long*)ptr, idx, mask, 4); | | 364 | +#if NPY_SIMD_GUARD_PARTIAL_LOAD | | 365 | + volatile __m256i workaround = ret; | | 366 | + ret = _mm256_or_si256(workaround, ret); | | 367 | +#endif | | 368 | + return ret; | 319 | 369 | } | 320 | 370 | // fill zero to rest lanes | 321 | 371 | NPY_FINLINE npyv_s32 npyv_loadn2_tillz_s32(const npy_int32 *ptr, npy_intp stride, npy_uintp nlane) | 322 | 372 | { return npyv_loadn2_till_s32(ptr, stride, nlane, 0, 0); } | 323 | 373 |
| 324 | 374 | //// 128-bit load over 64-bit stride | 325 | 375 | NPY_FINLINE npyv_s64 npyv_loadn2_till_s64(const npy_int64 *ptr, npy_intp stride, npy_uintp nlane, | 326 | | - npy_int64 fill_lo, npy_int64 fill_hi) | | 376 | + npy_int64 fill_lo, npy_int64 fill_hi) | 327 | 377 | { | 328 | 378 | assert(nlane > 0); | 329 | 379 | __m256i a = npyv_loadl_s64(ptr); | @@ -336,7 +386,12 @@ NPY_FINLINE npyv_s64 npyv_loadn2_till_s64(const npy_int64 *ptr, npy_intp stride, | 336 | 386 | __m128i fill = _mm_set_epi64x(fill_hi, fill_lo); | 337 | 387 | #endif | 338 | 388 | __m128i b = nlane > 1 ? _mm_loadu_si128((const __m128i*)(ptr + stride)) : fill; | 339 | | - return _mm256_inserti128_si256(a, b, 1); | | 389 | + __m256i ret = _mm256_inserti128_si256(a, b, 1); | | 390 | +#if NPY_SIMD_GUARD_PARTIAL_LOAD | | 391 | + volatile __m256i workaround = ret; | | 392 | + ret = _mm256_or_si256(workaround, ret); | | 393 | +#endif | | 394 | + return ret; | 340 | 395 | } | 341 | 396 | // fill zero to rest lanes | 342 | 397 | NPY_FINLINE npyv_s64 npyv_loadn2_tillz_s64(const npy_int64 *ptr, npy_intp stride, npy_uintp nlane) | |
Collapse file Copy file name to clipboardExpand all lines: numpy/core/src/common/simd/avx512/memory.h +66-11Lines changed: 66 additions & 11 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -248,29 +248,49 @@ NPY_FINLINE npyv_s32 npyv_load_till_s32(const npy_int32 *ptr, npy_uintp nlane, n | 248 | 248 | assert(nlane > 0); | 249 | 249 | const __m512i vfill = _mm512_set1_epi32(fill); | 250 | 250 | const __mmask16 mask = nlane > 15 ? -1 : (1 << nlane) - 1; | 251 | | - return _mm512_mask_loadu_epi32(vfill, mask, (const __m512i*)ptr); | | 251 | + __m512i ret = _mm512_mask_loadu_epi32(vfill, mask, (const __m512i*)ptr); | | 252 | +#if NPY_SIMD_GUARD_PARTIAL_LOAD | | 253 | + volatile __m512i workaround = ret; | | 254 | + ret = _mm512_or_si512(workaround, ret); | | 255 | +#endif | | 256 | + return ret; | 252 | 257 | } | 253 | 258 | // fill zero to rest lanes | 254 | 259 | NPY_FINLINE npyv_s32 npyv_load_tillz_s32(const npy_int32 *ptr, npy_uintp nlane) | 255 | 260 | { | 256 | 261 | assert(nlane > 0); | 257 | 262 | const __mmask16 mask = nlane > 15 ? -1 : (1 << nlane) - 1; | 258 | | - return _mm512_maskz_loadu_epi32(mask, (const __m512i*)ptr); | | 263 | + __m512i ret = _mm512_maskz_loadu_epi32(mask, (const __m512i*)ptr); | | 264 | +#if NPY_SIMD_GUARD_PARTIAL_LOAD | | 265 | + volatile __m512i workaround = ret; | | 266 | + ret = _mm512_or_si512(workaround, ret); | | 267 | +#endif | | 268 | + return ret; | 259 | 269 | } | 260 | 270 | //// 64 | 261 | 271 | NPY_FINLINE npyv_s64 npyv_load_till_s64(const npy_int64 *ptr, npy_uintp nlane, npy_int64 fill) | 262 | 272 | { | 263 | 273 | assert(nlane > 0); | 264 | 274 | const __m512i vfill = npyv_setall_s64(fill); | 265 | 275 | const __mmask8 mask = nlane > 7 ? -1 : (1 << nlane) - 1; | 266 | | - return _mm512_mask_loadu_epi64(vfill, mask, (const __m512i*)ptr); | | 276 | + __m512i ret = _mm512_mask_loadu_epi64(vfill, mask, (const __m512i*)ptr); | | 277 | +#if NPY_SIMD_GUARD_PARTIAL_LOAD | | 278 | + volatile __m512i workaround = ret; | | 279 | + ret = _mm512_or_si512(workaround, ret); | | 280 | +#endif | | 281 | + return ret; | 267 | 282 | } | 268 | 283 | // fill zero to rest lanes | 269 | 284 | NPY_FINLINE npyv_s64 npyv_load_tillz_s64(const npy_int64 *ptr, npy_uintp nlane) | 270 | 285 | { | 271 | 286 | assert(nlane > 0); | 272 | 287 | const __mmask8 mask = nlane > 7 ? -1 : (1 << nlane) - 1; | 273 | | - return _mm512_maskz_loadu_epi64(mask, (const __m512i*)ptr); | | 288 | + __m512i ret = _mm512_maskz_loadu_epi64(mask, (const __m512i*)ptr); | | 289 | +#if NPY_SIMD_GUARD_PARTIAL_LOAD | | 290 | + volatile __m512i workaround = ret; | | 291 | + ret = _mm512_or_si512(workaround, ret); | | 292 | +#endif | | 293 | + return ret; | 274 | 294 | } | 275 | 295 |
| 276 | 296 | //// 64-bit nlane | @@ -280,7 +300,12 @@ NPY_FINLINE npyv_s32 npyv_load2_till_s32(const npy_int32 *ptr, npy_uintp nlane, | 280 | 300 | assert(nlane > 0); | 281 | 301 | const __m512i vfill = _mm512_set4_epi32(fill_hi, fill_lo, fill_hi, fill_lo); | 282 | 302 | const __mmask8 mask = nlane > 7 ? -1 : (1 << nlane) - 1; | 283 | | - return _mm512_mask_loadu_epi64(vfill, mask, (const __m512i*)ptr); | | 303 | + __m512i ret = _mm512_mask_loadu_epi64(vfill, mask, (const __m512i*)ptr); | | 304 | +#if NPY_SIMD_GUARD_PARTIAL_LOAD | | 305 | + volatile __m512i workaround = ret; | | 306 | + ret = _mm512_or_si512(workaround, ret); | | 307 | +#endif | | 308 | + return ret; | 284 | 309 | } | 285 | 310 | // fill zero to rest lanes | 286 | 311 | NPY_FINLINE npyv_s32 npyv_load2_tillz_s32(const npy_int32 *ptr, npy_uintp nlane) | @@ -293,14 +318,24 @@ NPY_FINLINE npyv_u64 npyv_load2_till_s64(const npy_int64 *ptr, npy_uintp nlane, | 293 | 318 | assert(nlane > 0); | 294 | 319 | const __m512i vfill = _mm512_set4_epi64(fill_hi, fill_lo, fill_hi, fill_lo); | 295 | 320 | const __mmask8 mask = nlane > 3 ? -1 : (1 << (nlane*2)) - 1; | 296 | | - return _mm512_mask_loadu_epi64(vfill, mask, (const __m512i*)ptr); | | 321 | + __m512i ret = _mm512_mask_loadu_epi64(vfill, mask, (const __m512i*)ptr); | | 322 | +#if NPY_SIMD_GUARD_PARTIAL_LOAD | | 323 | + volatile __m512i workaround = ret; | | 324 | + ret = _mm512_or_si512(workaround, ret); | | 325 | +#endif | | 326 | + return ret; | 297 | 327 | } | 298 | 328 | // fill zero to rest lanes | 299 | 329 | NPY_FINLINE npyv_s64 npyv_load2_tillz_s64(const npy_int64 *ptr, npy_uintp nlane) | 300 | 330 | { | 301 | 331 | assert(nlane > 0); | 302 | 332 | const __mmask8 mask = nlane > 3 ? -1 : (1 << (nlane*2)) - 1; | 303 | | - return _mm512_maskz_loadu_epi64(mask, (const __m512i*)ptr); | | 333 | + __m512i ret = _mm512_maskz_loadu_epi64(mask, (const __m512i*)ptr); | | 334 | +#if NPY_SIMD_GUARD_PARTIAL_LOAD | | 335 | + volatile __m512i workaround = ret; | | 336 | + ret = _mm512_or_si512(workaround, ret); | | 337 | +#endif | | 338 | + return ret; | 304 | 339 | } | 305 | 340 | /********************************* | 306 | 341 | * Non-contiguous partial load | @@ -317,7 +352,12 @@ npyv_loadn_till_s32(const npy_int32 *ptr, npy_intp stride, npy_uintp nlane, npy_ | 317 | 352 | const __m512i idx = _mm512_mullo_epi32(steps, _mm512_set1_epi32((int)stride)); | 318 | 353 | const __m512i vfill = _mm512_set1_epi32(fill); | 319 | 354 | const __mmask16 mask = nlane > 15 ? -1 : (1 << nlane) - 1; | 320 | | - return _mm512_mask_i32gather_epi32(vfill, mask, idx, (const __m512i*)ptr, 4); | | 355 | + __m512i ret = _mm512_mask_i32gather_epi32(vfill, mask, idx, (const __m512i*)ptr, 4); | | 356 | +#if NPY_SIMD_GUARD_PARTIAL_LOAD | | 357 | + volatile __m512i workaround = ret; | | 358 | + ret = _mm512_or_si512(workaround, ret); | | 359 | +#endif | | 360 | + return ret; | 321 | 361 | } | 322 | 362 | // fill zero to rest lanes | 323 | 363 | NPY_FINLINE npyv_s32 | @@ -334,7 +374,12 @@ npyv_loadn_till_s64(const npy_int64 *ptr, npy_intp stride, npy_uintp nlane, npy_ | 334 | 374 | ); | 335 | 375 | const __m512i vfill = npyv_setall_s64(fill); | 336 | 376 | const __mmask8 mask = nlane > 15 ? -1 : (1 << nlane) - 1; | 337 | | - return _mm512_mask_i64gather_epi64(vfill, mask, idx, (const __m512i*)ptr, 8); | | 377 | + __m512i ret = _mm512_mask_i64gather_epi64(vfill, mask, idx, (const __m512i*)ptr, 8); | | 378 | +#if NPY_SIMD_GUARD_PARTIAL_LOAD | | 379 | + volatile __m512i workaround = ret; | | 380 | + ret = _mm512_or_si512(workaround, ret); | | 381 | +#endif | | 382 | + return ret; | 338 | 383 | } | 339 | 384 | // fill zero to rest lanes | 340 | 385 | NPY_FINLINE npyv_s64 | @@ -352,7 +397,12 @@ NPY_FINLINE npyv_s64 npyv_loadn2_till_s32(const npy_int32 *ptr, npy_intp stride, | 352 | 397 | ); | 353 | 398 | const __m512i vfill = _mm512_set4_epi32(fill_hi, fill_lo, fill_hi, fill_lo); | 354 | 399 | const __mmask8 mask = nlane > 7 ? -1 : (1 << nlane) - 1; | 355 | | - return _mm512_mask_i64gather_epi64(vfill, mask, idx, (const __m512i*)ptr, 4); | | 400 | + __m512i ret = _mm512_mask_i64gather_epi64(vfill, mask, idx, (const __m512i*)ptr, 4); | | 401 | +#if NPY_SIMD_GUARD_PARTIAL_LOAD | | 402 | + volatile __m512i workaround = ret; | | 403 | + ret = _mm512_or_si512(workaround, ret); | | 404 | +#endif | | 405 | + return ret; | 356 | 406 | } | 357 | 407 | // fill zero to rest lanes | 358 | 408 | NPY_FINLINE npyv_s32 npyv_loadn2_tillz_s32(const npy_int32 *ptr, npy_intp stride, npy_uintp nlane) | @@ -369,7 +419,12 @@ NPY_FINLINE npyv_s64 npyv_loadn2_till_s64(const npy_int64 *ptr, npy_intp stride, | 369 | 419 | ); | 370 | 420 | const __mmask8 mask = nlane > 3 ? -1 : (1 << (nlane*2)) - 1; | 371 | 421 | const __m512i vfill = _mm512_set4_epi64(fill_hi, fill_lo, fill_hi, fill_lo); | 372 | | - return _mm512_mask_i64gather_epi64(vfill, mask, idx, (const __m512i*)ptr, 8); | | 422 | + __m512i ret = _mm512_mask_i64gather_epi64(vfill, mask, idx, (const __m512i*)ptr, 8); | | 423 | +#if NPY_SIMD_GUARD_PARTIAL_LOAD | | 424 | + volatile __m512i workaround = ret; | | 425 | + ret = _mm512_or_si512(workaround, ret); | | 426 | +#endif | | 427 | + return ret; | 373 | 428 | } | 374 | 429 | // fill zero to rest lanes | 375 | 430 | NPY_FINLINE npyv_s64 npyv_loadn2_tillz_s64(const npy_int64 *ptr, npy_intp stride, npy_uintp nlane) | |
|