2 ms·
> Branch probability analysis | Branch prediction > Peephole optimisations, idioms | Idioms From the software side, what is it exactly that makes it so diffic
by uticus 4y ago
> Branch probability analysis | Branch prediction
> Peephole optimisations, idioms | Idioms
From the software side, what is it exactly that makes it so difficult to write a higher-level language that must be optimized, instead of a language that already exposes the optimizations in a friendly way?
("higher-level language" meaning c, not python or something)
- Pet_Ant 4y agoWell the low-level implementations differ from cpu-to-cpu. Even between Itanium releases the width changes. They don't want to get bound to a single implementation as techniques improve and new approaches are found. Otherwise, each time they discover something new they'd have to release a new ISA and backwards compatibility was the most commercially influential aspect of a chip. Now, it used to be that super-computer were made with custom chips, with custom ISAs, but the advantage of mass consumer parts is too high. So in general the decoupling of implementation and programming language allows for enough wiggle room to allow independent evolution without being rigidly coupled.
- avianes 4y agoNot sure what is exactly your thought, since the optimizations you quote don't really takes advantage of any exposed optimization feature of the language. Are your asking why we could not expose optimization feature (e.g. branch hint to replace branch-prediction) in the programming language ? Are you asking if it's difficult for a compiler to optimize some type of high-level languages ? Since "higher-level" language is C in your question, what the "language that already exposes the optimizations in a friendly way" ? Are you thinking the CPU µop as a language ?
- JonChesterfield 4y agoThe literal answer is that compilers are really easy to write when the source and destination language are the same and you don't want any optimisation. E.g. write the x64 machine code out as raw bytes and cat is good enough to turn it into x64 machine code. Difficulty increases as the source and target languages become less similar, as more ambitious performance optimisations are attempted, as more comprehensive type/lint/warning style systems are implemented and as performance constraints on the compiler itself tighten. So a compiler that takes imprecise scribblings, spots errors in them, and emits asymptotically perfect machine code for heterogenous distributed systems in real time is quite dramatically more complicated than cat.