| // Copyright 2023 Google LLC |
| // |
| // 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. |
| |
| #include <springbok.h> |
| #include <stdint.h> |
| #include <stdio.h> |
| #include <stdlib.h> |
| |
| #include "pw_unit_test/framework.h" |
| #include "softrvv/include/softrvv.h" |
| |
| namespace softrvv_vmin_test { |
| namespace { |
| |
| // common to all tests |
| int32_t src1[] = {-1, 2, 3, 4, 5}; |
| |
| // vector test |
| int32_t src2[] = {5, 4, 3, 2, 1}; |
| |
| // scalar register tests |
| int32_t rs1[] = {1, 3, 5}; |
| |
| }; // namespace |
| const int32_t kAVL = sizeof(src1) / sizeof(src1[0]); |
| int32_t dest[kAVL]; |
| |
| int32_t ref_vv[] = {-1, 2, 3, 2, 1}; |
| |
| int32_t ref_vx[3][kAVL] = { |
| {-1, 1, 1, 1, 1}, {-1, 2, 3, 3, 3}, {-1, 2, 3, 4, 5}}; |
| |
| class SoftRvvVminTest : public ::testing::Test { |
| protected: |
| void SetUp() override { memset(dest, 0, sizeof(dest)); } |
| }; |
| |
| TEST_F(SoftRvvVminTest, VV) { |
| softrvv::vmin_vv<int32_t>(dest, src1, src2, kAVL); |
| ASSERT_EQ(memcmp(dest, ref_vv, sizeof(dest)), 0); |
| } |
| |
| TEST_F(SoftRvvVminTest, VX) { |
| const int32_t num_vx_tests = sizeof(ref_vx) / sizeof(ref_vx[0]); |
| for (int32_t i = 0; i < num_vx_tests; i++) { |
| softrvv::vmin_vx<int32_t>(dest, src1, &rs1[i], kAVL); |
| ASSERT_EQ(memcmp(dest, &ref_vx[i], sizeof(dest)), 0); |
| } |
| } |
| |
| } // namespace softrvv_vmin_test |