|
Forum Index : Microcontroller and PC projects : Branchless Programming
| Author | Message | ||||
| OA47 Guru Joined: 11/04/2012 Location: AustraliaPosts: 1013 |
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: AustraliaPosts: 2832 |
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: NetherlandsPosts: 5480 |
a=min(a,b) PicomiteVGA PETSCII ROBOTS |
||||
| phil99 Guru Joined: 11/02/2018 Location: AustraliaPosts: 2832 |
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: NetherlandsPosts: 5480 |
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 KingdomPosts: 10627 |
Also check the CHOICE function |
||||
| Tinine Guru Joined: 30/03/2016 Location: United KingdomPosts: 1646 |
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 KingdomPosts: 1646 |
|
||||
| thwill Guru Joined: 16/09/2019 Location: United KingdomPosts: 4327 |
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 KingdomPosts: 1646 |
Yeah, that's what got me excited because I'm always looking for more efficient logic and that's what the manual claims: 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 KingdomPosts: 4327 |
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 KingdomPosts: 8303 |
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 KingdomPosts: 1646 |
Yup...just above Craig |
||||
| The Back Shed's forum code is written, and hosted, in Australia. | © JAQ Software 2025 |