Re: [PATCH 2/3] libstdc++: Optimize __uninitialized_default using memset

2024-06-28 Thread Jonathan Wakely
On Fri, 28 Jun 2024 at 07:53, Maciej Cencora wrote: > > But constexpr-ness of bit_cast has additional limitations and e.g. providing > an union as _Tp would be a hard-error. So we have two options: > - before bitcasting check if type can be bitcast-ed at compile-time, > - change the 'if constex

Re: [PATCH 2/3] libstdc++: Optimize __uninitialized_default using memset

2024-06-27 Thread Maciej Cencora
But constexpr-ness of bit_cast has additional limitations and e.g. providing an union as _Tp would be a hard-error. So we have two options: - before bitcasting check if type can be bitcast-ed at compile-time, - change the 'if constexpr' to regular 'if'. If we go with the second solution then we

Re: [PATCH 2/3] libstdc++: Optimize __uninitialized_default using memset

2024-06-27 Thread Jonathan Wakely
On Thu, 27 Jun 2024 at 14:27, Maciej Cencora wrote: > > I think going the bit_cast way would be the best because it enables the > optimization for many more classes including common wrappers like optional, > variant, pair, tuple and std::array. This isn't tested but seems to work on simple case

Re: [PATCH 2/3] libstdc++: Optimize __uninitialized_default using memset

2024-06-27 Thread Maciej Cencora
I think going the bit_cast way would be the best because it enables the optimization for many more classes including common wrappers like optional, variant, pair, tuple and std::array. Regards, Maciej Cencora czw., 27 cze 2024 o 14:57 Maciej Cencora napisał(a): > You could include some of the b

Re: [PATCH 2/3] libstdc++: Optimize __uninitialized_default using memset

2024-06-27 Thread Maciej Cencora
You could include some of the bigger classes by checking whether the class type is bit_cast-able to std::array of bytes, and that bitcasted output is equal to value-initialized array. Regards, Maciej czw., 27 cze 2024 o 14:50 Jonathan Wakely napisał(a): > On Thu, 27 Jun 2024 at 13:49, Jonathan

Re: [PATCH 2/3] libstdc++: Optimize __uninitialized_default using memset

2024-06-27 Thread Jonathan Wakely
On Thu, 27 Jun 2024 at 13:49, Jonathan Wakely wrote: > > On Thu, 27 Jun 2024 at 13:40, Maciej Cencora wrote: > > > > Hi, > > > > not sure whether I've missed some conditional that would exclude this case, > > but your change seems to incorrectly handle trivial types that have a > > non-zero bit

Re: [PATCH 2/3] libstdc++: Optimize __uninitialized_default using memset

2024-06-27 Thread Jonathan Wakely
On Thu, 27 Jun 2024 at 13:40, Maciej Cencora wrote: > > Hi, > > not sure whether I've missed some conditional that would exclude this case, > but your change seems to incorrectly handle trivial types that have a > non-zero bit pattern of value-initialized object, e.g. pointer to member. Good poi

[PATCH 2/3] libstdc++: Optimize __uninitialized_default using memset

2024-06-27 Thread Maciej Cencora
Hi, not sure whether I've missed some conditional that would exclude this case, but your change seems to incorrectly handle trivial types that have a non-zero bit pattern of value-initialized object, e.g. pointer to member. Regards, Maciej Cencora

Re: [PATCH 2/3] libstdc++: Optimize __uninitialized_default using memset

2024-06-27 Thread Jonathan Wakely
On Thu, 27 Jun 2024 at 11:53, Jonathan Wakely wrote: > > For trivial types std::__uninitialized_default (which is used by > std::uninitialized_value_construct) value-initializes the first element > then copies that to the rest of the range using std::fill. > > Tamar is working on improved vectoriz

[PATCH 2/3] libstdc++: Optimize __uninitialized_default using memset

2024-06-27 Thread Jonathan Wakely
For trivial types std::__uninitialized_default (which is used by std::uninitialized_value_construct) value-initializes the first element then copies that to the rest of the range using std::fill. Tamar is working on improved vectorization for std::fill, but for this value-initialized case where we