ac: add ac_build_fsign()
authorSamuel Pitoiset <samuel.pitoiset@gmail.com>
Fri, 2 Mar 2018 14:01:32 +0000 (15:01 +0100)
committerSamuel Pitoiset <samuel.pitoiset@gmail.com>
Mon, 5 Mar 2018 10:04:36 +0000 (11:04 +0100)
Signed-off-by: Samuel Pitoiset <samuel.pitoiset@gmail.com>
Reviewed-by: Timothy Arceri <tarceri@itsqueeze.com>
src/amd/common/ac_llvm_build.c
src/amd/common/ac_llvm_build.h
src/amd/common/ac_nir_to_llvm.c
src/gallium/drivers/radeonsi/si_shader_tgsi_alu.c

index cab8396f820dca4034960e1ab019b9967ddceb84..8140184b3ba3cb6099410db8f956a63ee9eb4d3c 100644 (file)
@@ -1731,6 +1731,29 @@ LLVMValueRef ac_build_isign(struct ac_llvm_context *ctx, LLVMValueRef src0,
        return val;
 }
 
+LLVMValueRef ac_build_fsign(struct ac_llvm_context *ctx, LLVMValueRef src0,
+                           unsigned bitsize)
+{
+       LLVMValueRef cmp, val, zero, one;
+       LLVMTypeRef type;
+
+       if (bitsize == 32) {
+               type = ctx->f32;
+               zero = ctx->f32_0;
+               one = ctx->f32_1;
+       } else {
+               type = ctx->f64;
+               zero = ctx->f64_0;
+               one = ctx->f64_1;
+       }
+
+       cmp = LLVMBuildFCmp(ctx->builder, LLVMRealOGT, src0, zero, "");
+       val = LLVMBuildSelect(ctx->builder, cmp, one, src0, "");
+       cmp = LLVMBuildFCmp(ctx->builder, LLVMRealOGE, val, zero, "");
+       val = LLVMBuildSelect(ctx->builder, cmp, val, LLVMConstReal(type, -1.0), "");
+       return val;
+}
+
 void ac_get_image_intr_name(const char *base_name,
                            LLVMTypeRef data_type,
                            LLVMTypeRef coords_type,
index 860c25f67775c3c8e81bb73c601572ddbcd5ac8e..4eee9b32e9a01985b23159b8923f871b76e12e69 100644 (file)
@@ -341,6 +341,9 @@ LLVMValueRef ac_build_fract(struct ac_llvm_context *ctx, LLVMValueRef src0,
 LLVMValueRef ac_build_isign(struct ac_llvm_context *ctx, LLVMValueRef src0,
                            unsigned bitsize);
 
+LLVMValueRef ac_build_fsign(struct ac_llvm_context *ctx, LLVMValueRef src0,
+                           unsigned bitsize);
+
 void ac_get_image_intr_name(const char *base_name,
                            LLVMTypeRef data_type,
                            LLVMTypeRef coords_type,
index 70198fbf208d253001c0d9c9cbc66fa0dcd0f4da..d2df2837c8ac1b281366720985f8e1c8602d1083 100644 (file)
@@ -1338,30 +1338,6 @@ static LLVMValueRef emit_iabs(struct ac_llvm_context *ctx,
                               LLVMBuildNeg(ctx->builder, src0, ""));
 }
 
-static LLVMValueRef emit_fsign(struct ac_llvm_context *ctx,
-                              LLVMValueRef src0,
-                              unsigned bitsize)
-{
-       LLVMValueRef cmp, val, zero, one;
-       LLVMTypeRef type;
-
-       if (bitsize == 32) {
-               type = ctx->f32;
-               zero = ctx->f32_0;
-               one = ctx->f32_1;
-       } else {
-               type = ctx->f64;
-               zero = ctx->f64_0;
-               one = ctx->f64_1;
-       }
-
-       cmp = LLVMBuildFCmp(ctx->builder, LLVMRealOGT, src0, zero, "");
-       val = LLVMBuildSelect(ctx->builder, cmp, one, src0, "");
-       cmp = LLVMBuildFCmp(ctx->builder, LLVMRealOGE, val, zero, "");
-       val = LLVMBuildSelect(ctx->builder, cmp, val, LLVMConstReal(type, -1.0), "");
-       return val;
-}
-
 static LLVMValueRef emit_uint_carry(struct ac_llvm_context *ctx,
                                    const char *intrin,
                                    LLVMValueRef src0, LLVMValueRef src1)
@@ -1789,7 +1765,8 @@ static void visit_alu(struct ac_nir_context *ctx, const nir_alu_instr *instr)
                break;
        case nir_op_fsign:
                src[0] = ac_to_float(&ctx->ac, src[0]);
-               result = emit_fsign(&ctx->ac, src[0], instr->dest.dest.ssa.bit_size);
+               result = ac_build_fsign(&ctx->ac, src[0],
+                                       instr->dest.dest.ssa.bit_size);
                break;
        case nir_op_ffloor:
                result = emit_intrin_1f_param(&ctx->ac, "llvm.floor",
index 87984934cac8315224e9ff9ef4d955e10be18186..201e4988fad9f42d36fb89d315e4748b4241cb38 100644 (file)
@@ -348,24 +348,17 @@ static void emit_ssg(const struct lp_build_tgsi_action *action,
                     struct lp_build_emit_data *emit_data)
 {
        struct si_shader_context *ctx = si_shader_context(bld_base);
-       LLVMBuilderRef builder = ctx->ac.builder;
 
-       LLVMValueRef cmp, val;
+       LLVMValueRef  val;
 
        if (emit_data->inst->Instruction.Opcode == TGSI_OPCODE_I64SSG) {
                val = ac_build_isign(&ctx->ac, emit_data->args[0], 64);
        } else if (emit_data->inst->Instruction.Opcode == TGSI_OPCODE_ISSG) {
                val = ac_build_isign(&ctx->ac, emit_data->args[0], 32);
        } else if (emit_data->inst->Instruction.Opcode == TGSI_OPCODE_DSSG) {
-               cmp = LLVMBuildFCmp(builder, LLVMRealOGT, emit_data->args[0], bld_base->dbl_bld.zero, "");
-               val = LLVMBuildSelect(builder, cmp, bld_base->dbl_bld.one, emit_data->args[0], "");
-               cmp = LLVMBuildFCmp(builder, LLVMRealOGE, val, bld_base->dbl_bld.zero, "");
-               val = LLVMBuildSelect(builder, cmp, val, LLVMConstReal(bld_base->dbl_bld.elem_type, -1), "");
-       } else { // float SSG
-               cmp = LLVMBuildFCmp(builder, LLVMRealOGT, emit_data->args[0], ctx->ac.f32_0, "");
-               val = LLVMBuildSelect(builder, cmp, ctx->ac.f32_1, emit_data->args[0], "");
-               cmp = LLVMBuildFCmp(builder, LLVMRealOGE, val, ctx->ac.f32_0, "");
-               val = LLVMBuildSelect(builder, cmp, val, LLVMConstReal(ctx->f32, -1), "");
+               val = ac_build_fsign(&ctx->ac, emit_data->args[0], 64);
+       } else {
+               val = ac_build_fsign(&ctx->ac, emit_data->args[0], 32);
        }
 
        emit_data->output[emit_data->chan] = val;