By ref and by pointer kills performance.

Richard (Rikki) Andrew Cattermole richard at cattermole.co.nz
Wed Feb 14 05:09:11 UTC 2024


On 14/02/2024 5:49 PM, Walter Bright wrote:
> On 2/12/2024 7:31 PM, Richard (Rikki) Andrew Cattermole wrote:
>> dmd having bad codegen here isn't a surprise, that is to be expected.
> 
> I'm used to people saying that DMD doesn't do data flow analysis. It 
> does. In fact, it is based on my OptimumC, which was the first C 
> compiler on DOS to do DFA back in the 1980s.
> 
> This isn't a case of buggy DFA. It's a case of doing DFA correctly.
> 
> The issue is pointer aliasing. A pointer can point to anything, 
> including const data. Therefore, storing through a pointer can alter any 
> value that is reachable via a pointer. Therefore, storing through a 
> pointer invalidates any cached value already read.
> 
> This is what you're seeing.
> 
> C99 tried to address this with __restrict, but few people use it or 
> understand it. D didn't bother with it because people will inevitably 
> misuse __restrict and get their data mysteriously corrupted.

I'm aware that what dmd is doing is right. But it isn't using SIMD 
either, so there is some performance left on the table.

A backend today vs 15 years ago is very different in terms of what they 
can do. Let alone one that last saw significant active development 30 
years ago.

I suggest that you have a chat with Bruce about this during the next 
meetup. We've been trying to explain to you just how backends have 
changed over the years from a users perspective. The ones today can only 
be described with one word: magical.

But I will say this: 20 years ago you needed inline assembly, 10 years 
ago you needed intrinsics, today you may not need to do anything special 
in D, although will in C++.


More information about the Digitalmars-d mailing list