Re: [RFC] Implementing detection of saturation and rounding arithmetic

2021-05-12 Thread Liu Hao via Gcc
在 5/12/21 5:13 PM, Tamar Christina via Gcc 写道: int f (int a, int b) { int res; if (__builtin_add_overflow (a, b, &res)) { if (res >= 0) return INT_MAX; else return INT_MIN; } return res; } Should be recognized as satur

Re: [RFC] Implementing detection of saturation and rounding arithmetic

2021-05-12 Thread Segher Boessenkool
On Wed, May 12, 2021 at 09:13:38AM +, Tamar Christina wrote: > > From: Segher Boessenkool > > On Tue, May 11, 2021 at 05:37:34AM +, Tamar Christina via Gcc wrote: > > > 2. Saturating abs: > > >char sat (char a) > > >{ > > > int tmp = abs (a); > > > return tmp > 127 ? 12

RE: [RFC] Implementing detection of saturation and rounding arithmetic

2021-05-12 Thread Richard Biener
On Wed, 12 May 2021, Tamar Christina wrote: > > > > -Original Message- > > From: Richard Biener > > Sent: Tuesday, May 11, 2021 12:45 PM > > To: Tamar Christina > > Cc: gcc@gcc.gnu.org; Richard Sandiford ; > > Jakub Jelinek > > Subject

Re: [RFC] Implementing detection of saturation and rounding arithmetic

2021-05-12 Thread Richard Biener
On Wed, 12 May 2021, Richard Sandiford wrote: > Tamar Christina writes: > > Hi All, > > > > We are looking to implement saturation support in the compiler. The aim is > > to > > recognize both Scalar and Vector variant of typical saturating expressions. > > > > As an example: > > > > 1. Saturat

RE: [RFC] Implementing detection of saturation and rounding arithmetic

2021-05-12 Thread Tamar Christina via Gcc
> -Original Message- > From: Richard Sandiford > Sent: Wednesday, May 12, 2021 9:48 AM > To: Tamar Christina > Cc: gcc@gcc.gnu.org; Richard Biener > Subject: Re: [RFC] Implementing detection of saturation and rounding > arithmetic > > Tamar Christina wri

RE: [RFC] Implementing detection of saturation and rounding arithmetic

2021-05-12 Thread Tamar Christina via Gcc
> -Original Message- > From: Joseph Myers > Sent: Tuesday, May 11, 2021 6:01 PM > To: David Brown > Cc: Tamar Christina ; gcc@gcc.gnu.org; Richard > Sandiford ; Richard Biener > > Subject: Re: [RFC] Implementing detection of saturation and rounding > ari

RE: [RFC] Implementing detection of saturation and rounding arithmetic

2021-05-12 Thread Tamar Christina via Gcc
Hi, > -Original Message- > From: Segher Boessenkool > Sent: Tuesday, May 11, 2021 4:43 PM > To: Tamar Christina > Cc: gcc@gcc.gnu.org; Richard Sandiford ; > Richard Biener > Subject: Re: [RFC] Implementing detection of saturation and rounding > arithmetic >

RE: [RFC] Implementing detection of saturation and rounding arithmetic

2021-05-12 Thread Tamar Christina via Gcc
> -Original Message- > From: Richard Biener > Sent: Tuesday, May 11, 2021 12:45 PM > To: Tamar Christina > Cc: gcc@gcc.gnu.org; Richard Sandiford ; > Jakub Jelinek > Subject: Re: [RFC] Implementing detection of saturation and rounding > arithmetic > &

Re: [RFC] Implementing detection of saturation and rounding arithmetic

2021-05-12 Thread Richard Sandiford via Gcc
Tamar Christina writes: > Hi All, > > We are looking to implement saturation support in the compiler. The aim is to > recognize both Scalar and Vector variant of typical saturating expressions. > > As an example: > > 1. Saturating addition: >char sat (char a, char b) >{ > int tmp =

Re: [RFC] Implementing detection of saturation and rounding arithmetic

2021-05-12 Thread David Brown
On 12/05/2021 10:00, Tamar Christina wrote: > Hi David, > >> -Original Message- >> From: David Brown >> Sent: Tuesday, May 11, 2021 11:04 AM >> To: Tamar Christina ; gcc@gcc.gnu.org >> Cc: Richard Sandiford ; Richard Biener >> >> Subject

RE: [RFC] Implementing detection of saturation and rounding arithmetic

2021-05-12 Thread Tamar Christina via Gcc
Hi David, > -Original Message- > From: David Brown > Sent: Tuesday, May 11, 2021 11:04 AM > To: Tamar Christina ; gcc@gcc.gnu.org > Cc: Richard Sandiford ; Richard Biener > > Subject: Re: [RFC] Implementing detection of saturation and rounding > arithmetic

Re: [RFC] Implementing detection of saturation and rounding arithmetic

2021-05-12 Thread David Brown
On 11/05/2021 19:00, Joseph Myers wrote: > On Tue, 11 May 2021, David Brown wrote: > >> It is also worth noting that gcc already has support for saturating >> types on some targets: >> >> >> >> My testing of these (quite a long time ago) left m

Re: [RFC] Implementing detection of saturation and rounding arithmetic

2021-05-11 Thread Joseph Myers
On Tue, 11 May 2021, David Brown wrote: > It is also worth noting that gcc already has support for saturating > types on some targets: > > > > My testing of these (quite a long time ago) left me with a feeling that > it was not a feature anyo

Re: [RFC] Implementing detection of saturation and rounding arithmetic

2021-05-11 Thread Segher Boessenkool
Hi! On Tue, May 11, 2021 at 05:37:34AM +, Tamar Christina via Gcc wrote: > 2. Saturating abs: >char sat (char a) >{ > int tmp = abs (a); > return tmp > 127 ? 127 : ((tmp < -128) ? -128 : tmp); >} That can be done quite a bit better, branchless at least. Same for all e

Re: [RFC] Implementing detection of saturation and rounding arithmetic

2021-05-11 Thread Richard Biener
On Tue, 11 May 2021, Tamar Christina wrote: > Hi All, > > We are looking to implement saturation support in the compiler. The aim is to > recognize both Scalar and Vector variant of typical saturating expressions. > > As an example: > > 1. Saturating addition: >char sat (char a, char b) >

Re: [RFC] Implementing detection of saturation and rounding arithmetic

2021-05-11 Thread David Brown
On 11/05/2021 07:37, Tamar Christina via Gcc wrote: > Hi All, > > We are looking to implement saturation support in the compiler. The aim is to > recognize both Scalar and Vector variant of typical saturating expressions. > > As an example: > > 1. Saturating addition: >char sat (char a, cha