Source-Changes-D archive
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]
Re: struct alignment in src/lib/libc/arch/m68k/softfloat
On Thu, 18 Sep 2025 02:39:48 Roland Illig wrote:
> Am 17.09.2025 um 13:32 schrieb Nathanial Sloss:
> > Module Name: src
> > Committed By: nat
> > Date: Wed Sep 17 11:32:06 UTC 2025
> >
> > Modified Files:
> > src/lib/libc/arch/m68k/softfloat: softfloat.h
> >
> > Log Message:
> > Store 80 bit floats properly on m68k.
> >
> > The libc/softfloat would store the high word as a short, where as gcc
> > will store it as a long with the sign and 15 bit exponent in the high
> > bytes.
> >
> > I had to use the __packed attribute as they were stored with an 8-byte
> > alignment....Why????
>
> struct floatx80 {
> uint64_t lo;
> uint16_t hi;
> };
>
> When you have an array of this type, each access to arr[i].lo should be
> aligned at an 8-byte boundary. Therefore, there's 6 bytes of padding at
> the end of the struct.
>
> On some architectures such as sparc, this padding is necessary to
> prevent SIGBUS, on other architectures such as x86_64, accessing an
> unaligned object results in bad performance, due to overlapping reads.
>
> C23 6.7.3.2p16 doesn't directly impose any alignment requirements on a
> struct or its members, other that each member has to be aligned
> "appropriate to its type". On the other hand, C23 6.7.3.2p19 allows
> unnamed padding at the end of a struct, so that sizeof(arr) can be the
> same as sizeof(arr[0]) * array_length(arr).
>
> Roland
Thank for the background information, I was just worried that I was loosing
memory throughout due to padding bytes.
Best regards,
Nat
Home |
Main Index |
Thread Index |
Old Index