[PATCH] include: introduce byte counting macros.

Matthias Hopf mhopf at suse.de
Tue Jun 16 03:40:56 PDT 2009


On Jun 16, 09 10:56:39 +1000, Peter Hutterer wrote:
> This patch adds the following three macros:
>  count_bytes(bits) - the number of bytes needed to hold 'bits'
>  count_4byte_units(bytes) - the number of 4-byte units to hold 'bytes'
>  pad_to_4(bytes) - the closest multiple of 4 equal to or larger than 'bytes'.

Generally I like abstraction like this.
I only have few minor comments:

- Macros should consist of capital letters - for a reason.
  They tend to behave weird if the arguments are lvalues with side
  effects (like i++). That said, these macros are save.

- The names are not describing. count_bytes() counts bytes, but from
  what? And it actually doesn't count.
  Suggesting something like bytes_needed_for_bits(),
  dwords_needed_for_bytes(), pad_to_dwords()

- pad_to_dwords(bytes) would probably be better (((bytes) + 3) & ~3)
  but that could result in the same code eventually if the compiler is
  smart enough and the code equivalent enough. Which I doubt (negative
  values?)

- They should all explicitly cast to unsigned. But that again makes it
  difficult to use the same macros for different types (32/64). Dunno
  what to do about that :-(
  If they should be able to work with signed values, they will
  definitely be more complex.

CU

Matthias

-- 
Matthias Hopf <mhopf at suse.de>      __        __   __
Maxfeldstr. 5 / 90409 Nuernberg   (_   | |  (_   |__          mat at mshopf.de
Phone +49-911-74053-715           __)  |_|  __)  |__  R & D   www.mshopf.de


More information about the xorg-devel mailing list