![]() |
![]() |
#1 |
XoXo/Tasko Developer
Join Date: Dec 2013
Location: Munich
Age: 49
Posts: 450
|
![]()
Hi,
I need an optimisation for this: Code:
; convert d0 from 32 to 16 bit move.l #$7fff,d1 cmp.l d1,d0 blt .low_d0 move.w d1,d0 bra .ready .low_d0 cmp.l #$ffff8000,d0 bgt .ready move.w #$8000,d0 .ready ags Last edited by AGS; 19 December 2013 at 20:51. |
![]() |
![]() |
#2 |
Computer Nerd
Join Date: Sep 2007
Location: Rotterdam/Netherlands
Age: 48
Posts: 3,946
|
You want signed 32 bit to signed 16 bit conversion with clamping, right?
|
![]() |
![]() |
#3 |
XoXo/Tasko Developer
Join Date: Dec 2013
Location: Munich
Age: 49
Posts: 450
|
I guess yes, what is clamping?
|
![]() |
![]() |
#4 |
Computer Nerd
Join Date: Sep 2007
Location: Rotterdam/Netherlands
Age: 48
Posts: 3,946
|
|
![]() |
![]() |
#5 |
XoXo/Tasko Developer
Join Date: Dec 2013
Location: Munich
Age: 49
Posts: 450
|
Yes, thats what I want.
![]() |
![]() |
![]() |
#6 |
Computer Nerd
Join Date: Sep 2007
Location: Rotterdam/Netherlands
Age: 48
Posts: 3,946
|
Then you could do it like this, although it's not really optimized, only the program flow is improved:
Code:
move.l #$7fff,d1 cmp.l d1,d0 bgt .l1 move.l #$ffff8000,d1 cmp.l d1,d0 blt .l1 move.w d0,d1 .l1 move.w d1,d0 I'm curious to see if anyone can come up with anything optimized for this. |
![]() |
![]() |
#7 |
Registered User
Join Date: Jan 2002
Location: Germany
Posts: 7,047
|
How about this:
Code:
tst.l d0 bmi .minus tst.w d0 bpl .ok move.w #$7fff,d0 bra .ok .minus tst.w d0 bmi .ok move.w #$8000,d0 .ok |
![]() |
![]() |
#8 |
XoXo/Tasko Developer
Join Date: Dec 2013
Location: Munich
Age: 49
Posts: 450
|
Looks good!
|
![]() |
![]() |
#9 |
Computer Nerd
Join Date: Sep 2007
Location: Rotterdam/Netherlands
Age: 48
Posts: 3,946
|
To thomas:
You made a mistake. |
![]() |
![]() |
#10 |
Join Date: Jul 2008
Location: Sweden
Posts: 2,269
|
Code:
move.l #-$8000, d1 cmp.l d1, d0 blt .1 not.l d1 cmp.l d1, d0 ble .2 .1 move.w d1, d0 .2 |
![]() |
![]() |
#11 |
XoXo/Tasko Developer
Join Date: Dec 2013
Location: Munich
Age: 49
Posts: 450
|
Impressive!
|
![]() |
![]() |
#12 |
Computer Nerd
Join Date: Sep 2007
Location: Rotterdam/Netherlands
Age: 48
Posts: 3,946
|
Nice
![]() |
![]() |
![]() |
#13 | |
Registered User
Join Date: Jun 2010
Location: PL?
Posts: 2,917
|
Quote:
|
|
![]() |
![]() |
#14 |
Registered User
Join Date: Jan 2008
Location: Warsaw/Poland
Age: 56
Posts: 2,112
|
Perhaps the fastest version is version based on meynaf's trick.
Code:
move.w D0,A0 cmp.l D0,A0 beq.b OK move.w #$8000,D0 tst.l D0 bmi.b OK not.w D0 OK |
![]() |
![]() |
#15 |
XoXo/Tasko Developer
Join Date: Dec 2013
Location: Munich
Age: 49
Posts: 450
|
I am impressed that this part of code of mine could really be optimized so good. I thought of solutions, but did not get the answer alone. Don, your Trick is faster as it only moves a word number instead of a long, and does this only when necessary. The previous solution did this always. What is actually "Meynaf's TRick"? What happens when you move a .w into an address register?
Last edited by AGS; 21 December 2013 at 17:14. |
![]() |
![]() |
#16 |
Computer Nerd
Join Date: Sep 2007
Location: Rotterdam/Netherlands
Age: 48
Posts: 3,946
|
I think it's this:
Code:
; to see if a value is between $FFFF8000 and $7FFF, better put it in An reg : cmpa.w a0,a0 ; cmp with a0.w extended to .l, and a0.l |
![]() |
![]() |
#17 |
XoXo/Tasko Developer
Join Date: Dec 2013
Location: Munich
Age: 49
Posts: 450
|
Hmm, looks interesting but you lost me. Please try again.
|
![]() |
![]() |
#18 |
Computer Nerd
Join Date: Sep 2007
Location: Rotterdam/Netherlands
Age: 48
Posts: 3,946
|
The trick is based on the fact that when you move a word value into an address register it's automatically sign extended to a long word. For the rest I haven't figured it out, either
![]() |
![]() |
![]() |
#19 |
XoXo/Tasko Developer
Join Date: Dec 2013
Location: Munich
Age: 49
Posts: 450
|
AH, ok, now i understand.
|
![]() |
![]() |
#20 | |
Registered User
Join Date: Jan 2008
Location: Warsaw/Poland
Age: 56
Posts: 2,112
|
Quote:
|
|
![]() |
Currently Active Users Viewing This Thread: 1 (0 members and 1 guests) | |
Thread Tools | |
![]() |
||||
Thread | Thread Starter | Forum | Replies | Last Post |
32-bit access on 16-bit bus? | NorthWay | Coders. Asm / Hardware | 7 | 04 September 2013 00:46 |
REQ: 17-Bit Artwork 2 (1988-04)(17-Bit Software) | Sea7 | request.Demos | 5 | 13 May 2011 01:07 |
8 bit to optimized 6 bit palette histogram improvements needed | NovaCoder | Coders. General | 0 | 14 April 2011 02:13 |
My A500 is dying bit by bit :( | Old Fool | support.Hardware | 3 | 03 July 2009 17:12 |
64 bit signed multiply | cdoty | Coders. General | 2 | 16 December 2007 12:24 |
|
|