Sun Dec 19 09:49:47 2021 UTC ()
provide BITS_PER_TYPE

Author: Maya Rashish <maya@NetBSD.org>


(riastradh)
diff -r1.14 -r1.15 src/sys/external/bsd/common/include/linux/bitops.h

cvs diff -r1.14 -r1.15 src/sys/external/bsd/common/include/linux/bitops.h (expand / switch to unified diff)

--- src/sys/external/bsd/common/include/linux/bitops.h 2021/12/19 09:44:27 1.14
+++ src/sys/external/bsd/common/include/linux/bitops.h 2021/12/19 09:49:47 1.15
@@ -1,14 +1,14 @@ @@ -1,14 +1,14 @@
1/* $NetBSD: bitops.h,v 1.14 2021/12/19 09:44:27 riastradh Exp $ */ 1/* $NetBSD: bitops.h,v 1.15 2021/12/19 09:49:47 riastradh Exp $ */
2 2
3/*- 3/*-
4 * Copyright (c) 2013 The NetBSD Foundation, Inc. 4 * Copyright (c) 2013 The NetBSD Foundation, Inc.
5 * All rights reserved. 5 * All rights reserved.
6 * 6 *
7 * This code is derived from software contributed to The NetBSD Foundation 7 * This code is derived from software contributed to The NetBSD Foundation
8 * by Taylor R. Campbell. 8 * by Taylor R. Campbell.
9 * 9 *
10 * Redistribution and use in source and binary forms, with or without 10 * Redistribution and use in source and binary forms, with or without
11 * modification, are permitted provided that the following conditions 11 * modification, are permitted provided that the following conditions
12 * are met: 12 * are met:
13 * 1. Redistributions of source code must retain the above copyright 13 * 1. Redistributions of source code must retain the above copyright
14 * notice, this list of conditions and the following disclaimer. 14 * notice, this list of conditions and the following disclaimer.
@@ -96,28 +96,29 @@ hweight64(uint64_t n) @@ -96,28 +96,29 @@ hweight64(uint64_t n)
96{ 96{
97 return popcount64(n); 97 return popcount64(n);
98} 98}
99 99
100static inline int64_t 100static inline int64_t
101sign_extend64(uint64_t x, unsigned n) 101sign_extend64(uint64_t x, unsigned n)
102{ 102{
103 return (int64_t)(x << (63 - n)) >> (63 - n); 103 return (int64_t)(x << (63 - n)) >> (63 - n);
104} 104}
105 105
106#define BITS_TO_LONGS(n) \ 106#define BITS_TO_LONGS(n) \
107 roundup2((n), (sizeof(unsigned long) * CHAR_BIT)) 107 roundup2((n), (sizeof(unsigned long) * CHAR_BIT))
108 108
109#define BITS_PER_BYTE NBBY 109#define BITS_PER_TYPE(type) (sizeof(type) * NBBY)
110#define BITS_PER_LONG (__SIZEOF_LONG__ * CHAR_BIT) 110#define BITS_PER_BYTE NBBY
 111#define BITS_PER_LONG (__SIZEOF_LONG__ * CHAR_BIT)
111 112
112#define BIT(n) ((unsigned long)__BIT(n)) 113#define BIT(n) ((unsigned long)__BIT(n))
113#define BIT_ULL(n) ((unsigned long long)__BIT(n)) 114#define BIT_ULL(n) ((unsigned long long)__BIT(n))
114#define GENMASK(h,l) ((unsigned long)__BITS(h,l)) 115#define GENMASK(h,l) ((unsigned long)__BITS(h,l))
115#define GENMASK_ULL(h,l)((unsigned long long)__BITS(h,l)) 116#define GENMASK_ULL(h,l)((unsigned long long)__BITS(h,l))
116 117
117static inline int 118static inline int
118test_bit(unsigned int n, const volatile unsigned long *p) 119test_bit(unsigned int n, const volatile unsigned long *p)
119{ 120{
120 const unsigned units = (sizeof(unsigned long) * CHAR_BIT); 121 const unsigned units = (sizeof(unsigned long) * CHAR_BIT);
121 122
122 return ((p[n / units] & (1UL << (n % units))) != 0); 123 return ((p[n / units] & (1UL << (n % units))) != 0);
123} 124}