Wanted: Fast Multybyte (32 bit) decrement, No FSR
dkemppai
Posts: 315
OK, I seem to be havning trouble finding the fastest 32 bit or 24 bit multibyte decrement...
...without using the FSR...· ...Anyone have any good examples?
Thanks,
Dan
...without using the FSR...· ...Anyone have any good examples?
Thanks,
Dan
Comments
dec cnt0
jnz :enddec
dec cnt1
jnz :enddec
dec cnt2
snz
dec cnt3
:enddec
If you need constant time execution, youll have to have a nop chain leadout.
Someone let me know if theyve found something faster.
<edit> wait the code example I gave is actually for incremeting, let me think about the appropriate code for decrementing while Im in transit to work </edit>
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
·1+1=10
Post Edited (Paul Baker) : 1/13/2006 2:56:44 PM GMT
Decrement is a little more complicated. You can't use the same scheme as an increment...
...you have to look for a roll from zero to 255 to decrement the next higher byte. In this
case zero is cleared...····
I think I have one that works...
Check out this code snippit...·· ...It seems to work, although it's not fully tested. It also
may not be the fastest decrement code possible...
Post Edited (dkemppai) : 1/13/2006 3:46:24 PM GMT
mov w, #1
sub cnt0, w
jnc :enddec
sub cnt1, w
jnc :enddec
sub cnt2, w
snc
sub cnt3, w
:enddec
In otherwords, the straightforward answer. Also the increment code given above can be replaced with incsz so save a few extra cycles, or
incjz cnt0, :enddec
incjz cnt1, :enddec
incsz cnt2
incsz cnt3
I cant remember if incjz is defined, if not its the standard: incsz fr; jmp target.
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
·1+1=10
A quick check seems to work fine.
It also takes the same number cycles for each time through.
Bean.
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
"SX-Video·Module" Now available from Parallax for only $28.95
http://www.parallax.com/detail.asp?product_id=30012
"SX-Video OSD module" Now available from Parallax for only·$49.95
http://www.parallax.com/detail.asp?product_id=30015
Product web site: www.sxvm.com
"Ability may get you to the top, but it takes character to keep you there."
Post Edited (Bean (Hitt Consulting)) : 1/13/2006 3:52:23 PM GMT
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
·1+1=10
I just copied "my" version of 32 bit decrement from the IDE to paste it into a reply post when I saw that Bean has exactly posted "my" code with the difference that Bean decrements 24 bits only.
I have tested the code with four variables in SXSim, and I can confirm that it works as expected - it takes 11 cycles though.
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Greetings from Germany,
G
it _TAKES_ 8 cycles for 32 bits - guess what - I found another bug in SXSim, and fixed it already (bad clock count for Skip Bit instructions). So it was really worth while testing this code with SXSim .
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Greetings from Germany,
G
Another view into this.........isn't this what carryx is all about?
Assuming carryx mode is enabled, then the following works properly
mov···· ·w,#1···· ·;load the decrementing value
stc·················· ·;always set carry prior to the subtract, or clear carry prior to an add
sub····· var1,w···· ;subtract to decrement
clr w················ ·;prep to subtract any remaining carry only
sub····· var2,w···· ;subtract carry if any
sub····· var3,w··· ·;subtract carry if any
sub····· var4,w··· ·;subtract carry if any
Uses 7 cycles, so barely faster than other suggestions.
Cheers,
Peter (pjv)
Post Edited (pjv) : 1/13/2006 5:30:20 PM GMT
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
·1+1=10
Post Edited (Paul Baker) : 1/13/2006 5:32:16 PM GMT
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
"When all think alike, no one is thinking very much.' - Walter Lippmann (1889-1974)
······································································ Warm regards,····· G. Herzog [noparse][[/noparse]·黃鶴 ]·in Taiwan
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Greetings from Germany,
G