agx: Implement simple floating point ops
authorAlyssa Rosenzweig <alyssa@rosenzweig.io>
Wed, 14 Apr 2021 19:28:13 +0000 (15:28 -0400)
committerAlyssa Rosenzweig <none>
Sun, 2 May 2021 21:41:14 +0000 (17:41 -0400)
These are all direct translations of NIR->AIR.

Signed-off-by: Alyssa Rosenzweig <alyssa@rosenzweig.io>
Acked-by: Jason Ekstrand <jason@jlekstrand.net>
Acked-by: Bas Nieuwenhuizen <bas@basnieuwenhuizen.nl>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/10582>

src/asahi/compiler/agx_compile.c

index 32d5e1a..148fe89 100644 (file)
@@ -214,7 +214,49 @@ agx_emit_alu(agx_builder *b, nir_alu_instr *instr)
    agx_index s2 = srcs > 2 ? agx_alu_src_index(b, instr->src[2]) : agx_null();
    agx_index s3 = srcs > 3 ? agx_alu_src_index(b, instr->src[3]) : agx_null();
 
+#define UNOP(nop, aop) \
+   case nir_op_ ## nop: return agx_ ## aop ## _to(b, dst, s0);
+#define BINOP(nop, aop) \
+   case nir_op_ ## nop: return agx_ ## aop ## _to(b, dst, s0, s1);
+#define TRIOP(nop, aop) \
+   case nir_op_ ## nop: return agx_ ## aop ## _to(b, dst, s0, s1, s2);
+
    switch (instr->op) {
+   BINOP(fadd, fadd);
+   BINOP(fmul, fmul);
+   TRIOP(ffma, fma);
+
+   UNOP(f2f16, fmov);
+   UNOP(f2f32, fmov);
+   UNOP(fround_even, roundeven);
+   UNOP(ftrunc, trunc);
+   UNOP(ffloor, floor);
+   UNOP(fceil, ceil);
+   UNOP(frcp, rcp);
+   UNOP(frsq, rsqrt);
+   UNOP(flog2, log2);
+   UNOP(fexp2, exp2);
+
+   UNOP(fddx, dfdx);
+   UNOP(fddx_coarse, dfdx);
+   UNOP(fddx_fine, dfdx);
+
+   UNOP(fddy, dfdy);
+   UNOP(fddy_coarse, dfdy);
+   UNOP(fddy_fine, dfdy);
+
+   case nir_op_fsqrt: return agx_fmul_to(b, dst, s0, agx_srsqrt(b, s0));
+   case nir_op_fsub: return agx_fadd_to(b, dst, s0, agx_neg(s1));
+   case nir_op_fabs: return agx_fmov_to(b, dst, agx_abs(s0));
+   case nir_op_fneg: return agx_fmov_to(b, dst, agx_neg(s0));
+
+   case nir_op_fsat:
+   {
+      agx_instr *I = agx_fadd_to(b, dst, s0, agx_negzero());
+      I->saturate = true;
+      return I;
+   }
+
    case nir_op_vec2:
    case nir_op_vec3:
    case nir_op_vec4: