rtc: BCD codeshrink
A message that is not in the archive (sent off-list or not yet received): [email protected]
Quoted 25 lines · On Tue, 1 Jul 2008 23:41:01 -0700 David Brownell <[email protected]> wrote:
This updates <
linux/bcd.h> to define the key routines as constant functions, which the macros will then call. Newer code can now callbcd2bin()instead of SCREAMINGBCD2BIN()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 <[email protected]>Acked-by Adrian Bunk <[email protected]>--- include/linux/bcd.h | 9 +++++++-- lib/Makefile | 2 +- lib/bcd.c | 14 ++++++++++++++ 3 files changed, 22 insertions(+), 3 deletions(-)include/linux/bcd.h +0
-0@@ -10,8 +10,13 @@#ifndef _BCD_H#define _BCD_H
include/linux/bcd.h line 19
Quoted 10 lines
include/linux/bcd.h +7
-2-#define BCD2BIN (val) (((val) & 0x0f) + ((val)>>4)*10) -#define BIN2BCD (val) ((((val)/10)<<4) + (val)%10) +#include <linux/compiler.h> + +unsigned bcd2bin(unsigned char val) __attribute_const__; +unsigned char bin2bcd(unsigned val) __attribute_const__; + +#define BCD2BIN (val) bcd2bin(val) +#define BIN2BCD (val) bin2bcd(val)
It'd be good to nuke these things now.
Unfortunately you didn't cc the list where nukers lurk. Please do cc linux-kernel on kernel-wide patches.
Quoted 30 lines
include/linux/bcd.h +0
-0/* backwards compat */ #define BCD_TO_BIN (val) ((val)=BCD2BIN(val))lib/Makefile +1
-1@@ -13,7 +13,7 @@ lib-$(CONFIG_SMP) += cpumask.o lib-y += kobject.o kref.o klist.o -obj-y += div64.o sort.o parser.o halfmd4.o debug_locks.o random32.o \ +obj-y += bcd.o div64.o sort.o parser.o halfmd4.o debug_locks.o random32.o \ bust_spinlocks.o hexdump.o kasprintf.o bitmap.o scatterlist.o ifeq ($(CONFIG_DEBUG_KOBJECT),y)lib/bcd.c new file +14
-0@@ -0,0 +1,14 @@ +#include <linux/bcd.h> +#include <linux/module.h> + +unsigned bcd2bin (unsigned char val) +{ +return (val &0x0f ) + (val >>4 ) *10 ; +} +EXPORT_SYMBOL (bcd2bin); + +unsigned char bin2bcd (unsigned val) +{ +return ((val /10 ) <<4 ) + val %10 ; +} +EXPORT_SYMBOL (bin2bcd);
Quoted 28 lines · Andrew Morton
Quoted 26 lines · On Tue, 1 Jul 2008 23:41:01 -0700 David Brownell <[email protected]> wrote:
This updates <
linux/bcd.h> to define the key routines as constant functions, which the macros will then call. Newer code can now callbcd2bin()instead of SCREAMINGBCD2BIN()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 <[email protected]>Acked-by Adrian Bunk <[email protected]>--- include/linux/bcd.h | 9 +++++++-- lib/Makefile | 2 +- lib/bcd.c | 14 ++++++++++++++ 3 files changed, 22 insertions(+), 3 deletions(-)include/linux/bcd.h +0
-0@@ -10,8 +10,13 @@#ifndef _BCD_H#define _BCD_H
Quoted 12 lines
include/linux/bcd.h line 19
Quoted 9 lines
include/linux/bcd.h +7
-2-#define BCD2BIN (val) (((val) & 0x0f) + ((val)>>4)*10) -#define BIN2BCD (val) ((((val)/10)<<4) + (val)%10) +#include <linux/compiler.h> + +unsigned bcd2bin(unsigned char val) __attribute_const__; +unsigned char bin2bcd(unsigned val) __attribute_const__; + +#define BCD2BIN (val) bcd2bin(val) +#define BIN2BCD (val) bin2bcd(val)It'd be good to nuke these things now.
...
Unless David is faster I plan to do this after the patch went into Linus' tree.
E.g. rtc-ramtron-fm3130-rtc-support.patch in 2.6.26-rc5-mm3 adds a new user, and it should create less hassle if the actual removal of the #define's happens around 2.6.27-rc1 when everything is merged into Linus' tree.
cu
Adrian
Signature · 4 lines
"Is there not promise of rain?" Ling Tan asked suddenly out
of the darkness. There had been need of rain for many days.
"Only a promise," Lao Er said.
Pearl S. Buck - Dragon Seed