diff options
| author | Anup Patel <[email protected]> | 2020-03-04 12:29:15 +0530 |
|---|---|---|
| committer | Anup Patel <[email protected]> | 2020-03-11 15:29:45 +0530 |
| commit | 3226bd93ce41ed0c815a9021f5e489cfe3e83fa3 (patch) | |
| tree | b518dafa8e44c3d03f66a1eb9456afae38782e1b /lib | |
| parent | 078686d75c929af72971bb51115438e3a2826896 (diff) | |
lib: Simple bitmap library
We add simple bitmap library which will help us create and maintain
bitmaps. It will also help us create a simple HART mask library.
Signed-off-by: Anup Patel <[email protected]>
Reviewed-by: Bin Meng <[email protected]>
Reviewed-by: Atish Patra <[email protected]>
Diffstat (limited to 'lib')
| -rw-r--r-- | lib/sbi/objects.mk | 1 | ||||
| -rw-r--r-- | lib/sbi/sbi_bitmap.c | 40 |
2 files changed, 41 insertions, 0 deletions
diff --git a/lib/sbi/objects.mk b/lib/sbi/objects.mk index d2a3ebe4..5f1bdbfb 100644 --- a/lib/sbi/objects.mk +++ b/lib/sbi/objects.mk @@ -12,6 +12,7 @@ libsbi-objs-y += riscv_atomic.o libsbi-objs-y += riscv_hardfp.o libsbi-objs-y += riscv_locks.o +libsbi-objs-y += sbi_bitmap.o libsbi-objs-y += sbi_bitops.o libsbi-objs-y += sbi_console.o libsbi-objs-y += sbi_ecall.o diff --git a/lib/sbi/sbi_bitmap.c b/lib/sbi/sbi_bitmap.c new file mode 100644 index 00000000..e74b6bbe --- /dev/null +++ b/lib/sbi/sbi_bitmap.c @@ -0,0 +1,40 @@ +/* + * SPDX-License-Identifier: BSD-2-Clause + * + * Copyright (c) 2020 Western Digital Corporation or its affiliates. + * + * Authors: + * Anup Patel <[email protected]> + */ + +#include <sbi/sbi_bitmap.h> + +void __bitmap_and(unsigned long *dst, const unsigned long *bitmap1, + const unsigned long *bitmap2, int bits) +{ + int k; + int nr = BITS_TO_LONGS(bits); + + for (k = 0; k < nr; k++) + dst[k] = bitmap1[k] & bitmap2[k]; +} + +void __bitmap_or(unsigned long *dst, const unsigned long *bitmap1, + const unsigned long *bitmap2, int bits) +{ + int k; + int nr = BITS_TO_LONGS(bits); + + for (k = 0; k < nr; k++) + dst[k] = bitmap1[k] | bitmap2[k]; +} + +void __bitmap_xor(unsigned long *dst, const unsigned long *bitmap1, + const unsigned long *bitmap2, int bits) +{ + int k; + int nr = BITS_TO_LONGS(bits); + + for (k = 0; k < nr; k++) + dst[k] = bitmap1[k] ^ bitmap2[k]; +} |
