nir: Expose double and int64 op_to_options_mask helpers
authorJason Ekstrand <jason.ekstrand@intel.com>
Fri, 1 Mar 2019 23:39:54 +0000 (17:39 -0600)
committerJason Ekstrand <jason@jlekstrand.net>
Wed, 6 Mar 2019 17:24:57 +0000 (17:24 +0000)
We already have one internally for int64 but we don't have a similar one
for doubles so we'll have to make one.

Reviewed-by: Matt Turner <mattst88@gmail.com>
Reviewed-by: Jordan Justen <jordan.l.justen@intel.com>
Reviewed-by: Kenneth Graunke <kenneth@whitecape.org>
src/compiler/nir/nir.h
src/compiler/nir/nir_lower_double_ops.c
src/compiler/nir/nir_lower_int64.c

index 0d5b70b1c34c2bddfe32e2c61720706fcdff8e1d..3e1714ec5d2ea181de6efbad042fe593bd4dbf5a 100644 (file)
@@ -3271,8 +3271,10 @@ bool nir_lower_bit_size(nir_shader *shader,
                         nir_lower_bit_size_callback callback,
                         void *callback_data);
 
+nir_lower_int64_options nir_lower_int64_op_to_options_mask(nir_op opcode);
 bool nir_lower_int64(nir_shader *shader, nir_lower_int64_options options);
 
+nir_lower_doubles_options nir_lower_doubles_op_to_options_mask(nir_op opcode);
 bool nir_lower_doubles(nir_shader *shader, nir_lower_doubles_options options);
 bool nir_lower_pack(nir_shader *shader);
 
index 054fce9c168219508ff283226b515304a3379fbb..69f4b3a78db3db68bbe5c9ac1dc30610e71b4b75 100644 (file)
@@ -589,6 +589,23 @@ lower_doubles_instr_to_soft(nir_builder *b, nir_alu_instr *instr,
    return true;
 }
 
+nir_lower_doubles_options
+nir_lower_doubles_op_to_options_mask(nir_op opcode)
+{
+   switch (opcode) {
+   case nir_op_frcp:          return nir_lower_drcp;
+   case nir_op_fsqrt:         return nir_lower_dsqrt;
+   case nir_op_frsq:          return nir_lower_drsq;
+   case nir_op_ftrunc:        return nir_lower_dtrunc;
+   case nir_op_ffloor:        return nir_lower_dfloor;
+   case nir_op_fceil:         return nir_lower_dceil;
+   case nir_op_ffract:        return nir_lower_dfract;
+   case nir_op_fround_even:   return nir_lower_dround_even;
+   case nir_op_fmod:          return nir_lower_dmod;
+   default:                   return 0;
+   }
+}
+
 static bool
 lower_doubles_instr(nir_builder *b, nir_alu_instr *instr,
                     nir_lower_doubles_options options)
@@ -607,55 +624,8 @@ lower_doubles_instr(nir_builder *b, nir_alu_instr *instr,
    if (lower_doubles_instr_to_soft(b, instr, options))
       return true;
 
-   switch (instr->op) {
-   case nir_op_frcp:
-      if (!(options & nir_lower_drcp))
-         return false;
-      break;
-
-   case nir_op_fsqrt:
-      if (!(options & nir_lower_dsqrt))
-         return false;
-      break;
-
-   case nir_op_frsq:
-      if (!(options & nir_lower_drsq))
-         return false;
-      break;
-
-   case nir_op_ftrunc:
-      if (!(options & nir_lower_dtrunc))
-         return false;
-      break;
-
-   case nir_op_ffloor:
-      if (!(options & nir_lower_dfloor))
-         return false;
-      break;
-
-   case nir_op_fceil:
-      if (!(options & nir_lower_dceil))
-         return false;
-      break;
-
-   case nir_op_ffract:
-      if (!(options & nir_lower_dfract))
-         return false;
-      break;
-
-   case nir_op_fround_even:
-      if (!(options & nir_lower_dround_even))
-         return false;
-      break;
-
-   case nir_op_fmod:
-      if (!(options & nir_lower_dmod))
-         return false;
-      break;
-
-   default:
+   if (!(options & nir_lower_doubles_op_to_options_mask(instr->op)))
       return false;
-   }
 
    b->cursor = nir_before_instr(&instr->instr);
 
index 6aae1816bd24a1a0a73f614370ff061df7754da9..e7d361da6da7aab948d472353127d9351c8b5bc5 100644 (file)
@@ -630,8 +630,8 @@ lower_irem64(nir_builder *b, nir_ssa_def *n, nir_ssa_def *d)
    return nir_bcsel(b, n_is_neg, nir_ineg(b, r), r);
 }
 
-static nir_lower_int64_options
-opcode_to_options_mask(nir_op opcode)
+nir_lower_int64_options
+nir_lower_int64_op_to_options_mask(nir_op opcode)
 {
    switch (opcode) {
    case nir_op_imul:
@@ -834,7 +834,7 @@ lower_int64_impl(nir_function_impl *impl, nir_lower_int64_options options)
             break;
          }
 
-         if (!(options & opcode_to_options_mask(alu->op)))
+         if (!(options & nir_lower_int64_op_to_options_mask(alu->op)))
             continue;
 
          b.cursor = nir_before_instr(instr);