guint32 real_size = (max_size + BITS_PER_CHUNK - 1) / BITS_PER_CHUNK;
MonoBitSet *result;
- result = g_malloc0 (sizeof (MonoBitSet) + sizeof (gsize) * (real_size - MONO_ZERO_LEN_ARRAY));
+ result = (MonoBitSet *) g_malloc0 (sizeof (MonoBitSet) + sizeof (gsize) * (real_size - MONO_ZERO_LEN_ARRAY));
result->size = real_size * BITS_PER_CHUNK;
result->flags = flags;
return result;
MonoBitSet *
mono_bitset_mem_new (gpointer mem, guint32 max_size, guint32 flags) {
guint32 real_size = (max_size + BITS_PER_CHUNK - 1) / BITS_PER_CHUNK;
- MonoBitSet *result = mem;
+ MonoBitSet *result = (MonoBitSet *) mem;
result->size = real_size * BITS_PER_CHUNK;
result->flags = flags | MONO_BITSET_DONT_FREE;
count = 0;
for (i = 0; i < set->size / BITS_PER_CHUNK; ++i) {
d = set->data [i];
- /* there is probably some asm code that can do this much faster */
- if (d) {
-#if SIZEOF_VOID_P == 8
- /* http://www.jjj.de/bitwizardry/bitwizardrypage.html */
- d -= (d>>1) & 0x5555555555555555;
- d = ((d>>2) & 0x3333333333333333) + (d & 0x3333333333333333);
- d = ((d>>4) + d) & 0x0f0f0f0f0f0f0f0f;
- d *= 0x0101010101010101;
- count += d >> 56;
+#ifdef __GNUC__
+ if (sizeof (gsize) == sizeof (unsigned long))
+ count += __builtin_popcountl (d);
+ else
+ count += __builtin_popcount (d);
#else
- /* http://aggregate.org/MAGIC/ */
- d -= ((d >> 1) & 0x55555555);
- d = (((d >> 2) & 0x33333333) + (d & 0x33333333));
- d = (((d >> 4) + d) & 0x0f0f0f0f);
- d += (d >> 8);
- d += (d >> 16);
- count += (d & 0x0000003f);
-#endif
+ while (d) {
+ count ++;
+ d &= (d - 1);
}
+#endif
}
return count;
}