Re: [committed] libstdc++: Define C++26 saturation arithmetic functions (P0543R3)

2023-11-17 Thread Jonathan Wakely
On Fri, 17 Nov 2023 at 15:32, Jonathan Wakely wrote: > > Tested x86_64-linux. Pushed to trunk. > > GCC generates better code for add_sat if we use: > > unsigned z = x + y; > z |= -(z < x); > return z; > > If the compiler can't be improved we should consider using that instead > of

Re: [committed] libstdc++: Define C++26 saturation arithmetic functions (P0543R3)

2023-11-17 Thread Daniel Krügler
Am Fr., 17. Nov. 2023 um 18:31 Uhr schrieb Jonathan Wakely : > > On Fri, 17 Nov 2023 at 17:01, Daniel Krügler > wrote: > > [..] > > > + > > > +namespace std _GLIBCXX_VISIBILITY(default) > > > +{ > > > +_GLIBCXX_BEGIN_NAMESPACE_VERSION > > > + > > > + /// Add two integers, with saturation in

Re: [committed] libstdc++: Define C++26 saturation arithmetic functions (P0543R3)

2023-11-17 Thread Jonathan Wakely
On Fri, 17 Nov 2023 at 17:01, Daniel Krügler wrote: > > Am Fr., 17. Nov. 2023 um 16:32 Uhr schrieb Jonathan Wakely > : > > > > Tested x86_64-linux. Pushed to trunk. > > > > GCC generates better code for add_sat if we use: > > > > unsigned z = x + y; > > z |= -(z < x); > > return z; > > > > If

Re: [committed] libstdc++: Define C++26 saturation arithmetic functions (P0543R3)

2023-11-17 Thread Daniel Krügler
Am Fr., 17. Nov. 2023 um 16:32 Uhr schrieb Jonathan Wakely : > > Tested x86_64-linux. Pushed to trunk. > > GCC generates better code for add_sat if we use: > > unsigned z = x + y; > z |= -(z < x); > return z; > > If the compiler can't be improved we should consider using that instead > of

[committed] libstdc++: Define C++26 saturation arithmetic functions (P0543R3)

2023-11-17 Thread Jonathan Wakely
Tested x86_64-linux. Pushed to trunk. GCC generates better code for add_sat if we use: unsigned z = x + y; z |= -(z < x); return z; If the compiler can't be improved we should consider using that instead of __builtin_add_overflow. -- >8 -- This was approved for C++26 last week at the WG21