DPDK 22.11.6
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
21extern "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
56static inline uint32_t
57rte_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
77static inline void
78rte_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
98static inline void
99rte_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
122static inline uint32_t
123rte_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
148static inline uint32_t
149rte_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
175static inline uint64_t
176rte_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
196static inline void
197rte_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
217static inline void
218rte_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
241static inline uint64_t
242rte_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
267static inline uint64_t
268rte_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_ */
#define RTE_BIT64(nr)
Definition: rte_bitops.h:30
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_test_and_set64(unsigned int nr, volatile uint64_t *addr)
Definition: rte_bitops.h:242
static __rte_experimental uint32_t rte_bit_relaxed_get32(unsigned int nr, volatile uint32_t *addr)
Definition: rte_bitops.h:57
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 void rte_bit_relaxed_clear32(unsigned int nr, volatile uint32_t *addr)
Definition: rte_bitops.h:99
#define RTE_BIT32(nr)
Definition: rte_bitops.h:38
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_get64(unsigned int nr, volatile uint64_t *addr)
Definition: rte_bitops.h:176
static __rte_experimental uint32_t rte_bit_relaxed_test_and_set32(unsigned int nr, volatile uint32_t *addr)
Definition: rte_bitops.h:123
static __rte_experimental uint32_t rte_bit_relaxed_test_and_clear32(unsigned int nr, volatile uint32_t *addr)
Definition: rte_bitops.h:149
static __rte_experimental void rte_bit_relaxed_set32(unsigned int nr, volatile uint32_t *addr)
Definition: rte_bitops.h:78