*
*/
+#include <inttypes.h>
#include "nir_search.h"
struct match_state {
static const uint8_t identity_swizzle[] = { 0, 1, 2, 3 };
-static bool alu_instr_is_bool(nir_alu_instr *instr);
-
+/**
+ * Check if a source produces a value of the given type.
+ *
+ * Used for satisfying 'a@type' constraints.
+ */
static bool
-src_is_bool(nir_src src)
+src_is_type(nir_src src, nir_alu_type type)
{
+ assert(type != nir_type_invalid);
+
if (!src.is_ssa)
return false;
- if (src.ssa->parent_instr->type != nir_instr_type_alu)
- return false;
- return alu_instr_is_bool(nir_instr_as_alu(src.ssa->parent_instr));
-}
-static bool
-alu_instr_is_bool(nir_alu_instr *instr)
-{
- switch (instr->op) {
- case nir_op_iand:
- case nir_op_ior:
- case nir_op_ixor:
- return src_is_bool(instr->src[0].src) && src_is_bool(instr->src[1].src);
- case nir_op_inot:
- return src_is_bool(instr->src[0].src);
- default:
- return (nir_alu_type_get_base_type(nir_op_infos[instr->op].output_type)
- == nir_type_bool);
+ /* Turn nir_type_bool32 into nir_type_bool...they're the same thing. */
+ if (nir_alu_type_get_base_type(type) == nir_type_bool)
+ type = nir_type_bool;
+
+ if (src.ssa->parent_instr->type == nir_instr_type_alu) {
+ nir_alu_instr *src_alu = nir_instr_as_alu(src.ssa->parent_instr);
+ nir_alu_type output_type = nir_op_infos[src_alu->op].output_type;
+
+ if (type == nir_type_bool) {
+ switch (src_alu->op) {
+ case nir_op_iand:
+ case nir_op_ior:
+ case nir_op_ixor:
+ return src_is_type(src_alu->src[0].src, nir_type_bool) &&
+ src_is_type(src_alu->src[1].src, nir_type_bool);
+ case nir_op_inot:
+ return src_is_type(src_alu->src[0].src, nir_type_bool);
+ default:
+ break;
+ }
+ }
+
+ return nir_alu_type_get_base_type(output_type) == type;
}
+
+ /* don't know */
+ return false;
}
static bool
for (unsigned i = 0; i < num_components; ++i)
new_swizzle[i] = instr->src[src].swizzle[swizzle[i]];
+ /* If the value has a specific bit size and it doesn't match, bail */
+ if (value->bit_size &&
+ nir_src_bit_size(instr->src[src].src) != value->bit_size)
+ return false;
+
switch (value->type) {
case nir_search_value_expression:
if (!instr->src[src].src.is_ssa)
instr->src[src].src.ssa->parent_instr->type != nir_instr_type_load_const)
return false;
- if (var->type != nir_type_invalid) {
- if (instr->src[src].src.ssa->parent_instr->type != nir_instr_type_alu)
- return false;
-
- nir_alu_instr *src_alu =
- nir_instr_as_alu(instr->src[src].src.ssa->parent_instr);
+ if (var->cond && !var->cond(instr, src, num_components, new_swizzle))
+ return false;
- if (nir_alu_type_get_base_type(nir_op_infos[src_alu->op].output_type) !=
- var->type &&
- !(nir_alu_type_get_base_type(var->type) == nir_type_bool &&
- alu_instr_is_bool(src_alu)))
- return false;
- }
+ if (var->type != nir_type_invalid &&
+ !src_is_type(instr->src[src].src, var->type))
+ return false;
state->variables_seen |= (1 << var->variable);
state->variables[var->variable].src = instr->src[src].src;
assert(instr->dest.dest.is_ssa);
+ if (expr->value.bit_size &&
+ instr->dest.dest.ssa.bit_size != expr->value.bit_size)
+ return false;
+
state->inexact_match = expr->inexact || state->inexact_match;
state->has_exact_alu = instr->exact || state->has_exact_alu;
if (state->inexact_match && state->has_exact_alu)
}
}
+ if (value->bit_size) {
+ assert(!tree->is_dest_sized || tree->dest_size == value->bit_size);
+ tree->common_size = value->bit_size;
+ }
+
return tree;
}
case nir_search_value_constant: {
const nir_search_constant *c = nir_search_value_as_constant(value);
- nir_load_const_instr *load = nir_load_const_instr_create(mem_ctx, 1);
+ nir_load_const_instr *load =
+ nir_load_const_instr_create(mem_ctx, 1, bitsize->dest_size);
switch (c->type) {
case nir_type_float:
break;
case nir_type_int:
- load->def.name = ralloc_asprintf(load, "%ld", c->data.i);
+ load->def.name = ralloc_asprintf(load, "%" PRIi64, c->data.i);
switch (bitsize->dest_size) {
case 32:
load->value.i32[0] = c->data.i;
break;
case nir_type_uint:
- load->def.name = ralloc_asprintf(load, "%lu", c->data.u);
+ load->def.name = ralloc_asprintf(load, "%" PRIu64, c->data.u);
switch (bitsize->dest_size) {
case 32:
load->value.u32[0] = c->data.u;
default:
unreachable("unknown bit size");
}
+ break;
case nir_type_bool32:
load->value.u32[0] = c->data.u;
unreachable("Invalid alu source type");
}
- load->def.bit_size = bitsize->dest_size;
-
nir_instr_insert_before(instr, &load->instr);
nir_alu_src val;