Do we need branch prediction?

By: Brendan (btrotter.delete@this.gmail.com), August 25, 2022 7:54 am
Room: Moderated Discussions
Hi,

Kara (karaardalan.delete@this.gmail.com) on August 24, 2022 2:07 pm wrote:
>
> Since like my second year programming I stopped writing branched code totally,
> few tens of thousands lines of code in, I haven't encounter anything that
> intrinsically requires speculative branch prediction, like logically.
>
> But I write only numes.
>
> Is there any program that can't be written without a branching that can't
> be rephrased (literally, all that is is rephrasing) into branchless?

Is it possible for a good and useful program to exist without at least one branch?

Just passing control from executable loader to your program involves an indirect branch, function pointers are indirect branches, function returns are just another type of indirect branch (pop a return address from stack and branch to it); "switch()" is (conditional or indirect) branches; all loops that can't be fully unrolled require branches; and things like "break;" and "continue;" are unconditional branches.

There's only 2 ways I can think of to avoid (all types of) branches:

a) Use self modifying code that continually appends pieces to linear/branchless sequence of instructions (like a train that lays train tracks in front of itself)

b) Lie. Make the programming language so high level and/or so specialized that the programmer doesn't notice that their code has branches (e.g. pixel shaders, where the outer "for each group of pixels" loop is implied).

- Brendan
< Previous Post in ThreadNext Post in Thread >
TopicPosted ByDate
Do we need branch prediction?Kara2022/08/24 02:07 PM
  Do we need branch prediction?Rayla2022/08/24 03:04 PM
  Do we need branch prediction?Mark Roulo2022/08/24 04:25 PM
    Do we need branch prediction?Paul A. Clayton2022/08/24 06:28 PM
      Do we need branch prediction?Anon2022/08/24 06:52 PM
    Do we need branch prediction?rwessel2022/08/24 06:40 PM
    Do we need branch prediction?ananon2022/08/25 12:56 AM
      Do we need branch prediction?Carlie Coats2022/08/25 07:39 AM
        OT: You wanted rather than Mark Roulo2022/08/25 09:57 AM
          OT: You wanted "pre" rather than "code" rather than Mark Roulo2022/08/25 09:57 AM
            OT: You wanted "pre" rather than "code" rather than Carlie Coats2022/08/25 11:43 AM
    Do we need branch prediction?Kevin G2022/08/25 08:47 AM
      Do we need branch prediction?rwessel2022/08/25 11:10 AM
          Do we need branch prediction?rwessel2022/08/26 10:37 AM
  Do we need branch prediction?Geoff Langdale2022/08/24 07:18 PM
  Do we need branch prediction?Adrian2022/08/25 12:58 AM
  Do we need branch prediction?Brendan2022/08/25 07:54 AM
    Do we need branch prediction?Anon42022/08/25 11:45 AM
      Do we need branch prediction?anon22022/08/25 09:08 PM
  Predicable branching patterns (aykm; )Kara2022/08/27 01:00 PM
    Predicable branching patterns (aykm; )Jukka Larja2022/08/27 11:38 PM
    Predicable branching patterns (aykm; )Eric Fink2022/08/28 01:22 AM
      Predicable branching patterns (aykm; )Doug S2022/08/28 10:17 AM
    Predicable branching patterns (aykm; )---2022/08/28 02:16 PM
      Predicable branching patterns (aykm; )Anon2022/08/28 02:35 PM
  Q: Do we need branch prediction? A: We don't need it, but....2022/08/29 02:17 PM
    Quantum stuff.Kara2022/08/29 03:01 PM
      Q: Do we need branch prediction? A: We don't need it, but....2022/08/30 11:48 AM
    "Quantum Woo" (hint; that's NOT how it works) (NT)anonymous22022/08/29 04:19 PM
      Q: Do we need branch prediction? A: We don't need it, but....2022/08/30 12:14 PM
Reply to this Topic
Name:
Email:
Topic:
Body: No Text
How do you spell tangerine? 🍊