Update bit field helpers to support more bit field operate

Signed-off-by: Huayang Duan <huayang.duan@mediatek.com>
Change-Id: I8f182fff45806912da2390939a6652932501d7c5
Reviewed-on: https://review.coreboot.org/c/coreboot/+/44705
Tested-by: build bot (Jenkins) <no-reply@coreboot.org>
Reviewed-by: Hung-Te Lin <hungte@chromium.org>
This commit is contained in:
Huayang Duan 2020-06-23 12:25:24 +08:00 committed by Hung-Te Lin
parent e4478637bd
commit 232d8a8eb5
1 changed files with 25 additions and 2 deletions

View File

@ -150,21 +150,44 @@ static inline void buffer_to_fifo32(void *buffer, size_t size, void *fifo,
_BF_APPLY6(op, __VA_ARGS__)) _BF_APPLY6(op, __VA_ARGS__))
#define _BF_APPLY8(op, name, value, ...) ((op(name, value)) | \ #define _BF_APPLY8(op, name, value, ...) ((op(name, value)) | \
_BF_APPLY7(op, __VA_ARGS__)) _BF_APPLY7(op, __VA_ARGS__))
#define _BF_APPLY9(op, name, value, ...) ((op(name, value)) | \
_BF_APPLY8(op, __VA_ARGS__))
#define _BF_APPLY10(op, name, value, ...) ((op(name, value)) | \
_BF_APPLY9(op, __VA_ARGS__))
#define _BF_APPLY11(op, name, value, ...) ((op(name, value)) | \
_BF_APPLY10(op, __VA_ARGS__))
#define _BF_APPLY12(op, name, value, ...) ((op(name, value)) | \
_BF_APPLY11(op, __VA_ARGS__))
#define _BF_APPLY13(op, name, value, ...) ((op(name, value)) | \
_BF_APPLY12(op, __VA_ARGS__))
#define _BF_APPLY14(op, name, value, ...) ((op(name, value)) | \
_BF_APPLY13(op, __VA_ARGS__))
#define _BF_APPLY15(op, name, value, ...) ((op(name, value)) | \
_BF_APPLY14(op, __VA_ARGS__))
#define _BF_APPLY16(op, name, value, ...) ((op(name, value)) | \
_BF_APPLY15(op, __VA_ARGS__))
#define _BF_APPLYINVALID(...) \ #define _BF_APPLYINVALID(...) \
_Static_assert(0, "Invalid arguments for {WRITE,SET}*_BITFIELDS") _Static_assert(0, "Invalid arguments for {WRITE,SET}*_BITFIELDS")
#define _BF_IMPL2(op, addr, \ #define _BF_IMPL2(op, addr, \
n1, v1, n2, v2, n3, v3, n4, v4, n5, v5, n6, v6, n7, v7, n8, v8, \ n1, v1, n2, v2, n3, v3, n4, v4, n5, v5, n6, v6, n7, v7, n8, v8, \
n9, v9, n10, v10, n11, v11, n12, v12, n13, v13, n14, v14, n15, v15, n16, v16, \
NARGS, ...) \ NARGS, ...) \
\ \
op(addr, \ op(addr, \
_BF_APPLY##NARGS(_BF_MASK, n1, v1, n2, v2, n3, v3, n4, v4, \ _BF_APPLY##NARGS(_BF_MASK, n1, v1, n2, v2, n3, v3, n4, v4, \
n5, v5, n6, v6, n7, v7, n8, v8), \ n5, v5, n6, v6, n7, v7, n8, v8, \
n9, v9, n10, v10, n11, v11, n12, v12, \
n13, v13, n14, v14, n15, v15, n16, v16), \
_BF_APPLY##NARGS(_BF_VALUE, n1, v1, n2, v2, n3, v3, n4, v4, \ _BF_APPLY##NARGS(_BF_VALUE, n1, v1, n2, v2, n3, v3, n4, v4, \
n5, v5, n6, v6, n7, v7, n8, v8)) n5, v5, n6, v6, n7, v7, n8, v8,\
n9, v9, n10, v10, n11, v11, n12, v12, \
n13, v13, n14, v14, n15, v15, n16, v16))
#define _BF_IMPL(op, addr, ...) \ #define _BF_IMPL(op, addr, ...) \
_BF_IMPL2(op, addr, __VA_ARGS__, \ _BF_IMPL2(op, addr, __VA_ARGS__, \
16, INVALID, 15, INVALID, 14, INVALID, 13, INVALID, \
12, INVALID, 11, INVALID, 10, INVALID, 9, INVALID, \
8, INVALID, 7, INVALID, 6, INVALID, 5, INVALID, \ 8, INVALID, 7, INVALID, 6, INVALID, 5, INVALID, \
4, INVALID, 3, INVALID, 2, INVALID, 1, INVALID) 4, INVALID, 3, INVALID, 2, INVALID, 1, INVALID)