// // Copyright (c) 2017 The Khronos Group Inc. // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. // You may obtain a copy of the License at // // http://www.apache.org/licenses/LICENSE-2.0 // // Unless required by applicable law or agreed to in writing, software // distributed under the License is distributed on an "AS IS" BASIS, // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. // See the License for the specific language governing permissions and // limitations under the License. // #ifndef TEST_CONFORMANCE_CLCPP_UTILS_TEST_DETAIL_VEC_HELPERS_HPP #define TEST_CONFORMANCE_CLCPP_UTILS_TEST_DETAIL_VEC_HELPERS_HPP #include #include #include #include #include #include "../../common.hpp" namespace detail { template T make_value(typename scalar_type::type x, typename std::enable_if::value>::type* = 0) { T value; for(size_t i = 0; i < vector_size::value; i++) { value.s[i] = x; } return value; } template T make_value(T x, typename std::enable_if::value>::type* = 0) { return x; } template result_type multiply(const IN1& x, const IN2& y, typename std::enable_if::value>::type* = 0) { static_assert( (vector_size::value == vector_size::value) && (vector_size::value == vector_size::value), "Vector sizes must be the same." ); typedef typename scalar_type::type SCALAR; result_type value; for(size_t i = 0; i < vector_size::value; i++) { value.s[i] = static_cast(x.s[i]) * static_cast(y.s[i]); } return value; } template result_type multiply(const IN1& x, const IN2& y, typename std::enable_if::value>::type* = 0) { static_assert( !is_vector_type::value && !is_vector_type::value, "IN1 and IN2 must be scalar types" ); return static_cast(x) * static_cast(y); } template T get_min() { typedef typename scalar_type::type SCALAR; return make_value((std::numeric_limits::min)()); } template T get_max() { typedef typename scalar_type::type SCALAR; return make_value((std::numeric_limits::max)()); } template T get_part_max(typename scalar_type::type x) { typedef typename scalar_type::type SCALAR; return make_value((std::numeric_limits::max)() / x); } template T def_limit(typename scalar_type::type x) { return make_value(x); } } // detail namespace #endif // TEST_CONFORMANCE_CLCPP_UTILS_TEST_DETAIL_VEC_HELPERS_HPP