1 /*
2  *  Header file for test utilities
3  *
4  *  Copyright (C) 2019  Wave Computing, Inc.
5  *  Copyright (C) 2019  Aleksandar Markovic <amarkovic@wavecomp.com>
6  *
7  *  This program is free software: you can redistribute it and/or modify
8  *  it under the terms of the GNU General Public License as published by
9  *  the Free Software Foundation, either version 2 of the License, or
10  *  (at your option) any later version.
11  *
12  *  This program is distributed in the hope that it will be useful,
13  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
14  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15  *  GNU General Public License for more details.
16  *
17  *  You should have received a copy of the GNU General Public License
18  *  along with this program.  If not, see <https://www.gnu.org/licenses/>.
19  *
20  */
21 
22 #ifndef TEST_UTILS_64_H
23 #define TEST_UTILS_64_H
24 
25 #include <stdio.h>
26 #include <stdint.h>
27 #include <inttypes.h>
28 #include <string.h>
29 
30 #define PRINT_RESULTS 0
31 
32 
33 static inline int32_t check_results_64(const char *isa_ase_name,
34                                        const char *group_name,
35                                        const char *instruction_name,
36                                        const uint32_t test_count,
37                                        const double elapsed_time,
38                                        const uint64_t *b64_result,
39                                        const uint64_t *b64_expect)
40 {
41 #if PRINT_RESULTS
42     uint32_t ii;
43     printf("\n");
44     for (ii = 0; ii < test_count; ii++) {
45         uint64_t a;
46         memcpy(&a, (b64_result + ii), 8);
47         if (ii % 8 != 0) {
48             printf("        0x%016llxULL,\n", a);
49         } else {
50             printf("        0x%016llxULL,                    /* %3d  */\n",
51                    a, ii);
52         }
53     }
54     printf("\n");
55 #endif
56     uint32_t i;
57     uint32_t pass_count = 0;
58     uint32_t fail_count = 0;
59 
60     printf("| %-10s \t| %-20s\t| %-16s \t|",
61            isa_ase_name, group_name, instruction_name);
62     for (i = 0; i < test_count; i++) {
63         if (b64_result[i] == b64_expect[i]) {
64             pass_count++;
65         } else {
66             fail_count++;
67         }
68     }
69 
70     printf(" PASS: %3d \t| FAIL: %3d \t| elapsed time: %5.2f ms \t|\n",
71            pass_count, fail_count, elapsed_time);
72 
73     if (fail_count > 0) {
74         return -1;
75     } else {
76         return 0;
77     }
78 }
79 
80 
81 #endif
82