r/programming • • Sep 03 '26

Branch‑Avoidant Programming

https://easylang.online/blog/branchless
254 Upvotes

92 comments sorted by

View all comments

Show parent comment

7

u/Nwallins Sep 03 '26

small_numbers[0] is unconditionally assigned; it will have a single element > 500.

7

u/nukethebees Sep 03 '26

Ah, thanks for pointing that out.

It will have a value written to it, yes, but smlen will remain 0 in all cases so there shouldn't be any risk. In all cases the array has SIZE elements. smlen tells us how many contain valid numbers.

4

u/tiftik Sep 03 '26

Why does that assignment matter? You're not going to use any element at i >= smlen

1

u/sopunny Sep 03 '26

You can add a sanity check at the end for this edge case. I think you actually need to check the array trail every time