Home
JAQForum Ver 24.01
Log In or Join  
Active Topics
Local Time 10:36 01 Aug 2025 Privacy Policy
Jump to

Notice. New forum software under development. It's going to miss a few functions and look a bit ugly for a while, but I'm working on it full time now as the old forum was too unstable. Couple days, all good. If you notice any issues, please contact me.

Forum Index : Microcontroller and PC projects : Branchless Programming

Author Message
OA47

Guru

Joined: 11/04/2012
Location: Australia
Posts: 986
Posted: 04:48am 08 Jun 2022
Copy link to clipboard 
Print this post

https://www.youtube.com/watch?v=bVJ-mWWL7cE

Does this apply to MMBasic?

OA47
Edited 2022-06-08 14:51 by OA47
 
phil99

Guru

Joined: 11/02/2018
Location: Australia
Posts: 2640
Posted: 05:03am 08 Jun 2022
Copy link to clipboard 
Print this post

def Smaller_Branchless(a, b):
   return a * (a < b) + b * (b <= a)

Is a branchless way of finding the smaller of a and b. I can't think of a simple way to do that in Basic without a branch.
 
Volhout
Guru

Joined: 05/03/2018
Location: Netherlands
Posts: 5089
Posted: 05:25am 08 Jun 2022
Copy link to clipboard 
Print this post

a=min(a,b)

PicomiteVGA PETSCII ROBOTS
 
phil99

Guru

Joined: 11/02/2018
Location: Australia
Posts: 2640
Posted: 05:36am 08 Jun 2022
Copy link to clipboard 
Print this post

I should RTFM

Also

Print a * (a < b) + b * (b <= a)

does evaluate correctly in MMBasic.
Learn something new every day. Unfortunately forgetting at least two things every day!

Perhaps I knew all that stuff last week.
Edited 2022-06-08 15:42 by phil99
 
Volhout
Guru

Joined: 05/03/2018
Location: Netherlands
Posts: 5089
Posted: 06:13am 08 Jun 2022
Copy link to clipboard 
Print this post


print a*(a<b)+b*(b<=a)


works for picomite VGA 5/07.05b5
Edited 2022-06-08 16:14 by Volhout
PicomiteVGA PETSCII ROBOTS
 
matherp
Guru

Joined: 11/12/2012
Location: United Kingdom
Posts: 10310
Posted: 06:36am 08 Jun 2022
Copy link to clipboard 
Print this post

Also check the CHOICE function
 
Tinine
Guru

Joined: 30/03/2016
Location: United Kingdom
Posts: 1646
Posted: 07:22am 08 Jun 2022
Copy link to clipboard 
Print this post



a% = 1
ct% =0
timer = 0
do
 if a% = 1 then
   b$ = "hello"
 else
   b$ = "bye"
 end if
 inc ct%
loop until ct% = 10000

print "If/Then/Else: "; timer

ct% =0
timer = 0
do
 b$ = choice(a%,"hello","bye")
 inc ct%
loop until ct% = 10000
       
print "Choice: "; timer




 
Tinine
Guru

Joined: 30/03/2016
Location: United Kingdom
Posts: 1646
Posted: 07:38am 08 Jun 2022
Copy link to clipboard 
Print this post

 
thwill

Guru

Joined: 16/09/2019
Location: United Kingdom
Posts: 4311
Posted: 07:55am 08 Jun 2022
Copy link to clipboard 
Print this post

  Tinine said  


Interesting, I would have guessed that CHOICE would be the fastest.

Best wishes,

Tom
MMBasic for Linux, Game*Mite, CMM2 Welcome Tape, Creaky old text adventures
 
Tinine
Guru

Joined: 30/03/2016
Location: United Kingdom
Posts: 1646
Posted: 08:14am 08 Jun 2022
Copy link to clipboard 
Print this post

  thwill said  
  Tinine said  


Interesting, I would have guessed that CHOICE would be the fastest.

Best wishes,

Tom


Yeah, that's what got me excited because I'm always looking for more efficient logic and that's what the manual claims:

  Quote  
This function allows you to do simple either/or selections more efficiently
and faster than using IF THEN ELSE ENDIF clauses.


Anti-climax  



Craig
 
thwill

Guru

Joined: 16/09/2019
Location: United Kingdom
Posts: 4311
Posted: 08:21am 08 Jun 2022
Copy link to clipboard 
Print this post

I think it's because on the PicoMite IF runs from RAM but CHOICE runs from flash.

Best wishes,

Tom
MMBasic for Linux, Game*Mite, CMM2 Welcome Tape, Creaky old text adventures
 
Mixtel90

Guru

Joined: 05/10/2019
Location: United Kingdom
Posts: 7937
Posted: 09:52am 08 Jun 2022
Copy link to clipboard 
Print this post

Has anyone run this using Select/Case, just as a matter of interest?
Mick

Zilog Inside! nascom.info for Nascom & Gemini
Preliminary MMBasic docs & my PCB designs
 
Tinine
Guru

Joined: 30/03/2016
Location: United Kingdom
Posts: 1646
Posted: 10:48am 08 Jun 2022
Copy link to clipboard 
Print this post

  Tinine said  


Yup...just above  





Craig
 
Print this page


To reply to this topic, you need to log in.

The Back Shed's forum code is written, and hosted, in Australia.
© JAQ Software 2025