summaryrefslogtreecommitdiffstats
path: root/src/backend/switchstack_gcc_64_linux_mac.s
blob: ced6a5de1bca313e83dae6e2d713ca74c3835025 (plain)
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
42
43
44
.text
.globl _switchStackInternal

_switchStackInternal:
    // save callee-saved registers
    push %rbp
    movq %rsp, %rbp
    push %rbx
    push %r12
    push %r13
    push %r14
    push %r15

    // store SIMD floating point control word
    sub $4, %rsp
    stmxcsr (%rsp)

    // store floating point control bytes
    sub $4, %rsp
    fstcw (%rsp)

    // save the old stack pointer (second arg in rsi)
    movq %rsp, (%rsi)
    // set the new stack pointer (first arg in rdi)
    movq %rdi, %rsp

    // restore floating point control bytes
    fnclex
    fldcw (%rsp)
    add $4, %rsp

    // restore SIMD floating point control word
    ldmxcsr (%rsp)
    add $4, %rsp

    // pop callee-saved registers
    pop %r15
    pop %r14
    pop %r13
    pop %r12
    pop %rbx
    pop %rbp

    retq