Changeset: 5da8bfcfa942 for MonetDB URL: https://dev.monetdb.org/hg/MonetDB?cmd=changeset;node=5da8bfcfa942 Modified Files: gdk/gdk_aggr.c gdk/gdk_cand.c gdk/gdk_cand.h Branch: unlock Log Message:
Code deduplication: move pop into gdk_cand.h and change the name. diffs (164 lines): diff --git a/gdk/gdk_aggr.c b/gdk/gdk_aggr.c --- a/gdk/gdk_aggr.c +++ b/gdk/gdk_aggr.c @@ -955,27 +955,6 @@ BATgroupsum(BAT *b, BAT *g, BAT *e, BAT return bn; } -/* population count: count number of 1 bits in a value */ -static inline uint32_t __attribute__((__const__)) -pop(uint32_t x) -{ -#ifdef __GNUC__ - return (uint32_t) __builtin_popcount(x); -#else -#ifdef _MSC_VER - return (uint32_t) __popcnt((unsigned int) (x)); -#else - /* divide and conquer implementation */ - x = (x & 0x55555555) + ((x >> 1) & 0x55555555); - x = (x & 0x33333333) + ((x >> 2) & 0x33333333); - x = (x & 0x0F0F0F0F) + ((x >> 4) & 0x0F0F0F0F); - x = (x & 0x00FF00FF) + ((x >> 8) & 0x00FF00FF); - x = (x & 0x0000FFFF) + ((x >> 16) & 0x0000FFFF); - return x; -#endif -#endif -} - static BUN mskCountOnes(BAT *b, struct canditer *ci) { @@ -986,21 +965,21 @@ mskCountOnes(BAT *b, struct canditer *ci int bits = (ci->seq - b->hseqbase) % 32; if (bits + ncand <= 32) { if (ncand == 32) - return pop(src[0]); - return pop(src[0] & (((1U << ncand) - 1) << bits)); + return candmask_pop(src[0]); + return candmask_pop(src[0] & (((1U << ncand) - 1) << bits)); } if (bits != 0) { - cnt = pop(src[0] & (~0U << bits)); + cnt = candmask_pop(src[0] & (~0U << bits)); src++; ncand -= 32 - bits; } while (ncand >= 32) { - cnt += pop(*src); + cnt += candmask_pop(*src); src++; ncand -= 32; } if (ncand > 0) - cnt += pop(*src & ((1U << ncand) - 1)); + cnt += candmask_pop(*src & ((1U << ncand) - 1)); return cnt; } for (BUN i = 0; i < ci->ncand; i++) { diff --git a/gdk/gdk_cand.c b/gdk/gdk_cand.c --- a/gdk/gdk_cand.c +++ b/gdk/gdk_cand.c @@ -374,27 +374,6 @@ binsearchcand(const oid *cand, BUN hi, o return hi; } -/* population count: count number of 1 bits in a value */ -static inline uint32_t __attribute__((__const__)) -pop(uint32_t x) -{ -#ifdef __GNUC__ - return (uint32_t) __builtin_popcount(x); -#else -#ifdef _MSC_VER - return (uint32_t) __popcnt((unsigned int) (x)); -#else - /* divide and conquer implementation */ - x = (x & 0x55555555) + ((x >> 1) & 0x55555555); - x = (x & 0x33333333) + ((x >> 2) & 0x33333333); - x = (x & 0x0F0F0F0F) + ((x >> 4) & 0x0F0F0F0F); - x = (x & 0x00FF00FF) + ((x >> 8) & 0x00FF00FF); - x = (x & 0x0000FFFF) + ((x >> 16) & 0x0000FFFF); - return x; -#endif -#endif -} - /* count number of 1 bits in ci->mask between bit positions lo * (inclusive) and hi (not inclusive) */ static BUN @@ -412,12 +391,12 @@ count_mask_bits(struct canditer *ci, BUN lo %= 32; hi %= 32; if (loi == hii) - return (BUN) pop((ci->mask[loi] & ((1U << hi) - 1)) >> lo); - n = (BUN) pop(ci->mask[loi++] >> lo); + return (BUN) candmask_pop((ci->mask[loi] & ((1U << hi) - 1)) >> lo); + n = (BUN) candmask_pop(ci->mask[loi++] >> lo); while (loi < hii) - n += (BUN) pop(ci->mask[loi++]); + n += (BUN) candmask_pop(ci->mask[loi++]); if (hi != 0) - n += (BUN) pop(ci->mask[loi] & ((1U << hi) - 1)); + n += (BUN) candmask_pop(ci->mask[loi] & ((1U << hi) - 1)); return n; } @@ -867,7 +846,7 @@ canditer_idx(struct canditer *ci, BUN p) break; case cand_mask: { BUN x; - if ((x = pop(ci->mask[0] >> ci->firstbit)) > p) { + if ((x = candmask_pop(ci->mask[0] >> ci->firstbit)) > p) { for (uint8_t i = ci->firstbit; ; i++) { if (ci->mask[0] & (1U << i)) { if (p == 0) @@ -879,7 +858,7 @@ canditer_idx(struct canditer *ci, BUN p) for (BUN n = 1; n < ci->nvals; n++) { uint32_t mask = ci->mask[n]; p -= x; - x = pop(mask); + x = candmask_pop(mask); if (x > p) { for (uint8_t i = 0; ; i++) { if (mask & (1U << i)) { diff --git a/gdk/gdk_cand.h b/gdk/gdk_cand.h --- a/gdk/gdk_cand.h +++ b/gdk/gdk_cand.h @@ -63,7 +63,7 @@ struct canditer { }; /* returns the position of the lowest order bit in x, i.e. the - * smallest n such that (x & (1<<n)) != 0; or -1 if x is 0 */ + * smallest n such that (x & (1<<n)) != 0; must not be called with 0 */ static inline int __attribute__((__const__)) candmask_lobit(uint32_t x) { @@ -86,6 +86,27 @@ candmask_lobit(uint32_t x) #endif } +/* population count: count number of 1 bits in a value */ +static inline uint32_t __attribute__((__const__)) +candmask_pop(uint32_t x) +{ +#ifdef __GNUC__ + return (uint32_t) __builtin_popcount(x); +#else +#ifdef _MSC_VER + return (uint32_t) __popcnt((unsigned int) (x)); +#else + /* divide and conquer implementation */ + x = (x & 0x55555555) + ((x >> 1) & 0x55555555); + x = (x & 0x33333333) + ((x >> 2) & 0x33333333); + x = (x & 0x0F0F0F0F) + ((x >> 4) & 0x0F0F0F0F); + x = (x & 0x00FF00FF) + ((x >> 8) & 0x00FF00FF); + x = (x & 0x0000FFFF) + ((x >> 16) & 0x0000FFFF); + return x; +#endif +#endif +} + #define canditer_next_dense(ci) ((ci)->seq + (ci)->next++) #define canditer_next_mater(ci) ((ci)->oids[(ci)->next++]) static inline oid _______________________________________________ checkin-list mailing list checkin-list@monetdb.org https://www.monetdb.org/mailman/listinfo/checkin-list