Mad-Pascal icon indicating copy to clipboard operation
Mad-Pascal copied to clipboard

[Optimizing] Extra jump to the correct part of the procedure when there are sub-functions in the function/procedure.

Open GSoftwareDevelopment opened this issue 1 year ago • 3 comments

We have such a piece of code:

Procedure myProc();

  Function myFunc:byte;
  Begin
    { some code here }
  End;

Begin
  { some code here }
End;

Begin
  myProc;
End.

Its result after compilation is more or less as follows:

{...}

.local MYPROC
  jmp l_xxx

.local MYFUNC
 { assembled code of function myFunc() }
  rts
.endl

l_xxx
 { assembled code of procedure myProc() }
 rts
.endl
{...}

{ somewhere in code }

  jmp MYPROC

{...}

Now, when the program makes a jump to the procedure myProc it jumps to the address where jmp l_xxx is, and not, to the address where the label l_xxx points to. I can understand that this JMP l_xxx may be due to some compiler rules - forgive me, I don't know anything about compilers :) However, in time-critical situations, this jump is precious cycles.

My question. Would it be possible to optimise this phenomenon? :)

I'll honestly say that even during debugging, it can mess with my head a bit ;) and I won't mention the precious cycles ;)

GSoftwareDevelopment avatar Sep 14 '23 17:09 GSoftwareDevelopment

3 cycles ? really ?

tebe6502 avatar Sep 20 '23 09:09 tebe6502

And you are asking for 3 cycles? Seriously? ;)

For my side, really really :D

GSoftwareDevelopment avatar Sep 21 '23 09:09 GSoftwareDevelopment

Don't be like a clerk sending you back to a room where they have to tell you where to go.

GSoftwareDevelopment avatar Sep 21 '23 09:09 GSoftwareDevelopment