3 ms·
Late reply, but I think that people who use a "proper function" don't usually put it immediately after the call - can you really call it a proper function if co
by im3w1l 2y ago
Late reply, but I think that people who use a "proper function" don't usually put it immediately after the call - can you really call it a proper function if control flow falls through into it? That's certainly not how functions usually work. So I think people would either put the function somewhere entirely different, or do something like
do_something_with_rip:
call .get_rip
jmp .after_get_rip
.get_rip:
;...
ret
.after_get_rip:
;...
Your example is kinda cute, but I'd guess few enough people use that trick for it to be worth special casing or optimizing for.
As for
call .push_rip
.push_rip:
pop rax
I can see that appearing in old hand-written code before knowledge of branch predictor implications become well known? Or perhaps people who know it's suboptimal but figure that it is fast enough (getting the rip is likely to be very cold code).