bcd.h 559 B

1234567891011121314151617181920212223
  1. /* SPDX-License-Identifier: GPL-2.0 */
  2. #ifndef _BCD_H
  3. #define _BCD_H
  4. #include <linux/compiler.h>
  5. #define bcd2bin(x) \
  6. (__builtin_constant_p((u8 )(x)) ? \
  7. const_bcd2bin(x) : \
  8. _bcd2bin(x))
  9. #define bin2bcd(x) \
  10. (__builtin_constant_p((u8 )(x)) ? \
  11. const_bin2bcd(x) : \
  12. _bin2bcd(x))
  13. #define const_bcd2bin(x) (((x) & 0x0f) + ((x) >> 4) * 10)
  14. #define const_bin2bcd(x) ((((x) / 10) << 4) + (x) % 10)
  15. unsigned _bcd2bin(unsigned char val) __attribute_const__;
  16. unsigned char _bin2bcd(unsigned val) __attribute_const__;
  17. #endif /* _BCD_H */