diff mbox series

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

Message ID DBBPR83MB0613A71DB5403BE3D50B1007F8462@DBBPR83MB0613.EURPRD83.prod.outlook.com
State New
Headers show
Series None | expand

Commit Message

Evgeny Karpov Oct. 16, 2024, 3:04 p.m. UTC
Thursday, September 19, 2024
Richard Sandiford <richard.sandiford@arm.com> wrote:

>> 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.
>
> What goes wrong if we don't do this?  I'm not sure from the description
> whether it's a correctness fix, a performance fix, or whether it's about
> avoiding wasted space.

It is a correctness fix.

>> +#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)); \
>
> There's a ROUND_UP macro that could be used here.

Here is the patch after applying ROUND_UP.

Regards,
Evgeny

Comments

Richard Sandiford Oct. 17, 2024, 5:30 p.m. UTC | #1
Evgeny Karpov <Evgeny.Karpov@microsoft.com> writes:
> Thursday, September 19, 2024
> Richard Sandiford <richard.sandiford@arm.com> wrote:
>
>>> 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.
>>
>> What goes wrong if we don't do this?  I'm not sure from the description
>> whether it's a correctness fix, a performance fix, or whether it's about
>> avoiding wasted space.
>
> It is a correctness fix.

But you could you explain what goes wrong if you don't do this?
(I realise it might be very obvious when you've seen it happen :)
But I'm genuinely unsure.)

Why do we ignore the alignment if it is less than BIGGEST_ALIGNMENT?

>>> +#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)); \
>>
>> There's a ROUND_UP macro that could be used here.
>
> Here is the patch after applying ROUND_UP.
>
> Regards,
> Evgeny
>
> diff --git a/gcc/config/aarch64/aarch64-coff.h b/gcc/config/aarch64/aarch64-coff.h
> index 3c8aed806c9..1a45256ebfe 100644
> --- a/gcc/config/aarch64/aarch64-coff.h
> +++ b/gcc/config/aarch64/aarch64-coff.h
> @@ -58,6 +58,13 @@
>    assemble_name ((FILE), (NAME)),              \
>    fprintf ((FILE), "," HOST_WIDE_INT_PRINT_DEC  "\n", (ROUNDED)))
>
> +#define ASM_OUTPUT_ALIGNED_LOCAL(FILE, NAME, SIZE, ALIGNMENT)  \
> +  {                                                            \
> +    unsigned rounded = ROUND_UP (MAX ((SIZE), 1),              \
> +      MAX ((ALIGNMENT), BIGGEST_ALIGNMENT) / BITS_PER_UNIT);   \

Better to use "auto" rather than "unsigned".

Otherwise it looks good modulo the questions above.

Thanks,
Richard

> +    ASM_OUTPUT_LOCAL (FILE, NAME, SIZE, rounded);              \
> +  }
> +
>  #define ASM_OUTPUT_SKIP(STREAM, NBYTES)        \
>    fprintf (STREAM, "\t.space\t%d  // skip\n", (int) (NBYTES))
diff mbox series

Patch

diff --git a/gcc/config/aarch64/aarch64-coff.h b/gcc/config/aarch64/aarch64-coff.h
index 3c8aed806c9..1a45256ebfe 100644
--- a/gcc/config/aarch64/aarch64-coff.h
+++ b/gcc/config/aarch64/aarch64-coff.h
@@ -58,6 +58,13 @@ 
   assemble_name ((FILE), (NAME)),              \
   fprintf ((FILE), "," HOST_WIDE_INT_PRINT_DEC  "\n", (ROUNDED)))

+#define ASM_OUTPUT_ALIGNED_LOCAL(FILE, NAME, SIZE, ALIGNMENT)  \
+  {                                                            \
+    unsigned rounded = ROUND_UP (MAX ((SIZE), 1),              \
+      MAX ((ALIGNMENT), BIGGEST_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))