Add __BIT and __BITS macros from NetBSD to help support new testcases

MFC after:	1 week
This commit is contained in:
Enji Cooper 2017-01-12 09:01:14 +00:00
parent 17160457b4
commit 7ad417dff8
Notes: svn2git 2020-12-20 02:59:44 +00:00
svn path=/head/; revision=311972

View File

@ -71,4 +71,13 @@
*/
#define __arraycount(__x) (sizeof(__x) / sizeof(__x[0]))
/* __BIT(n): nth bit, where __BIT(0) == 0x1. */
#define __BIT(__n) \
(((uintmax_t)(__n) >= NBBY * sizeof(uintmax_t)) ? 0 : \
((uintmax_t)1 << (uintmax_t)((__n) & (NBBY * sizeof(uintmax_t) - 1))))
/* __BITS(m, n): bits m through n, m < n. */
#define __BITS(__m, __n) \
((__BIT(MAX((__m), (__n)) + 1) - 1) ^ (__BIT(MIN((__m), (__n))) - 1))
#endif /* _LIBNETBSD_SYS_CDEFS_H_ */