| /* |
| * 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 "crt/printf_traits.h" |
| #include "tests/kelvin_isa/kelvin_test.h" |
| |
| #define vevn_vv(T, Vd, Vs, Vt) \ |
| { \ |
| if (sizeof(T) == 1) { \ |
| vevn_b_vv(Vd, Vs, Vt); \ |
| } \ |
| if (sizeof(T) == 2) { \ |
| vevn_h_vv(Vd, Vs, Vt); \ |
| } \ |
| if (sizeof(T) == 4) { \ |
| vevn_w_vv(Vd, Vs, Vt); \ |
| } \ |
| } |
| |
| #define vevn_vv_m(T, Vd, Vs, Vt) \ |
| { \ |
| if (sizeof(T) == 1) { \ |
| vevn_b_vv_m(Vd, Vs, Vt); \ |
| } \ |
| if (sizeof(T) == 2) { \ |
| vevn_h_vv_m(Vd, Vs, Vt); \ |
| } \ |
| if (sizeof(T) == 4) { \ |
| vevn_w_vv_m(Vd, Vs, Vt); \ |
| } \ |
| } |
| |
| #define vodd_vv(T, Vd, Vs, Vt) \ |
| { \ |
| if (sizeof(T) == 1) { \ |
| vodd_b_vv(Vd, Vs, Vt); \ |
| } \ |
| if (sizeof(T) == 2) { \ |
| vodd_h_vv(Vd, Vs, Vt); \ |
| } \ |
| if (sizeof(T) == 4) { \ |
| vodd_w_vv(Vd, Vs, Vt); \ |
| } \ |
| } |
| |
| #define vodd_vv_m(T, Vd, Vs, Vt) \ |
| { \ |
| if (sizeof(T) == 1) { \ |
| vodd_b_vv_m(Vd, Vs, Vt); \ |
| } \ |
| if (sizeof(T) == 2) { \ |
| vodd_h_vv_m(Vd, Vs, Vt); \ |
| } \ |
| if (sizeof(T) == 4) { \ |
| vodd_w_vv_m(Vd, Vs, Vt); \ |
| } \ |
| } |
| |
| #define vevnodd_vv(T, Vd, Vs, Vt) \ |
| { \ |
| if (sizeof(T) == 1) { \ |
| vevnodd_b_vv(Vd, Vs, Vt); \ |
| } \ |
| if (sizeof(T) == 2) { \ |
| vevnodd_h_vv(Vd, Vs, Vt); \ |
| } \ |
| if (sizeof(T) == 4) { \ |
| vevnodd_w_vv(Vd, Vs, Vt); \ |
| } \ |
| } |
| |
| #define vevnodd_vv_m(T, Vd, Vs, Vt) \ |
| { \ |
| if (sizeof(T) == 1) { \ |
| vevnodd_b_vv_m(Vd, Vs, Vt); \ |
| } \ |
| if (sizeof(T) == 2) { \ |
| vevnodd_h_vv_m(Vd, Vs, Vt); \ |
| } \ |
| if (sizeof(T) == 4) { \ |
| vevnodd_w_vv_m(Vd, Vs, Vt); \ |
| } \ |
| } |
| |
| template <typename T> |
| static void test_vevnodd() { |
| constexpr int n = sizeof(T); |
| int lanes; |
| getmaxvl(T, lanes); |
| |
| T inp[2][lanes] __attribute__((aligned(64))); |
| T ref[2][lanes] __attribute__((aligned(64))); |
| T dut[2][lanes] __attribute__((aligned(64))); |
| |
| for (int i = 0; i < lanes; ++i) { |
| inp[0][i] = (0x40 << (8 * (n - 1))) + i; |
| inp[1][i] = (0x80 << (8 * (n - 1))) + i; |
| } |
| |
| for (int i = 0; i < lanes; ++i) { |
| int m = lanes / 2; |
| ref[0][i] = i < m ? inp[0][2 * i + 0] : inp[1][2 * (i - m) + 0]; |
| ref[1][i] = i < m ? inp[0][2 * i + 1] : inp[1][2 * (i - m) + 1]; |
| } |
| |
| vld_x(T, v2, inp[0]); |
| vld_x(T, v7, inp[1]); |
| vevnodd_vv(T, v0, v2, v7); |
| vst_x(T, v0, dut[0]); |
| vst_x(T, v1, dut[1]); |
| |
| for (int j = 0; j < 2; ++j) { |
| for (int i = 0; i < lanes; ++i) { |
| if (ref[j][i] != dut[j][i]) { |
| printf("**error vevnodd_vv[%d,%d] ", j, i); |
| printf(PrintfTraits<T>::kFmtHex, ref[j][i]); |
| printf(" "); |
| printf(PrintfTraits<T>::kFmtHex, dut[j][i]); |
| printf("\n"); |
| exit(-1); |
| } |
| } |
| } |
| } |
| |
| template <typename T> |
| static void test_vevnodd_m() { |
| constexpr int n = sizeof(T); |
| int lanes; |
| getmaxvl_m(T, lanes); |
| |
| T inp[2][lanes] __attribute__((aligned(64))); |
| T ref[2][lanes] __attribute__((aligned(64))); |
| T dut[2][lanes] __attribute__((aligned(64))); |
| |
| for (int i = 0; i < lanes; ++i) { |
| inp[0][i] = (0x40 << (8 * (n - 1))) + i; |
| inp[1][i] = (0x80 << (8 * (n - 1))) + i; |
| } |
| |
| for (int i = 0; i < lanes; ++i) { |
| int m = lanes / 2; |
| ref[0][i] = i < m ? inp[0][2 * i + 0] : inp[1][2 * (i - m) + 0]; |
| ref[1][i] = i < m ? inp[0][2 * i + 1] : inp[1][2 * (i - m) + 1]; |
| } |
| |
| vld_x_m(T, v8, inp[0]); |
| vld_x_m(T, v24, inp[1]); |
| vevnodd_vv_m(T, v0, v8, v24); |
| vst_x_m(T, v0, dut[0]); |
| vst_x_m(T, v4, dut[1]); |
| |
| for (int j = 0; j < 2; ++j) { |
| for (int i = 0; i < lanes; ++i) { |
| if (ref[j][i] != dut[j][i]) { |
| printf("**error vevnodd_vv_m[%d,%d] ", j, i); |
| printf(PrintfTraits<T>::kFmtHex, ref[j][i]); |
| printf(" "); |
| printf(PrintfTraits<T>::kFmtHex, dut[j][i]); |
| printf("\n"); |
| exit(-1); |
| } |
| } |
| } |
| } |
| |
| template <typename T> |
| static void test_vevn() { |
| constexpr int n = sizeof(T); |
| int lanes; |
| getmaxvl(T, lanes); |
| |
| T inp[2][lanes] __attribute__((aligned(64))); |
| T ref[lanes] __attribute__((aligned(64))); |
| T dut[lanes] __attribute__((aligned(64))); |
| |
| for (int i = 0; i < lanes; ++i) { |
| inp[0][i] = (0x40 << (8 * (n - 1))) + i; |
| inp[1][i] = (0x80 << (8 * (n - 1))) + i; |
| } |
| |
| for (int i = 0; i < lanes; ++i) { |
| int m = lanes / 2; |
| ref[i] = i < m ? inp[0][2 * i + 0] : inp[1][2 * (i - m) + 0]; |
| } |
| |
| vld_x(T, v2, inp[0]); |
| vld_x(T, v7, inp[1]); |
| vevn_vv(T, v0, v2, v7); |
| vst_x(T, v0, dut); |
| |
| for (int i = 0; i < lanes; ++i) { |
| if (ref[i] != dut[i]) { |
| printf("**error vevn_vv[%d] ", i); |
| printf(PrintfTraits<T>::kFmtHex, ref[i]); |
| printf(" "); |
| printf(PrintfTraits<T>::kFmtHex, dut[i]); |
| printf("\n"); |
| exit(-1); |
| } |
| } |
| } |
| |
| template <typename T> |
| static void test_vevn_m() { |
| constexpr int n = sizeof(T); |
| int lanes; |
| getmaxvl_m(T, lanes); |
| |
| T inp[2][lanes] __attribute__((aligned(64))); |
| T ref[lanes] __attribute__((aligned(64))); |
| T dut[lanes] __attribute__((aligned(64))); |
| |
| for (int i = 0; i < lanes; ++i) { |
| inp[0][i] = (0x40 << (8 * (n - 1))) + i; |
| inp[1][i] = (0x80 << (8 * (n - 1))) + i; |
| } |
| |
| for (int i = 0; i < lanes; ++i) { |
| int m = lanes / 2; |
| ref[i] = i < m ? inp[0][2 * i + 0] : inp[1][2 * (i - m) + 0]; |
| } |
| |
| vld_x_m(T, v4, inp[0]); |
| vld_x_m(T, v24, inp[1]); |
| vevn_vv_m(T, v0, v4, v24); |
| vst_x_m(T, v0, dut); |
| |
| for (int i = 0; i < lanes; ++i) { |
| if (ref[i] != dut[i]) { |
| printf("**error vevn_vv_m[%d] ", i); |
| printf(PrintfTraits<T>::kFmtHex, ref[i]); |
| printf(" "); |
| printf(PrintfTraits<T>::kFmtHex, dut[i]); |
| printf("\n"); |
| exit(-1); |
| } |
| } |
| } |
| |
| template <typename T> |
| static void test_vodd() { |
| constexpr int n = sizeof(T); |
| int lanes; |
| getmaxvl(T, lanes); |
| |
| T inp[2][lanes] __attribute__((aligned(64))); |
| T ref[lanes] __attribute__((aligned(64))); |
| T dut[lanes] __attribute__((aligned(64))); |
| |
| for (int i = 0; i < lanes; ++i) { |
| inp[0][i] = (0x40 << (8 * (n - 1))) + i; |
| inp[1][i] = (0x80 << (8 * (n - 1))) + i; |
| } |
| |
| for (int i = 0; i < lanes; ++i) { |
| int m = lanes / 2; |
| ref[i] = i < m ? inp[0][2 * i + 1] : inp[1][2 * (i - m) + 1]; |
| } |
| |
| vld_x(T, v2, inp[0]); |
| vld_x(T, v7, inp[1]); |
| vodd_vv(T, v0, v2, v7); |
| vst_x(T, v0, dut); |
| |
| for (int i = 0; i < lanes; ++i) { |
| if (ref[i] != dut[i]) { |
| printf("**error vodd_vv[%d] ", i); |
| printf(PrintfTraits<T>::kFmtHex, ref[i]); |
| printf(" "); |
| printf(PrintfTraits<T>::kFmtHex, dut[i]); |
| printf("\n"); |
| exit(-1); |
| } |
| } |
| } |
| |
| template <typename T> |
| static void test_vodd_m() { |
| constexpr int n = sizeof(T); |
| int lanes; |
| getmaxvl_m(T, lanes); |
| |
| T inp[2][lanes] __attribute__((aligned(64))); |
| T ref[lanes] __attribute__((aligned(64))); |
| T dut[lanes] __attribute__((aligned(64))); |
| |
| for (int i = 0; i < lanes; ++i) { |
| inp[0][i] = (0x40 << (8 * (n - 1))) + i; |
| inp[1][i] = (0x80 << (8 * (n - 1))) + i; |
| } |
| |
| for (int i = 0; i < lanes; ++i) { |
| int m = lanes / 2; |
| ref[i] = i < m ? inp[0][2 * i + 1] : inp[1][2 * (i - m) + 1]; |
| } |
| |
| // TODO(b/307456144): Re-enable {v4, v24} as the inputs. |
| vld_x_m(T, v12, inp[0]); |
| vld_x_m(T, v24, inp[1]); |
| vodd_vv_m(T, v0, v12, v24); |
| vst_x_m(T, v0, dut); |
| |
| for (int i = 0; i < lanes; ++i) { |
| if (ref[i] != dut[i]) { |
| printf("**error vodd_vv_m[%d] ", i); |
| printf(PrintfTraits<T>::kFmtHex, ref[i]); |
| printf(" "); |
| printf(PrintfTraits<T>::kFmtHex, dut[i]); |
| printf("\n"); |
| exit(-1); |
| } |
| } |
| } |
| |
| int main() { |
| test_vevnodd<int8_t>(); |
| test_vevnodd<int16_t>(); |
| test_vevnodd<int32_t>(); |
| |
| test_vevnodd_m<int8_t>(); |
| test_vevnodd_m<int16_t>(); |
| test_vevnodd_m<int32_t>(); |
| |
| test_vevn<int8_t>(); |
| test_vevn<int16_t>(); |
| test_vevn<int32_t>(); |
| |
| test_vevn_m<int8_t>(); |
| test_vevn_m<int16_t>(); |
| test_vevn_m<int32_t>(); |
| |
| test_vodd<int8_t>(); |
| test_vodd<int16_t>(); |
| test_vodd<int32_t>(); |
| |
| test_vodd_m<int8_t>(); |
| test_vodd_m<int16_t>(); |
| test_vodd_m<int32_t>(); |
| |
| return 0; |
| } |