llvmpipe: convert double to long long instead of unsigned long long
authorOded Gabbay <oded.gabbay@gmail.com>
Thu, 3 Sep 2015 16:00:26 +0000 (19:00 +0300)
committerIlia Mirkin <imirkin@alum.mit.edu>
Fri, 4 Sep 2015 21:37:17 +0000 (17:37 -0400)
commit4f2290d1612569686284609059d29a85c9de67cf
tree29990e7132574b3904cf57e6524f3a6c91eda315
parent3c6c4d4f298ec81fe57992790a68aaab2e573519
llvmpipe: convert double to long long instead of unsigned long long

round(val*dscale) produces a double result, as val and dscale are double.
However, LLVMConstInt receives unsigned long long, so there is an
implicit conversion from double to unsigned long long.
This is an undefined behavior. Therefore, we need to first explicitly
convert the round result to long long, and then let the compiler handle
conversion from that to unsigned long long.

This bug manifests itself in POWER, where all IMM values of -1 are being
converted to 0 implicitly, causing a wrong LLVM IR output.

Signed-off-by: Oded Gabbay <oded.gabbay@gmail.com>
CC: "10.6 11.0" <mesa-stable@lists.freedesktop.org>
Reviewed-by: Tom Stellard <thomas.stellard@amd.com>
Reviewed-by: Roland Scheidegger <sroland@vmware.com>
src/gallium/auxiliary/gallivm/lp_bld_const.c