nv50/ir/gk110: add implementations of div u32/s32
[mesa.git] / src / glsl / ir_equals.cpp
1 /*
2 * Copyright © 2013 Intel Corporation
3 *
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:
10 *
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
13 * Software.
14 *
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
21 * DEALINGS IN THE SOFTWARE.
22 */
23
24 #include "ir.h"
25
26 /**
27 * Helper for checking equality when one instruction might be NULL, since you
28 * can't access a's vtable in that case.
29 */
30 static bool
31 possibly_null_equals(ir_instruction *a, ir_instruction *b, enum ir_node_type ignore)
32 {
33 if (!a || !b)
34 return !a && !b;
35
36 return a->equals(b, ignore);
37 }
38
39 /**
40 * The base equality function: Return not equal for anything we don't know
41 * about.
42 */
43 bool
44 ir_instruction::equals(ir_instruction *ir, enum ir_node_type)
45 {
46 return false;
47 }
48
49 bool
50 ir_constant::equals(ir_instruction *ir, enum ir_node_type ignore)
51 {
52 const ir_constant *other = ir->as_constant();
53 if (!other)
54 return false;
55
56 if (type != other->type)
57 return false;
58
59 for (unsigned i = 0; i < type->components(); i++) {
60 if (value.u[i] != other->value.u[i])
61 return false;
62 }
63
64 return true;
65 }
66
67 bool
68 ir_dereference_variable::equals(ir_instruction *ir, enum ir_node_type ignore)
69 {
70 const ir_dereference_variable *other = ir->as_dereference_variable();
71 if (!other)
72 return false;
73
74 return var == other->var;
75 }
76
77 bool
78 ir_dereference_array::equals(ir_instruction *ir, enum ir_node_type ignore)
79 {
80 const ir_dereference_array *other = ir->as_dereference_array();
81 if (!other)
82 return false;
83
84 if (type != other->type)
85 return false;
86
87 if (!array->equals(other->array, ignore))
88 return false;
89
90 if (!array_index->equals(other->array_index, ignore))
91 return false;
92
93 return true;
94 }
95
96 bool
97 ir_swizzle::equals(ir_instruction *ir, enum ir_node_type ignore)
98 {
99 const ir_swizzle *other = ir->as_swizzle();
100 if (!other)
101 return false;
102
103 if (type != other->type)
104 return false;
105
106 if (ignore != ir_type_swizzle) {
107 if (mask.x != other->mask.x ||
108 mask.y != other->mask.y ||
109 mask.z != other->mask.z ||
110 mask.w != other->mask.w) {
111 return false;
112 }
113 }
114
115 return val->equals(other->val, ignore);
116 }
117
118 bool
119 ir_texture::equals(ir_instruction *ir, enum ir_node_type ignore)
120 {
121 const ir_texture *other = ir->as_texture();
122 if (!other)
123 return false;
124
125 if (type != other->type)
126 return false;
127
128 if (op != other->op)
129 return false;
130
131 if (!possibly_null_equals(coordinate, other->coordinate, ignore))
132 return false;
133
134 if (!possibly_null_equals(projector, other->projector, ignore))
135 return false;
136
137 if (!possibly_null_equals(shadow_comparitor, other->shadow_comparitor, ignore))
138 return false;
139
140 if (!possibly_null_equals(offset, other->offset, ignore))
141 return false;
142
143 if (!sampler->equals(other->sampler, ignore))
144 return false;
145
146 switch (op) {
147 case ir_tex:
148 case ir_lod:
149 case ir_query_levels:
150 break;
151 case ir_txb:
152 if (!lod_info.bias->equals(other->lod_info.bias, ignore))
153 return false;
154 break;
155 case ir_txl:
156 case ir_txf:
157 case ir_txs:
158 if (!lod_info.lod->equals(other->lod_info.lod, ignore))
159 return false;
160 break;
161 case ir_txd:
162 if (!lod_info.grad.dPdx->equals(other->lod_info.grad.dPdx, ignore) ||
163 !lod_info.grad.dPdy->equals(other->lod_info.grad.dPdy, ignore))
164 return false;
165 break;
166 case ir_txf_ms:
167 if (!lod_info.sample_index->equals(other->lod_info.sample_index, ignore))
168 return false;
169 break;
170 case ir_tg4:
171 if (!lod_info.component->equals(other->lod_info.component, ignore))
172 return false;
173 break;
174 default:
175 assert(!"Unrecognized texture op");
176 }
177
178 return true;
179 }
180
181 bool
182 ir_expression::equals(ir_instruction *ir, enum ir_node_type ignore)
183 {
184 const ir_expression *other = ir->as_expression();
185 if (!other)
186 return false;
187
188 if (type != other->type)
189 return false;
190
191 if (operation != other->operation)
192 return false;
193
194 for (unsigned i = 0; i < get_num_operands(); i++) {
195 if (!operands[i]->equals(other->operands[i], ignore))
196 return false;
197 }
198
199 return true;
200 }