Preserve xmm registers on x86_64

Summary: public

`%xmm` registers weren't being preserved what would cause eventual weird issues
for methods using floats / doubles / etc.

Reviewed By: jspahrsummers

Differential Revision: D2581358

fb-gh-sync-id: 701498def0f05716c665f4749e5154b828bf41ec
This commit is contained in:
Tadeu Zagallo 2015-10-28 05:33:47 -07:00 коммит произвёл facebook-github-bot-4
Родитель 46e67ef428
Коммит 8185b203be
1 изменённых файлов: 25 добавлений и 8 удалений

Просмотреть файл

@ -22,6 +22,15 @@ SYMBOL_NAME(RCTProfileTrampoline):
* We have to save %r12 since its value should be preserved across function * We have to save %r12 since its value should be preserved across function
* calls and we'll use it to keep the stack pointer * calls and we'll use it to keep the stack pointer
*/ */
subq $0x80+8, %rsp // 8 x 16-bytes xmm registers + 8-bytes alignment
movdqa %xmm0, 0x70(%rsp)
movdqa %xmm1, 0x60(%rsp)
movdqa %xmm2, 0x50(%rsp)
movdqa %xmm3, 0x40(%rsp)
movdqa %xmm4, 0x30(%rsp)
movdqa %xmm5, 0x20(%rsp)
movdqa %xmm6, 0x10(%rsp)
movdqa %xmm7, 0x00(%rsp)
pushq %rdi pushq %rdi
pushq %rsi pushq %rsi
pushq %rdx pushq %rdx
@ -82,7 +91,7 @@ SYMBOL_NAME(RCTProfileTrampoline):
movq %r14, 0x8(%rax) movq %r14, 0x8(%rax)
// mov the pointers we need to the callee saved registers // mov the pointers we need to the callee saved registers
movq 0x48(%rsp), %r13 // caller of RCTProfileTrampoline movq 0xd8(%rsp), %r13 // caller of RCTProfileTrampoline (0xd8 is stack top)
movq %rax, %r14 // allocated memory's address movq %rax, %r14 // allocated memory's address
/** /**
@ -108,6 +117,15 @@ SYMBOL_NAME(RCTProfileTrampoline):
popq %rdx popq %rdx
popq %rsi popq %rsi
popq %rdi popq %rdi
movdqa 0x00(%rsp), %xmm7
movdqa 0x10(%rsp), %xmm6
movdqa 0x20(%rsp), %xmm5
movdqa 0x30(%rsp), %xmm4
movdqa 0x40(%rsp), %xmm3
movdqa 0x50(%rsp), %xmm2
movdqa 0x60(%rsp), %xmm1
movdqa 0x70(%rsp), %xmm0
addq $0x80+8, %rsp
/** /**
* delete parent caller (saved in %r13) `call` will add the new address so * delete parent caller (saved in %r13) `call` will add the new address so
@ -118,6 +136,8 @@ SYMBOL_NAME(RCTProfileTrampoline):
// call the actual function and save the return value // call the actual function and save the return value
callq *%r11 callq *%r11
pushq %rax pushq %rax
subq $0x10+8, %rsp //16-bytes xmm register + 8-bytes for alignment
movdqa %xmm0, (%rsp)
// align stack // align stack
pushq %r12 pushq %r12
@ -131,15 +151,12 @@ SYMBOL_NAME(RCTProfileTrampoline):
movq %r12, %rsp movq %r12, %rsp
popq %r12 popq %r12
// save the return of the actual function call
popq %rax
/** /**
* Restore the initial value of the callee saved registers, saved in the * Restore the initial value of the callee saved registers, saved in the
* memory allocated. * memory allocated.
*/ */
movq %r13, %rcx movq %r13, %rcx
movq %r14, %rdx movq %r14, %rdi
movq 0x0(%r14), %r13 movq 0x0(%r14), %r13
movq 0x8(%r14), %r14 movq 0x8(%r14), %r14
@ -148,13 +165,11 @@ SYMBOL_NAME(RCTProfileTrampoline):
* memory) and align the stack * memory) and align the stack
*/ */
pushq %rcx pushq %rcx
pushq %rax
pushq %r12 pushq %r12
movq %rsp, %r12 movq %rsp, %r12
andq $-0x10, %rsp andq $-0x10, %rsp
// Free the memory allocated to stash callee saved registers // Free the memory allocated to stash callee saved registers
movq %rdx, %rdi
callq SYMBOL_NAME(free) callq SYMBOL_NAME(free)
// unalign stack and restore %r12 // unalign stack and restore %r12
@ -165,8 +180,10 @@ SYMBOL_NAME(RCTProfileTrampoline):
* pop the caller address to %rcx and the actual function return value to * pop the caller address to %rcx and the actual function return value to
* %rax, so it's the return value of RCTProfileTrampoline * %rax, so it's the return value of RCTProfileTrampoline
*/ */
popq %rax
popq %rcx popq %rcx
movdqa (%rsp), %xmm0
addq $0x10+8, %rsp
popq %rax
// jump to caller // jump to caller
jmpq *%rcx jmpq *%rcx