View Single Post
Old 21 November 2018, 10:20   #156
dissident
Registered User
 
Join Date: Sep 2015
Location: Germany
Posts: 260
Quote:
Originally Posted by Gorf View Post
Multiplication by a constant can be done very efficiently. So if you know by what factor you are going to multiply, you could use one of these tricks:

multiply d0 by 29:

Code:
move.l  d0, d1
lsl.l   #4, d0
sub.l   d1, d0
add.l   d0, d0
sub.l   d1, d0
multiply d0 by 625:

Code:
move.l  d0, d1
lsl.l   #2, d0
add.l   d1, d0
lsl.l   #3, d0
sub.l   d1, d0
lsl.l   #4, d0
add.l   d1, d0
multiply d0 by 156:

Code:
move.l  d0, d1
lsl.l   #2, d1
add.l   d1, d0
lsl.l   #5, d0
sub.l   d1, d0
I've attached my collection of these multiply tricks based on the MC68000 execution times (including these three cases above) as macros, so they can be easily used in every sourcecode.
Attached Files
File Type: s MULU-Macros.s (25.1 KB, 261 views)
dissident is offline  
 
Page generated in 0.04965 seconds with 12 queries