blob: d7b77d8b4e9b1bf063b0365e09eaf7bcccaf7766 [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_vand_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};
const uint32_t kAVL = sizeof(src1) / sizeof(src1[0]);
uint32_t dest[kAVL];
uint32_t ref_vv[] = {0xAA, 0xA0, 0x00, 0x00, 0xAA};
uint32_t ref_vx[3][kAVL] = {{0xAA, 0xA0, 0x0A, 0x00, 0xAA},
{0x0A, 0x00, 0x0A, 0x00, 0x0A},
{0xA0, 0xA0, 0x00, 0x00, 0xA0}};
class SoftRvvVandTest : public ::testing::Test {
protected:
void SetUp() override { memset(dest, 0, sizeof(dest)); }
};
TEST_F(SoftRvvVandTest, VV) {
softrvv::vand_vv<uint32_t>(dest, src1, src2, kAVL);
ASSERT_EQ(memcmp(dest, ref_vv, sizeof(dest)), 0);
}
TEST_F(SoftRvvVandTest, VX) {
const int32_t num_vx_tests = sizeof(rs1) / sizeof(rs1[0]);
for (int32_t i = 0; i < num_vx_tests; i++) {
softrvv::vand_vx<uint32_t>(dest, src1, &rs1[i], kAVL);
ASSERT_EQ(memcmp(dest, &ref_vx[i], sizeof(dest)), 0);
}
}
} // namespace
} // namespace softrvv_vand_test