Some 370 Assembler Macros

ST R1,0(R4)  ; This instruction may occasionally fault.
  ST R4,EX   ; If so do this.
IF and ENDIF are assembler macros. In particular “IF FAULT” compiles no instructions but forms a new entry in a table consulted by the code that runs upon a mapping fault. This table had just a few entries for the 370 Keykos kernel. A table entry was a pair of instruction addresses: When a fault occurred the fault routine would merely consult the table to see if had occurred on one of the few kernel instructions followed by an “IF FAULT”. If the PC matched the first address of an entry it was replaced by the 2nd address in the entry and normal execution was resumed. The ENDIF macro compiled a branch to the instruction following “ST R1,0(R4)”. The instructions between the IF and ENDIF were placed out-of-line (elsewhere).

Such faults were rare and the normal case paid neither execution time or cache space to hold the exception code, or even the address of the exception code. The same pattern works for divide by zero but our kernel did not need that.

I see no reason why compilers cannot use just this pattern. A small negotiation with the run-time is necessary.

This pattern was not limited to privileged code, but was most used there.

More common variations on IF included “IF Z” often coded following an instruction that set the condition code. A conditional branch would then be produced to the out-of-line code. We considered but did not implement variations on the IF forms that compiled conditional branches. The variation would specify that the condition was likely true and then the nested code would be compiled in-line for better performance. There were few if any conditional branches in the 370 kernel that were likely. That is not true of other code that I have written. That it is true of the kernel warrants a philosophical note that I have not written.