blob: 08cb7c812da3f5be7092acf02335233eb0fe7bce [file] [log] [blame]
// 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 <limits.h>
#include <springbok.h>
#include <stdio.h>
#include "pw_unit_test/framework.h"
#include "softrvv.h"
namespace softrvv_vand_test {
namespace {
int8_t dest_e8[] = {-5, 3, 0};
int16_t dest_e16[] = {-5, 3, 0};
int32_t dest_e32[] = {-5, 3, 0};
// register value will truncate and replace vd[0]
int32_t rs1[] = {INT32_MIN, -1, 1, INT32_MAX};
const uint32_t kAVL = sizeof(dest_e8) / sizeof(dest_e8[0]);
const int32_t num_vx_tests = sizeof(rs1) / sizeof(rs1[0]);
int8_t ref_vx_e8[num_vx_tests][kAVL] = {{static_cast<int8_t>(INT32_MIN), 3, 0},
{-1, 3, 0},
{1, 3, 0},
{static_cast<int8_t>(INT32_MAX), 3, 0}};
int16_t ref_vx_e16[num_vx_tests][kAVL] = {
{static_cast<int16_t>(INT32_MIN), 3, 0},
{-1, 3, 0},
{1, 3, 0},
{static_cast<int16_t>(INT32_MAX), 3, 0}};
int32_t ref_vx_e32[num_vx_tests][kAVL] = {
{INT32_MIN, 3, 0}, {-1, 3, 0}, {1, 3, 0}, {INT32_MAX, 3, 0}};
class SoftRvvVmvsxTest : public ::testing::Test {
protected:
void SetUp() override {}
};
TEST_F(SoftRvvVmvsxTest, S_X) {
for (int32_t i = 0; i < num_vx_tests; i++) {
softrvv::vmv_s_x<int8_t, int32_t>(dest_e8, &rs1[i]);
ASSERT_EQ(memcmp(dest_e8, &ref_vx_e8[i], sizeof(dest_e8)), 0);
softrvv::vmv_s_x<int16_t, int32_t>(dest_e16, &rs1[i]);
ASSERT_EQ(memcmp(dest_e16, &ref_vx_e16[i], sizeof(dest_e16)), 0);
softrvv::vmv_s_x<int32_t, int32_t>(dest_e32, &rs1[i]);
ASSERT_EQ(memcmp(dest_e32, &ref_vx_e32[i], sizeof(dest_e32)), 0);
}
}
} // namespace
} // namespace softrvv_vand_test