mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: David Brownell <david-b@pacbell.net>
To: lkml <linux-kernel@vger.kernel.org>
Cc: rtc-linux@googlegroups.com
Subject: [patch 2.6.26-rc7] <linux/bcd.h> space reduction
Date: Sun, 22 Jun 2008 19:54:36 -0700	[thread overview]
Message-ID: <200806221954.37088.david-b@pacbell.net> (raw)

This updates <linux/bcd.h> to define the key routines as static
constant functions, which the macros will then call.

In effect this lets each user of these BCD routines shrink their
codespace, when GCC observes that's a win, by using N function calls
and one copy of the routines, instead of N inlined copies of these
constant functions.

These routines aren't used in speed-critical code.  Almost all callers
are from the RTC framework.  Typical per-driver savings top 200 bytes.
On one RTC driver that's almost a 20% reduction in runtime I-space
footprint; for many, closer to 10%; for rtc-cmos it's about 4%.

Signed-off-by: David Brownell <dbrownell@users.sourceforge.net>
---
 include/linux/bcd.h |   16 ++++++++++++++--
 1 file changed, 14 insertions(+), 2 deletions(-)

--- a/include/linux/bcd.h	2008-06-21 22:26:14.000000000 -0700
+++ b/include/linux/bcd.h	2008-06-21 22:37:48.000000000 -0700
@@ -10,8 +10,20 @@
 #ifndef _BCD_H
 #define _BCD_H
 
-#define BCD2BIN(val)	(((val) & 0x0f) + ((val)>>4)*10)
-#define BIN2BCD(val)	((((val)/10)<<4) + (val)%10)
+static int __bcd2bin(u8 val) __attribute_const__ __maybe_unused;
+static int __bcd2bin(u8 val)
+{
+	return (val & 0x0f) + (val >> 4) * 10;
+}
+
+static u8 __bin2bcd(unsigned val) __attribute_const__ __maybe_unused;
+static u8 __bin2bcd(unsigned val)
+{
+	return ((val/10) << 4) + val % 10;
+}
+
+#define BCD2BIN(val)	__bcd2bin(val)
+#define BIN2BCD(val)	__bin2bcd(val)
 
 /* backwards compat */
 #define BCD_TO_BIN(val) ((val)=BCD2BIN(val))

             reply	other threads:[~2008-06-23  2:55 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2008-06-23  2:54 David Brownell [this message]
2008-06-23  6:50 ` Adrian Bunk
2008-06-23  7:15   ` David Brownell
2008-06-24 21:54     ` Adrian Bunk
2008-06-30  0:41       ` David Brownell
2008-06-30 18:20         ` Adrian Bunk

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=200806221954.37088.david-b@pacbell.net \
    --to=david-b@pacbell.net \
    --cc=linux-kernel@vger.kernel.org \
    --cc=rtc-linux@googlegroups.com \
    /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®