06 April 2018, 15:52 | #1 |
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 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 |
06 April 2018, 16:16 | #2 |
Lemon. / Core Design
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 |
06 April 2018, 17:31 | #3 |
Thalion Webshrine
Join Date: Jan 2004
Location: Oxford
Posts: 14,354
|
Are the shift instructions faster if the shift value is in a register rather than an immediate?
|
06 April 2018, 17:39 | #4 | |
Registered User
Join Date: Jan 2008
Location: Warsaw/Poland
Age: 55
Posts: 1,975
|
Quote:
|
|
06 April 2018, 17:48 | #5 | |
Registered User
Join Date: Oct 2017
Location: Sunderland, England
Posts: 2,702
|
Quote:
http://mrjester.hapisan.com/04_MC68/...eTimes/LSL.htm |
|
06 April 2018, 17:59 | #6 | |
Registered User
Join Date: Oct 2017
Location: Sunderland, England
Posts: 2,702
|
Quote:
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 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 Big saving! |
|
06 April 2018, 18:13 | #7 |
Lemon. / Core Design
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.
|
06 April 2018, 18:15 | #8 |
Lemon. / Core Design
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
|
06 April 2018, 18:28 | #9 |
Registered User
Join Date: Jan 2008
Location: Warsaw/Poland
Age: 55
Posts: 1,975
|
|
06 April 2018, 18:31 | #10 |
Registered User
Join Date: Oct 2017
Location: Sunderland, England
Posts: 2,702
|
|
06 April 2018, 19:29 | #11 |
Registered User
Join Date: Jan 2008
Location: Warsaw/Poland
Age: 55
Posts: 1,975
|
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 |
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 |
|
|