radeonsi: make use of ac_build_fdiv()
[mesa.git] / src / gallium / drivers / radeonsi / si_shader_tgsi_alu.c
index 913b6c329597ab0f210a1fe5f80b5dc99848ac1c..cec33c38b4e4c165c1fc70a7fe8318bac3594c33 100644 (file)
@@ -535,31 +535,8 @@ static void emit_lsb(const struct lp_build_tgsi_action *action,
                     struct lp_build_emit_data *emit_data)
 {
        struct si_shader_context *ctx = si_shader_context(bld_base);
-       LLVMValueRef args[2] = {
-               emit_data->args[0],
-
-               /* The value of 1 means that ffs(x=0) = undef, so LLVM won't
-                * add special code to check for x=0. The reason is that
-                * the LLVM behavior for x=0 is different from what we
-                * need here. However, LLVM also assumes that ffs(x) is
-                * in [0, 31], but GLSL expects that ffs(0) = -1, so
-                * a conditional assignment to handle 0 is still required.
-                */
-               LLVMConstInt(ctx->i1, 1, 0)
-       };
-
-       LLVMValueRef lsb =
-               lp_build_intrinsic(ctx->ac.builder, "llvm.cttz.i32",
-                               emit_data->dst_type, args, ARRAY_SIZE(args),
-                               LP_FUNC_ATTR_READNONE);
-
-       /* TODO: We need an intrinsic to skip this conditional. */
-       /* Check for zero: */
-       emit_data->output[emit_data->chan] =
-               LLVMBuildSelect(ctx->ac.builder,
-                               LLVMBuildICmp(ctx->ac.builder, LLVMIntEQ, args[0],
-                                             ctx->i32_0, ""),
-                               LLVMConstInt(ctx->i32, -1, 0), lsb, "");
+
+       emit_data->output[emit_data->chan] = ac_find_lsb(&ctx->ac, emit_data->dst_type, emit_data->args[0]);
 }
 
 /* Find the last bit set. */
@@ -691,13 +668,7 @@ static void emit_fdiv(const struct lp_build_tgsi_action *action,
        struct si_shader_context *ctx = si_shader_context(bld_base);
 
        emit_data->output[emit_data->chan] =
-               LLVMBuildFDiv(ctx->ac.builder,
-                             emit_data->args[0], emit_data->args[1], "");
-
-       /* Use v_rcp_f32 instead of precise division. */
-       if (!LLVMIsConstant(emit_data->output[emit_data->chan]))
-               LLVMSetMetadata(emit_data->output[emit_data->chan],
-                               ctx->fpmath_md_kind, ctx->fpmath_md_2p5_ulp);
+               ac_build_fdiv(&ctx->ac, emit_data->args[0], emit_data->args[1]);
 }
 
 /* 1/sqrt is translated to rsq for f32 if fp32 denormals are not enabled in