From: Marek Olšák <[email protected]>

---
 src/gallium/drivers/radeonsi/si_shader_tgsi_alu.c   | 17 ++++++++++-------
 src/gallium/drivers/radeonsi/si_shader_tgsi_setup.c |  7 +++----
 2 files changed, 13 insertions(+), 11 deletions(-)

diff --git a/src/gallium/drivers/radeonsi/si_shader_tgsi_alu.c 
b/src/gallium/drivers/radeonsi/si_shader_tgsi_alu.c
index 3dcbb23..eeb6eb2 100644
--- a/src/gallium/drivers/radeonsi/si_shader_tgsi_alu.c
+++ b/src/gallium/drivers/radeonsi/si_shader_tgsi_alu.c
@@ -127,21 +127,21 @@ static void emit_icmp(const struct lp_build_tgsi_action 
*action,
 static void emit_ucmp(const struct lp_build_tgsi_action *action,
                      struct lp_build_tgsi_context *bld_base,
                      struct lp_build_emit_data *emit_data)
 {
        struct si_shader_context *ctx = si_shader_context(bld_base);
        LLVMBuilderRef builder = bld_base->base.gallivm->builder;
 
        LLVMValueRef arg0 = ac_to_integer(&ctx->ac, emit_data->args[0]);
 
        LLVMValueRef v = LLVMBuildICmp(builder, LLVMIntNE, arg0,
-                                      bld_base->uint_bld.zero, "");
+                                      ctx->i32_0, "");
 
        emit_data->output[emit_data->chan] =
                LLVMBuildSelect(builder, v, emit_data->args[1], 
emit_data->args[2], "");
 }
 
 static void emit_cmp(const struct lp_build_tgsi_action *action,
                     struct lp_build_tgsi_context *bld_base,
                     struct lp_build_emit_data *emit_data)
 {
        LLVMBuilderRef builder = bld_base->base.gallivm->builder;
@@ -353,33 +353,34 @@ static void emit_xor(const struct lp_build_tgsi_action 
*action,
 {
        LLVMBuilderRef builder = bld_base->base.gallivm->builder;
        emit_data->output[emit_data->chan] = LLVMBuildXor(builder,
                        emit_data->args[0], emit_data->args[1], "");
 }
 
 static void emit_ssg(const struct lp_build_tgsi_action *action,
                     struct lp_build_tgsi_context *bld_base,
                     struct lp_build_emit_data *emit_data)
 {
+       struct si_shader_context *ctx = si_shader_context(bld_base);
        LLVMBuilderRef builder = bld_base->base.gallivm->builder;
 
        LLVMValueRef cmp, val;
 
        if (emit_data->inst->Instruction.Opcode == TGSI_OPCODE_I64SSG) {
                cmp = LLVMBuildICmp(builder, LLVMIntSGT, emit_data->args[0], 
bld_base->int64_bld.zero, "");
                val = LLVMBuildSelect(builder, cmp, bld_base->int64_bld.one, 
emit_data->args[0], "");
                cmp = LLVMBuildICmp(builder, LLVMIntSGE, val, 
bld_base->int64_bld.zero, "");
                val = LLVMBuildSelect(builder, cmp, val, 
LLVMConstInt(bld_base->int64_bld.elem_type, -1, true), "");
        } else if (emit_data->inst->Instruction.Opcode == TGSI_OPCODE_ISSG) {
-               cmp = LLVMBuildICmp(builder, LLVMIntSGT, emit_data->args[0], 
bld_base->int_bld.zero, "");
-               val = LLVMBuildSelect(builder, cmp, bld_base->int_bld.one, 
emit_data->args[0], "");
-               cmp = LLVMBuildICmp(builder, LLVMIntSGE, val, 
bld_base->int_bld.zero, "");
+               cmp = LLVMBuildICmp(builder, LLVMIntSGT, emit_data->args[0], 
ctx->i32_0, "");
+               val = LLVMBuildSelect(builder, cmp, ctx->i32_1, 
emit_data->args[0], "");
+               cmp = LLVMBuildICmp(builder, LLVMIntSGE, val, ctx->i32_0, "");
                val = LLVMBuildSelect(builder, cmp, val, 
LLVMConstInt(bld_base->int_bld.elem_type, -1, true), "");
        } 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], 
bld_base->base.zero, "");
                val = LLVMBuildSelect(builder, cmp, bld_base->base.one, 
emit_data->args[0], "");
                cmp = LLVMBuildFCmp(builder, LLVMRealOGE, val, 
bld_base->base.zero, "");
@@ -475,33 +476,34 @@ build_tgsi_intrinsic_nomem(const struct 
lp_build_tgsi_action *action,
        emit_data->output[emit_data->chan] =
                lp_build_intrinsic(base->gallivm->builder, action->intr_name,
                                   emit_data->dst_type, emit_data->args,
                                   emit_data->arg_count, LP_FUNC_ATTR_READNONE);
 }
 
 static void emit_bfi(const struct lp_build_tgsi_action *action,
                     struct lp_build_tgsi_context *bld_base,
                     struct lp_build_emit_data *emit_data)
 {
+       struct si_shader_context *ctx = si_shader_context(bld_base);
        struct gallivm_state *gallivm = bld_base->base.gallivm;
        LLVMBuilderRef builder = gallivm->builder;
        LLVMValueRef bfi_args[3];
        LLVMValueRef bfi_sm5;
        LLVMValueRef cond;
 
        // Calculate the bitmask: (((1 << src3) - 1) << src2
        bfi_args[0] = LLVMBuildShl(builder,
                                   LLVMBuildSub(builder,
                                                LLVMBuildShl(builder,
-                                                            
bld_base->int_bld.one,
+                                                            ctx->i32_1,
                                                             
emit_data->args[3], ""),
-                                               bld_base->int_bld.one, ""),
+                                               ctx->i32_1, ""),
                                   emit_data->args[2], "");
 
        bfi_args[1] = LLVMBuildShl(builder, emit_data->args[1],
                                   emit_data->args[2], "");
 
        bfi_args[2] = emit_data->args[0];
 
        /* Calculate:
         *   (arg0 & arg1) | (~arg0 & arg2) = arg2 ^ (arg0 & (arg1 ^ arg2)
         * Use the right-hand side, which the LLVM backend can convert to V_BFI.
@@ -541,20 +543,21 @@ static void emit_bfe(const struct lp_build_tgsi_action 
*action,
                             LLVMConstInt(ctx->i32, 32, 0), "");
        emit_data->output[emit_data->chan] =
                LLVMBuildSelect(builder, cond, emit_data->args[0], bfe_sm5, "");
 }
 
 /* this is ffs in C */
 static void emit_lsb(const struct lp_build_tgsi_action *action,
                     struct lp_build_tgsi_context *bld_base,
                     struct lp_build_emit_data *emit_data)
 {
+       struct si_shader_context *ctx = si_shader_context(bld_base);
        struct gallivm_state *gallivm = bld_base->base.gallivm;
        LLVMBuilderRef builder = gallivm->builder;
        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
@@ -566,21 +569,21 @@ static void emit_lsb(const struct lp_build_tgsi_action 
*action,
        LLVMValueRef lsb =
                lp_build_intrinsic(gallivm->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(builder,
                                LLVMBuildICmp(builder, LLVMIntEQ, args[0],
-                                             bld_base->uint_bld.zero, ""),
+                                             ctx->i32_0, ""),
                                lp_build_const_int32(gallivm, -1), lsb, "");
 }
 
 /* Find the last bit set. */
 static void emit_umsb(const struct lp_build_tgsi_action *action,
                      struct lp_build_tgsi_context *bld_base,
                      struct lp_build_emit_data *emit_data)
 {
        struct si_shader_context *ctx = si_shader_context(bld_base);
 
diff --git a/src/gallium/drivers/radeonsi/si_shader_tgsi_setup.c 
b/src/gallium/drivers/radeonsi/si_shader_tgsi_setup.c
index 5b20ff3..aee8cdd 100644
--- a/src/gallium/drivers/radeonsi/si_shader_tgsi_setup.c
+++ b/src/gallium/drivers/radeonsi/si_shader_tgsi_setup.c
@@ -408,25 +408,25 @@ si_llvm_emit_fetch_64bit(struct lp_build_tgsi_context 
*bld_base,
 {
        struct si_shader_context *ctx = si_shader_context(bld_base);
        LLVMBuilderRef builder = bld_base->base.gallivm->builder;
        LLVMValueRef result;
 
        result = 
LLVMGetUndef(LLVMVectorType(LLVMIntTypeInContext(bld_base->base.gallivm->context,
 32), bld_base->base.type.length * 2));
 
        result = LLVMBuildInsertElement(builder,
                                        result,
                                        ac_to_integer(&ctx->ac, ptr),
-                                       bld_base->int_bld.zero, "");
+                                       ctx->i32_0, "");
        result = LLVMBuildInsertElement(builder,
                                        result,
                                        ac_to_integer(&ctx->ac, ptr2),
-                                       bld_base->int_bld.one, "");
+                                       ctx->i32_1, "");
        return bitcast(bld_base, type, result);
 }
 
 static LLVMValueRef
 emit_array_fetch(struct lp_build_tgsi_context *bld_base,
                 unsigned File, enum tgsi_opcode_type type,
                 struct tgsi_declaration_range range,
                 unsigned swizzle)
 {
        struct si_shader_context *ctx = si_shader_context(bld_base);
@@ -1124,22 +1124,21 @@ static void if_emit(const struct lp_build_tgsi_action 
*action,
 
 static void uif_emit(const struct lp_build_tgsi_action *action,
                     struct lp_build_tgsi_context *bld_base,
                     struct lp_build_emit_data *emit_data)
 {
        struct si_shader_context *ctx = si_shader_context(bld_base);
        struct gallivm_state *gallivm = bld_base->base.gallivm;
        LLVMValueRef cond;
 
        cond = LLVMBuildICmp(gallivm->builder, LLVMIntNE,
-               ac_to_integer(&ctx->ac, emit_data->args[0]),
-                       bld_base->int_bld.zero, "");
+               ac_to_integer(&ctx->ac, emit_data->args[0]), ctx->i32_0, "");
 
        if_cond_emit(action, bld_base, emit_data, cond);
 }
 
 static void emit_immediate(struct lp_build_tgsi_context *bld_base,
                           const struct tgsi_full_immediate *imm)
 {
        unsigned i;
        struct si_shader_context *ctx = si_shader_context(bld_base);
 
-- 
2.7.4

_______________________________________________
mesa-dev mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/mesa-dev

Reply via email to