4 ms·
Is the C++ standards committee trying to make the language as incomprehensible to its users as possible? I cannot even begin to comprehend what assembly is goi
by cjhanks 8y ago
Is the C++ standards committee trying to make the language as incomprehensible to its users as possible?
I cannot even begin to comprehend what assembly is going to be generated in this code sample. Are those calls indirect? Can they be vectorized? How much stack space is this going to use? What (if anything) gets put on the heap?
- saagarjha 8y agoThe C++ standard has nothing to do with these, and you won’t find a mention of them at all in the text of the standard. The standard defines an abstract virtual machine for running C++ code, and it lays out the guidelines for what compilers are allowed to do with regards to the optimizations you mentioned.
- repsilat 8y agoThis is kinda true in theory, but about as far from the truth as you can be in practice. Zero-overhead abstraction is a core part of the language's philosophy, and that means features are designed to be translated to "efficient" machine code. If nobody believed that optimising compilers could wring something decent out of these features they wouldn't have been standardised.
- saagarjha 8y agoThe abstract machine is designed to be relatively easy and efficient to implement, but specific features such as vectorization are not part of the standard. Remember, C++ runs on machines that don’t support any “advanced” features, so there is a limit to what can be required in the standard.
- cjhanks 8y agoI understand what you are saying, and I agree that it's true in principle. But, if C++ did not provide me predictable optimizations - it would be worthless to me. I know scientific computing is only one domain of computing. But without this level of intuition for code -> asm. My day becomes filled with reading objdump outputs, I don't want that.
- htfy96 8y agoYou cannot understand every assembly generated by modern compilers either. Both C & C++ provide no guarantee for any of these. Since ranges is basically a pair of begin/end iterator, I think it will be almost identical to it.
- alacombe 8y agoI've got the feeling this is the kind of language tooling that will get you a 0.5% compiler-specific performance improvement in very specific real-life work case. Most companies are still busy dealing with their C++98 backlog libraries. I don't expect this to get in production code within 5 to 10 years...
- gpderetta 8y agoI haven't tried to compile these specific examples, but a while ago Eric wrote an article about the abstraction cost of (a previous iteration of) the range library. At least GCC generated pretty much the same assembly as the hand written nested for loops. Since then, both the library and compilers have improved.