nir/lower_double_ops: lower fract()
authorIago Toral Quiroga <itoral@igalia.com>
Tue, 5 Jan 2016 08:14:51 +0000 (09:14 +0100)
committerSamuel Iglesias Gonsálvez <siglesias@igalia.com>
Thu, 28 Apr 2016 10:01:40 +0000 (12:01 +0200)
At least i965 hardware does not have native support for fract() on doubles.

Reviewed-by: Jason Ekstrand <jason@jlekstrand.net>
src/compiler/nir/nir.h
src/compiler/nir/nir_lower_double_ops.c

index 252567ceae50d27f0b146fc6f1839d5dd5c8bec5..ac96727cad68179dd083af0299257f35c81d177d 100644 (file)
@@ -2420,6 +2420,7 @@ typedef enum {
    nir_lower_dtrunc = (1 << 3),
    nir_lower_dfloor = (1 << 4),
    nir_lower_dceil = (1 << 5),
+   nir_lower_dfract = (1 << 6)
 } nir_lower_doubles_options;
 
 void nir_lower_doubles(nir_shader *shader, nir_lower_doubles_options options);
index 2d94f78ec4ebb6702e924f4dd9e5db808101fc1a..f1fa2c3fd2df7b6064b0a3dba35f006c607b85d7 100644 (file)
@@ -383,6 +383,12 @@ lower_ceil(nir_builder *b, nir_ssa_def *src)
                     nir_fadd(b, tr, nir_imm_double(b, 1.0)));
 }
 
+static nir_ssa_def *
+lower_fract(nir_builder *b, nir_ssa_def *src)
+{
+   return nir_fsub(b, src, nir_ffloor(b, src));
+}
+
 static void
 lower_doubles_instr(nir_alu_instr *instr, nir_lower_doubles_options options)
 {
@@ -421,6 +427,11 @@ lower_doubles_instr(nir_alu_instr *instr, nir_lower_doubles_options options)
          return;
       break;
 
+   case nir_op_ffract:
+      if (!(options & nir_lower_dfract))
+         return;
+      break;
+
    default:
       return;
    }
@@ -453,6 +464,9 @@ lower_doubles_instr(nir_alu_instr *instr, nir_lower_doubles_options options)
    case nir_op_fceil:
       result = lower_ceil(&bld, src);
       break;
+   case nir_op_ffract:
+      result = lower_fract(&bld, src);
+      break;
    default:
       unreachable("unhandled opcode");
    }