blob: 55b81e5e79ef08ccd424ab9e3e36a4cdb267eaf3 [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 <cstdio>
#include "tests/kelvin_isa/kelvin_test.h"
template <int bits>
void test_acset() {
vconv_u8_t cmd;
cmd.mode = 0;
cmd.start = 0;
cmd.stop = 7;
cmd.sbias1 = 0x56;
cmd.sdata1 = false;
cmd.sbias2 = 0xbc;
cmd.sdata2 = true;
uint32_t cmdw;
memcpy(&cmdw, &cmd, 4);
// clang-format off
const uint8_t ina[8][bits/8] = {
{ 0xea, 0xe6, 0xaa, 0xb0, 0x5e, 0x46, 0x43, 0x2c,
0x58, 0x69, 0xd4, 0x25, 0xf0, 0xe9, 0x74, 0xd5,
0x34, 0x16, 0x4c, 0x86, 0xa8, 0x0c, 0xac, 0xa8,
0x9f, 0x99, 0x5d, 0xe0, 0x1a, 0x93, 0x65, 0x88, },
{ 0x4a, 0x3a, 0x57, 0x8b, 0x50, 0x6c, 0x1b, 0x37,
0x76, 0x8c, 0x72, 0x55, 0xb3, 0xce, 0xf3, 0x50,
0x74, 0x51, 0xb2, 0xb9, 0xb9, 0x76, 0xc4, 0x94,
0x29, 0x52, 0x16, 0xa8, 0x68, 0xa7, 0x8e, 0xe2, },
{ 0x61, 0xe8, 0xb8, 0xae, 0x43, 0x0a, 0xbe, 0xfa,
0x0b, 0x32, 0x7a, 0x92, 0x44, 0x3a, 0x60, 0xd3,
0x11, 0xc0, 0xb3, 0x8c, 0x7e, 0x5b, 0x9c, 0xe9,
0x03, 0x94, 0x7f, 0x10, 0x38, 0xd5, 0xc6, 0xeb, },
{ 0x5c, 0x79, 0x44, 0xe9, 0xfb, 0x32, 0x00, 0xf0,
0x79, 0xed, 0x92, 0x77, 0x93, 0x45, 0xc3, 0x63,
0x33, 0x7e, 0x07, 0xc5, 0x07, 0x76, 0x9d, 0xf0,
0x4e, 0x6a, 0x67, 0xcc, 0xca, 0xab, 0xd4, 0x24, },
{ 0x82, 0x86, 0xbb, 0xd9, 0x4b, 0xda, 0x2e, 0xbb,
0x8d, 0xbb, 0x82, 0x0e, 0x53, 0xaa, 0xb8, 0xfa,
0xa1, 0x75, 0x6e, 0x4a, 0x3c, 0xba, 0xa1, 0x88,
0x88, 0x6c, 0x74, 0x5b, 0x09, 0x83, 0x98, 0xdc, },
{ 0x91, 0x9a, 0x9f, 0xcd, 0x87, 0xd7, 0x74, 0x90,
0xa5, 0x25, 0xcf, 0x56, 0x5d, 0x41, 0x56, 0xc2,
0x0d, 0xdd, 0xd8, 0x2c, 0x59, 0x1d, 0x1c, 0x66,
0x06, 0xe9, 0xd3, 0x51, 0x83, 0x16, 0x65, 0x56, },
{ 0xf6, 0x95, 0x7c, 0x47, 0xf5, 0x56, 0x53, 0x58,
0x87, 0x9c, 0xde, 0xac, 0x76, 0x78, 0x71, 0x86,
0x5c, 0xdb, 0x5f, 0x0d, 0xc4, 0x5f, 0x48, 0x61,
0x48, 0x6f, 0x77, 0x26, 0x68, 0xf1, 0x39, 0x58, },
{ 0x32, 0x36, 0x68, 0x29, 0x67, 0xb8, 0x7c, 0xdd,
0xb9, 0x17, 0xb0, 0xec, 0x2e, 0xcc, 0xa5, 0x54,
0x76, 0x56, 0xc8, 0x0b, 0x77, 0xa1, 0xef, 0xf5,
0xcf, 0xd6, 0x84, 0x7a, 0x84, 0x0f, 0x4e, 0x16, },
};
const uint8_t inb[8][bits/8] = {
{ 0x33, 0xc9, 0xb8, 0xa1, 0xea, 0x2d, 0x2c, 0x18,
0x92, 0x98, 0x8e, 0x19, 0xf2, 0xd8, 0x55, 0x92,
0x26, 0x4a, 0x8d, 0x3e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x10, 0x57, 0x7d,
0x14, 0xec, 0x5f, 0x39, 0xa3, 0x0e, 0x92, 0x62,
0x86, 0xad, 0xae, 0x38, 0x95, 0x7f, 0xde, 0x30,
0x9d, 0xbf, 0xe5, 0xb2, 0xb3, 0xb6, 0xf1, 0x42, },
{ 0x0c, 0xd7, 0xd4, 0xa8, 0xae, 0x1a, 0xe6, 0x3c,
0xf0, 0xd7, 0x4f, 0x36, 0x37, 0xeb, 0x1d, 0xe9,
0xc7, 0xe4, 0x82, 0xe4, 0x44, 0x1c, 0x6a, 0xa1,
0x96, 0xfe, 0x2e, 0x9d, 0x36, 0xb4, 0x1c, 0x03, },
};
// clang-format on
uint32_t ref[bits / 32][bits / 32];
uint32_t dut[bits / 32][bits / 32];
vld_b_x(v0, ina[0]);
vld_b_x(v1, ina[1]);
vld_b_x(v2, ina[2]);
vld_b_x(v3, ina[3]);
vld_b_x(v4, ina[4]);
vld_b_x(v5, ina[5]);
vld_b_x(v6, ina[6]);
vld_b_x(v7, ina[7]);
vld_b_x(v16, inb[0]);
vld_b_x(v17, inb[1]);
vld_b_x(v18, inb[2]);
vld_b_x(v19, inb[3]);
vld_b_x(v20, inb[4]);
vld_b_x(v21, inb[5]);
vld_b_x(v22, inb[6]);
vld_b_x(v23, inb[7]);
// REF.
aconv_vxv(v48, v0, cmdw, v16);
aconv_vxv(v48, v16, cmdw, v0);
vcget(v48);
vst_w_x(v48, ref[0]);
vst_w_x(v49, ref[1]);
vst_w_x(v50, ref[2]);
vst_w_x(v51, ref[3]);
vst_w_x(v52, ref[4]);
vst_w_x(v53, ref[5]);
vst_w_x(v54, ref[6]);
vst_w_x(v55, ref[7]);
// DUT.
aconv_vxv(v48, v0, cmdw, v16);
vcget(v48);
acset_v(v48, v48);
aconv_vxv(v48, v16, cmdw, v0);
vcget(v48);
vst_w_x(v48, dut[0]);
vst_w_x(v49, dut[1]);
vst_w_x(v50, dut[2]);
vst_w_x(v51, dut[3]);
vst_w_x(v52, dut[4]);
vst_w_x(v53, dut[5]);
vst_w_x(v54, dut[6]);
vst_w_x(v55, dut[7]);
// Check the results.
for (int i = 0; i < 8; ++i) {
for (int j = 0; j < 8; ++j) {
const uint32_t r = ref[i][j];
const uint32_t d = dut[i][j];
if (r != d) {
printf("**error::test_acset[%d,%d] %08lx %08lx\n", i, j, r, d);
exit(-1);
}
}
}
}
int main() {
test_acset<VLEN>();
return 0;
}