summaryrefslogtreecommitdiffstats
path: root/src/gallium/drivers
diff options
context:
space:
mode:
authorMarek Olšák <marek.olsak@amd.com>2016-10-26 01:08:15 +0200
committerEmil Velikov <emil.l.velikov@gmail.com>2016-11-01 12:50:53 +0000
commit6c55e33424899301a05726f4f57a157a46c74298 (patch)
tree1354efc9b539c33f412df4113ec48de113197108 /src/gallium/drivers
parent2ec8ad91b3d27d8f2fca813ce18ea7eb7b66b106 (diff)
downloadexternal_mesa3d-6c55e33424899301a05726f4f57a157a46c74298.zip
external_mesa3d-6c55e33424899301a05726f4f57a157a46c74298.tar.gz
external_mesa3d-6c55e33424899301a05726f4f57a157a46c74298.tar.bz2
radeonsi: fix behavior of GLSL findLSB(0)
12.0 and older need the same fix but elsewhere. Cc: 13.0 <mesa-stable@lists.freedesktop.org> Reviewed-by: Nicolai Hähnle <nicolai.haehnle@amd.com> (cherry picked from commit 4bf45a6079b5cc6b0360b637c0c7baa456b8257d)
Diffstat (limited to 'src/gallium/drivers')
-rw-r--r--src/gallium/drivers/radeonsi/si_shader_tgsi_alu.c17
1 files changed, 13 insertions, 4 deletions
diff --git a/src/gallium/drivers/radeonsi/si_shader_tgsi_alu.c b/src/gallium/drivers/radeonsi/si_shader_tgsi_alu.c
index 1ee9afb..123ff5d 100644
--- a/src/gallium/drivers/radeonsi/si_shader_tgsi_alu.c
+++ b/src/gallium/drivers/radeonsi/si_shader_tgsi_alu.c
@@ -491,23 +491,32 @@ static void emit_lsb(const struct lp_build_tgsi_action *action,
struct lp_build_emit_data *emit_data)
{
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.
- *
- * The hardware already implements the correct behavior.
+ * 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(LLVMInt1TypeInContext(gallivm->context), 1, 0)
};
- emit_data->output[emit_data->chan] =
+ LLVMValueRef lsb =
lp_build_intrinsic(gallivm->builder, "llvm.cttz.i32",
emit_data->dst_type, args, ARRAY_SIZE(args),
LLVMReadNoneAttribute);
+
+ /* 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, ""),
+ lp_build_const_int32(gallivm, -1), lsb, "");
}
/* Find the last bit set. */