Earlier quoted context omitted.
This is basically what many functional programming languages do. This always came with plausibly sounding claims that this allows so much better optimizations that this soon will surpass imperative programs in performance, but this never materialized (it still did not - even though Rust fans now adopted this claim, it still isn't quite true). Also control over explicit memory layout is still more important.
Gah, can't believe I forgot about functional programming languages here :( > even though Rust fans now adopted this claim Did they? Rust's references seem pretty pointer-like to me on the scale of "has pointers" to "pointers have been entirely removed from the language". (Obviously Rust has actual pointers as well, but since usefully using them requires unsafe I assume they're out of scope here)
Aliasing
21–30 of 36 posts
Re: Aliasing
#22Earlier quoted context omitted.
Is it? You just add "restrict" where needed? https://godbolt.org/z/jva4shbjs
> Is it? You just add "restrict" where needed? Yes. That is the main solution and it is not a good one. 1- `restrict` need to be used carefully. Putting it everywhere in large codebase can lead to pretty tricky bugs if aliasing does occurs under the hood. 1- Restrict is not an official keyword in C++. C++ always has refused to standardize it because it plays terribly with almost any object model.
For C++, yes, I agree.
Re: Aliasing
#23Re: Aliasing
#24I wonder how much potential optimisation there is if we entirely drop pointer nonsense.
For a system programming language the right solution is to properly track aliasing information in the type system as done in Rust. Aliasing issues is just yet another instance of C/C++ inferiority holding the industry back. C could've learnt from Fortran, but we ended up with the language we have...
void foo(void *a, void *b, int n) {
assume_aligned(a, 16);
assume_stride(a, 16);
assume_distinct(a, b);
... go and vectorize!
}Re: Aliasing
#25Earlier quoted context omitted.
For a system programming language the right solution is to properly track aliasing information in the type system as done in Rust. Aliasing issues is just yet another instance of C/C++ inferiority holding the industry back. C could've learnt from Fortran, but we ended up with the language we have...
For systems programming the correct way is to have explicit annotations so you can tell the compiler things like: void foo(void *a, void *b, int n) { assume_aligned(a, 16); assume_stride(a, 16); assume_distinct(a, b); ... go and vectorize! }
Just look at the utter failure of `restrict`. It was so rarely used in C that it took several years of constant nagging from Rust developers to iron out various bugs in compilers caused by it.
Re: Aliasing
#26Earlier quoted context omitted.
Aliasing can be a problem in Fortran too. Decades ago I was a Fortran developer and encountered a very odd bug in which the wrong values were being calculated. After a lot of investigation I tracked it down to a subroutine call in which a hard-coded zero was being passed as an argument. It turned out that in the body of that subroutine the value 4 was being assigned to that parameter for some reason. The side effect…
How does this bug concern aliasing?
"Passing constants to a subprogram" https://www.ibiblio.org/pub/languages/fortran/ch1-8.html
Re: Aliasing
#27When you have done enough C++ you don't need to fire up compiler explorer, you just use local variables to avoid aliasing pessimisations. I also wrote about this a while ago: https://forwardscattering.org/post/51
I think this might not be a shortcoming of MSVC but rather a deliberate design decision. It seems likely that MSVC is failing to apply strict aliasing, but that it's deliberately avoiding it, probably for compatibility reasons with code that wasn't/isn't written to spec. And frankly it can be very onerous to write code that is 100% correct per the standard when dealing with e.g. memory-mapped files; I'm struggling to…
Re: Aliasing
#28Earlier quoted context omitted.
Gah, can't believe I forgot about functional programming languages here :( > even though Rust fans now adopted this claim Did they? Rust's references seem pretty pointer-like to me on the scale of "has pointers" to "pointers have been entirely removed from the language". (Obviously Rust has actual pointers as well, but since usefully using them requires unsafe I assume they're out of scope here)
What I meant is that Rust has stricter aliasing rules which make some optimization possible without extra annotations, but this is balanced out by many other issues.
Re: Aliasing
#29Re: Aliasing
#30Earlier quoted context omitted.
For systems programming the correct way is to have explicit annotations so you can tell the compiler things like: void foo(void *a, void *b, int n) { assume_aligned(a, 16); assume_stride(a, 16); assume_distinct(a, b); ... go and vectorize! }
LOL, nope. Those annotations must be part of the type system (e.g. `&mut T` in Rust) and must be checked by the compiler (the borrow checker). The language can provide escape hatches like `unsafe`, but they should be rarely used. Without it you get a fragile footgunny mess. Just look at the utter failure of `restrict`. It was so rarely used in C that it took several years of constant nagging from Rust developers to i…