| 1 | // Auto-generated file. Do not edit! |
| 2 | // Template: test/s16-simd.cc.in |
| 3 | // Generator: tools/xngen |
| 4 | // |
| 5 | // Copyright 2024 Google LLC |
| 6 | // |
| 7 | // This source code is licensed under the BSD-style license found in the |
| 8 | // LICENSE file in the root directory of this source tree. |
| 9 | |
| 10 | |
| 11 | // This header needs to go first for the arch test macros. |
| 12 | #include "xnnpack/common.h" |
| 13 | |
| 14 | #if XNN_ARCH_X86 || XNN_ARCH_X86_64 |
| 15 | |
| 16 | #include <algorithm> |
| 17 | #include <cmath> |
| 18 | #include <cstddef> |
| 19 | #include <cstdint> |
| 20 | #include <limits> |
| 21 | #include <random> |
| 22 | #include <vector> |
| 23 | |
| 24 | #include <gmock/gmock.h> |
| 25 | #include <gtest/gtest.h> |
| 26 | #include "xnnpack/isa-checks.h" |
| 27 | #include "xnnpack/simd/s16-avx512skx.h" |
| 28 | #include "replicable_random_device.h" |
| 29 | |
| 30 | namespace xnnpack { |
| 31 | |
| 32 | class S16SimdAVX512SKXTest : public ::testing::Test { |
| 33 | protected: |
| 34 | void SetUp() override { |
| 35 | TEST_REQUIRES_X86_AVX512SKX; |
| 36 | inputs_.resize(3 * xnn_simd_size_s16); |
| 37 | output_.resize(xnn_simd_size_s16); |
| 38 | std::uniform_int_distribution<int16_t> s16(-100, 100); |
| 39 | std::generate(inputs_.begin(), inputs_.end(), |
| 40 | [&]() { return s16(rng_); }); |
| 41 | } |
| 42 | |
| 43 | xnnpack::ReplicableRandomDevice rng_; |
| 44 | std::vector<int16_t> inputs_; |
| 45 | std::vector<int16_t> output_; |
| 46 | }; |
| 47 | |
| 48 | TEST_F(S16SimdAVX512SKXTest, StoreTail) { |
| 49 | const xnn_simd_s16_t a = xnn_loadu_s16(inputs_.data()); |
| 50 | for (size_t num_elements = 1; num_elements < xnn_simd_size_s16; |
| 51 | num_elements++) { |
| 52 | xnn_store_tail_s16(output_.data(), a, num_elements); |
| 53 | for (size_t k = 0; k < num_elements; k++) { |
| 54 | ASSERT_EQ(output_[k], inputs_[k]) << " " << k; |
| 55 | } |
| 56 | for (size_t k = num_elements; k < xnn_simd_size_s16; k++) { |
| 57 | ASSERT_EQ(output_[k], 0.0f); |
| 58 | } |
| 59 | } |
| 60 | } |
| 61 | } // namespace xnnpack |
| 62 | |
| 63 | #endif // XNN_ARCH_X86 || XNN_ARCH_X86_64 |