From: Matt Turner Date: Thu, 19 Sep 2013 19:56:10 +0000 (-0700) Subject: glsl: Add ir_binop_carry and ir_binop_borrow. X-Git-Url: https://git.libre-soc.org/?a=commitdiff_plain;h=499d7a7f6e47403a4a3da448eddaf15bdf56395c;p=mesa.git glsl: Add ir_binop_carry and ir_binop_borrow. Calculates the carry out of the addition of two values and the borrow from subtraction respectively. Will be used in uaddCarry() and usubBorrow() built-in implementations. Reviewed-by: Kenneth Graunke Reviewed-by: Ian Romanick --- diff --git a/src/glsl/ir.cpp b/src/glsl/ir.cpp index ae67d6bddec..149ddbd5342 100644 --- a/src/glsl/ir.cpp +++ b/src/glsl/ir.cpp @@ -398,6 +398,8 @@ ir_expression::ir_expression(int op, ir_rvalue *op0, ir_rvalue *op1) this->type = glsl_type::uint_type; break; + case ir_binop_carry: + case ir_binop_borrow: case ir_binop_lshift: case ir_binop_rshift: case ir_binop_bfm: @@ -528,6 +530,8 @@ static const char *const operator_strs[] = { "-", "*", "/", + "carry", + "borrow", "%", "<", ">", diff --git a/src/glsl/ir.h b/src/glsl/ir.h index 1a4a3a2e36b..756ce9c7cd3 100644 --- a/src/glsl/ir.h +++ b/src/glsl/ir.h @@ -1094,6 +1094,21 @@ enum ir_expression_operation { ir_binop_mul, ir_binop_div, + /** + * Returns the carry resulting from the addition of the two arguments. + */ + /*@{*/ + ir_binop_carry, + /*@}*/ + + /** + * Returns the borrow resulting from the subtraction of the second argument + * from the first argument. + */ + /*@{*/ + ir_binop_borrow, + /*@}*/ + /** * Takes one of two combinations of arguments: * diff --git a/src/glsl/ir_builder.cpp b/src/glsl/ir_builder.cpp index 98b43229508..b6ce889834c 100644 --- a/src/glsl/ir_builder.cpp +++ b/src/glsl/ir_builder.cpp @@ -221,6 +221,16 @@ ir_expression *div(operand a, operand b) return expr(ir_binop_div, a, b); } +ir_expression *carry(operand a, operand b) +{ + return expr(ir_binop_carry, a, b); +} + +ir_expression *borrow(operand a, operand b) +{ + return expr(ir_binop_borrow, a, b); +} + ir_expression *round_even(operand a) { return expr(ir_unop_round_even, a); diff --git a/src/glsl/ir_builder.h b/src/glsl/ir_builder.h index 6a5f771193b..1345788ab13 100644 --- a/src/glsl/ir_builder.h +++ b/src/glsl/ir_builder.h @@ -134,6 +134,8 @@ ir_expression *add(operand a, operand b); ir_expression *sub(operand a, operand b); ir_expression *mul(operand a, operand b); ir_expression *div(operand a, operand b); +ir_expression *carry(operand a, operand b); +ir_expression *borrow(operand a, operand b); ir_expression *round_even(operand a); ir_expression *dot(operand a, operand b); ir_expression *dotlike(operand a, operand b); diff --git a/src/glsl/ir_validate.cpp b/src/glsl/ir_validate.cpp index 2c64f4e582a..38db8c20677 100644 --- a/src/glsl/ir_validate.cpp +++ b/src/glsl/ir_validate.cpp @@ -429,6 +429,13 @@ ir_validate::visit_leave(ir_expression *ir) } break; + case ir_binop_carry: + case ir_binop_borrow: + assert(ir->type == ir->operands[0]->type); + assert(ir->type == ir->operands[1]->type); + assert(ir->type->base_type == GLSL_TYPE_UINT); + break; + case ir_binop_less: case ir_binop_greater: case ir_binop_lequal: diff --git a/src/mesa/program/ir_to_mesa.cpp b/src/mesa/program/ir_to_mesa.cpp index 6b22b507415..2f87cfd65c4 100644 --- a/src/mesa/program/ir_to_mesa.cpp +++ b/src/mesa/program/ir_to_mesa.cpp @@ -1497,6 +1497,8 @@ ir_to_mesa_visitor::visit(ir_expression *ir) case ir_quadop_bitfield_insert: case ir_binop_ldexp: case ir_triop_csel: + case ir_binop_carry: + case ir_binop_borrow: assert(!"not supported"); break; diff --git a/src/mesa/state_tracker/st_glsl_to_tgsi.cpp b/src/mesa/state_tracker/st_glsl_to_tgsi.cpp index f11305b590a..f33bea6eb02 100644 --- a/src/mesa/state_tracker/st_glsl_to_tgsi.cpp +++ b/src/mesa/state_tracker/st_glsl_to_tgsi.cpp @@ -1978,6 +1978,8 @@ glsl_to_tgsi_visitor::visit(ir_expression *ir) case ir_binop_vector_extract: case ir_triop_vector_insert: case ir_binop_ldexp: + case ir_binop_carry: + case ir_binop_borrow: /* This operation is not supported, or should have already been handled. */ assert(!"Invalid ir opcode in glsl_to_tgsi_visitor::visit()");