[Piglit] [PATCH] CL Builtins: Fix sign-extension bug in rotate
Tom Stellard
tom at stellard.net
Mon Apr 1 10:15:37 PDT 2013
On Sat, Mar 23, 2013 at 12:06:53PM -0500, Aaron Watry wrote:
> When rotating a negative number right, sign extension was producing the wrong
> expected result.
Reviewed-by: Tom Stellard <thomas.stellard at amd.com>
> ---
> generated_tests/generate-cl-int-builtins.py | 17 ++++++++++++-----
> 1 file changed, 12 insertions(+), 5 deletions(-)
>
> diff --git a/generated_tests/generate-cl-int-builtins.py b/generated_tests/generate-cl-int-builtins.py
> index 2460594..56abbc7 100755
> --- a/generated_tests/generate-cl-int-builtins.py
> +++ b/generated_tests/generate-cl-int-builtins.py
> @@ -196,9 +196,16 @@ def pow(val,pow):
> return val ** pow
>
> def rotate_right(x, n, bits):
> + #Find all bits that will wrap
> mask = (2L**n) - 1
> - mask_bits = x & mask
> - return (x >> n) | (mask_bits << (bits - n))
> + wrapped_bits = x & mask
> +
> + #sign extension needs to be masked out
> + se_mask = (1 << (bits - n)) - 1;
> + unwrapped_bits = x >> n;
> + unwrapped_bits &= se_mask;
> +
> + return unwrapped_bits | (wrapped_bits << (bits - n))
>
> def rotate_left(x, n, bits):
> return rotate_right(x, bits - n, bits)
> @@ -518,11 +525,11 @@ signed_generic_tests = {
> 'function_type': 'ttt',
> 'values': [
> [ MIN, MIN, [rot,1,-3,SIZE], 1,
> - MIN, [pow,2,[sub,SIZE,2]], MIN],
> + MIN, [pow,2,[sub,SIZE,2]], MIN, [rot,-2,-1,SIZE]],
> [ 1, 1, 1, 1,
> - 1, 1, 1],
> + 1, 1, 1, -2],
> [[sub,SIZE,1], -1, -3, [mul,SIZE,-1],
> - [mul,[add,SIZE,1],-1], [mul,[add,SIZE,2],-1], [sub,SIZE,1]]
> + [mul,[add,SIZE,1],-1], [mul,[add,SIZE,2],-1], [sub,SIZE,1], -1]
> ]
> },
> 'sub_sat': {
> --
> 1.7.10.4
>
> _______________________________________________
> Piglit mailing list
> Piglit at lists.freedesktop.org
> http://lists.freedesktop.org/mailman/listinfo/piglit
More information about the Piglit
mailing list