2 * Copyright © 2012 Intel Corporation
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:
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
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
20 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
24 /** @file brw_eu_compact.c
26 * Instruction compaction is a feature of gm45 and newer hardware that allows
27 * for a smaller instruction encoding.
29 * The instruction cache is on the order of 32KB, and many programs generate
30 * far more instructions than that. The instruction cache is built to barely
31 * keep up with instruction dispatch abaility in cache hit cases -- L1
32 * instruction cache misses that still hit in the next level could limit
33 * throughput by around 50%.
35 * The idea of instruction compaction is that most instructions use a tiny
36 * subset of the GPU functionality, so we can encode what would be a 16 byte
37 * instruction in 8 bytes using some lookup tables for various fields.
40 #include "brw_context.h"
42 #include "intel_asm_annotation.h"
44 static const uint32_t gen6_control_index_table
[32] = {
79 static const uint32_t gen6_datatype_table
[32] = {
100 0b001011011000101100,
101 0b001011010110100101,
102 0b001011110110100101,
103 0b001111011110111101,
104 0b001111011110111100,
105 0b001111011110111101,
106 0b001111011110011101,
107 0b001111011110111110,
108 0b001000000000100001,
109 0b001000000000100010,
110 0b001001111111011101,
111 0b001000001110111110,
114 static const uint16_t gen6_subreg_table
[32] = {
149 static const uint16_t gen6_src_index_table
[32] = {
184 static const uint32_t gen7_control_index_table
[32] = {
185 0b0000000000000000010,
186 0b0000100000000000000,
187 0b0000100000000000001,
188 0b0000100000000000010,
189 0b0000100000000000011,
190 0b0000100000000000100,
191 0b0000100000000000101,
192 0b0000100000000000111,
193 0b0000100000000001000,
194 0b0000100000000001001,
195 0b0000100000000001101,
196 0b0000110000000000000,
197 0b0000110000000000001,
198 0b0000110000000000010,
199 0b0000110000000000011,
200 0b0000110000000000100,
201 0b0000110000000000101,
202 0b0000110000000000111,
203 0b0000110000000001001,
204 0b0000110000000001101,
205 0b0000110000000010000,
206 0b0000110000100000000,
207 0b0001000000000000000,
208 0b0001000000000000010,
209 0b0001000000000000100,
210 0b0001000000100000000,
211 0b0010110000000000000,
212 0b0010110000000010000,
213 0b0011000000000000000,
214 0b0011000000100000000,
215 0b0101000000000000000,
216 0b0101000000100000000
219 static const uint32_t gen7_datatype_table
[32] = {
220 0b001000000000000001,
221 0b001000000000100000,
222 0b001000000000100001,
223 0b001000000001100001,
224 0b001000000010111101,
225 0b001000001011111101,
226 0b001000001110100001,
227 0b001000001110100101,
228 0b001000001110111101,
229 0b001000010000100001,
230 0b001000110000100000,
231 0b001000110000100001,
232 0b001001010010100101,
233 0b001001110010100100,
234 0b001001110010100101,
235 0b001111001110111101,
236 0b001111011110011101,
237 0b001111011110111100,
238 0b001111011110111101,
239 0b001111111110111100,
240 0b000000001000001100,
241 0b001000000000111101,
242 0b001000000010100101,
243 0b001000010000100000,
244 0b001001010010100100,
245 0b001001110010000100,
246 0b001010010100001001,
247 0b001101111110111101,
248 0b001111111110111101,
249 0b001011110110101100,
250 0b001010010100101000,
254 static const uint16_t gen7_subreg_table
[32] = {
289 static const uint16_t gen7_src_index_table
[32] = {
324 static const uint32_t gen8_control_index_table
[32] = {
325 0b0000000000000000010,
326 0b0000100000000000000,
327 0b0000100000000000001,
328 0b0000100000000000010,
329 0b0000100000000000011,
330 0b0000100000000000100,
331 0b0000100000000000101,
332 0b0000100000000000111,
333 0b0000100000000001000,
334 0b0000100000000001001,
335 0b0000100000000001101,
336 0b0000110000000000000,
337 0b0000110000000000001,
338 0b0000110000000000010,
339 0b0000110000000000011,
340 0b0000110000000000100,
341 0b0000110000000000101,
342 0b0000110000000000111,
343 0b0000110000000001001,
344 0b0000110000000001101,
345 0b0000110000000010000,
346 0b0000110000100000000,
347 0b0001000000000000000,
348 0b0001000000000000010,
349 0b0001000000000000100,
350 0b0001000000100000000,
351 0b0010110000000000000,
352 0b0010110000000010000,
353 0b0011000000000000000,
354 0b0011000000100000000,
355 0b0101000000000000000,
356 0b0101000000100000000
359 static const uint32_t gen8_datatype_table
[32] = {
360 0b001000000000000000001,
361 0b001000000000001000000,
362 0b001000000000001000001,
363 0b001000000000011000001,
364 0b001000000000101011101,
365 0b001000000010111011101,
366 0b001000000011101000001,
367 0b001000000011101000101,
368 0b001000000011101011101,
369 0b001000001000001000001,
370 0b001000011000001000000,
371 0b001000011000001000001,
372 0b001000101000101000101,
373 0b001000111000101000100,
374 0b001000111000101000101,
375 0b001011100011101011101,
376 0b001011101011100011101,
377 0b001011101011101011100,
378 0b001011101011101011101,
379 0b001011111011101011100,
380 0b000000000010000001100,
381 0b001000000000001011101,
382 0b001000000000101000101,
383 0b001000001000001000000,
384 0b001000101000101000100,
385 0b001000111000100000100,
386 0b001001001001000001001,
387 0b001010111011101011101,
388 0b001011111011101011101,
389 0b001001111001101001100,
390 0b001001001001001001000,
391 0b001001011001001001000
394 static const uint16_t gen8_subreg_table
[32] = {
429 static const uint16_t gen8_src_index_table
[32] = {
464 /* This is actually the control index table for Cherryview (26 bits), but the
465 * only difference from Broadwell (24 bits) is that it has two extra 0-bits at
468 * The low 24 bits have the same mappings on both hardware.
470 static const uint32_t gen8_3src_control_index_table
[4] = {
471 0b00100000000110000000000001,
472 0b00000000000110000000000001,
473 0b00000000001000000000000001,
474 0b00000000001000000000100001
477 /* This is actually the control index table for Cherryview (49 bits), but the
478 * only difference from Broadwell (46 bits) is that it has three extra 0-bits
481 * The low 44 bits have the same mappings on both hardware, and since the high
482 * three bits on Broadwell are zero, we can reuse Cherryview's table.
484 static const uint64_t gen8_3src_source_index_table
[4] = {
485 0b0000001110010011100100111001000001111000000000000,
486 0b0000001110010011100100111001000001111000000000010,
487 0b0000001110010011100100111001000001111000000001000,
488 0b0000001110010011100100111001000001111000000100000
491 static const uint32_t *control_index_table
;
492 static const uint32_t *datatype_table
;
493 static const uint16_t *subreg_table
;
494 static const uint16_t *src_index_table
;
497 set_control_index(struct brw_context
*brw
, brw_compact_inst
*dst
, brw_inst
*src
)
499 uint32_t uncompacted
= /* 17b/SNB; 19b/IVB+ */
500 (brw_inst_bits(src
, 31, 31) << 16) | /* 1b */
501 (brw_inst_bits(src
, 23, 8)); /* 16b */
503 /* On gen7, the flag register and subregister numbers are integrated into
507 uncompacted
|= brw_inst_bits(src
, 90, 89) << 17; /* 2b */
509 for (int i
= 0; i
< 32; i
++) {
510 if (control_index_table
[i
] == uncompacted
) {
511 brw_compact_inst_set_control_index(dst
, i
);
520 set_datatype_index(struct brw_context
*brw
, brw_compact_inst
*dst
,
523 uint32_t uncompacted
= /* 18b */
524 (brw_inst_bits(src
, 63, 61) << 15) | /* 3b */
525 (brw_inst_bits(src
, 46, 32)); /* 15b */
527 for (int i
= 0; i
< 32; i
++) {
528 if (datatype_table
[i
] == uncompacted
) {
529 brw_compact_inst_set_datatype_index(dst
, i
);
538 set_subreg_index(struct brw_context
*brw
, brw_compact_inst
*dst
, brw_inst
*src
,
541 uint16_t uncompacted
= /* 15b */
542 (brw_inst_bits(src
, 52, 48) << 0) | /* 5b */
543 (brw_inst_bits(src
, 68, 64) << 5); /* 5b */
546 uncompacted
|= brw_inst_bits(src
, 100, 96) << 10; /* 5b */
548 for (int i
= 0; i
< 32; i
++) {
549 if (subreg_table
[i
] == uncompacted
) {
550 brw_compact_inst_set_subreg_index(dst
, i
);
559 get_src_index(uint16_t uncompacted
,
562 for (int i
= 0; i
< 32; i
++) {
563 if (src_index_table
[i
] == uncompacted
) {
573 set_src0_index(struct brw_context
*brw
, brw_compact_inst
*dst
, brw_inst
*src
)
576 uint16_t uncompacted
= brw_inst_bits(src
, 88, 77); /* 12b */
578 if (!get_src_index(uncompacted
, &compacted
))
581 brw_compact_inst_set_src0_index(dst
, compacted
);
587 set_src1_index(struct brw_context
*brw
, brw_compact_inst
*dst
, brw_inst
*src
,
593 compacted
= (brw_inst_imm_ud(brw
, src
) >> 8) & 0x1f;
595 uint16_t uncompacted
= brw_inst_bits(src
, 120, 109); /* 12b */
597 if (!get_src_index(uncompacted
, &compacted
))
601 brw_compact_inst_set_src1_index(dst
, compacted
);
606 /* Compacted instructions have 12-bits for immediate sources, and a 13th bit
607 * that's replicated through the high 20 bits.
609 * Effectively this means we get 12-bit integers, 0.0f, and some limited uses
610 * of packed vectors as compactable immediates.
613 is_compactable_immediate(unsigned imm
)
615 /* We get the low 12 bits as-is. */
618 /* We get one bit replicated through the top 20 bits. */
619 return imm
== 0 || imm
== 0xfffff000;
623 * Tries to compact instruction src into dst.
625 * It doesn't modify dst unless src is compactable, which is relied on by
626 * brw_compact_instructions().
629 brw_try_compact_instruction(struct brw_context
*brw
, brw_compact_inst
*dst
,
632 brw_compact_inst temp
;
634 if (brw_inst_opcode(brw
, src
) == BRW_OPCODE_IF
||
635 brw_inst_opcode(brw
, src
) == BRW_OPCODE_ELSE
||
636 brw_inst_opcode(brw
, src
) == BRW_OPCODE_ENDIF
||
637 brw_inst_opcode(brw
, src
) == BRW_OPCODE_HALT
||
638 brw_inst_opcode(brw
, src
) == BRW_OPCODE_DO
||
639 brw_inst_opcode(brw
, src
) == BRW_OPCODE_WHILE
) {
640 /* FINISHME: The fixup code below, and brw_set_uip_jip and friends, needs
641 * to be able to handle compacted flow control instructions..
647 brw_inst_src0_reg_file(brw
, src
) == BRW_IMMEDIATE_VALUE
||
648 brw_inst_src1_reg_file(brw
, src
) == BRW_IMMEDIATE_VALUE
;
649 if (is_immediate
&& !is_compactable_immediate(brw_inst_imm_ud(brw
, src
))) {
653 memset(&temp
, 0, sizeof(temp
));
655 brw_compact_inst_set_opcode(&temp
, brw_inst_opcode(brw
, src
));
656 brw_compact_inst_set_debug_control(&temp
, brw_inst_debug_control(brw
, src
));
657 if (!set_control_index(brw
, &temp
, src
))
659 if (!set_datatype_index(brw
, &temp
, src
))
661 if (!set_subreg_index(brw
, &temp
, src
, is_immediate
))
663 brw_compact_inst_set_acc_wr_control(&temp
,
664 brw_inst_acc_wr_control(brw
, src
));
665 brw_compact_inst_set_cond_modifier(&temp
, brw_inst_cond_modifier(brw
, src
));
667 brw_compact_inst_set_flag_subreg_nr(&temp
,
668 brw_inst_flag_subreg_nr(brw
, src
));
669 brw_compact_inst_set_cmpt_control(&temp
, true);
670 if (!set_src0_index(brw
, &temp
, src
))
672 if (!set_src1_index(brw
, &temp
, src
, is_immediate
))
674 brw_compact_inst_set_dst_reg_nr(&temp
, brw_inst_dst_da_reg_nr(brw
, src
));
675 brw_compact_inst_set_src0_reg_nr(&temp
, brw_inst_src0_da_reg_nr(brw
, src
));
677 brw_compact_inst_set_src1_reg_nr(&temp
, brw_inst_imm_ud(brw
, src
) & 0xff);
679 brw_compact_inst_set_src1_reg_nr(&temp
,
680 brw_inst_src1_da_reg_nr(brw
, src
));
689 set_uncompacted_control(struct brw_context
*brw
, brw_inst
*dst
,
690 brw_compact_inst
*src
)
692 uint32_t uncompacted
=
693 control_index_table
[brw_compact_inst_control_index(src
)];
695 brw_inst_set_bits(dst
, 31, 31, (uncompacted
>> 16) & 0x1);
696 brw_inst_set_bits(dst
, 23, 8, (uncompacted
& 0xffff));
699 brw_inst_set_bits(dst
, 90, 89, uncompacted
>> 17);
703 set_uncompacted_datatype(struct brw_context
*brw
, brw_inst
*dst
,
704 brw_compact_inst
*src
)
706 uint32_t uncompacted
= datatype_table
[brw_compact_inst_datatype_index(src
)];
708 brw_inst_set_bits(dst
, 63, 61, (uncompacted
>> 15));
709 brw_inst_set_bits(dst
, 46, 32, (uncompacted
& 0x7fff));
713 set_uncompacted_subreg(struct brw_context
*brw
, brw_inst
*dst
,
714 brw_compact_inst
*src
)
716 uint16_t uncompacted
= subreg_table
[brw_compact_inst_subreg_index(src
)];
718 brw_inst_set_bits(dst
, 100, 96, (uncompacted
>> 10));
719 brw_inst_set_bits(dst
, 68, 64, (uncompacted
>> 5) & 0x1f);
720 brw_inst_set_bits(dst
, 52, 48, (uncompacted
>> 0) & 0x1f);
724 set_uncompacted_src0(struct brw_context
*brw
, brw_inst
*dst
,
725 brw_compact_inst
*src
)
727 uint32_t compacted
= brw_compact_inst_src0_index(src
);
728 uint16_t uncompacted
= src_index_table
[compacted
];
730 brw_inst_set_bits(dst
, 88, 77, uncompacted
);
734 set_uncompacted_src1(struct brw_context
*brw
, brw_inst
*dst
,
735 brw_compact_inst
*src
, bool is_immediate
)
738 signed high5
= brw_compact_inst_src1_index(src
);
739 /* Replicate top bit of src1_index into high 20 bits of the immediate. */
740 brw_inst_set_imm_ud(brw
, dst
, (high5
<< 27) >> 19);
742 uint16_t uncompacted
= src_index_table
[brw_compact_inst_src1_index(src
)];
744 brw_inst_set_bits(dst
, 120, 109, uncompacted
);
749 brw_uncompact_instruction(struct brw_context
*brw
, brw_inst
*dst
,
750 brw_compact_inst
*src
)
752 memset(dst
, 0, sizeof(*dst
));
754 brw_inst_set_opcode(brw
, dst
, brw_compact_inst_opcode(src
));
755 brw_inst_set_debug_control(brw
, dst
, brw_compact_inst_debug_control(src
));
757 set_uncompacted_control(brw
, dst
, src
);
758 set_uncompacted_datatype(brw
, dst
, src
);
760 /* src0/1 register file fields are in the datatype table. */
761 bool is_immediate
= brw_inst_src0_reg_file(brw
, dst
) == BRW_IMMEDIATE_VALUE
||
762 brw_inst_src1_reg_file(brw
, dst
) == BRW_IMMEDIATE_VALUE
;
764 set_uncompacted_subreg(brw
, dst
, src
);
765 brw_inst_set_acc_wr_control(brw
, dst
, brw_compact_inst_acc_wr_control(src
));
766 brw_inst_set_cond_modifier(brw
, dst
, brw_compact_inst_cond_modifier(src
));
768 brw_inst_set_flag_subreg_nr(brw
, dst
,
769 brw_compact_inst_flag_subreg_nr(src
));
770 set_uncompacted_src0(brw
, dst
, src
);
771 set_uncompacted_src1(brw
, dst
, src
, is_immediate
);
772 brw_inst_set_dst_da_reg_nr(brw
, dst
, brw_compact_inst_dst_reg_nr(src
));
773 brw_inst_set_src0_da_reg_nr(brw
, dst
, brw_compact_inst_src0_reg_nr(src
));
775 brw_inst_set_imm_ud(brw
, dst
,
776 brw_inst_imm_ud(brw
, dst
) |
777 brw_compact_inst_src1_reg_nr(src
));
779 brw_inst_set_src1_da_reg_nr(brw
, dst
, brw_compact_inst_src1_reg_nr(src
));
783 void brw_debug_compact_uncompact(struct brw_context
*brw
,
785 brw_inst
*uncompacted
)
787 fprintf(stderr
, "Instruction compact/uncompact changed (gen%d):\n",
790 fprintf(stderr
, " before: ");
791 brw_disassemble_inst(stderr
, brw
, orig
, true);
793 fprintf(stderr
, " after: ");
794 brw_disassemble_inst(stderr
, brw
, uncompacted
, false);
796 uint32_t *before_bits
= (uint32_t *)orig
;
797 uint32_t *after_bits
= (uint32_t *)uncompacted
;
798 fprintf(stderr
, " changed bits:\n");
799 for (int i
= 0; i
< 128; i
++) {
800 uint32_t before
= before_bits
[i
/ 32] & (1 << (i
& 31));
801 uint32_t after
= after_bits
[i
/ 32] & (1 << (i
& 31));
803 if (before
!= after
) {
804 fprintf(stderr
, " bit %d, %s to %s\n", i
,
805 before
? "set" : "unset",
806 after
? "set" : "unset");
812 compacted_between(int old_ip
, int old_target_ip
, int *compacted_counts
)
814 int this_compacted_count
= compacted_counts
[old_ip
];
815 int target_compacted_count
= compacted_counts
[old_target_ip
];
816 return target_compacted_count
- this_compacted_count
;
820 update_uip_jip(struct brw_context
*brw
, brw_inst
*insn
,
821 int this_old_ip
, int *compacted_counts
)
823 int scale
= brw
->gen
>= 8 ? sizeof(brw_compact_inst
) : 1;
825 int32_t jip
= brw_inst_jip(brw
, insn
);
827 compacted_between(this_old_ip
, this_old_ip
+ jip
, compacted_counts
);
828 brw_inst_set_jip(brw
, insn
, jip
);
830 if (brw_inst_opcode(brw
, insn
) == BRW_OPCODE_ENDIF
||
831 brw_inst_opcode(brw
, insn
) == BRW_OPCODE_WHILE
)
834 int32_t uip
= brw_inst_uip(brw
, insn
);
836 compacted_between(this_old_ip
, this_old_ip
+ uip
, compacted_counts
);
837 brw_inst_set_uip(brw
, insn
, uip
);
841 brw_init_compaction_tables(struct brw_context
*brw
)
843 assert(gen6_control_index_table
[ARRAY_SIZE(gen6_control_index_table
) - 1] != 0);
844 assert(gen6_datatype_table
[ARRAY_SIZE(gen6_datatype_table
) - 1] != 0);
845 assert(gen6_subreg_table
[ARRAY_SIZE(gen6_subreg_table
) - 1] != 0);
846 assert(gen6_src_index_table
[ARRAY_SIZE(gen6_src_index_table
) - 1] != 0);
847 assert(gen7_control_index_table
[ARRAY_SIZE(gen7_control_index_table
) - 1] != 0);
848 assert(gen7_datatype_table
[ARRAY_SIZE(gen7_datatype_table
) - 1] != 0);
849 assert(gen7_subreg_table
[ARRAY_SIZE(gen7_subreg_table
) - 1] != 0);
850 assert(gen7_src_index_table
[ARRAY_SIZE(gen7_src_index_table
) - 1] != 0);
851 assert(gen8_control_index_table
[ARRAY_SIZE(gen8_control_index_table
) - 1] != 0);
852 assert(gen8_datatype_table
[ARRAY_SIZE(gen8_datatype_table
) - 1] != 0);
853 assert(gen8_subreg_table
[ARRAY_SIZE(gen8_subreg_table
) - 1] != 0);
854 assert(gen8_src_index_table
[ARRAY_SIZE(gen8_src_index_table
) - 1] != 0);
858 control_index_table
= gen8_control_index_table
;
859 datatype_table
= gen8_datatype_table
;
860 subreg_table
= gen8_subreg_table
;
861 src_index_table
= gen8_src_index_table
;
864 control_index_table
= gen7_control_index_table
;
865 datatype_table
= gen7_datatype_table
;
866 subreg_table
= gen7_subreg_table
;
867 src_index_table
= gen7_src_index_table
;
870 control_index_table
= gen6_control_index_table
;
871 datatype_table
= gen6_datatype_table
;
872 subreg_table
= gen6_subreg_table
;
873 src_index_table
= gen6_src_index_table
;
881 brw_compact_instructions(struct brw_compile
*p
, int start_offset
,
882 int num_annotations
, struct annotation
*annotation
)
884 struct brw_context
*brw
= p
->brw
;
885 void *store
= p
->store
+ start_offset
/ 16;
886 /* For an instruction at byte offset 8*i before compaction, this is the number
887 * of compacted instructions that preceded it.
889 int compacted_counts
[(p
->next_insn_offset
- start_offset
) / 8];
890 /* For an instruction at byte offset 8*i after compaction, this is the
891 * 8-byte offset it was at before compaction.
893 int old_ip
[(p
->next_insn_offset
- start_offset
) / 8];
895 if (brw
->gen
< 6 || brw
->gen
>= 8)
900 int compacted_count
= 0;
901 for (src_offset
= 0; src_offset
< p
->next_insn_offset
- start_offset
;) {
902 brw_inst
*src
= store
+ src_offset
;
903 void *dst
= store
+ offset
;
905 old_ip
[offset
/ 8] = src_offset
/ 8;
906 compacted_counts
[src_offset
/ 8] = compacted_count
;
908 brw_inst saved
= *src
;
910 if (!brw_inst_cmpt_control(brw
, src
) &&
911 brw_try_compact_instruction(brw
, dst
, src
)) {
915 brw_inst uncompacted
;
916 brw_uncompact_instruction(brw
, &uncompacted
, dst
);
917 if (memcmp(&saved
, &uncompacted
, sizeof(uncompacted
))) {
918 brw_debug_compact_uncompact(brw
, &saved
, &uncompacted
);
925 int size
= brw_inst_cmpt_control(brw
, src
) ? 8 : 16;
927 /* It appears that the end of thread SEND instruction needs to be
928 * aligned, or the GPU hangs.
930 if ((brw_inst_opcode(brw
, src
) == BRW_OPCODE_SEND
||
931 brw_inst_opcode(brw
, src
) == BRW_OPCODE_SENDC
) &&
932 brw_inst_eot(brw
, src
) &&
934 brw_compact_inst
*align
= store
+ offset
;
935 memset(align
, 0, sizeof(*align
));
936 brw_compact_inst_set_opcode(align
, BRW_OPCODE_NOP
);
937 brw_compact_inst_set_cmpt_control(align
, true);
939 old_ip
[offset
/ 8] = src_offset
/ 8;
940 dst
= store
+ offset
;
943 /* If we didn't compact this intruction, we need to move it down into
946 if (offset
!= src_offset
) {
947 memmove(dst
, src
, size
);
954 /* Fix up control flow offsets. */
955 p
->next_insn_offset
= start_offset
+ offset
;
956 for (offset
= 0; offset
< p
->next_insn_offset
- start_offset
;) {
957 brw_inst
*insn
= store
+ offset
;
958 int this_old_ip
= old_ip
[offset
/ 8];
959 int this_compacted_count
= compacted_counts
[this_old_ip
];
960 int target_old_ip
, target_compacted_count
;
962 switch (brw_inst_opcode(brw
, insn
)) {
963 case BRW_OPCODE_BREAK
:
964 case BRW_OPCODE_CONTINUE
:
965 case BRW_OPCODE_HALT
:
966 update_uip_jip(brw
, insn
, this_old_ip
, compacted_counts
);
970 case BRW_OPCODE_ELSE
:
971 case BRW_OPCODE_ENDIF
:
972 case BRW_OPCODE_WHILE
:
974 update_uip_jip(brw
, insn
, this_old_ip
, compacted_counts
);
975 } else if (brw
->gen
== 6) {
976 int gen6_jump_count
= brw_inst_gen6_jump_count(brw
, insn
);
977 target_old_ip
= this_old_ip
+ gen6_jump_count
;
978 target_compacted_count
= compacted_counts
[target_old_ip
];
979 gen6_jump_count
-= (target_compacted_count
- this_compacted_count
);
980 brw_inst_set_gen6_jump_count(brw
, insn
, gen6_jump_count
);
985 offset
= next_offset(brw
, store
, offset
);
988 /* p->nr_insn is counting the number of uncompacted instructions still, so
989 * divide. We do want to be sure there's a valid instruction in any
990 * alignment padding, so that the next compression pass (for the FS 8/16
991 * compile passes) parses correctly.
993 if (p
->next_insn_offset
& 8) {
994 brw_compact_inst
*align
= store
+ offset
;
995 memset(align
, 0, sizeof(*align
));
996 brw_compact_inst_set_opcode(align
, BRW_OPCODE_NOP
);
997 brw_compact_inst_set_cmpt_control(align
, true);
998 p
->next_insn_offset
+= 8;
1000 p
->nr_insn
= p
->next_insn_offset
/ 16;
1002 /* Update the instruction offsets for each annotation. */
1004 for (int offset
= 0, i
= 0; i
< num_annotations
; i
++) {
1005 while (start_offset
+ old_ip
[offset
/ 8] * 8 != annotation
[i
].offset
) {
1006 assert(start_offset
+ old_ip
[offset
/ 8] * 8 <
1007 annotation
[i
].offset
);
1008 offset
= next_offset(brw
, store
, offset
);
1011 annotation
[i
].offset
= start_offset
+ offset
;
1013 offset
= next_offset(brw
, store
, offset
);
1016 annotation
[num_annotations
].offset
= p
->next_insn_offset
;