nir/opcodes: Don't go through doubles when constant-folding iabs
authorJason Ekstrand <jason.ekstrand@intel.com>
Mon, 26 Jan 2015 17:40:25 +0000 (09:40 -0800)
committerJason Ekstrand <jason.ekstrand@intel.com>
Mon, 26 Jan 2015 19:25:02 +0000 (11:25 -0800)
Previously, we called the abs() function in math.h.  However, this involves
unnecessarily going through double.  This commit changes it to use integers
directly with a ternary.

Reviewed-by: Connor Abbott <cwabbott0@gmail.com>
Reviewed-by: Eric Anholt <eric@anholt.net>
src/glsl/nir/nir_opcodes.py

index 0fa8bf543da4de7e3b509be35810042232ae1143..f54a0176c0d78a5cba2726adcb78cee41c8424f9 100644 (file)
@@ -147,7 +147,7 @@ unop("inot", tint, "~src0") # invert every bit of the integer
 unop("fnot", tfloat, "(src0 == 0.0f) ? 1.0f : 0.0f")
 unop("fsign", tfloat, "(src0 == 0.0f) ? 0.0f : ((src0 > 0.0f) ? 1.0f : -1.0f)")
 unop("isign", tint, "(src0 == 0) ? 0 : ((src0 > 0) ? 1 : -1)")
-unop("iabs", tint, "abs(src0)")
+unop("iabs", tint, "(src0 < 0) ? -src0 : src0")
 unop("fabs", tfloat, "fabsf(src0)")
 unop("fsat", tfloat, "(src0 > 1.0f) ? 1.0f : ((src0 <= 0.0f) ? 0.0f : src0)")
 unop("frcp", tfloat, "1.0f / src0")