From: "Robert P. J. Day" <rpjday@crashcourse.ca>
To: Linux Kernel Mailing List <linux-kernel@vger.kernel.org>
Subject: more possible aesthetic cleanup -- *lots* of power of 2 stuff
Date: Wed, 10 Nov 2010 09:56:14 -0500 (EST) [thread overview]
Message-ID: <alpine.DEB.2.00.1011100956060.5730@localhost6.localdomain6> (raw)
following up on jesper's yeoman efforts to tidy up a lot of the
*malloc calls, once upon a time, i whined enough to get the
<linux/log2.h> header file added so that a lot of painful bit tests
for power of 2 could be abbreviated.
the most useful test seems to have been:
static inline __attribute__((const))
bool is_power_of_2(unsigned long n)
{
return (n != 0 && ((n & (n - 1)) == 0));
}
i wrote a short script that looks for various forms of the old power
of 2 tests:
===== start =====
#!/bin/sh
DIR=${1-*}
echo -e " x & (x - 1):\n"
grep -Ern "([^\(\)]+) ?\& ?\(\1 ?- ?1\)" ${DIR}
echo -e " x & ((x) - 1):\n"
grep -Ern "([^\(\)]+) ?\& ?\(\(\1\) ?- ?1\)" ${DIR}
echo -e " (x) & (x - 1):\n"
grep -Ern "\(([^\(\)]+)\) ?\& ?\(\1 ?- ?1\)" ${DIR}
echo -e " (x) & ((x) - 1):\n"
grep -Ern "\(([^\(\)]+)\) ?\& ?\(\(\1\) ?- ?1\)" ${DIR}
===== end =====
and, unsurprisingly, while i once submitted a fair bit of that
cleanup, there's lots left -- just run the script at the top of the
source tree (give an optional subdir to restrict the search). there
are even a few places where code is still defining that test for
itself:
drivers/net/bna/bna.h:50:#define BNA_POWER_OF_2(x) (((x) & ((x) - 1)) == 0)
drivers/net/wireless/rt2x00/rt2x00reg.h:187:#define is_power_of_two(x) ( !((x) & ((x)-1)) )
if anyone wants to run the script on their favourite bit of the
tree, have at it.
rday
p.s. perhaps tests like this could be added to the checkpatch.pl
script. just a thought.
--
========================================================================
Robert P. J. Day Waterloo, Ontario, CANADA
http://crashcourse.ca
Twitter: http://twitter.com/rpjday
LinkedIn: http://ca.linkedin.com/in/rpjday
========================================================================
reply other threads:[~2010-11-10 14:56 UTC|newest]
Thread overview: [no followups] expand[flat|nested] mbox.gz Atom feed
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=alpine.DEB.2.00.1011100956060.5730@localhost6.localdomain6 \
--to=rpjday@crashcourse.ca \
--cc=linux-kernel@vger.kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®