From: Vincent Pit Date: Sat, 16 May 2009 07:29:24 +0000 (+0200) Subject: Freshen bitvect.h X-Git-Tag: v0.06~20 X-Git-Url: http://git.vpit.fr/?a=commitdiff_plain;h=7a9796b71b5cbf50959196f91a3183d8815483a2;p=perl%2Fmodules%2FScalar-Vec-Util.git Freshen bitvect.h --- diff --git a/bitvect.h b/bitvect.h index 4721a35..ab9e01b 100644 --- a/bitvect.h +++ b/bitvect.h @@ -24,13 +24,12 @@ #define BV_DO_ALIGNED(T, A) \ mask = BV_MASK_HIGHER(T, BITS(T) - fs); \ if (fs + l <= BITS(T)) { \ - if (fs + l < BITS(T)) { \ - /* Branching is apparently useless, \ - * but since we can't portably shift \ - * CHAR_BITS from a char... \ - * Actually, we only copy up to this */ \ + /* Branching is apparently useless, \ + * but since we can't portably shift \ + * CHAR_BITS from a char... \ + * Actually, we only copy up to this */ \ + if (fs + l < BITS(T)) \ mask &= BV_MASK_LOWER(T, fs + l); \ - } \ *t = (*t & ~mask) | (*f & mask); \ } else { \ size_t lo, lk; \ @@ -52,9 +51,8 @@ step = ts - fs; \ mask = BV_MASK_HIGHER(T, BITS(T) - ts); \ if (ts + l <= BITS(T)) { \ - if (ts + l < BITS(T)) { \ + if (ts + l < BITS(T)) \ mask &= BV_MASK_LOWER(T, ts + l); \ - } \ *t = (*t & ~mask) | ((*f & (mask >> step)) << step); \ } else { \ size_t pets = BITS(T) - step; \ @@ -89,9 +87,8 @@ step = fs - ts; \ mask = BV_MASK_HIGHER(T, BITS(T) - fs); \ if (fs + l <= BITS(T)) { \ - if (fs + l < BITS(T)) { \ + if (fs + l < BITS(T)) \ mask &= BV_MASK_LOWER(T, fs + l); \ - } \ *t = (*t & ~(mask >> step)) | ((*f & mask) >> step); \ } else { \ l -= (BITS(T) - fs); \ @@ -103,7 +100,8 @@ BV_##A##_UNIT_RIGHT_FORWARD(T, t, f, step); \ ++t; ++f; \ } \ - if (!offset) { offset += BITS(T); } \ + if (!offset) \ + offset += BITS(T); \ if (offset > step) { \ mask = BV_MASK_LOWER(T, offset - step); \ *t = (*t & ~mask) | (ins & mask); \ @@ -119,9 +117,8 @@ step = ts - fs; \ mask = BV_MASK_LOWER(T, BITS(T) - ts); \ if (ts + l <= BITS(T)) { \ - if (ts + l < BITS(T)) { \ + if (ts + l < BITS(T)) \ mask &= BV_MASK_HIGHER(T, ts + l); \ - } \ *t = (*t & ~mask) | ((*f & (mask << step)) >> step); \ } else { \ size_t pets = BITS(T) - step; \ @@ -156,9 +153,8 @@ step = fs - ts; \ mask = BV_MASK_LOWER(T, BITS(T) - fs); \ if (fs + l <= BITS(T)) { \ - if (fs + l < BITS(T)) { \ + if (fs + l < BITS(T)) \ mask &= BV_MASK_HIGHER(T, fs + l); \ - } \ *t = (*t & ~(mask << step)) | ((*f & mask) << step); \ } else { \ l -= (BITS(T) - fs); \ @@ -170,7 +166,8 @@ BV_##A##_UNIT_RIGHT_BACKWARD(T, t, f, step); \ --t; --f; \ } \ - if (!offset) { offset += BITS(T); } \ + if (!offset) \ + offset += BITS(T); \ if (offset > step) { \ mask = BV_MASK_HIGHER(T, offset - step); \ *t = (*t & ~mask) | (ins & mask); \ @@ -201,8 +198,11 @@ INLINE_DECLARE(void bv_copy(void *t_, size_t ts, const void *f_, size_t fs, size #ifdef INLINE_DEFINE { size_t offset, step; - T ins, mask, *t = t_; - const T *f = f_, *end; + T ins, mask, *t = (T *) t_; + const T *f = (const T *) f_, *end; + + if (!l) + return; t += ts / BITS(T); ts %= BITS(T); @@ -218,6 +218,7 @@ INLINE_DECLARE(void bv_copy(void *t_, size_t ts, const void *f_, size_t fs, size BV_DO_LEFT_FORWARD(T, COPY); } + return; } #endif /* INLINE_DEFINE */ #undef T @@ -262,9 +263,12 @@ INLINE_DECLARE(void bv_move(void *bv_, size_t ts, size_t fs, size_t l)) #ifdef INLINE_DEFINE { size_t to, fo, offset, step; - T ins, tmp, mask, *bv = bv_, *t, *f; + T ins, tmp, mask, *bv = (T *) bv_, *t, *f; const T *begin, *end; + if (!l) + return; + to = ts % BITS(T); fo = fs % BITS(T); @@ -295,6 +299,7 @@ INLINE_DECLARE(void bv_move(void *bv_, size_t ts, size_t fs, size_t l)) } } + return; } #endif /* INLINE_DEFINE */ #undef T @@ -302,7 +307,7 @@ INLINE_DECLARE(void bv_move(void *bv_, size_t ts, size_t fs, size_t l)) /* ... Compare ............................................................. */ #define BV_EQ(T, B1, B2) \ - if (((T) (B1)) != ((T) (B2))) { return 0; } + if (((T) (B1)) != ((T) (B2))) return 0; #define BV_EQ_MASK(T, B1, B2, M) BV_EQ(T, (B1) & (M), (B2) & (M)) @@ -331,7 +336,8 @@ INLINE_DECLARE(void bv_move(void *bv_, size_t ts, size_t fs, size_t l)) ins = *(B2) >> (B); \ ++(B1); ++(B2); \ } \ - if (!offset) { offset += BITS(T); } \ + if (!offset) \ + offset += BITS(T); \ if (offset >= (B)) { \ mask = BV_MASK_LOWER(T, offset - (B)); \ BV_EQ_MASK(T, *(B1), ins, mask); \ @@ -347,7 +353,7 @@ INLINE_DECLARE(int bv_eq(const void *bv1_, size_t s1, const void *bv2_, size_t s { size_t offset, step; T ins, mask; - const T *bv1 = bv1_, *bv2 = bv2_, *end; + const T *bv1 = (const T *) bv1_, *bv2 = (const T *) bv2_, *end; bv1 += s1 / BITS(T); s1 %= BITS(T); @@ -364,7 +370,7 @@ INLINE_DECLARE(int bv_eq(const void *bv1_, size_t s1, const void *bv2_, size_t s } BV_EQ_MASK(T, *bv1, *bv2, mask); } else { - int ret = 0; + int ret; size_t lo, lk; BV_EQ_MASK(T, *bv1, *bv2, mask); ++bv1; @@ -372,7 +378,8 @@ INLINE_DECLARE(int bv_eq(const void *bv1_, size_t s1, const void *bv2_, size_t s l -= (BITS(T) - s2); lo = l % BITS(T); lk = l / BITS(T); - if ((ret = memcmp(bv1, bv2, lk * sizeof(T))) != 0) { return 0; } + if ((ret = memcmp(bv1, bv2, lk * sizeof(T))) != 0) + return 0; if (lo) { mask = BV_MASK_LOWER(T, lo); BV_EQ_MASK(T, *bv1, *bv2, mask); @@ -384,9 +391,8 @@ INLINE_DECLARE(int bv_eq(const void *bv1_, size_t s1, const void *bv2_, size_t s step = s2 - s1; mask = BV_MASK_HIGHER(T, BITS(T) - s2); if (s2 + l <= BITS(T)) { - if (s2 + l < BITS(T)) { + if (s2 + l < BITS(T)) mask &= BV_MASK_LOWER(T, s2 + l); - } BV_EQ(T, *bv1 & (mask >> step), (*bv2 & mask) >> step); } else { l -= (BITS(T) - s2); @@ -399,7 +405,8 @@ INLINE_DECLARE(int bv_eq(const void *bv1_, size_t s1, const void *bv2_, size_t s ins = *bv2 >> step; ++bv1; ++bv2; } - if (!offset) { offset += BITS(T); } + if (!offset) + offset += BITS(T); if (offset >= step) { mask = BV_MASK_LOWER(T, offset - step); BV_EQ_MASK(T, *bv1, ins, mask); @@ -408,6 +415,7 @@ INLINE_DECLARE(int bv_eq(const void *bv1_, size_t s1, const void *bv2_, size_t s BV_EQ(T, *bv1 & ~(~mask << (BITS(T) - step)), ((*bv2 & mask) << (BITS(T) - step)) | ins); } +/* BV_EQ_RIGHT(T, bv1, bv2, l, step); */ } } else { /* s1 > s2 */ @@ -415,9 +423,8 @@ INLINE_DECLARE(int bv_eq(const void *bv1_, size_t s1, const void *bv2_, size_t s step = s1 - s2; mask = BV_MASK_HIGHER(T, BITS(T) - s1); if (s1 + l <= BITS(T)) { - if (s1 + l < BITS(T)) { + if (s1 + l < BITS(T)) mask &= BV_MASK_LOWER(T, s1 + l); - } BV_EQ(T, *bv1 & mask, (*bv2 & (mask >> step)) << step); } else { size_t pets = BITS(T) - step; @@ -445,6 +452,7 @@ INLINE_DECLARE(int bv_eq(const void *bv1_, size_t s1, const void *bv2_, size_t s mask = BV_MASK_LOWER(T, offset); BV_EQ_MASK(T, *bv1, ins, mask); } +/* BV_EQ_LEFT(T, bv1, bv2, l, step); */ } } @@ -462,18 +470,21 @@ INLINE_DECLARE(void bv_fill(void *bv_, size_t s, size_t l, unsigned int f)) #ifdef INLINE_DEFINE { size_t o, k; - T mask, *bv = bv_; + T mask, *bv = (T *) bv_; + + if (!l) + return; - if (f) { f = ~0; } + if (f) + f = ~0; bv += s / BITS(T); o = s % BITS(T); mask = BV_MASK_HIGHER(T, BITS(T) - o); if (o + l <= BITS(T)) { - if (o + l < BITS(T)) { + if (o + l < BITS(T)) mask &= BV_MASK_LOWER(T, o + l); - } *bv = (*bv & ~mask) | (f & mask); } else { *bv = (*bv & ~mask) | (f & mask); @@ -489,6 +500,7 @@ INLINE_DECLARE(void bv_fill(void *bv_, size_t s, size_t l, unsigned int f)) } } + return; } #endif /* INLINE_DEFINE */ #undef T