![]() |
![]() |
#1 |
Lemon. / Core Design
Join Date: Mar 2016
Location: Tier 5
Posts: 1,213
|
Conditional JSR and RTS
So imagine I have this code:
blah blah tst.w d0 beq.s .DoNotJsr1 jsr DoSomething .DoNotJsr1 blah blah tst.w d0 beq.s .DoNotJsr2 jsr DoSomething .DoNotJsr2 blah blah DoSomething: blah blah blah rts just to be clear, blah = some instructions Is there a quicker way of doing this conditional check / jsr / rts combo? The JSR can be BSR if that makes it easier.... |
![]() |
![]() |
#2 |
This cat is no more
Join Date: Dec 2004
Location: FRANCE
Age: 52
Posts: 8,373
|
looks fine to me (but hey I haven't written major Amiga titles). Maybe you want to analyse the frequency of the branch vs the non-branch. If it branches often, maybe use a bne and a bra so you're not breaking the instruction pipeline/prefetch.
|
![]() |
![]() |
#3 | |
Lemon. / Core Design
Join Date: Mar 2016
Location: Tier 5
Posts: 1,213
|
Quote:
Obviously, I need to make sure input data keeps iterations to a minimum. It's for vanilla 68k / A500 ![]() |
|
![]() |
![]() |
#4 |
Registered User
Join Date: Jan 2019
Location: Germany
Posts: 3,315
|
That depends on the statistics of the branches. An alternative approach would be to store the branch destination in an address register that either points to the real target, or to a single RTS. This is quicker in case you often take the subroutine and rarely jump over it.
However, typically: It does not matter. If your function is reasonably sized, I doubt that this makes a lot of difference and isn't worth the trouble. Profile first, then decide. |
![]() |
![]() |
#5 |
Registered User
Join Date: Jun 2020
Location: Druidia
Posts: 389
|
Presuming DoSomething doesn't depend on the prior results.
Could you combine 16 test results into a word something like: moveq #0,d1 // d1 = results bitfield tst.w d0 add.w d1,d1 // shift one bit left sub.w d0,d1 // add our tst bit (sub because tst returns -1) Do that 16x and then you can jump have DoSomething unrolled 16x and jump to the appropriate place. That or something like it might reduce the number of jsr rts uses. |
![]() |
![]() |
#6 |
Lemon. / Core Design
Join Date: Mar 2016
Location: Tier 5
Posts: 1,213
|
I am now thinking of putting this all into nested macros, so that I don't have to do any JSR/RTS
|
![]() |
![]() |
#7 |
Registered User
Join Date: Jun 2020
Location: Druidia
Posts: 389
|
Inlining DoSomething would seem like the simplest solution if there is room.
|
![]() |
![]() |
#8 |
Registered User
Join Date: Jan 2016
Location: Santa Cruz/US
Posts: 48
|
See http://eab.abime.net/showthread.php?...72#post1104172 for ideas for macro(s).
|
![]() |
![]() |
#9 |
Registered User
Join Date: Jun 2016
Location: europe
Posts: 1,064
|
Not enough info.. What is the break/exit condition and where is it checked? Are blahs the same unrolled code or different code?
Could you write it in this form, gives you better branching and gets rid of jsrs... Code:
bra.b ENTRY do_something: blah blah blah ENTRY: blah blah test.w d0 bne.b do_something blah blah test.w d0 bne.b do_something blah blah test.w d0 bne.b do_something ... |
![]() |
![]() |
#10 |
Registered User
Join Date: Aug 2008
Location: Salisbury
Posts: 769
|
|
![]() |
Currently Active Users Viewing This Thread: 1 (0 members and 1 guests) | |
Thread Tools | |
![]() |
||||
Thread | Thread Starter | Forum | Replies | Last Post |
Call vs JSR | idrougge | Coders. Blitz Basic | 17 | 05 February 2017 22:40 |
conditional breakpoints | jotd | request.UAE Wishlist | 2 | 12 June 2016 19:36 |
Noobie Help (conditional branching) | bodhi | Coders. Asm / Hardware | 7 | 03 January 2013 00:55 |
Game appears to use weird JSR instructions | MethodGit | Coders. General | 15 | 18 March 2011 16:26 |
68040 MMU jsr/bsr | Toni Wilen | Coders. General | 5 | 28 April 2010 20:57 |
|
|