[Beignet] [PATCH] GBE/libocl: Fix sub_sat corner case.

Zhigang Gong zhigang.gong at linux.intel.com
Sun Sep 14 21:05:03 PDT 2014


LGTM, pushed, thanks.
On Mon, Sep 15, 2014 at 11:14:05AM +0800, Ruiling Song wrote:
> It seems that hw return wrong result when y is equal to 0x80000000
> in sub_sat(int x, int y). So we re-write it as:
> add_sat(add_sat(0x7fffffff, x), 1)
> 
> Also enable corresponding utest.
> 
> Signed-off-by: Ruiling Song <ruiling.song at intel.com>
> ---
>  backend/src/libocl/tmpl/ocl_integer.tmpl.cl |    2 +-
>  utests/compiler_saturate_sub.cpp            |    2 +-
>  2 files changed, 2 insertions(+), 2 deletions(-)
> 
> diff --git a/backend/src/libocl/tmpl/ocl_integer.tmpl.cl b/backend/src/libocl/tmpl/ocl_integer.tmpl.cl
> index d33d70e..9230604 100644
> --- a/backend/src/libocl/tmpl/ocl_integer.tmpl.cl
> +++ b/backend/src/libocl/tmpl/ocl_integer.tmpl.cl
> @@ -100,7 +100,7 @@ OVERLOADABLE int ocl_sadd_sat(int x, int y);
>  OVERLOADABLE int add_sat(int x, int y) { return ocl_sadd_sat(x, y); }
>  OVERLOADABLE int ocl_ssub_sat(int x, int y);
>  OVERLOADABLE int sub_sat(int x, int y) {
> -  return (y == 0x80000000u) ? (x & 0x7FFFFFFF) : ocl_ssub_sat(x, y);
> +  return (y == 0x80000000u) ? (ocl_sadd_sat(ocl_sadd_sat(0x7fffffff, x), 1)) : ocl_ssub_sat(x, y);
>  }
>  OVERLOADABLE long ocl_sadd_sat(long x, long y);
>  OVERLOADABLE long add_sat(long x, long y) {
> diff --git a/utests/compiler_saturate_sub.cpp b/utests/compiler_saturate_sub.cpp
> index 48947b7..1c95e2d 100644
> --- a/utests/compiler_saturate_sub.cpp
> +++ b/utests/compiler_saturate_sub.cpp
> @@ -108,7 +108,7 @@ compiler_saturate_sub(int8_t, test_char)
>  compiler_saturate_sub(uint8_t, test_uchar)
>  compiler_saturate_sub(int16_t, test_short)
>  compiler_saturate_sub(uint16_t, test_ushort)
> -//compiler_saturate_sub(int32_t, test_int) // TODO due to the possible hardware bug, we disable this, uncomment it when it's done.
> +compiler_saturate_sub(int32_t, test_int)
>  compiler_saturate_sub(uint32_t, test_uint)
>  //compiler_saturate_sub(int64_t, test_long)
>  //compiler_saturate_sub(uint64_t, test_ulong)
> -- 
> 1.7.10.4
> 
> _______________________________________________
> Beignet mailing list
> Beignet at lists.freedesktop.org
> http://lists.freedesktop.org/mailman/listinfo/beignet


More information about the Beignet mailing list