armips icon indicating copy to clipboard operation
armips copied to clipboard

Safety of convenience macros

Open clbr opened this issue 5 years ago • 6 comments

The branch convenience macros are said to use sltu etc. This means they clobber a register, and the docs do not say which. This is a problem for RSP and other such platforms where there is no ABI to follow, and all registers may be in use.

clbr avatar Sep 27 '20 12:09 clbr

They use $at / r1. This indeed should be documented.

If you're in a context where $at cannot be safely used as the assembler temporary, you should not use any assembler macros. This register is normally reserved for this purpose.

-[Unknown]

unknownbrackets avatar Sep 27 '20 17:09 unknownbrackets

How can you know what is a macro and what isn't? The names are very similar to instructions.

Thus this is a multi-part request.

  • document which reg is used
  • add a warning: if the file uses both a macro and the r1 register, print a warning
  • add a directive that disables all such dangerous macros (note: not all macros)

clbr avatar Sep 28 '20 05:09 clbr

(I can't edit) the warning should only be if a dangerous macro is used naturally, not any macro.

clbr avatar Sep 28 '20 05:09 clbr

I feel documenting that the macros may use r1 for temporary values (as specified by the standard MIPS ABI) is enough here. If the code doesn't conform to the standard ABI then the usage of convenience macros is the risk of the user. The proposed warnings would have both false positives (when your own code uses r1 for a temporary value in another place) and false negatives (when code that isn't changed relies on r1 being unchanged).

A directive for disabling MIPS macros could be worth having though.

Kingcom avatar Oct 04 '20 13:10 Kingcom

Please only have it disable the dangerous macros; li, la, the load/store ones don't clobber, I believe.

clbr avatar Oct 04 '20 16:10 clbr

The store macros clobber r1 as well since they need a register for storing the upper half of the address, and unlike loads they can not use the load destination register for that.

sp1187 avatar Oct 04 '20 17:10 sp1187