/* * Copyright (c) Meta Platforms, Inc. and affiliates. * All rights reserved. * * This source code is licensed under the BSD-style license found in the * LICENSE file in the root directory of this source tree. */ #include #include #include #include #define TEST_FORALL_SUPPORTED_CTYPES(_) \ _(); \ _(); \ _(); \ _(); namespace { // Fill a vector with a monotonic sequence of integer values template void fill_monotonic( std::vector& arr, const int start = 0, const int step = 1) { int value = start; for (size_t i = 0; i < arr.size(); ++i) { arr[i] = static_cast(value); value += step; } } template bool check_all_equal_to(std::vector& arr, const float value) { for (size_t i = 0; i < arr.size(); ++i) { if (arr[i] != static_cast(value)) { return false; } } return true; } } // namespace template void test_load_and_add() { using Vec = executorch::vec::Vectorized; constexpr size_t kVecSize = static_cast(Vec::size()); std::vector in_1(kVecSize); fill_monotonic(in_1); std::vector in_2(kVecSize); fill_monotonic(in_2, kVecSize, -1); const Vec in_1_vec = Vec::loadu(in_1.data()); const Vec in_2_vec = Vec::loadu(in_2.data()); const Vec out_vec = in_1_vec + in_2_vec; std::vector out(kVecSize); out_vec.store(out.data()); EXPECT_TRUE(check_all_equal_to(out, static_cast(kVecSize))); } TEST(VecFloatTest, LoadAndAdd) { TEST_FORALL_SUPPORTED_CTYPES(test_load_and_add); }