summaryrefslogtreecommitdiffstats
path: root/src/compiler/glsl/ir_expression_operation.py
diff options
context:
space:
mode:
authorIan Romanick <ian.d.romanick@intel.com>2016-07-12 11:29:21 -0700
committerIan Romanick <ian.d.romanick@intel.com>2016-08-30 16:28:02 -0700
commit13106e1041c254a80c7e2df392efea93dcbb215f (patch)
treef2cd08f1ac9687e0eb5eb6f2ed9adf39541a0f0f /src/compiler/glsl/ir_expression_operation.py
parent90da8bf5477cb65b9f2e5148c05ef621a09b704f (diff)
downloadexternal_mesa3d-13106e1041c254a80c7e2df392efea93dcbb215f.zip
external_mesa3d-13106e1041c254a80c7e2df392efea93dcbb215f.tar.gz
external_mesa3d-13106e1041c254a80c7e2df392efea93dcbb215f.tar.bz2
glsl: Generate code for constant ir_binop_lshift and ir_binop_rshift expressions
The code generated is quite different from what was previously used. I believe that it is still correct by the GLSL spec, and I believe, due to C rules about shifts, the behavior will be the same. Section 5.9 (Expressions) of the GLSL 4.50 spec says: The result is undefined if the right operand is negative, or greater than or equal to the number of bits in the left expression's base type. Signed-off-by: Ian Romanick <ian.d.romanick@intel.com> Reviewed-by: Matt Turner <mattst88@gmail.com> Acked-by: Dylan Baker <dylan@pnwbakers.com>
Diffstat (limited to 'src/compiler/glsl/ir_expression_operation.py')
-rw-r--r--src/compiler/glsl/ir_expression_operation.py15
1 files changed, 13 insertions, 2 deletions
diff --git a/src/compiler/glsl/ir_expression_operation.py b/src/compiler/glsl/ir_expression_operation.py
index b3f60a4..1cb9734 100644
--- a/src/compiler/glsl/ir_expression_operation.py
+++ b/src/compiler/glsl/ir_expression_operation.py
@@ -163,7 +163,17 @@ constant_template5 = mako.template.Template("""\
# of scalar and vector operands.
constant_template_vector_scalar = mako.template.Template("""\
case ${op.get_enum_name()}:
+ % if "mixed" in op.flags:
+ % for i in xrange(op.num_operands):
+ assert(op[${i}]->type->base_type == ${op.source_types[0].glsl_type} ||
+ % for src_type in op.source_types[1:-1]:
+ op[${i}]->type->base_type == ${src_type.glsl_type} ||
+ % endfor
+ op[${i}]->type->base_type == ${op.source_types[-1].glsl_type});
+ % endfor
+ % else:
assert(op[0]->type == op[1]->type || op0_scalar || op1_scalar);
+ % endif
for (unsigned c = 0, c0 = 0, c1 = 0;
c < components;
c0 += c0_inc, c1 += c1_inc, c++) {
@@ -200,6 +210,7 @@ vector_scalar_operation = "vector-scalar"
horizontal_operation = "horizontal"
types_identical_operation = "identical"
non_assign_operation = "nonassign"
+mixed_type_operation = "mixed"
class operation(object):
def __init__(self, name, num_operands, printable_name = None, source_types = None, dest_type = None, c_expression = None, flags = None, all_signatures = None):
@@ -457,8 +468,8 @@ ir_expression_operation = [
operation("any_nequal", 2, source_types=all_types, dest_type=bool_type, c_expression="!op[0]->has_value(op[1])", flags=frozenset((horizontal_operation, types_identical_operation))),
# Bit-wise binary operations.
- operation("lshift", 2, printable_name="<<"),
- operation("rshift", 2, printable_name=">>"),
+ operation("lshift", 2, printable_name="<<", source_types=integer_types, c_expression="{src0} << {src1}", flags=frozenset((vector_scalar_operation, mixed_type_operation))),
+ operation("rshift", 2, printable_name=">>", source_types=integer_types, c_expression="{src0} >> {src1}", flags=frozenset((vector_scalar_operation, mixed_type_operation))),
operation("bit_and", 2, printable_name="&", source_types=integer_types, c_expression="{src0} & {src1}", flags=vector_scalar_operation),
operation("bit_xor", 2, printable_name="^", source_types=integer_types, c_expression="{src0} ^ {src1}", flags=vector_scalar_operation),
operation("bit_or", 2, printable_name="|", source_types=integer_types, c_expression="{src0} | {src1}", flags=vector_scalar_operation),