English Amiga Board


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

 
 
Thread Tools
Old 13 January 2021, 14:05   #1
DanScott
Lemon. / Core Design
 
DanScott's Avatar
 
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....
DanScott is offline  
Old 13 January 2021, 14:10   #2
jotd
This cat is no more
 
jotd's Avatar
 
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.
jotd is offline  
Old 13 January 2021, 14:19   #3
DanScott
Lemon. / Core Design
 
DanScott's Avatar
 
Join Date: Mar 2016
Location: Tier 5
Posts: 1,213
Quote:
Originally Posted by jotd View Post
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.
it can vary between always taking the branch and never taking the branch depending on the input bit stream.. it is also part of a recursive routine, that can iterate up to possibly 1280 times (minimum 20, max 1280)

Obviously, I need to make sure input data keeps iterations to a minimum.

It's for vanilla 68k / A500
DanScott is offline  
Old 13 January 2021, 14:24   #4
Thomas Richter
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.
Thomas Richter is offline  
Old 13 January 2021, 14:42   #5
Jobbo
Registered User
 
Jobbo's Avatar
 
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.
Jobbo is offline  
Old 13 January 2021, 14:47   #6
DanScott
Lemon. / Core Design
 
DanScott's Avatar
 
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
DanScott is offline  
Old 13 January 2021, 14:59   #7
Jobbo
Registered User
 
Jobbo's Avatar
 
Join Date: Jun 2020
Location: Druidia
Posts: 389
Inlining DoSomething would seem like the simplest solution if there is room.
Jobbo is offline  
Old 14 January 2021, 08:20   #8
Knocker
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).
Knocker is offline  
Old 14 January 2021, 22:20   #9
a/b
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
...
a/b is offline  
Old 15 January 2021, 02:56   #10
h0ffman
Registered User
 
Join Date: Aug 2008
Location: Salisbury
Posts: 769
Quote:
Originally Posted by DanScott View Post
I am now thinking of putting this all into nested macros, so that I don't have to do any JSR/RTS
Macros and relative labels ftw id say. Not writing to the stack potentially 1280 times will be a massive win.
h0ffman is online now  
 


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools

Similar Threads
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

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 19:51.

Top

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