By: rwessel (rwessel.delete@this.yahoo.com), August 24, 2022 6:40 pm
Room: Moderated Discussions
Mark Roulo (nothanks.delete@this.xxx.com) on August 24, 2022 4:25 pm wrote:
> 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?
> >
> > Mind risc-v don't offer BPU, there's extensions but not in the requirements.
>
> How do you write code to do one thing if a condition holds and another thing if the condition doesn't hold?
>
> Example:
Not hard with a cmov, or some form of predication, or a hack* implementing it, but if you consider those equivalent to branches, then not obviously.
FWIW, a number of optimization guides for CPUs with cmov suggest that code with a well predicted branch will be faster than using a cmov (with cmov winning on unpredictable code).
*:
p = (b!=0)*"hello" + (b==0)*"goodbye";
printf(p);
(ignoring conversion rules, and assuming that points are simple integers)
> 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?
> >
> > Mind risc-v don't offer BPU, there's extensions but not in the requirements.
>
> How do you write code to do one thing if a condition holds and another thing if the condition doesn't hold?
>
> Example:
I'll note that the conditional operator (?) is a branch.
> if (b)
> printf("Hello");
> else
> printf("Goodbye");
>
Not hard with a cmov, or some form of predication, or a hack* implementing it, but if you consider those equivalent to branches, then not obviously.
FWIW, a number of optimization guides for CPUs with cmov suggest that code with a well predicted branch will be faster than using a cmov (with cmov winning on unpredictable code).
*:
p = (b!=0)*"hello" + (b==0)*"goodbye";
printf(p);
(ignoring conversion rules, and assuming that points are simple integers)