F
Francois Grieu
This macro returns 1 if the low 8 bits of x form a valid BCD value,
and 0 otherwise.
#define VALIDBCD(x) (((x)&0x0F)<0x0A && ((x)&0xF0)<0xA0)
How do you rewrite it so that it evaluates its argument only once,
requires no temp variable or table, and is fully C99 compliant?
My shortest solution uses 3 constants, and beats the original
hands off in term of performance on my desktop CPU.
I wish my C compilers would know this kind of optimization.
François Grieu
and 0 otherwise.
#define VALIDBCD(x) (((x)&0x0F)<0x0A && ((x)&0xF0)<0xA0)
How do you rewrite it so that it evaluates its argument only once,
requires no temp variable or table, and is fully C99 compliant?
My shortest solution uses 3 constants, and beats the original
hands off in term of performance on my desktop CPU.
I wish my C compilers would know this kind of optimization.
François Grieu