Earlier quoted context omitted.
I think it's actually mostly the language. Rust idioms just generate a lot of code. Clang is in a worse spot than rustc is in terms of emitting good LLVM IR, since it has no IR aside from the AST. By contrast, rustc has MIR which is more amenable to optimizations. At this point I'm fairly sure the problem is just that C code naturally generates less IR than Rust code does. All those function calls that go into iterat…
Modern C++ is in a similar situation with iterators, indexing, etc. and it's still often faster for LLVM to get through. MIR optimization can help close the gap but that still involved generating "garbage" that takes extra time to codegen (in Debug) or optimize out (in Release). Being smarter about generating IR, whether MIR or LLVM IR, is still an area rustc has a lot of room to improve, even given Rust's idioms. E.…
A possible new back end for Rust
211–220 of 224 posts
Re: A possible new back end for Rust
#212Earlier quoted context omitted.
Ah now we are into the opinion of experts in the matter don't count, only if I prove it myself? I guess that is why NVidia has spent 10 years doing hardware design to optimize their cards for C++ execution. Apparently that was wasted money, they should have kept using C.
I mentioned theory and experts, you said enough theory. I switched to practical applications and walk the talk showing my code, and then you back off and want to go back to opinions. I see now that you want to back myself with experts since reproducible code and runnable benchmarks is not enough. Apparently you recognize Nvidia as an expert so let's talk about CuDNN where optimizing convolution is all about memory la…
But then since you saw it was a lousing battle going down that path, you pulled the hardware rabbit trick out of the magician hat.
So we moved from C++ is not faster than C assertion, to memory layouts, hardware design and data representation.
Now you are even asserting that it's not about C vs C++ vs PTX, and going down quantum transport lane?
Yeah, whatever.
Re: A possible new back end for Rust
#213Earlier quoted context omitted.
I mentioned theory and experts, you said enough theory. I switched to practical applications and walk the talk showing my code, and then you back off and want to go back to opinions. I see now that you want to back myself with experts since reproducible code and runnable benchmarks is not enough. Apparently you recognize Nvidia as an expert so let's talk about CuDNN where optimizing convolution is all about memory la…
Nah, I was answering the whole "C vs C++" issue. But then since you saw it was a lousing battle going down that path, you pulled the hardware rabbit trick out of the magician hat. So we moved from C++ is not faster than C assertion, to memory layouts, hardware design and data representation. Now you are even asserting that it's not about C vs C++ vs PTX, and going down quantum transport lane? Yeah, whatever.
There is no C vs C++ issue, you keep saying that constexpr and template metaprogramming matter in high performance computing and GPGPU, I have given you links, benchmarks and actual code that showed you that what makes a difference is memory locality.
Ergo, as long as your language is low-level enough to control that locality, be it C, C++, Fortran, Rust, Nim, Zig, ... you can achieve speedups by several order of magnitude and it is absolutely required to get high-performance.
Constexpr and template metaprogramming don't matter in high performance computing, prove me wrong, walk the talk, don't drink the kool-aid.
There are plenty of well studied computation kernels you can use: matrix multiplication, convolution, ray-tracing, recurrent neural network, laplacian, video encoding, Cholesky decomposition, Gaussian filter, Jacobi, Heat, Gauss Seidel, ...
Re: A possible new back end for Rust
#214Earlier quoted context omitted.
Haskell, OCaml, SML, Idris also compile quite fast, with complex type systems. Their secret? Multiple backends with different kinds of optimizations. You don't need to compile for the ultimate release performance when in the middle of compile-debug-edit cycle.
Haskell and Idris both have very slow compilation time.
Re: A possible new back end for Rust
#215Earlier quoted context omitted.
Modern C++ is in a similar situation with iterators, indexing, etc. and it's still often faster for LLVM to get through. MIR optimization can help close the gap but that still involved generating "garbage" that takes extra time to codegen (in Debug) or optimize out (in Release). Being smarter about generating IR, whether MIR or LLVM IR, is still an area rustc has a lot of room to improve, even given Rust's idioms. E.…
I think people are way too hard on rustc. That linked issue is pretty esoteric and is a good example of the low-hanging fruit being picked. I doubt it'll move the needle much.
Re: A possible new back end for Rust
#216Earlier quoted context omitted.
There is a hidden floating-point environment that affects, and is affected by, every single floating-point instruction. Predominantly, this is rounding mode control, sticky bits, and exception control (does overflow cause a SIGFPE?), although most processors have some form of flushing denormals or treating them as 0s, which isn't in IEEE 754. LLVM's floating point instructions assume that there is no floating point e…
Is GIMPLE any worse or better in this regards?
It looks like the only major compiler that actually supports IEEE 754 correctly is icc. MSVC, gcc, and clang all optimize floating-point operations without considering if the dynamic environment is the same.
Re: A possible new back end for Rust
#217Earlier quoted context omitted.
> I can write a c++ compiler in a few months. Not that it substantially distracts from your point, but I strongly doubt this. Or did you mean a heavily restricted subset of C++? A C++ front end alone is so complex to build that these guys make a living off of licensing their front end code: https://www.edg.com/ (Fun fact: Microsoft rebuilt IntelliSense for C++ on the EDG front end. Yes, that Microsoft with the MSVC c…
Edg is writing a good front end. With good error handling and all of the other things that make a commercial program a few hundred times harder than a quick prototype. I'd be writing a brute force front end that is slow, and goes straight to assembly. If there is a syntax error I'll handle it by crashing. When you create a variable is used twice in a row I'll store the intermediate value back into memory and reload i…
I'd be curious where these classes draw the line. Do you happen to have a syllabus or so? I don't doubt you can implement a meaningful portion of C++ in a semester, but converting 500 pages of standardese into code within as many hours seems like an impossible goal for a class to me.
Re: A possible new back end for Rust
#218Earlier quoted context omitted.
I think we can all agree that LLVM IR is a more powerful compilation target than C. However, what Pizlo was saying is that generating C can be simpler than generating LLVM IR. A bunch of printfs can get you very far.
There are very few things that you can say in LLVM IR that you can't say in C.
Re: A possible new back end for Rust
#219Earlier quoted context omitted.
> There is no technical advantage to transforming Rust into C There is a key one: the ability to use any C compiler out there (including proprietary ones). This allows you to target all platforms out there.
A dumb interpreter for the IR as bootstraping stage is a better alternative. Plus very few platforms have only support for C and nothing else, unless we are speaking about esoteric embedded CPUs.
Then you can also add custom CPUs and systems, FPGAs, etc. Those are way more rare, but still something people use daily in some industries.
Re: A possible new back end for Rust
#220Earlier quoted context omitted.
It's complete enough to compile C11 programs - to me, that's as good of a benchmark as anything. The main thing qbe is missing for cproc's purposes is inline assembly and VLAs. DWARF support would also be nice, but no one seems to care enough to do the work yet.
Are you saying that qbe does not generate any debug information, or just not DWARF format?