diff options
author | thegeorg <thegeorg@yandex-team.com> | 2024-06-29 11:45:54 +0300 |
---|---|---|
committer | thegeorg <thegeorg@yandex-team.com> | 2024-06-29 11:54:41 +0300 |
commit | 9158d9115725ca7f4ada745ec55eddd5747bc61e (patch) | |
tree | f262cd6d7a98bb367943a4918b6963a7800f3937 /contrib/tools/bison/lib/abitset.c | |
parent | 632b3cedb8e12fbbb0bcd1bdbf7ec5686725b7e9 (diff) | |
download | ydb-9158d9115725ca7f4ada745ec55eddd5747bc61e.tar.gz |
Update contrib/tools/bison to 3.2.4
78e59a97f3fde03511ddb9969cd1daabbaf998bd
Diffstat (limited to 'contrib/tools/bison/lib/abitset.c')
-rw-r--r-- | contrib/tools/bison/lib/abitset.c | 192 |
1 files changed, 68 insertions, 124 deletions
diff --git a/contrib/tools/bison/lib/abitset.c b/contrib/tools/bison/lib/abitset.c index 830fdefcfc..0d6b9a5d8a 100644 --- a/contrib/tools/bison/lib/abitset.c +++ b/contrib/tools/bison/lib/abitset.c @@ -35,33 +35,28 @@ static bitset_bindex abitset_resize (bitset src, bitset_bindex size) { - /* These bitsets have a fixed size. */ - if (BITSET_SIZE_ (src) != size) - abort (); + /* These bitsets have a fixed size. */ + if (BITSET_SIZE_ (src) != size) + abort (); - return size; + return size; } /* Find list of up to NUM bits set in BSET starting from and including - *NEXT and store in array LIST. Return with actual number of bits - found and with *NEXT indicating where search stopped. */ + *NEXT and store in array LIST. Return with actual number of bits + found and with *NEXT indicating where search stopped. */ static bitset_bindex abitset_small_list (bitset src, bitset_bindex *list, bitset_bindex num, bitset_bindex *next) { - bitset_bindex bitno; - bitset_bindex count; - bitset_windex size; - bitset_word word; - - word = ABITSET_WORDS (src)[0]; + bitset_word word = ABITSET_WORDS (src)[0]; /* Short circuit common case. */ if (!word) return 0; - size = BITSET_SIZE_ (src); - bitno = *next; + bitset_windex size = BITSET_SIZE_ (src); + bitset_bindex bitno = *next; if (bitno >= size) return 0; @@ -70,6 +65,7 @@ abitset_small_list (bitset src, bitset_bindex *list, /* If num is 1, we could speed things up with a binary search of the word of interest. */ + bitset_bindex count; if (num >= BITSET_WORD_BITS) { for (count = 0; word; bitno++) @@ -142,36 +138,27 @@ static bitset_bindex abitset_list_reverse (bitset src, bitset_bindex *list, bitset_bindex num, bitset_bindex *next) { - bitset_bindex bitno; - bitset_bindex rbitno; - bitset_bindex count; - bitset_windex windex; - unsigned bitcnt; - bitset_bindex bitoff; + bitset_bindex rbitno = *next; bitset_word *srcp = ABITSET_WORDS (src); bitset_bindex n_bits = BITSET_SIZE_ (src); - rbitno = *next; - /* If num is 1, we could speed things up with a binary search of the word of interest. */ if (rbitno >= n_bits) return 0; - count = 0; + bitset_bindex count = 0; - bitno = n_bits - (rbitno + 1); + bitset_bindex bitno = n_bits - (rbitno + 1); - windex = bitno / BITSET_WORD_BITS; - bitcnt = bitno % BITSET_WORD_BITS; - bitoff = windex * BITSET_WORD_BITS; + bitset_windex windex = bitno / BITSET_WORD_BITS; + unsigned bitcnt = bitno % BITSET_WORD_BITS; + bitset_bindex bitoff = windex * BITSET_WORD_BITS; do { - bitset_word word; - - word = srcp[windex] << (BITSET_WORD_BITS - 1 - bitcnt); + bitset_word word = srcp[windex] << (BITSET_WORD_BITS - 1 - bitcnt); for (; word; bitcnt--) { if (word & BITSET_MSB) @@ -196,23 +183,20 @@ abitset_list_reverse (bitset src, bitset_bindex *list, /* Find list of up to NUM bits set in BSET starting from and including - *NEXT and store in array LIST. Return with actual number of bits - found and with *NEXT indicating where search stopped. */ + *NEXT and store in array LIST. Return with actual number of bits + found and with *NEXT indicating where search stopped. */ static bitset_bindex abitset_list (bitset src, bitset_bindex *list, bitset_bindex num, bitset_bindex *next) { - bitset_bindex bitno; - bitset_bindex count; bitset_windex windex; bitset_bindex bitoff; bitset_windex size = src->b.csize; bitset_word *srcp = ABITSET_WORDS (src); - bitset_word word; - bitno = *next; + bitset_bindex bitno = *next; - count = 0; + bitset_bindex count = 0; if (!bitno) { /* Many bitsets are zero, so make this common case fast. */ @@ -242,7 +226,7 @@ abitset_list (bitset src, bitset_bindex *list, on the previous call to this function. */ bitoff = windex * BITSET_WORD_BITS; - word = srcp[windex] >> bitno; + bitset_word word = srcp[windex] >> bitno; for (bitno = bitoff + bitno; word; bitno++) { if (word & 1) @@ -263,7 +247,8 @@ abitset_list (bitset src, bitset_bindex *list, for (; windex < size; windex++, bitoff += BITSET_WORD_BITS) { - if (!(word = srcp[windex])) + bitset_word word = srcp[windex]; + if (!word) continue; if ((count + BITSET_WORD_BITS) < num) @@ -302,9 +287,7 @@ abitset_list (bitset src, bitset_bindex *list, static inline void abitset_unused_clear (bitset dst) { - unsigned last_bit; - - last_bit = BITSET_SIZE_ (dst) % BITSET_WORD_BITS; + unsigned last_bit = BITSET_SIZE_ (dst) % BITSET_WORD_BITS; if (last_bit) ABITSET_WORDS (dst)[dst->b.csize - 1] &= ((bitset_word) 1 << last_bit) - 1; @@ -315,9 +298,7 @@ static void abitset_ones (bitset dst) { bitset_word *dstp = ABITSET_WORDS (dst); - size_t bytes; - - bytes = sizeof (bitset_word) * dst->b.csize; + size_t bytes = sizeof (bitset_word) * dst->b.csize; memset (dstp, -1, bytes); abitset_unused_clear (dst); @@ -328,9 +309,7 @@ static void abitset_zero (bitset dst) { bitset_word *dstp = ABITSET_WORDS (dst); - size_t bytes; - - bytes = sizeof (bitset_word) * dst->b.csize; + size_t bytes = sizeof (bitset_word) * dst->b.csize; memset (dstp, 0, bytes); } @@ -339,13 +318,11 @@ abitset_zero (bitset dst) static bool abitset_empty_p (bitset dst) { - bitset_windex i; bitset_word *dstp = ABITSET_WORDS (dst); - for (i = 0; i < dst->b.csize; i++) + for (bitset_windex i = 0; i < dst->b.csize; i++) if (dstp[i]) return false; - return true; } @@ -355,10 +332,9 @@ abitset_copy1 (bitset dst, bitset src) { bitset_word *srcp = ABITSET_WORDS (src); bitset_word *dstp = ABITSET_WORDS (dst); - bitset_windex size = dst->b.csize; - if (srcp == dstp) - return; + return; + bitset_windex size = dst->b.csize; memcpy (dstp, srcp, sizeof (bitset_word) * size); } @@ -366,13 +342,12 @@ abitset_copy1 (bitset dst, bitset src) static void abitset_not (bitset dst, bitset src) { - bitset_windex i; bitset_word *srcp = ABITSET_WORDS (src); bitset_word *dstp = ABITSET_WORDS (dst); bitset_windex size = dst->b.csize; - for (i = 0; i < size; i++) - *dstp++ = ~(*srcp++); + for (bitset_windex i = 0; i < size; i++) + *dstp++ = ~(*srcp++); abitset_unused_clear (dst); } @@ -380,14 +355,13 @@ abitset_not (bitset dst, bitset src) static bool abitset_equal_p (bitset dst, bitset src) { - bitset_windex i; bitset_word *srcp = ABITSET_WORDS (src); bitset_word *dstp = ABITSET_WORDS (dst); bitset_windex size = dst->b.csize; - for (i = 0; i < size; i++) - if (*srcp++ != *dstp++) - return false; + for (bitset_windex i = 0; i < size; i++) + if (*srcp++ != *dstp++) + return false; return true; } @@ -395,14 +369,13 @@ abitset_equal_p (bitset dst, bitset src) static bool abitset_subset_p (bitset dst, bitset src) { - bitset_windex i; bitset_word *srcp = ABITSET_WORDS (src); bitset_word *dstp = ABITSET_WORDS (dst); bitset_windex size = dst->b.csize; - for (i = 0; i < size; i++, dstp++, srcp++) - if (*dstp != (*srcp | *dstp)) - return false; + for (bitset_windex i = 0; i < size; i++, dstp++, srcp++) + if (*dstp != (*srcp | *dstp)) + return false; return true; } @@ -410,15 +383,13 @@ abitset_subset_p (bitset dst, bitset src) static bool abitset_disjoint_p (bitset dst, bitset src) { - bitset_windex i; bitset_word *srcp = ABITSET_WORDS (src); bitset_word *dstp = ABITSET_WORDS (dst); bitset_windex size = dst->b.csize; - for (i = 0; i < size; i++) - if (*srcp++ & *dstp++) - return false; - + for (bitset_windex i = 0; i < size; i++) + if (*srcp++ & *dstp++) + return false; return true; } @@ -426,31 +397,28 @@ abitset_disjoint_p (bitset dst, bitset src) static void abitset_and (bitset dst, bitset src1, bitset src2) { - bitset_windex i; bitset_word *src1p = ABITSET_WORDS (src1); bitset_word *src2p = ABITSET_WORDS (src2); bitset_word *dstp = ABITSET_WORDS (dst); bitset_windex size = dst->b.csize; - for (i = 0; i < size; i++) - *dstp++ = *src1p++ & *src2p++; + for (bitset_windex i = 0; i < size; i++) + *dstp++ = *src1p++ & *src2p++; } static bool abitset_and_cmp (bitset dst, bitset src1, bitset src2) { - bitset_windex i; bool changed = false; bitset_word *src1p = ABITSET_WORDS (src1); bitset_word *src2p = ABITSET_WORDS (src2); bitset_word *dstp = ABITSET_WORDS (dst); bitset_windex size = dst->b.csize; - for (i = 0; i < size; i++, dstp++) + for (bitset_windex i = 0; i < size; i++, dstp++) { bitset_word tmp = *src1p++ & *src2p++; - if (*dstp != tmp) { changed = true; @@ -464,31 +432,28 @@ abitset_and_cmp (bitset dst, bitset src1, bitset src2) static void abitset_andn (bitset dst, bitset src1, bitset src2) { - bitset_windex i; bitset_word *src1p = ABITSET_WORDS (src1); bitset_word *src2p = ABITSET_WORDS (src2); bitset_word *dstp = ABITSET_WORDS (dst); bitset_windex size = dst->b.csize; - for (i = 0; i < size; i++) - *dstp++ = *src1p++ & ~(*src2p++); + for (bitset_windex i = 0; i < size; i++) + *dstp++ = *src1p++ & ~(*src2p++); } static bool abitset_andn_cmp (bitset dst, bitset src1, bitset src2) { - bitset_windex i; bool changed = false; bitset_word *src1p = ABITSET_WORDS (src1); bitset_word *src2p = ABITSET_WORDS (src2); bitset_word *dstp = ABITSET_WORDS (dst); bitset_windex size = dst->b.csize; - for (i = 0; i < size; i++, dstp++) + for (bitset_windex i = 0; i < size; i++, dstp++) { bitset_word tmp = *src1p++ & ~(*src2p++); - if (*dstp != tmp) { changed = true; @@ -502,28 +467,26 @@ abitset_andn_cmp (bitset dst, bitset src1, bitset src2) static void abitset_or (bitset dst, bitset src1, bitset src2) { - bitset_windex i; bitset_word *src1p = ABITSET_WORDS (src1); bitset_word *src2p = ABITSET_WORDS (src2); bitset_word *dstp = ABITSET_WORDS (dst); bitset_windex size = dst->b.csize; - for (i = 0; i < size; i++) - *dstp++ = *src1p++ | *src2p++; + for (bitset_windex i = 0; i < size; i++) + *dstp++ = *src1p++ | *src2p++; } static bool abitset_or_cmp (bitset dst, bitset src1, bitset src2) { - bitset_windex i; bool changed = false; bitset_word *src1p = ABITSET_WORDS (src1); bitset_word *src2p = ABITSET_WORDS (src2); bitset_word *dstp = ABITSET_WORDS (dst); bitset_windex size = dst->b.csize; - for (i = 0; i < size; i++, dstp++) + for (bitset_windex i = 0; i < size; i++, dstp++) { bitset_word tmp = *src1p++ | *src2p++; @@ -540,28 +503,26 @@ abitset_or_cmp (bitset dst, bitset src1, bitset src2) static void abitset_xor (bitset dst, bitset src1, bitset src2) { - bitset_windex i; bitset_word *src1p = ABITSET_WORDS (src1); bitset_word *src2p = ABITSET_WORDS (src2); bitset_word *dstp = ABITSET_WORDS (dst); bitset_windex size = dst->b.csize; - for (i = 0; i < size; i++) - *dstp++ = *src1p++ ^ *src2p++; + for (bitset_windex i = 0; i < size; i++) + *dstp++ = *src1p++ ^ *src2p++; } static bool abitset_xor_cmp (bitset dst, bitset src1, bitset src2) { - bitset_windex i; bool changed = false; bitset_word *src1p = ABITSET_WORDS (src1); bitset_word *src2p = ABITSET_WORDS (src2); bitset_word *dstp = ABITSET_WORDS (dst); bitset_windex size = dst->b.csize; - for (i = 0; i < size; i++, dstp++) + for (bitset_windex i = 0; i < size; i++, dstp++) { bitset_word tmp = *src1p++ ^ *src2p++; @@ -578,22 +539,20 @@ abitset_xor_cmp (bitset dst, bitset src1, bitset src2) static void abitset_and_or (bitset dst, bitset src1, bitset src2, bitset src3) { - bitset_windex i; bitset_word *src1p = ABITSET_WORDS (src1); bitset_word *src2p = ABITSET_WORDS (src2); bitset_word *src3p = ABITSET_WORDS (src3); bitset_word *dstp = ABITSET_WORDS (dst); bitset_windex size = dst->b.csize; - for (i = 0; i < size; i++) - *dstp++ = (*src1p++ & *src2p++) | *src3p++; + for (bitset_windex i = 0; i < size; i++) + *dstp++ = (*src1p++ & *src2p++) | *src3p++; } static bool abitset_and_or_cmp (bitset dst, bitset src1, bitset src2, bitset src3) { - bitset_windex i; bool changed = false; bitset_word *src1p = ABITSET_WORDS (src1); bitset_word *src2p = ABITSET_WORDS (src2); @@ -601,10 +560,9 @@ abitset_and_or_cmp (bitset dst, bitset src1, bitset src2, bitset src3) bitset_word *dstp = ABITSET_WORDS (dst); bitset_windex size = dst->b.csize; - for (i = 0; i < size; i++, dstp++) + for (bitset_windex i = 0; i < size; i++, dstp++) { bitset_word tmp = (*src1p++ & *src2p++) | *src3p++; - if (*dstp != tmp) { changed = true; @@ -618,22 +576,20 @@ abitset_and_or_cmp (bitset dst, bitset src1, bitset src2, bitset src3) static void abitset_andn_or (bitset dst, bitset src1, bitset src2, bitset src3) { - bitset_windex i; bitset_word *src1p = ABITSET_WORDS (src1); bitset_word *src2p = ABITSET_WORDS (src2); bitset_word *src3p = ABITSET_WORDS (src3); bitset_word *dstp = ABITSET_WORDS (dst); bitset_windex size = dst->b.csize; - for (i = 0; i < size; i++) - *dstp++ = (*src1p++ & ~(*src2p++)) | *src3p++; + for (bitset_windex i = 0; i < size; i++) + *dstp++ = (*src1p++ & ~(*src2p++)) | *src3p++; } static bool abitset_andn_or_cmp (bitset dst, bitset src1, bitset src2, bitset src3) { - bitset_windex i; bool changed = false; bitset_word *src1p = ABITSET_WORDS (src1); bitset_word *src2p = ABITSET_WORDS (src2); @@ -641,10 +597,9 @@ abitset_andn_or_cmp (bitset dst, bitset src1, bitset src2, bitset src3) bitset_word *dstp = ABITSET_WORDS (dst); bitset_windex size = dst->b.csize; - for (i = 0; i < size; i++, dstp++) + for (bitset_windex i = 0; i < size; i++, dstp++) { bitset_word tmp = (*src1p++ & ~(*src2p++)) | *src3p++; - if (*dstp != tmp) { changed = true; @@ -658,22 +613,20 @@ abitset_andn_or_cmp (bitset dst, bitset src1, bitset src2, bitset src3) static void abitset_or_and (bitset dst, bitset src1, bitset src2, bitset src3) { - bitset_windex i; bitset_word *src1p = ABITSET_WORDS (src1); bitset_word *src2p = ABITSET_WORDS (src2); bitset_word *src3p = ABITSET_WORDS (src3); bitset_word *dstp = ABITSET_WORDS (dst); bitset_windex size = dst->b.csize; - for (i = 0; i < size; i++) - *dstp++ = (*src1p++ | *src2p++) & *src3p++; + for (bitset_windex i = 0; i < size; i++) + *dstp++ = (*src1p++ | *src2p++) & *src3p++; } static bool abitset_or_and_cmp (bitset dst, bitset src1, bitset src2, bitset src3) { - bitset_windex i; bool changed = false; bitset_word *src1p = ABITSET_WORDS (src1); bitset_word *src2p = ABITSET_WORDS (src2); @@ -681,10 +634,9 @@ abitset_or_and_cmp (bitset dst, bitset src1, bitset src2, bitset src3) bitset_word *dstp = ABITSET_WORDS (dst); bitset_windex size = dst->b.csize; - for (i = 0; i < size; i++, dstp++) + for (bitset_windex i = 0; i < size; i++, dstp++) { bitset_word tmp = (*src1p++ | *src2p++) & *src3p++; - if (*dstp != tmp) { changed = true; @@ -699,9 +651,9 @@ static void abitset_copy (bitset dst, bitset src) { if (BITSET_COMPATIBLE_ (dst, src)) - abitset_copy1 (dst, src); + abitset_copy1 (dst, src); else - bitset_copy_ (dst, src); + bitset_copy_ (dst, src); } @@ -784,14 +736,12 @@ struct bitset_vtable abitset_vtable = { size_t abitset_bytes (bitset_bindex n_bits) { - bitset_windex size; - size_t bytes; size_t header_size = offsetof (union bitset_union, a.words); struct bitset_align_struct { char a; union bitset_union b; }; size_t bitset_alignment = offsetof (struct bitset_align_struct, b); - size = ABITSET_N_WORDS (n_bits); - bytes = header_size + size * sizeof (bitset_word); + bitset_windex size = ABITSET_N_WORDS (n_bits); + size_t bytes = header_size + size * sizeof (bitset_word); /* Align the size properly for a vector of abitset objects. */ if (header_size % bitset_alignment != 0 @@ -808,19 +758,13 @@ abitset_bytes (bitset_bindex n_bits) bitset abitset_init (bitset bset, bitset_bindex n_bits) { - bitset_windex size; - - size = ABITSET_N_WORDS (n_bits); + bitset_windex size = ABITSET_N_WORDS (n_bits); BITSET_NBITS_ (bset) = n_bits; /* Use optimized routines if bitset fits within a single word. There is probably little merit if using caching since the small bitset will always fit in the cache. */ - if (size == 1) - bset->b.vtable = &abitset_small_vtable; - else - bset->b.vtable = &abitset_vtable; - + bset->b.vtable = size == 1 ? &abitset_small_vtable : &abitset_vtable; bset->b.cindex = 0; bset->b.csize = size; bset->b.cdata = ABITSET_WORDS (bset); |