i965/vs: Implement integer quotient and remainder math operations.
authorKenneth Graunke <kenneth@whitecape.org>
Thu, 29 Sep 2011 00:37:55 +0000 (17:37 -0700)
committerKenneth Graunke <kenneth@whitecape.org>
Mon, 3 Oct 2011 00:01:11 +0000 (17:01 -0700)
Signed-off-by: Kenneth Graunke <kenneth@whitecape.org>
Tested-by: Ian Romanick <ian.d.romanick@intel.com>
Reviewed-by: Ian Romanick <ian.d.romanick@intel.com>
Reviewed-by: Eric Anholt <eric@anholt.net>
src/mesa/drivers/dri/i965/brw_vec4.cpp
src/mesa/drivers/dri/i965/brw_vec4_emit.cpp
src/mesa/drivers/dri/i965/brw_vec4_visitor.cpp

index a3da5e3b93bae37748a723a3e30d3289bb2961d1..54ef9b6f0d4c896d577e829baba6e3d3630fd679 100644 (file)
@@ -41,6 +41,8 @@ vec4_instruction::is_math()
           opcode == SHADER_OPCODE_LOG2 ||
           opcode == SHADER_OPCODE_SIN ||
           opcode == SHADER_OPCODE_COS ||
+          opcode == SHADER_OPCODE_INT_QUOTIENT ||
+          opcode == SHADER_OPCODE_INT_REMAINDER ||
           opcode == SHADER_OPCODE_POW);
 }
 /**
index 3feecbf805de32f64831d78afb54ed29a43158ec..c080dfd48b4253bb460b34a51b6a162f6d2844b3 100644 (file)
@@ -307,7 +307,7 @@ vec4_visitor::generate_math2_gen4(vec4_instruction *inst,
                                  struct brw_reg src0,
                                  struct brw_reg src1)
 {
-   brw_MOV(p, brw_message_reg(inst->base_mrf + 1), src1);
+   brw_MOV(p, retype(brw_message_reg(inst->base_mrf + 1), src1.type), src1);
 
    brw_math(p,
            dst,
@@ -544,6 +544,8 @@ vec4_visitor::generate_vs_instruction(vec4_instruction *instruction,
       break;
 
    case SHADER_OPCODE_POW:
+   case SHADER_OPCODE_INT_QUOTIENT:
+   case SHADER_OPCODE_INT_REMAINDER:
       if (intel->gen >= 6) {
         generate_math2_gen6(inst, dst, src[0], src[1]);
       } else {
index 94206842399a9f6f21caefd00266593d851f1b39..ad8b43365ad5a3915fac7d442cee60e1d241070e 100644 (file)
@@ -326,10 +326,12 @@ vec4_visitor::emit_math2_gen6(enum opcode opcode,
     */
 
    expanded = src_reg(this, glsl_type::vec4_type);
+   expanded.type = src0.type;
    emit(MOV(dst_reg(expanded), src0));
    src0 = expanded;
 
    expanded = src_reg(this, glsl_type::vec4_type);
+   expanded.type = src1.type;
    emit(MOV(dst_reg(expanded), src1));
    src1 = expanded;
 
@@ -338,6 +340,7 @@ vec4_visitor::emit_math2_gen6(enum opcode opcode,
        * writemasks.
        */
       dst_reg temp_dst = dst_reg(this, glsl_type::vec4_type);
+      temp_dst.type = dst.type;
 
       emit(opcode, temp_dst, src0, src1);
 
@@ -360,7 +363,15 @@ void
 vec4_visitor::emit_math(enum opcode opcode,
                        dst_reg dst, src_reg src0, src_reg src1)
 {
-   assert(opcode == SHADER_OPCODE_POW);
+   switch (opcode) {
+   case SHADER_OPCODE_POW:
+   case SHADER_OPCODE_INT_QUOTIENT:
+   case SHADER_OPCODE_INT_REMAINDER:
+      break;
+   default:
+      assert(!"not reached: unsupported binary math opcode");
+      return;
+   }
 
    if (intel->gen >= 6) {
       return emit_math2_gen6(opcode, dst, src0, src1);
@@ -1112,9 +1123,14 @@ vec4_visitor::visit(ir_expression *ir)
       }
       break;
    case ir_binop_div:
-      assert(!"not reached: should be handled by ir_div_to_mul_rcp");
+      /* Floating point should be lowered by DIV_TO_MUL_RCP in the compiler. */
+      assert(ir->type->is_integer());
+      emit_math(SHADER_OPCODE_INT_QUOTIENT, result_dst, op[0], op[1]);
+      break;
    case ir_binop_mod:
-      assert(!"ir_binop_mod should have been converted to b * fract(a/b)");
+      /* Floating point should be lowered by MOD_TO_FRACT in the compiler. */
+      assert(ir->type->is_integer());
+      emit_math(SHADER_OPCODE_INT_REMAINDER, result_dst, op[0], op[1]);
       break;
 
    case ir_binop_less: