Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
PojavLauncherTeam
GitHub Repository: PojavLauncherTeam/mesa
Path: blob/21.2-virgl/src/panfrost/bifrost/bi_test_pack.c
4564 views
1
/*
2
* Copyright (C) 2020 Collabora, Ltd.
3
*
4
* Permission is hereby granted, free of charge, to any person obtaining a
5
* copy of this software and associated documentation files (the "Software"),
6
* to deal in the Software without restriction, including without limitation
7
* the rights to use, copy, modify, merge, publish, distribute, sublicense,
8
* and/or sell copies of the Software, and to permit persons to whom the
9
* Software is furnished to do so, subject to the following conditions:
10
*
11
* The above copyright notice and this permission notice (including the next
12
* paragraph) shall be included in all copies or substantial portions of the
13
* Software.
14
*
15
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
18
* THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
* SOFTWARE.
22
*/
23
24
#include "compiler.h"
25
26
#ifdef NDEBUG
27
28
int
29
bi_test_packing_formats(void)
30
{
31
/* stub */
32
return 0;
33
}
34
35
#else
36
37
static void
38
bi_test_pack_format_1(void)
39
{
40
/* Test case from the blob */
41
struct bi_packed_tuple tuples[] = {
42
{ 0x2380cb1c02200000, 0x10e0 },
43
};
44
45
uint64_t header = 0x021000011800;
46
47
struct util_dynarray result;
48
util_dynarray_init(&result, NULL);
49
50
bi_pack_format(&result, 1, tuples, 1, header, 0, 0, true);
51
uint64_t *result_u64 = (uint64_t *) result.data;
52
53
assert(result.size == 16);
54
assert(result_u64[0] == 0x80cb1c022000004a);
55
assert(result_u64[1] == 0x10800008c000e023);
56
}
57
58
static void
59
bi_test_pack_format_2(void)
60
{
61
struct bi_packed_tuple tuples[] = {
62
{ 0x9380cb6044000044, 0xf65 },
63
{ 0xaf8721a05c000081, 0x1831 },
64
};
65
66
struct util_dynarray result;
67
util_dynarray_init(&result, NULL);
68
69
bi_pack_format(&result, 0, tuples, 2, 0x52800011800, 0, 0, false);
70
bi_pack_format(&result, 2, tuples, 2, 0x52800011800, 0, 0, false);
71
uint64_t *result_u64 = (uint64_t *) result.data;
72
73
assert(result.size == 32);
74
assert(result_u64[0] == 0x80cb604400004429);
75
assert(result_u64[1] == 0x29400008c0076593);
76
assert(result_u64[2] == 0x8721a05c00008103);
77
assert(result_u64[3] == 0x60000000000031af);
78
}
79
80
static void
81
bi_test_pack_format_3(void)
82
{
83
struct bi_packed_tuple tuples[] = {
84
{ 0x93805b8040000000, 0xf65 },
85
{ 0x93886db05c000000, 0xf65 },
86
{ 0xb380cb180c000080, 0x18b1 },
87
};
88
89
struct util_dynarray result;
90
util_dynarray_init(&result, NULL);
91
92
bi_pack_format(&result, 0, tuples, 3, 0x3100000000, 0, 0, true);
93
bi_pack_format(&result, 3, tuples, 3, 0x3100000000, 0, 0, true);
94
bi_pack_format(&result, 4, tuples, 3, 0x3100000000, 0, 0, true);
95
uint64_t *result_u64 = (uint64_t *) result.data;
96
97
assert(result.size == 48);
98
assert(result_u64[0] == 0x805b804000000029);
99
assert(result_u64[1] == 0x188000000076593);
100
assert(result_u64[2] == 0x886db05c00000021);
101
assert(result_u64[3] == 0x58c0600004076593);
102
assert(result_u64[4] == 0x44);
103
assert(result_u64[5] == 0x60002c6ce0300000);
104
}
105
106
static void
107
bi_test_pack_format_4(void)
108
{
109
struct bi_packed_tuple tuples[] = {
110
{ 0xad8c87004000005f, 0x2f18 },
111
{ 0xad8c87385c00004f, 0x2f18 },
112
{ 0xad8c87385c00006e, 0x2f18 },
113
{ 0xb380cb182c000080, 0x18b1 },
114
};
115
116
struct util_dynarray result;
117
util_dynarray_init(&result, NULL);
118
119
uint64_t EC0 = (0x10000001ff000000) >> 4;
120
121
bi_pack_format(&result, 0, tuples, 4, 0x3100000000, EC0, 0, false);
122
bi_pack_format(&result, 3, tuples, 4, 0x3100000000, EC0, 0, false);
123
bi_pack_format(&result, 6, tuples, 4, 0x3100000000, EC0, 0, false);
124
uint64_t *result_u64 = (uint64_t *) result.data;
125
126
assert(result.size == 48);
127
assert(result_u64[0] == 0x8c87004000005f2d);
128
assert(result_u64[1] == 0x1880000000718ad);
129
assert(result_u64[2] == 0x8c87385c00004f25);
130
assert(result_u64[3] == 0x39c2e000037718ad);
131
assert(result_u64[4] == 0x80cb182c00008005);
132
assert(result_u64[5] == 0xac01c62b6320b1b3);
133
}
134
135
static void
136
bi_test_pack_format_5(void)
137
{
138
struct bi_packed_tuple tuples[] = {
139
{ 0x9380688040000000, 0xf65 },
140
{ 0xd4057300c000040, 0xf26 },
141
{ 0x1f80cb1858000000, 0x19ab },
142
{ 0x937401f85c000000, 0xf65 },
143
{ 0xb380cb180c000080, 0x18a1 },
144
};
145
146
struct util_dynarray result;
147
util_dynarray_init(&result, NULL);
148
149
uint64_t EC0 = (0x183f800000) >> 4;
150
151
bi_pack_format(&result, 0, tuples, 5, 0x3100000000, EC0, 0, true);
152
bi_pack_format(&result, 3, tuples, 5, 0x3100000000, EC0, 0, true);
153
bi_pack_format(&result, 7, tuples, 5, 0x3100000000, EC0, 0, true);
154
bi_pack_format(&result, 8, tuples, 5, 0x3100000000, EC0, 0, true);
155
uint64_t *result_u64 = (uint64_t *) result.data;
156
157
assert(result.size == 64);
158
assert(result_u64[0] == 0x8068804000000029);
159
assert(result_u64[1] == 0x188000000076593);
160
assert(result_u64[2] == 0x4057300c00004021);
161
assert(result_u64[3] == 0x58c2c0000007260d);
162
assert(result_u64[4] == 0x7401f85c0000008b);
163
assert(result_u64[5] == 0x6ac7e0376593);
164
assert(result_u64[6] == 0x80cb180c00008053);
165
assert(result_u64[7] == 0x183f80a1b3);
166
}
167
168
static void
169
bi_test_pack_format_6(void)
170
{
171
struct bi_packed_tuple tuples[] = {
172
{ 0xad8c870068000048, 0x2f18 },
173
{ 0xad8c87385c000050, 0x2f18 },
174
{ 0xad8c87385c00006a, 0x2f18 },
175
{ 0xad8c87385c000074, 0x2f18 },
176
{ 0xad8c87385c000020, 0x2f18 },
177
{ 0xad8c87385c000030, 0x2f18 },
178
};
179
180
struct util_dynarray result;
181
util_dynarray_init(&result, NULL);
182
183
uint64_t EC0 = (0x345678912345670) >> 4;
184
185
bi_pack_format(&result, 0, tuples, 6, 0x60000011800, EC0, 0, false);
186
bi_pack_format(&result, 3, tuples, 6, 0x60000011800, EC0, 0, false);
187
bi_pack_format(&result, 5, tuples, 6, 0x60000011800, EC0, 0, false);
188
bi_pack_format(&result, 9, tuples, 6, 0x60000011800, EC0, 0, false);
189
bi_pack_format(&result, 10, tuples, 6, 0x60000011800, EC0, 0, false);
190
uint64_t *result_u64 = (uint64_t *) result.data;
191
192
assert(result.size == 80);
193
assert(result_u64[0] == 0x8c8700680000482d);
194
assert(result_u64[1] == 0x30000008c00718ad);
195
assert(result_u64[2] == 0x8c87385c00005025);
196
assert(result_u64[3] == 0x39c2e000035718ad);
197
assert(result_u64[4] == 0x8c87385c00007401);
198
assert(result_u64[5] == 0xb401c62b632718ad);
199
assert(result_u64[6] == 0x8c87385c00002065);
200
assert(result_u64[7] == 0x39c2e000018718ad);
201
assert(result_u64[8] == 0x3456789123456706);
202
assert(result_u64[9] == 0xa001c62b63200000);
203
}
204
205
static void
206
bi_test_pack_format_7(void)
207
{
208
struct bi_packed_tuple tuples[] = {
209
{ 0x9020074040000083, 0xf65 },
210
{ 0x90000d4058100080, 0xf65 },
211
{ 0x90000a3058700082, 0xf65 },
212
{ 0x9020074008114581, 0xf65 },
213
{ 0x90000d0058000080, 0xf65 },
214
{ 0x9000083058700082, 0xf65 },
215
{ 0x2380cb199ac38400, 0x327a },
216
};
217
218
struct util_dynarray result;
219
util_dynarray_init(&result, NULL);
220
221
bi_pack_format(&result, 0, tuples, 7, 0x3000100000, 0, 0, true);
222
bi_pack_format(&result, 3, tuples, 7, 0x3000100000, 0, 0, true);
223
bi_pack_format(&result, 5, tuples, 7, 0x3000100000, 0, 0, true);
224
bi_pack_format(&result, 9, tuples, 7, 0x3000100000, 0, 0, true);
225
bi_pack_format(&result, 11, tuples, 7, 0x3000100000, 0, 0, true);
226
uint64_t *result_u64 = (uint64_t *) result.data;
227
228
assert(result.size == 80);
229
assert(result_u64[0] == 0x2007404000008329);
230
assert(result_u64[1] == 0x180008000076590);
231
assert(result_u64[2] == 0xd405810008021);
232
assert(result_u64[3] == 0x5182c38004176590);
233
assert(result_u64[4] == 0x2007400811458101);
234
assert(result_u64[5] == 0x2401d96400076590);
235
assert(result_u64[6] == 0xd005800008061);
236
assert(result_u64[7] == 0x4182c38004176590);
237
assert(result_u64[8] == 0x80cb199ac3840047);
238
assert(result_u64[9] == 0x3801d96400027a23);
239
}
240
241
static void
242
bi_test_pack_format_8(void)
243
{
244
struct bi_packed_tuple tuples[] = {
245
{ 0x442087037a2f8643, 0x3021 },
246
{ 0x84008d0586100043, 0x200 },
247
{ 0x7c008d0028014543, 0x0 },
248
{ 0x1c00070058200081, 0x1980 },
249
{ 0x1600dd878320400, 0x200 },
250
{ 0x49709c1b08308900, 0x200 },
251
{ 0x6c2007807881ca00, 0x40 },
252
{ 0x8d70fc0d94900083, 0x800 },
253
};
254
255
struct util_dynarray result;
256
util_dynarray_init(&result, NULL);
257
258
uint64_t EC0 = (0x32e635d0) >> 4;
259
260
bi_pack_format(&result, 0, tuples, 8, 0x61001311800, EC0, 0, true);
261
bi_pack_format(&result, 3, tuples, 8, 0x61001311800, EC0, 0, true);
262
bi_pack_format(&result, 5, tuples, 8, 0x61001311800, EC0, 0, true);
263
bi_pack_format(&result, 9, tuples, 8, 0x61001311800, EC0, 0, true);
264
bi_pack_format(&result, 12, tuples, 8, 0x61001311800, EC0, 0, true);
265
bi_pack_format(&result, 13, tuples, 8, 0x61001311800, EC0, 0, true);
266
uint64_t *result_u64 = (uint64_t *) result.data;
267
268
assert(result.size == 96);
269
assert(result_u64[0] == 0x2087037a2f86432e);
270
assert(result_u64[1] == 0x30800988c0002144);
271
assert(result_u64[2] == 0x8d058610004320);
272
assert(result_u64[3] == 0x6801400a2a1a0084);
273
assert(result_u64[4] == 0x7005820008101);
274
assert(result_u64[5] == 0xc00001f0021801c);
275
assert(result_u64[6] == 0x600dd87832040060);
276
assert(result_u64[7] == 0xe0d8418448020001);
277
assert(result_u64[8] == 0x2007807881ca00c0);
278
assert(result_u64[9] == 0xc6ba80125c20406c);
279
assert(result_u64[10] == 0x70fc0d9490008359);
280
assert(result_u64[11] == 0x32e0008d);
281
}
282
283
int
284
bi_test_packing_formats(void)
285
{
286
bi_test_pack_format_1();
287
bi_test_pack_format_2();
288
bi_test_pack_format_3();
289
bi_test_pack_format_4();
290
bi_test_pack_format_5();
291
bi_test_pack_format_6();
292
bi_test_pack_format_7();
293
bi_test_pack_format_8();
294
295
return 0;
296
}
297
298
#endif
299
300