[PATCH 01/18] include: introduce byte counting functions.
Peter Hutterer
peter.hutterer at who-t.net
Thu Jul 9 21:34:48 PDT 2009
On Thu, Jul 09, 2009 at 12:54:07PM +0200, David Jander wrote:
> On Thursday 09 July 2009 11:55:11 René Rebe wrote:
> > Peter Hutterer wrote:
> > > On Thu, Jul 09, 2009 at 11:01:54AM +0200, David Jander wrote:
> > >> On Thursday 09 July 2009 02:04:59 Peter Hutterer wrote:
> > >>> This patch adds the following three functions:
> > >>> num_bytes_for_bits(bits) - the number of bytes needed to hold 'bits'
> > >>> num_dwords_for_bytes(bytes) - the number of 4-byte units to hold
> > >>> 'bytes' pad_to_dwords(bytes) - the closest multiple of 4 equal to or
> > >>> larger than 'bytes'.
> > >>
> > >> Sorry to make this probably useless comment about naming, but while a
> > >> byte has a defined length (8 bits), the meaning of "word" and "dword" in
> > >> terms of length is undefined. By definition "word" in computing means
> > >> the natural unit of data used by a particular computer design. This
> > >> would be 32 bits on most 32-bit computers, and by consequence a "dword"
> > >> would be 64 bit wide. Your definition of the names "word" and "dword"
> > >> seem to be 16-bit platform-specific... not the most common platform for
> > >> Xorg!
> > >> Please, let's deprecate this flawed naming convention, and not use it in
> > >> new code... it's confusing and just plain wrong when used on
> > >> platform-independent code!
> > >
> > > This can be changed with a simple search+replace, I wouldn't mind
> > > changing it.
> > >
> > > Please suggest a better alternative naming though, the only appropriate
> > > equivalent I can think of is num_4byte_units_for_bytes and similar which
> > > does make the function names a tad long.
> >
> > ...int8..., ...int16..., ...int32..., ...
>
> I agree. Although in theory 'int8' and 'byte' are of the same length (not
> necessarily same type).
>
> If you want to make the names _really_ short, you might consider the
> convention used in the linux kernel and some other places: u8, s8, u16, s16,
> u32.... etc, very short and still readable ;-)
New patch below, new names are bits_to_bytes, bits_to_int32, pad_to_int32. I
think these are short enough, not as clumsy as the num_a_from_b and int32 is
more precise than dword.
I don't think we need to worry about the size of a byte anymore...
I won't send all new patches since they are just search+replace, if needed
they are available on
git://people.freedesktop.org/~whot/xserver.git bytecounting
Thanks for all the comments, I really didn't think of int32 and the like.
Cheers,
Peter
More information about the xorg-devel
mailing list