<Omikron Basic> Raise x faster than x+=1?

Moderators: exxos, simonsunnyboy, Mug UK, Zorro 2, Moderator Team

User avatar
Omikronman
Atari Super Hero
Atari Super Hero
Posts: 525
Joined: Wed Dec 01, 2004 12:13 am
Location: Germany
Contact:

<Omikron Basic> Raise x faster than x+=1?

Postby Omikronman » Thu Feb 18, 2010 9:44 pm

My AAP makes use of many x+=1 commands. I wonder if there is a way to raise x faster than that to speed up again the program.

User avatar
charles
10 GOTO 10
10 GOTO 10
Posts: 2057
Joined: Tue Aug 17, 2004 12:11 am
Location: ont. Canada
Contact:

Re: <Omikron Basic> Raise x faster than x+=1?

Postby charles » Thu Feb 18, 2010 10:48 pm

which version omikron do you use?

is there and inc ....like
INC a%,1

or make certain to keep variable declaration within valriable range

no use using a float # to only count to three all the time

maybe try th c method
A++

i dunno , why so many adds in the first place?

hows the program function after compiling?

charles
atari is my lifestyle,not a hobby.
HOLD ON ! ! !,
Im printing unreadable characters ...!

User avatar
Omikronman
Atari Super Hero
Atari Super Hero
Posts: 525
Joined: Wed Dec 01, 2004 12:13 am
Location: Germany
Contact:

Re: <Omikron Basic> Raise x faster than x+=1?

Postby Omikronman » Thu Feb 18, 2010 11:04 pm

Hello charles,

I use Omikron.Basic 3.6 / 5.0. I can not find a INC command. The X variable is used as integer. The "x+=1" is the C-method, similar to "x=x+1" which would be slower. AAP needs so many adds because it compares the whole picture in blocks of 8x8 with all letters of the Atari ST system font by pixel to find the best matching character. I am not sure what you asked for with the last question. O.o

Omi

User avatar
Nyh
Atari God
Atari God
Posts: 1496
Joined: Tue Oct 12, 2004 2:25 pm
Location: Netherlands

Re: <Omikron Basic> Raise x faster than x+=1?

Postby Nyh » Thu Feb 18, 2010 11:34 pm

Omikronman wrote:My AAP makes use of many x+=1 commands. I wonder if there is a way to raise x faster than that to speed up again the program.

No, the Omikron compiler will use and addq.w for a x%+=1 and and addq.l for x+=1.
Ho much RAM do you want to spend to increase speed? An option is to convert the pixel bitmap to a byte bitmap (will take 256000 bytes) and acces them A quick way to convert bit to bytes is to use a lookup 256x8 table:

Code: Select all

scr=start_of_screen
dest=start_of_big_memoryblock
lookup=look_up_table
i%=32000
do
  memory_move(lookup+(peek(scr) shl 3), dest, 8)
  dest+=8
  src+=1
  i%-=1;
while(i%)

I hope this is all valid Omikron, I am a bit rusty on the exact syntax but I think you will understand what I am trying to do.
In general count down to 0 is faster as counting up to a certain value.

An other good thing is to use relative addressing. So not:

Code: Select all

for y=0 to 400
  for x=0 to 640
    pixel=(peek(lpeek($44e)+y*80+x\8) shr(7-(x and 7))) and 1
    (Do something usefull with the pixel)
  next x
next y

But

Code: Select all

ptr=lpeek($44e)
y%=400
do
  x%=80
  do
    z%=8
    data%=peek(ptr)
    data%=swapbits[data%]
    ptr+=1
    do
      pixel%=data and 1
      data%=data% shr 1
      (do something usefull with the pixel)
      z%-=1
    while(z%)
    x%-=1
  while(x%)
  y%-=1
while(y%)

With swapbits an array that reverses the bits, ie swapbits[128]=1, swapbits[7]=224

If you want to scan 2 lines at the time just make a ptr and a ptr1 and initialize it as ptr1=ptr+80, increase the ptr's with 80 after each line.

Hans Wessels

Efit: fixed typo aqqq.w -> addq.w
Last edited by Nyh on Fri Feb 19, 2010 12:39 am, edited 1 time in total.

User avatar
Omikronman
Atari Super Hero
Atari Super Hero
Posts: 525
Joined: Wed Dec 01, 2004 12:13 am
Location: Germany
Contact:

Re: <Omikron Basic> Raise x faster than x+=1?

Postby Omikronman » Thu Feb 18, 2010 11:44 pm

Oha, that looks quite interesting. O.o In Omikron.Basic we do not have a DO command, but maybe I find something similar. At the moment I am a bit confused with these tips because I was never good in playing around with bits and bytes (but I should be if I like to improve performance). :)

User avatar
Nyh
Atari God
Atari God
Posts: 1496
Joined: Tue Oct 12, 2004 2:25 pm
Location: Netherlands

Re: <Omikron Basic> Raise x faster than x+=1?

Postby Nyh » Fri Feb 19, 2010 12:05 am

Omikronman wrote:The X variable is used as integer. The "x+=1" is the C-method, similar to "x=x+1" which would be slower.

No, it is not. x=x+1 and x+=1 are both compiled to an addq.l #1,d16(a6).
The "x+=1" is just less typing.

Omikronman wrote:AAP needs so many adds because it compares the whole picture in blocks of 8x8 with all letters of the Atari ST system font by pixel to find the best matching character.

Ah, so the best way is to fetch all those 64 bits in one time:

Code: Select all

pixels0=peek(ptr0)
pixels1=peek(ptr1)
pixels2=peek(ptr2)
pixels3=peek(ptr3)
pixels4=peek(ptr4)
pixels5=peek(ptr5)
pixels6=peek(ptr6)
pixels7=peek(ptr7)
ptr0+=1
..
ptr7+=1

and after a line
ptr0+=560
..
ptr7+=560

A very good speed up might be:

Code: Select all

if(pixels0 or pixels1 or pixels2 or pixels3 or pixels4 or pixels5 or pixels6 or pixels7) then
  do some magic
else
  outchar$=" "
endif

Maybe the same can be done for and all black block (use AND instead of OR and compare with 255). Do subpixel addressing with ANDs or, if you need an 0 or 1 as result, with an look-up table for the higher bits because shifting is slow. I don't know when a lookup table starts to be faster then shifting in Omikron, you will have to test.

Code: Select all

bit0=pixels0 and 1
bit1=(pixels0 shr 1) and 1
bit2=(pixels0 shr 2) and 1
bit3=lookup3[pixels0]
bit4=lookup4[pixels0]
bit7=lookup7[pixels0]

The lookup tables are 256 byte lookup tables (it is very important to make them byte lookup tables) with 1 if the important bit is set and 0 in all other cases. So the lookup table will always have 128 1 bits and 128 0 bits. The look something like:
lookup0=[0,1,0,1,0,1,0,1,0...
lookup1=[0,0,1,1,0,0,1,1,0,0,1,1...
lookup2=[0,0,0,0,1,1,1,1,0,0,0,0,1,....
...

Hans Wessels

Edit: fixed typo's
Last edited by Nyh on Fri Feb 19, 2010 12:42 am, edited 2 times in total.

User avatar
charles
10 GOTO 10
10 GOTO 10
Posts: 2057
Joined: Tue Aug 17, 2004 12:11 am
Location: ont. Canada
Contact:

Re: <Omikron Basic> Raise x faster than x+=1?

Postby charles » Fri Feb 19, 2010 12:07 am

the do should be exchanged with while and the while shoule be exchanged with wend..or end
i forget its been about a year since i played with omikron.

nyh knows alot and is always helpfull, this code he submitted is probally the one even he himself uses,, anymore questions just ask , there is always somebody here that knows,

charles
atari is my lifestyle,not a hobby.
HOLD ON ! ! !,
Im printing unreadable characters ...!

User avatar
Nyh
Atari God
Atari God
Posts: 1496
Joined: Tue Oct 12, 2004 2:25 pm
Location: Netherlands

Re: <Omikron Basic> Raise x faster than x+=1?

Postby Nyh » Fri Feb 19, 2010 12:28 am

Omikronman wrote:Oha, that looks quite interesting. O.o In Omikron.Basic we do not have a DO command, but maybe I find something similar.

Ah, yes, it is called REPEAT UNTIL, sorry, too much C, haven't done any Omikron coding the last 15 years or so...
So you will have to use
until(i%=0)
Comparing with 0 is a lot faster as comparing with another number. And having the compare at the and of the loop is faster as having the compare at the start. You have to be sure you will execute the loop at least once.
Just time the speed difference in:

Code: Select all

t=timer
for i%=1 to 32000
 x+=1
next i%
? timer-t
t=timer
i%=0
while(i%<>32000)
  x+=1
  i%+=1;
wend
? timer-t
t=timer
i%=0
repeat
  x+=1
  i%-=1
untl(i%=32000)
? timer-t
t=timer
i%=32000
while(i%)
  x+=1
  i%-=1;
wend
i%=32000
? timer-t
t=timer
repeat
  x+=1
  i%-=1
untl(i%=0)
? timer-t

I am curious to the results too!

Omikronman wrote:At the moment I am a bit confused with these tips because I was never good in playing around with bits and bytes (but I should be if I like to improve performance). :)

Yeah, I think most speed can be won by handling you bits in a more efficient way. I think you still see them as pixels and not as bits inside a byte

Hans Wessels

User avatar
Omikronman
Atari Super Hero
Atari Super Hero
Posts: 525
Joined: Wed Dec 01, 2004 12:13 am
Location: Germany
Contact:

Re: <Omikron Basic> Raise x faster than x+=1?

Postby Omikronman » Fri Feb 19, 2010 12:34 am

"I think you still see them as pixels and not as bits inside a byte"

That is true ... :D

User avatar
Omikronman
Atari Super Hero
Atari Super Hero
Posts: 525
Joined: Wed Dec 01, 2004 12:13 am
Location: Germany
Contact:

Re: <Omikron Basic> Raise x faster than x+=1?

Postby Omikronman » Wed Mar 03, 2010 3:12 pm

"No, it is not. x=x+1 and x+=1 are both compiled to an addq.l #1,d16(a6).
The "x+=1" is just less typing."


I made some tests again and the result is the same as with my test some years ago: x+=1 is slightly faster than x=x+1. I ran the test again and again and it is always 1,2 % faster. Don´t know why. :-/

User avatar
Nyh
Atari God
Atari God
Posts: 1496
Joined: Tue Oct 12, 2004 2:25 pm
Location: Netherlands

Re: <Omikron Basic> Raise x faster than x+=1?

Postby Nyh » Wed Mar 03, 2010 4:08 pm

Omikronman wrote:"No, it is not. x=x+1 and x+=1 are both compiled to an addq.l #1,d16(a6).
The "x+=1" is just less typing."


I made some tests again and the result is the same as with my test some years ago: x+=1 is slightly faster than x=x+1. I ran the test again and again and it is always 1,2 % faster. Don´t know why. :-/

Can you show the test code? I am curious...

Hans Wessels

User avatar
Omikronman
Atari Super Hero
Atari Super Hero
Posts: 525
Joined: Wed Dec 01, 2004 12:13 am
Location: Germany
Contact:

<Omikron Basic> Raise x faster than x+=1?

Postby Omikronman » Wed Mar 03, 2010 4:25 pm

Yes, here it is: (see attachment). After some more tests I see that it is faster every time I run the test: between 0.8 and 1,2 %.
You do not have the required permissions to view the files attached to this post.

User avatar
Nyh
Atari God
Atari God
Posts: 1496
Joined: Tue Oct 12, 2004 2:25 pm
Location: Netherlands

Re: <Omikron Basic> Raise x faster than x+=1?

Postby Nyh » Wed Mar 03, 2010 10:12 pm

Omikronman wrote:Yes, here it is: (see attachment). After some more tests I see that it is faster every time I run the test: between 0.8 and 1,2 %.

Thank you.

I compiled the code and then disassembled it. Note the A=$12345678 was inserted to find the compiled code easier.

Code: Select all

; A%L=$12345678
      MOVE.L    #$12345678,-32768(A6)
; T%L= TIMER
      MOVE.L    $4BA.L,D0
      MOVE.L    D0,-32764(A6)
; FOR X%L=0 TO 5E+8
      MOVEQ     #0,D0
      MOVE.L    D0,-32760(A6)
      MOVE.L    #$1DCD6500,D0
      MOVE.L    A3,-(A7)
      MOVEA.L   D0,A3
      MOVE.L    -32760(A6),D0
      BRA       L019E
;  A%L+=1
L019D:ADDQ.L    #1,-32768(A6)
; NEXT
      MOVE.L    -32760(A6),D0
      ADDQ.L    #1,D0
      MOVE.L    D0,-32760(A6)
L019E:CMP.L     A3,D0
      BLE       L019D
      MOVEA.L   (A7)+,A3
; PRINT ( TIMER -T%L)/200
      MOVE.L    $4BA.L,D0
      SUB.L     -32764(A6),D0
      JSR       5024(A5)
      MOVE.W    D1,D3
      MOVE.L    D0,D2
      MOVE.L    #-$38000000,D0
      MOVEQ     #$10,D1
      JSR       5140(A5)
      JSR       5128(A5)
; T%L= TIMER
      MOVE.L    $4BA.L,D0
      MOVE.L    D0,-32764(A6)
; FOR X%L=0 TO 5E+8
      MOVEQ     #0,D0
      MOVE.L    D0,-32760(A6)
      MOVE.L    #$1DCD6500,D0
      MOVE.L    A3,-(A7)
      MOVEA.L   D0,A3
      MOVE.L    -32760(A6),D0
      BRA       L01A0
; A%L=A%L+1
L019F:ADDQ.L    #1,-32768(A6)
; NEXT
      MOVE.L    -32760(A6),D0
      ADDQ.L    #1,D0
      MOVE.L    D0,-32760(A6)
L01A0:CMP.L     A3,D0
      BLE       L019F
      MOVEA.L   (A7)+,A3
;  PRINT ( TIMER -T%L)/200
      MOVE.L    $4BA.L,D0
      SUB.L     -32764(A6),D0
      JSR       5024(A5)
      MOVE.W    D1,D3
      MOVE.L    D0,D2
      MOVE.L    #-$38000000,D0
      MOVEQ     #$10,D1
      JSR       5140(A5)
      JSR       5128(A5)

Note both add are compiled the same way: ADDQ.L #1,-32768(A6).
Most time is spend in the for next code and not the add code. To get a better measurement of the add code duplicate the add a lot (like 128 times or so...).

So there shouldn't be any speed difference. I don't understand why you get one. Are you running a normal ST or something with an instruction cache (accelerator board, 68030)?
Is the effect still there when you

Further I would force the code to show the exact time by forcing a floating point divide:
PRINT ( TIMER -T%L)/200.0
This will give more precise results. Both loops resulted in 1002.98 in STeem.
Note that moving the mouse during the test run will change the results.

Maybe also important: I used Omikron compiler 3.57.... Compiled it with Omikron 5 too. The add instruction is the same as in 3.57. Timing is 2 times 1019.17. Hmm why is that? The code looks the same. A difference in interrupts?

Hans Wessels

User avatar
Omikronman
Atari Super Hero
Atari Super Hero
Posts: 525
Joined: Wed Dec 01, 2004 12:13 am
Location: Germany
Contact:

Re: <Omikron Basic> Raise x faster than x+=1?

Postby Omikronman » Wed Mar 03, 2010 10:22 pm

Are you running a normal ST or something with an instruction cache (accelerator board, 68030)?

Yes, I ran it on my Afterburner040 Falcon some time ago and now I made some tests with the STemulator in Crossover with the iMac. In both cases the first loop was faster.

Is the effect still there when you

These sentence seems to be incomplete, or I do not understand it (?)

I will try your other thoughts/tips to see if I get still different results for both loops!

Tnx, Omi :)

User avatar
Nyh
Atari God
Atari God
Posts: 1496
Joined: Tue Oct 12, 2004 2:25 pm
Location: Netherlands

Re: <Omikron Basic> Raise x faster than x+=1?

Postby Nyh » Wed Mar 03, 2010 10:41 pm

Omikronman wrote:Is the effect still there when you

These sentence seems to be incomplete, or I do not understand it (?)

I will try your other thoughts/tips to see if I get still different results for both loops!

Well, yes, it seems I was interrupted during typing and I didn't do a proper return. I wanted to say: is the effect still there if you swap the code to be tested?

But with processors with cache your results may vary. I am not an expert on this subject.

Hans Wessels

rockyone
Captain Atari
Captain Atari
Posts: 344
Joined: Thu Jan 20, 2011 8:47 pm
Location: France
Contact:

Re: <Omikron Basic> Raise x faster than x+=1?

Postby rockyone » Sat Feb 12, 2011 7:52 pm

bonjour Omikronman

J' ai téléchargé SPDTST_2.zip , mais je n'ai que Omikron 3.01, pouvez vous le nettre en fichier asccii ( Save bloc)

User avatar
Omikronman
Atari Super Hero
Atari Super Hero
Posts: 525
Joined: Wed Dec 01, 2004 12:13 am
Location: Germany
Contact:

Re: <Omikron Basic> Raise x faster than x+=1?

Postby Omikronman » Sat Feb 12, 2011 8:04 pm

Bonjour Rockyone, Voici le code source.

COMPILER "cutlib"
COMPILER "troff"
COMPILER "cie"
COMPILER "no_linenumbers"
'
PRINT "escf"
'
T= TIMER
FOR X=0 TO 5E+8
A+=1
NEXT

PRINT ( TIMER -T)/200

T= TIMER
FOR X=0 TO 5E+8
A=A+1
NEXT

PRINT ( TIMER -T)/200
WAIT 5
END

User avatar
charles
10 GOTO 10
10 GOTO 10
Posts: 2057
Joined: Tue Aug 17, 2004 12:11 am
Location: ont. Canada
Contact:

Re: <Omikron Basic> Raise x faster than x+=1?

Postby charles » Sun Feb 13, 2011 1:12 am

but do it avec the l'source
then do it avec the l'exececutable

executable will be premier version
as how you'd want the final aresult to stand

charles
atari is my lifestyle,not a hobby.
HOLD ON ! ! !,
Im printing unreadable characters ...!


Social Media

     

Return to “Other BASIC”

Who is online

Users browsing this forum: No registered users and 2 guests