Commit 6cb362d0 authored by Martin Storsjö's avatar Martin Storsjö Committed by Ronald S. Bultje

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.
parent 1bb1ec21
...@@ -28,8 +28,23 @@ ...@@ -28,8 +28,23 @@
#ifndef __DAV1D_COMMON_ATTRIBUTES_H__ #ifndef __DAV1D_COMMON_ATTRIBUTES_H__
#define __DAV1D_COMMON_ATTRIBUTES_H__ #define __DAV1D_COMMON_ATTRIBUTES_H__
#include "config.h"
#include <stddef.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: * API for variables, struct members (ALIGN()) like:
* uint8_t var[1][2][3][4] * uint8_t var[1][2][3][4]
...@@ -51,10 +66,10 @@ ...@@ -51,10 +66,10 @@
* ALIGN_STK_$align(uint8_t, var, 1, [2][3][4]) * ALIGN_STK_$align(uint8_t, var, 1, [2][3][4])
*/ */
#define ALIGN_STK_32(type, var, sz1d, sznd) \ #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) // as long as stack is itself 16-byte aligned, this works (win64, gcc)
#define ALIGN_STK_16(type, var, sz1d, sznd) \ #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: * Forbid inlining of a function:
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment