5 ms·
The point of the article is that precisely what you suggest will have extremely bad consequences for optimization. In your proposal, how do you propose to solv
by pcwalton 11y ago
The point of the article is that precisely what you suggest will have extremely bad consequences for optimization.
In your proposal, how do you propose to solve the load-load forwarding issue described in the article?
- pjmlp 11y agoBy taking the approach that in proper engineering quality should precede "anything goes" mentality.
- pcwalton 11y agoThat's very philosophical. It also fails to describe a technical solution to the problem. What is the specific solution to the specific load-load forwarding problem described in the article? This is a technical problem that needs a specific technical solution, not philosophy.
- pjmlp 11y agoI replied to it, indirectly. My position is the same as Tony Hoare, optimizations that exploit undefined behavior or contribute to possible malfunctioning programs are not to be done at all.
- pcwalton 11y agoThen you are making programs at least 2x slower, probably much more. That is untenable for many of us who are using C and C++. Customers will simply not accept e.g. browser engines that are 2x slower.
- twic 11y ago> Then you are making programs at least 2x slower, probably much more. Then how come programs written in languages which don't have undefined behaviour, like Java, are not 2x slower than those written in C?
- jerf 11y agoBecause they aren't C. I think it's not just that "undefined behavior can be optimized" in some abstract sense but that in particular C has the problem that its undefined behavior is where a lot of optimizations live. This is due to a combination of the language being very old now, and the hardware world having moved on a lot since it was (half-)specified. I really don't consider this a criticism of C per se or its designers. It is unreasonable to expect that a language specified in the 1970s would be tuned for either modern processors or have the benefit of an additional 40 years of collective experience. But it is, nevertheless, true. (It's part of why my position is very much that this entire approach just won't work. C is pretty much what it is; it can not be changed. It is literally easier to use another language than to try to specify a "friendly C" in 2016. And I don't say that because I don't know how large a task it is to start writing code in another language; I say that because people are really underestimating how much work Friendly C will take. I suggest that everyone observe that all who have now seriously tried to sketch what this would look like have immediately given up and totally surrendered. This means something.)
- pjmlp 11y agoThere is another reason for C's undefined behavior. Back when the language was being standardize, there was way more hardware diversity than there is now and C implementations outside UNIX, even K&R ones, had lots of semantic differences. As no compiler vendor involved in the first ANSI C process wanted to give up on their semantics, all of them were swept into "undefined behavior".
- jerf 11y agoKinda part of what I meant by "the hardware world having moved on a lot". I mean, I can hardly think of a way in which it is the same world, except perhaps a vague von-Neumann-esque architecture still being used, but even that's a lot different than it used to, thanks to the way that nowadays even assembler code is really just a specification to the CPU, rather than an execution plan, since the CPU recompiles it to internal microcode and just does whatever it likes instead on the fly. Almost nothing is the same as it was back then.
- pjmlp 11y agoGiven the amount of CVE entries related to such optimizations bugs, should we really keep doing them in name of speed? EDIT: There is always Assembly, after properly using a profiler, instead of relying in undefined behavior outcomes that are compiler specific and can even change between releases.
- nickpsecurity 11y agoExactly. Either that or some high-level assembler along the lines of SSA code. They can't tell me they're getting better performance with a superior method if they also can't tell me if the code will consistently work. The whole concept is ludicrous of building our program's correctness and performance on top of compiler attributes that are little to non-documented and not guaranteed to remain. Plus, most of the software runs on x86 (now ARM) anyway. So, that's two ISA's to account for outside of operating systems, embedded, and ISV's for unusual platforms. Even then, one might use a subset of C with no undefined behavior and then make platform-specific optimizers. So, two possibilities that make a lot of sense vs depending on known unknowns plus transforms without safety arguments.
- nickpsecurity 11y agoI don't know enough about C language and compiler technology to give a specific recommendation on that. However, your other comment on Java hints that its a hold-over from bad language design. Also, I recall that Fortran compilers could optimize the heck out of code that C compilers held back on specifically because Fortran was more deterministic. The compiler knew what the code was doing and could guess where usage was going. C's properties made the same code a giant unknown due to effects of pointers. My overall point is that you can do an optimization from a set of statements with specific meaning at least as easy as you can from one with unknown meaning. So, a similarly low-level language with well-defined behavior could be optimized at least as much as C. However, since compiler faces uncertainty, the argument doesn't work the other way around. That's why C and its undefined behavior are bad by design. And hence all the discussions on workarounds like the OP.