I am writing a linux security module, and I use a bitmap
structure in the code. I have two candidate structures as follows
struct bitmap {
unsigned long val[DIV_ROUND_UP(CONFIG_BITMAP_MAX_BITS, sizeof(unsigned long) * 8)];
}
vs
struct bitmap {
u64 val[DIV_ROUND_UP(CONFIG_BITMAP_MAX_BITS, 64)];
}
The underlying type used is just an implementation detail, and not exposed to anything that uses the bitmap structure. Instead, there are helper functions which do bitmap_union
, bitmap_intersection
, add_bit_to_bitmap
, remove_bit_from_bitmap
, ...
Hence, I'd like to know if it is a better choice to use unsigned long
, considering only performance implications of bit operations (bitwise-and, bitwise-or, bitwise-xor, ..) across architectures.
Edit: Since this is a linux security module, it is intended to support all architectures supported by linux kernel (both 32-bit and 64-bit). Since uint64_t
and unsigned long
only differ in 32-bit processors (as far as I know), the comparision only makes sense for 32-bit architectures. A list of architectures supported by linux kernel is available at this wiki page and here. The main focus is on x86
and arm
processors.