Boost logo

Boost :

Subject: Re: [boost] interest in structure of arrays container?
From: Larry Evans (cppljevans_at_[hidden])
Date: 2016-10-26 03:56:31


On 10/26/2016 02:27 AM, Michael Marcin wrote:
> On 10/26/2016 12:58 AM, Larry Evans wrote:
>> On 10/25/2016 11:07 PM, Michael Marcin wrote:
>>> On 10/25/2016 8:23 PM, Larry Evans wrote:
>>>>>
>>>>> At the very least support for the basic SSE 16 byte alignment of
>>>>> subarrays is crucial.
>>>>>
>>>>>
>>>>> My best idea so far is some magic wrapper type that gets special
>>>>> treatment. Like:
>>>>> using data_t = soa_block< float3, soa_align<float,16>, bool >;
>>>>
>>>> Something like:
>>>>
>>>> template<typename T, std::size_t Alignment>
>>>> struct alignas(Alignment) soa_align {
>>>> T data;
>>>> };
>>>>
>>>> Have you tried that yet. If not, I might try.
>>>>
>>>
>>> The issue is you don't want to overalign all elements of the array, just
>>> the first element.
>>>
>>
>> But aligning the first soa_align<T,A> is all that's needed because
>> sizeof(soa_align<T,A>)%A == 0, hence, all subsequent elements would
>> be aligned. At least that's my understanding. Am I missing something?
>>
>
> Perhaps I'm misunderstanding.
> Using your struct above:
> std::array< soa_align<float, 16>, 4 > data;
> std::cout << "align array: " << alignof(decltype(data)) << '\n'
> << "size element: " << sizeof( data[0] ) << '\n'
> << "size array: " << sizeof( data ) << '\n'
> << "offset[1]: " << (char*)&(data[1]) - (char*)data.data() << '\n';
>
> align array: 16
> size element: 16
> size array: 64
> offset[1]: 16
>
> For data to work with SSE instructions this needs to report:
>
> align array: 16
> size element: 4
> size array: 16
> offset[1]: 4
>
> i.e. 4 floats have to be contiguous in memory, and the *first* float has
> to be aligned to 16 bytes.
>
Ah! I had no clue :(
Thanks for explaining.
I should have read more about SSE.
[snip]


Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk