Re: [PATCH] P0556R3 Integral power-of-2 operations, P0553R2 Bit operations

2018-07-04 Thread Jonathan Wakely
On 04/07/18 10:26 +0200, Jakub Jelinek wrote: On Wed, Jul 04, 2018 at 09:14:04AM +0100, Jonathan Wakely wrote: > Unfortunately it is not correct if _Nd is not power of two. > E.g. for __sN 1, -1U % 20 is 15, not 19. > So it would need to be > return (__x << __sN) | (__x >> ((_Nd - __sN) %

Re: [PATCH] P0556R3 Integral power-of-2 operations, P0553R2 Bit operations

2018-07-04 Thread Jakub Jelinek
On Wed, Jul 04, 2018 at 09:14:04AM +0100, Jonathan Wakely wrote: > > Unfortunately it is not correct if _Nd is not power of two. > > E.g. for __sN 1, -1U % 20 is 15, not 19. > > So it would need to be > > return (__x << __sN) | (__x >> ((_Nd - __sN) % _Nd)); > > Unfortunately, our rotate

Re: [PATCH] P0556R3 Integral power-of-2 operations, P0553R2 Bit operations

2018-07-04 Thread Jonathan Wakely
On 04/07/18 10:09 +0200, Jakub Jelinek wrote: On Tue, Jul 03, 2018 at 11:24:00PM +0100, Jonathan Wakely wrote: > Wouldn't it be better to use some branchless pattern that > GCC can also optimize well, like: > return (__x << __sN) | (__x >> ((-_sN) & (_Nd - 1))); > (iff _Nd is always power

Re: [PATCH] P0556R3 Integral power-of-2 operations, P0553R2 Bit operations

2018-07-04 Thread Jakub Jelinek
On Tue, Jul 03, 2018 at 11:24:00PM +0100, Jonathan Wakely wrote: > > Wouldn't it be better to use some branchless pattern that > > GCC can also optimize well, like: > > return (__x << __sN) | (__x >> ((-_sN) & (_Nd - 1))); > > (iff _Nd is always power of two), > > _Nd is 20 for one of the

Re: [PATCH] P0556R3 Integral power-of-2 operations, P0553R2 Bit operations

2018-07-04 Thread Jonathan Wakely
On 03/07/18 23:23 +0100, Jonathan Wakely wrote: On 03/07/18 23:40 +0200, Jakub Jelinek wrote: On Tue, Jul 03, 2018 at 10:02:47PM +0100, Jonathan Wakely wrote: +#ifndef _GLIBCXX_BIT +#define _GLIBCXX_BIT 1 + +#pragma GCC system_header + +#if __cplusplus >= 201402L + +#include +#include +

Re: [PATCH] P0556R3 Integral power-of-2 operations, P0553R2 Bit operations

2018-07-03 Thread Jonathan Wakely
On 03/07/18 23:40 +0200, Jakub Jelinek wrote: On Tue, Jul 03, 2018 at 10:02:47PM +0100, Jonathan Wakely wrote: +#ifndef _GLIBCXX_BIT +#define _GLIBCXX_BIT 1 + +#pragma GCC system_header + +#if __cplusplus >= 201402L + +#include +#include + +namespace std _GLIBCXX_VISIBILITY(default) +{

Re: [PATCH] P0556R3 Integral power-of-2 operations, P0553R2 Bit operations

2018-07-03 Thread Jakub Jelinek
On Tue, Jul 03, 2018 at 10:02:47PM +0100, Jonathan Wakely wrote: > +#ifndef _GLIBCXX_BIT > +#define _GLIBCXX_BIT 1 > + > +#pragma GCC system_header > + > +#if __cplusplus >= 201402L > + > +#include > +#include > + > +namespace std _GLIBCXX_VISIBILITY(default) > +{ >

[PATCH] P0556R3 Integral power-of-2 operations, P0553R2 Bit operations

2018-07-03 Thread Jonathan Wakely
P0553R2 is not in the C++2a working draft yet, but is likely to be approved soon. Neither proposal supports std::byte but this adds overloads of each function for std::byte, assuming that will also get added. * include/Makefile.am: Add new header. * include/Makefile.in: