2 * Copyright © 2014 Broadcom
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
25 * @file vc4_opt_small_immediates.c
27 * Turns references to small constant uniform values into small immediates
37 qir_opt_small_immediates(struct vc4_compile
*c
)
39 bool progress
= false;
40 struct simple_node
*node
;
41 struct qinst
*defs
[c
->num_temps
];
43 foreach(node
, &c
->instructions
) {
44 struct qinst
*inst
= (struct qinst
*)node
;
46 if (inst
->dst
.file
== QFILE_TEMP
)
47 defs
[inst
->dst
.index
] = inst
;
49 /* The small immediate value sits in the raddr B field, so we
50 * can't have 2 small immediates in one instruction (unless
51 * they're the same value, but that should be optimized away
54 bool uses_small_imm
= false;
55 for (int i
= 0; i
< qir_get_op_nsrc(inst
->op
); i
++) {
56 if (inst
->src
[i
].file
== QFILE_SMALL_IMM
)
57 uses_small_imm
= true;
62 for (int i
= 0; i
< qir_get_op_nsrc(inst
->op
); i
++) {
63 struct qreg src
= qir_follow_movs(defs
, inst
->src
[i
]);
65 if (src
.file
!= QFILE_UNIF
||
66 c
->uniform_contents
[src
.index
] !=
72 (inst
->op
== QOP_TEX_S
||
73 inst
->op
== QOP_TEX_T
||
74 inst
->op
== QOP_TEX_R
||
75 inst
->op
== QOP_TEX_B
)) {
76 /* No turning the implicit uniform read into
82 uint32_t imm
= c
->uniform_data
[src
.index
];
83 uint32_t small_imm
= qpu_encode_small_immediate(imm
);
88 fprintf(stderr
, "opt_small_immediate() from: ");
89 qir_dump_inst(c
, inst
);
90 fprintf(stderr
, "\n");
92 inst
->src
[i
].file
= QFILE_SMALL_IMM
;
93 inst
->src
[i
].index
= imm
;
95 fprintf(stderr
, "to: ");
96 qir_dump_inst(c
, inst
);
97 fprintf(stderr
, "\n");