Add sqrt() builtin as an IR operation.
authorEric Anholt <eric@anholt.net>
Sat, 27 Mar 2010 20:01:51 +0000 (13:01 -0700)
committerIan Romanick <ian.d.romanick@intel.com>
Mon, 29 Mar 2010 19:48:45 +0000 (12:48 -0700)
Following a discussion in #dri-devel, I think this makes more sense
than implementing it as RSQ RCP CMP as Mesa did.  The i965 has a
hardware sqrt that should work, and AMD is suppposed to be able to
implement it as RSQ RCP with an alternate floating point mode so that
the 0.0 case is handled like we want.

builtin_function.cpp
ir.h
ir_print_visitor.cpp

index ec1b54a2dd54d7ed2610ad286225c0e24bd368c3..9d231e872b6709696849d6bc3ebf20fd0ddf5a29 100644 (file)
@@ -84,6 +84,14 @@ generate_rsq(exec_list *instructions,
    generate_unop(instructions, declarations, type, ir_unop_rsq);
 }
 
+static void
+generate_sqrt(exec_list *instructions,
+              ir_variable **declarations,
+              const glsl_type *type)
+{
+   generate_unop(instructions, declarations, type, ir_unop_sqrt);
+}
+
 static void
 generate_abs(exec_list *instructions,
             ir_variable **declarations,
@@ -227,7 +235,7 @@ generate_110_functions(glsl_symbol_table *symtab, exec_list *instructions)
    make_gentype_function(symtab, instructions, "log", 1, generate_log);
    /* FINISHME: exp2() */
    /* FINISHME: log2() */
-   /* FINISHME: sqrt() */
+   make_gentype_function(symtab, instructions, "sqrt", 1, generate_sqrt);
    make_gentype_function(symtab, instructions, "inversesqrt", 1, generate_rsq);
    make_gentype_function(symtab, instructions, "abs", 1, generate_abs);
    /* FINISHME: sign() */
diff --git a/ir.h b/ir.h
index bad5111b5a8d03e19ab090cefc3af493891bd28b..45905289485028ee599287606813cfdcdfdfbed6 100644 (file)
--- a/ir.h
+++ b/ir.h
@@ -225,6 +225,7 @@ enum ir_expression_operation {
    ir_unop_abs,
    ir_unop_rcp,
    ir_unop_rsq,
+   ir_unop_sqrt,
    ir_unop_exp,
    ir_unop_log,
    ir_unop_f2i,      /**< Float-to-integer conversion. */
index ecfdb49c480d2275834d06ad346657ac53b3635e..8b2080f7ec520c266fb04ab73afed8c606eb135e 100644 (file)
@@ -93,6 +93,7 @@ void ir_print_visitor::visit(ir_expression *ir)
       "abs",
       "rcp",
       "rsq",
+      "sqrt",
       "exp",
       "log",
       "f2i",