| 1 | // Copyright (C) 2020-2025 Free Software Foundation, Inc. |
| 2 | // |
| 3 | // This file is part of the GNU ISO C++ Library. This library is free |
| 4 | // software; you can redistribute it and/or modify it under the |
| 5 | // terms of the GNU General Public License as published by the |
| 6 | // Free Software Foundation; either version 3, or (at your option) |
| 7 | // any later version. |
| 8 | // |
| 9 | // This library is distributed in the hope that it will be useful, |
| 10 | // but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 11 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 12 | // GNU General Public License for more details. |
| 13 | // |
| 14 | // You should have received a copy of the GNU General Public License along |
| 15 | // with this library; see the file COPYING3. If not see |
| 16 | // <http://www.gnu.org/licenses/>. |
| 17 | |
| 18 | // expensive: * [1-9] * * |
| 19 | #include "bits/main.h" |
| 20 | |
| 21 | namespace stdx = std::experimental; |
| 22 | |
| 23 | template <typename From, typename To> |
| 24 | void |
| 25 | conversions() |
| 26 | { |
| 27 | using ToV = typename To::simd_type; |
| 28 | |
| 29 | using stdx::simd_cast; |
| 30 | using stdx::static_simd_cast; |
| 31 | using stdx::__proposed::resizing_simd_cast; |
| 32 | |
| 33 | auto x = resizing_simd_cast<To>(From()); |
| 34 | COMPARE(typeid(x), typeid(To)); |
| 35 | COMPARE(x, To()); |
| 36 | |
| 37 | x = resizing_simd_cast<To>(From(true)); |
| 38 | const To ref = ToV([](auto i) { return i; }) < int(From::size()); |
| 39 | COMPARE(x, ref) << "converted from: " << From(true); |
| 40 | |
| 41 | const ullong all_bits = ~ullong() >> (64 - From::size()); |
| 42 | for (ullong bit_pos = 1; bit_pos /*until overflow*/; bit_pos *= 2) |
| 43 | { |
| 44 | for (ullong bits : {bit_pos & all_bits, ~bit_pos & all_bits}) |
| 45 | { |
| 46 | const auto from = From::__from_bitset(bits); |
| 47 | const auto to = resizing_simd_cast<To>(from); |
| 48 | COMPARE(to, To::__from_bitset(bits)) |
| 49 | << "\nfrom: " << from << "\nbits: " << std::hex << bits << std::dec; |
| 50 | for (std::size_t i = 0; i < To::size(); ++i) |
| 51 | { |
| 52 | COMPARE(to[i], (bits >> i) & 1) |
| 53 | << "\nfrom: " << from << "\nto: " << to |
| 54 | << "\nbits: " << std::hex << bits << std::dec << "\ni: " << i; |
| 55 | } |
| 56 | } |
| 57 | } |
| 58 | } |
| 59 | |
| 60 | template <typename T, typename V, typename = void> |
| 61 | struct rebind_or_max_fixed |
| 62 | { |
| 63 | using type = stdx::rebind_simd_t< |
| 64 | T, stdx::resize_simd_t<stdx::simd_abi::max_fixed_size<T>, V>>; |
| 65 | }; |
| 66 | |
| 67 | template <typename T, typename V> |
| 68 | struct rebind_or_max_fixed<T, V, std::void_t<stdx::rebind_simd_t<T, V>>> |
| 69 | { |
| 70 | using type = stdx::rebind_simd_t<T, V>; |
| 71 | }; |
| 72 | |
| 73 | template <typename From, typename To> |
| 74 | void |
| 75 | apply_abis() |
| 76 | { |
| 77 | using M0 = typename rebind_or_max_fixed<To, From>::type; |
| 78 | using M1 = stdx::native_simd_mask<To>; |
| 79 | using M2 = stdx::simd_mask<To>; |
| 80 | using M3 = stdx::simd_mask<To, stdx::simd_abi::scalar>; |
| 81 | |
| 82 | using std::is_same_v; |
| 83 | conversions<From, M0>(); |
| 84 | if constexpr (!is_same_v<M1, M0>) |
| 85 | conversions<From, M1>(); |
| 86 | if constexpr (!is_same_v<M2, M0> && !is_same_v<M2, M1>) |
| 87 | conversions<From, M2>(); |
| 88 | if constexpr (!is_same_v<M3, M0> && !is_same_v<M3, M1> && !is_same_v<M3, M2>) |
| 89 | conversions<From, M3>(); |
| 90 | } |
| 91 | |
| 92 | template <typename V> |
| 93 | void |
| 94 | test() |
| 95 | { |
| 96 | using M = typename V::mask_type; |
| 97 | apply_abis<M, ldouble>(); |
| 98 | apply_abis<M, double>(); |
| 99 | apply_abis<M, float>(); |
| 100 | apply_abis<M, ullong>(); |
| 101 | apply_abis<M, llong>(); |
| 102 | apply_abis<M, ulong>(); |
| 103 | apply_abis<M, long>(); |
| 104 | apply_abis<M, uint>(); |
| 105 | apply_abis<M, int>(); |
| 106 | apply_abis<M, ushort>(); |
| 107 | apply_abis<M, short>(); |
| 108 | apply_abis<M, uchar>(); |
| 109 | apply_abis<M, schar>(); |
| 110 | apply_abis<M, char>(); |
| 111 | apply_abis<M, wchar_t>(); |
| 112 | apply_abis<M, char16_t>(); |
| 113 | apply_abis<M, char32_t>(); |
| 114 | } |