[x265] [PATCH 19 of 20] x86inc: Avoid using eax/rax for storing the stack pointer

vignesh at multicorewareinc.com vignesh at multicorewareinc.com
Mon Jun 12 07:38:01 CEST 2017


# HG changeset patch
# User Vignesh Vijayakumar
# Date 1496833646 -19800
#      Wed Jun 07 16:37:26 2017 +0530
# Node ID 7d5dad48e96f576e34c7fee96e39d8005c15dca3
# Parent  f90f9db1a86d6eccb0ce6859dc5498f32892b9d8
x86inc: Avoid using eax/rax for storing the stack pointer

When allocating stack space with an alignment requirement that is larger
than the current stack alignment we need to store a copy of the original
stack pointer in order to be able to restore it later.

If we chose to use another register for this purpose we should not pick
eax/rax since it can be overwritten as a return value.

diff -r f90f9db1a86d -r 7d5dad48e96f source/common/x86/x86inc.asm
--- a/source/common/x86/x86inc.asm	Wed Jun 07 16:27:09 2017 +0530
+++ b/source/common/x86/x86inc.asm	Wed Jun 07 16:37:26 2017 +0530
@@ -362,10 +362,18 @@
     %ifnum %1
         %if %1 != 0 && required_stack_alignment > STACK_ALIGNMENT
             %if %1 > 0
+                ; Reserve an additional register for storing the original stack pointer, but avoid using
+                ; eax/rax for this purpose since it can potentially get overwritten as a return value.
                 %assign regs_used (regs_used + 1)
+                %if ARCH_X86_64 && regs_used == 7
+                    %assign regs_used 8
+                %elif ARCH_X86_64 == 0 && regs_used == 1
+                    %assign regs_used 2
+                %endif
             %endif
             %if ARCH_X86_64 && regs_used < 5 + UNIX64 * 3
-                ; Ensure that we don't clobber any registers containing arguments
+                ; Ensure that we don't clobber any registers containing arguments. For UNIX64 we also preserve r6 (rax)
+                ; since it's used as a hidden argument in vararg functions to specify the number of vector registers used.
                 %assign regs_used 5 + UNIX64 * 3
             %endif
         %endif


More information about the x265-devel mailing list