2 * Copyright © 2016 Red Hat
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 * Rob Clark <robclark@freedesktop.org>
27 #ifndef _NIR_SEARCH_HELPERS_
28 #define _NIR_SEARCH_HELPERS_
31 #include "util/bitscan.h"
34 is_pos_power_of_two(nir_alu_instr
*instr
, unsigned src
, unsigned num_components
,
35 const uint8_t *swizzle
)
37 nir_const_value
*val
= nir_src_as_const_value(instr
->src
[src
].src
);
39 /* only constant srcs: */
43 for (unsigned i
= 0; i
< num_components
; i
++) {
44 switch (nir_op_infos
[instr
->op
].input_types
[src
]) {
46 if (val
->i32
[swizzle
[i
]] < 0)
48 if (!util_is_power_of_two_nonzero(val
->i32
[swizzle
[i
]]))
52 if (!util_is_power_of_two_nonzero(val
->u32
[swizzle
[i
]]))
64 is_neg_power_of_two(nir_alu_instr
*instr
, unsigned src
, unsigned num_components
,
65 const uint8_t *swizzle
)
67 nir_const_value
*val
= nir_src_as_const_value(instr
->src
[src
].src
);
69 /* only constant srcs: */
73 for (unsigned i
= 0; i
< num_components
; i
++) {
74 switch (nir_op_infos
[instr
->op
].input_types
[src
]) {
76 if (val
->i32
[swizzle
[i
]] > 0)
78 if (!util_is_power_of_two_nonzero(abs(val
->i32
[swizzle
[i
]])))
90 is_zero_to_one(nir_alu_instr
*instr
, unsigned src
, unsigned num_components
,
91 const uint8_t *swizzle
)
93 nir_const_value
*val
= nir_src_as_const_value(instr
->src
[src
].src
);
98 for (unsigned i
= 0; i
< num_components
; i
++) {
99 switch (nir_op_infos
[instr
->op
].input_types
[src
]) {
101 if (val
->f32
[swizzle
[i
]] < 0.0f
|| val
->f32
[swizzle
[i
]] > 1.0f
)
113 is_not_const(nir_alu_instr
*instr
, unsigned src
, UNUSED
unsigned num_components
,
114 UNUSED
const uint8_t *swizzle
)
116 nir_const_value
*val
= nir_src_as_const_value(instr
->src
[src
].src
);
125 is_used_more_than_once(nir_alu_instr
*instr
)
127 bool zero_if_use
= list_empty(&instr
->dest
.dest
.ssa
.if_uses
);
128 bool zero_use
= list_empty(&instr
->dest
.dest
.ssa
.uses
);
130 if (zero_use
&& zero_if_use
)
132 else if (zero_use
&& list_is_singular(&instr
->dest
.dest
.ssa
.if_uses
))
134 else if (zero_if_use
&& list_is_singular(&instr
->dest
.dest
.ssa
.uses
))
141 is_used_once(nir_alu_instr
*instr
)
143 bool zero_if_use
= list_empty(&instr
->dest
.dest
.ssa
.if_uses
);
144 bool zero_use
= list_empty(&instr
->dest
.dest
.ssa
.uses
);
146 if (zero_if_use
&& zero_use
)
149 if (!zero_if_use
&& list_is_singular(&instr
->dest
.dest
.ssa
.uses
))
152 if (!zero_use
&& list_is_singular(&instr
->dest
.dest
.ssa
.if_uses
))
155 if (!list_is_singular(&instr
->dest
.dest
.ssa
.if_uses
) &&
156 !list_is_singular(&instr
->dest
.dest
.ssa
.uses
))
163 is_not_used_by_if(nir_alu_instr
*instr
)
165 return list_empty(&instr
->dest
.dest
.ssa
.if_uses
);
168 #endif /* _NIR_SEARCH_ */