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

Matt Arsenault arsenm2 at gmail.com
Mon Aug 4 15:28:19 PDT 2014


On Aug 4, 2014, at 3:26 PM, Matt Arsenault <Matthew.Arsenault at amd.com> wrote:

> 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

Whoops, nevermind. I thought m was also int



More information about the Libclc-dev mailing list