<div dir="auto"><div><div class="gmail_quote"><div dir="ltr" class="gmail_attr">On Fri, 23 Aug 2024, 12:26 Nicholas Wilson via Digitalmars-d, <<a href="mailto:digitalmars-d@puremagic.com">digitalmars-d@puremagic.com</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">On Friday, 23 August 2024 at 01:47:37 UTC, Manu wrote:<br>
> I'm working on microcontrollers, and many don't have a branch <br>
> predictor. They do "static" prediction, that is, they just <br>
> predict branch-not-taken and it's on you to write your code as <br>
> such, and that's not always possible. (like the loop condition <br>
> in a for loop)<br>
><br>
> This leads to a lot of awkward looking if's written in <br>
> unnatural 'backwards' terms, and also, leads to undesirable <br>
> depth of nested scopes.<br>
><br>
> The compiler backend can and should re-jig the comparisons, but <br>
> it needs to receive a hint which way is 'likely' from the <br>
> programmer.<br>
><br>
> How can we add an attribute to the branch condition that the <br>
> backend can take advantage of? I think it needs to be in the <br>
> language spec...<br>
<br>
For LDC see, <br>
<a href="https://github.com/ldc-developers/ldc/blob/master/runtime/druntime/src/ldc/intrinsics.di#L619" rel="noreferrer noreferrer" target="_blank">https://github.com/ldc-developers/ldc/blob/master/runtime/druntime/src/ldc/intrinsics.di#L619</a> and see also `llvm_assume` just beneath it.<br>
<br>
GDC probably has something similar too.<br></blockquote></div></div><div dir="auto"><br></div><div dir="auto">Yes exactly, this is my point, we need something in the spec. I think there might be an opportunity to express branch prediction hints in a more user-friendly way than assume statements... But a language assume() would also be very useful!</div><div dir="auto"><div class="gmail_quote"><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
</blockquote></div></div></div>