Page 1 of 1
Decreasing FOR loops..
Posted: Wed Oct 19, 2005 10:14 am
by dagcrack
Apart from wanting more FOR functionality (like in other languages) I also would also like to see a descrease option... because decreasing FOR loops are faster than increasing ones. This is a MUST have.
So, something like:
For l=1000 to 0
Next
Should be faster than an increasing value, as on every iteration "the loop" should check wether L equals 0 and if it does, then break the loop... This is faster than comparing the value L with the actual iteration number, isnt it?, should be in ASM..
For when, Fred?

(Or is it possible by now?, Don't think so though).
After all, we like the high-level functions of PB.. but we want the functionality of lower-level languages too, be it there for the ones who needs it.
Don't make us do it by ourselves

Re: Decreasing FOR loops..
Posted: Wed Oct 19, 2005 10:44 am
by va!n
!? its possible...
is this what you mena!? i know the issue you are talking about... i have read some articles about this too... but i dont know how purebasic will convert its to asm...
Edited:
corrected 1 to -1
Posted: Wed Oct 19, 2005 12:04 pm
by GedB
I doubt you'd get much from using it in a for loop, because you'd still have to maintain the loop variable for use in the program.
Perhaps it would good to be able to have something like
With the loop being highly optimised.
Posted: Wed Oct 19, 2005 12:07 pm
by benny
And btw ...
@va!n:
shouldn't it be
Step -1:
Posted: Wed Oct 19, 2005 12:53 pm
by va!n
benny wrote:
@va!n:
shouldn't it be Step -1:
@benny:
sure!

corrected, small typemistake...
@GedB:
Sorry, but i dont see there any different... using Repeat/Until Do/Loop will do internaly the same, isnt it? And i would not like to see another way for Repeat/Until... We still have it and i like the way how to use it and the commands name!
Posted: Wed Oct 19, 2005 1:12 pm
by benny
@va!n:
Maybe Geb_B speaks about the asm-command
LOOP whichs decrements
ECX and branches to a label (loops) as long as ECX is
not zero.
So something like this :
Code: Select all
i.l = 10
x.l = 0
!XOR ecx, ecx
!MOV ecx, dword[v_i]
!_LOOPSTART:
x+1
!LOOP _LOOPSTART
!MOV dword[v_i], ecx
Debug x
Generally speaking I do not know if the above makes sense or is faster
than the one produced by PureBasic. I think such optimazations should
be done in external tools, like the one by remi and/or Deem2031.
IMHO the official development of Purebasic should concentrate on the de-
velopment of new functionality / features.
Just my 2 cents

Posted: Wed Oct 19, 2005 1:26 pm
by ts-soft
Code: Select all
I = 1000
While I
!DEC[v_I]
Debug I
Wend
another fast way, i hope
Posted: Wed Oct 19, 2005 2:27 pm
by va!n
benny wrote:
Maybe Geb_B speaks about the asm-command LOOP whichs decrements ECX and branches to a label (loops) as long as ECX is not zero.
@benny:
Ohhhh, ok... its possible that he means the ASM Loop command but it doesnt looked so at the first moment for me
benny wrote:...I think such optimazations should be done in external tools, like the one by remi and/or Deem2031. IMHO the official development of Purebasic should concentrate on the development of new functionality / features.
@benny:
sorry i have to disagree with you! i think when such optimisations (in general) are possible, why shouldnt they implented directly inside purebasic!? Its nice to have such tools as from remi_meier and Deeem2031 but it would be much greater and cleaner/professional when PureBasic do this job and not any 3rd part tool "hacking/modify" your source without any guarantee...
I think before adding any new 2d/3d or any other extended stuff to purebasic, its very important to solve known bugs, like strings in threads, and that the mainengine of purebasic supports more different types lile doubles, unsigned/signed.... in my opinion this is the most importants basic for any sdk - if this is done, all other stuff can be added!

Posted: Wed Oct 19, 2005 5:57 pm
by benny
@va!n:
Ok. Having other priorities in mind - I totally agree with you to complete and
remove any bugs from the purebasic core. First a solid core should exits
before spending too much time on other complex matters like 3D for example.
Nevertheless, considering the fact that Purebasic exists for multiple OS and
it is a commercial application that competes against other languages like
BlitzBasic, I think Fred found a good way so far and built a damn cool system/
language.
However, back to topic
I did a quick test on that LOOP thing and it seems to be pretty lame compared
to the normal FOR-construct created by Purebasic. So forget the source
I wrote above :roll:
ts-soft's version seems to be pretty much the same as the normal FOR-
construct.
The generated ASM Code for a FOR/NEXT Loop looks like this:
Code: Select all
i.l = 10
!_For1:
!XOR eax,eax
!CMP eax,dword [v_i]
!JG _Next2
; Next i
!_NextContinue2:
!DEC dword [v_i]
!JMP _For1
!_Next2:
whereas the generated WHILE-Loop is something like this:
Code: Select all
i.l = 10
; While (i)
!_While1:
!CMP dword [v_i],0
!JE _Wend1
;!DEC[v_i]
; i-1
!DEC dword [v_i]
; Debug i
; Wend
!JMP _While1
!_Wend1:
So, acutally the same just the XOR-command is missing and the comparision
is between value and a constant which could make it slightly faster

But
maybe an assembler pro wants to comment that.
And btw, @ts-soft:
There isn't any different between
!DEC[v_i] and
i-1, is it

Posted: Wed Oct 19, 2005 6:17 pm
by ts-soft
i hoped my code was fast

Posted: Wed Oct 19, 2005 6:20 pm
by benny
ts-soft wrote:i hoped my code was fast

It is ... in my eyes

Posted: Wed Oct 19, 2005 6:26 pm
by benny
Could this be counted as a test :roll:
Debugger 0ff
Code: Select all
Delay(1000)
t1.l = ElapsedMilliseconds()
i.l = 999999999
x.l = 0
!XOR ecx, ecx
!MOV ecx, dword[v_i]
!_LOOPSTART:
;x+1
!INC dword[v_i]
!LOOP _LOOPSTART
!MOV dword[v_i], ecx
t2 = ElapsedMilliseconds() - t1
Delay(1000)
t3.l = ElapsedMilliseconds()
i.l = 999999999
!_For1:
!XOR eax,eax
!CMP eax,dword [v_i]
!JG _Next2
; Next i
!_NextContinue2:
!DEC dword [v_i]
!JMP _For1
!_Next2:
t4 = ElapsedMilliseconds() - t3
Delay(1000)
t5.l = ElapsedMilliseconds()
i.l = 999999999
; While (i)
!_While1:
!CMP dword [v_i],0
!JE _Wend1
;!DEC[v_i]
; i-1
!DEC dword [v_i]
; Debug i
; Wend
!JMP _While1
!_Wend1:
t6 = ElapsedMilliseconds() - t5
MessageRequester("Speed", "LOOP-Methode: "+Str(t2)+Chr(13)+Chr(10)+"FOR-Methode: "+Str(t4)+Chr(13)+Chr(10)+"WHILE-Methode"+Str(t6))
Posted: Wed Oct 19, 2005 6:27 pm
by dracflamloc
Well...
You get the same thing (though with more operations) by doing:
Code: Select all
For i = 0 to 1000
ii = 1000-i
;do whatever
next
Posted: Wed Oct 19, 2005 6:38 pm
by va!n
@benny:
ok, no problem

Sure, PureBasic is a nice language but there is a lot of work to do!
Here are my results of your speed comparsion test:
Code: Select all
LOOP-Methode: 4093
FOR-Methode: 4391
WHILE-Methode: 4406
Sadly but i cant use /COMMENTED - does not works here for any reason ;(
[Edited:]
Maybe it make more sence to compare LOOP/FOR/WHILE with increasind and decreasing values...!?

Posted: Wed Oct 19, 2005 6:48 pm
by benny
@va!n:
Strange

Here (AMD Duron 1.3Mhz) it is the complete opposite. The Loop
Version is the slowest whereas the FOR/NEXT is nearly as fast as the WHILE
method.
Maybe it is hardware (chip) specific ... but maybe I should stop talking now
because I didn't touched any assembly language since I left the Amiga scene :roll:
Maybe some of our
optimization-specialists can comment anything to
this
