Skip to content

Commit 40d774b

Browse files
authored
Avoid memory dependency between instructions. (ruby#8284)
1 parent 97a97d6 commit 40d774b

File tree

1 file changed

+24
-18
lines changed

1 file changed

+24
-18
lines changed

coroutine/amd64/Context.S

+24-18
Original file line numberDiff line numberDiff line change
@@ -13,29 +13,35 @@
1313
.globl PREFIXED_SYMBOL(SYMBOL_PREFIX,coroutine_transfer)
1414
PREFIXED_SYMBOL(SYMBOL_PREFIX,coroutine_transfer):
1515

16-
# Save caller state
17-
pushq %rbp
18-
pushq %rbx
19-
pushq %r12
20-
pushq %r13
21-
pushq %r14
22-
pushq %r15
23-
24-
# Save caller stack pointer
16+
# Make space on the stack for 6 registers:
17+
subq $48, %rsp
18+
19+
# Save caller state:
20+
movq %rbp, 40(%rsp)
21+
movq %rbx, 32(%rsp)
22+
movq %r12, 24(%rsp)
23+
movq %r13, 16(%rsp)
24+
movq %r14, 8(%rsp)
25+
movq %r15, (%rsp)
26+
27+
# Save caller stack pointer:
2528
movq %rsp, (%rdi)
2629

27-
# Restore callee stack pointer
30+
# Restore callee stack pointer:
2831
movq (%rsi), %rsp
2932

3033
# Restore callee state
31-
popq %r15
32-
popq %r14
33-
popq %r13
34-
popq %r12
35-
popq %rbx
36-
popq %rbp
37-
38-
# Put the first argument into the return value
34+
movq 40(%rsp), %rbp
35+
movq 32(%rsp), %rbx
36+
movq 24(%rsp), %r12
37+
movq 16(%rsp), %r13
38+
movq 8(%rsp), %r14
39+
movq (%rsp), %r15
40+
41+
# Adjust stack pointer back:
42+
addq $48, %rsp
43+
44+
# Put the first argument into the return value:
3945
movq %rdi, %rax
4046

4147
# We pop the return address and jump to it

0 commit comments

Comments
 (0)