DPDK  22.07.0
rte_bitops.h
Go to the documentation of this file.
1 /* SPDX-License-Identifier: BSD-3-Clause
2  * Copyright(c) 2020 Arm Limited
3  */
4 
5 #ifndef _RTE_BITOPS_H_
6 #define _RTE_BITOPS_H_
7 
16 #include <stdint.h>
17 #include <rte_debug.h>
18 #include <rte_compat.h>
19 
20 #ifdef __cplusplus
21 extern "C" {
22 #endif
23 
30 #define RTE_BIT64(nr) (UINT64_C(1) << (nr))
31 
38 #define RTE_BIT32(nr) (UINT32_C(1) << (nr))
39 
40 /*------------------------ 32-bit relaxed operations ------------------------*/
41 
55 __rte_experimental
56 static inline uint32_t
57 rte_bit_relaxed_get32(unsigned int nr, volatile uint32_t *addr)
58 {
59  RTE_ASSERT(nr < 32);
60 
61  uint32_t mask = UINT32_C(1) << nr;
62  return (*addr) & mask;
63 }
64 
76 __rte_experimental
77 static inline void
78 rte_bit_relaxed_set32(unsigned int nr, volatile uint32_t *addr)
79 {
80  RTE_ASSERT(nr < 32);
81 
82  uint32_t mask = RTE_BIT32(nr);
83  *addr = (*addr) | mask;
84 }
85 
97 __rte_experimental
98 static inline void
99 rte_bit_relaxed_clear32(unsigned int nr, volatile uint32_t *addr)
100 {
101  RTE_ASSERT(nr < 32);
102 
103  uint32_t mask = RTE_BIT32(nr);
104  *addr = (*addr) & (~mask);
105 }
106 
121 __rte_experimental
122 static inline uint32_t
123 rte_bit_relaxed_test_and_set32(unsigned int nr, volatile uint32_t *addr)
124 {
125  RTE_ASSERT(nr < 32);
126 
127  uint32_t mask = RTE_BIT32(nr);
128  uint32_t val = *addr;
129  *addr = val | mask;
130  return val & mask;
131 }
132 
147 __rte_experimental
148 static inline uint32_t
149 rte_bit_relaxed_test_and_clear32(unsigned int nr, volatile uint32_t *addr)
150 {
151  RTE_ASSERT(nr < 32);
152 
153  uint32_t mask = RTE_BIT32(nr);
154  uint32_t val = *addr;
155  *addr = val & (~mask);
156  return val & mask;
157 }
158 
159 /*------------------------ 64-bit relaxed operations ------------------------*/
160 
174 __rte_experimental
175 static inline uint64_t
176 rte_bit_relaxed_get64(unsigned int nr, volatile uint64_t *addr)
177 {
178  RTE_ASSERT(nr < 64);
179 
180  uint64_t mask = RTE_BIT64(nr);
181  return (*addr) & mask;
182 }
183 
195 __rte_experimental
196 static inline void
197 rte_bit_relaxed_set64(unsigned int nr, volatile uint64_t *addr)
198 {
199  RTE_ASSERT(nr < 64);
200 
201  uint64_t mask = RTE_BIT64(nr);
202  (*addr) = (*addr) | mask;
203 }
204 
216 __rte_experimental
217 static inline void
218 rte_bit_relaxed_clear64(unsigned int nr, volatile uint64_t *addr)
219 {
220  RTE_ASSERT(nr < 64);
221 
222  uint64_t mask = RTE_BIT64(nr);
223  *addr = (*addr) & (~mask);
224 }
225 
240 __rte_experimental
241 static inline uint64_t
242 rte_bit_relaxed_test_and_set64(unsigned int nr, volatile uint64_t *addr)
243 {
244  RTE_ASSERT(nr < 64);
245 
246  uint64_t mask = RTE_BIT64(nr);
247  uint64_t val = *addr;
248  *addr = val | mask;
249  return val;
250 }
251 
266 __rte_experimental
267 static inline uint64_t
268 rte_bit_relaxed_test_and_clear64(unsigned int nr, volatile uint64_t *addr)
269 {
270  RTE_ASSERT(nr < 64);
271 
272  uint64_t mask = RTE_BIT64(nr);
273  uint64_t val = *addr;
274  *addr = val & (~mask);
275  return val & mask;
276 }
277 
278 #ifdef __cplusplus
279 }
280 #endif
281 
282 #endif /* _RTE_BITOPS_H_ */
static __rte_experimental void rte_bit_relaxed_clear64(unsigned int nr, volatile uint64_t *addr)
Definition: rte_bitops.h:218
static __rte_experimental uint64_t rte_bit_relaxed_test_and_clear64(unsigned int nr, volatile uint64_t *addr)
Definition: rte_bitops.h:268
static __rte_experimental uint32_t rte_bit_relaxed_test_and_set32(unsigned int nr, volatile uint32_t *addr)
Definition: rte_bitops.h:123
#define RTE_BIT32(nr)
Definition: rte_bitops.h:38
static __rte_experimental void rte_bit_relaxed_set64(unsigned int nr, volatile uint64_t *addr)
Definition: rte_bitops.h:197
static __rte_experimental uint64_t rte_bit_relaxed_get64(unsigned int nr, volatile uint64_t *addr)
Definition: rte_bitops.h:176
static __rte_experimental void rte_bit_relaxed_set32(unsigned int nr, volatile uint32_t *addr)
Definition: rte_bitops.h:78
static __rte_experimental void rte_bit_relaxed_clear32(unsigned int nr, volatile uint32_t *addr)
Definition: rte_bitops.h:99
static __rte_experimental uint32_t rte_bit_relaxed_get32(unsigned int nr, volatile uint32_t *addr)
Definition: rte_bitops.h:57
static __rte_experimental uint32_t rte_bit_relaxed_test_and_clear32(unsigned int nr, volatile uint32_t *addr)
Definition: rte_bitops.h:149
#define RTE_BIT64(nr)
Definition: rte_bitops.h:30
static __rte_experimental uint64_t rte_bit_relaxed_test_and_set64(unsigned int nr, volatile uint64_t *addr)
Definition: rte_bitops.h:242