On 12/07/2021 10:18, Richard Porter wrote:
> Yes, somebody does have to write the compiler, so it's inevitably less
> efficient than assembler code but more portable, one would hope.
There are two parts of a compiler, the front end which interprets the
human readable language, optimises it and produces an intermediate
representation, then the backend which is specific to a processor
architecture and converts that to native instructions.
I'll completely ignore whether the front end can produce better
optimised code than a human, as the original question was how new
instructions are added to the compiler backend.
With a simple CPU like the 6502 and ARM2, a human could do much better
than a contemporary compiler backend, being able to work out clever
tricks and shortcuts. But compilers have improved considerably and CPUs
have become far more complex. With ARMv7 and ARMv8 chips, a human is
hard pushed to remember all the instructions (integer, VFP, neon and
other special purpose instructions), never mind huge number of
constraints which affect the most efficient use of a superscalar pipeline.
Where as a compiler backend can be given information on thousands of
instructions and constraints, and work out which is the most optimal
combination is almost every circumstance. Even if a human could match
that, it would be diabolical waste of their time to attempt it.
---druck