Hello,
On Mon, 9 Aug 2021, H.J. Lu wrote:
What's the voting status for N2763? I.e. is it perhaps too early to add
it to the psABI, or just the right time?
> +\subsubsection{Optional Fundamental Types of N-bit Integers}
> +
> +\texttt{_BitInt(N)} from ISO/IEC WG14 N2763, where \code{N} is an
> +integral constant expression representing the exact number of bits to
> +be used to represent the type, is a family of integer types.
> +
> +\begin{itemize}
> + \item \texttt{_BitInt(N)} types are signed and unsigned types are
> + \texttt{unsigned _BitInt(N)}.
> + \item \texttt{_BitInt(N)} types are stored in little-endian order in
> + memory.
As this touches bit-fields we probably also need to say something about
how bits are allocated, not just the bytes, maybe just by referring to the
bit-fields section earlier.
> + \item For N <= 64, they have the same size and alignment as
> + the smallest of (signed and unsigned) \code{char}, \code{short},
> + \code{int}, \code{long} and \code{long long} types that can contain
> + them.
> + \item For N > 64, they treated as struct of 64-bit integer
+ "are"
> + chunks. The number of chunks is the smallest number that can contain
> + the type. \texttt{_BitInt(N)} types are bit-aligned to the next
> + greatest power-of-2 up to 64 bits.
I have difficulties to interpret this, also in the N2763 document: apart
from the placement above (the document specifies this also for the smaller
than 64bit type) what is "bit-aligned" supposed to mean, exactly? E.g.
for a _BitInt(4) type, the bit-alignment, as specified, will be 4. The
bit size will be 4 as well (and sizeof will be 1). Of course that's not a
whole byte, which normally is the smallest unit of alignment. So we have
a bit alignment of "4" now, does this mean that two successive fields of
that type will share a byte? What about an array of these types? Can you
or can you not address individual elements of them? (Same question for
address of struct members with these types).
FWIW, I don't see how such bit alignment with the obvious meaning (i.e.
resulting in tight packing) could be implemented: there is a reason why
addresses of bit fields can't be taken, the addresses aren't expressible
in whole units.
So, I think something is amiss with the n2763 document regarding alignment
of _BitInt(N) with N < 8. (For larger BitInts the alignment and size will
always be multiple of 8 bits (in fact always be power of 2 >= 8), so don't
have the issue above).
Ciao,
Michael.