1 /*
2  *  Test program for MIPS64R6 instruction DBITSWAP
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 #include <sys/time.h>
23 #include <stdint.h>
24 
25 #include "../../../../include/wrappers_mips64r6.h"
26 #include "../../../../include/test_inputs_64.h"
27 #include "../../../../include/test_utils_64.h"
28 
29 #define TEST_COUNT_TOTAL (PATTERN_INPUTS_64_COUNT + RANDOM_INPUTS_64_COUNT)
30 
31 
32 int32_t main(void)
33 {
34     char *instruction_name = "DBITSWAP";
35     int32_t ret;
36     uint32_t i;
37     struct timeval start, end;
38     double elapsed_time;
39 
40     uint64_t b64_result[TEST_COUNT_TOTAL];
41     uint64_t b64_expect[TEST_COUNT_TOTAL] = {
42         0xffffffffffffffffULL,                    /*   0  */
43         0x0000000000000000ULL,
44         0x5555555555555555ULL,
45         0xaaaaaaaaaaaaaaaaULL,
46         0x3333333333333333ULL,
47         0xccccccccccccccccULL,
48         0xc7711cc7711cc771ULL,
49         0x388ee3388ee3388eULL,
50         0x0f0f0f0f0f0f0f0fULL,                    /*   8  */
51         0xf0f0f0f0f0f0f0f0ULL,
52         0x1f7cf0c1071f7cf0ULL,
53         0xe0830f3ef8e0830fULL,
54         0x3ff0033ff0033ff0ULL,
55         0xc00ffcc00ffcc00fULL,
56         0x7fc01ff007fc017fULL,
57         0x803fe00ff803fe80ULL,
58         0xff00ff00ff00ff00ULL,                    /*  16  */
59         0x00ff00ff00ff00ffULL,
60         0xff01fc07f01fc07fULL,
61         0x00fe03f80fe03f80ULL,
62         0xff03f03f00ff03f0ULL,
63         0x00fc0fc0ff00fc0fULL,
64         0xff07c0ff01f07f00ULL,
65         0x00f83f00fe0f80ffULL,
66         0xff0f00ff0f00ff0fULL,                    /*  24  */
67         0x00f0ff00f0ff00f0ULL,
68         0xff1f00fc7f00f0ffULL,
69         0x00e0ff0380ff0f00ULL,
70         0xff3f00f0ff0300ffULL,
71         0x00c0ff0f00fcff00ULL,
72         0xff7f00c0ff1f00f0ULL,
73         0x0080ff3f00e0ff0fULL,
74         0xffff0000ffff0000ULL,                    /*  32  */
75         0x0000ffff0000ffffULL,
76         0xffff0100fcff0700ULL,
77         0x0000feff0300f8ffULL,
78         0xffff0300f0ff3f00ULL,
79         0x0000fcff0f00c0ffULL,
80         0xffff0700c0ffff01ULL,
81         0x0000f8ff3f0000feULL,
82         0xffff0f0000ffff0fULL,                    /*  40  */
83         0x0000f0ffff0000f0ULL,
84         0xffff1f0000fcff7fULL,
85         0x0000e0ffff030080ULL,
86         0xffff3f0000f0ffffULL,
87         0x0000c0ffff0f0000ULL,
88         0xffff7f0000c0ffffULL,
89         0x000080ffff3f0000ULL,
90         0xffffff000000ffffULL,                    /*  48  */
91         0x000000ffffff0000ULL,
92         0xffffff010000fcffULL,
93         0x000000feffff0300ULL,
94         0xffffff030000f0ffULL,
95         0x000000fcffff0f00ULL,
96         0xffffff070000c0ffULL,
97         0x000000f8ffff3f00ULL,
98         0xffffff0f000000ffULL,                    /*  56  */
99         0x000000f0ffffff00ULL,
100         0xffffff1f000000fcULL,
101         0x000000e0ffffff03ULL,
102         0xffffff3f000000f0ULL,
103         0x000000c0ffffff0fULL,
104         0xffffff7f000000c0ULL,
105         0x00000080ffffff3fULL,
106         0x115667331446aa02ULL,                    /*  64  */
107         0xdf7d00c6b2c9e310ULL,
108         0x355a75559df3d101ULL,
109         0x0ef268b27a8c4772ULL,
110         0x9d49d63ebef5421aULL,
111         0x0be47d91ff50749fULL,
112         0x1ddc1a60a6533d52ULL,
113         0x3ff1c40f5965ed41ULL,
114         0x047890b36a756792ULL,                    /*  72  */
115         0xa53e9bc8a69ba7ebULL,
116         0x45176faf93d363d8ULL,
117         0x15394f8f8c152675ULL,
118         0x67281c97654a5750ULL,
119         0x2952acbf98c48615ULL,
120         0x620c42c6447def39ULL,
121         0xd15ae5454f9a7bb5ULL,
122     };
123 
124     gettimeofday(&start, NULL);
125 
126     for (i = 0; i < TEST_COUNT_TOTAL; i++) {
127         if (i < PATTERN_INPUTS_64_COUNT) {
128             do_mips64r6_DBITSWAP(b64_pattern + i, b64_result + i);
129         } else {
130             do_mips64r6_DBITSWAP(b64_random + (i - PATTERN_INPUTS_64_COUNT),
131                                  b64_result + i);
132         }
133     }
134 
135     gettimeofday(&end, NULL);
136 
137     elapsed_time = (end.tv_sec - start.tv_sec) * 1000.0;
138     elapsed_time += (end.tv_usec - start.tv_usec) / 1000.0;
139 
140     ret = check_results_64(instruction_name, TEST_COUNT_TOTAL, elapsed_time,
141                            b64_result, b64_expect);
142 
143     return ret;
144 }
145