<div dir="ltr"><div class="gmail_quote"><div dir="ltr" class="gmail_attr">On Tue, 27 Aug 2024 at 15:27, Manu <<a href="mailto:turkeyman@gmail.com">turkeyman@gmail.com</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex"><div dir="ltr"><div class="gmail_quote"><div dir="ltr" class="gmail_attr">On Mon, 26 Aug 2024 at 17:16, Walter Bright via Digitalmars-d <<a href="mailto:digitalmars-d@puremagic.com" target="_blank">digitalmars-d@puremagic.com</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">On 8/24/2024 9:47 AM, Manu wrote:<br>
> C++ is way ahead on this... they added attributes to the language years back, <br>
> and they defined [[likely]] and [[unlikely]] post-fix on control statements. <br>
> It's really convenient, it reads well, and it's easy to retrofit without <br>
> disturbing the code.<br>
> That's the de-facto now, and we should follow it.<br>
<br>
It's unattractive.<br>
<br>
I provided two alternate means to accomplish the same thing elsewhere in this <br>
thread.<br>
<br>
<a href="https://www.digitalmars.com/d/archives/digitalmars/D/Standard_way_to_supply_hints_to_branches_375697.html#N375717" rel="noreferrer" target="_blank">https://www.digitalmars.com/d/archives/digitalmars/D/Standard_way_to_supply_hints_to_branches_375697.html#N375717</a><br></blockquote><div><br></div><div>"Unattractive"? ... seriously?</div><div>Your suggestions were to quite seriously molest the code, reordering, adding extra scopes, inverting logic, nonsense statements like `do {} while(0)`, using labels and goto's which doesn't marry well with general control flow and RAII type things... sorry; but "unattractive"? That might be the most bizarre thing I've ever heard you say! ;)<br></div></div></div></blockquote><div><br></div><div>Just so it's clear what's going on here; certain microcontrollers don't have branch predictors at all; so hinting is essential on these exotic platforms. Your suggestions could appear in almost every single at-least-warm function, and it's not clear how they marry with eachother. We discussed 2 principle cases; likely early return because of short-path or cached value, and unlikely early return due to argument validation failure. Plenty of functions contain both cases, and plenty of functions contain numerous such items.</div><div>Try and imagine how your suggestion scales when there are 4-5 conditions that need to be tested on function entry, and they don't all receive the same hint. I value readable and maintainable code...</div></div></div>