Boost logo

Boost :

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


On 10/26/2016 02:27 AM, Michael Marcin wrote:
[snip]

> 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.
>
So why not:

   alignas(16) std::array<float, 4> data;

IOW, does the decltype(data) have to have the required alignment
or does &data have to have that alignment?


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