Willem <> writes:
> Ben Bacarisse wrote:
> ) Artist <> writes:
> )<snip>
> )> I need to know which of the above equations, 1, 2, or 3, will access
> )> the data quickest.
> )
> ) Since I think you'll have to try them all, you might want to consider
> ) two other options:
> )
> ) 4) Use a 2D array to get the compiler to do the address arithmetic.
> ) It's unlikely, but the compiler might be able to do it better than
> ) you can, but if it's no worse you get cleaner code and that can only
> ) be a Good Thing.
>
> It's already a 2D array, isn't it?
> You just need to cast it to the correct type.
Technically, no, it isn't; it's possible for (ie, the Standard
allows) arrays to have alignment requirements that are more
restrictive than their element types. Thus we could have,
for example, an array 'int x[4096];' that has the same
alignment as int, but an array 'int y[512][8];' that has
an alignment of 8 int's. So converting an (int *) pointer
to a (int (*)[8]) pointer could transgress into undefined
behavior. Granted, incredibly unlikely, but possible
under the rules of the Standard.
|