profiles/mojoshader_profile_metal.c
changeset 1297 5667281f0da9
parent 1220 048797e6aae1
equal deleted inserted replaced
1296:9b3b01f2a9b7 1297:5667281f0da9
  1118     output_line(ctx, "%s", code);
  1118     output_line(ctx, "%s", code);
  1119 } // emit_METAL_MUL
  1119 } // emit_METAL_MUL
  1120 
  1120 
  1121 void emit_METAL_RCP(Context *ctx)
  1121 void emit_METAL_RCP(Context *ctx)
  1122 {
  1122 {
  1123     char src0[64]; make_METAL_srcarg_string_masked(ctx, 0, src0, sizeof (src0));
  1123     const int vecsize = vecsize_from_writemask(ctx->dest_arg.writemask);
       
  1124     char cast[16] = { '\0' };
       
  1125     if (vecsize != 1)
       
  1126         snprintf(cast, sizeof (cast), "float%d", vecsize);
       
  1127     char src0[64]; make_METAL_srcarg_string_scalar(ctx, 0, src0, sizeof (src0));
  1124     char code[128];
  1128     char code[128];
  1125     ctx->metal_need_header_math = 1;
  1129     ctx->metal_need_header_math = 1;
  1126     make_METAL_destarg_assign(ctx, code, sizeof (code), "(%s == 0.0) ? FLT_MAX : 1.0 / %s", src0, src0);
  1130     make_METAL_destarg_assign(ctx, code, sizeof (code), "%s((%s == 0.0) ? FLT_MAX : 1.0 / %s)", cast, src0, src0);
  1127     output_line(ctx, "%s", code);
  1131     output_line(ctx, "%s", code);
  1128 } // emit_METAL_RCP
  1132 } // emit_METAL_RCP
  1129 
  1133 
  1130 void emit_METAL_RSQ(Context *ctx)
  1134 void emit_METAL_RSQ(Context *ctx)
  1131 {
  1135 {
  1132     char src0[64]; make_METAL_srcarg_string_masked(ctx, 0, src0, sizeof (src0));
  1136     const int vecsize = vecsize_from_writemask(ctx->dest_arg.writemask);
       
  1137     char cast[16] = { '\0' };
       
  1138     if (vecsize != 1)
       
  1139         snprintf(cast, sizeof (cast), "float%d", vecsize);
       
  1140     char src0[64]; make_METAL_srcarg_string_scalar(ctx, 0, src0, sizeof (src0));
  1133     char code[128];
  1141     char code[128];
  1134     ctx->metal_need_header_math = 1;
  1142     ctx->metal_need_header_math = 1;
  1135     make_METAL_destarg_assign(ctx, code, sizeof (code), "(%s == 0.0) ? FLT_MAX : rsqrt(abs(%s))", src0, src0);
  1143     make_METAL_destarg_assign(ctx, code, sizeof (code), "%s((%s == 0.0) ? FLT_MAX : rsqrt(abs(%s)))", cast, src0, src0);
  1136     output_line(ctx, "%s", code);
  1144     output_line(ctx, "%s", code);
  1137 } // emit_METAL_RSQ
  1145 } // emit_METAL_RSQ
  1138 
  1146 
  1139 void emit_METAL_dotprod(Context *ctx, const char *src0, const char *src1,
  1147 void emit_METAL_dotprod(Context *ctx, const char *src0, const char *src1,
  1140                               const char *extra)
  1148                               const char *extra)