"매 CPU 의 매 branch 의 outcome 의 wait 의 X — 매 predicted path 의 의 ahead 의 execute, 매 wrong → rollback". 1990s Pentium Pro 매 first commercial impl → 2018 Spectre/Meltdown 매 the dark side 의 reveal → 2026 매 hardware mitigation (Intel CET, ARM BTI/MTE) + compiler hardening 매 standard.
매 핵심
매 mechanism
Branch predictor 매 매 branch 의 taken/not-taken 의 history 의 학습 (TAGE, Perceptron).
Reorder buffer (ROB) 매 매 speculative instruction 의 in-flight 의 hold.
Retire stage 매 매 branch 의 resolved 의 후 의 commit (correct) or flush (mispredict).
Misprediction penalty: 매 modern CPU 매 ~15-25 cycles.
매 dark side
Spectre v1 (Bounds Check Bypass): 매 attacker 의 branch predictor 의 train → 매 sensitive memory 의 cache 의 leak.
Spectre v2 (Branch Target Injection): 매 indirect branch 의 mispredict 의 force.
Meltdown: 매 user 의 kernel memory 의 speculative read.
L1TF, MDS, Retbleed, GhostRace (2018-2024): 매 variant 의 endless.
매 응용
CPU performance (1.5-3x IPC vs in-order).
Branch prediction research.
Compiler 매 PGO + autovectorization 의 enabler.
💻 패턴
Pattern 1: 매 Spectre v1 매 PoC (educational)
// 매 educational only
uint8_tarray1[16]={0};uint8_tarray2[256*512];char*secret="key";unsignedintarray1_size=16;voidvictim(size_tx){if(x<array1_size){// <-- 매 trained branch
uint8_tv=array2[array1[x]*512];// 매 cache 의 leak via timing
}}// Attacker 매 array1_size 의 cache 의 evict → speculative path 매 OOB read
Pattern 2: 매 LFENCE / 매 retpoline 의 mitigation
// gcc -mindirect-branch=thunk-extern -mfunction-return=thunk-extern
staticinlinevoidspeculation_barrier(void){__asm__volatile("lfence":::"memory");}boolsafe_lookup(size_ti,size_tn,uint8_t*arr){if(i<n){speculation_barrier();// 매 stops speculative path
returnarr[i];}return0;}
Pattern 3: 매 bench 의 branch misprediction
// perf stat -e branches,branch-misses ./a.out
#include<stdio.h>intmain(intargc,char**argv){intsum=0;for(inti=0;i<1000000;i++){if(i%2==0)sum+=i;// 매 100% predictable
// if ((rand() & 1)) sum += i; // 매 50% miss → much slower
}printf("%d\n",sum);}
Pattern 4: 매 V8 / JIT 의 speculative optimization
// V8 매 hidden class 의 speculatively assume → 매 type 의 change → 매 deopt
functionadd(o){returno.x+o.y;}add({x:1,y:2});// 매 monomorphic, JIT 의 specialize
add({x:1,y:2,z:3});// 매 hidden class 의 change → 매 deopt
매 결정 기준
상황
Approach
매 user code 매 typical app
매 default — speculation 매 win, 매 mitigation OS-level