[PATCH] libstdc++: Rewrite or avoid casts to 64-bit element types

2023-06-06 Thread Matthias Kretz via Gcc-patches
Last part to resolve test failure introduced with PR109822. OK for master and backports (gcc-11 doesn't have __builtin_shufflevector, though)? Tested on x86_64-pc-linux-gnu and powerpc64le-linux-gnu - >8 - Fix SFINAE on __is_intrinsic_type for 64-bit element types on non-VSX POWER targ

[PATCH] libstdc++: Avoid vector casts while still avoiding PR90424

2023-06-06 Thread Matthias Kretz via Gcc-patches
This is the first part of a fix for the failure of the new simd test on non- VSX POWER targets. There are more casts to unavailable vectors of 64-bit element types to be rewritten. OK for master and backports? Tested on x86_64-pc-linux-gnu and powerpc64le-linux-gnu -- >8 --- Signed-off

[PATCH] libstdc++: Replace use of incorrect non-temporal store

2023-06-06 Thread Matthias Kretz via Gcc-patches
OK for master and backports? Tested on x86_64-pc-linux-gnu - >8 - The call to the base implementation sometimes didn't find a matching signature because the _Abi parameter of _SimdImpl* was "wrong" after conversion. It has to call into ::_SimdImpl instead of the current ABI tag's _SimdIm

[committed] libstdc++: Protect against macros

2023-06-06 Thread Matthias Kretz via Gcc-patches
pushed to trunk, will backport later tested on x86_64-pc-linux-gnu --- >8 Signed-off-by: Matthias Kretz libstdc++-v3/ChangeLog: * include/experimental/bits/simd.h (__bit_cast): Use __gnu__::__vector_size__ instead of gnu::vector_size. --- libstdc++-v3/include/exp

Re: [PATCH] libstdc++: Correct NTTP and simd_mask ctor call

2023-06-02 Thread Matthias Kretz via Gcc-patches
On Friday, 2 June 2023 11:30:17 CEST Alexandre Oliva wrote: > I also noticed the same test is failing on rtems6 (at least with gcc > 11). AFAICT the problem is that _GLIBCXX_SIMD_MATH_CALL* macros in > simd_math.h expect the named functions to be in std::, but I get such > errors as: > > .../aarc

Re: [PATCH] doc: clarify semantics of vector bitwise shifts

2023-06-02 Thread Matthias Kretz via Gcc-patches
On Friday, 2 June 2023 11:24:23 CEST Alexander Monakov wrote: > > > I'm not sure what you consider a breaking change here. Is that the > > > implied > > > threat to use undefinedness for range deduction and other optimizations? > > > > Consider the stdx::simd implementation. It currently follows s

Re: [PATCH] doc: clarify semantics of vector bitwise shifts

2023-06-02 Thread Matthias Kretz via Gcc-patches
On Friday, 2 June 2023 09:49:26 CEST Alexander Monakov wrote: > > simd x = ...; > > bool t = all_of(x < x + 1); // unconditionally true or not? > > > > I'd expect t to be unconditionally true. Because simd simply is a > > data- parallel version of int. > > Okay, I see opinions will vary here. I w

Re: [PATCH] libstdc++: Correct NTTP and simd_mask ctor call

2023-06-02 Thread Matthias Kretz via Gcc-patches
Hello Alexandre, On Friday, 2 June 2023 10:32:40 CEST Alexandre Oliva wrote: > On May 26, 2023, Matthias Kretz via Libstdc++ wrote: > > OK for master and all backports (after 11.4 is done)? > > tested on powerpc64le-linux-gnu and x86_64-pc-linux-gnu > > > > * testsuite/experimental/simd/pr10

Re: [PATCH] doc: clarify semantics of vector bitwise shifts

2023-06-02 Thread Matthias Kretz via Gcc-patches
On Thursday, 1 June 2023 20:25:14 CEST Alexander Monakov wrote: > On Wed, 31 May 2023, Richard Biener wrote: > > So yes, we probably should clarify the semantics to match the > > implementation (since we have two targets doing things differently > > since forever we can only document it as UB) and

[committed] libstdc++: Fix condition for supported SIMD types on ARMv8

2023-06-01 Thread Matthias Kretz via Gcc-patches
pushed to trunk, will backport tested on arm-linux-gnueabihf -- 8< -- Signed-off-by: Matthias Kretz libstdc++-v3/ChangeLog: PR libstdc++/110050 * include/experimental/bits/simd.h (__vectorized_sizeof): With __have_neon_a32 only single-precision float wo

[PATCH] libstdc++: Correct NTTP and simd_mask ctor call

2023-05-26 Thread Matthias Kretz via Gcc-patches
OK for master and all backports (after 11.4 is done)? tested on powerpc64le-linux-gnu and x86_64-pc-linux-gnu --- 8< Signed-off-by: Matthias Kretz libstdc++-v3/ChangeLog: PR libstdc++/109822 * include/experimental/bits/simd.h (to_native): Use int NTTP

[PATCH] libstdc++: Simplify calculation of expected value in simd test

2023-05-26 Thread Matthias Kretz via Gcc-patches
OK for master and all backports (after 11.4 is done)? tested on powerpc64le-linux-gnu --- 8< This avoids a failure on PR109964. Signed-off-by: Matthias Kretz libstdc++-v3/ChangeLog: * testsuite/experimental/simd/tests/integer_operators.cc: Compute expecte

[PATCH] libstdc++: Fix test assumptions on long and long double

2023-05-26 Thread Matthias Kretz via Gcc-patches
OK for master and all backports (after 11.4 is done) tested on powerpc64le-linux-gnu (with 64-bit long double) --- 8< Expect that long might not fit into the long double mantissa bits. Signed-off-by: Matthias Kretz libstdc++-v3/ChangeLog: * testsuite/experimental

[committed] libstdc++: Resolve -Wsign-compare issue

2023-05-26 Thread Matthias Kretz via Gcc-patches
pushed to master, will backport later tested on x86_64-pc-linux-gnu and powerpc64le-linux-gnu --- 8< Signed-off-by: Matthias Kretz libstdc++-v3/ChangeLog: * include/experimental/bits/simd_ppc.h (_S_bit_shift_left): Negative __y is UB, so prefer signed com

[PATCH] libstdc++: Fix type of first argument to vec_cntm call

2023-05-24 Thread Matthias Kretz via Gcc-patches
OK for master and backports? (also a long-standing bug that didn't surface until the new constexpr test was added) tested on powerpc64le-linux-gnu - 8< - Signed-off-by: Matthias Kretz libstdc++-v3/ChangeLog: PR libstdc++/109949 * include/experiment

[PATCH] libstdc++: Fix SFINAE for __is_intrinsic_type on ARM

2023-05-24 Thread Matthias Kretz via Gcc-patches
OK for master and all branches? (this issue only surfaced because of the new test) 8< - On ARM NEON doesn't support double, so __is_intrinsic_type_v should say false (instead of being ill-formed). Signed-off-by: Matthias Kretz libstdc++-v3/ChangeLog: PR l

[PATCH] libstdc++: Add missing constexpr to simd_neon

2023-05-23 Thread Matthias Kretz via Gcc-patches
Signed-off-by: Matthias Kretz libstdc++-v3/ChangeLog: PR libstdc++/109261 * include/experimental/bits/simd_neon.h (_S_reduce): Add constexpr and make NEON implementation conditional on not __builtin_is_constant_evaluated. --- .../include/experimental/bits/simd_n

[committed] Re: [PATCH] libstdc++: Add missing constexpr to simd

2023-05-23 Thread Matthias Kretz via Gcc-patches
I pushed the attached patch. I kept the operator names... too late, there were already operator names in the stdx::simd implemenation anyway. ;) - Matthias On Monday, 22 May 2023 22:51:49 CEST Jonathan Wakely wrote: > On Mon, 22 May 2023 at 21:27, Matthias Kretz wrote: > > On Monday, 22 May 20

Re: [PATCH] libstdc++: Add missing constexpr to simd

2023-05-22 Thread Matthias Kretz via Gcc-patches
On Monday, 22 May 2023 18:25:15 CEST Jonathan Wakely wrote: > I note that using if (not __builtin_constant_evaluated()) will fail if > compiled with -fno-operator-names, which is why we don't use 'not', 'and', > etc. elsewhere in libstdc++. I don't know if (or why) anybody uses that > option though

[PATCH] libstdc++: Add missing constexpr to simd

2023-05-22 Thread Matthias Kretz via Gcc-patches
OK for trunk and backporting? regtested on x86_64-linux and aarch64-linux The constexpr API is only available with -std=gnu++XX (and proposed for C++26). The proposal is to have the complete simd API usable in constant expressions. This patch resolves several issues with using simd in constant e

[committed] libstdc++: Resolve -Wunused-variable warnings in stdx::simd and tests

2023-05-22 Thread Matthias Kretz via Gcc-patches
pushed to master, will backport later regtested on x86_64-linux Signed-off-by: Matthias Kretz libstdc++-v3/ChangeLog: * include/experimental/bits/simd_builtin.h (_S_fpclassify): Move __infn into #ifdef'ed block. * testsuite/experimental/simd/tests/fpclassify.cc: Declare

[committed] libstdc++: Fix operator% implementation for Clang

2023-03-28 Thread Matthias Kretz via Gcc-patches
This resolves a regression of my previous fix where Clang would ICE on _S_divides. Signed-off-by: Matthias Kretz libstdc++-v3/ChangeLog: * include/experimental/bits/simd_x86.h (_SimdImplX86): Use _Base::_S_divides if the optimized _S_divides function is hidden via the

[PATCH] libstdc++: Add missing trait is_simd_flag_type

2023-03-28 Thread Matthias Kretz via Gcc-patches
I don't know how, but I forgot to implement the is_simd_flag_type trait. This fixes it. No new check-simd failures on x86_64-pc-linux-gnu --- 8< -- Signed-off-by: Matthias Kretz libstdc++-v3/ChangeLog: * include/experimental/bits/simd.h (is_simd_flag_type)

[PATCH] libstdc++: Use more precise __RECIPROCAL_MATH__ macro

2023-03-21 Thread Matthias Kretz via Gcc-patches
Tested on x86_64-pc-linux-gnu. - 8< --- Signed-off-by: Matthias Kretz libstdc++-v3/ChangeLog: * include/experimental/bits/simd_x86.h (_SimdImplX86::_S_divides): Replace test for __GCC_IEC_559 == 0 with __RECIPROCAL_MATH__. --- libstdc++-v3/include/exper

[PATCH] libstdc++: Skip integer division optimization for Clang

2023-03-21 Thread Matthias Kretz via Gcc-patches
Tested on x86_64-pc-linux-gnu. - 8< --- Clang ICEs on _SimdImplX86::_S_divides. The function is only working around a missed optimization and not necessary for correctness. Therefore, don't use it for Clang. Signed-off-by: Matthias Kretz libstdc++-v3/ChangeLog: * inclu

[committed] libstdc++: Fix simd compilation with Clang

2023-03-21 Thread Matthias Kretz via Gcc-patches
Slightly modified patch. I had to fix floating-point AVX512 blending on Clang by removing a cast. While at it I cleaned up the -Wundef noise. - 8< -- Clang fails to compile some constant expressions involving simd. Therefore, just disable this non-conforming extension for clang. Fix AVX

[PATCH 2/2] libstdc++: Fix simd compilation with Clang

2023-03-21 Thread Matthias Kretz via Gcc-patches
Clang fails to compile some constant expressions involving simd. Therefore, just disable this non-conforming extension for clang. Fix AVX512 blend implementation for Clang. It was converting the bitmask to bool before, which is obviously wrong. Instead use a Clang builtin to convert the bitmask

[PATCH 1/2] libstdc++: Fix simd test compilation with Clang

2023-03-21 Thread Matthias Kretz via Gcc-patches
Signed-off-by: Matthias Kretz libstdc++-v3/ChangeLog: * testsuite/experimental/simd/tests/operators.cc: Clang doesn't define __GCC_IEC_559. Use __STDC_IEC_559__ instead. --- .../testsuite/experimental/simd/tests/operators.cc | 9 - 1 file changed, 8 insertions(+)

[PATCH 0/2] Make std::experimental::simd (more) usable with Clang

2023-03-21 Thread Matthias Kretz via Gcc-patches
Up to now, compiling std::experimental::simd with Clang would lead to wrong code, not compiling, or ICEs. After these patches I hope it's only ICEs. Tested on x86_64-pc-linux-gnu. Matthias Kretz (2): libstdc++: Fix simd test compilation with Clang libstdc++: Fix simd compilation with Clang

Re: [PATCH 6/8] libstdc++: Fix formatting

2023-02-24 Thread Matthias Kretz via Gcc-patches
On Friday, 24 February 2023 18:14:53 CET Jonathan Wakely wrote: > Looks like there are a few remaining spaces that could be removed > where you've joined lines, e.g. Fixed and pushed. > OK for trunk anyway (and the branches if you want). I'll likely backport after I backported all other patches

Re: [PATCH 4/8] libstdc++: Add missing constexpr on simd shift implementation

2023-02-23 Thread Matthias Kretz via Gcc-patches
On Thursday, 23 February 2023 12:07:11 CET Jonathan Wakely wrote: > On Thu, 23 Feb 2023 at 08:55, Matthias Kretz via Libstdc++ > > wrote: > > Resolves -Wtautological-compare warnings about `if > > (__builtin_is_constant_evaluated())` in the implementations of these > > functions. > > The 'inline

[PATCH 0/8] std::experimental::simd patchset

2023-02-23 Thread Matthias Kretz via Gcc-patches
Tested on x86_64-pc-linux. This patchset provides the final changes for PR108030 and resolves PR108856. The latter is a pure optimization and could wait for Stage 1 (I'm submitting the patch because simd is experimental/TS) Matthias Kretz (8): libstdc++: Simplify three helper functions into o

[PATCH 1/8] libstdc++: Simplify three helper functions into one

2023-02-23 Thread Matthias Kretz via Gcc-patches
Broadcast is a very common function. This should reduce compile-time effort. Signed-off-by: Matthias Kretz libstdc++-v3/ChangeLog: PR libstdc++/108030 * include/experimental/bits/simd.h (__vector_broadcast): Implement via __vector_broadcast_impl instead of __ca

[PATCH 3/8] libstdc++: More efficient masked inc-/decrement implementation

2023-02-23 Thread Matthias Kretz via Gcc-patches
Signed-off-by: Matthias Kretz libstdc++-v3/ChangeLog: PR libstdc++/108856 * include/experimental/bits/simd_builtin.h (_SimdImplBuiltin::_S_masked_unary): More efficient implementation of masked inc-/decrement for integers and floats without AVX2.

[PATCH 5/8] libstdc++: Always-inline most of non-cmath fixed_size implementation

2023-02-23 Thread Matthias Kretz via Gcc-patches
For simd, the inlining behavior should be similar to builtin types. (No operator on buitin types is ever translated into a function call.) Therefore, always_inline is the right choice (i.e. inline on -O0 as well). Signed-off-by: Matthias Kretz libstdc++-v3/ChangeLog: PR libstdc++/1080

[PATCH 2/8] libstdc++: Fix simd build failure on clang

2023-02-23 Thread Matthias Kretz via Gcc-patches
Clang does not support __attribute__ on lambdas. Therefore, only set _GLIBCXX_SIMD_ALWAYS_INLINE_LAMBDA if __clang__ is not defined. Signed-off-by: Matthias Kretz libstdc++-v3/ChangeLog: PR libstdc++/108030 * include/experimental/bits/simd_detail.h (_GLIBCXX_SIMD_ALWAY

[PATCH 7/8] libstdc++: Fix -Wsign-compare issue

2023-02-23 Thread Matthias Kretz via Gcc-patches
Signed-off-by: Matthias Kretz libstdc++-v3/ChangeLog: * include/experimental/bits/simd_builtin.h (_S_set): Compare as int. The actual range of these indexes is very small. --- libstdc++-v3/include/experimental/bits/simd_builtin.h | 2 +- 1 file changed, 1 insertion(+), 1 delet

[PATCH 6/8] libstdc++: Fix formatting

2023-02-23 Thread Matthias Kretz via Gcc-patches
Whitespace changes only. Signed-off-by: Matthias Kretz libstdc++-v3/ChangeLog: * include/experimental/bits/simd.h: Line breaks and indenting fixed to follow the libstdc++ standard. * include/experimental/bits/simd_builtin.h: Likewise. * include/experimental/bit

[PATCH 4/8] libstdc++: Add missing constexpr on simd shift implementation

2023-02-23 Thread Matthias Kretz via Gcc-patches
Resolves -Wtautological-compare warnings about `if (__builtin_is_constant_evaluated())` in the implementations of these functions. Signed-off-by: Matthias Kretz libstdc++-v3/ChangeLog: * include/experimental/bits/simd_x86.h (_S_bit_shift_left) (_S_bit_shift_right): Declare con

[PATCH 8/8] libstdc++: Test that integral simd reductions are precise

2023-02-23 Thread Matthias Kretz via Gcc-patches
Signed-off-by: Matthias Kretz libstdc++-v3/ChangeLog: * testsuite/experimental/simd/tests/reductions.cc: Introduce max_distance as the type-dependent max error. --- libstdc++-v3/testsuite/experimental/simd/tests/reductions.cc | 3 ++- 1 file changed, 2 insertions(+), 1 deletio

[committed] libstdc++: Fix uses of non-reserved names in simd header

2023-02-20 Thread Matthias Kretz via Gcc-patches
Tested x86_64-pc-linux. Pushed to trunk. -- >8 -- Signed-off-by: Matthias Kretz libstdc++-v3/ChangeLog: * include/experimental/bits/simd.h (__extract_part, split): Use reserved name for template parameter. --- libstdc++-v3/include/experimental/bits/simd.h | 22 +---

[PATCH 6/7] libstdc++: Fix incorrect __builtin_is_constant_evaluated calls

2023-02-15 Thread Matthias Kretz via Gcc-patches
Signed-off-by: Matthias Kretz libstdc++-v3/ChangeLog: * include/experimental/bits/simd_x86.h (_SimdImplX86::_S_not_equal_to, _SimdImplX86::_S_less) (_SimdImplX86::_S_less_equal): Do not call __builtin_is_constant_evaluated in constexpr-if. --- .../include/exper

[PATCH 4/7] libstdc++: Use a PCH to speed up check-simd

2023-02-15 Thread Matthias Kretz via Gcc-patches
Signed-off-by: Matthias Kretz libstdc++-v3/ChangeLog: * testsuite/experimental/simd/generate_makefile.sh: Generate and pre-compile pch.h, which includes all headers that do not depend on command-line macros. * testsuite/experimental/simd/tests/bits/conversions.h:

[PATCH 5/7] libstdc++: printf format string fix in testsuite

2023-02-15 Thread Matthias Kretz via Gcc-patches
Signed-off-by: Matthias Kretz libstdc++-v3/ChangeLog: * testsuite/experimental/simd/tests/bits/verify.h (verify::verify): Use %zx for size_t in format string. --- libstdc++-v3/testsuite/experimental/simd/tests/bits/verify.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)

[PATCH 2/7] libstdc++: Annotate most lambdas with always_inline

2023-02-15 Thread Matthias Kretz via Gcc-patches
All of the annotated lambdas are simply a necessary means for implementing these functions and should never result in an actual function call. Many of these lambdas would go away if C++ had better language support for packs. Signed-off-by: Matthias Kretz libstdc++-v3/ChangeLog: PR lib

[PATCH 7/7] libstdc++: Fix incorrect function call in -ffast-math optimization

2023-02-15 Thread Matthias Kretz via Gcc-patches
Signed-off-by: Matthias Kretz libstdc++-v3/ChangeLog: * include/experimental/bits/simd_math.h (__hypot): Bitcasting between scalars requires the __bit_cast helper function instead of simd_bit_cast. --- libstdc++-v3/include/experimental/bits/simd_math.h | 4 ++-- 1 file

[PATCH 3/7] libstdc++: Document timeout and timeout-factor of simd tests

2023-02-15 Thread Matthias Kretz via Gcc-patches
Signed-off-by: Matthias Kretz libstdc++-v3/ChangeLog: * testsuite/experimental/simd/README.md: Document the timeout and timeout-factor directives. Minor typo fixed. --- libstdc++-v3/testsuite/experimental/simd/README.md | 10 -- 1 file changed, 8 insertions(+), 2 delet

[PATCH 1/7] libstdc++: Ensure __builtin_constant_p isn't lost on the way

2023-02-15 Thread Matthias Kretz via Gcc-patches
The more expensive code path should only be taken if it can be optimized away. Signed-off-by: Matthias Kretz libstdc++-v3/ChangeLog: * include/experimental/bits/simd.h (_SimdWrapper::_M_is_constprop_none_of) (_SimdWrapper::_M_is_constprop_all_of): Return false unless t

[PATCH 0/7] Work on PR108030 and several simd bugfixes and testsuite improvements

2023-02-15 Thread Matthias Kretz via Gcc-patches
As suggested in PR108030, I used __attribute__ syntax to annotate lambdas as always_inline. In few cases the lambda was meant to be a function boundary and the attribute was omitted. PR108030 mentions a few more functions as problematic. But ideally these should not be inline in some fixed_size

Re: [PATCH] libstdc++: ppc: conditionalize vsx-only simd intrinsics

2022-04-29 Thread Matthias Kretz via Gcc-patches
On Friday, 29 April 2022 03:53:40 CEST Alexandre Oliva via Gcc-patches wrote: > Thanks, awaiting feedback on the suggestion above to post the consolidated > patch. LGTM. I think this improves clarity for the __intrisic_type static assertions significantly. And don't bother with my other mail. If

Re: [PATCH] libstdc++: ppc: conditionalize vsx-only simd intrinsics

2022-04-28 Thread Matthias Kretz via Gcc-patches
On Thursday, 28 April 2022 08:09:54 CEST Alexandre Oliva via Gcc-patches wrote: > libstdc++'s bits/simd.h section for PPC (Altivec) defines various > intrinsic vector types that are only available along with VSX: 64-bit > long double, double, (un)signed long long, and 64-bit (un)signed long. Oh,

Re: [PATCH] libstdc++: Implement std::unreachable() for C++23 (P0627R6)

2022-04-01 Thread Matthias Kretz via Gcc-patches
On Friday, 1 April 2022 13:33:42 CEST Jonathan Wakely wrote: > Matthias didn't like my Princess Bride easter egg :-) > Would the attached be better? LGTM. -- ── Dr. Matthias Kretz https://mattkretz

Re: [PATCH] libstdc++: Implement std::unreachable() for C++23 (P0627R6)

2022-03-31 Thread Matthias Kretz via Gcc-patches
I like it. But I'd like it even more if we could have #elif defined _UBSAN __ubsan_invoke_ub("reached std::unreachable()"); But to my knowledge UBSAN has no hooks for the library like this (yet). and... On Thursday, 31 March 2022 17:30:29 CEST Jonathan Wakely via Gcc-patches wrote: > diff