PB4 final - ASM Output (unneeded jmp?)

Everything else that doesn't fall into one of the other PB categories.
va!n
Addict
Addict
Posts: 1104
Joined: Wed Apr 20, 2005 12:48 pm

PB4 final - ASM Output (unneeded jmp?)

Post by va!n »

I noticed following while taking a clother look to the created ASM output when using procedures:

Code: Select all

... code ...
JMP   _EndProcedure9
; EndProcedure
XOR    eax,eax       ; <<< this will never be called, so we can save the JMP
_EndProcedure9:
RET    4
whats the reason for it? (small mistake?) what about changing to...

Code: Select all

... code ...
; JMP   _EndProcedure9
; EndProcedure
; XOR    eax,eax
; _EndProcedure9:
RET    4 
Seems this happens to any procedure you are using! o_O
va!n aka Thorsten

Intel i7-980X Extreme Edition, 12 GB DDR3, Radeon 5870 2GB, Windows7 x64,
User avatar
Deeem2031
Enthusiast
Enthusiast
Posts: 216
Joined: Sat Sep 20, 2003 3:57 pm
Location: Germany
Contact:

Post by Deeem2031 »

Its the same like in 3.94. If you use ProcedureReturn at the end of the procedure it JMPs to the end to avoid reseting eax. Because if you don't use ProcedureReturn at the end it must always return 0. (Of course its the same with strings)
So its just a thing what could be optimized, but it isn't a bug.

My Optimizer for 3.94 removed this JMP if its possible. Fred said he would include a optimize-interface for the compiler to let dlls optimize the asm-output so i didn't tried to convert the Optimizer for 4.0. Fred - whats with the interface? ;)
irc://irc.freenode.org/#purebasic
Trond
Always Here
Always Here
Posts: 7446
Joined: Mon Sep 22, 2003 6:45 pm
Location: Norway

Post by Trond »

How much is one unneeded jump. Take a look at this:

Code: Select all

; If - (Not #False)
  JMP     No0
  XOR    eax,eax ; Never reached
  JMP    Ok0 ; Never reached
No0:
  MOV    eax,1
Ok0:
  MOV    ebx,eax ; Moving 1 into eax, then eax into ebx, then negating ebx instead of moving 0 into ebx!
  NEG    ebx
  AND    ebx,ebx
  JE    _EndIf2
; Debug 1
; EndIf
_EndIf2:
That's 7 unneccessary instructions. It could all have been simplified into the single "Debug 1" statement.

But personally I think it's worse that this gives a compiles without errors:

Code: Select all

If And Not Not And Or Not And Or Not And
  Debug 1
EndIf
And we have a problem here:

Code: Select all

If #False = Not(#True)
  Debug 1
EndIf
Fred
Administrator
Administrator
Posts: 18351
Joined: Fri May 17, 2002 4:39 pm
Location: France
Contact:

Post by Fred »

About the extra jump, it is still here because it is not that easy to remove it without ugly tricks in the compiler pipeline.

BTW, a compiler isn't here to optimize bad codes. If it can be simplified, just do it.
va!n
Addict
Addict
Posts: 1104
Joined: Wed Apr 20, 2005 12:48 pm

Post by va!n »

@Deeem2031:
I have searched the announced (optimizer) plugin interface too but seems its sadly not included to v4 final. the only available switches are:

/CONSTANT /IGNORERESIDENT /LINKER /VERSION /UNICODE /THREAD /LINENUMBERING /DYNAMICCPU /SSE2 /SSE /3DNOW /MMX /CONSOLE /DLL /INLINEASM /SUBSYSTEM /RESOURCE /RESIDENT /XP /REASM /QUIET /ICON /EXE /DEBUGGER /COMMENTED /STANDBY

Btw, Deeem2031: how is your project going on? (i think you know what i am talking about ^^) have a nice day
va!n aka Thorsten

Intel i7-980X Extreme Edition, 12 GB DDR3, Radeon 5870 2GB, Windows7 x64,
Post Reply