By ref and by pointer kills performance.

Patrick Schluter Patrick.Schluter at bbox.fr
Tue Feb 13 15:14:06 UTC 2024


On Tuesday, 13 February 2024 at 03:31:31 UTC, Richard (Rikki) 
Andrew Cattermole wrote:
> dmd having bad codegen here isn't a surprise, that is to be 
> expected.
>
> Now for ldc:
>
> ```d
> void fillBP(immutable(uint*) value, uint* dest) {
>      dest[0] = *value;
>      dest[1] = *value;
>      dest[2] = *value;
>      dest[3] = *value;
> }
> ```
>
> I expected that to not do the extra loads, but it did.
>
> ```d
> void fillBP(immutable(uint*) value, uint* dest) {
> 	dest[0 .. 4][] = *value;
> }
> ```
>
> And that certainly should not be doing it either.
> Even if it wasn't immutable.
>
> For your code, because it is not immutable and therefore can be 
> changed externally on another thread, the fact that the 
> compiler has to do the loads is correct. This isn't a bug.

Is not a thread issue. The memory the pointers point to only 
needs to overlap and the loads are required to get the "right" 
result.


More information about the Digitalmars-d mailing list