1 /* 2 * Copyright(c) 2022-2023 Qualcomm Innovation Center, Inc. All Rights Reserved. 3 * 4 * This program is free software; you can redistribute it and/or modify 5 * it under the terms of the GNU General Public License as published by 6 * the Free Software Foundation; either version 2 of the License, or 7 * (at your option) any later version. 8 * 9 * This program is distributed in the hope that it will be useful, 10 * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 * GNU General Public License for more details. 13 * 14 * You should have received a copy of the GNU General Public License 15 * along with this program; if not, see <http://www.gnu.org/licenses/>. 16 */ 17 18 #include <stdio.h> 19 #include <stdint.h> 20 #include <stdbool.h> 21 #include <string.h> 22 #include <limits.h> 23 24 int err; 25 26 #include "hvx_misc.h" 27 28 MMVector v6mpy_buffer0[BUFSIZE] __attribute__((aligned(MAX_VEC_SIZE_BYTES))); 29 MMVector v6mpy_buffer1[BUFSIZE] __attribute__((aligned(MAX_VEC_SIZE_BYTES))); 30 31 static void init_v6mpy_buffers(void) 32 { 33 int counter0 = 0; 34 int counter1 = 17; 35 for (int i = 0; i < BUFSIZE; i++) { 36 for (int j = 0; j < MAX_VEC_SIZE_BYTES / 4; j++) { 37 v6mpy_buffer0[i].w[j] = counter0++; 38 v6mpy_buffer1[i].w[j] = counter1++; 39 } 40 } 41 } 42 43 int v6mpy_ref[BUFSIZE][MAX_VEC_SIZE_BYTES / 4] = { 44 #include "v6mpy_ref.c.inc" 45 }; 46 47 static void test_v6mpy(void) 48 { 49 void *p00 = buffer0; 50 void *p01 = v6mpy_buffer0; 51 void *p10 = buffer1; 52 void *p11 = v6mpy_buffer1; 53 void *pout = output; 54 55 memset(expect, 0xff, sizeof(expect)); 56 memset(output, 0xff, sizeof(expect)); 57 58 for (int i = 0; i < BUFSIZE; i++) { 59 asm("v2 = vmem(%0 + #0)\n\t" 60 "v3 = vmem(%1 + #0)\n\t" 61 "v4 = vmem(%2 + #0)\n\t" 62 "v5 = vmem(%3 + #0)\n\t" 63 "v5:4.w = v6mpy(v5:4.ub, v3:2.b, #1):v\n\t" 64 "vmem(%4 + #0) = v4\n\t" 65 : : "r"(p00), "r"(p01), "r"(p10), "r"(p11), "r"(pout) 66 : "v2", "v3", "v4", "v5", "memory"); 67 p00 += sizeof(MMVector); 68 p01 += sizeof(MMVector); 69 p10 += sizeof(MMVector); 70 p11 += sizeof(MMVector); 71 pout += sizeof(MMVector); 72 73 for (int j = 0; j < MAX_VEC_SIZE_BYTES / 4; j++) { 74 expect[i].w[j] = v6mpy_ref[i][j]; 75 } 76 } 77 78 check_output_w(__LINE__, BUFSIZE); 79 } 80 81 int main() 82 { 83 init_buffers(); 84 init_v6mpy_buffers(); 85 86 test_v6mpy(); 87 88 puts(err ? "FAIL" : "PASS"); 89 return err ? 1 : 0; 90 } 91