By ref and by pointer kills performance.

jmh530 john.michael.hall at gmail.com
Tue Feb 13 15:40:23 UTC 2024


On Tuesday, 13 February 2024 at 06:02:47 UTC, Bruce Carneal wrote:
> [snip]
>
> To reuse the value the compiler would have to prove that the 
> memory locations do not overlap.  FORTRAN does not have this 
> problem, neither does ldc once you take responsibility for 
> non-overlap with the @restrict attribute as seen here:
>
> https://d.godbolt.org/z/z9vYndWqP
>
> When loops are involved between potentially overlapping indexed 
> arrays I've seen ldc go through the proof and do two versions 
> of the code with a branch.

As a heads up, the LDC wiki page doesn't have restrict on it.

https://wiki.dlang.org/LDC-specific_language_changes

Does LDC's @restrict only work with pointers directly and not 
slices? `fillRestricted2` doesn't compile (it only fails because 
`value` is a slice, not because `dest` is one. But 
`fillRestricted3` compiles just fine.

```d
void fillRestricted2(@restrict uint[] value, uint[] dest)
{
     dest[0] = value[0];
     dest[1] = value[1];
     dest[2] = value[2];
     dest[3] = value[3];
}

void fillRestricted3(@restrict uint* value, uint[] dest)
{
     dest[0] = value[0];
     dest[1] = value[1];
     dest[2] = value[2];
     dest[3] = value[3];
}

```


More information about the Digitalmars-d mailing list