Ich habe mal folgendes getestet und wundere mich über die Ergebnisse.
Normal sollte ein >> schneller sein, als ein / . Beim Shiften werden
alle Bits um einen Platz nach rechts verschoben, sodass ein Bit herausfällt.
In der Hilfe ist es auch noch etwas genauer beschrieben.
Nun dachte ich, man könnte sich mal das ASM-Ergebnis nach einem
pbcompiler "ShiftTest.pb" /COMMENTED mal anschauen, wie es im
ASM aussieht.
Ich hoffe das ausgeben des kommentierten ASM-Souce ist soweit korrekt
PS: Den Kopf habe ich weggelassen
Hier mal der PB-Testsouce:
Code: Alles auswählen
For a=0 To 9
start=0
Wert=0
start=ElapsedMilliseconds()
For i = 0 To 1000000
Wert = 569878993>>1
Next i
Debug ElapsedMilliseconds()-start
;Debug Wert
;
start=0
Wert=0
start=ElapsedMilliseconds()
For i = 0 To 1000000
Wert = 569878993/2
Next i
Debug ElapsedMilliseconds()-start
;Debug Wert
Debug"------------------------"
Next a
Die ASM-Ausgabe dazu hier:
Wenn ich das richtig sehe, wird hier nicht geteilt, sondern nur der schon
vorher ausgerechnete Wert in den Schleifen wiederholt.
Code: Alles auswählen
PureBasicStart:
;
PUSH dword I_BSSEnd-I_BSSStart
PUSH dword 0
PUSH dword I_BSSStart
CALL _memset
ADD esp,12
PUSH dword 0
CALL _GetModuleHandleA@4
MOV [_PB_Instance],eax
PUSH dword 0
PUSH dword 4096
PUSH dword 0
CALL _HeapCreate@12
MOV [PB_MemoryBase],eax
; :
; For a=0 To 9
MOV dword [v_a],0
_For1:
MOV eax,9
CMP eax,dword [v_a]
JL _Next2
; start=0
MOV dword [v_start],0
; Wert=0
MOV dword [v_Wert],0
; start=ElapsedMilliseconds()
CALL _PB_ElapsedMilliseconds@0
MOV dword [v_start],eax
; For i = 0 To 1000000
MOV dword [v_i],0
_For3:
MOV eax,1000000
CMP eax,dword [v_i]
JL _Next4
; Wert = 569878993>>1
MOV dword [v_Wert],284939496
; Next i
_NextContinue4:
INC dword [v_i]
JMP _For3
_Next4:
; Debug ElapsedMilliseconds()-start
;Debug Wert
;
; start=0
MOV dword [v_start],0
; Wert=0
MOV dword [v_Wert],0
; start=ElapsedMilliseconds()
CALL _PB_ElapsedMilliseconds@0
MOV dword [v_start],eax
; For i = 0 To 1000000
MOV dword [v_i],0
_For5:
MOV eax,1000000
CMP eax,dword [v_i]
JL _Next6
; Wert = 569878993/2
MOV dword [v_Wert],284939496
; Next i
_NextContinue6:
INC dword [v_i]
JMP _For5
_Next6:
;
; Debug ElapsedMilliseconds()-start
;Debug Wert
; Debug"------------------------"
; Next a
_NextContinue2:
INC dword [v_a]
JMP _For1
_Next2:
;
_PB_EOP_NoValue:
PUSH dword 0
_PB_EOP:
CALL _PB_EndFunctions
PUSH dword [PB_MemoryBase]
CALL _HeapDestroy@4
CALL _ExitProcess@4
_PB_EndFunctions:
RET
;
;
section '.data' data readable writeable
;
_PB_DataSection:
_PB_DEBUGGER_LineNumber: dd -1
_PB_DEBUGGER_IncludedFiles: dd 0
_PB_ExecutableType: dd 0
pb_align 4
pb_align 4
s_s:
dd 0
dd -1
pb_align 4
;
section '.bss' readable writeable
_PB_BSSSection:
pb_bssalign 4
;
I_BSSStart:
_PB_MemoryBase:
PB_MemoryBase: rd 1
_PB_Instance:
PB_Instance: rd 1
;
pb_bssalign 4
PB_DataPointer rd 1
v_a rd 1
v_i rd 1
v_start rd 1
v_Wert rd 1
pb_bssalign 4
pb_bssalign 4
pb_bssalign 4
pb_bssalign 4
I_BSSEnd:
section '.data' data readable writeable
SYS_EndDataSection:
Gruß, Falko