1 // Copyright (C) 2020-2023 Free Software Foundation, Inc.
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)
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.
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/>.
18 #ifndef SIMD_TESTS_BITS_MATHREFERENCE_H_
19 #define SIMD_TESTS_BITS_MATHREFERENCE_H_
25 struct SincosReference
29 std::tuple
<const T
&, const T
&, const T
&>
31 { return std::tie(x
, s
, c
); }
38 std::tuple
<const T
&, const T
&>
40 { return std::tie(x
, ref
); }
50 : size_(0), data_(nullptr) {}
52 Array(size_t s
, const T
*p
)
53 : size_(s
), data_(p
) {}
61 { return data_
+ size_
; }
69 struct sincos
{ static constexpr const char *const str
= "sincos"; };
70 struct atan
{ static constexpr const char *const str
= "atan"; };
71 struct asin
{ static constexpr const char *const str
= "asin"; };
72 struct acos
{ static constexpr const char *const str
= "acos"; };
73 struct log
{ static constexpr const char *const str
= "ln"; };
74 struct log2
{ static constexpr const char *const str
= "log2"; };
75 struct log10
{ static constexpr const char *const str
= "log10"; };
79 struct testdatatype_for_function
82 using type
= Reference
<T
>;
86 struct testdatatype_for_function
<function::sincos
>
89 using type
= SincosReference
<T
>;
92 template <class F
, class T
>
93 using testdatatype_for_function_t
94 = typename testdatatype_for_function
<F
>::template type
<T
>;
101 StaticDeleter(const T
*p
)
108 template <class F
, class T
>
109 inline std::string
filename()
111 static_assert(std::is_floating_point
<T
>::value
, "");
112 static const auto cache
113 = std::string("reference-") + F::str
114 + (sizeof(T
) == 4 && std::__digits_v
<T
> == 24
115 && std::__max_exponent_v
<T
> == 128
118 && std::__digits_v
<T
> == 53
119 && std::__max_exponent_v
<T
> == 1024
121 : (sizeof(T
) == 16 && std::__digits_v
<T
> == 64
122 && std::__max_exponent_v
<T
> == 16384
124 : (sizeof(T
) == 16 && std::__digits_v
<T
> == 113
125 && std::__max_exponent_v
<T
> == 16384
132 template <class Fun
, class T
, class Ref
= testdatatype_for_function_t
<Fun
, T
>>
136 static Array
<Ref
> data
;
137 if (data
.data_
== nullptr)
139 FILE* file
= std::fopen(filename
<Fun
, T
>().c_str(), "rb");
142 std::fseek(file
, 0, SEEK_END
);
143 const size_t size
= std::ftell(file
) / sizeof(Ref
);
145 auto mem
= new Ref
[size
];
146 static StaticDeleter
<Ref
> _cleanup(data
.data_
);
147 data
.size_
= std::fread(mem
, sizeof(Ref
), size
, file
);
155 "%s:%d: the reference data %s does not exist in the current "
156 "working directory.\n",
157 __FILE__
, __LINE__
, filename
<Fun
, T
>().c_str());
163 #endif // SIMD_TESTS_BITS_MATHREFERENCE_H_