...........................................................................
:                                                                         :
:              A S S E M B L E R   O P T I M I Z A T I O N S              :
:                                                                         :
:.........................................................................:

                              ASP68K PROJECT

                               Third Edition

                              by Michael Glew
                        mglew@laurel.ocs.mq.edu.au

---------------------------------------------------------------------------
                          C O N T R I B U T O R S
---------------------------------------------------------------------------

Erik Bakke, Robert Barton, Kasimir Blomstedt, Frans Bouma, David Carson,
Nicolas Dade, Irmen de Jong, Andy Duplain, Steven Eker, Calle Englund,
Alexander Fritsch, Charlie Gibbs, Kurt Haenen, Kjetil Jacobsen,
Olav Kalgraf, Markku Kolkka, Dave Mc Mahan, Lindsay Meek, Walter Misar,
Boerge Noest, Gunnar Rxnning, Peter Simons.


---------------------------------------------------------------------------
                          I N T R O D U C T I O N
---------------------------------------------------------------------------

A while back, I was quite interested to find that there was an electronic
magazine called "howtocode" that included lots of interesting hints and
tips of coding.  In the fifth edition, there was a list of optimizations
that really got be thinking.  "What if there was a proggy that you could
put an assembler program through, that would speed it up, taking out all
the stupid things output by compilers, and over-tired coders?" 8).  I
started combing the networks, and came across one such program, called
the "SELCO Source Optimizer".  It only had four optimizations, so I set
to writing my own.

Step one was to collect as many optimization ideas as I could.  I posted
to Usenet and got an impressive response, and the contributors are listed
above.  I promised a report on the optimizations recieved, and here it
is.  My aim now is to write a program to make these optimizations, and
to distribute it.  Contributers will recieve a copy of the final archive,
to thank them for their time and energy.  Further contributions will be
welcomed, so rather than making changes yourself tell me what you want
changed, and i'll distribute it with the next update.

The second edition incorperated a hell of a lot of corrections.  Double
copies of some optimizations were incorperated in to just one copy, and
a few additions were made.  Sorry that the first edition was not sent
out to all contributors, but I was a tad busy. 8)


---------------------------------------------------------------------------
                               C H A N G E S
---------------------------------------------------------------------------

Due to the distribution of the second edition document, many comments were
recieved and a couple of the "optimizations" were found to be incorrect.
Analysis of the mul/div optimizations ended in a few modifications for
safety.  They still save a huge number of clock cycles, so it is better to
be safe than sorry.

Also, I have made it so that the number of words of space saved or
increased is shown.  Space savings are positive, increases are negative.
Zero means no change.


---------------------------------------------------------------------------
                         O P T I M I Z A T I O N S
---------------------------------------------------------------------------

Note:-

    m?      = memory operand
    dx      = data register
    ds      = data register (scratch)
    ax      = address register
    rx      = either a data or address register
    #n      = immediate operand
    ??,?1,?2= address label
    *       = anything
    .x      = any size
    b<cc>   = branch commands

    Opt     = optimization
    Notes   = notes about where optimization is valid, and misc notes
    Speed   = are clock periods saved? ("Y" = yes
                                        "y" = in some cases
                                        "N" = no
                                        "*" = increase
                                        "-" = cannot be used on this cpu)
    Size    = how many bytes are saved?

--------------------------------------------------------------------------------
Opt                                  Notes                         Speed    Size
                                                                000 010 020
------------------------------------+--------------------------+---+---+---+----
clr.x -(ax) -> move.x ds,-(ax)      | ds must equal zero       | Y | Y | ? | 0
------------------------------------+--------------------------+---+---+---+----
clr.x n(ax,rx) -> move.x ds,n(ax,rx)| ds must equal zero       | Y | Y | ? | 0
------------------------------------+--------------------------+---+---+---+----
move.l #n,dx -> moveq #n,dx         | if -128 <= n <= 127      | Y | Y | ? | 4
------------------------------------+--------------------------+---+---+---+----
move.x #0,ax -> sub.l ax,ax         |                          | Y | Y | ? | 2/4
------------------------------------+--------------------------+---+---+---+----
clr.l dx -> moveq #0,dx             |                          | Y | Y | ? | 0
------------------------------------+--------------------------+---+---+---+----
cmp.x #0,m? -> tst.x m?             |                          | Y | Y | ? | 2/4
------------------------------------+--------------------------+---+---+---+----
cmp.x #0,dx -> tst.x dx             |                          | Y | Y | ? | 2/4
------------------------------------+--------------------------+---+---+---+----
cmp.x #0,ax -> move.x ax,ds         | move ax to scratch reg.  | Y | Y | ? | 2/4
------------------------------------+--------------------------+---+---+---+----
add.x #n,* -> addq.x #n,*           | if 1<=n<=8               | Y | Y | ? | 2/4
------------------------------------+--------------------------+---+---+---+----
sub.x #n,* -> subq.x #n,*           | if 1<=n<=8               | Y | Y | ? | 2/4
------------------------------------+--------------------------+---+---+---+----
jmp ?? -> bra.w ??                  | abs(??-pc)<32768         | Y | Y | ? | 2
                                    | same section             |   |   |   |
------------------------------------+--------------------------+---+---+---+----
* ??* -> * n(pc)*                   | n = ??-pc , n<32768      | Y | Y | ? | 2
------------------------------------+--------------------------+---+---+---+----
jsr ?? -> bsr.w ??                  | abs(??-pc)<32768         | Y | Y | ? | 2
                                    | same section             |   |   |   |
------------------------------------+--------------------------+---+---+---+----
bsr ?? -> bra ??                    | different stack depth    | Y | Y | ? | 2
rts                                 |                          |   |   |   |
------------------------------------+--------------------------+---+---+---+----
jsr * -> jmp *                      | different stack depth    | Y | Y | ? | 2
rts                                 |                          |   |   |   |
------------------------------------+--------------------------+---+---+---+----
asl.x #1,dy -> add.x dy,dy          |                          | Y | Y | ? | 0
------------------------------------+--------------------------+---+---+---+----
lsl.x #1,dy -> add.x dy,dy          |                          | Y | Y | ? | 0
------------------------------------+--------------------------+---+---+---+----
asl.w #2,dy -> add.w dy,dy          |                          | Y | Y | ? | -2
               add.w dy,dy          |                          |   |   |   |
------------------------------------+--------------------------+---+---+---+----
asl.b #2,dy -> add.b dy,dy          |                          | Y | Y | ? | -2
               add.b dy,dy          |                          |   |   |   |
------------------------------------+--------------------------+---+---+---+----
lsl.w #2,dy -> add.w dy,dy          |                          | Y | Y | ? | -2
               add.w dy,dy          |                          |   |   |   |
------------------------------------+--------------------------+---+---+---+----
lsl.b #2,dy -> add.b dy,dy          |                          | Y | Y | ? | -2
               add.b dy,dy          |                          |   |   |   |
------------------------------------+--------------------------+---+---+---+----
mulu #n,dx -> swap dx               | n is 2^m, 2..2^8         | Y | Y | ? | -4
              clr.w dx              |                          |   |   |   |
              swap dx               |                          |   |   |   |
              asl.l #m,dx           |                          |   |   |   |
------------------------------------+--------------------------+---+---+---+----
muls #n,dx -> ext.l dx              | n is 2^m, 2..2^8         | Y | Y | ? | 0
              asl.l #m,dx           |                          |   |   |   |
------------------------------------+--------------------------+---+---+---+----
divu #n,dx -> lsr.l #m,dx           | n is 2^m, 2..2^8         | Y | Y | ? | 2
                                    | ignore remainder         |   |   |   |
------------------------------------+--------------------------+---+---+---+----
add.x #n,ax -> lea n(ax),ax         | -32768 <= n <= -9        | Y | Y | ? | 0/2
                                    | 9 <= n <= 32767          |   |   |   |
------------------------------------+--------------------------+---+---+---+----
sub.x #n,ax -> lea -n(ax),ax        | -32768 <= n <= -9        | Y | Y | ? | 0/2
                                    | 9 <= n <= 32767          |   |   |   |
------------------------------------+--------------------------+---+---+---+----
lea (ax),ax -> (nothing)            | delete                   | Y | Y | Y | 2
------------------------------------+--------------------------+---+---+---+----
lea n(ax),ax -> addq.w #n,ax        | if 1<=n<=8               | Y | Y | ? | 2
------------------------------------+--------------------------+---+---+---+----
lea n(ax),ax -> subq.w #-n,ax       | if -8<=n<=-1             | Y | Y | ? | 2
------------------------------------+--------------------------+---+---+---+----
move.x #n,ax -> lea n,ax            | n <> 0                   | Y | Y | ? | 0
------------------------------------+--------------------------+---+---+---+----
move.x ax,ay -> lea n(ax),ay        | -32768 <= n <= 32767     | Y | Y | ? | 2/4
add.x #n,ay                         |                          |   |   |   |
------------------------------------+--------------------------+---+---+---+----
addq.l #n,ax -> addq.w #n,ax        |                          | Y | Y | ? | 0
------------------------------------+--------------------------+---+---+---+----
subq.l #n,ax -> subq.w #n,ax        |                          | Y | Y | ? | 0
------------------------------------+--------------------------+---+---+---+----
movem.x @,* -> move.x @,*           | @ = a single register    | Y | Y | ? | 2
------------------------------------+--------------------------+---+---+---+----
movem.x *,@ -> move.x *,@           | @ = a single register    | Y | Y | ? | 2
                                    | not (@=dx & .x=.w)       |   |   |   |
------------------------------------+--------------------------+---+---+---+----
movem.w *,dx -> move.w *,dx         |                          | Y | Y | ? | 0
                ext.l dx            |                          |   |   |   |
------------------------------------+--------------------------+---+---+---+----
*0(ax)* -> *(ax)*                   |                          | Y | Y | ? | 2
------------------------------------+--------------------------+---+---+---+----
mulu #0,dx -> moveq #0,dx           |                          | Y | Y | ? | 2
------------------------------------+--------------------------+---+---+---+----
muls #0,dx -> moveq #0,dx           |                          | Y | Y | ? | 2
------------------------------------+--------------------------+---+---+---+----
mulu #1,dx -> swap dx               |                          | Y | Y | ? | -2
              clr.w dx              |                          |   |   |   |
              swap dx               |                          |   |   |   |
------------------------------------+--------------------------+---+---+---+----
muls #1,dx -> ext.l dx              |                          | Y | Y | ? | 2
------------------------------------+--------------------------+---+---+---+----
move.l (n.w,ax),dy ->               |                          | - | - | ? | ?
                    move.l n(ax),dy |                          |   |   |   |
------------------------------------+--------------------------+---+---+---+----
move.l (bd.x,ax),dy ->              |                          | - | - | ? | ?
                     move.l bd.x,dy |                          |   |   |   |
------------------------------------+--------------------------+---+---+---+----
move.l #n,dx -> moveq #m,dx         | -8323073 <= n <= -65537  | Y | Y | ? | 2
                swap dx             | 4096 <= n <= 8323072     |   |   |   |
                                    | n = m*65536              |   |   |   |
------------------------------------+--------------------------+---+---+---+----
move.l #n,dx -> moveq #m,dx         | 128 <= n <= 255          | Y | Y | ? | 2
                neg.b dx            | m= 255-n                 |   |   |   |
------------------------------------+--------------------------+---+---+---+----
move.l #n,dx -> moveq #m,dx         | 65534 <= n <= 65408      | Y | Y | ? | 2
                neg.w dx            | -65409 <= n <= -65536    |   |   |   |
                                    | m = 65535-abs(n)         |   |   |   |
------------------------------------+--------------------------+---+---+---+----
move.b #-1,dx -> st dx              | status flags are wrong   | Y | Y | ? | 2
------------------------------------+--------------------------+---+---+---+----
move.b #-1,(ax) -> st (ax)          | status flags are wrong   | Y | Y | ? | 2
------------------------------------+--------------------------+---+---+---+----
move.b #-1,(ax)+ -> st (ax)+        | status flags are wrong   | N | N | ? | 2
------------------------------------+--------------------------+---+---+---+----
move.b #-1,-(ax) -> st -(ax)        | status flags are wrong   | N | N | ? | 2
------------------------------------+--------------------------+---+---+---+----
move.b #-1,n(ax) -> st n(ax)        | status flags are wrong   | Y | Y | ? | 2
------------------------------------+--------------------------+---+---+---+----
move.b #-1,n(ax,rx) -> st n(ax,rx)  | status flags are wrong   | Y | Y | ? | 2
------------------------------------+--------------------------+---+---+---+----
move.b #-1,?? -> st ??              | status flags are wrong   | Y | Y | ? | 2
------------------------------------+--------------------------+---+---+---+----
add.x #n,* -> subq.x #-n,*          | -8 <= n <= -1            | Y | Y | ? | 2/4
------------------------------------+--------------------------+---+---+---+----
sub.x #n,* -> addq.x #-n,*          | -8 <= n <= -1            | Y | Y | ? | 2/4
------------------------------------+--------------------------+---+---+---+----
b<cc>.w ?? -> b<cc>.s ??            | abs(??-pc)<128           | Y | Y | ? | 2
------------------------------------+--------------------------+---+---+---+----
mulu #n,dx -> swap dx               | n is 2^m, 8<m<14         | Y | Y | ? | -6
              moveq #m,ds           |                          |   |   |   |
              clr.w dx              |                          |   |   |   |
              swap dx               |                          |   |   |   |
              asl.l ds,dx           |                          |   |   |   |
------------------------------------+--------------------------+---+---+---+----
muls #n,dx -> moveq #m,ds           | n is 2^m, 8<m<14         | Y | Y | ? | -2
              ext.l dx              |                          |   |   |   |
              asl.l ds,dx           |                          |   |   |   |
------------------------------------+--------------------------+---+---+---+----
divu #n,dx -> moveq #m,ds           | n is 2^m, 8<m<32         | Y | Y | ? | 0
              lsr.l ds,dx           | ignore remainder         |   |   |   |
------------------------------------+--------------------------+---+---+---+----
divu #n,dx -> moveq #0,dx           | n is 2^m, m=32 or more   | Y | Y | ? | 2
------------------------------------+--------------------------+---+---+---+----
nop -> (nothing)                    | remove nops              | Y | Y | ? | 2
------------------------------------+--------------------------+---+---+---+----
muls #2,dx -> ext.l dx              |                          | Y | Y | ? | 0
              add.l dx,dx           |                          |   |   |   |
------------------------------------+--------------------------+---+---+---+----
mulu #2,dx -> swap dx               |                          | Y | Y | ? | -4
              clr.w dx              |                          |   |   |   |
              swap dx               |                          |   |   |   |
              add.l dx,dx           |                          |   |   |   |
------------------------------------+--------------------------+---+---+---+----
muls #3,dx -> ext.l dx              |                          | Y | Y | ? | -4
              move.l dx,ds          |                          |   |   |   |
              add.l dx,dx           |                          |   |   |   |
              add.l ds,dx           |                          |   |   |   |
------------------------------------+--------------------------+---+---+---+----
mulu #3,dx -> swap dx               |                          | Y | Y | ? | -8
              clr.w dx              |                          |   |   |   |
              swap dx               |                          |   |   |   |
              move.l dx,ds          |                          |   |   |   |
              add.l dx,dx           |                          |   |   |   |
              add.l ds,dx           |                          |   |   |   |
------------------------------------+--------------------------+---+---+---+----
muls #5,dx -> ext.l dx              |                          | Y | Y | ? | -4
              move.l dx,ds          |                          |   |   |   |
              asl.l #2,dx           |                          |   |   |   |
              add.l ds,dx           |                          |   |   |   |
------------------------------------+--------------------------+---+---+---+----
mulu #5,dx -> swap dx               |                          | Y | Y | ? | -8
              clr.w dx              |                          |   |   |   |
              swap dx               |                          |   |   |   |
              move.l dx,ds          |                          |   |   |   |
              asl.l #2,dx           |                          |   |   |   |
              add.l ds,dx           |                          |   |   |   |
------------------------------------+--------------------------+---+---+---+----
muls #6,dx -> ext.l dx              |                          | Y | Y | ? | -6
              add.l dx,dx           |                          |   |   |   |
              move.l dx,ds          |                          |   |   |   |
              add.l ds,dx           |                          |   |   |   |
              add.l ds,dx           |                          |   |   |   |
------------------------------------+--------------------------+---+---+---+----
mulu #6,dx -> swap dx               |                          | Y | Y | ? | -10
              clr.w dx              |                          |   |   |   |
              swap dx               |                          |   |   |   |
              add.l dx,dx           |                          |   |   |   |
              move.l dx,ds          |                          |   |   |   |
              add.l ds,dx           |                          |   |   |   |
              add.l ds,dx           |                          |   |   |   |
------------------------------------+--------------------------+---+---+---+----
muls #7,dx -> ext.l dx              |                          | Y | Y | ? | -4
              move.l dx,ds          |                          |   |   |   |
              asl.l #3,dx           |                          |   |   |   |
              sub.l ds,dx           |                          |   |   |   |
------------------------------------+--------------------------+---+---+---+----
mulu #7,dx -> swap dx               |                          | Y | Y | ? | -8
              clr.w dx              |                          |   |   |   |
              swap dx               |                          |   |   |   |
              move.l dx,ds          |                          |   |   |   |
              asl.l #3,dx           |                          |   |   |   |
              sub.l ds,dx           |                          |   |   |   |
------------------------------------+--------------------------+---+---+---+----
muls #9,dx -> ext.l dx              |                          | Y | Y | ? | -4
              move.l dx,ds          |                          |   |   |   |
              asl.l #3,dx           |                          |   |   |   |
              add.l ds,dx           |                          |   |   |   |
------------------------------------+--------------------------+---+---+---+----
mulu #9,dx -> swap dx               |                          | Y | Y | ? | -8
              clr.w dx              |                          |   |   |   |
              swap dx               |                          |   |   |   |
              move.l dx,ds          |                          |   |   |   |
              asl.l #3,dx           |                          |   |   |   |
              add.l ds,dx           |                          |   |   |   |
------------------------------------+--------------------------+---+---+---+----
muls #10,dx -> ext.l dx             |                          | Y | Y | ? | -6
               add.l dx,dx          |                          |   |   |   |
               move.l dx,ds         |                          |   |   |   |
               asl.l #2,dx          |                          |   |   |   |
               add.l ds,dx          |                          |   |   |   |
------------------------------------+--------------------------+---+---+---+----
muls #11,dx -> ext.l dx             |                          | Y | Y | ? | -8
               move.l dx,ds         |                          |   |   |   |
               add.l dx,dx          |                          |   |   |   |
               add.l dx,ds          |                          |   |   |   |
               asl.l #3,dx          |                          |   |   |   |
               add.l ds,dx          |                          |   |   |   |
------------------------------------+--------------------------+---+---+---+----
muls #12,dx -> ext.l dx             |                          | Y | Y | ? | -6
               asl.l #2,dx          |                          |   |   |   |
               move.l dx,ds         |                          |   |   |   |
               add.l dx,dx          |                          |   |   |   |
               add.l ds,dx          |                          |   |   |   |
------------------------------------+--------------------------+---+---+---+----
mulu #12,dx -> swap dx              |                          | Y | Y | ? | -10
               clr.w dx             |                          |   |   |   |
               swap dx              |                          |   |   |   |
               asl.l #2,dx          |                          |   |   |   |
               move.l dx,ds         |                          |   |   |   |
               add.l dx,dx          |                          |   |   |   |
               add.l ds,dx          |                          |   |   |   |
------------------------------------+--------------------------+---+---+---+----
move.l #n,m? -> moveq  #n,ds        | -128 <= n <= 127         | Y | Y | ? | 2
                move.l ds,m?        |                          |   |   |   |
------------------------------------+--------------------------+---+---+---+----
move.l #n,-(sp) -> pea n.w          | -32768 <= n <= 32767     | Y | Y | ? | 2
------------------------------------+--------------------------+---+---+---+----
eori.x #-1,* -> not.x *             |                          | Y | Y | ? | 2/4
------------------------------------+--------------------------+---+---+---+----
lea 0.w,ax -> sub.l ax,ax           |                          | Y | Y | - | 2
------------------------------------+--------------------------+---+---+---+----
move.l ax,-(sp) -> link ax,#n       | -32768 <= n <= 32767     | Y | Y | ? | 4
move.l sp,ax                        |                          |   |   |   |
add.w #n,sp                         |                          |   |   |   |
------------------------------------+--------------------------+---+---+---+----
move.l ax,sp -> unlk ax             |                          | Y | Y | ? | 2
move.l (sp)+,ax                     |                          |   |   |   |
------------------------------------+--------------------------+---+---+---+----
move.l ax,-(sp) -> pea n(ax)        |                          | Y | Y | ? | 0/4
add*.l #n,(sp)                      |                          |   |   |   |
------------------------------------+--------------------------+---+---+---+----
move.l ax,-(sp) -> pea -n(ax)       |                          | Y | Y | ? | 0/4
sub*.l #n,(sp)                      |                          |   |   |   |
------------------------------------+--------------------------+---+---+---+----
move.l #n,ax -> move.w #n,ax        | -32768 <= n <= 32767     | Y | Y | ? | 2
------------------------------------+--------------------------+---+---+---+----
add*.x #0,dx -> tst.x dx            |                          | Y | Y | ? | 2/4
------------------------------------+--------------------------+---+---+---+----
sub*.x #0,dx -> tst.x dx            |                          | Y | Y | ? | 2/4
------------------------------------+--------------------------+---+---+---+----
move.l #n,dx -> moveq #y,dx         | n = y * 2^z              | * | * | ? | 2
                lsl.l #z,dx         |                          |   |   |   |
------------------------------------+--------------------------+---+---+---+----
ori.l #n,dx -> bset.l #b,dx         | n = 2^b, only 1 bit set  | Y | Y | ? | 2
------------------------------------+--------------------------+---+---+---+----
andi.l #n,dx -> bclr.l #b,dx        | n = 2^b, only 1 bit off  | Y | Y | ? | 2
------------------------------------+--------------------------+---+---+---+----
subq.w #1,dx -> db<cc> dx,??        | if dx=0 then will be     | y | y | ? | -2
b<cc> ??        b<cc> ??            | slower                   |   |   |   |
------------------------------------+--------------------------+---+---+---+----
subq.w #1,dx -> dbf dx,??           | dx<>0 (will work, but    | Y | Y | ? | -2
bra ??          bra ??              | will be slower)          |   |   |   |
------------------------------------+--------------------------+---+---+---+----
jsr ?1 -> pea ?2                    | same time if jsr is      | y | y | ? | 0
jmp ?2    jmp ?1                    | Abs.l                    |   |   |   |
------------------------------------+--------------------------+---+---+---+----
tst.w dx -> dbra dx,??              | dx will be trashed       | y | y | ? | 2
bne ??                              |                          |   |   |   |
------------------------------------+--------------------------+---+---+---+----
moveq #n,az -> lea n(ax,ay),az      | az=n+ax+ay               | Y | Y | ? | 2
add.x ax,az                         | -128<=n<=127             |   |   |   |
add.x ay,az                         |                          |   |   |   |
------------------------------------+--------------------------+---+---+---+----
move.l ay,az -> lea n(ax,ay.l*2),az | az=n+ax+2*ay             | - | - | ? | ?
add.x az,az                         | -128<=n<=127             |   |   |   |
add.x ax,az                         |                          |   |   |   |
add.x #n,az                         |                          |   |   |   |
------------------------------------+--------------------------+---+---+---+----
move.l ax,az -> lea n(ax.l*4),az    | az=n+4*ax                | - | - | ? | ?
asl.l #2,az                         | -128<=n<=127             |   |   |   |
add.x #n,az                         |                          |   |   |   |
------------------------------------+--------------------------+---+---+---+----
move.l ay,az -> lea n(ax,ay.l*4),az | az=n+ax+4*ay             | - | - | ? | ?
asl.l #2,az                         | -32768<=n<=32767         |   |   |   |
add.l ax,az                         |                          |   |   |   |
add.x #n,az                         |                          |   |   |   |
------------------------------------+--------------------------+---+---+---+----
move.l ax,az -> lea n(ax.l*8),az    | az=n+8*ax                | - | - | ? | ?
asl.l #3,az                         | -32768<=n<=32767         |   |   |   |
add.x #n,az                         |                          |   |   |   |
------------------------------------+--------------------------+---+---+---+----
move.l ay,az -> lea n(ax,ay.l*8),az | az=n+ax+8*ay             | - | - | ? | ?
asl.l #3,az                         | -32768<=n<=32767         |   |   |   |
add.l ax,az                         |                          |   |   |   |
add.x #n,az                         |                          |   |   |   |
------------------------------------+--------------------------+---+---+---+----
bra ?? -> (nothing)                 | remove null branches     | Y | Y | Y | 2/4
??                                  |                          |   |   |   |
------------------------------------+--------------------------+---+---+---+----
asl.l #16,dx -> swap dx             | status flags are wrong   | Y | Y | ? | -2
                clr.w dx            |                          |   |   |   |
------------------------------------+--------------------------+---+---+---+----
lsl.l #16,dx -> swap dx             | status flags are wrong   | Y | Y | ? | -2
                clr.w dx            |                          |   |   |   |
------------------------------------+--------------------------+---+---+---+----
asr.l #16,dx -> swap dx             | status flags are wrong   | Y | Y | ? | -2
                ext.l dx            |                          |   |   |   |
------------------------------------+--------------------------+---+---+---+----
lsr.l #16,dx -> clr.w dx            | status flags are wrong   | Y | Y | ? | -2
                swap dx             |                          |   |   |   |
------------------------------------+--------------------------+---+---+---+----
asl.l #n,dx -> asl.w #(n-16),dx     | status flags are wrong   | Y | Y | ? | -4
               swap dx              | 16<n<32                  |   |   |   |
               clr.w dx             |                          |   |   |   |
------------------------------------+--------------------------+---+---+---+----
asr.l #n,dx -> swap dx              | status flags are wrong   | Y | Y | ? | -4
               asr.w #(n-16),dx     | 16<n<32                  |   |   |   |
               ext.l dx             |                          |   |   |   |
------------------------------------+--------------------------+---+---+---+----
lsl.l #n,dx -> lsl.w #(n-16),dx     | status flags are wrong   | Y | Y | ? | -4
               swap dx              | 16<n<32                  |   |   |   |
               clr.w dx             |                          |   |   |   |
------------------------------------+--------------------------+---+---+---+----
lsr.l #n,dx -> clr.w dx             | status flags are wrong   | Y | Y | ? | -4
               swap dx              | 16<n<32                  |   |   |   |
               lsr.w #(n-16),dx     |                          |   |   |   |
------------------------------------+--------------------------+---+---+---+----
asl.l #n,dx -> moveq #0,dx          | status flags are wrong   | Y | Y | ? | 0
                                    | n>=32                    |   |   |   |
------------------------------------+--------------------------+---+---+---+----
asl.w #n,dx -> clr.w dx             | status flags are wrong   | Y | Y | ? | 0
                                    | n>=16                    |   |   |   |
------------------------------------+--------------------------+---+---+---+----
asl.b #n,dx -> clr.b dx             | status flags are wrong   | Y | Y | ? | 0
                                    | n>=8                     |   |   |   |
------------------------------------+--------------------------+---+---+---+----
lsl.l #n,dx -> moveq #0,dx          | status flags are wrong   | Y | Y | ? | 0
                                    | n>=32                    |   |   |   |
------------------------------------+--------------------------+---+---+---+----
lsl.w #n,dx -> clr.w dx             | status flags are wrong   | Y | Y | ? | 0
                                    | n>=16                    |   |   |   |
------------------------------------+--------------------------+---+---+---+----
lsl.b #n,dx -> clr.b dx             | status flags are wrong   | Y | Y | ? | 0
                                    | n>=8                     |   |   |   |
------------------------------------+--------------------------+---+---+---+----
asr.l #n,dx -> moveq #0,dx          | status flags are wrong   | Y | Y | ? | 0
                                    | n>=32                    |   |   |   |
------------------------------------+--------------------------+---+---+---+----
asr.w #n,dx -> clr.w dx             | status flags are wrong   | Y | Y | ? | 0
                                    | n>=16                    |   |   |   |
------------------------------------+--------------------------+---+---+---+----
asr.b #n,dx -> clr.b dx             | status flags are wrong   | Y | Y | ? | 0
                                    | n>=8                     |   |   |   |
------------------------------------+--------------------------+---+---+---+----
lsr.l #n,dx -> moveq #0,dx          | status flags are wrong   | Y | Y | ? | 0
                                    | n>=32                    |   |   |   |
------------------------------------+--------------------------+---+---+---+----
lsr.w #n,dx -> clr.w dx             | status flags are wrong   | Y | Y | ? | 0
                                    | n>=16                    |   |   |   |
------------------------------------+--------------------------+---+---+---+----
lsr.b #n,dx -> clr.b dx             | status flags are wrong   | Y | Y | ? | 0
                                    | n>=8                     |   |   |   |
------------------------------------+--------------------------+---+---+---+----


---------------------------------------------------------------------------
                          H I N T S   &   T I P S
---------------------------------------------------------------------------

This new section is for stuff that cannot be included in the above tables.
This can include pipelining optimizations and other stuff.

020+    Sequential memory accesses can cause pipeline stalls, so try and
        rearrange code so memory accesses do not immediately follow each
        other.  The same problem occurs if an address register updated
        in one line is accessed in the next line.

ALL     Include small routines as macros, because inline routines will
        be much faster, and in extreme cases smaller.

ALL     If a subroutine is only called from one position, either move
        it inline, or only use jmp/bra commands.


---------------------------------------------------------------------------
                            C O N C L U S I O N
---------------------------------------------------------------------------

There are the optimizations i've come up with so far.  If you could check
what i've done, and report any errors, that would make this list better.  I
only have so much time to spend on this, and many hands make light work.
Also, stats (and more optimizations) for 68020+ CPU's would be welcomed.
Currently this list is only for simple peephole optimization stuff, but I
will hopefully get around to more extensive optimizations.  Pipeline
optimization is on the way, so look out.  Any info on the 68020+ pipelines
would be appreciated.

Optimizations with ?question-marks? in the boxes next to them, I do not
have the data to check.  I would appreciate info about where I can get
the info.  Incidentally, i'm looking around for a 68020 programming
reference...


===========================================================================
EOF EOF EOF EOF EOF EOF EOF EOF EOF EOF EOF EOF EOF EOF EOF EOF EOF EOF EOF
===========================================================================
