<div dir="ltr"><br><div class="gmail_extra"><br><div class="gmail_quote">On Tue, Apr 12, 2016 at 1:05 AM, Samuel Iglesias Gonsálvez <span dir="ltr"><<a href="mailto:siglesias@igalia.com" target="_blank">siglesias@igalia.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">From: Iago Toral Quiroga <<a href="mailto:itoral@igalia.com">itoral@igalia.com</a>><br>
<br>
At least i965 hardware does not have native support for floor on doubles.<br>
---<br>
 src/compiler/nir/nir.h                  |  1 +<br>
 src/compiler/nir/nir_lower_double_ops.c | 29 +++++++++++++++++++++++++++++<br>
 2 files changed, 30 insertions(+)<br>
<br>
diff --git a/src/compiler/nir/nir.h b/src/compiler/nir/nir.h<br>
index f83b2e0..b7231a7 100644<br>
--- a/src/compiler/nir/nir.h<br>
+++ b/src/compiler/nir/nir.h<br>
@@ -2287,6 +2287,7 @@ typedef enum {<br>
    nir_lower_dsqrt = (1 << 1),<br>
    nir_lower_drsq = (1 << 2),<br>
    nir_lower_dtrunc = (1 << 3),<br>
+   nir_lower_dfloor = (1 << 4),<br>
 } nir_lower_doubles_options;<br>
<br>
 void nir_lower_doubles(nir_shader *shader, nir_lower_doubles_options options);<br>
diff --git a/src/compiler/nir/nir_lower_double_ops.c b/src/compiler/nir/nir_lower_double_ops.c<br>
index 9eec858..e1ec6da 100644<br>
--- a/src/compiler/nir/nir_lower_double_ops.c<br>
+++ b/src/compiler/nir/nir_lower_double_ops.c<br>
@@ -377,6 +377,27 @@ lower_trunc(nir_builder *b, nir_ssa_def *src)<br>
    return nir_pack_double_2x32_split(b, new_src_lo, new_src_hi);<br>
 }<br>
<br>
+static nir_ssa_def *<br>
+lower_floor(nir_builder *b, nir_ssa_def *src)<br>
+{<br>
+   /*<br>
+    * For x >= 0, floor(x) = trunc(x)<br>
+    * For x < 0,<br>
+    *    - if x is integer, floor(x) = x<br>
+    *    - otherwise, floor(x) = trunc(x) - 1<br>
+    */<br>
+   nir_ssa_def *tr = nir_ftrunc(b, src);<br>
+   return nir_bcsel(b,<br>
+                    nir_fge(b, src, nir_imm_double(b, 0.0)),<br>
+                    tr,<br>
+                    nir_bcsel(b,<br>
+                              nir_fne(b,<br>
+                                      nir_fsub(b, src, tr),<br>
+                                      nir_imm_double(b, 0.0)),<br></blockquote><div><br></div><div>As an aside, you can just as easily check "x is integer" by "x == truc(x)".  That might be simpler.  Same goes for ceil().<br></div><div> </div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
+                              nir_fsub(b, tr, nir_imm_double(b, 1.0)),<br>
+                              src));<br>
+}<br>
+<br>
 static void<br>
 lower_doubles_instr(nir_alu_instr *instr, nir_lower_doubles_options options)<br>
 {<br>
@@ -405,6 +426,11 @@ lower_doubles_instr(nir_alu_instr *instr, nir_lower_doubles_options options)<br>
          return;<br>
       break;<br>
<br>
+   case nir_op_ffloor:<br>
+      if (!(options & nir_lower_dfloor))<br>
+         return;<br>
+      break;<br>
+<br>
    default:<br>
       return;<br>
    }<br>
@@ -431,6 +457,9 @@ lower_doubles_instr(nir_alu_instr *instr, nir_lower_doubles_options options)<br>
    case nir_op_ftrunc:<br>
       result = lower_trunc(&bld, src);<br>
       break;<br>
+   case nir_op_ffloor:<br>
+      result = lower_floor(&bld, src);<br>
+      break;<br>
    default:<br>
       unreachable("unhandled opcode");<br>
    }<br>
<span class="HOEnZb"><font color="#888888">--<br>
2.5.0<br>
<br>
_______________________________________________<br>
mesa-dev mailing list<br>
<a href="mailto:mesa-dev@lists.freedesktop.org">mesa-dev@lists.freedesktop.org</a><br>
<a href="https://lists.freedesktop.org/mailman/listinfo/mesa-dev" rel="noreferrer" target="_blank">https://lists.freedesktop.org/mailman/listinfo/mesa-dev</a><br>
</font></span></blockquote></div><br></div></div>