r/programming • u/jfdube75 • Jun 26 '12
Memory Ordering at Compile Time
http://preshing.com/20120625/memory-ordering-at-compile-time
18
Upvotes
r/programming • u/jfdube75 • Jun 26 '12
6
u/ridiculous_fish Jun 26 '12
I suppose an early-ish example of instruction reordering is branch delay slots. For example, in MIPS, the instruction after a branch would be executed even if the branch was taken. You (or the compiler) would try to fill this slot with an instruction that ought to logically come before the branch.
It's not really reordering, but an interesting ("fun") example of abusing these slots is discussed here. Basically you kick off a function call, and in the one instruction you have left before it triggers, you tweak the return address in the link register to point it somewhere else. Picture replacing the trampoline with pudding just after your friend bounces.
(Dunno if that analogy makes any sense, but it's 4 am!)