David-Horner / text-format

0 stars 0 forks source link

Towards quantifying Optimization: explicit ideas related to #24 in riscv-code-size-reduction #20

Open David-Horner opened 3 years ago

David-Horner commented 3 years ago

depreciate JALR with low bit set.

We could provide an optional compatibility mode. But it will not be used. No compiler generates this code, nor would it. It is useless.

First make it reserved. Then determine its best use.

A possible use is as the high bit below sign in the offset of a revised JALR If the new code is run on an old implementation the problem should manifest in an obvious way. To quote spec:

Although there is potentially a slight loss of error checking in this case, in practice jumps to an incorrect instruction address will usually quickly raise an exception.

David-Horner commented 3 years ago

fast TBLJMP and CALLVEC backward emulation for HiFive E310

Encoding is in system instructions Only high bit set are optimized

swap t0,mtval
bgtz t0,swapBackforTrapHandler
 ;# fetch, load or store to negative addresses will be fatal
 ; # assume t0 is expendable temp var as is t1
xori t1,t0,X'73' # low 7  bits of SYSTEM OpCode
andi t1,t1,X'7F'    
bnez t1,oops # mtval lost - need to re-read from instruction address
  ;# 5 instructions with no memory references before we  can emulate. Not bad!!
..... Emulation code
MRTI   ;# low overhead return also, if all code under interrupts masked.
           ;# must also ensure ewxception does not happen!!