even un even addresses dpoke

GFA BASIC-related articles in here please

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

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

Re: even un even addresses dpoke

Postby Nyh » Thu Dec 04, 2008 9:28 am

charles wrote:maybe optimize?

If you are thinking the code you included is an optimized version of the previous code you are wrong.

Hans Wessels

User avatar
GroovyBee
Obsessive compulsive Atari behavior
Obsessive compulsive Atari behavior
Posts: 143
Joined: Thu Oct 16, 2008 1:23 pm
Location: North, England

Re: even un even addresses dpoke

Postby GroovyBee » Thu Dec 04, 2008 11:54 am

@Charles: Thats optimized? 8O :lol: Why do you think a loop and 4 divides (2 DIVs and 2 MODs *) is faster than four logical shift rights?

* I don't know if GFA will see that 256 is a power of two and optimize them into shifts and logical ANDs.

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

Re: even un even addresses dpoke

Postby charles » Thu Dec 04, 2008 12:17 pm

it s onlt optimal compared to what i had previously listed , a logical shift is a form of divide or multiply so if compared that way too , it may be equal in speed
i should try nyhs method in gfa. who knows?

charles any body else going to start a topic or do i have to all the time?
The radioactive half-life : )
Atari is a 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: even un even addresses dpoke

Postby Nyh » Thu Dec 04, 2008 2:16 pm

charles wrote:it s onlt optimal compared to what i had previously listed , a logical shift is a form of divide or multiply so if compared that way too , it may be equal in speed

No, they are not. Shift instructions are a lot faster as divide and multiply instructions on the 68000. You will have to look ate the compiled Gfa code to see if the Gfa compiler is so smart as to convert a /256 into a SHR8.

But in programming logic it is much better to use a shift: you want to move bits to an other position. I do not want to divide by a number, which in this case happens to be 256 and gives the same effect as a SHR over 8.

Hans Wessels

User avatar
lp
Fuji Shaped Bastard
Fuji Shaped Bastard
Posts: 2364
Joined: Wed Nov 12, 2003 11:09 pm
Location: GFA Headquarters
Contact:

Re: even un even addresses dpoke

Postby lp » Thu Dec 04, 2008 4:56 pm

A dis-assembly proves to yield a rather long source file. The divide appears to end up a shift, although I didn't spend much time looking at the dis-assembly, but a right shift turns up in the code.

1) The extra local itself is a tiny speed bump. The less locals a routine has the faster it executes in GFA.
2) The extra testing of the loop also uneeded.
3) The MOD ends up calling some library function and is also not needed.
4) The variable 'num' is seen as a float, so there are extra calls to convert the float. Should be a long%.

It starts at _LPOKE

Code: Select all

*   Created by TT-Digger v7
*   Thu Dec 04 11:48:20 2008

*   TT-Digger v7

*   TEXT   238 bytes, segment starts at STARTADR
*   DATA   8 bytes, segment starts at VARTAB
*   BSS   32 bytes, segment starts at BssA5
*   SYMBOLS   252 bytes
*   FLAG   0000


   .XREF   INIT,MKLSTOS,END,GOSUB,VALPARF,VALPARI,LOCALC,VFFTOI,ISTOF,LMOD
   .XREF   RETURN

   .XDEF   STARTADR,BssA5,VARTAB,DATASTAR,DATAENDE,MEMSIZE,_LPOKE

   .TEXT

STARTADR:
   movea.l   a7,a2
   moveq   #15,d0
   lea    STARTADR(pc),a7
   jsr   INIT.l
   move.l   #$3E3E3E3E,d0
   lea    -32756(a5),a0
   bsr     MKLSTOS
   pea   22 
   pea   -2147483648.l
   pea   1024 
   jsr   _LPOKE.l
   move.l   #$3C3C3C3C,d0
   lea    -32756(a5),a0
   bsr     MKLSTOS
   bsr     END
_LPOKE:
   bsr     GOSUB
   lea    -32768(a5),a0
   bsr     VALPARF
   lea    -32764(a5),a0
   bsr     VALPARI
   lea    -32760(a5),a0
   bsr     LOCALC
L94:
   movea.l   -32768(a5),a0
   bsr     VFFTOI
   swap   d0
   movea.l   -32768(a5),a0
   bsr     ISTOF
   moveq   #0,d0
   movea.l   -32760(a5),a2
   move.b   (a2),d0
   movea.l   -32764(a5),a2
   add.l   (a2),d0
   move.l   d0,-(a7)
   movea.l   -32768(a5),a0
   bsr     VFFTOI
   andi.l   #65535,d0
   tst.l   d0
   bpl.s   L152
   addi.l   #255,d0
L152:
   moveq   #8,d1
   asr.l   d1,d0
   movea.l   (a7)+,a0
   move.b   d0,(a0)
   movea.l   -32760(a5),a2
   addq.b   #1,(a2)
   moveq   #0,d0
   movea.l   -32760(a5),a2
   move.b   (a2),d0
   movea.l   -32764(a5),a2
   add.l   (a2),d0
   move.l   d0,-(a7)
   movea.l   -32768(a5),a0
   bsr     VFFTOI
   andi.l   #65535,d0
   move.l   #256,d1
   bsr     LMOD
   movea.l   (a7)+,a0
   move.b   d0,(a0)
   movea.l   -32760(a5),a2
   addq.b   #1,(a2)
   moveq   #0,d0
   movea.l   -32760(a5),a2
   move.b   (a2),d0
   subq.l   #3,d0
   ble     L94
   bra     RETURN

   bsr     END

   .DATA

VARTAB:
   dc.w   0,18,2052,256

   .BSS

BssA5:
DATASTAR:
DATAENDE:
   ds.b   32
U278:
   end   

User avatar
GroovyBee
Obsessive compulsive Atari behavior
Obsessive compulsive Atari behavior
Posts: 143
Joined: Thu Oct 16, 2008 1:23 pm
Location: North, England

Re: even un even addresses dpoke

Postby GroovyBee » Thu Dec 04, 2008 10:07 pm

lp wrote:It starts at _LPOKE


Blurgh! Thats some ugly assembly code. Mind you, the BASIC source isn't good either.

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

Re: even un even addresses dpoke

Postby charles » Thu Dec 04, 2008 11:12 pm

hey hey , thats assembler code ... i can almost make sence just reading thru ..

is that the ..or part of the math unit in gfa?

i know about the locals , they drive me nuts , but speed doesn't matter , or somebody used that as a statement before ,, i really like speed i tyhink that less drag more action,, or
more time to calculate ..you know..

so really i can change that float to a long int in my code too,
it good cause i forgot to declare check some stuff,, thanks.


but about the mod , i seen it some "mac" libraries , how to do with out ,, just ike nyh's example?
or another method?

charles
i got a tempo control change in my midi program , and as saved as a standard midi file
this segment only requires three bytes of a long poke and a small midi id op code as a header .. iused to just plug away with mkl and mki but i needed a little more control
the total length is 6bytes of the tempo change 255,81,03,07,161,32
first three bytes are status,type and length to read then remaining three are a long poke
but only three places...
spent years learning all these midi op codes...
The radioactive half-life : )
Atari is a lifestyle,not a hobby.
HOLD ON ! ! ! Im printing unreadable characters ...!

User avatar
lp
Fuji Shaped Bastard
Fuji Shaped Bastard
Posts: 2364
Joined: Wed Nov 12, 2003 11:09 pm
Location: GFA Headquarters
Contact:

Re: even un even addresses dpoke

Postby lp » Fri Dec 05, 2008 4:46 am

GroovyBee wrote:
lp wrote:It starts at _LPOKE


Blurgh! Thats some ugly assembly code. Mind you, the BASIC source isn't good either.


lol, yes I'd have to agree on both points.

If you toss the loop out and stick to just integers and stick with shifting with AND and OR, GFA will do a whole lot better. Floats just make a mess of it. Well it is BASIC after all too. :wink:

I'd show a proper example but I am not going to write it for him. I dis-assembled it so the things Nyh warned of could be seen. :)


Social Media

     

Return to “GFA BASIC”

Who is online

Users browsing this forum: No registered users and 3 guests