X-Git-Url: http://wien.tomnetworks.com/gitweb/?a=blobdiff_plain;f=mono%2Futils%2Fmonobitset.h;h=7ec53f60bcf91cf53c3ea6f87f77589f7b09fe4f;hb=5901caa6ce510e300117609410192bcf15b098f0;hp=12f45628e71f35a18c1a862f30b7084a07bb057a;hpb=881f83658281916d8f0784df7c726ecb7cc289db;p=mono.git diff --git a/mono/utils/monobitset.h b/mono/utils/monobitset.h index 12f45628e71..7ec53f60bcf 100644 --- a/mono/utils/monobitset.h +++ b/mono/utils/monobitset.h @@ -3,20 +3,59 @@ #include -typedef struct MonoBitSet MonoBitSet; +/* + * When embedding, you have to define MONO_ZERO_LEN_ARRAY before including any + * other Mono header file if you use a different compiler from the one used to + * build Mono. + */ +#ifndef MONO_ZERO_LEN_ARRAY +#ifdef __GNUC__ +#define MONO_ZERO_LEN_ARRAY 0 +#else +#define MONO_ZERO_LEN_ARRAY 1 +#endif +#endif + +#define MONO_BITSET_BITS_PER_CHUNK (8 * sizeof (gsize)) + +typedef struct { + gsize size; + gsize flags; + gsize data [MONO_ZERO_LEN_ARRAY]; +} MonoBitSet; + typedef void (*MonoBitSetFunc) (guint idx, gpointer data); enum { MONO_BITSET_DONT_FREE = 1 }; -#define MONO_BITSET_BITS_PER_CHUNK (8 * sizeof (gsize)) - /* Fast access to bits which depends on the implementation of the bitset */ -#define mono_bitset_test_fast(set,n) (((gsize*)set)[2+(n)/MONO_BITSET_BITS_PER_CHUNK] & ((gsize)1 << ((n) % MONO_BITSET_BITS_PER_CHUNK))) -#define mono_bitset_set_fast(set,n) do { ((gsize*)set)[2+(n)/MONO_BITSET_BITS_PER_CHUNK] |= ((gsize)1 << ((n) % MONO_BITSET_BITS_PER_CHUNK)); } while (0) -#define mono_bitset_clear_fast(set,n) do { ((gsize*)set)[2+(n)/MONO_BITSET_BITS_PER_CHUNK] &= ~((gsize)1 << ((n) % MONO_BITSET_BITS_PER_CHUNK)); } while (0) -#define mono_bitset_get_fast(set,n) (((gsize*)set)[2+(n)]) +#define mono_bitset_test_fast(set,n) ((set)->data [(n)/MONO_BITSET_BITS_PER_CHUNK] & ((gsize)1 << ((n) % MONO_BITSET_BITS_PER_CHUNK))) +#define mono_bitset_test_fast(set,n) ((set)->data [(n)/MONO_BITSET_BITS_PER_CHUNK] & ((gsize)1 << ((n) % MONO_BITSET_BITS_PER_CHUNK))) +#define mono_bitset_set_fast(set,n) do { (set)->data [(n)/MONO_BITSET_BITS_PER_CHUNK] |= ((gsize)1 << ((n) % MONO_BITSET_BITS_PER_CHUNK)); } while (0) +#define mono_bitset_clear_fast(set,n) do { (set)->data [(n)/MONO_BITSET_BITS_PER_CHUNK] &= ~((gsize)1 << ((n) % MONO_BITSET_BITS_PER_CHUNK)); } while (0) +#define mono_bitset_get_fast(set,n) ((set)->data[(n)]) + +#define mono_bitset_copyto_fast(src,dest) do { memcpy (&(dest)->data, &(src)->data, (dest)->size / 8); } while (0) + +#define mono_bitset_union_fast(dest,src) do { \ + MonoBitSet *tmp_src = (src); \ + MonoBitSet *tmp_dest = (dest); \ + int i, size; \ + size = tmp_dest->size / MONO_BITSET_BITS_PER_CHUNK; \ + for (i = 0; i < size; ++i) \ + tmp_dest->data [i] |= tmp_src->data [i]; \ +} while (0) + +#define mono_bitset_sub_fast(dest,src) do { \ + MonoBitSet *tmp_src = (src); \ + MonoBitSet *tmp_dest = (dest); \ + int i, size; \ + size = tmp_dest->size / MONO_BITSET_BITS_PER_CHUNK; \ + for (i = 0; i < size; ++i) \ + tmp_dest->data [i] &= ~tmp_src->data [i]; \ +} while (0) /* * Interface documentation can be found in the c-file.