https://gcc.gnu.org/bugzilla/show_bug.cgi?id=124063
--- Comment #2 from Jiang XueZhi <jiangxuezhi2 at huawei dot com> ---
(In reply to Andrew Pinski from comment #1)
> >*(const double *)
>
> This deference requires 8byte alignment due to the alignment requirements of
> C.
>
> If you want a type which has a lower alignment you can do:
>
> typedef double unaligned_double __attribute__((aligned(1)));
>
> And then use that:
> ```
> uint32_t test(const void *pAddr, unaligned_double *plfValue)
> {
> if ((NULL == pAddr) || (NULL == plfValue)) {
> return (0 | 7);
> }
>
> *plfValue = (double)(*(const unaligned_double *)pAddr);
> return (0 | 0);
> }
> ```
>
>
> Also note even in GCC 7, it required an alignment of 64bits:
> ```
> (insn 21 20 22 4 (set (reg:DF 113 [ _4 ])
> (mem:DF (reg/v/f:SI 115 [ pAddr ]) [1 MEM[(const double
> *)pAddr_7(D)]+0 S8 A64])) "/app/example.cpp":8 -1
> (nil))
> (insn 22 21 6 4 (set (mem:DF (reg/v/f:SI 116 [ plfValue ]) [1
> *plfValue_8(D)+0 S8 A64])
> (reg:DF 113 [ _4 ])) "/app/example.cpp":8 -1
> (nil))
> ```
>
> It just didn't use those instructions then.
Thanks for your reply. (In reply to Andrew Pinski from comment #1)
> >*(const double *)
>
> This deference requires 8byte alignment due to the alignment requirements of
> C.
>
> If you want a type which has a lower alignment you can do:
>
> typedef double unaligned_double __attribute__((aligned(1)));
>
> And then use that:
> ```
> uint32_t test(const void *pAddr, unaligned_double *plfValue)
> {
> if ((NULL == pAddr) || (NULL == plfValue)) {
> return (0 | 7);
> }
>
> *plfValue = (double)(*(const unaligned_double *)pAddr);
> return (0 | 0);
> }
> ```
>
>
> Also note even in GCC 7, it required an alignment of 64bits:
> ```
> (insn 21 20 22 4 (set (reg:DF 113 [ _4 ])
> (mem:DF (reg/v/f:SI 115 [ pAddr ]) [1 MEM[(const double
> *)pAddr_7(D)]+0 S8 A64])) "/app/example.cpp":8 -1
> (nil))
> (insn 22 21 6 4 (set (mem:DF (reg/v/f:SI 116 [ plfValue ]) [1
> *plfValue_8(D)+0 S8 A64])
> (reg:DF 113 [ _4 ])) "/app/example.cpp":8 -1
> (nil))
> ```
>
> It just didn't use those instructions then.
Thank you for your response. I’d like to ask which specific patch introduced
the optimization that eventually led to the generation of hard float
instructions. I noticed that this optimization was first introduced in GCC 13.
Could you please provide some insight into this? Thanks again.