Cindy Liu | 2fe3247 | 2023-10-24 11:28:47 -0700 | [diff] [blame] | 1 | /* |
| 2 | * Copyright 2023 Google LLC |
| 3 | * |
| 4 | * Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | * you may not use this file except in compliance with the License. |
| 6 | * You may obtain a copy of the License at |
| 7 | * |
| 8 | * http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | * |
| 10 | * Unless required by applicable law or agreed to in writing, software |
| 11 | * distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | * See the License for the specific language governing permissions and |
| 14 | * limitations under the License. |
| 15 | */ |
| 16 | |
| 17 | #include <cstdio> |
| 18 | |
| 19 | #include "tests/kelvin_isa/kelvin_test.h" |
| 20 | |
| 21 | template <int ireg> |
| 22 | void test_256_actr() { |
| 23 | uint32_t inp[8][8] __attribute__((aligned(64))); |
| 24 | uint32_t ref[8][8] __attribute__((aligned(64))); |
| 25 | uint32_t dut[8][8] __attribute__((aligned(64))); |
| 26 | |
| 27 | int value = 0; |
| 28 | for (int j = 0; j < 8; ++j) { |
| 29 | for (int i = 0; i < 8; ++i) { |
| 30 | inp[j][i] = (krand() << 8) | value++; |
| 31 | } |
| 32 | } |
| 33 | |
| 34 | for (int j = 0; j < 8; ++j) { |
| 35 | for (int i = 0; i < 8; ++i) { |
| 36 | ref[i][j] = inp[j][i]; |
| 37 | } |
| 38 | } |
| 39 | |
| 40 | if (ireg == 0) { |
| 41 | vld_w_x(v0, inp[0]); |
| 42 | vld_w_x(v1, inp[1]); |
| 43 | vld_w_x(v2, inp[2]); |
| 44 | vld_w_x(v3, inp[3]); |
| 45 | vld_w_x(v4, inp[4]); |
| 46 | vld_w_x(v5, inp[5]); |
| 47 | vld_w_x(v6, inp[6]); |
| 48 | vld_w_x(v7, inp[7]); |
| 49 | } |
| 50 | if (ireg == 16) { |
| 51 | vld_w_x(v16, inp[0]); |
| 52 | vld_w_x(v17, inp[1]); |
| 53 | vld_w_x(v18, inp[2]); |
| 54 | vld_w_x(v19, inp[3]); |
| 55 | vld_w_x(v20, inp[4]); |
| 56 | vld_w_x(v21, inp[5]); |
| 57 | vld_w_x(v22, inp[6]); |
| 58 | vld_w_x(v23, inp[7]); |
| 59 | } |
| 60 | if (ireg == 32) { |
| 61 | vld_w_x(v32, inp[0]); |
| 62 | vld_w_x(v33, inp[1]); |
| 63 | vld_w_x(v34, inp[2]); |
| 64 | vld_w_x(v35, inp[3]); |
| 65 | vld_w_x(v36, inp[4]); |
| 66 | vld_w_x(v37, inp[5]); |
| 67 | vld_w_x(v38, inp[6]); |
| 68 | vld_w_x(v39, inp[7]); |
| 69 | } |
| 70 | if (ireg == 48) { |
| 71 | vld_w_x(v48, inp[0]); |
| 72 | vld_w_x(v49, inp[1]); |
| 73 | vld_w_x(v50, inp[2]); |
| 74 | vld_w_x(v51, inp[3]); |
| 75 | vld_w_x(v52, inp[4]); |
| 76 | vld_w_x(v53, inp[5]); |
| 77 | vld_w_x(v54, inp[6]); |
| 78 | vld_w_x(v55, inp[7]); |
| 79 | } |
| 80 | |
| 81 | if (ireg == 0) { |
| 82 | actr_v(v48, v0); |
| 83 | } |
| 84 | if (ireg == 16) { |
| 85 | actr_v(v48, v16); |
| 86 | } |
| 87 | if (ireg == 32) { |
| 88 | actr_v(v48, v32); |
| 89 | } |
| 90 | if (ireg == 48) { |
| 91 | actr_v(v48, v48); |
| 92 | } |
| 93 | vcget(v48); |
| 94 | |
| 95 | vst_w_x_m(v48, dut[0]); |
| 96 | vst_w_x_m(v52, dut[4]); |
| 97 | |
| 98 | for (int j = 0; j < 8; ++j) { |
| 99 | for (int i = 0; i < 8; ++i) { |
| 100 | if (ref[j][i] != dut[j][i]) { |
| 101 | printf("**error actr_v[%d][%d,%d] %08lx %08lx\n", ireg, j, i, ref[j][i], |
| 102 | dut[j][i]); |
| 103 | exit(-1); |
| 104 | } |
| 105 | } |
| 106 | } |
| 107 | } |
| 108 | int main() { |
| 109 | test_256_actr<0>(); |
| 110 | test_256_actr<16>(); |
| 111 | test_256_actr<32>(); |
| 112 | test_256_actr<48>(); |
| 113 | |
| 114 | return 0; |
| 115 | } |