5 * Copyright (c) 2013 Connor Abbott (connor@abbott.cx)
6 * Copyright (c) 2018 Alyssa Rosenzweig (alyssa@rosenzweig.io)
8 * Permission is hereby granted, free of charge, to any person obtaining a copy
9 * of this software and associated documentation files (the "Software"), to deal
10 * in the Software without restriction, including without limitation the rights
11 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
12 * copies of the Software, and to permit persons to whom the Software is
13 * furnished to do so, subject to the following conditions:
15 * The above copyright notice and this permission notice shall be included in
16 * all copies or substantial portions of the Software.
18 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
19 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
20 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
21 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
22 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
23 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
34 #include "midgard-parse.h"
35 #include "midgard_ops.h"
36 #include "disassemble.h"
38 #include "util/half_float.h"
40 #define DEFINE_CASE(define, str) case define: { printf(str); break; }
42 static bool is_instruction_int
= false;
44 /* Prints a short form of the tag for branching, the minimum needed to be
45 * legible and unambiguous */
48 print_tag_short(unsigned tag
)
50 switch (midgard_word_types
[tag
]) {
51 case midgard_word_type_texture
:
52 printf("tex/%X", tag
);
55 case midgard_word_type_load_store
:
59 case midgard_word_type_alu
:
60 printf("alu%d/%X", midgard_word_size
[tag
], tag
);
64 printf("%s%X", (tag
> 0) ? "" : "unk", tag
);
70 print_alu_opcode(midgard_alu_op op
)
74 if (alu_opcode_props
[op
].name
) {
75 printf("%s", alu_opcode_props
[op
].name
);
77 int_op
= midgard_is_integer_op(op
);
79 printf("alu_op_%02X", op
);
81 /* For constant analysis */
82 is_instruction_int
= int_op
;
86 print_ld_st_opcode(midgard_load_store_op op
)
88 if (load_store_opcode_names
[op
])
89 printf("%s", load_store_opcode_names
[op
]);
91 printf("ldst_op_%02X", op
);
94 static bool is_embedded_constant_half
= false;
95 static bool is_embedded_constant_int
= false;
98 prefix_for_bits(unsigned bits
)
113 print_reg(unsigned reg
, unsigned bits
)
115 /* Perform basic static analysis for expanding constants correctly */
118 is_embedded_constant_int
= is_instruction_int
;
119 is_embedded_constant_half
= (bits
< 32);
122 char prefix
= prefix_for_bits(bits
);
130 static char *outmod_names_float
[4] = {
137 static char *outmod_names_int
[4] = {
144 static char *srcmod_names_int
[4] = {
152 print_outmod(unsigned outmod
, bool is_int
)
154 printf("%s", is_int
? outmod_names_int
[outmod
] :
155 outmod_names_float
[outmod
]);
159 print_quad_word(uint32_t *words
, unsigned tabs
)
163 for (i
= 0; i
< 4; i
++)
164 printf("0x%08X%s ", words
[i
], i
== 3 ? "" : ",");
169 static const char components
[16] = "xyzwefghijklmnop";
171 /* Helper to print 4 chars of a swizzle */
173 print_swizzle_helper(unsigned swizzle
, bool upper
)
175 for (unsigned i
= 0; i
< 4; ++i
) {
176 unsigned c
= (swizzle
>> (i
* 2)) & 3;
178 printf("%c", components
[c
]);
182 /* Helper to print 8 chars of a swizzle, duplicating over */
184 print_swizzle_helper_8(unsigned swizzle
, bool upper
)
186 for (unsigned i
= 0; i
< 4; ++i
) {
187 unsigned c
= (swizzle
>> (i
* 2)) & 3;
190 printf("%c%c", components
[c
], components
[c
+1]);
195 print_swizzle_vec16(unsigned swizzle
, bool rep_high
, bool rep_low
,
196 midgard_dest_override override
)
200 if (override
== midgard_dest_override_upper
) {
202 printf(" /* rep_high */ ");
204 printf(" /* rep_low */ ");
206 if (!rep_high
&& rep_low
)
207 print_swizzle_helper_8(swizzle
, true);
209 print_swizzle_helper_8(swizzle
, false);
211 print_swizzle_helper_8(swizzle
, rep_high
& 1);
212 print_swizzle_helper_8(swizzle
, !rep_low
& 1);
217 print_swizzle_vec8(unsigned swizzle
, bool rep_high
, bool rep_low
)
221 print_swizzle_helper(swizzle
, rep_high
& 1);
222 print_swizzle_helper(swizzle
, !rep_low
& 1);
226 print_swizzle_vec4(unsigned swizzle
, bool rep_high
, bool rep_low
)
229 printf(" /* rep_high */ ");
231 printf(" /* rep_low */ ");
233 if (swizzle
== 0xE4) return; /* xyzw */
236 print_swizzle_helper(swizzle
, 0);
239 print_swizzle_vec2(unsigned swizzle
, bool rep_high
, bool rep_low
)
242 printf(" /* rep_high */ ");
244 printf(" /* rep_low */ ");
246 if (swizzle
== 0xE4) return; /* XY */
250 for (unsigned i
= 0; i
< 4; i
+= 2) {
251 unsigned a
= (swizzle
>> (i
* 2)) & 3;
252 unsigned b
= (swizzle
>> ((i
+1) * 2)) & 3;
254 /* Normally we're adjacent, but if there's an issue, don't make
258 printf("[%c%c]", components
[a
], components
[b
]);
260 printf("%c", components
[a
>> 1]);
261 else if (b
== (a
+ 1))
262 printf("%c", "XY"[a
>> 1]);
264 printf("[%c%c]", components
[a
], components
[b
]);
269 bits_for_mode(midgard_reg_mode mode
)
272 case midgard_reg_mode_8
:
274 case midgard_reg_mode_16
:
276 case midgard_reg_mode_32
:
278 case midgard_reg_mode_64
:
286 bits_for_mode_halved(midgard_reg_mode mode
, bool half
)
288 unsigned bits
= bits_for_mode(mode
);
297 print_vector_src(unsigned src_binary
,
298 midgard_reg_mode mode
, unsigned reg
,
299 midgard_dest_override override
, bool is_int
)
301 midgard_vector_alu_src
*src
= (midgard_vector_alu_src
*)&src_binary
;
303 /* Modifiers change meaning depending on the op's context */
305 midgard_int_mod int_mod
= src
->mod
;
308 printf("%s", srcmod_names_int
[int_mod
]);
310 if (src
->mod
& MIDGARD_FLOAT_MOD_NEG
)
313 if (src
->mod
& MIDGARD_FLOAT_MOD_ABS
)
318 unsigned bits
= bits_for_mode_halved(mode
, src
->half
);
319 print_reg(reg
, bits
);
323 print_swizzle_vec8(src
->swizzle
, src
->rep_high
, src
->rep_low
);
325 print_swizzle_vec16(src
->swizzle
, src
->rep_high
, src
->rep_low
, override
);
327 print_swizzle_vec4(src
->swizzle
, src
->rep_high
, src
->rep_low
);
329 print_swizzle_vec2(src
->swizzle
, src
->rep_high
, src
->rep_low
);
331 /* Since we wrapped with a function-looking thing */
333 if (is_int
&& int_mod
== midgard_int_shift
)
334 printf(") << %d", bits
);
335 else if ((is_int
&& (int_mod
!= midgard_int_normal
))
336 || (!is_int
&& src
->mod
& MIDGARD_FLOAT_MOD_ABS
))
341 decode_vector_imm(unsigned src2_reg
, unsigned imm
)
344 ret
= src2_reg
<< 11;
345 ret
|= (imm
& 0x7) << 8;
346 ret
|= (imm
>> 3) & 0xFF;
351 print_immediate(uint16_t imm
)
353 if (is_instruction_int
)
356 printf("#%g", _mesa_half_to_float(imm
));
360 print_dest(unsigned reg
, midgard_reg_mode mode
, midgard_dest_override override
)
362 /* Depending on the mode and override, we determine the type of
363 * destination addressed. Absent an override, we address just the
364 * type of the operation itself */
366 unsigned bits
= bits_for_mode(mode
);
368 if (override
!= midgard_dest_override_none
)
371 print_reg(reg
, bits
);
377 print_mask_vec16(uint8_t mask
, midgard_dest_override override
)
381 if (override
== midgard_dest_override_none
) {
382 for (unsigned i
= 0; i
< 8; i
++) {
386 components
[i
*2 + 1]);
389 bool upper
= (override
== midgard_dest_override_upper
);
391 for (unsigned i
= 0; i
< 8; i
++) {
393 printf("%c", components
[i
+ (upper
? 8 : 0)]);
398 /* For 16-bit+ masks, we read off from the 8-bit mask field. For 16-bit (vec8),
399 * it's just one bit per channel, easy peasy. For 32-bit (vec4), it's one bit
400 * per channel with one duplicate bit in the middle. For 64-bit (vec2), it's
401 * one-bit per channel with _3_ duplicate bits in the middle. Basically, just
402 * subdividing the 128-bit word in 16-bit increments. For 64-bit, we uppercase
403 * the mask to make it obvious what happened */
406 print_mask(uint8_t mask
, unsigned bits
, midgard_dest_override override
)
409 print_mask_vec16(mask
, override
);
413 /* Skip 'complete' masks */
415 if (bits
>= 32 && mask
== 0xFF) return;
420 else if (mask
== 0xF0) {
428 unsigned skip
= (bits
/ 16);
429 bool uppercase
= bits
> 32;
430 bool tripped
= false;
432 for (unsigned i
= 0; i
< 8; i
+= skip
) {
433 bool a
= (mask
& (1 << i
)) != 0;
435 for (unsigned j
= 1; j
< skip
; ++j
) {
436 bool dupe
= (mask
& (1 << (i
+ j
))) != 0;
437 tripped
|= (dupe
!= a
);
441 char c
= components
[i
/ skip
];
451 printf(" /* %X */", mask
);
455 print_mask_4(unsigned mask
)
459 for (unsigned i
= 0; i
< 4; ++i
) {
460 bool a
= (mask
& (1 << i
)) != 0;
462 printf("%c", components
[i
]);
467 print_vector_field(const char *name
, uint16_t *words
, uint16_t reg_word
,
470 midgard_reg_info
*reg_info
= (midgard_reg_info
*)®_word
;
471 midgard_vector_alu
*alu_field
= (midgard_vector_alu
*) words
;
472 midgard_reg_mode mode
= alu_field
->reg_mode
;
473 unsigned override
= alu_field
->dest_override
;
475 /* For now, prefix instruction names with their unit, until we
476 * understand how this works on a deeper level */
479 print_alu_opcode(alu_field
->op
);
481 /* Postfix with the size to disambiguate if necessary */
482 char postfix
= prefix_for_bits(bits_for_mode(mode
));
483 bool size_ambiguous
= override
!= midgard_dest_override_none
;
486 printf("%c", postfix
? postfix
: 'r');
488 /* Print the outmod, if there is one */
489 print_outmod(alu_field
->outmod
,
490 midgard_is_integer_out_op(alu_field
->op
));
494 /* Mask denoting status of 8-lanes */
495 uint8_t mask
= alu_field
->mask
;
497 /* First, print the destination */
499 print_dest(reg_info
->out_reg
, mode
, alu_field
->dest_override
);
501 /* Apply the destination override to the mask */
503 if (mode
== midgard_reg_mode_32
|| mode
== midgard_reg_mode_64
) {
504 if (override
== midgard_dest_override_lower
)
506 else if (override
== midgard_dest_override_upper
)
508 } else if (mode
== midgard_reg_mode_16
509 && override
== midgard_dest_override_lower
) {
513 if (override
!= midgard_dest_override_none
) {
514 bool modeable
= (mode
!= midgard_reg_mode_8
);
515 bool known
= override
!= 0x3; /* Unused value */
517 if (!(modeable
&& known
))
518 printf("/* do%d */ ", override
);
521 print_mask(mask
, dest_size
, override
);
525 bool is_int
= midgard_is_integer_op(alu_field
->op
);
526 print_vector_src(alu_field
->src1
, mode
, reg_info
->src1_reg
, override
, is_int
);
530 if (reg_info
->src2_imm
) {
531 uint16_t imm
= decode_vector_imm(reg_info
->src2_reg
, alu_field
->src2
>> 2);
532 print_immediate(imm
);
534 print_vector_src(alu_field
->src2
, mode
,
535 reg_info
->src2_reg
, override
, is_int
);
542 print_scalar_src(unsigned src_binary
, unsigned reg
)
544 midgard_scalar_alu_src
*src
= (midgard_scalar_alu_src
*)&src_binary
;
552 print_reg(reg
, src
->full
? 32 : 16);
554 unsigned c
= src
->component
;
557 assert((c
& 1) == 0);
561 printf(".%c", components
[c
]);
569 decode_scalar_imm(unsigned src2_reg
, unsigned imm
)
572 ret
= src2_reg
<< 11;
573 ret
|= (imm
& 3) << 9;
574 ret
|= (imm
& 4) << 6;
575 ret
|= (imm
& 0x38) << 2;
581 print_scalar_field(const char *name
, uint16_t *words
, uint16_t reg_word
,
584 midgard_reg_info
*reg_info
= (midgard_reg_info
*)®_word
;
585 midgard_scalar_alu
*alu_field
= (midgard_scalar_alu
*) words
;
587 if (alu_field
->unknown
)
588 printf("scalar ALU unknown bit set\n");
591 print_alu_opcode(alu_field
->op
);
592 print_outmod(alu_field
->outmod
,
593 midgard_is_integer_out_op(alu_field
->op
));
596 bool full
= alu_field
->output_full
;
597 print_reg(reg_info
->out_reg
, full
? 32 : 16);
598 unsigned c
= alu_field
->output_component
;
601 assert((c
& 1) == 0);
605 printf(".%c, ", components
[c
]);
607 print_scalar_src(alu_field
->src1
, reg_info
->src1_reg
);
611 if (reg_info
->src2_imm
) {
612 uint16_t imm
= decode_scalar_imm(reg_info
->src2_reg
,
614 print_immediate(imm
);
616 print_scalar_src(alu_field
->src2
, reg_info
->src2_reg
);
622 print_branch_op(int op
)
625 case midgard_jmp_writeout_op_branch_uncond
:
629 case midgard_jmp_writeout_op_branch_cond
:
633 case midgard_jmp_writeout_op_writeout
:
637 case midgard_jmp_writeout_op_tilebuffer_pending
:
638 printf("tilebuffer.");
641 case midgard_jmp_writeout_op_discard
:
646 printf("unk%d.", op
);
652 print_branch_cond(int cond
)
655 case midgard_condition_write0
:
659 case midgard_condition_false
:
663 case midgard_condition_true
:
667 case midgard_condition_always
:
672 printf("unk%X", cond
);
678 print_compact_branch_writeout_field(uint16_t word
)
680 midgard_jmp_writeout_op op
= word
& 0x7;
683 case midgard_jmp_writeout_op_branch_uncond
: {
684 midgard_branch_uncond br_uncond
;
685 memcpy((char *) &br_uncond
, (char *) &word
, sizeof(br_uncond
));
686 printf("br.uncond ");
688 if (br_uncond
.unknown
!= 1)
689 printf("unknown:%d, ", br_uncond
.unknown
);
691 if (br_uncond
.offset
>= 0)
694 printf("%d -> ", br_uncond
.offset
);
695 print_tag_short(br_uncond
.dest_tag
);
701 case midgard_jmp_writeout_op_branch_cond
:
702 case midgard_jmp_writeout_op_writeout
:
703 case midgard_jmp_writeout_op_discard
:
705 midgard_branch_cond br_cond
;
706 memcpy((char *) &br_cond
, (char *) &word
, sizeof(br_cond
));
710 print_branch_op(br_cond
.op
);
711 print_branch_cond(br_cond
.cond
);
715 if (br_cond
.offset
>= 0)
718 printf("%d -> ", br_cond
.offset
);
719 print_tag_short(br_cond
.dest_tag
);
728 print_extended_branch_writeout_field(uint8_t *words
)
730 midgard_branch_extended br
;
731 memcpy((char *) &br
, (char *) words
, sizeof(br
));
735 print_branch_op(br
.op
);
737 /* Condition repeated 8 times in all known cases. Check this. */
739 unsigned cond
= br
.cond
& 0x3;
741 for (unsigned i
= 0; i
< 16; i
+= 2) {
742 assert(((br
.cond
>> i
) & 0x3) == cond
);
745 print_branch_cond(cond
);
748 printf(".unknown%d", br
.unknown
);
755 printf("%d -> ", br
.offset
);
756 print_tag_short(br
.dest_tag
);
761 num_alu_fields_enabled(uint32_t control_word
)
765 if ((control_word
>> 17) & 1)
768 if ((control_word
>> 19) & 1)
771 if ((control_word
>> 21) & 1)
774 if ((control_word
>> 23) & 1)
777 if ((control_word
>> 25) & 1)
784 float_bitcast(uint32_t integer
)
796 print_alu_word(uint32_t *words
, unsigned num_quad_words
,
799 uint32_t control_word
= words
[0];
800 uint16_t *beginning_ptr
= (uint16_t *)(words
+ 1);
801 unsigned num_fields
= num_alu_fields_enabled(control_word
);
802 uint16_t *word_ptr
= beginning_ptr
+ num_fields
;
803 unsigned num_words
= 2 + num_fields
;
805 if ((control_word
>> 16) & 1)
806 printf("unknown bit 16 enabled\n");
808 if ((control_word
>> 17) & 1) {
809 print_vector_field("vmul", word_ptr
, *beginning_ptr
, tabs
);
815 if ((control_word
>> 18) & 1)
816 printf("unknown bit 18 enabled\n");
818 if ((control_word
>> 19) & 1) {
819 print_scalar_field("sadd", word_ptr
, *beginning_ptr
, tabs
);
825 if ((control_word
>> 20) & 1)
826 printf("unknown bit 20 enabled\n");
828 if ((control_word
>> 21) & 1) {
829 print_vector_field("vadd", word_ptr
, *beginning_ptr
, tabs
);
835 if ((control_word
>> 22) & 1)
836 printf("unknown bit 22 enabled\n");
838 if ((control_word
>> 23) & 1) {
839 print_scalar_field("smul", word_ptr
, *beginning_ptr
, tabs
);
845 if ((control_word
>> 24) & 1)
846 printf("unknown bit 24 enabled\n");
848 if ((control_word
>> 25) & 1) {
849 print_vector_field("lut", word_ptr
, *beginning_ptr
, tabs
);
855 if ((control_word
>> 26) & 1) {
856 print_compact_branch_writeout_field(*word_ptr
);
861 if ((control_word
>> 27) & 1) {
862 print_extended_branch_writeout_field((uint8_t *) word_ptr
);
867 if (num_quad_words
> (num_words
+ 7) / 8) {
868 assert(num_quad_words
== (num_words
+ 15) / 8);
869 //Assume that the extra quadword is constants
870 void *consts
= words
+ (4 * num_quad_words
- 4);
872 if (is_embedded_constant_int
) {
873 if (is_embedded_constant_half
) {
874 int16_t *sconsts
= (int16_t *) consts
;
875 printf("sconstants %d, %d, %d, %d\n",
881 int32_t *iconsts
= (int32_t *) consts
;
882 printf("iconstants %d, %d, %d, %d\n",
889 if (is_embedded_constant_half
) {
890 uint16_t *hconsts
= (uint16_t *) consts
;
891 printf("hconstants %g, %g, %g, %g\n",
892 _mesa_half_to_float(hconsts
[0]),
893 _mesa_half_to_float(hconsts
[1]),
894 _mesa_half_to_float(hconsts
[2]),
895 _mesa_half_to_float(hconsts
[3]));
897 uint32_t *fconsts
= (uint32_t *) consts
;
898 printf("fconstants %g, %g, %g, %g\n",
899 float_bitcast(fconsts
[0]),
900 float_bitcast(fconsts
[1]),
901 float_bitcast(fconsts
[2]),
902 float_bitcast(fconsts
[3]));
910 print_varying_parameters(midgard_load_store_word
*word
)
912 midgard_varying_parameter param
;
913 unsigned v
= word
->varying_parameters
;
914 memcpy(¶m
, &v
, sizeof(param
));
916 if (param
.is_varying
) {
917 /* If a varying, there are qualifiers */
921 if (param
.interpolation
!= midgard_interp_default
) {
922 if (param
.interpolation
== midgard_interp_centroid
)
925 printf(".interp%d", param
.interpolation
);
928 if (param
.modifier
!= midgard_varying_mod_none
) {
929 if (param
.modifier
== midgard_varying_mod_perspective_w
)
930 printf(".perspectivew");
931 else if (param
.modifier
== midgard_varying_mod_perspective_z
)
932 printf(".perspectivez");
934 printf(".mod%d", param
.modifier
);
936 } else if (param
.flat
|| param
.interpolation
|| param
.modifier
) {
937 printf(" /* is_varying not set but varying metadata attached */");
940 if (param
.zero0
|| param
.zero1
|| param
.zero2
)
941 printf(" /* zero tripped, %d %d %d */ ", param
.zero0
, param
.zero1
, param
.zero2
);
945 is_op_varying(unsigned op
)
948 case midgard_op_st_vary_16
:
949 case midgard_op_st_vary_32
:
950 case midgard_op_ld_vary_16
:
951 case midgard_op_ld_vary_32
:
959 print_load_store_instr(uint64_t data
,
962 midgard_load_store_word
*word
= (midgard_load_store_word
*) &data
;
964 print_ld_st_opcode(word
->op
);
966 if (is_op_varying(word
->op
))
967 print_varying_parameters(word
);
969 printf(" r%d", word
->reg
);
970 print_mask_4(word
->mask
);
972 int address
= word
->address
;
974 if (word
->op
== midgard_op_ld_uniform_32
) {
975 /* Uniforms use their own addressing scheme */
977 int lo
= word
->varying_parameters
>> 7;
978 int hi
= word
->address
;
980 /* TODO: Combine fields logically */
981 address
= (hi
<< 3) | lo
;
984 printf(", %d", address
);
986 print_swizzle_vec4(word
->swizzle
, false, false);
988 printf(", 0x%X /* %X */\n", word
->unknown
, word
->varying_parameters
);
992 print_load_store_word(uint32_t *word
, unsigned tabs
)
994 midgard_load_store
*load_store
= (midgard_load_store
*) word
;
996 if (load_store
->word1
!= 3) {
997 print_load_store_instr(load_store
->word1
, tabs
);
1000 if (load_store
->word2
!= 3) {
1001 print_load_store_instr(load_store
->word2
, tabs
);
1006 print_texture_reg(bool full
, bool select
, bool upper
)
1009 printf("r%d", REG_TEX_BASE
+ select
);
1011 printf("hr%d", (REG_TEX_BASE
+ select
) * 2 + upper
);
1014 printf("// error: out full / upper mutually exclusive\n");
1019 print_texture_reg_triple(unsigned triple
)
1021 bool full
= triple
& 1;
1022 bool select
= triple
& 2;
1023 bool upper
= triple
& 4;
1025 print_texture_reg(full
, select
, upper
);
1029 print_texture_format(int format
)
1031 /* Act like a modifier */
1035 DEFINE_CASE(TEXTURE_2D
, "2d");
1036 DEFINE_CASE(TEXTURE_3D
, "3d");
1037 DEFINE_CASE(TEXTURE_CUBE
, "cube");
1040 printf("fmt_%d", format
);
1046 print_texture_op(unsigned op
)
1048 /* Act like a bare name, like ESSL functions */
1051 DEFINE_CASE(TEXTURE_OP_NORMAL
, "texture");
1052 DEFINE_CASE(TEXTURE_OP_LOD
, "textureLod");
1053 DEFINE_CASE(TEXTURE_OP_TEXEL_FETCH
, "texelFetch");
1056 printf("tex_%d", op
);
1062 texture_op_takes_bias(unsigned op
)
1064 return op
== TEXTURE_OP_NORMAL
;
1070 print_texture_word(uint32_t *word
, unsigned tabs
)
1072 midgard_texture_word
*texture
= (midgard_texture_word
*) word
;
1074 /* Broad category of texture operation in question */
1075 print_texture_op(texture
->op
);
1077 /* Specific format in question */
1078 print_texture_format(texture
->format
);
1080 /* Instruction "modifiers" parallel the ALU instructions. */
1082 if (texture
->shadow
)
1093 print_texture_reg(texture
->out_full
, texture
->out_reg_select
, texture
->out_upper
);
1094 print_mask_4(texture
->mask
);
1097 printf("texture%d, ", texture
->texture_handle
);
1099 printf("sampler%d", texture
->sampler_handle
);
1100 print_swizzle_vec4(texture
->swizzle
, false, false);
1103 print_texture_reg(texture
->in_reg_full
, texture
->in_reg_select
, texture
->in_reg_upper
);
1104 print_swizzle_vec4(texture
->in_reg_swizzle
, false, false);
1106 /* There is *always* an offset attached. Of
1107 * course, that offset is just immediate #0 for a
1108 * GLES call that doesn't take an offset. If there
1109 * is a non-negative non-zero offset, this is
1110 * specified in immediate offset mode, with the
1111 * values in the offset_* fields as immediates. If
1112 * this is a negative offset, we instead switch to
1113 * a register offset mode, where the offset_*
1114 * fields become register triplets */
1116 if (texture
->offset_register
) {
1118 print_texture_reg_triple(texture
->offset_x
);
1120 /* I've never seen them different than this */
1121 if (texture
->offset_y
!= 2)
1122 printf(" /* y = %d */", texture
->offset_y
);
1124 if (texture
->offset_z
!= 1)
1125 printf(" /* z = %d */", texture
->offset_z
);
1128 } else if (texture
->offset_x
|| texture
->offset_y
|| texture
->offset_z
) {
1129 printf(" + <%d, %d, %d>, ",
1137 if (texture
->lod_register
) {
1139 printf("lod/bias/grad reg 0x%X (%X), ", texture
->bias
, texture
->bias_int
);
1140 } else if (texture
->bias
|| texture
->bias_int
) {
1141 int bias_int
= texture
->bias_int
;
1142 float bias_frac
= texture
->bias
/ 256.0f
;
1143 float bias
= bias_int
+ bias_frac
;
1145 bool is_bias
= texture_op_takes_bias(texture
->op
);
1146 char operand
= is_bias
? '+' : '=';
1148 printf("lod %c %f, ", operand
, bias
);
1153 /* While not zero in general, for these simple instructions the
1154 * following unknowns are zero, so we don't include them */
1156 if (texture
->unknown2
||
1157 texture
->unknown3
||
1158 texture
->unknown4
||
1159 texture
->unknownA
||
1160 texture
->unknownB
||
1161 texture
->unknown8
) {
1162 printf("// unknown2 = 0x%x\n", texture
->unknown2
);
1163 printf("// unknown3 = 0x%x\n", texture
->unknown3
);
1164 printf("// unknown4 = 0x%x\n", texture
->unknown4
);
1165 printf("// unknownA = 0x%x\n", texture
->unknownA
);
1166 printf("// unknownB = 0x%x\n", texture
->unknownB
);
1167 printf("// unknown8 = 0x%x\n", texture
->unknown8
);
1170 if (texture
->offset_unknown4
||
1171 texture
->offset_unknown8
) {
1172 printf("// offset_unknown4 = 0x%x\n", texture
->offset_unknown4
);
1173 printf("// offset_unknown8 = 0x%x\n", texture
->offset_unknown8
);
1177 if (texture
->unknown7
!= 0x1)
1178 printf("// (!) unknown7 = %d\n", texture
->unknown7
);
1182 disassemble_midgard(uint8_t *code
, size_t size
)
1184 uint32_t *words
= (uint32_t *) code
;
1185 unsigned num_words
= size
/ 4;
1188 bool prefetch_flag
= false;
1192 while (i
< num_words
) {
1193 unsigned tag
= words
[i
] & 0xF;
1194 unsigned num_quad_words
= midgard_word_size
[tag
];
1196 switch (midgard_word_types
[tag
]) {
1197 case midgard_word_type_texture
:
1198 print_texture_word(&words
[i
], tabs
);
1201 case midgard_word_type_load_store
:
1202 print_load_store_word(&words
[i
], tabs
);
1205 case midgard_word_type_alu
:
1206 print_alu_word(&words
[i
], num_quad_words
, tabs
);
1211 /* Reset word static analysis state */
1212 is_embedded_constant_half
= false;
1213 is_embedded_constant_int
= false;
1218 printf("Unknown word type %u:\n", words
[i
] & 0xF);
1220 print_quad_word(&words
[i
], tabs
);
1227 unsigned next
= (words
[i
] & 0xF0) >> 4;
1229 i
+= 4 * num_quad_words
;
1231 /* Break based on instruction prefetch flag */
1233 if (i
< num_words
&& next
== 1) {
1234 prefetch_flag
= true;
1236 if (midgard_word_types
[words
[i
] & 0xF] != midgard_word_type_alu
)