gpu_neon: fix some missing ebuf updates
[pcsx_rearmed.git] / deps / lightning / lib / jit_print.c
1 /*
2  * Copyright (C) 2012-2023  Free Software Foundation, Inc.
3  *
4  * This file is part of GNU lightning.
5  *
6  * GNU lightning is free software; you can redistribute it and/or modify it
7  * under the terms of the GNU Lesser General Public License as published
8  * by the Free Software Foundation; either version 3, or (at your option)
9  * any later version.
10  *
11  * GNU lightning is distributed in the hope that it will be useful, but
12  * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
13  * or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU Lesser General Public
14  * License for more details.
15  *
16  * Authors:
17  *      Paulo Cesar Pereira de Andrade
18  */
19
20 #include <lightning.h>
21 #include <lightning/jit_private.h>
22
23 #if __WORDSIZE == 32
24 #  define MININT                0x80000000
25 #  define INT_FMT               "%d"
26 #  define DEC_FMT               "%d"
27 #  define HEX_FMT               "0x%x"
28 #else
29 #  define MININT                0x8000000000000000
30 #  define INT_FMT               "%d"
31 #  define DEC_FMT               "%ld"
32 #  define HEX_FMT               "0x%lx"
33 #endif
34
35
36 #define print_chr(value)                fputc(value, print_stream)
37 #define print_hex(value)                                                \
38     do {                                                                \
39         if (value < 0 && value != MININT)                               \
40             fprintf(print_stream, "-" HEX_FMT, (jit_uword_t)-value);    \
41         else                                                            \
42             fprintf(print_stream, HEX_FMT, (jit_uword_t)value);         \
43     } while (0)
44 #define print_dec(value)                fprintf(print_stream, DEC_FMT, value)
45 #define print_int(value)                fprintf(print_stream, INT_FMT, value)
46 #define print_flt(value)                fprintf(print_stream, "%g", value)
47 #define print_str(value)                fprintf(print_stream, "%s", value)
48 #define print_ptr(value)                fprintf(print_stream, "%p", value)
49 #define print_reg(value)                                                \
50     do {                                                                \
51         if ((value) & jit_regno_patch)                                  \
52             print_chr('?');                                             \
53         print_str(_rvs[jit_regno(value)].name);                         \
54     } while (0)
55 #define print_arg(value)                                                \
56     do {                                                                \
57         print_chr('#');                                                 \
58         if (value)                                                      \
59             print_dec((value)->v.w);                                    \
60         else                                                            \
61             print_chr('?');                                             \
62     } while (0)
63
64 /*
65  * Initialization
66  */
67 #include "jit_names.c"
68 /*
69  * Initialization
70  */
71 static FILE     *print_stream;
72
73
74 /*
75  * Implementation
76  */
77 void
78 jit_init_print(void)
79 {
80     if (!print_stream)
81         print_stream = stdout;
82 }
83
84 void
85 _jit_print(jit_state_t *_jit)
86 {
87     jit_node_t          *node;
88
89     if ((node = _jitc->head)) {
90         jit_print_node(node);
91         for (node = node->next; node; node = node->next) {
92             print_chr('\n');
93             jit_print_node(node);
94         }
95         print_chr('\n');
96     }
97 }
98
99 void
100 _jit_print_node(jit_state_t *_jit, jit_node_t *node)
101 {
102     jit_block_t         *block;
103     jit_int32_t          value;
104     jit_int32_t          offset;
105
106     if (node->code == jit_code_label ||
107         node->code == jit_code_prolog || node->code == jit_code_epilog) {
108         print_chr('L');
109         print_dec(node->v.w);
110         print_chr(':');
111         block = _jitc->blocks.ptr + node->v.w;
112         for (offset = 0; offset < _jitc->reglen; offset++) {
113             if (jit_regset_tstbit(&block->reglive, offset)) {
114                 print_chr(' ');
115                 print_reg(offset);
116             }
117         }
118         if (node->code == jit_code_prolog ||
119             node->code == jit_code_epilog) {
120             print_str(" /* ");
121             print_str(code_name[node->code]);
122             print_str(" */");
123         }
124         return;
125     }
126     value = jit_classify(node->code) &
127         (jit_cc_a0_int|jit_cc_a0_flt|jit_cc_a0_dbl|jit_cc_a0_jmp|
128          jit_cc_a0_reg|jit_cc_a0_rlh|jit_cc_a0_arg|
129          jit_cc_a1_reg|jit_cc_a1_rlh|jit_cc_a1_int|
130          jit_cc_a1_flt|jit_cc_a1_dbl|jit_cc_a1_arg|
131          jit_cc_a2_reg|jit_cc_a2_int|jit_cc_a2_flt|jit_cc_a2_dbl|jit_cc_a2_rlh);
132     if (!(node->flag & jit_flag_synth) && ((value & jit_cc_a0_jmp) ||
133                                            node->code == jit_code_finishr ||
134                                            node->code == jit_code_finishi))
135         print_str("    ");
136     else
137         print_chr('\t');
138     if (node->flag & jit_flag_synth)
139         print_str(" \\__ ");
140     print_str(code_name[node->code]);
141     switch (node->code) {
142         r:
143             print_chr(' ');     print_reg(node->u.w);   return;
144         w:
145             print_chr(' ');     print_hex(node->u.w);   return;
146         f:
147             print_chr(' ');
148             if (node->flag & jit_flag_data)
149                 print_flt(*(jit_float32_t *)node->u.n->u.w);
150             else
151                 print_flt(node->u.f);
152             return;
153         d:
154             print_chr(' ');
155             if (node->flag & jit_flag_data)
156                 print_flt(*(jit_float64_t *)node->u.n->u.w);
157             else
158                 print_flt(node->u.d);
159             return;
160         n:
161             print_chr(' ');
162             if (!(node->flag & jit_flag_node))
163                 print_ptr(node->u.p);
164             else {
165                 print_chr('L');
166                 print_dec(node->u.n->v.w);
167             }
168             return;
169         a:
170             print_chr(' ');     print_arg(node);        return;
171         r_r:
172             print_chr(' ');     print_reg(node->u.w);
173             print_chr(' ');     print_reg(node->v.w);   return;
174         r_w:
175             print_chr(' ');     print_reg(node->u.w);
176             print_chr(' ');     print_hex(node->v.w);   return;
177         r_f:
178             print_chr(' ');     print_reg(node->u.w);
179             print_chr(' ');
180             if (node->flag & jit_flag_data)
181                 print_flt(*(jit_float32_t *)node->v.n->u.w);
182             else
183                 print_flt(node->v.f);
184             return;
185         r_d:
186             print_chr(' ');     print_reg(node->u.w);
187             print_chr(' ');
188             if (node->flag & jit_flag_data)
189                 print_flt(*(jit_float64_t *)node->v.n->u.w);
190             else
191                 print_flt(node->v.d);
192             return;
193         r_a:
194             print_chr(' ');     print_reg(node->u.w);
195             print_chr(' ');     print_arg(node->v.n);
196             return;
197         w_r:
198             print_chr(' ');     print_hex(node->u.w);
199             print_chr(' ');     print_reg(node->v.w);   return;
200         w_w:
201             print_chr(' ');     print_hex(node->u.w);
202             print_chr(' ');     print_hex(node->v.w);   return;
203         w_a:
204             print_chr(' ');     print_hex(node->u.w);
205             print_chr(' ');     print_arg(node->v.n);
206             return;
207         f_a:
208             print_chr(' ');
209             if (node->flag & jit_flag_data)
210                 print_flt(*(jit_float32_t *)node->u.n->u.w);
211             else
212                 print_flt(node->u.f);
213             print_chr(' ');     print_arg(node->v.n);
214             return;
215         d_a:
216             print_chr(' ');
217             if (node->flag & jit_flag_data)
218                 print_flt(*(jit_float64_t *)node->u.n->u.w);
219             else
220                 print_flt(node->u.d);
221             print_chr(' ');     print_arg(node->v.n);
222             return;
223         r_r_r:
224             print_chr(' ');     print_reg(node->u.w);
225             print_chr(' ');     print_reg(node->v.w);
226             print_chr(' ');     print_reg(node->w.w);   return;
227         r_r_w:
228             print_chr(' ');     print_reg(node->u.w);
229             print_chr(' ');     print_reg(node->v.w);
230             print_chr(' ');     print_hex(node->w.w);   return;
231         r_w_w:
232             print_chr(' ');     print_reg(node->u.w);
233             print_chr(' ');     print_hex(node->v.w);
234             print_chr(' ');
235             if (node->code == jit_code_movi_ww_d)
236                 print_hex(node->w.w);
237             else
238                 print_dec(node->w.w);
239             return;
240         w_r_w:
241             print_chr(' ');     print_hex(node->u.w);
242             print_chr(' ');     print_reg(node->v.w);
243             print_chr(' ');     print_dec(node->w.w);   return;
244         q_r_r:
245             print_str(" (");    print_reg(node->u.q.l);
246             print_chr(' ');     print_reg(node->u.q.h);
247             print_str(") ");    print_reg(node->v.w);
248             print_chr(' ');     print_reg(node->w.w);   return;
249         q_r_w:
250             print_str(" (");    print_reg(node->u.q.l);
251             print_chr(' ');     print_reg(node->u.q.h);
252             print_str(") ");    print_reg(node->v.w);
253             print_chr(' ');     print_hex(node->w.w);   return;
254         r_r_q:
255             print_chr(' ');     print_reg(node->u.w);
256             print_chr(' ');     print_reg(node->v.w);
257             print_str(" (");    print_reg(node->w.q.l);
258             print_chr(' ');     print_reg(node->w.q.h);
259             print_str(") ");    return;
260         r_w_q:
261             print_chr(' ');     print_reg(node->u.w);
262             print_chr(' ');     print_hex(node->v.w);
263             print_str(" (");    print_reg(node->w.q.l);
264             print_chr(' ');     print_reg(node->w.q.h);
265             print_str(") ");    return;
266         r_r_iq:
267             print_chr(' ');     print_reg(node->u.w);
268             print_chr(' ');     print_reg(node->v.w);
269             print_str(" (");    print_int(node->w.q.l);
270             print_chr(' ');     print_int(node->w.q.h);
271             print_str(") ");    return;
272         r_w_iq:
273             print_chr(' ');     print_reg(node->u.w);
274             print_chr(' ');     print_hex(node->v.w);
275             print_str(" (");    print_int(node->w.q.l);
276             print_chr(' ');     print_int(node->w.q.h);
277             print_str(") ");    return;
278         r_q_r:
279             print_chr(' ');     print_reg(node->u.w);
280             print_str(" (");    print_reg(node->v.q.l);
281             print_chr(' ');     print_reg(node->v.q.h);
282             print_str(") ");    print_reg(node->w.w);
283             return;
284         r_r_f:
285             print_chr(' ');     print_reg(node->u.w);
286             print_chr(' ');     print_reg(node->v.w);
287             print_chr(' ');
288             if (node->flag & jit_flag_data)
289                 print_flt(*(jit_float32_t *)node->w.n->u.w);
290             else
291                 print_flt(node->w.f);
292             return;
293         r_q_f:
294             print_chr(' ');     print_reg(node->u.w);
295             print_str(" (");    print_reg(node->v.q.l);
296             print_chr(' ');     print_reg(node->v.q.h);
297             print_str(") ");
298             if (node->flag & jit_flag_data)
299                 print_flt(*(jit_float32_t *)node->w.n->u.w);
300             else
301                 print_flt(node->w.f);
302             return;
303         r_r_d:
304             print_chr(' ');     print_reg(node->u.w);
305             print_chr(' ');     print_reg(node->v.w);
306             print_chr(' ');
307             if (node->flag & jit_flag_data)
308                 print_flt(*(jit_float64_t *)node->w.n->u.w);
309             else
310                 print_flt(node->w.d);
311             return;
312         r_q_d:
313             print_chr(' ');     print_reg(node->u.w);
314             print_str(" (");    print_reg(node->v.q.l);
315             print_chr(' ');     print_reg(node->v.q.h);
316             print_str(") ");
317             if (node->flag & jit_flag_data)
318                 print_flt(*(jit_float64_t *)node->w.n->u.w);
319             else
320                 print_flt(node->w.d);
321             return;
322         w_r_r:
323             print_chr(' ');     print_hex(node->u.w);
324             print_chr(' ');     print_reg(node->v.w);
325             print_chr(' ');     print_reg(node->w.w);   return;
326         n_r_r:
327             print_chr(' ');
328             if (!(node->flag & jit_flag_node))
329                 print_ptr(node->u.p);
330             else {
331                 print_chr('L');
332                 print_dec(node->u.n->v.w);
333             }
334             print_chr(' ');     print_reg(node->v.w);
335             print_chr(' ');     print_reg(node->w.w);   return;
336         n_r_w:
337             print_chr(' ');
338             if (!(node->flag & jit_flag_node))
339                 print_ptr(node->u.p);
340             else {
341                 print_chr('L');
342                 print_dec(node->u.n->v.w);
343             }
344             print_chr(' ');     print_reg(node->v.w);
345             print_chr(' ');     print_hex(node->w.w);   return;
346         n_r_f:
347             print_chr(' ');
348             if (!(node->flag & jit_flag_node))
349                 print_ptr(node->u.p);
350             else{
351                 print_chr('L');
352                 print_dec(node->u.n->v.w);
353             }
354             print_chr(' ');     print_reg(node->v.w);
355             print_chr(' ');
356             if (node->flag & jit_flag_data)
357                 print_flt(*(jit_float32_t *)node->w.n->u.w);
358             else
359                 print_flt(node->w.f);
360             return;
361         n_r_d:
362             print_chr(' ');
363             if (!(node->flag & jit_flag_node))
364                 print_ptr(node->u.p);
365             else {
366                 print_chr('L');
367                 print_dec(node->u.n->v.w);
368             }
369             print_chr(' ');     print_reg(node->v.w);
370             print_chr(' ');
371             if (node->flag & jit_flag_data)
372                 print_flt(*(jit_float64_t *)node->w.n->u.w);
373             else
374                 print_flt(node->w.d);
375             return;
376         case jit_code_name:
377             print_chr(' ');
378             if (node->v.p && _jitc->emit)
379                 print_str((char *)node->v.n->u.p);
380             break;
381         case jit_code_note:
382             print_chr(' ');
383             if (node->v.p && _jitc->emit)
384                 print_str((char *)node->v.n->u.p);
385             if (node->v.p && _jitc->emit && node->w.w)
386                 print_chr(':');
387             if (node->w.w)
388                 print_dec(node->w.w);
389             break;
390         case jit_code_data:
391         case jit_code_label:
392         case jit_code_ellipsis:
393         case jit_code_prolog:   case jit_code_epilog:
394         case jit_code_ret:      case jit_code_prepare:
395             break;
396         case jit_code_save:     case jit_code_load:
397             goto r;
398         default:
399             switch (value) {
400                 case jit_cc_a0_reg:
401                 case jit_cc_a0_reg|jit_cc_a0_chg:
402                 case jit_cc_a0_reg|jit_cc_a0_jmp:
403                     goto r;
404                 case jit_cc_a0_int:
405                     goto w;
406                 case jit_cc_a0_flt:
407                     goto f;
408                 case jit_cc_a0_dbl:
409                     goto d;
410                 case jit_cc_a0_jmp:
411                     goto n;
412                 case jit_cc_a0_int|jit_cc_a0_arg:
413                     goto a;
414                 case jit_cc_a0_reg|jit_cc_a1_reg:
415                     goto r_r;
416                 case jit_cc_a0_reg|jit_cc_a1_int:
417                     goto r_w;
418                 case jit_cc_a0_reg|jit_cc_a1_flt:
419                     goto r_f;
420                 case jit_cc_a0_reg|jit_cc_a1_dbl:
421                     goto r_d;
422                 case jit_cc_a0_reg|jit_cc_a1_arg:
423                     goto r_a;
424                 case jit_cc_a0_int|jit_cc_a1_reg:
425                     goto w_r;
426                 case jit_cc_a0_int|jit_cc_a1_int:
427                     goto w_w;
428                 case jit_cc_a0_int|jit_cc_a1_arg:
429                     goto w_a;
430                 case jit_cc_a0_flt|jit_cc_a1_arg:
431                     goto f_a;
432                 case jit_cc_a0_dbl|jit_cc_a1_arg:
433                     goto d_a;
434                 case jit_cc_a0_reg|jit_cc_a1_reg|jit_cc_a2_reg:
435                     goto r_r_r;
436                 case jit_cc_a0_reg|jit_cc_a1_reg|jit_cc_a2_int:
437                     goto r_r_w;
438                 case jit_cc_a0_reg|jit_cc_a1_int|jit_cc_a2_int:
439                     goto r_w_w;
440                 case jit_cc_a0_int|jit_cc_a1_reg|jit_cc_a2_int:
441                     goto w_r_w;
442                 case jit_cc_a0_reg|jit_cc_a0_rlh|
443                      jit_cc_a1_reg|jit_cc_a2_reg:
444                     goto q_r_r;
445                 case jit_cc_a0_reg|jit_cc_a0_rlh|
446                      jit_cc_a1_reg|jit_cc_a2_int:
447                     goto q_r_w;
448                 case jit_cc_a0_reg|jit_cc_a1_reg|
449                     jit_cc_a2_reg|jit_cc_a2_rlh:
450                     goto r_r_q;
451                 case jit_cc_a0_reg|jit_cc_a1_int|
452                     jit_cc_a2_reg|jit_cc_a2_rlh:
453                     goto r_w_q;
454                 case jit_cc_a0_reg|jit_cc_a1_reg|jit_cc_a2_rlh:
455                     goto r_r_iq;
456                 case jit_cc_a0_reg|jit_cc_a1_int|jit_cc_a2_rlh:
457                     goto r_w_iq;
458                 case jit_cc_a0_reg|jit_cc_a1_reg|jit_cc_a2_flt:
459                     goto r_r_f;
460                 case jit_cc_a0_reg|jit_cc_a1_reg|jit_cc_a2_dbl:
461                     goto r_r_d;
462                 case jit_cc_a0_int|jit_cc_a1_reg|jit_cc_a2_reg:
463                     goto w_r_r;
464                 case jit_cc_a0_jmp|jit_cc_a1_reg|jit_cc_a2_reg:
465                     goto n_r_r;
466                 case jit_cc_a0_jmp|jit_cc_a1_reg|jit_cc_a2_int:
467                     goto n_r_w;
468                 case jit_cc_a0_jmp|jit_cc_a1_reg|jit_cc_a2_flt:
469                     goto n_r_f;
470                 case jit_cc_a0_jmp|jit_cc_a1_reg|jit_cc_a2_dbl:
471                     goto n_r_d;
472                 case jit_cc_a0_reg|jit_cc_a1_reg|jit_cc_a1_rlh|jit_cc_a2_reg:
473                     goto r_q_r;
474                 case jit_cc_a0_reg|jit_cc_a1_reg|jit_cc_a1_rlh|jit_cc_a2_flt:
475                     goto r_q_f;
476                 case jit_cc_a0_reg|jit_cc_a1_reg|jit_cc_a1_rlh|jit_cc_a2_dbl:
477                     goto r_q_d;
478                 default:
479                     abort();
480             }
481             break;
482     }
483 }