DPDK  21.08.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 
26 #define RTE_BIT64(nr) (UINT64_C(1) << (nr))
27 
34 #define RTE_BIT32(nr) (UINT32_C(1) << (nr))
35 
36 /*------------------------ 32-bit relaxed operations ------------------------*/
37 
51 __rte_experimental
52 static inline uint32_t
53 rte_bit_relaxed_get32(unsigned int nr, volatile uint32_t *addr)
54 {
55  RTE_ASSERT(nr < 32);
56 
57  uint32_t mask = UINT32_C(1) << nr;
58  return (*addr) & mask;
59 }
60 
72 __rte_experimental
73 static inline void
74 rte_bit_relaxed_set32(unsigned int nr, volatile uint32_t *addr)
75 {
76  RTE_ASSERT(nr < 32);
77 
78  uint32_t mask = RTE_BIT32(nr);
79  *addr = (*addr) | mask;
80 }
81 
93 __rte_experimental
94 static inline void
95 rte_bit_relaxed_clear32(unsigned int nr, volatile uint32_t *addr)
96 {
97  RTE_ASSERT(nr < 32);
98 
99  uint32_t mask = RTE_BIT32(nr);
100  *addr = (*addr) & (~mask);
101 }
102 
117 __rte_experimental
118 static inline uint32_t
119 rte_bit_relaxed_test_and_set32(unsigned int nr, volatile uint32_t *addr)
120 {
121  RTE_ASSERT(nr < 32);
122 
123  uint32_t mask = RTE_BIT32(nr);
124  uint32_t val = *addr;
125  *addr = val | mask;
126  return val & mask;
127 }
128 
143 __rte_experimental
144 static inline uint32_t
145 rte_bit_relaxed_test_and_clear32(unsigned int nr, volatile uint32_t *addr)
146 {
147  RTE_ASSERT(nr < 32);
148 
149  uint32_t mask = RTE_BIT32(nr);
150  uint32_t val = *addr;
151  *addr = val & (~mask);
152  return val & mask;
153 }
154 
155 /*------------------------ 64-bit relaxed operations ------------------------*/
156 
170 __rte_experimental
171 static inline uint64_t
172 rte_bit_relaxed_get64(unsigned int nr, volatile uint64_t *addr)
173 {
174  RTE_ASSERT(nr < 64);
175 
176  uint64_t mask = RTE_BIT64(nr);
177  return (*addr) & mask;
178 }
179 
191 __rte_experimental
192 static inline void
193 rte_bit_relaxed_set64(unsigned int nr, volatile uint64_t *addr)
194 {
195  RTE_ASSERT(nr < 64);
196 
197  uint64_t mask = RTE_BIT64(nr);
198  (*addr) = (*addr) | mask;
199 }
200 
212 __rte_experimental
213 static inline void
214 rte_bit_relaxed_clear64(unsigned int nr, volatile uint64_t *addr)
215 {
216  RTE_ASSERT(nr < 64);
217 
218  uint64_t mask = RTE_BIT64(nr);
219  *addr = (*addr) & (~mask);
220 }
221 
236 __rte_experimental
237 static inline uint64_t
238 rte_bit_relaxed_test_and_set64(unsigned int nr, volatile uint64_t *addr)
239 {
240  RTE_ASSERT(nr < 64);
241 
242  uint64_t mask = RTE_BIT64(nr);
243  uint64_t val = *addr;
244  *addr = val | mask;
245  return val;
246 }
247 
262 __rte_experimental
263 static inline uint64_t
264 rte_bit_relaxed_test_and_clear64(unsigned int nr, volatile uint64_t *addr)
265 {
266  RTE_ASSERT(nr < 64);
267 
268  uint64_t mask = RTE_BIT64(nr);
269  uint64_t val = *addr;
270  *addr = val & (~mask);
271  return val & mask;
272 }
273 
274 #endif /* _RTE_BITOPS_H_ */
static __rte_experimental void rte_bit_relaxed_clear64(unsigned int nr, volatile uint64_t *addr)
Definition: rte_bitops.h:214
static __rte_experimental uint64_t rte_bit_relaxed_test_and_clear64(unsigned int nr, volatile uint64_t *addr)
Definition: rte_bitops.h:264
static __rte_experimental uint32_t rte_bit_relaxed_test_and_set32(unsigned int nr, volatile uint32_t *addr)
Definition: rte_bitops.h:119
#define RTE_BIT32(nr)
Definition: rte_bitops.h:34
static __rte_experimental void rte_bit_relaxed_set64(unsigned int nr, volatile uint64_t *addr)
Definition: rte_bitops.h:193
static __rte_experimental uint64_t rte_bit_relaxed_get64(unsigned int nr, volatile uint64_t *addr)
Definition: rte_bitops.h:172
static __rte_experimental void rte_bit_relaxed_set32(unsigned int nr, volatile uint32_t *addr)
Definition: rte_bitops.h:74
static __rte_experimental void rte_bit_relaxed_clear32(unsigned int nr, volatile uint32_t *addr)
Definition: rte_bitops.h:95
static __rte_experimental uint32_t rte_bit_relaxed_get32(unsigned int nr, volatile uint32_t *addr)
Definition: rte_bitops.h:53
static __rte_experimental uint32_t rte_bit_relaxed_test_and_clear32(unsigned int nr, volatile uint32_t *addr)
Definition: rte_bitops.h:145
#define RTE_BIT64(nr)
Definition: rte_bitops.h:26
static __rte_experimental uint64_t rte_bit_relaxed_test_and_set64(unsigned int nr, volatile uint64_t *addr)
Definition: rte_bitops.h:238