shithub: dav1d

Download patch

ref: 6cb362d015ba0592eb72eb3face5ed806d20c738
parent: 1bb1ec21eae5934b06323f2e3dfe9cac8b41c5ed
author: Martin Storsjö <[email protected]>
date: Thu Oct 25 07:58:51 EDT 2018

attributes: Don't align to more than what assembly needs/benefits from

For arm/arm64, there's no need to align any buffer to 32 bytes
as the assembly doesn't need it and doesn't benefit from it.

This would be much more elegant if defined like this:

    #define MAX_ALIGN 16
    #define ALIGN(align) __attribute__((aligned(MIN(align, MAX_ALIGN))))

This works for GCC and Clang, but the MSVC alignment __declspec
needs a literal alignment value, it can't handle an expression.

--- a/include/common/attributes.h
+++ b/include/common/attributes.h
@@ -28,8 +28,23 @@
 #ifndef __DAV1D_COMMON_ATTRIBUTES_H__
 #define __DAV1D_COMMON_ATTRIBUTES_H__
 
+#include "config.h"
+
 #include <stddef.h>
 
+#if ARCH_X86
+#define ALIGN_32_VAL 32
+#define ALIGN_16_VAL 16
+#elif ARCH_ARM || ARCH_AARCH64
+// ARM doesn't benefit from anything more than 16 byte alignment.
+#define ALIGN_32_VAL 16
+#define ALIGN_16_VAL 16
+#else
+// No need for extra alignment on platforms without assembly.
+#define ALIGN_32_VAL 8
+#define ALIGN_16_VAL 8
+#endif
+
 /*
  * API for variables, struct members (ALIGN()) like:
  * uint8_t var[1][2][3][4]
@@ -51,10 +66,10 @@
  * ALIGN_STK_$align(uint8_t, var, 1, [2][3][4])
  */
 #define ALIGN_STK_32(type, var, sz1d, sznd) \
-    ALIGN(type var[sz1d]sznd, 32)
+    ALIGN(type var[sz1d]sznd, ALIGN_32_VAL)
 // as long as stack is itself 16-byte aligned, this works (win64, gcc)
 #define ALIGN_STK_16(type, var, sz1d, sznd) \
-    ALIGN(type var[sz1d]sznd, 16)
+    ALIGN(type var[sz1d]sznd, ALIGN_16_VAL)
 
 /*
  * Forbid inlining of a function: