English Amiga Board


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

 
 
Thread Tools
Old 06 April 2018, 15:52   #1
mcgeezer
Registered User
 
Join Date: Oct 2017
Location: Sunderland, England
Posts: 2,702
Fast multiply / divide by 64?

Hi all,

My code uses a lot of multiplying and dividing by 64.

for example:

Code:
lsl.w #6,d0
lsl.w #6,d1

---

lsr.w #6,d0
lsr.w #6,d1
Each one of those shifts is taking 18 cycles.

The maximum number i need to shift to and from is 200 so if I were to use a table I would need values going up to 12800, therefore I would need to hold a table on memory that would be over 25Kb (big waste).

Is there a better/faster method i can use for doing this multiplication without sapping 25Kb ram with a table?

Looking at doing it in a table I still would'nt improve on the cycle count anyway.

Cheers,
Geezer

Last edited by mcgeezer; 06 April 2018 at 16:11. Reason: Added table table cycle counts
mcgeezer is offline  
Old 06 April 2018, 16:16   #2
DanScott
Lemon. / Core Design
 
DanScott's Avatar
 
Join Date: Mar 2016
Location: Tier 5
Posts: 1,212
add.w d0,d0
move.w Shift6Table(PC,d0.w),d0


you're still looking at 18 cycles for that anyway
DanScott is offline  
Old 06 April 2018, 17:31   #3
alexh
Thalion Webshrine
 
alexh's Avatar
 
Join Date: Jan 2004
Location: Oxford
Posts: 14,337
Are the shift instructions faster if the shift value is in a register rather than an immediate?
alexh is offline  
Old 06 April 2018, 17:39   #4
Don_Adan
Registered User
 
Join Date: Jan 2008
Location: Warsaw/Poland
Age: 55
Posts: 1,960
Quote:
Originally Posted by mcgeezer View Post
Hi all,

My code uses a lot of multiplying and dividing by 64.

for example:

Code:
lsl.w #6,d0
lsl.w #6,d1

---

lsr.w #6,d0
lsr.w #6,d1
Each one of those shifts is taking 18 cycles.

The maximum number i need to shift to and from is 200 so if I were to use a table I would need values going up to 12800, therefore I would need to hold a table on memory that would be over 25Kb (big waste).

Is there a better/faster method i can use for doing this multiplication without sapping 25Kb ram with a table?

Looking at doing it in a table I still would'nt improve on the cycle count anyway.

Cheers,
Geezer
I see only one good enough solution for 64 multiply, but it needs many code changes. You can place D1.W at high word position of D0 and use lsl.l #6,D0 and later swap D0 or move.l D0,D1 and swap D1.
Don_Adan is offline  
Old 06 April 2018, 17:48   #5
mcgeezer
Registered User
 
Join Date: Oct 2017
Location: Sunderland, England
Posts: 2,702
Quote:
Originally Posted by alexh View Post
Are the shift instructions faster if the shift value is in a register rather than an immediate?
Not as far as I can see.
http://mrjester.hapisan.com/04_MC68/...eTimes/LSL.htm
mcgeezer is offline  
Old 06 April 2018, 17:59   #6
mcgeezer
Registered User
 
Join Date: Oct 2017
Location: Sunderland, England
Posts: 2,702
Quote:
Originally Posted by Don_Adan View Post
I see only one good enough solution for 64 multiply, but it needs many code changes. You can place D1.W at high word position of D0 and use lsl.l #6,D0 and later swap D0 or move.l D0,D1 and swap D1.
This is not a bad idea as I have to move x and y coordinates into the registers anyway. Looks like an lsl.l is 20 cycles as opposed to 18 for a .w

so at the moment i typically have.

Code:
move.w XPOS(a2),d0    ;12 
move.w YPOS(a2),d1    ;12
lsl.w #6,d0    ;18
lsl.w #6,d1    ;18
; do something to move object
lsr.w #6,d0    ;18
lsr.w #6,d1    ;18
; 96 cycles

Code:
move.w XPOS(a2),d0    ;12 
swap d0    ;4
move.w YPOS(a2),d0    ;12
lsl.l #6,d0    ;20

; do something to move object
lsr.l #6,d0    ;20
; 68 cycles.

Big saving!
mcgeezer is offline  
Old 06 April 2018, 18:13   #7
DanScott
Lemon. / Core Design
 
DanScott's Avatar
 
Join Date: Mar 2016
Location: Tier 5
Posts: 1,212
Depending on how your data is arranged, and if you have a reasonably large (and well arranged) array of words that need shifting, you could use the blitter with shift and A source masking to shift them all in one go.
DanScott is offline  
Old 06 April 2018, 18:15   #8
DanScott
Lemon. / Core Design
 
DanScott's Avatar
 
Join Date: Mar 2016
Location: Tier 5
Posts: 1,212
For the swap method, you should arrange XPos and YPos to be consecutive words, so you can just read them with a move.l XPos(a0),d0
DanScott is offline  
Old 06 April 2018, 18:28   #9
Don_Adan
Registered User
 
Join Date: Jan 2008
Location: Warsaw/Poland
Age: 55
Posts: 1,960
Quote:
Originally Posted by DanScott View Post
For the swap method, you should arrange XPos and YPos to be consecutive words, so you can just read them with a move.l XPos(a0),d0
Yes, it can save next 12 cycles too.
Don_Adan is offline  
Old 06 April 2018, 18:31   #10
mcgeezer
Registered User
 
Join Date: Oct 2017
Location: Sunderland, England
Posts: 2,702
Quote:
Originally Posted by DanScott View Post
For the swap method, you should arrange XPos and YPos to be consecutive words, so you can just read them with a move.l XPos(a0),d0
And infact they already are!!!
mcgeezer is offline  
Old 06 April 2018, 19:29   #11
Don_Adan
Registered User
 
Join Date: Jan 2008
Location: Warsaw/Poland
Age: 55
Posts: 1,960
And remember that divide by 64 is not safe. This is dependent on input data values and/or later data handling. You can/must use:
; do something to move object
lsr.l #6,d0 ;20
and.w #$00FF, D0
Don_Adan 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
Are there any compressors/tools that re-arrange/block-divide data(pictures)? NorthWay Coders. General 15 15 May 2019 21:18
DivIDE Type Device for Amstrad CPC 464 manic23 request.Other 9 16 August 2014 10:55
Use of 4MB PCMCIA Fast Flash Memory as Fast RAM in A1200 nkarytia support.Hardware 10 16 September 2011 13:37
ERROR: Dalek Attack (Integer Divide By Zero) Hungry Horace project.Killergorilla's WHD packs 18 20 September 2009 22:17
64 bit signed multiply cdoty Coders. General 2 16 December 2007 12:24

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 18:25.

Top

Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2024, vBulletin Solutions Inc.
Page generated in 0.10593 seconds with 13 queries