Added few more stubs so that control reaches to DestroyDevice().
[mesa.git] / src / panfrost / midgard / midgard_print_constant.c
1 /*
2 * Copyright (C) 2018-2019 Alyssa Rosenzweig <alyssa@rosenzweig.io>
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 <math.h>
25 #include <inttypes.h>
26 #include "util/half_float.h"
27 #include "midgard.h"
28 #include "helpers.h"
29 #include "midgard_ops.h"
30
31 void
32 mir_print_constant_component(FILE *fp, const midgard_constants *consts, unsigned c,
33 midgard_reg_mode reg_mode, bool half,
34 unsigned mod, midgard_alu_op op)
35 {
36 bool is_sint = false, is_uint = false, is_hex = false;
37 const char *opname = alu_opcode_props[op].name;
38
39 /* Add a sentinel name to prevent crashing */
40 if (!opname)
41 opname = "unknown";
42
43 if (opname[0] == 'u') {
44 /* If the opcode starts with a 'u' we are sure we deal with an
45 * unsigned int operation
46 */
47 is_uint = true;
48 } else if (opname[0] == 'i') {
49 /* Bit ops are easier to follow when the constant is printed in
50 * hexadecimal. Other operations starting with a 'i' are
51 * considered to operate on signed integers. That might not
52 * be true for all of them, but it's good enough for traces.
53 */
54 if (op >= midgard_alu_op_iand &&
55 op <= midgard_alu_op_ibitcount8)
56 is_hex = true;
57 else
58 is_sint = true;
59 }
60
61 if (half)
62 reg_mode--;
63
64 switch (reg_mode) {
65 case midgard_reg_mode_64:
66 if (is_sint) {
67 fprintf(fp, "%"PRIi64, consts->i64[c]);
68 } else if (is_uint) {
69 fprintf(fp, "%"PRIu64, consts->u64[c]);
70 } else if (is_hex) {
71 fprintf(fp, "0x%"PRIX64, consts->u64[c]);
72 } else {
73 double v = consts->f64[c];
74
75 if (mod & MIDGARD_FLOAT_MOD_ABS) v = fabs(v);
76 if (mod & MIDGARD_FLOAT_MOD_NEG) v = -v;
77
78 printf("%g", v);
79 }
80 break;
81
82 case midgard_reg_mode_32:
83 if (is_sint) {
84 int64_t v;
85
86 if (half && mod == midgard_int_zero_extend)
87 v = consts->u32[c];
88 else if (half && mod == midgard_int_shift)
89 v = (uint64_t)consts->u32[c] << 32;
90 else
91 v = consts->i32[c];
92
93 fprintf(fp, "%"PRIi64, v);
94 } else if (is_uint || is_hex) {
95 uint64_t v;
96
97 if (half && mod == midgard_int_shift)
98 v = (uint64_t)consts->u32[c] << 32;
99 else
100 v = consts->u32[c];
101
102 fprintf(fp, is_uint ? "%"PRIu64 : "0x%"PRIX64, v);
103 } else {
104 float v = consts->f32[c];
105
106 if (mod & MIDGARD_FLOAT_MOD_ABS) v = fabsf(v);
107 if (mod & MIDGARD_FLOAT_MOD_NEG) v = -v;
108
109 fprintf(fp, "%g", v);
110 }
111 break;
112
113 case midgard_reg_mode_16:
114 if (is_sint) {
115 int32_t v;
116
117 if (half && mod == midgard_int_zero_extend)
118 v = consts->u16[c];
119 else if (half && mod == midgard_int_shift)
120 v = (uint32_t)consts->u16[c] << 16;
121 else
122 v = consts->i16[c];
123
124 fprintf(fp, "%d", v);
125 } else if (is_uint || is_hex) {
126 uint32_t v;
127
128 if (half && mod == midgard_int_shift)
129 v = (uint32_t)consts->u16[c] << 16;
130 else
131 v = consts->u16[c];
132
133 fprintf(fp, is_uint ? "%u" : "0x%X", v);
134 } else {
135 float v = _mesa_half_to_float(consts->f16[c]);
136
137 if (mod & MIDGARD_FLOAT_MOD_ABS) v = fabsf(v);
138 if (mod & MIDGARD_FLOAT_MOD_NEG) v = -v;
139
140 fprintf(fp, "%g", v);
141 }
142 break;
143
144 case midgard_reg_mode_8:
145 fprintf(fp, "0x%X", consts->u8[c]);
146
147 if (mod)
148 fprintf(fp, " /* %u */", mod);
149
150 assert(!half); /* No 4-bit */
151
152 break;
153 }
154 }
155
156