// 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_vmadd_vnmsub_test {
namespace {

class SoftRvvVmaddTest : public ::testing::Test {
 protected:
  void SetUp() override { }
};

class SoftRvvVnmsubTest : public ::testing::Test {
 protected:
  void SetUp() override { }
};


// Integer multiply-add, overwrite multiplicand
// vmadd.vv vd, vs1, vs2, vm    # vd[i] = (vs1[i] * vd[i]) + vs2[i]
uint32_t vmaddvv_vs1[] = {1, 1, 128,   64,   0};
uint32_t vmaddvv_vs2[] = {0, 1,   1,   2,  32};
const uint32_t vmaddvv_kAVL = sizeof(vmaddvv_vs2) / sizeof(vmaddvv_vs2[0]);
uint32_t vmaddvv_vd[] =  {0, 1,  2,   4,   8};
int32_t vmaddvv_ref[] =  {0, 2,  257, 258,  32};
TEST_F(SoftRvvVmaddTest, VV) {
  softrvv::vmadd_vv<uint32_t>(vmaddvv_vd, vmaddvv_vs1, vmaddvv_vs2, vmaddvv_kAVL);
  ASSERT_EQ(memcmp(vmaddvv_vd, vmaddvv_ref, sizeof(vmaddvv_vd)), 0);
}

// Integer multiply-add, overwrite multiplicand
// vmadd.vx vd, rs1, vs2, vm    # vd[i] = (x[rs1] * vd[i]) + vs2[i]
uint32_t vmaddvx_rs1[] = {170};
uint32_t vmaddvx_vs2[] = {0, 1,   1,   2, 32};
const uint32_t vmaddvx_kAVL = sizeof(vmaddvx_vs2) / sizeof(vmaddvx_vs2[0]);
uint32_t vmaddvx_vd[] =  {0, 1,   2,   4,  8};
int32_t vmaddvx_ref[] =  {0, 171,   341,   682,  1392};
TEST_F(SoftRvvVmaddTest, VX) {
    softrvv::vmadd_vx<uint32_t>(vmaddvx_vd, vmaddvx_rs1, vmaddvx_vs2, vmaddvx_kAVL);
    ASSERT_EQ(memcmp(vmaddvx_vd, vmaddvx_ref, sizeof(vmaddvx_vd)), 0);
}

// Integer multiply-sub, overwrite multiplicand
// vnmsub.vv vd, vs1, vs2, vm    # vd[i] = -(vs1[i] * vd[i]) + vs2[i]
uint32_t vnmsubvv_vs1[] = {220,  24,  1234,   150,     1386};
uint32_t vnmsubvv_vs2[] = {  1,   2,     2,    10,     1000};
const uint32_t vnmsubvv_kAVL = sizeof(vnmsubvv_vs2) / sizeof(vnmsubvv_vs2[0]);
uint32_t vnmsubvv_vd[] =  {  0,  10,    10,  1000,        1};
int32_t vnmsubvv_ref[] = {1, -238, -12338,  -149990, -386};
TEST_F(SoftRvvVnmsubTest, VV) {
  softrvv::vnmsub_vv<uint32_t>(vnmsubvv_vd, vnmsubvv_vs1, vnmsubvv_vs2, vnmsubvv_kAVL);
  ASSERT_EQ(memcmp(vnmsubvv_vd, vnmsubvv_ref, sizeof(vnmsubvv_ref)), 0);
}

// Integer multiply-sub, overwrite minuend
// vnmsub.vx vd, rs1, vs2, vm    # vd[i] = -(x[rs1] * vd[i]) + vs2[i]
uint32_t vnmsubvx_rs1[] = {170};
uint32_t vnmsubvx_vs2[] = {  1, 2, 2, 10, 1000};
const uint32_t vnmsubvx_kAVL = sizeof(vnmsubvx_vs2) / sizeof(vnmsubvx_vs2[0]);
uint32_t vnmsubvx_vd[] = {170, 350, 10, 0, 0};
int32_t vnmsubvx_ref[] = {-28899, -59498, -1698, 10, 1000};
TEST_F(SoftRvvVnmsubTest, VX) {
    softrvv::vnmsub_vx<uint32_t>(vnmsubvx_vd, vnmsubvx_rs1, vnmsubvx_vs2, vnmsubvx_kAVL);
    ASSERT_EQ(memcmp(vnmsubvx_vd, vnmsubvx_ref, sizeof(vnmsubvx_ref)), 0);
}

}  // namespace
}  // namespace softrvv_vmacc_vnmsub_test
