Question on ORG.SaveRegs / ORG.RestoreRegs in the FPGA Oberon compiler
...but ALSO for *regular* procedures, i.e. in ORP.StatSequence…
But in this case, surely RH is 0 so no registers are saved? Maybe the apparent asymmetry comes from having to handle procedure variables too.
That’s indeed the reason: when one calls a procedure variable, e.g. V.handle in Viewers, then dereferencing V to get to V.handle in ORP.selector/ ORG.DeRef will use up an additional register, so RH = 1 in PrepCall. But still, shouldn’t this register be somehow accounted for ? Perhaps with the second of the following lines in ORG.Call: IF x.mode <= ORB.Par THEN load(x); DEC(RH) ELSE Put2(Ldr, RH, SP, 0); Put1(Add, SP, SP, 4); DEC(r); DEC(frame, 4) <--- END ; I just haven’t investigated yet.. -ap
But still, shouldn’t this register be somehow accounted for ? ... by ELSE Put2(Ldr, RH, SP, 0); Put1(Add, SP, SP, 4); DEC(r); DEC(frame, 4)
Right. If the procedure variable was not actually loaded before the parameters were evaluated (ie the procedure was not the result of an expression), no registers needed to be saved, so the save is explicitly avoided. It's only in the case where it was already loaded into a register (detected by RH > 0 before the save), where it was therefore saved (first, fortunately), and consequently needs to be explicitly restored. It's RestoreRegs(1), in effect, but only in that case. Anyway, I'm labouring it, you've answered your own question! :) Cheers Paul
Am 18.12.18 um 22:41 schrieb Paul Reed:
But still, shouldn’t this register be somehow accounted for ? ... by ELSE Put2(Ldr, RH, SP, 0); Put1(Add, SP, SP, 4); DEC(r); DEC(frame, 4) Right. If the procedure variable was not actually loaded before the parameters were evaluated (ie the procedure was not the result of an expression), no registers needed to be saved, so the save is explicitly avoided.
There comes the question: why is the register variable loaded before the parameters are evaluated? To save a register? This should not matter on RISC5. Looks to me it would be much nicer code without. Peter
Hi Peter,
There comes the question: why is the register variable loaded before the parameters are evaluated? To save a register? This should not matter on RISC5. Looks to me it would be much nicer code without.
Not sure what you mean. The value of the procedure (proper procedure or function) variable will be in a register before the parameter evaluation if, for example, it comes from looking up in an array or dereferencing a pointer. Cheers, Paul
Am 19.12.18 um 18:08 schrieb Paul Reed:
Hi Peter,
There comes the question: why is the register variable loaded before the parameters are evaluated? To save a register? This should not matter on RISC5. Looks to me it would be much nicer code without.
Not sure what you mean. The value of the procedure (proper procedure or function) variable will be in a register before the parameter evaluation if, for example, it comes from looking up in an array or dereferencing a pointer.
Currently, the procedure address is put in R0, R0 is stored on stack, the parameters are passed beginning from R0 and procedure address is loaded from stack to next free register. I suppose it would be possible as well to first pass the parameters beginning with R0 and then directly put procedure address in next free register. Peter
... I suppose it would be possible as well to first pass the parameters beginning with R0 and then directly put procedure address in next free register.
How would you know which register to use, in advance, since evaluating each parameter could involve expressions? I don't think you're talking about Prof. Wirth's 2800-line compiler anymore, are you? ;-)
Am 19.12.18 um 19:00 schrieb Paul Reed:
... I suppose it would be possible as well to first pass the parameters beginning with R0 and then directly put procedure address in next free register.
How would you know which register to use, in advance, since evaluating each parameter could involve expressions?
I don't think you're talking about Prof. Wirth's 2800-line compiler anymore, are you? ;-) Still talking about Project Oberon compiler, but I use different back end.
Answer to my question is that e.g. in Display.Handle at F.handle(F, M), F is dereferenced before you know the amount of parameters, and for this, it is easiest to intertemporally store the value on the stack. Peter
participants (3)
-
Andreas Pirklbauer -
Paul Reed -
Peter Matthias