[x265] [PATCH] align the stack for GCC x86_32 builds

Steve Borho steve at borho.org
Wed Apr 23 05:45:56 CEST 2014


# HG changeset patch
# User Steve Borho <steve at borho.org>
# Date 1397762142 18000
#      Thu Apr 17 14:15:42 2014 -0500
# Node ID 69e53e87d1201b720d69f31fb7978d22ad4357a8
# Parent  d11c90310c8adc58ee8e0da78798147750037ac4
align the stack for GCC x86_32 builds

For all threads x265 creates, align the stack immediately in the call to
threadMain().

The API calls do not appear to require an aligned stack; all primitives that
require stack aligned buffers are called from frame encoder or worker pool
threads

diff -r d11c90310c8a -r 69e53e87d120 source/cmake/CMakeASM_YASMInformation.cmake
--- a/source/cmake/CMakeASM_YASMInformation.cmake	Tue Apr 22 13:41:04 2014 -0500
+++ b/source/cmake/CMakeASM_YASMInformation.cmake	Thu Apr 17 14:15:42 2014 -0500
@@ -21,8 +21,7 @@
     endif()
 endif()
 
-# we cannot assume 16-byte stack alignment on x86_32 even with GCC
-if(GCC AND X64)
+if(GCC)
     set(ASM_FLAGS "${ASM_FLAGS} -DHAVE_ALIGNED_STACK=1")
 else()
     set(ASM_FLAGS "${ASM_FLAGS} -DHAVE_ALIGNED_STACK=0")
diff -r d11c90310c8a -r 69e53e87d120 source/common/common.h
--- a/source/common/common.h	Tue Apr 22 13:41:04 2014 -0500
+++ b/source/common/common.h	Thu Apr 17 14:15:42 2014 -0500
@@ -47,10 +47,21 @@
 #define ALIGN_VAR_8(T, var)  T var __attribute__((aligned(8)))
 #define ALIGN_VAR_16(T, var) T var __attribute__((aligned(16)))
 #define ALIGN_VAR_32(T, var) T var __attribute__((aligned(32)))
+
+#if X265_ARCH_X86 && !defined(X86_64)
+extern "C" intptr_t x265_stack_align( void (*func)(), ... );
+#define x265_stack_align(func,...) x265_stack_align((void (*)())func, __VA_ARGS__)
+#else
+#define x265_stack_align(func,...) func(__VA_ARGS__)
+#endif
+
 #elif defined(_MSC_VER)
+
 #define ALIGN_VAR_8(T, var)  __declspec(align(8)) T var
 #define ALIGN_VAR_16(T, var) __declspec(align(16)) T var
 #define ALIGN_VAR_32(T, var) __declspec(align(32)) T var
+#define x265_stack_align(func,...) func(__VA_ARGS__)
+
 #endif // if defined(__GNUC__)
 
 #if HIGH_BIT_DEPTH
diff -r d11c90310c8a -r 69e53e87d120 source/common/threading.cpp
--- a/source/common/threading.cpp	Tue Apr 22 13:41:04 2014 -0500
+++ b/source/common/threading.cpp	Thu Apr 17 14:15:42 2014 -0500
@@ -28,12 +28,18 @@
 namespace x265 {
 // x265 private namespace
 
+/* C shim for forced stack alignment */
+static void stackAlignMain(Thread *instance)
+{
+    instance->threadMain();
+}
+
 #if _WIN32
 
 static DWORD WINAPI ThreadShim(Thread *instance)
 {
     // defer processing to the virtual function implemented in the derived class
-    instance->threadMain();
+    x265_stack_align(stackAlignMain, instance);
 
     return 0;
 }
@@ -70,7 +76,7 @@
     // defer processing to the virtual function implemented in the derived class
     Thread *instance = reinterpret_cast<Thread *>(opaque);
 
-    instance->threadMain();
+    x265_stack_align(stackAlignMain, instance);
 
     return NULL;
 }


More information about the x265-devel mailing list