blob: 9758992b1c9e095fe4acff664ddde1c90ade9d9e [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 <springbok.h>
#include <stdio.h>
#include <stdlib.h>
#include "pw_unit_test/framework.h"
#include "softrvv.h"
namespace softrvv_vor_test {
namespace {
uint32_t src1[] = {0xAA, 0xA5, 0x5A, 0x55, 0xFF}; // 0x55 = 0b0101
// vector test
uint32_t src2[] = {0xAA, 0xAA, 0x00, 0xAA, 0xAA}; // 0xAA = 0b1010
// register tests
uint32_t rs1[] = {0xAA, 0x0A, 0xA0};
// imm tests
// Note: simm5 is sign extended before op
uint32_t imm[] = {
0xF0,
0x05,
0x0E,
}; // simm5 ∈ [-16, 15]; 0xF0 = -16; 0x0E = 15
const uint32_t kAVL = sizeof(src1) / sizeof(src1[0]);
uint32_t dest[kAVL];
uint32_t ref_vv[] = {0xAA, 0xAF, 0x5A, 0xFF, 0xFF};
uint32_t ref_vx[3][kAVL] = {{0xAA, 0xAF, 0xFA, 0xFF, 0xFF},
{0xAA, 0xAF, 0x5A, 0x5F, 0xFF},
{0xAA, 0xA5, 0xFA, 0xF5, 0xFF}};
uint32_t ref_vi[3][kAVL] = {{0xFA, 0xF5, 0xFA, 0xF5, 0xFF},
{0xAF, 0xA5, 0x5F, 0x55, 0xFF},
{0xAE, 0xAF, 0x5E, 0x5F, 0xFF}};
class SoftRvvVorTest : public ::testing::Test {
protected:
void SetUp() override { memset(dest, 0, sizeof(dest)); }
};
TEST_F(SoftRvvVorTest, VV) {
softrvv::vor_vv<uint32_t>(dest, src1, src2, kAVL);
ASSERT_EQ(memcmp(dest, ref_vv, sizeof(dest)), 0);
}
TEST_F(SoftRvvVorTest, VX) {
const int32_t num_vx_tests = sizeof(rs1) / sizeof(rs1[0]);
for (int32_t i = 0; i < num_vx_tests; i++) {
softrvv::vor_vx<uint32_t>(dest, src1, &rs1[i], kAVL);
ASSERT_EQ(memcmp(dest, &ref_vx[i], sizeof(dest)), 0);
}
}
TEST_F(SoftRvvVorTest, VI) {
const int32_t num_vi_tests = sizeof(imm) / sizeof(imm[0]);
for (int32_t i = 0; i < num_vi_tests; i++) {
softrvv::vor_vx<uint32_t>(dest, src1, &imm[i], kAVL);
ASSERT_EQ(memcmp(dest, &ref_vi[i], sizeof(dest)), 0);
}
}
} // namespace
} // namespace softrvv_vor_test