Michael S <
already...@yahoo.com> writes:
>On Sunday, April 16, 2023 at 4:22:24=E2=80=AFPM UTC+3, MarioCPPP wrote:
>> On 14/04/23 20:00, Scott Lurndal wrote:=20
>> > MarioCPPP <
NoliMihiFran...@libero.it> writes:=20
>> >> I am seeing a new (new to me) directive (ALIGNAT) but it=20
>> >> cannot pack bitfields spanning over two different bytes.=20
>> >>=20
>> >> Is it there a way to avoid "padding" within the structure,=20
>> >> because the function would be the redistribution of bits (I=20
>> >> mean, some mapping of 5 bytes of 8 bits in 8 fields of 5=20
>> >> bits, all of this by mean of a union, with another 40++ bits=20
>> >> wide integer and a single read / write) ?=20
>> >>=20
>> >> maybe my approach is wrong from the beginning.=20
>> >> In this case, what way would you recommend to explore ?=20
>> >>=20
>> >> I mean sth like this (the code is bugged, due to padding !)=20
>> >>=20
>> >>=20
>> >> struct EightSymbolsFiveBitWide=20
>> >> {=20
>> >> unsigned Field_0 : 5;=20
>> >> unsigned Field_1 : 5;=20
>> >> unsigned Field_2 : 5;=20
>> >> unsigned Field_3 : 5;=20
>> >> unsigned Field_4 : 5;=20
>> >> unsigned Field_5 : 5;=20
>> >> unsigned Field_6 : 5;=20
>> >> unsigned Field_7 : 5;=20
>> >> };=20
>> >=20
>> > struct eight_symbols_five_bits_wide {=20
>> > uint64_t field0 : 5,=20
>> > field1 : 5,=20
>> > field2 : 5,=20
>> > field3 : 5,=20
>> > field4 : 5,=20
>> > field5 : 5,=20
>> > field6 : 5,=20
>> > field7 : 5,=20
>> > unused : 24;=20
>> > } __attribute__ ((packed));=20
>> >
>> intresting !!! But for the little I can understand, this=20
>> answer seems in contrast with former Bo Persson reply. So=20
>> which is true ? Or is it just me that don't understand they=20
>> are not really in contrast ?=20
>>=20
>
>There is no contradiction if you know that the answer came from Scott Lurnd=
>al.
>In recent years Scott always assumes ARM64 platform unless explicitly
Actually, in this case, I was posting code for x86_64.
which we
use in production every day. Note that the order of the lsbit and
msbit differ depend on whether the host is big-endian or little-endian.
>stated otherwise.
>On ARM64 his solution is indeed portable between different compilers
>because the ABI on this platform specifies exact rules for bit fields.
>
>>=20
>> another sub-question : why the type is defined with a=20
>> precise size unsigned type, which does not even match the=20
>> width ? I mean, I usually see only plain unsigned. uint64_t=20
>> is a "complete" type, suggesting 64 bit width, which is not=20
>> the actual size. Why so ?=20
>
>On ARM64 Linux uint64_t is the same as unsigned long.
on x86_64 as well.