Tim Rentsch <tr.17687@z991.linuxsc.com> writes:
scott@slp53.sl.home (Scott Lurndal) writes:
One might also define data structures for control and status
registers using bitfield structs.
Yeah. This kind of application (among others) I consider one of
the motivating forces behind bitfields.
[Some whitespace trimming done in the excerpt below.]
e.g. for the SATA UAHC_GLB_OOBR register:
union UAHC_GBL_OOBR {
uint32_t u;
struct UAHC_GBL_OOBR_s {
#if __BYTE_ORDER == __BIG_ENDIAN
uint32_t we : 1; /**< R/W/H - Write enable. */
uint32_t cwmin : 7; /**< R/W/H - COMWAKE minimum value [...] */
uint32_t cwmax : 8; /**< R/W/H - COMWAKE maximum value [...] */
uint32_t cimin : 8; /**< R/W/H - COMINIT minimum value [...] */
uint32_t cimax : 8; /**< R/W/H - COMINIT maximum value [...] */
#else
uint32_t cimax : 8;
uint32_t cimin : 8;
uint32_t cwmax : 8;
uint32_t cwmin : 7;
uint32_t we : 1;
#endif
} s;
};
To me it seems kind of goofy to use uint32_t for the bitfields type.
I would just use unsigned, which is just as sure to work as intended,
isn't it?
The SATA hardware register is defined as a 32-bit register in the
SATA specification. Therefore we explicitly declare it as such.
There are other hardware registers in our implementation of the SATA controller that are defined as 64-bit registers, for those we use
uint64_t (rather than relying on 'unsigned long' for 64-bit linux
or 'unsigned long long' for 32-bit OS - and this code was designed
to be compiled for both 32-bit and 64-bit targets originally).
scott@slp53.sl.home (Scott Lurndal) writes:
Tim Rentsch <tr.17687@z991.linuxsc.com> writes:
scott@slp53.sl.home (Scott Lurndal) writes:
One might also define data structures for control and status
registers using bitfield structs.
Yeah. This kind of application (among others) I consider one of
the motivating forces behind bitfields.
[Some whitespace trimming done in the excerpt below.]
e.g. for the SATA UAHC_GLB_OOBR register:
union UAHC_GBL_OOBR {
uint32_t u;
struct UAHC_GBL_OOBR_s {
#if __BYTE_ORDER == __BIG_ENDIAN
uint32_t we : 1; /**< R/W/H - Write enable. */
uint32_t cwmin : 7; /**< R/W/H - COMWAKE minimum value [...] */ >>>> uint32_t cwmax : 8; /**< R/W/H - COMWAKE maximum value [...] */ >>>> uint32_t cimin : 8; /**< R/W/H - COMINIT minimum value [...] */ >>>> uint32_t cimax : 8; /**< R/W/H - COMINIT maximum value [...] */ >>>> #else
uint32_t cimax : 8;
uint32_t cimin : 8;
uint32_t cwmax : 8;
uint32_t cwmin : 7;
uint32_t we : 1;
#endif
} s;
};
To me it seems kind of goofy to use uint32_t for the bitfields type.
I would just use unsigned, which is just as sure to work as intended,
isn't it?
The SATA hardware register is defined as a 32-bit register in the
SATA specification. Therefore we explicitly declare it as such.
I understand the motivation for using uint32_t for the union member
u. My question is only about the type used for the bitfields. Do
you know of any platform, or even suspect that there might be a
platform, where using 'unsigned' rather than 'uint32_t' for the type
of the bitfields makes any difference at all?
There are other hardware registers in our implementation of the SATA
controller that are defined as 64-bit registers, for those we use
uint64_t (rather than relying on 'unsigned long' for 64-bit linux
or 'unsigned long long' for 32-bit OS - and this code was designed
to be compiled for both 32-bit and 64-bit targets originally).
Sure, for the non-bitfield member. My question is only about
(unsigned) bitfields all of width 8 or less.
I understand the motivation for using uint32_t for the union member
u. My question is only about the type used for the bitfields. Do
you know of any platform, or even suspect that there might be a
platform, where using 'unsigned' rather than 'uint32_t' for the type
of the bitfields makes any difference at all?
scott@slp53.sl.home (Scott Lurndal) writes:
Tim Rentsch <tr.17687@z991.linuxsc.com> writes:
scott@slp53.sl.home (Scott Lurndal) writes:
One might also define data structures for control and status
registers using bitfield structs.
Yeah. This kind of application (among others) I consider one of
the motivating forces behind bitfields.
[Some whitespace trimming done in the excerpt below.]
e.g. for the SATA UAHC_GLB_OOBR register:
union UAHC_GBL_OOBR {
uint32_t u;
struct UAHC_GBL_OOBR_s {
#if __BYTE_ORDER == __BIG_ENDIAN
uint32_t we : 1; /**< R/W/H - Write enable. */
uint32_t cwmin : 7; /**< R/W/H - COMWAKE minimum value [...] */
uint32_t cwmax : 8; /**< R/W/H - COMWAKE maximum value [...] */
uint32_t cimin : 8; /**< R/W/H - COMINIT minimum value [...] */
uint32_t cimax : 8; /**< R/W/H - COMINIT maximum value [...] */
#else
uint32_t cimax : 8;
uint32_t cimin : 8;
uint32_t cwmax : 8;
uint32_t cwmin : 7;
uint32_t we : 1;
#endif
} s;
};
To me it seems kind of goofy to use uint32_t for the bitfields type.
I would just use unsigned, which is just as sure to work as intended,
isn't it?
The SATA hardware register is defined as a 32-bit register in the
SATA specification. Therefore we explicitly declare it as such.
I understand the motivation for using uint32_t for the union member
u. My question is only about the type used for the bitfields. Do
you know of any platform, or even suspect that there might be a
platform, where using 'unsigned' rather than 'uint32_t' for the type
of the bitfields makes any difference at all?
On 15/08/2026 3:51 AM, Tim Rentsch wrote:
scott@slp53.sl.home (Scott Lurndal) writes:
Tim Rentsch <tr.17687@z991.linuxsc.com> writes:
scott@slp53.sl.home (Scott Lurndal) writes:
One might also define data structures for control and status
registers using bitfield structs.
Yeah.ÿ This kind of application (among others) I consider one of
the motivating forces behind bitfields.
[Some whitespace trimming done in the excerpt below.]
e.g. for the SATA UAHC_GLB_OOBR register:
union UAHC_GBL_OOBR {
ÿÿ uint32_t u;
ÿÿ struct UAHC_GBL_OOBR_s {
#if __BYTE_ORDER == __BIG_ENDIAN
ÿÿÿÿ uint32_t weÿÿÿÿ :ÿ 1; /**< R/W/H - Write enable. */
ÿÿÿÿ uint32_t cwminÿ :ÿ 7; /**< R/W/H - COMWAKE minimum value [...] */ >>>>> ÿÿÿÿ uint32_t cwmaxÿ :ÿ 8; /**< R/W/H - COMWAKE maximum value [...] */ >>>>> ÿÿÿÿ uint32_t ciminÿ :ÿ 8; /**< R/W/H - COMINIT minimum value [...] */ >>>>> ÿÿÿÿ uint32_t cimaxÿ :ÿ 8; /**< R/W/H - COMINIT maximum value [...] */ >>>>> #else
ÿÿÿÿ uint32_t cimaxÿ :ÿ 8;
ÿÿÿÿ uint32_t ciminÿ :ÿ 8;
ÿÿÿÿ uint32_t cwmaxÿ :ÿ 8;
ÿÿÿÿ uint32_t cwminÿ :ÿ 7;
ÿÿÿÿ uint32_t weÿÿÿÿ :ÿ 1;
#endif
ÿÿ } s;
};
To me it seems kind of goofy to use uint32_t for the bitfields type.
I would just use unsigned, which is just as sure to work as intended,
isn't it?
The SATA hardware register is defined as a 32-bit register in the
SATA specification.ÿ Therefore we explicitly declare it as such.
I understand the motivation for using uint32_t for the union member
u.ÿ My question is only about the type used for the bitfields.ÿ Do
you know of any platform, or even suspect that there might be a
platform, where using 'unsigned' rather than 'uint32_t' for the type
of the bitfields makes any difference at all?
Yes, people still code real mode DOS for fun and amusement.ÿ Not to
mention boot strapping code for /real operating systems/, for some value
of /real/.
On 6502, int is 16bit, I believe, for reasons.ÿ And I also believe it
makes total sense to keep int 16bit on a 68000.
There are other hardware registers in our implementation of the SATA
controller that are defined as 64-bit registers, for those we use
uint64_t (rather than relying on 'unsigned long' for 64-bit linux
or 'unsigned long long' for 32-bit OS - and this code was designed
to be compiled for both 32-bit and 64-bit targets originally).
Sure, for the non-bitfield member.ÿ My question is only about
(unsigned) bitfields all of width 8 or less.
I'm ignorant of the prior discussion, so I'll stop now; happy retro-
coding!
Tim Rentsch <tr.17687@z991.linuxsc.com> writes:
scott@slp53.sl.home (Scott Lurndal) writes:
Tim Rentsch <tr.17687@z991.linuxsc.com> writes:
scott@slp53.sl.home (Scott Lurndal) writes:
One might also define data structures for control and status
registers using bitfield structs.
Yeah. This kind of application (among others) I consider one of
the motivating forces behind bitfields.
[Some whitespace trimming done in the excerpt below.]
e.g. for the SATA UAHC_GLB_OOBR register:
union UAHC_GBL_OOBR {
uint32_t u;
struct UAHC_GBL_OOBR_s {
#if __BYTE_ORDER == __BIG_ENDIAN
uint32_t we : 1; /**< R/W/H - Write enable. */
uint32_t cwmin : 7; /**< R/W/H - COMWAKE minimum value
[...] */ uint32_t cwmax : 8; /**< R/W/H - COMWAKE maximum
value [...] */ uint32_t cimin : 8; /**< R/W/H - COMINIT
minimum value [...] */ uint32_t cimax : 8; /**< R/W/H -
COMINIT maximum value [...] */ #else
uint32_t cimax : 8;
uint32_t cimin : 8;
uint32_t cwmax : 8;
uint32_t cwmin : 7;
uint32_t we : 1;
#endif
} s;
};
To me it seems kind of goofy to use uint32_t for the bitfields
type. I would just use unsigned, which is just as sure to work as
intended, isn't it?
The SATA hardware register is defined as a 32-bit register in the
SATA specification. Therefore we explicitly declare it as such.
I understand the motivation for using uint32_t for the union member
u. My question is only about the type used for the bitfields. Do
you know of any platform, or even suspect that there might be a
platform, where using 'unsigned' rather than 'uint32_t' for the type
of the bitfields makes any difference at all?
I haven't canvassed all the available platforms, and don't have
any desire so to do. In my opinion, using the same type for the
bitfield members as was used for the corresponding union
element is simply logical. If we declare the integer part
of the union as uint64_t, we use the same time for the
bitfields (and yes, we could have used unsigned long
(or unsigned long long on the micky OS) - uint64_t
is less typing.
On Fri, 14 Aug 2026 21:42:38 GMT
scott@slp53.sl.home (Scott Lurndal) wrote:
Tim Rentsch <tr.17687@z991.linuxsc.com> writes:
scott@slp53.sl.home (Scott Lurndal) writes:
Tim Rentsch <tr.17687@z991.linuxsc.com> writes:
scott@slp53.sl.home (Scott Lurndal) writes:
One might also define data structures for control and status
registers using bitfield structs.
Yeah. This kind of application (among others) I consider one of
the motivating forces behind bitfields.
[Some whitespace trimming done in the excerpt below.]
e.g. for the SATA UAHC_GLB_OOBR register:
union UAHC_GBL_OOBR {
uint32_t u;
struct UAHC_GBL_OOBR_s {
#if __BYTE_ORDER == __BIG_ENDIAN
uint32_t we : 1; /**< R/W/H - Write enable. */
uint32_t cwmin : 7; /**< R/W/H - COMWAKE minimum value
[...] */ uint32_t cwmax : 8; /**< R/W/H - COMWAKE maximum
value [...] */ uint32_t cimin : 8; /**< R/W/H - COMINIT
minimum value [...] */ uint32_t cimax : 8; /**< R/W/H -
COMINIT maximum value [...] */ #else
uint32_t cimax : 8;
uint32_t cimin : 8;
uint32_t cwmax : 8;
uint32_t cwmin : 7;
uint32_t we : 1;
#endif
} s;
};
To me it seems kind of goofy to use uint32_t for the bitfields
type. I would just use unsigned, which is just as sure to work as
intended, isn't it?
The SATA hardware register is defined as a 32-bit register in the
SATA specification. Therefore we explicitly declare it as such.
I understand the motivation for using uint32_t for the union member
u. My question is only about the type used for the bitfields. Do
you know of any platform, or even suspect that there might be a
platform, where using 'unsigned' rather than 'uint32_t' for the type
of the bitfields makes any difference at all?
I haven't canvassed all the available platforms, and don't have
any desire so to do. In my opinion, using the same type for the
bitfield members as was used for the corresponding union
element is simply logical. If we declare the integer part
of the union as uint64_t, we use the same time for the
bitfields (and yes, we could have used unsigned long
(or unsigned long long on the micky OS) - uint64_t
is less typing.
Why not plain 'unsigned' ?
Michael S <already5chosen@yahoo.com> writes:
On Fri, 14 Aug 2026 21:42:38 GMT
scott@slp53.sl.home (Scott Lurndal) wrote:
Tim Rentsch <tr.17687@z991.linuxsc.com> writes:
scott@slp53.sl.home (Scott Lurndal) writes:
Tim Rentsch <tr.17687@z991.linuxsc.com> writes:
scott@slp53.sl.home (Scott Lurndal) writes:
One might also define data structures for control and status
registers using bitfield structs.
Yeah. This kind of application (among others) I consider one
of the motivating forces behind bitfields.
[Some whitespace trimming done in the excerpt below.]
e.g. for the SATA UAHC_GLB_OOBR register:
union UAHC_GBL_OOBR {
uint32_t u;
struct UAHC_GBL_OOBR_s {
#if __BYTE_ORDER == __BIG_ENDIAN
uint32_t we : 1; /**< R/W/H - Write enable. */
uint32_t cwmin : 7; /**< R/W/H - COMWAKE minimum value
[...] */ uint32_t cwmax : 8; /**< R/W/H - COMWAKE maximum
value [...] */ uint32_t cimin : 8; /**< R/W/H - COMINIT
minimum value [...] */ uint32_t cimax : 8; /**< R/W/H -
COMINIT maximum value [...] */ #else
uint32_t cimax : 8;
uint32_t cimin : 8;
uint32_t cwmax : 8;
uint32_t cwmin : 7;
uint32_t we : 1;
#endif
} s;
};
To me it seems kind of goofy to use uint32_t for the bitfields
type. I would just use unsigned, which is just as sure to work
as intended, isn't it?
The SATA hardware register is defined as a 32-bit register in
the SATA specification. Therefore we explicitly declare it as
such.
I understand the motivation for using uint32_t for the union
member u. My question is only about the type used for the
bitfields. Do you know of any platform, or even suspect that
there might be a platform, where using 'unsigned' rather than
'uint32_t' for the type of the bitfields makes any difference at
all?
I haven't canvassed all the available platforms, and don't have
any desire so to do. In my opinion, using the same type for the
bitfield members as was used for the corresponding union
element is simply logical. If we declare the integer part
of the union as uint64_t, we use the same time for the
bitfields (and yes, we could have used unsigned long
(or unsigned long long on the micky OS) - uint64_t
is less typing.
Why not plain 'unsigned' ?
Did you not read the paragraph you are responding to?
Tim Rentsch <tr.17687@z991.linuxsc.com> writes:
scott@slp53.sl.home (Scott Lurndal) writes:
Tim Rentsch <tr.17687@z991.linuxsc.com> writes:
scott@slp53.sl.home (Scott Lurndal) writes:
One might also define data structures for control and status
registers using bitfield structs.
Yeah. This kind of application (among others) I consider one of
the motivating forces behind bitfields.
[Some whitespace trimming done in the excerpt below.]
e.g. for the SATA UAHC_GLB_OOBR register:
union UAHC_GBL_OOBR {
uint32_t u;
struct UAHC_GBL_OOBR_s {
#if __BYTE_ORDER == __BIG_ENDIAN
uint32_t we : 1; /**< R/W/H - Write enable. */
uint32_t cwmin : 7; /**< R/W/H - COMWAKE minimum value [...] */ >>>>> uint32_t cwmax : 8; /**< R/W/H - COMWAKE maximum value [...] */ >>>>> uint32_t cimin : 8; /**< R/W/H - COMINIT minimum value [...] */ >>>>> uint32_t cimax : 8; /**< R/W/H - COMINIT maximum value [...] */ >>>>> #else
uint32_t cimax : 8;
uint32_t cimin : 8;
uint32_t cwmax : 8;
uint32_t cwmin : 7;
uint32_t we : 1;
#endif
} s;
};
To me it seems kind of goofy to use uint32_t for the bitfields type.
I would just use unsigned, which is just as sure to work as intended,
isn't it?
The SATA hardware register is defined as a 32-bit register in the
SATA specification. Therefore we explicitly declare it as such.
I understand the motivation for using uint32_t for the union member
u. My question is only about the type used for the bitfields. Do
you know of any platform, or even suspect that there might be a
platform, where using 'unsigned' rather than 'uint32_t' for the type
of the bitfields makes any difference at all?
I haven't canvassed all the available platforms, and don't have
any desire so to do. In my opinion, using the same type for the
bitfield members as was used for the corresponding union
element is simply logical. If we declare the integer part
of the union as uint64_t, we use the same time for the
bitfields (and yes, we could have used unsigned long
(or unsigned long long on the micky OS) - uint64_t
is less typing.
Tim Rentsch <tr.17687@z991.linuxsc.com> writes:
scott@slp53.sl.home (Scott Lurndal) writes:
Tim Rentsch <tr.17687@z991.linuxsc.com> writes:
scott@slp53.sl.home (Scott Lurndal) writes:
One might also define data structures for control and status
registers using bitfield structs.
Yeah. This kind of application (among others) I consider one of
the motivating forces behind bitfields.
[Some whitespace trimming done in the excerpt below.]
e.g. for the SATA UAHC_GLB_OOBR register:
union UAHC_GBL_OOBR {
uint32_t u;
struct UAHC_GBL_OOBR_s {
#if __BYTE_ORDER == __BIG_ENDIAN
uint32_t we : 1; /**< R/W/H - Write enable. */
uint32_t cwmin : 7; /**< R/W/H - COMWAKE minimum value [...] */ >>>>> uint32_t cwmax : 8; /**< R/W/H - COMWAKE maximum value [...] */ >>>>> uint32_t cimin : 8; /**< R/W/H - COMINIT minimum value [...] */ >>>>> uint32_t cimax : 8; /**< R/W/H - COMINIT maximum value [...] */ >>>>> #else
uint32_t cimax : 8;
uint32_t cimin : 8;
uint32_t cwmax : 8;
uint32_t cwmin : 7;
uint32_t we : 1;
#endif
} s;
};
To me it seems kind of goofy to use uint32_t for the bitfields type.
I would just use unsigned, which is just as sure to work as intended,
isn't it?
The SATA hardware register is defined as a 32-bit register in the
SATA specification. Therefore we explicitly declare it as such.
I understand the motivation for using uint32_t for the union member
u. My question is only about the type used for the bitfields. Do
you know of any platform, or even suspect that there might be a
platform, where using 'unsigned' rather than 'uint32_t' for the type
of the bitfields makes any difference at all?
I haven't canvassed all the available platforms, and don't have
any desire so to do. In my opinion, using the same type for the
bitfield members as was used for the corresponding union
element is simply logical. If we declare the integer part
of the union as uint64_t, we use the same time for the
bitfields (and yes, we could have used unsigned long
(or unsigned long long on the micky OS) - uint64_t
is less typing.
On 14/08/2026 22:02, Johann 'Myrkraverk' Oskarsson wrote:
On 15/08/2026 3:51 AM, Tim Rentsch wrote:
scott@slp53.sl.home (Scott Lurndal) writes:
Tim Rentsch <tr.17687@z991.linuxsc.com> writes:
scott@slp53.sl.home (Scott Lurndal) writes:
One might also define data structures for control and status
registers using bitfield structs.
Yeah.ÿ This kind of application (among others) I consider one of
the motivating forces behind bitfields.
[Some whitespace trimming done in the excerpt below.]
e.g. for the SATA UAHC_GLB_OOBR register:
union UAHC_GBL_OOBR {
ÿÿ uint32_t u;
ÿÿ struct UAHC_GBL_OOBR_s {
#if __BYTE_ORDER == __BIG_ENDIAN
ÿÿÿÿ uint32_t weÿÿÿÿ :ÿ 1; /**< R/W/H - Write enable. */
ÿÿÿÿ uint32_t cwminÿ :ÿ 7; /**< R/W/H - COMWAKE minimum value
[...] */
ÿÿÿÿ uint32_t cwmaxÿ :ÿ 8; /**< R/W/H - COMWAKE maximum value
[...] */
ÿÿÿÿ uint32_t ciminÿ :ÿ 8; /**< R/W/H - COMINIT minimum value
[...] */
ÿÿÿÿ uint32_t cimaxÿ :ÿ 8; /**< R/W/H - COMINIT maximum value
[...] */
#else
ÿÿÿÿ uint32_t cimaxÿ :ÿ 8;
ÿÿÿÿ uint32_t ciminÿ :ÿ 8;
ÿÿÿÿ uint32_t cwmaxÿ :ÿ 8;
ÿÿÿÿ uint32_t cwminÿ :ÿ 7;
ÿÿÿÿ uint32_t weÿÿÿÿ :ÿ 1;
#endif
ÿÿ } s;
};
To me it seems kind of goofy to use uint32_t for the bitfields type. >>>>> I would just use unsigned, which is just as sure to work as intended, >>>>> isn't it?
The SATA hardware register is defined as a 32-bit register in the
SATA specification.ÿ Therefore we explicitly declare it as such.
I understand the motivation for using uint32_t for the union member
u.ÿ My question is only about the type used for the bitfields.ÿ Do
you know of any platform, or even suspect that there might be a
platform, where using 'unsigned' rather than 'uint32_t' for the type
of the bitfields makes any difference at all?
Yes, people still code real mode DOS for fun and amusement.ÿ Not to
mention boot strapping code for /real operating systems/, for some value
of /real/.
On 6502, int is 16bit, I believe, for reasons.ÿ And I also believe it
makes total sense to keep int 16bit on a 68000.
WTF are you on about? If you're an actual human then I suggest getting
some help. If not then where the hell does all this bilge come from?
There are other hardware registers in our implementation of the SATA
controller that are defined as 64-bit registers, for those we use
uint64_t (rather than relying on 'unsigned long' for 64-bit linux
or 'unsigned long long' for 32-bit OS - and this code was designed
to be compiled for both 32-bit and 64-bit targets originally).
Sure, for the non-bitfield member.ÿ My question is only about
(unsigned) bitfields all of width 8 or less.
I'm ignorant of the prior discussion, so I'll stop now; happy retro-
coding!
'Happy' - OK, CMT has finally convinced me!
On Sat, 15 Aug 2026 19:39:54 GMT
scott@slp53.sl.home (Scott Lurndal) wrote:
Michael S <already5chosen@yahoo.com> writes:
On Fri, 14 Aug 2026 21:42:38 GMT
scott@slp53.sl.home (Scott Lurndal) wrote:
Tim Rentsch <tr.17687@z991.linuxsc.com> writes:
scott@slp53.sl.home (Scott Lurndal) writes:
Tim Rentsch <tr.17687@z991.linuxsc.com> writes:
scott@slp53.sl.home (Scott Lurndal) writes:
One might also define data structures for control and status
registers using bitfield structs.
Yeah. This kind of application (among others) I consider one
of the motivating forces behind bitfields.
[Some whitespace trimming done in the excerpt below.]
e.g. for the SATA UAHC_GLB_OOBR register:
union UAHC_GBL_OOBR {
uint32_t u;
struct UAHC_GBL_OOBR_s {
#if __BYTE_ORDER == __BIG_ENDIAN
uint32_t we : 1; /**< R/W/H - Write enable. */
uint32_t cwmin : 7; /**< R/W/H - COMWAKE minimum value
[...] */ uint32_t cwmax : 8; /**< R/W/H - COMWAKE maximum
value [...] */ uint32_t cimin : 8; /**< R/W/H - COMINIT
minimum value [...] */ uint32_t cimax : 8; /**< R/W/H -
COMINIT maximum value [...] */ #else
uint32_t cimax : 8;
uint32_t cimin : 8;
uint32_t cwmax : 8;
uint32_t cwmin : 7;
uint32_t we : 1;
#endif
} s;
};
To me it seems kind of goofy to use uint32_t for the bitfields
type. I would just use unsigned, which is just as sure to work
as intended, isn't it?
The SATA hardware register is defined as a 32-bit register in
the SATA specification. Therefore we explicitly declare it as
such.
I understand the motivation for using uint32_t for the union
member u. My question is only about the type used for the
bitfields. Do you know of any platform, or even suspect that
there might be a platform, where using 'unsigned' rather than
'uint32_t' for the type of the bitfields makes any difference at
all?
I haven't canvassed all the available platforms, and don't have
any desire so to do. In my opinion, using the same type for the
bitfield members as was used for the corresponding union
element is simply logical. If we declare the integer part
of the union as uint64_t, we use the same time for the
bitfields (and yes, we could have used unsigned long
(or unsigned long long on the micky OS) - uint64_t
is less typing.
Why not plain 'unsigned' ?
Did you not read the paragraph you are responding to?
I missed the part about "using the same type". Sorry.
Now, when I read it ... no, I don't think that it is logical.
Michael S <already5chosen@yahoo.com> writes:[...]
On Sat, 15 Aug 2026 19:39:54 GMT
scott@slp53.sl.home (Scott Lurndal) wrote:
Michael S <already5chosen@yahoo.com> writes:
Why not plain 'unsigned' ?
Did you not read the paragraph you are responding to?
I missed the part about "using the same type". Sorry.
Now, when I read it ... no, I don't think that it is logical.
Using unsigned for the bitfields wouldn't work properly
if the modeled register is 64 bits and any of the fields
are more than 32 bits in size.
I've never liked using unadorned 'unsigned' in C.
scott@slp53.sl.home (Scott Lurndal) writes:
Tim Rentsch <tr.17687@z991.linuxsc.com> writes:
scott@slp53.sl.home (Scott Lurndal) writes:
Tim Rentsch <tr.17687@z991.linuxsc.com> writes:
scott@slp53.sl.home (Scott Lurndal) writes:
One might also define data structures for control and status
registers using bitfield structs.
Yeah. This kind of application (among others) I consider one of
the motivating forces behind bitfields.
[Some whitespace trimming done in the excerpt below.]
e.g. for the SATA UAHC_GLB_OOBR register:
union UAHC_GBL_OOBR {
uint32_t u;
struct UAHC_GBL_OOBR_s {
#if __BYTE_ORDER == __BIG_ENDIAN
uint32_t we : 1; /**< R/W/H - Write enable. */
uint32_t cwmin : 7; /**< R/W/H - COMWAKE minimum value [...] */ >>>>>> uint32_t cwmax : 8; /**< R/W/H - COMWAKE maximum value [...] */ >>>>>> uint32_t cimin : 8; /**< R/W/H - COMINIT minimum value [...] */ >>>>>> uint32_t cimax : 8; /**< R/W/H - COMINIT maximum value [...] */ >>>>>> #else
uint32_t cimax : 8;
uint32_t cimin : 8;
uint32_t cwmax : 8;
uint32_t cwmin : 7;
uint32_t we : 1;
#endif
} s;
};
To me it seems kind of goofy to use uint32_t for the bitfields type. >>>>> I would just use unsigned, which is just as sure to work as intended, >>>>> isn't it?
The SATA hardware register is defined as a 32-bit register in the
SATA specification. Therefore we explicitly declare it as such.
I understand the motivation for using uint32_t for the union member
u. My question is only about the type used for the bitfields. Do
you know of any platform, or even suspect that there might be a
platform, where using 'unsigned' rather than 'uint32_t' for the type
of the bitfields makes any difference at all?
I haven't canvassed all the available platforms, and don't have
any desire so to do. In my opinion, using the same type for the
bitfield members as was used for the corresponding union
element is simply logical. If we declare the integer part
of the union as uint64_t, we use the same time for the
bitfields (and yes, we could have used unsigned long
(or unsigned long long on the micky OS) - uint64_t
is less typing.
To me it seems more logical to use the smallest basic type that
suffices for the width of the associated bit-field, assuming
the compiler allows it, or 'unsigned' for compilers that don't
provide those extensions.
scott@slp53.sl.home (Scott Lurndal) writes:
Tim Rentsch <tr.17687@z991.linuxsc.com> writes:
scott@slp53.sl.home (Scott Lurndal) writes:
Tim Rentsch <tr.17687@z991.linuxsc.com> writes:
scott@slp53.sl.home (Scott Lurndal) writes:
One might also define data structures for control and status
registers using bitfield structs.
Yeah. This kind of application (among others) I consider one of
the motivating forces behind bitfields.
[Some whitespace trimming done in the excerpt below.]
e.g. for the SATA UAHC_GLB_OOBR register:
union UAHC_GBL_OOBR {
uint32_t u;
struct UAHC_GBL_OOBR_s {
#if __BYTE_ORDER == __BIG_ENDIAN
uint32_t we : 1; /**< R/W/H - Write enable. */
uint32_t cwmin : 7; /**< R/W/H - COMWAKE minimum value [...] */ >>>>>> uint32_t cwmax : 8; /**< R/W/H - COMWAKE maximum value [...] */ >>>>>> uint32_t cimin : 8; /**< R/W/H - COMINIT minimum value [...] */ >>>>>> uint32_t cimax : 8; /**< R/W/H - COMINIT maximum value [...] */ >>>>>> #else
uint32_t cimax : 8;
uint32_t cimin : 8;
uint32_t cwmax : 8;
uint32_t cwmin : 7;
uint32_t we : 1;
#endif
} s;
};
To me it seems kind of goofy to use uint32_t for the bitfields type. >>>>> I would just use unsigned, which is just as sure to work as intended, >>>>> isn't it?
The SATA hardware register is defined as a 32-bit register in the
SATA specification. Therefore we explicitly declare it as such.
I understand the motivation for using uint32_t for the union member
u. My question is only about the type used for the bitfields. Do
you know of any platform, or even suspect that there might be a
platform, where using 'unsigned' rather than 'uint32_t' for the type
of the bitfields makes any difference at all?
I haven't canvassed all the available platforms, and don't have
any desire so to do. In my opinion, using the same type for the
bitfield members as was used for the corresponding union
element is simply logical. If we declare the integer part
of the union as uint64_t, we use the same time for the
bitfields (and yes, we could have used unsigned long
(or unsigned long long on the micky OS) - uint64_t
is less typing.
To me it seems more logical to use the smallest basic type that
suffices for the width of the associated bit-field, assuming
the compiler allows it, or 'unsigned' for compilers that don't
provide those extensions.
I've never liked using unadorned 'unsigned' in C.
scott@slp53.sl.home (Scott Lurndal) writes:
I've never liked using unadorned 'unsigned' in C.
Can you say why that is? Do you also, for example, never
use 'long' but always use 'long int'?
scott@slp53.sl.home (Scott Lurndal) writes:
I've never liked using unadorned 'unsigned' in C.
Can you say why that is?
Do you also, for example, never
use 'long' but always use 'long int'?
On 23/08/2026 16:56, Tim Rentsch wrote:
scott@slp53.sl.home (Scott Lurndal) writes:
I've never liked using unadorned 'unsigned' in C.
Can you say why that is? Do you also, for example, never
use 'long' but always use 'long int'?
For me, personally, it simply sounds like poor grammar to use a
standalone adjective instead of a noun. If I see "unsigned" or "long",
I am thinking "unsigned /what/ ?" "long /what/ ?". Of course I know
what these mean when I read them in C code, but it just looks and feels
ugly and incomplete.
Tim Rentsch <tr.17687@z991.linuxsc.com> wrote:
[on deciding which type to use for a bit-field member]
To me it seems more logical to use the smallest basic type that
suffices for the width of the associated bit-field, assuming
the compiler allows it, or 'unsigned' for compilers that don't
provide those extensions.
Conider the following two structs:
typedef struct {char a:5; char b:5; char c:5;} bf1;
typedef struct {short a:5; short b:5; short c:5;} bf2;
gcc allocates 3 bytes to first one and 2 bytes for the second one.
Bitfields are frequently used to converve memory and the second
one is better in this aspect. So it is hard the avoid notion
of storage unit and using type to control size of storage unit.
Of course, if you can not count on compiler behaving in specific
way, abd you can not tolerate different behaviour, then it is better
to use access if given needed size and masks and shifts to access
the bits.
antispam@fricas.org (Waldek Hebisch) writes:
Tim Rentsch <tr.17687@z991.linuxsc.com> wrote:
[on deciding which type to use for a bit-field member]
To me it seems more logical to use the smallest basic type that
suffices for the width of the associated bit-field, assuming
the compiler allows it, or 'unsigned' for compilers that don't
provide those extensions.
Conider the following two structs:
typedef struct {char a:5; char b:5; char c:5;} bf1;
typedef struct {short a:5; short b:5; short c:5;} bf2;
gcc allocates 3 bytes to first one and 2 bytes for the second one.
That's interesting; thank you for the research. I wouldn't
expect code to use char for a bit-field type but presumably
unsigned char or signed char would give the same result.
Bitfields are frequently used to converve memory and the second
one is better in this aspect. So it is hard the avoid notion
of storage unit and using type to control size of storage unit.
In the early days of C conserving space may have been a common
consideration. These days I expect it hardly ever is, except
perhaps in the case of lots of _Bool bit-fields.
Furthermore there are advantages to using a type where the
members occupy separate bytes rather than being packed into a
single 16-bit object. The generated code may be better. Also
using a single byte for each member reduces the change of
undefined behavior when accessing these bit-fields.
On 23/08/2026 16:56, Tim Rentsch wrote:
scott@slp53.sl.home (Scott Lurndal) writes:
I've never liked using unadorned 'unsigned' in C.
Can you say why that is?ÿ Do you also, for example, never
use 'long' but always use 'long int'?
For me, personally, it simply sounds like poor grammar to use a
standalone adjective instead of a noun.ÿ If I see "unsigned" or "long",
I am thinking "unsigned /what/ ?"ÿ "long /what/ ?".ÿ Of course I know
what these mean when I read them in C code, but it just looks and feels
ugly and incomplete.
On 8/23/2026 8:37 AM, David Brown wrote:
On 23/08/2026 16:56, Tim Rentsch wrote:
scott@slp53.sl.home (Scott Lurndal) writes:
I've never liked using unadorned 'unsigned' in C.
Can you say why that is?ÿ Do you also, for example, never
use 'long' but always use 'long int'?
For me, personally, it simply sounds like poor grammar to use a
standalone adjective instead of a noun.ÿ If I see "unsigned" or
"long", I am thinking "unsigned /what/ ?"ÿ "long /what/ ?".ÿ Of course
I know what these mean when I read them in C code, but it just looks
and feels ugly and incomplete.
long is fine with me. well, signed long? ;^)
Tim Rentsch <tr.17687@z991.linuxsc.com> wrote:
antispam@fricas.org (Waldek Hebisch) writes:
Tim Rentsch <tr.17687@z991.linuxsc.com> wrote:
[on deciding which type to use for a bit-field member]
To me it seems more logical to use the smallest basic type that
suffices for the width of the associated bit-field, assuming
the compiler allows it, or 'unsigned' for compilers that don't
provide those extensions.
Conider the following two structs:
typedef struct {char a:5; char b:5; char c:5;} bf1;
typedef struct {short a:5; short b:5; short c:5;} bf2;
gcc allocates 3 bytes to first one and 2 bytes for the second one.
That's interesting; thank you for the research. I wouldn't
expect code to use char for a bit-field type but presumably
unsigned char or signed char would give the same result.
Yes, the same result.
Bitfields are frequently used to converve memory and the second
one is better in this aspect. So it is hard the avoid notion
of storage unit and using type to control size of storage unit.
In the early days of C conserving space may have been a common
consideration. These days I expect it hardly ever is, except
perhaps in the case of lots of _Bool bit-fields.
Maybe people care less on total memory use, but is rather common
to care about speed. And experience shows that small, tightly
packed data structures frequently lead to faster code.
Furthermore there are advantages to using a type where the
members occupy separate bytes rather than being packed into a
single 16-bit object. The generated code may be better. Also
using a single byte for each member reduces the change of
undefined behavior when accessing these bit-fields.
But why use bitfields in such case? AFAICS when there is a single
bitfield in a byte gcc still is masking and extracting the
field. And write operation produces full read-modify-write
seqence. So using appropriate variant of char would reduce
number of instructions.
Concerning generated code, on reasonably big machines I would
expect 32-bit access to be quite efficient and on 64-bit machines
64-bit access is likely to be quite efficient. 8-bit versus
16-bit access is going to be quite machine specific.
Tim Rentsch <tr.17687@z991.linuxsc.com> writes:
scott@slp53.sl.home (Scott Lurndal) writes:
I've never liked using unadorned 'unsigned' in C.
Can you say why that is?
Because I consider it a qualifier rather than a type,
regardless of how the language defines it. A personal
quirk, if you will.
Tim Rentsch <tr.17687@z991.linuxsc.com> writes:
scott@slp53.sl.home (Scott Lurndal) writes:
I've never liked using unadorned 'unsigned' in C.
Can you say why that is?
Because I consider it a qualifier rather than a type,
regardless of how the language defines it. A personal
quirk, if you will.
Do you also, for example, never
use 'long' but always use 'long int'?
{sentence moved to later} I also consider 'long' a qualifier,
so yes, I would use 'long int' (or long long) if necessary.
{moved here} Actually, 99.9% of the time, I use <stdint.h>
types rather than the core C types.
Note that I exclusively program at very low levels for
operating system code, hypervisor code and various
simulators where matching the hardware characteristics
is key.
Tim Rentsch <tr.17687@z991.linuxsc.com> wrote:
antispam@fricas.org (Waldek Hebisch) writes:
Tim Rentsch <tr.17687@z991.linuxsc.com> wrote:
[on deciding which type to use for a bit-field member]
To me it seems more logical to use the smallest basic type that
suffices for the width of the associated bit-field, assuming
the compiler allows it, or 'unsigned' for compilers that don't
provide those extensions.
Conider the following two structs:
typedef struct {char a:5; char b:5; char c:5;} bf1;
typedef struct {short a:5; short b:5; short c:5;} bf2;
gcc allocates 3 bytes to first one and 2 bytes for the second one.
That's interesting; thank you for the research. I wouldn't
expect code to use char for a bit-field type but presumably
unsigned char or signed char would give the same result.
Yes, the same result.
Bitfields are frequently used to converve memory and the second
one is better in this aspect. So it is hard the avoid notion
of storage unit and using type to control size of storage unit.
In the early days of C conserving space may have been a common
consideration. These days I expect it hardly ever is, except
perhaps in the case of lots of _Bool bit-fields.
Maybe people care less on total memory use, but is rather common
to care about speed. And experience shows that small, tightly
packed data structures frequently lead to faster code.
Furthermore there are advantages to using a type where the
members occupy separate bytes rather than being packed into a
single 16-bit object. The generated code may be better. Also
using a single byte for each member reduces the change of
undefined behavior when accessing these bit-fields.
But why use bitfields in such case?
AFAICS when there is a single
bitfield in a byte gcc still is masking and extracting the
field. And write operation produces full read-modify-write
seqence. So using appropriate variant of char would reduce
number of instructions.
Concerning generated code, on reasonably big machines I would
expect 32-bit access to be quite efficient and on 64-bit machines
64-bit access is likely to be quite efficient. 8-bit versus
16-bit access is going to be quite machine specific.
Hey bart! You fucking piece of shit asshole.
AFAICS when there is a single bitfield in a byte gcc still is
masking and extracting the field.
On Sun, 23 Aug 2026 21:22:06 -0000 (UTC), Waldek Hebisch wrote:
AFAICS when there is a single bitfield in a byte gcc still is
masking and extracting the field.
Some instruction sets have, or used to have, instructions for inserting/extracting variable-length bitfields. Not sure if these are
faster than shift/mask, though.
And unlike shift/mask, they are endian-dependent.
On Sun, 23 Aug 2026 21:22:06 -0000 (UTC), Waldek Hebisch wrote:
AFAICS when there is a single bitfield in a byte gcc still is
masking and extracting the field.
Some instruction sets have, or used to have, instructions for inserting/extracting variable-length bitfields. Not sure if these are
faster than shift/mask, though.
Lawrence D?Oliveiro <ldo@nz.invalid> wrote:
On Sun, 23 Aug 2026 21:22:06 -0000 (UTC), Waldek Hebisch wrote:
AFAICS when there is a single bitfield in a byte gcc still is
masking and extracting the field.
Some instruction sets have, or used to have, instructions for
inserting/extracting variable-length bitfields. Not sure if these are
faster than shift/mask, though.
AFAIK no processor that I use have support for variable-length
(or variable position) bitfields. But C bitfields have length
and position known at compile time and what ARM has is enough
to extract or set a bitfield in a register using single
instruction.
Lawrence D?Oliveiro <ldo@nz.invalid> wrote:
On Sun, 23 Aug 2026 21:22:06 -0000 (UTC), Waldek Hebisch wrote:
AFAICS when there is a single bitfield in a byte gcc still is
masking and extracting the field.
Some instruction sets have, or used to have, instructions for
inserting/extracting variable-length bitfields. Not sure if these are
faster than shift/mask, though.
AFAIK no processor that I use have support for variable-length
(or variable position) bitfields. But C bitfields have length
and position known at compile time and what ARM has is enough
to extract or set a bitfield in a register using single
instruction.
On 03/09/2026 21:36, Waldek Hebisch wrote:
Lawrence D?Oliveiro <ldo@nz.invalid> wrote:
On Sun, 23 Aug 2026 21:22:06 -0000 (UTC), Waldek Hebisch wrote:
AFAICS when there is a single bitfield in a byte gcc still is
masking and extracting the field.
Some instruction sets have, or used to have, instructions for
inserting/extracting variable-length bitfields. Not sure if these are
faster than shift/mask, though.
AFAIK no processor that I use have support for variable-length
(or variable position) bitfields. But C bitfields have length
and position known at compile time and what ARM has is enough
to extract or set a bitfield in a register using single
instruction.
Was Lawrence talking about bit-fields whose length is not known at
compile time? I have never come across such a thing - certainly C has
no direct support for it. I suppose you could have a bit array and
views or slices of part of that, but you would presumably have to deal
with slices that do not fit into any containing element. It would be
quite inefficient to deal with such an object, but if it is big enough,
the cache space savings might make it a suitable choice of structure.
| Sysop: | Tetrazocine |
|---|---|
| Location: | Melbourne, VIC, Australia |
| Users: | 9 |
| Nodes: | 8 (0 / 8) |
| Uptime: | 245:25:59 |
| Calls: | 220 |
| Files: | 21,513 |
| Messages: | 83,782 |