![]() |
The ROme OpTimistic Simulator
2.0.0
A General-Purpose Multithreaded Parallel/Distributed Simulation Platform
|
Bitmap data type. More...
Go to the source code of this file.
Macros | |
#define | B_BLOCK_TYPE unsigned |
#define | B_BLOCK_SIZE ((unsigned)sizeof(B_BLOCK_TYPE)) |
#define | B_BITS_PER_BLOCK (B_BLOCK_SIZE*CHAR_BIT) |
#define | B_MASK ((B_BLOCK_TYPE)1U) |
#define | B_UNION_CAST(bitmap) UNION_CAST(((rootsim_bitmap*)(bitmap)), B_BLOCK_TYPE*) |
#define | B_MOD_OF_BPB(n) (((unsigned)(n)) & ((unsigned)(B_BITS_PER_BLOCK - 1))) |
#define | B_SET_BIT_AT(B, K) ( B |= (B_MASK << K) ) |
#define | B_RESET_BIT_AT(B, K) ( B &= ~(B_MASK << K) ) |
#define | B_CHECK_BIT_AT(B, K) ( B & (B_MASK << K) ) |
#define | B_SET_BIT(A, I) B_SET_BIT_AT((A)[((I) / B_BITS_PER_BLOCK)], (B_MOD_OF_BPB(I))) |
#define | B_RESET_BIT(A, I) B_RESET_BIT_AT((A)[((I) / B_BITS_PER_BLOCK)], (B_MOD_OF_BPB(I))) |
#define | B_CHECK_BIT(A, I) B_CHECK_BIT_AT((A)[((I) / B_BITS_PER_BLOCK)], (B_MOD_OF_BPB(I))) |
#define | B_CTZ(x) |
#define | B_POPC(x) |
#define | bitmap_required_size(requested_bits) ((((requested_bits)/B_BITS_PER_BLOCK) + (B_MOD_OF_BPB(requested_bits) != 0))*B_BLOCK_SIZE) |
Computes the required size of a bitmap with requested_bits entries. More... | |
#define | bitmap_initialize(memory_pointer, requested_bits) (memset(memory_pointer, 0, bitmap_required_size(requested_bits))) |
This initializes the bitmap at memory_pointer containing requested_bits entries. More... | |
#define | bitmap_set(bitmap, bit_index) (B_SET_BIT(B_UNION_CAST(bitmap), ((unsigned)(bit_index)))) |
This sets the bit with index bit_index of the bitmap bitmap. More... | |
#define | bitmap_reset(bitmap, bit_index) (B_RESET_BIT(B_UNION_CAST(bitmap), ((unsigned)(bit_index)))) |
This resets the bit with index bit_index of the bitmap bitmap. More... | |
#define | bitmap_check(bitmap, bit_index) (B_CHECK_BIT(B_UNION_CAST(bitmap), ((unsigned)(bit_index))) != 0) |
This checks if the bit with index bit_index of the bitmap bitmap is set or unset. More... | |
#define | bitmap_count_reset(bitmap, bitmap_size) |
This counts the occurrences of cleared bits in the bitmap bitmap. More... | |
#define | bitmap_first_reset(bitmap, bitmap_size) |
This returns the index of the first cleared bit in bitmap. More... | |
#define | bitmap_foreach_set(bitmap, bitmap_size, func) |
This executes a user supplied function for each set bit in bitmap. More... | |
Typedefs | |
typedef unsigned char | rootsim_bitmap |
This defines a generic bitmap. | |
Bitmap data type.
This a simple bitmap implemented with some simple macros. Keep in mind that some trust is given to the developer since the implementation, for performances and simplicity reasons, doesn't remember his effective size; consequently it doesn't check boundaries on the array that stores the bits.
This file is part of ROOT-Sim (ROme OpTimistic Simulator).
ROOT-Sim is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; only version 3 of the License applies.
ROOT-Sim is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
You should have received a copy of the GNU General Public License along with ROOT-Sim; if not, write to the Free Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
Definition in file bitmap.h.
#define B_CTZ | ( | x | ) |
#define B_POPC | ( | x | ) |
#define bitmap_check | ( | bitmap, | |
bit_index | |||
) | (B_CHECK_BIT(B_UNION_CAST(bitmap), ((unsigned)(bit_index))) != 0) |
This checks if the bit with index bit_index of the bitmap bitmap is set or unset.
bitmap | a pointer to the bitmap. |
bit_index | the index of the bit to read |
Care to avoid side effects in the arguments because they may be evaluated more than once
#define bitmap_count_reset | ( | bitmap, | |
bitmap_size | |||
) |
This counts the occurrences of cleared bits in the bitmap bitmap.
bitmap | a pointer to the bitmap. |
bitmap_size | the size of the bitmap in bytes (obtainable through bitmap_required_size()) |
XXX: maybe the unsigned variables holding the indexes and the counts are too limited for our application! This macro expects the number of bits in the bitmap to be a multiple of B_BITS_PER_BLOCK. Care to avoid side effects in the arguments because they may be evaluated more than once
#define bitmap_first_reset | ( | bitmap, | |
bitmap_size | |||
) |
This returns the index of the first cleared bit in bitmap.
bitmap | a pointer to the bitmap. |
bitmap_size | the size of the bitmap in bytes (obtainable through bitmap_required_size()) |
XXX: maybe the unsigned variables holding the indexes and the counts are too limited for our application! This macro expects the number of bits in the bitmap to be a multiple of B_BITS_PER_BLOCK. Care to avoid side effects in the arguments because they may be evaluated more than once
#define bitmap_foreach_set | ( | bitmap, | |
bitmap_size, | |||
func | |||
) |
This executes a user supplied function for each set bit in bitmap.
bitmap | a pointer to the bitmap. |
bitmap_size | the size of the bitmap in bytes (obtainable through bitmap_required_size()) |
func | a function which takes a single unsigned argument, the index of the current set bit. |
XXX: maybe the unsigned variables holding the indexes and the counts are too limited for our application! This macro expects the number of bits in the bitmap to be a multiple of B_BITS_PER_BLOCK. Care to avoid side effects in the arguments because they may be evaluated more than once
#define bitmap_initialize | ( | memory_pointer, | |
requested_bits | |||
) | (memset(memory_pointer, 0, bitmap_required_size(requested_bits))) |
This initializes the bitmap at memory_pointer containing requested_bits entries.
memory_pointer | the pointer to the bitmap to initialize. |
requested_bits | the number of bits contained in the bitmap. |
The argument requested_bits is necessary since the bitmap is "dumb" For example this dynamically declares a 100 entries bitmap and initializes it: rootsim_bitmap *my_bitmap = malloc(bitmap_required_size(100)); bitmap_initialize(my_bitmap, 100);
Care to avoid side effects in the arguments because they may be evaluated more than once
#define bitmap_required_size | ( | requested_bits | ) | ((((requested_bits)/B_BITS_PER_BLOCK) + (B_MOD_OF_BPB(requested_bits) != 0))*B_BLOCK_SIZE) |
Computes the required size of a bitmap with requested_bits entries.
requested_bits | the requested number of bits. |
For example this statically declares a 100 entries bitmap and initializes it: rootsim_bitmap my_bitmap[bitmap_required_size(100)] = {0};
Care to avoid side effects in the arguments because they may be evaluated more than once
#define bitmap_reset | ( | bitmap, | |
bit_index | |||
) | (B_RESET_BIT(B_UNION_CAST(bitmap), ((unsigned)(bit_index)))) |
#define bitmap_set | ( | bitmap, | |
bit_index | |||
) | (B_SET_BIT(B_UNION_CAST(bitmap), ((unsigned)(bit_index)))) |