OpenOCD
bitfield.h
Go to the documentation of this file.
1 /* SPDX-License-Identifier: BSD-2-Clause */
2 
3 /*
4 * Copyright (c) 2020-2024 The FreeBSD Foundation
5 *
6 * This software was developed by Björn Zeeb under sponsorship from
7 * the FreeBSD Foundation.
8 */
9 
10 #ifndef OPENOCD_HELPER_BITFIELD_H
11 #define OPENOCD_HELPER_BITFIELD_H
12 
19 #define __bf_shf(x) (__builtin_ffsll(x) - 1)
20 
31 #define FIELD_FIT(_mask, _value) \
32  (!(((typeof(_mask))(_value) << __bf_shf(_mask)) & ~(_mask)))
33 
44 #define FIELD_PREP(_mask, _value) \
45  (((typeof(_mask))(_value) << __bf_shf(_mask)) & (_mask))
46 
57 #define FIELD_GET(_mask, _value) \
58  ((typeof(_mask))(((_value) & (_mask)) >> __bf_shf(_mask)))
59 
60 #endif /* OPENOCD_HELPER_BITFIELD_H */