English Amiga Board


Go Back   English Amiga Board > Coders > Coders. Asm / Hardware

 
 
Thread Tools
Old 03 February 2011, 10:52   #1
pmc
gone
pmc's Avatar
 
Join Date: Apr 2007
Location: completely gone
Posts: 1,596
68000 code optimisations

Thread title says it all really.

I'm interested in the quickest ways to do things on the 68000 processor.

I imagine that an optimisation that is valid for 68000 might not necessarily be valid for > 68000 processors but my main interest is in vanilla 68000 coding.

So, if you have any, please post them here.

In the meantime, some from me. Right hand operand(s) accomplish (according to my own testing, correct me if I'm wrong! ) the same as the left hand operand(s) only faster:

Code:
 
68000 code speed optimisations
------------------------------
 
clr.l     d0     -->     moveq.l     #0,d0
 
lsl.w     #1,d0  -->     add.w       d0,d0
 
lsl.w     #2,d0  -->     add.w       d0,d0
                         add.w       d0,d0
 
adda.w    #10,a0 -->     lea         10(a0),a0
 
moveq.l   #16,d0 -->     swap        d1
ror.l     d0,d1
 
moveq.l   #15,d0 -->     swap        d1
ror.l     d0,d1          rol.l       #1,d1
pmc is offline  
Old 03 February 2011, 12:26   #2
phx
Natteravn

phx's Avatar
 
Join Date: Nov 2009
Location: Herford / Germany
Posts: 1,649
I could add a longer list here, but you could also refer to
http://sun.hasenbraten.de/vasm/release/vasm.html
which shows most of vasm's optimizations in chapter 13.5.
phx is offline  
Old 03 February 2011, 12:36   #3
pmc
gone
pmc's Avatar
 
Join Date: Apr 2007
Location: completely gone
Posts: 1,596
Thanks phx - been reading those optimisations at that link you posted - nice!

So far I haven't used your VASM assembler (sorry about that ) but I have to say it looks pretty cool, might be time to change my old habits.

Last edited by pmc; 03 February 2011 at 13:16. Reason: no need for the question I thought was needed :D
pmc is offline  
Old 03 February 2011, 12:37   #4
Cosmos
Banned
 
Join Date: Jan 2007
Location: France
Posts: 655
addq.l #,ax --> addq.w #,ax

b/jsr subroutine --> bra/jmp subroutine
rts
Cosmos is offline  
Old 03 February 2011, 14:24   #5
phx
Natteravn

phx's Avatar
 
Join Date: Nov 2009
Location: Herford / Germany
Posts: 1,649
Quote:
Originally Posted by Cosmos View Post
addq.l #,ax --> addq.w #,ax
Vasm is generally optimizing all instructions of the form "<op>.L #x,An" to "<op>.W #x,An". But I doubt that it makes a difference for ADDQ (I haven't checked the manual) ?
phx is offline  
Old 03 February 2011, 14:37   #6
pmc
gone
pmc's Avatar
 
Join Date: Apr 2007
Location: completely gone
Posts: 1,596
According to the manual:

addq.l #x,An = 8 clock cycles
addq.w #x,An = 4 clock cycles
pmc is offline  
Old 03 February 2011, 15:07   #7
Toni Wilen
WinUAE developer
 
Join Date: Aug 2001
Location: Hämeenlinna/Finland
Age: 45
Posts: 23,809
Quote:
Originally Posted by pmc View Post
According to the manual:

addq.l #x,An = 8 clock cycles
addq.w #x,An = 4 clock cycles
It is wrong. (compare it with SUBAQ in same page). 68000/010 can't execute one instruction with two ALU operations in 4 cycles (ALU is only 16-bit and all address register operations are always full 32-bit)
Toni Wilen is online now  
Old 03 February 2011, 15:11   #8
pmc
gone
pmc's Avatar
 
Join Date: Apr 2007
Location: completely gone
Posts: 1,596
Quote:
Originally Posted by Toni Wilen
It is wrong.
OK, if anyone would know, it would be you.

Have you told Motorola their manual's wrong...?
pmc is offline  
Old 03 February 2011, 16:28   #9
Galahad/FLT
Going nowhere

Galahad/FLT's Avatar
 
Join Date: Oct 2001
Location: United Kingdom
Age: 46
Posts: 7,583
How about:

add.w d4,a0
move.l (a0),a1

as

move.l 0(a0,d4.w),a1

Also using the movem.l instruction to move lots of longwords in one instruction as opposed to a more processor intensive loop

Last edited by Galahad/FLT; 03 February 2011 at 22:56. Reason: Back-to-back posts merged. Use the edit function.
Galahad/FLT is online now  
Old 03 February 2011, 16:41   #10
Cosmos
Banned
 
Join Date: Jan 2007
Location: France
Posts: 655
... move.l 0(a0,d4.l),a1
Cosmos is offline  
Old 04 February 2011, 19:12   #11
TheDarkCoder
Registered User
 
Join Date: Dec 2007
Location: Dark Kingdom
Posts: 211
Quote:
Originally Posted by Toni Wilen View Post
It is wrong. (compare it with SUBAQ in same page). 68000/010 can't execute one instruction with two ALU operations in 4 cycles (ALU is only 16-bit and all address register operations are always full 32-bit)
I can confirm what Toni says. Finding suspicious the difference with SUBAQ, I mesured time spent by repeating a lot od ADDAQ and there is no difference between .w and .l
Also, I think that in the 68010 manual both are reported 8 cyles
TheDarkCoder is offline  
Old 04 February 2011, 19:22   #12
Toni Wilen
WinUAE developer
 
Join Date: Aug 2001
Location: Hämeenlinna/Finland
Age: 45
Posts: 23,809
"Undocumented un-optimization": bset x,dn (and friends) take 2 cycles more if x >= 16.
Toni Wilen is online now  
Old 04 February 2011, 23:21   #13
Lonewolf10
AMOS Extensions Developer
Lonewolf10's Avatar
 
Join Date: Jun 2007
Location: near Cambridge, UK
Age: 40
Posts: 1,924
I heard that the movem instruction can be used to clear screens quickly. Is this true and how would it be done?


Regards,
Lonewolf10
Lonewolf10 is offline  
Old 04 February 2011, 23:52   #14
frank_b
Registered User
 
Join Date: Jun 2008
Location: Boston USA
Posts: 443
Quote:
Originally Posted by Lonewolf10 View Post
I heard that the movem instruction can be used to clear screens quickly. Is this true and how would it be done?


Regards,
Lonewolf10
Set sp to the top of memory you want to clear.
Zero all registers and

Code:
rept lots of times
movem.l d0-a6,-(sp)
endr
For added fun switch to supervisor and use the usp too

Last edited by frank_b; 29 July 2012 at 13:06. Reason: Added code tags
frank_b is offline  
Old 04 February 2011, 23:57   #15
Galahad/FLT
Going nowhere

Galahad/FLT's Avatar
 
Join Date: Oct 2001
Location: United Kingdom
Age: 46
Posts: 7,583
Quote:
Originally Posted by Lonewolf10 View Post
I heard that the movem instruction can be used to clear screens quickly. Is this true and how would it be done?


Regards,
Lonewolf10
Used in the early days of Amiga, and used extensively on the Atari ST.
Galahad/FLT is online now  
Old 05 February 2011, 00:02   #16
frank_b
Registered User
 
Join Date: Jun 2008
Location: Boston USA
Posts: 443
Code:
and.w #power of 2-1,d0
A quick way to get the remainder on a power of two div
Code:
      move.w x,d0
      and.w   #$f,d0   ; blitter shift value
It's a tad faster than a div.
Code:
       move.b  d0,-(sp)
       move.w (sp)+,d0  ; magic fast shift :)
Reduce system call overhead (not really relevant on the Amiga but cool on the ST)
If you call functions and pass params via the stack might be useful.

Code:
       move.w #something,-(sp)
       trap      #x


       move.w  #some other param,-(sp)
       trap       #x

       addq.l      #4,sp   ; clean up both params at once
Absolute short addressing to set ST IO registers. Don't try this on anything other than a vanilla 68k
Code:
      move.w    #val,$ffff8240.w
Relying on the cpu flags to avoid a compare
Code:
      move.l   somevar,d0
      beq.s     itiszero

itiszero
      blah blah blah

Last edited by frank_b; 29 July 2012 at 13:07. Reason: Added code tags
frank_b is offline  
Old 05 February 2011, 13:22   #17
Lonewolf10
AMOS Extensions Developer
Lonewolf10's Avatar
 
Join Date: Jun 2007
Location: near Cambridge, UK
Age: 40
Posts: 1,924
Quote:
Originally Posted by frank_b View Post
Set sp to the top of memory you want to clear.
Zero all registers and

rept lots of times
movem.l d0-a6,-(sp)
endr

For added fun switch to supervisor and use the usp too

Thanks for that.


Regards,
Lonewolf10
Lonewolf10 is offline  
Old 05 February 2011, 13:34   #18
Cosmos
Banned
 
Join Date: Jan 2007
Location: France
Posts: 655
How many penality cycles on 68000/010 for :

ax = $00005000
move.l #$12345678,3(ax)


And for 020+ with datacache ??
Cosmos is offline  
Old 05 February 2011, 13:42   #19
StingRay
move.l #$c0ff33,throat

StingRay's Avatar
 
Join Date: Dec 2005
Location: Berlin/Joymoney
Posts: 6,455
Quote:
Originally Posted by Cosmos View Post
How many penality cycles on 68000/010 for :

ax = $00005000
move.l #$12345678,3(ax)
A lot since it will generate an address error exception and your code will crash (68000 only allows byte moves to odd addresses).
StingRay is offline  
Old 05 February 2011, 21:49   #20
pmc
gone
pmc's Avatar
 
Join Date: Apr 2007
Location: completely gone
Posts: 1,596
Quote:
Originally Posted by Lonewolf10
I heard that the movem instruction can be used to clear screens quickly. Is this true and how would it be done?
Quote:
Originally Posted by frank_b
Set sp to the top of memory you want to clear.
Zero all registers and

rept lots of times
movem.l d0-a6,-(sp)
endr
But on a 68000 equipped Amiga this wouldn't be faster than using the blitter to clear memory surely.

Quote:
Originally Posted by frank_b
Relying on the cpu flags to avoid a compare
move.l somevar,d0
beq.s itiszero

itiszero
blah blah blah
This should be just standard coding practice in my opinion. Moves, and various other commands, affect the condition codes so no need for compares on the results of those for things like zero, not zero, plus or minus number etc.

Comparing for a specific value would still be needed of course.
pmc is offline  
 


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools

Similar Threads
Thread Thread Starter Forum Replies Last Post
68000 boot code billt Coders. General 15 05 May 2012 20:13
Wasted Dreams on 68000 sanjyuubi support.Games 5 27 May 2011 17:11
680x0 to 68000 Counia Hardware mods 1 01 March 2011 10:18
quitting on 68000? Hungry Horace project.WHDLoad 60 19 December 2006 20:17
3D code and/or internet code for Blitz Basic 2.1 EdzUp Retrogaming General Discussion 0 10 February 2002 11:40

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +2. The time now is 17:52.


Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2020, vBulletin Solutions Inc.
Page generated in 0.10474 seconds with 16 queries