This page contains a number of simple tricks and optimizations for speed on the the Motorola 68000 (m68k) chip for use on the Commodore Amiga.
This list was compiled after relearning Amiga assembler programming in 2016 after a 25 year gap. I wish I’d had this information in the 90s – I didn’t even know about moveq for the longest time!
Here are some basic optimizations. Generally these are drop-in replacements that can be used without much thought.
|clr.l d0||moveq.l #0,d0||moveq is faster than clr. Also this sign-extends to 32-bits so even though the value can only be -128 to +127 it is very useful for ensuring the high 16-bits are cleared.|
|movea.l #0, a0|
|lsl.w #1,d0||add.w d0,d0||1 add is quicker than a shift.|
|lsl.w #2,d0||add.w d0,d0|
|Even 2 adds is quicker than a shift.|
|adda.w #10,a0||lea 10(a0),a0|
|swap d1||Shifting left by 16 bits. Swapping is quicker.|
|Shifting left 15 bits. Swapping followed by a single shift is quicker.|
|cmpi.l #num,d0||moveq.l #num,d1|
|num must be in the range -128 to +127.|
These are some additional optimizations that can be used:
|If returning directly after a “jsr” or “bsr” call then you can just use a basic branch and let the subroutine do the return.|
|Pushing return addresses onto stack in reverse order, then directly jumping to the first sub-routine. (68000 only). After each sub-routine does “rts” it will “return” to the start of the next subroutine.|