[Libclc-dev] [PATCH 1/1] Implement generic mad_sat

Matt Arsenault Matthew.Arsenault at amd.com
Mon Aug 4 15:26:16 PDT 2014


On 08/04/2014 03:23 PM, Jan Vesely wrote:
> +_CLC_OVERLOAD _CLC_DEF int mad_sat(int x, int y, int z) {
> +  int mhi = mul_hi(x, y);
> +  uint mlo = x * y;
> +  long m = upsample(mhi, mlo);
> +  m += z;
> +  if (m > INT_MAX)
> +    return INT_MAX;
> +  if (m < INT_MIN)
> +    return INT_MIN;
> +  return m;
> +}
Signed overflow is undefined, so you can't test for it this way. You 
need to check if it would overflow before performing the overflowing 
computation




More information about the Libclc-dev mailing list