2 * Copyright (C) 2020 Collabora Ltd.
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 FROM,
20 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
23 * Authors (Collabora):
24 * Alyssa Rosenzweig <alyssa.rosenzweig@collabora.com>
29 /* Does an instruction respect outmods and source mods? Depend
30 * on the types involved */
33 bi_has_outmod(bi_instruction
*ins
)
35 bool classy
= bi_class_props
[ins
->type
] & BI_MODS
;
36 bool floaty
= nir_alu_type_get_base_type(ins
->dest_type
) == nir_type_float
;
38 return classy
&& floaty
;
41 /* Technically we should check the source type, not the dest
42 * type, but the type converting opcodes (i2f, f2i) don't
43 * actually support mods so it doesn't matter. */
46 bi_has_source_mods(bi_instruction
*ins
)
48 return bi_has_outmod(ins
);
51 /* A source is swizzled if the op is swizzlable, in 8-bit or
52 * 16-bit mode, and the swizzled op. TODO: multi args */
55 bi_is_src_swizzled(bi_instruction
*ins
, unsigned s
)
57 bool classy
= bi_class_props
[ins
->type
] & BI_SWIZZLABLE
;
58 bool small
= nir_alu_type_get_type_size(ins
->dest_type
) < 32;
59 bool first
= (s
== 0); /* TODO: prop? */
61 return classy
&& small
&& first
;
65 bi_has_arg(bi_instruction
*ins
, unsigned arg
)
70 bi_foreach_src(ins
, s
) {
71 if (ins
->src
[s
] == arg
)
79 bi_from_bytemask(uint16_t bytemask
, unsigned bytes
)
83 for (unsigned c
= 0, d
= 0; c
< 16; c
+= bytes
, ++d
) {
84 bool a
= (bytemask
& (1 << c
)) != 0;
86 for (unsigned q
= c
; q
< bytes
; ++q
)
87 assert(((bytemask
& (1 << q
)) != 0) == a
);
96 bi_get_component_count(bi_instruction
*ins
)
98 if (bi_class_props
[ins
->type
] & BI_VECTOR
) {
101 /* Stores imply VECTOR */
102 assert(ins
->dest_type
);
103 unsigned bytes
= MAX2(nir_alu_type_get_type_size(ins
->dest_type
), 8);
109 bi_bytemask_of_read_components(bi_instruction
*ins
, unsigned node
)
112 unsigned component_count
= bi_get_component_count(ins
);
114 bi_foreach_src(ins
, s
) {
115 if (ins
->src
[s
] != node
) continue;
116 nir_alu_type T
= ins
->src_types
[s
];
117 unsigned size
= nir_alu_type_get_type_size(T
);
118 unsigned bytes
= (MAX2(size
, 8) / 8);
119 unsigned cmask
= (1 << bytes
) - 1;
121 for (unsigned i
= 0; i
< component_count
; ++i
) {
122 unsigned c
= ins
->swizzle
[s
][i
];
123 mask
|= (cmask
<< (c
* bytes
));