profiles/mojoshader_profile_metal.c
changeset 1297 5667281f0da9
parent 1220 048797e6aae1
--- a/profiles/mojoshader_profile_metal.c	Mon Jul 20 20:07:06 2020 -0400
+++ b/profiles/mojoshader_profile_metal.c	Mon Jul 20 20:07:44 2020 -0400
@@ -1120,19 +1120,27 @@
 
 void emit_METAL_RCP(Context *ctx)
 {
-    char src0[64]; make_METAL_srcarg_string_masked(ctx, 0, src0, sizeof (src0));
+    const int vecsize = vecsize_from_writemask(ctx->dest_arg.writemask);
+    char cast[16] = { '\0' };
+    if (vecsize != 1)
+        snprintf(cast, sizeof (cast), "float%d", vecsize);
+    char src0[64]; make_METAL_srcarg_string_scalar(ctx, 0, src0, sizeof (src0));
     char code[128];
     ctx->metal_need_header_math = 1;
-    make_METAL_destarg_assign(ctx, code, sizeof (code), "(%s == 0.0) ? FLT_MAX : 1.0 / %s", src0, src0);
+    make_METAL_destarg_assign(ctx, code, sizeof (code), "%s((%s == 0.0) ? FLT_MAX : 1.0 / %s)", cast, src0, src0);
     output_line(ctx, "%s", code);
 } // emit_METAL_RCP
 
 void emit_METAL_RSQ(Context *ctx)
 {
-    char src0[64]; make_METAL_srcarg_string_masked(ctx, 0, src0, sizeof (src0));
+    const int vecsize = vecsize_from_writemask(ctx->dest_arg.writemask);
+    char cast[16] = { '\0' };
+    if (vecsize != 1)
+        snprintf(cast, sizeof (cast), "float%d", vecsize);
+    char src0[64]; make_METAL_srcarg_string_scalar(ctx, 0, src0, sizeof (src0));
     char code[128];
     ctx->metal_need_header_math = 1;
-    make_METAL_destarg_assign(ctx, code, sizeof (code), "(%s == 0.0) ? FLT_MAX : rsqrt(abs(%s))", src0, src0);
+    make_METAL_destarg_assign(ctx, code, sizeof (code), "%s((%s == 0.0) ? FLT_MAX : rsqrt(abs(%s)))", cast, src0, src0);
     output_line(ctx, "%s", code);
 } // emit_METAL_RSQ