Author: steve-myers
Posted: Wed Feb 08, 2017 9:01 pm (GMT 5.5)
When the relative branch instruction came out in the 1990s, my analysis is the main beneficiary would be the compilers, which do tend to write relatively large blocks of code compared to Assembler programmers. For a couple of years, say from 2010 to 2013, I got in a jag where I just used relative branch instructions, but them I just mostly switched to conventional BC instructions.
In 1991, when I was unemployed for a considerable period, I learned C, and learned the C qsort library function function. By the end of 1991 I was back in real machines and using Assembler again. In 1993 I wrote QSORT. Like qsort it uses a compare function. After a while, I realized that by using BRC instructions I did not need a base register for the compare function, so I could cut down the registers I use, and the registers I had to save and restore. Shades of XPLINK. QSORT calls the compare function using conventional linkage -
CALL compare,(address1,address2)
Most programs that use QSORT call it multiple times, with multiple compare functions. The compare functions pretty much use a common startup sequence, usually -
SAVE 14
LM 14,15,0(1)
LR 1,15
LA 15,1
* Insert compare code here.
Register 15 has an initial return code, the qsort staples - negative, 0, positive, with the same meanings.
All of the compare functions share a common suffix, generally
Sometimes you get to SC0100 as a fall through when there is no less than or greater than branch, SC0200 or SC0300 are generally branched to by JL SC0200 or JH SC0300. The compare function is performance critical, so everything I can save is a step in the right direction. I do not save and restore registers 0 and 1 because QSORT doesn't need them. The actual CALL macro in QSORT is
LR R15,R5
CALL (15),((R9),(R10)),MF=(E,PARMLIST)
Registers 14, 15 and 1 are trashed by the macro, and QSORT does not actually use register 0. Register 5 has the address of the compare routine. Obviously registers 2 through 13 cannot be altered by by the compare function, but it doesn't use them anyway.
Now if the compare function needs its own base register, it would be coded differently, probably
USING *,2
SAVE (14,2)
LR 2,15
LA 15,1
...
RETURN (14,2),RC=(15)
The SAVE macro expands as
+ STM 14,2,12(13)
compared to
+ ST 14,12(,13)
and RETURN expands as
+ L 14,12(,13)
+ LM 0,2,20(13)
+ BR 14
compared to
+ L 14,12(,13)
+ BR 14
Posted: Wed Feb 08, 2017 9:01 pm (GMT 5.5)
When the relative branch instruction came out in the 1990s, my analysis is the main beneficiary would be the compilers, which do tend to write relatively large blocks of code compared to Assembler programmers. For a couple of years, say from 2010 to 2013, I got in a jag where I just used relative branch instructions, but them I just mostly switched to conventional BC instructions.
In 1991, when I was unemployed for a considerable period, I learned C, and learned the C qsort library function function. By the end of 1991 I was back in real machines and using Assembler again. In 1993 I wrote QSORT. Like qsort it uses a compare function. After a while, I realized that by using BRC instructions I did not need a base register for the compare function, so I could cut down the registers I use, and the registers I had to save and restore. Shades of XPLINK. QSORT calls the compare function using conventional linkage -
CALL compare,(address1,address2)
Most programs that use QSORT call it multiple times, with multiple compare functions. The compare functions pretty much use a common startup sequence, usually -
SAVE 14
LM 14,15,0(1)
LR 1,15
LA 15,1
* Insert compare code here.
Register 15 has an initial return code, the qsort staples - negative, 0, positive, with the same meanings.
All of the compare functions share a common suffix, generally
Code: |
SC0100 SR 15,15 BRC 15,SC0300 SC0200 LNR 15,15 SC0300 RETURN 14,RC=(15) |
LR R15,R5
CALL (15),((R9),(R10)),MF=(E,PARMLIST)
Registers 14, 15 and 1 are trashed by the macro, and QSORT does not actually use register 0. Register 5 has the address of the compare routine. Obviously registers 2 through 13 cannot be altered by by the compare function, but it doesn't use them anyway.
Now if the compare function needs its own base register, it would be coded differently, probably
USING *,2
SAVE (14,2)
LR 2,15
LA 15,1
...
RETURN (14,2),RC=(15)
The SAVE macro expands as
+ STM 14,2,12(13)
compared to
+ ST 14,12(,13)
and RETURN expands as
+ L 14,12(,13)
+ LM 0,2,20(13)
+ BR 14
compared to
+ L 14,12(,13)
+ BR 14