aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDavid Brownell <david-b@pacbell.net>2008-07-24 00:30:37 -0400
committerLinus Torvalds <torvalds@linux-foundation.org>2008-07-24 13:47:33 -0400
commitd3de851a445123f24ad8ece18662014b5e8a8b4e (patch)
tree44ef8b43208ba8a071fcd4d4b22e76c55881836d
parent53e84b672c1a8190af2b376c35c7a39cf1214f59 (diff)
rtc: BCD codeshrink
This updates <linux/bcd.h> to define the key routines as constant functions, which the macros will then call. Newer code can now call bcd2bin() instead of SCREAMING BCD2BIN() TO THE FOUR WINDS. This lets each driver shrink their codespace by using N function calls to a single (global) copy of those routines, instead of N inlined copies of these functions per driver. These routines aren't used in speed-critical code. Almost all callers are in the RTC framework. Typical per-driver savings is near 300 bytes. Signed-off-by: David Brownell <dbrownell@users.sourceforge.net> Acked-by: Adrian Bunk <bunk@kernel.org> Cc: Alessandro Zummo <a.zummo@towertech.it> Signed-off-by: Andrew Morton <akpm@linux-foundation.org> Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
-rw-r--r--include/linux/bcd.h9
-rw-r--r--lib/Makefile2
-rw-r--r--lib/bcd.c14
3 files changed, 22 insertions, 3 deletions
diff --git a/include/linux/bcd.h b/include/linux/bcd.h
index c545308125b0..7ac518e3c152 100644
--- a/include/linux/bcd.h
+++ b/include/linux/bcd.h
@@ -10,8 +10,13 @@
10#ifndef _BCD_H 10#ifndef _BCD_H
11#define _BCD_H 11#define _BCD_H
12 12
13#define BCD2BIN(val) (((val) & 0x0f) + ((val)>>4)*10) 13#include <linux/compiler.h>
14#define BIN2BCD(val) ((((val)/10)<<4) + (val)%10) 14
15unsigned bcd2bin(unsigned char val) __attribute_const__;
16unsigned char bin2bcd(unsigned val) __attribute_const__;
17
18#define BCD2BIN(val) bcd2bin(val)
19#define BIN2BCD(val) bin2bcd(val)
15 20
16/* backwards compat */ 21/* backwards compat */
17#define BCD_TO_BIN(val) ((val)=BCD2BIN(val)) 22#define BCD_TO_BIN(val) ((val)=BCD2BIN(val))
diff --git a/lib/Makefile b/lib/Makefile
index 818c4d455518..9085ad6fa53d 100644
--- a/lib/Makefile
+++ b/lib/Makefile
@@ -18,7 +18,7 @@ lib-$(CONFIG_SMP) += cpumask.o
18 18
19lib-y += kobject.o kref.o klist.o 19lib-y += kobject.o kref.o klist.o
20 20
21obj-y += div64.o sort.o parser.o halfmd4.o debug_locks.o random32.o \ 21obj-y += bcd.o div64.o sort.o parser.o halfmd4.o debug_locks.o random32.o \
22 bust_spinlocks.o hexdump.o kasprintf.o bitmap.o scatterlist.o 22 bust_spinlocks.o hexdump.o kasprintf.o bitmap.o scatterlist.o
23 23
24ifeq ($(CONFIG_DEBUG_KOBJECT),y) 24ifeq ($(CONFIG_DEBUG_KOBJECT),y)
diff --git a/lib/bcd.c b/lib/bcd.c
new file mode 100644
index 000000000000..d74257fd0fe7
--- /dev/null
+++ b/lib/bcd.c
@@ -0,0 +1,14 @@
1#include <linux/bcd.h>
2#include <linux/module.h>
3
4unsigned bcd2bin(unsigned char val)
5{
6 return (val & 0x0f) + (val >> 4) * 10;
7}
8EXPORT_SYMBOL(bcd2bin);
9
10unsigned char bin2bcd(unsigned val)
11{
12 return ((val / 10) << 4) + val % 10;
13}
14EXPORT_SYMBOL(bin2bcd);