3 ms·
What makes C problematic is that the language is specified in terms of an abstract machine that looks absolutely nothing like real hardware, and executing instr
by protomyth 8y ago
What makes C problematic is that the language is specified in terms of an abstract machine that looks absolutely nothing like real hardware, and executing instructions that make no sense in the abstract machine but are very well-defined in the real hardware is liable to cause problems for the optimizer in the compiler.
Is there a language (other than assembly) that would have a closer model to the hardware?
- jcranmer 8y agoTo my knowledge, there isn't any language that really tries to be the kind of "portable assembler" that people try to shoehorn C into. There just really isn't the demand for it, since trying to be a portable assembler requires trading off fidelity to hardware for optimization, and most people would rather have faster code than more accurate hardware representation. The internal IRs of compilers (such as LLVM IR or GCC GIMPLE) is likely to be much more accurate to hardware (and the ones I called out are indeed so). It's debatable if you want to actually call these non-assembly languages, though.
- tom_mellior 8y agoThe claim about compiler IRs is strange. For one thing, hardware is different. Which hardware are you claiming LLVM IR is "accurate" to? More concretely, LLVM IR has integer types for any bit size, while actual hardware architectures have only a few. Many real CPUs have condition code registers set as side effects of operations, while LLVM requires explicit compares, etc.
- jcranmer 8y agoThe big thing that you see in LLVM IR that you don't see in C is vector register support. There is also support for multiple return values, as well as some better coverage of hardware instructions via intrinsics (e.g., fma). It is somewhat poor in support for things like exposing hardware exceptions and the condition code support, and its support for vectors, floating point, and bit sizes is definitely in the realm of supporting union of architectural possibilities instead of the intersection. I definitely would not call LLVM IR accurate to hardware, but it is more accurate than C is.
- agumonkey 8y agoMaybe something generic that can infer interfaces and algebras from VLSI. (I sound like fluff but I had a few ideas in the past about a way to map hardware closer to avoid ambiguity pain and inefficiencies, I just can't remember)