]>
Commit | Line | Data |
---|---|---|
7adcbafe | 1 | // Copyright (C) 2020-2022 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 | ||
aa89c53c | 18 | // expensive: * [1-9] * * |
02e32295 MK |
19 | #include "bits/verify.h" |
20 | ||
21 | template <typename V> | |
22 | void | |
23 | test() | |
24 | { | |
25 | using T = typename V::value_type; | |
26 | ||
27 | // V must store V::size() values of type T giving us the lower bound on the | |
28 | // sizeof | |
29 | VERIFY(sizeof(V) >= sizeof(T) * V::size()); | |
30 | ||
31 | // For fixed_size, V should not pad more than to the next-power-of-2 of | |
32 | // sizeof(T) * V::size() (for ABI stability of V), giving us the upper bound | |
33 | // on the sizeof. For non-fixed_size we give the implementation a bit more | |
34 | // slack to trade space vs. efficiency. | |
35 | auto n = sizeof(T) * V::size(); | |
36 | if (n & (n - 1)) | |
37 | { | |
38 | n = ((n << 1) & ~n) & ~((n >> 1) | (n >> 3)); | |
39 | while (n & (n - 1)) | |
40 | n &= n - 1; | |
41 | } | |
42 | if constexpr ( | |
43 | !std::is_same_v<typename V::abi_type, | |
44 | std::experimental::simd_abi::fixed_size<V::size()>>) | |
45 | n *= 2; | |
46 | VERIFY(sizeof(V) <= n) << "\nsizeof(V): " << sizeof(V) << "\nn: " << n; | |
47 | } |