[PATCH 04/11 v2] libstdc++: Make use of __builtin_bit_cast

Matthias Kretz m.kretz@gsi.de
Fri Jun 11 10:53:17 GMT 2021


While testing newer patches I found several missing conversions from 
__bit_cast to simd_bit_cast in this patch (i.e. where bit casting to / from 
fixed_size was sometimes required). Corrected patch attached.


From: Matthias Kretz <kretz@kde.org>

The __bit_cast function was a hack to achieve what __builtin_bit_cast
can do, therefore use __builtin_bit_cast if possible. However,
__builtin_bit_cast cannot be used to cast from/to fixed_size_simd, since
it isn't trivially copyable (in the language sense — in principle it
is). Therefore add __proposed::simd_bit_cast to enable the use case
required in the test framework.

Signed-off-by: Matthias Kretz <m.kretz@gsi.de>

libstdc++-v3/ChangeLog:

        * include/experimental/bits/simd.h (__bit_cast): Implement via
        __builtin_bit_cast #if available.
        (__proposed::simd_bit_cast): Add overloads for simd and
        simd_mask, which use __builtin_bit_cast (or __bit_cast #if not
        available), which return an object of the requested type with
        the same bits as the argument.
        * include/experimental/bits/simd_math.h: Use simd_bit_cast
        instead of __bit_cast to allow casts to fixed_size_simd.
        (copysign): Remove branch that was only required if __bit_cast
        cannot be constexpr.
        * testsuite/experimental/simd/tests/bits/test_values.h: Switch
        from __bit_cast to __proposed::simd_bit_cast since the former
        will not cast fixed_size objects anymore.
---
 libstdc++-v3/include/experimental/bits/simd.h | 57 ++++++++++++++++++-
 .../include/experimental/bits/simd_math.h     | 36 +++++-------
 .../simd/tests/bits/test_values.h             |  8 +--
 3 files changed, 75 insertions(+), 26 deletions(-)


--
──────────────────────────────────────────────────────────────────────────
 Dr. Matthias Kretz                           https://mattkretz.github.io
 GSI Helmholtz Centre for Heavy Ion Research               https://gsi.de
 std::experimental::simd              https://github.com/VcDevel/std-simd
──────────────────────────────────────────────────────────────────────────
-------------- next part --------------
A non-text attachment was scrubbed...
Name: 0001-libstdc-Make-use-of-__builtin_bit_cast.patch
Type: text/x-patch
Size: 8732 bytes
Desc: not available
URL: <https://gcc.gnu.org/pipermail/libstdc++/attachments/20210611/e0f6736c/attachment.bin>


More information about the Libstdc++ mailing list