diff mbox series

[v1,9/9] aarch64: Handle alignment when it is bigger than BIGGEST_ALIGNMENT

Message ID DBBPR83MB0613D6929174C90188C8DFAAF8922@DBBPR83MB0613.EURPRD83.prod.outlook.com
State New
Headers show
Series SMALL code model fixes, optimization fixes, LTO and minimal C++ enablement | expand

Commit Message

Evgeny Karpov Sept. 2, 2024, 1:14 p.m. UTC
In some cases, the alignment can be bigger than BIGGEST_ALIGNMENT.
The patch handles these cases.

gcc/ChangeLog:

	* config/aarch64/aarch64-coff.h (ASM_OUTPUT_ALIGNED_LOCAL):
	Change alignment.
---
 gcc/config/aarch64/aarch64-coff.h | 10 ++++++++++
 1 file changed, 10 insertions(+)

Comments

Richard Sandiford Sept. 2, 2024, 3:36 p.m. UTC | #1
Evgeny Karpov <Evgeny.Karpov@microsoft.com> writes:
> In some cases, the alignment can be bigger than BIGGEST_ALIGNMENT.
> The patch handles these cases.
>
> gcc/ChangeLog:
>
> 	* config/aarch64/aarch64-coff.h (ASM_OUTPUT_ALIGNED_LOCAL):
> 	Change alignment.

Can you go into more detail?  What kind of testcase requires this?

Thanks,
Richard

> ---
>  gcc/config/aarch64/aarch64-coff.h | 10 ++++++++++
>  1 file changed, 10 insertions(+)
>
> diff --git a/gcc/config/aarch64/aarch64-coff.h b/gcc/config/aarch64/aarch64-coff.h
> index 77c09df82e4..131145171a0 100644
> --- a/gcc/config/aarch64/aarch64-coff.h
> +++ b/gcc/config/aarch64/aarch64-coff.h
> @@ -58,6 +58,16 @@
>    assemble_name ((FILE), (NAME)),		\
>    fprintf ((FILE), ",%u\n", (int)(ROUNDED)))
>  
> +#define ASM_OUTPUT_ALIGNED_LOCAL(FILE, NAME, SIZE, ALIGNMENT)  \
> +  { \
> +    unsigned HOST_WIDE_INT rounded = MAX ((SIZE), 1); \
> +    unsigned HOST_WIDE_INT alignment = MAX ((ALIGNMENT), BIGGEST_ALIGNMENT); \
> +    rounded += (alignment / BITS_PER_UNIT) - 1; \
> +    rounded = (rounded / (alignment / BITS_PER_UNIT) \
> +      * (alignment / BITS_PER_UNIT)); \
> +    ASM_OUTPUT_LOCAL (FILE, NAME, SIZE, rounded); \
> +  }
> +
>  #define ASM_OUTPUT_SKIP(STREAM, NBYTES) 	\
>    fprintf (STREAM, "\t.space\t%d  // skip\n", (int) (NBYTES))
Evgeny Karpov Sept. 3, 2024, 2:51 p.m. UTC | #2
Monday, September 2, 2024 5:36 PM
Richard Sandiford <richard.sandiford@arm.com> wrote:

>> In some cases, the alignment can be bigger than BIGGEST_ALIGNMENT.
>> The patch handles these cases.
>>
>> gcc/ChangeLog:
>>
>>        * config/aarch64/aarch64-coff.h (ASM_OUTPUT_ALIGNED_LOCAL):
>>        Change alignment.
>
> Can you go into more detail?  What kind of testcase requires this?

The issue was detected while building FFmpeg.
It creates structures, most likely for AVX optimization.

For instance:
float __attribute__((aligned (32))) large_aligned_array[3];

BIGGEST_ALIGNMENT could be up to 512 bits on x64.
This patch has been added to cover this case without needing to change the FFmpeg code.

Regards,
Evgeny
diff mbox series

Patch

diff --git a/gcc/config/aarch64/aarch64-coff.h b/gcc/config/aarch64/aarch64-coff.h
index 77c09df82e4..131145171a0 100644
--- a/gcc/config/aarch64/aarch64-coff.h
+++ b/gcc/config/aarch64/aarch64-coff.h
@@ -58,6 +58,16 @@ 
   assemble_name ((FILE), (NAME)),		\
   fprintf ((FILE), ",%u\n", (int)(ROUNDED)))
 
+#define ASM_OUTPUT_ALIGNED_LOCAL(FILE, NAME, SIZE, ALIGNMENT)  \
+  { \
+    unsigned HOST_WIDE_INT rounded = MAX ((SIZE), 1); \
+    unsigned HOST_WIDE_INT alignment = MAX ((ALIGNMENT), BIGGEST_ALIGNMENT); \
+    rounded += (alignment / BITS_PER_UNIT) - 1; \
+    rounded = (rounded / (alignment / BITS_PER_UNIT) \
+      * (alignment / BITS_PER_UNIT)); \
+    ASM_OUTPUT_LOCAL (FILE, NAME, SIZE, rounded); \
+  }
+
 #define ASM_OUTPUT_SKIP(STREAM, NBYTES) 	\
   fprintf (STREAM, "\t.space\t%d  // skip\n", (int) (NBYTES))