Standard way to supply hints to branches
Walter Bright
newshound2 at digitalmars.com
Wed Sep 11 05:15:25 UTC 2024
Compile the following with -vasm -O:
```
void bar();
int foo(int i)
{
if (i)
return 0;
bar();
return 1;
}
int baz(int i)
{
if (i)
goto Lreturn0;
bar();
return 1;
Lreturn0:
return 0;
}
```
and you get:
```
_D5test93fooFiZi:
0000: 55 push RBP
0001: 48 8B EC mov RBP,RSP
0004: 85 FF test EDI,EDI
0006: 74 04 je Lc
0008: 31 C0 xor EAX,EAX // hot path
000a: 5D pop RBP
000b: C3 ret
000c: E8 00 00 00 00 call L0 // cold path
0011: B8 01 00 00 00 mov EAX,1
0016: 5D pop RBP
0017: C3 ret
_D5test93bazFiZi:
0000: 55 push RBP
0001: 48 8B EC mov RBP,RSP
0004: 85 FF test EDI,EDI
0006: 75 0C jne L14
0008: E8 00 00 00 00 call L0 // hot path
000d: B8 01 00 00 00 mov EAX,1
0012: 5D pop RBP
0013: C3 ret
0014: 31 C0 xor EAX,EAX // cold path
0016: 5D pop RBP
0017: C3 ret
```
More information about the Digitalmars-d
mailing list