Skip to content

Commit d3de851

Browse files
David Brownelltorvalds
authored andcommitted
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>
1 parent 53e84b6 commit d3de851

3 files changed

Lines changed: 22 additions & 3 deletions

File tree

‎include/linux/bcd.h‎

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,13 @@
1010
#ifndef _BCD_H
1111
#define _BCD_H
1212

13-
#define BCD2BIN(val) (((val) & 0x0f) + ((val)>>4)*10)
14-
#define BIN2BCD(val) ((((val)/10)<<4) + (val)%10)
13+
#include <linux/compiler.h>
14+
15+
unsigned bcd2bin(unsigned char val) __attribute_const__;
16+
unsigned char bin2bcd(unsigned val) __attribute_const__;
17+
18+
#define BCD2BIN(val) bcd2bin(val)
19+
#define BIN2BCD(val) bin2bcd(val)
1520

1621
/* backwards compat */
1722
#define BCD_TO_BIN(val) ((val)=BCD2BIN(val))

‎lib/Makefile‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ lib-$(CONFIG_SMP) += cpumask.o
1818

1919
lib-y += kobject.o kref.o klist.o
2020

21-
obj-y += div64.o sort.o parser.o halfmd4.o debug_locks.o random32.o \
21+
obj-y += bcd.o div64.o sort.o parser.o halfmd4.o debug_locks.o random32.o \
2222
bust_spinlocks.o hexdump.o kasprintf.o bitmap.o scatterlist.o
2323

2424
ifeq ($(CONFIG_DEBUG_KOBJECT),y)

‎lib/bcd.c‎

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
#include <linux/bcd.h>
2+
#include <linux/module.h>
3+
4+
unsigned bcd2bin(unsigned char val)
5+
{
6+
return (val & 0x0f) + (val >> 4) * 10;
7+
}
8+
EXPORT_SYMBOL(bcd2bin);
9+
10+
unsigned char bin2bcd(unsigned val)
11+
{
12+
return ((val / 10) << 4) + val % 10;
13+
}
14+
EXPORT_SYMBOL(bin2bcd);

0 commit comments

Comments
 (0)