]> git.ipfire.org Git - thirdparty/gcc.git/blame - libstdc++-v3/testsuite/experimental/simd/tests/simd.cc
Fix earlier commit missing patch review changes
[thirdparty/gcc.git] / libstdc++-v3 / testsuite / experimental / simd / tests / simd.cc
CommitLineData
a054608c 1// Copyright (C) 2020-2021 Free Software Foundation, Inc.
02e32295
MK
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#include "bits/verify.h"
19
20template <typename V>
21 void
22 test()
23 {
24 using T = typename V::value_type;
25
26 // V must store V::size() values of type T giving us the lower bound on the
27 // sizeof
28 VERIFY(sizeof(V) >= sizeof(T) * V::size());
29
30 // For fixed_size, V should not pad more than to the next-power-of-2 of
31 // sizeof(T) * V::size() (for ABI stability of V), giving us the upper bound
32 // on the sizeof. For non-fixed_size we give the implementation a bit more
33 // slack to trade space vs. efficiency.
34 auto n = sizeof(T) * V::size();
35 if (n & (n - 1))
36 {
37 n = ((n << 1) & ~n) & ~((n >> 1) | (n >> 3));
38 while (n & (n - 1))
39 n &= n - 1;
40 }
41 if constexpr (
42 !std::is_same_v<typename V::abi_type,
43 std::experimental::simd_abi::fixed_size<V::size()>>)
44 n *= 2;
45 VERIFY(sizeof(V) <= n) << "\nsizeof(V): " << sizeof(V) << "\nn: " << n;
46 }