[PATCH] include: introduce byte counting macros. (v2)
Matthias Hopf
mhopf at suse.de
Tue Jun 16 07:27:35 PDT 2009
On Jun 16, 09 22:14:52 +1000, Peter Hutterer wrote:
> On Tue, Jun 16, 2009 at 12:40:56PM +0200, Matthias Hopf wrote:
> > - 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.
>
> there's no particular reason for lowercase other than that I find it a lot
> easier to read code that doesn't scream at me. I'm not too fussed about
Agreed. And as long as macros have no potential bad side effects this is
not an issue at all.
> > - 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()
>
> thanks, that was my biggest grief with the patch. How is:
> num_bytes_for_bits
> num_dwords_for_bytes
> pad_to_dwords
> I think these are more descriptive.
Sounds good :)
> > - 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?)
>
> amended, see below.
> divisions changed to >> 2 and >> 3.
That is actually optimized by current compilers ;-)
But it's better anyway.
> Amended patch below.
+1
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