Re: [AD] Remove -fno-strength-reduce |
[ Thread Index |
Date Index
| More lists.liballeg.org/allegro-developers Archives
]
Eric Botcazou wrote:
> [Strength reduction is the operation that turns
>
> int i;
> int array[N];
>
> for (i=0; i<N; i++)
> array[i] = ...;
>
> into
>
> char *p;
> int array[N];
>
> for (p=(char *)array; p < (char*)array+ N*sizeof(int); p+=sizeof(int)) {
> int *ip = (int *)p;
> *ip = ...;
> }]
And the latter is faster because ... ?
I would think that an array index computation would amount to
something like
array[i] = *(array + i);
The top loop then has, every iteration, something like
if (i < N), i++
*(array + i) = ...
and the bottom loop
if (p < a + N * sizeof), p += sizeof
int ip = (int *)p;
*ip = ...;
I can see how the line "*(array + i) = ..." would be converted to a
multiplication, an addition and a cast, but even then, where is the
speed gain? The bottom case still has the multiplication and the cast
every iteration, and it also has two sizeof's although they could be
optimized out. How does that work? Is the multiplication optimized out
because it is in the condition clause of the for loop?
Hein Zelle
>-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-<
Unix is user friendly. It's just very particular about who
it's friends are.
Hein Zelle hein@xxxxxxxxxx
http://www.icce.rug.nl/~hein
>-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-<