/* Quicktex Texture Compression Library Copyright (C) 2021 Andrew Cassidy Partially derived from rgbcx.h written by Richard Geldreich and licenced under the public domain This program is free software: you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details. You should have received a copy of the GNU Lesser General Public License along with this program. If not, see . */ #include #include #include #include #include #include #include #include #include #include namespace quicktex::tests { template constexpr auto make_arrays() { std::vector::size>> arrays; std::array::size> buffer; std::iota(buffer.begin(), buffer.end(), 1); arrays.push_back(buffer); buffer.fill(1); arrays.push_back(buffer); buffer.fill(0); arrays.push_back(buffer); buffer.fill(std::numeric_limits::max()); arrays.push_back(buffer); if (std::is_signed_v) { std::iota(buffer.begin(), buffer.end(), -1 * (int)xsimd::batch::size); arrays.push_back(buffer); buffer.fill(-1); arrays.push_back(buffer); buffer.fill(std::numeric_limits::min()); arrays.push_back(buffer); } return arrays; } #define TEST_WHADD(TYPE) \ TEST(simd, whadd_##TYPE) { \ for (auto arr : make_arrays()) { \ auto v = xsimd::load_unaligned(&arr[0]); \ auto vsum = simd::whadd(v); \ auto ssum = std::accumulate(arr.begin(), arr.end(), static_cast>(0)); \ EXPECT_EQ(vsum, ssum); \ } \ } TEST_WHADD(int8_t) TEST_WHADD(uint8_t) TEST_WHADD(int16_t) TEST_WHADD(uint16_t) TEST_WHADD(int32_t) TEST_WHADD(uint32_t) } // namespace quicktex::tests