pan/bit: Add FREXP interp support
authorAlyssa Rosenzweig <alyssa.rosenzweig@collabora.com>
Tue, 14 Apr 2020 16:50:48 +0000 (12:50 -0400)
committerAlyssa Rosenzweig <alyssa.rosenzweig@collabora.com>
Fri, 17 Apr 2020 20:25:36 +0000 (16:25 -0400)
Signed-off-by: Alyssa Rosenzweig <alyssa.rosenzweig@collabora.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/4615>

src/panfrost/bifrost/test/bi_interpret.c

index 2f3295772d92ed986966953dd7bbd8949be1c75f..53c3d983eb161a0a617f9d4a98b0de517bbba111 100644 (file)
@@ -340,6 +340,28 @@ bit_as_int16(nir_alu_type T, bit_t src, unsigned C, enum bifrost_roundmode rm)
         }
 }
 
+static float
+frexp_log(float x, int *e)
+{
+        /* Ignore sign until end */
+        float xa = fabs(x);
+
+        /* frexp reduces to [0.5, 1) */
+        float f = frexpf(xa, e);
+
+        /* reduce to [0.75, 1.5) */
+        if (f < 0.75) {
+                f *= 2.0;
+                (*e)--;
+        }
+
+        /* Reattach sign */
+        if (xa < 0.0)
+                f = -f;
+
+        return f;
+}
+
 void
 bit_step(struct bit_state *s, bi_instruction *ins, bool FMA)
 {
@@ -424,7 +446,18 @@ bit_step(struct bit_state *s, bi_instruction *ins, bool FMA)
                 unreachable("Unknown type");
         }
 
-        case BI_FREXP:
+        case BI_FREXP: {
+                if (ins->src_types[0] != nir_type_float32)
+                        unreachable("Unknown frexp type");
+
+
+                if (ins->op.frexp == BI_FREXPE_LOG)
+                        frexp_log(srcs[0].f32, &dest.i32);
+                else
+                        unreachable("Unknown frexp");
+
+                break;
+        }
         case BI_ISUB:
                 unreachable("Unsupported op");