| #include <springbok.h> |
| #include <stdio.h> |
| #include <stdlib.h> |
| |
| #include "pw_unit_test/framework.h" |
| #include "softrvv.h" |
| |
| namespace softrvv_vmacc_test { |
| namespace { |
| |
| class SoftRvvVmaccTest : public ::testing::Test { |
| protected: |
| void SetUp() override { } |
| }; |
| |
| class SoftRvvVnmsacTest : public ::testing::Test { |
| protected: |
| void SetUp() override { } |
| }; |
| |
| // Integer multiply-add, overwrite addend |
| // vmacc.vv vd, vs1, vs2, vm # vd[i] = +(vs1[i] * vs2[i]) + vd[i] |
| uint32_t vmacvv_vs1[] = {1, 1, 128, 64, 0}; |
| uint32_t vmacvv_vs2[] = {0, 1, 1, 2, 32}; |
| const uint32_t vmacvv_kAVL = sizeof(vmacvv_vs2) / sizeof(vmacvv_vs2[0]); |
| uint32_t vmacvv_vd[] = {0, 1, 2, 4, 8}; |
| int32_t vmacvv_ref[] = {0, 2, 130, 132, 8}; |
| TEST_F(SoftRvvVmaccTest, VV) { |
| softrvv::vmacc_vv<uint32_t>(vmacvv_vd, vmacvv_vs1, vmacvv_vs2, vmacvv_kAVL); |
| ASSERT_EQ(memcmp(vmacvv_vd, vmacvv_ref, sizeof(vmacvv_vd)), 0); |
| } |
| |
| // Integer multiply-add, overwrite addend |
| // vmacc.vx vd, rs1, vs2, vm # vd[i] = +(x[rs1] * src2[i]) + vd[i] |
| uint32_t vmaccvx_rs1[] = {170}; |
| uint32_t vmaccvx_vs2[] = {0, 1, 1, 2, 32}; |
| const uint32_t vmaccvx_kAVL = sizeof(vmaccvx_vs2) / sizeof(vmaccvx_vs2[0]); |
| uint32_t vmaccvx_vd[] = {0, 1, 2, 4, 8}; |
| int32_t vmaccvx_ref[] = {0, 171, 172, 344, 5448}; |
| TEST_F(SoftRvvVmaccTest, VX) { |
| softrvv::vmacc_vx<uint32_t>(vmaccvx_vd, vmaccvx_rs1, vmaccvx_vs2, vmaccvx_kAVL); |
| ASSERT_EQ(memcmp(vmaccvx_vd, vmaccvx_ref, sizeof(vmaccvx_vd)), 0); |
| } |
| |
| // Integer multiply-sub, overwrite minuend |
| // vnmsac.vv vd, vs1, vs2, vm # vd[i] = -(vs1[i] * vs2[i]) + vd[i] |
| uint32_t vnmsacvv_vs1[] = {220, 24, 1234, 150, 1386}; |
| uint32_t vnmsacvv_vs2[] = { 1, 2, 2, 10, 1000}; |
| const uint32_t vnmsacvv_kAVL = sizeof(vnmsacvv_vs2) / sizeof(vnmsacvv_vs2[0]); |
| uint32_t vnmsacvv_vd[] = { 0, 10, 10, 1000, 1}; |
| int32_t vnmsacvv_ref[] = {-220, -38, -2458, -500, -1385999}; |
| TEST_F(SoftRvvVnmsacTest, VV) { |
| softrvv::vnmsac_vv<uint32_t>(vnmsacvv_vd, vnmsacvv_vs1, vnmsacvv_vs2, vnmsacvv_kAVL); |
| ASSERT_EQ(memcmp(vnmsacvv_vd, vnmsacvv_ref, sizeof(vnmsacvv_ref)), 0); |
| } |
| |
| // Integer multiply-sub, overwrite minuend |
| // vnmsac.vx vd, rs1, vs2, vm # vd[i] = -(x[rs1] * vs2[i]) + vd[i] |
| uint32_t vnmsacvx_rs1[] = {170}; |
| uint32_t vnmsacvx_vs2[] = { 1, 2, 2, 10, 1000}; |
| const uint32_t vnmsacvx_kAVL = sizeof(vnmsacvx_vs2) / sizeof(vnmsacvx_vs2[0]); |
| uint32_t vnmsacvx_vd[] = {170, 350, 10, 0, 0}; |
| int32_t vnmsacvx_ref[] = {0, 10, -330, -1700, -170000}; |
| TEST_F(SoftRvvVnmsacTest, VX) { |
| softrvv::vnmsac_vx<uint32_t>(vnmsacvx_vd, vnmsacvx_rs1, vnmsacvx_vs2, vnmsacvx_kAVL); |
| ASSERT_EQ(memcmp(vnmsacvx_vd, vnmsacvx_ref, sizeof(vnmsacvx_ref)), 0); |
| } |
| |
| } // namespace |
| } // namespace softrvv_vmacc_test |