From 006f76b4f791d3b879ea967171bb67d5aa59e3b0 Mon Sep 17 00:00:00 2001 From: Zachary Dremann Date: Tue, 30 Jul 2024 15:28:31 -0400 Subject: [PATCH] Bump to croaring 4.1.1 No API changes, just implementation --- Cargo.lock | 2 +- README.md | 2 +- .../CRoaring/bindgen_bundled_version.rs | 6 +- croaring-sys/CRoaring/roaring.c | 145 ++++++++++++------ croaring-sys/CRoaring/roaring.h | 8 +- croaring-sys/CRoaring/roaring.hh | 2 +- croaring-sys/Cargo.toml | 2 +- croaring-sys/build.rs | 2 +- croaring/src/bitmap/imp.rs | 2 +- croaring/src/bitmap/ops.rs | 2 +- croaring/src/bitmap/view.rs | 2 +- 11 files changed, 115 insertions(+), 60 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 269473c..ae6e87f 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -186,7 +186,7 @@ dependencies = [ [[package]] name = "croaring-sys" -version = "4.1.0" +version = "4.1.1" dependencies = [ "cc", ] diff --git a/README.md b/README.md index dfe98e9..91f7c06 100644 --- a/README.md +++ b/README.md @@ -127,7 +127,7 @@ Current documentation is available at https://docs.rs/croaring/latest/croaring/ ## CRoaring Version -This crate uses [CRoaring version `4.1.0`](https://github.com/RoaringBitmap/CRoaring/releases/tag/v4.1.0). +This crate uses [CRoaring version `4.1.1`](https://github.com/RoaringBitmap/CRoaring/releases/tag/v4.1.1). The version of this crate does not necessarily match the version of CRoaring: the major version of the crate is only incremented when there are breaking changes in the Rust API: It is possible (and has happened) that breaking changes in the CRoaring C API do not necessitate a major version bump in this crate. \ No newline at end of file diff --git a/croaring-sys/CRoaring/bindgen_bundled_version.rs b/croaring-sys/CRoaring/bindgen_bundled_version.rs index f3aa8c3..afa695e 100644 --- a/croaring-sys/CRoaring/bindgen_bundled_version.rs +++ b/croaring-sys/CRoaring/bindgen_bundled_version.rs @@ -1,9 +1,9 @@ /* automatically generated by rust-bindgen 0.69.4 */ -pub const ROARING_VERSION: &[u8; 6] = b"4.0.0\0"; +pub const ROARING_VERSION: &[u8; 6] = b"4.1.1\0"; pub const ROARING_VERSION_MAJOR: _bindgen_ty_1 = 4; -pub const ROARING_VERSION_MINOR: _bindgen_ty_1 = 0; -pub const ROARING_VERSION_REVISION: _bindgen_ty_1 = 0; +pub const ROARING_VERSION_MINOR: _bindgen_ty_1 = 1; +pub const ROARING_VERSION_REVISION: _bindgen_ty_1 = 1; pub type _bindgen_ty_1 = ::core::ffi::c_uint; extern "C" { #[doc = " result might be undefined when input_num is zero"] diff --git a/croaring-sys/CRoaring/roaring.c b/croaring-sys/CRoaring/roaring.c index 10cc715..21489cd 100644 --- a/croaring-sys/CRoaring/roaring.c +++ b/croaring-sys/CRoaring/roaring.c @@ -1,5 +1,5 @@ // !!! DO NOT EDIT - THIS IS AN AUTO-GENERATED FILE !!! -// Created by amalgamation.sh on 2024-07-03T21:30:32Z +// Created by amalgamation.sh on 2024-07-30T19:32:00Z /* * The CRoaring project is under a dual license (Apache/MIT). @@ -12787,11 +12787,8 @@ int array_container_shrink_to_fit(array_container_t *src) { /* Free memory. */ void array_container_free(array_container_t *arr) { - if (arr->array != - NULL) { // Jon Strabala reports that some tools complain otherwise - roaring_free(arr->array); - arr->array = NULL; // pedantic - } + if (arr == NULL) return; + roaring_free(arr->array); roaring_free(arr); } @@ -12819,10 +12816,7 @@ void array_container_grow(array_container_t *container, int32_t min, (uint16_t *)roaring_realloc(array, new_capacity * sizeof(uint16_t)); if (container->array == NULL) roaring_free(array); } else { - // Jon Strabala reports that some tools complain otherwise - if (array != NULL) { - roaring_free(array); - } + roaring_free(array); container->array = (uint16_t *)roaring_malloc(new_capacity * sizeof(uint16_t)); } @@ -13343,11 +13337,8 @@ void bitset_container_add_from_range(bitset_container_t *bitset, uint32_t min, /* Free memory. */ void bitset_container_free(bitset_container_t *bitset) { - if (bitset->words != - NULL) { // Jon Strabala reports that some tools complain otherwise - roaring_aligned_free(bitset->words); - bitset->words = NULL; // pedantic - } + if (bitset == NULL) return; + roaring_aligned_free(bitset->words); roaring_free(bitset); } @@ -17979,11 +17970,8 @@ void run_container_offset(const run_container_t *c, container_t **loc, /* Free memory. */ void run_container_free(run_container_t *run) { - if (run->runs != - NULL) { // Jon Strabala reports that some tools complain otherwise - roaring_free(run->runs); - run->runs = NULL; // pedantic - } + if (run == NULL) return; + roaring_free(run->runs); roaring_free(run); } @@ -18001,10 +17989,7 @@ void run_container_grow(run_container_t *run, int32_t min, bool copy) { run->capacity * sizeof(rle16_t)); if (run->runs == NULL) roaring_free(oldruns); } else { - // Jon Strabala reports that some tools complain otherwise - if (run->runs != NULL) { - roaring_free(run->runs); - } + roaring_free(run->runs); run->runs = (rle16_t *)roaring_malloc(run->capacity * sizeof(rle16_t)); } // We may have run->runs == NULL. @@ -18426,24 +18411,6 @@ void run_container_andnot(const run_container_t *src_1, } } -ALLOW_UNALIGNED -int run_container_to_uint32_array(void *vout, const run_container_t *cont, - uint32_t base) { - int outpos = 0; - uint32_t *out = (uint32_t *)vout; - for (int i = 0; i < cont->n_runs; ++i) { - uint32_t run_start = base + cont->runs[i].value; - uint16_t le = cont->runs[i].length; - for (int j = 0; j <= le; ++j) { - uint32_t val = run_start + j; - memcpy(out + outpos, &val, - sizeof(uint32_t)); // should be compiled as a MOV on x64 - outpos++; - } - } - return outpos; -} - /* * Print this container using printf (useful for debugging). */ @@ -18816,6 +18783,47 @@ static inline int _avx2_run_container_cardinality(const run_container_t *run) { return sum; } +ALLOW_UNALIGNED +int _avx2_run_container_to_uint32_array(void *vout, const run_container_t *cont, + uint32_t base) { + int outpos = 0; + uint32_t *out = (uint32_t *)vout; + + for (int i = 0; i < cont->n_runs; ++i) { + uint32_t run_start = base + cont->runs[i].value; + uint16_t le = cont->runs[i].length; + if (le < 8) { + for (int j = 0; j <= le; ++j) { + uint32_t val = run_start + j; + memcpy(out + outpos, &val, + sizeof(uint32_t)); // should be compiled as a MOV on x64 + outpos++; + } + } else { + int j = 0; + __m256i run_start_v = _mm256_set1_epi32(run_start); + // [8,8,8,8....] + __m256i inc = _mm256_set1_epi32(8); + // used for generate sequence: + // [0, 1, 2, 3...], [8, 9, 10,...] + __m256i delta = _mm256_setr_epi32(0, 1, 2, 3, 4, 5, 6, 7); + for (j = 0; j + 8 <= le; j += 8) { + __m256i val_v = _mm256_add_epi32(run_start_v, delta); + _mm256_storeu_si256((__m256i *)(out + outpos), val_v); + delta = _mm256_add_epi32(inc, delta); + outpos += 8; + } + for (; j <= le; ++j) { + uint32_t val = run_start + j; + memcpy(out + outpos, &val, + sizeof(uint32_t)); // should be compiled as a MOV on x64 + outpos++; + } + } + } + return outpos; +} + CROARING_UNTARGET_AVX2 /* Get the cardinality of `run'. Requires an actual computation. */ @@ -18845,6 +18853,34 @@ int run_container_cardinality(const run_container_t *run) { return _scalar_run_container_cardinality(run); } } + +int _scalar_run_container_to_uint32_array(void *vout, + const run_container_t *cont, + uint32_t base) { + int outpos = 0; + uint32_t *out = (uint32_t *)vout; + for (int i = 0; i < cont->n_runs; ++i) { + uint32_t run_start = base + cont->runs[i].value; + uint16_t le = cont->runs[i].length; + for (int j = 0; j <= le; ++j) { + uint32_t val = run_start + j; + memcpy(out + outpos, &val, + sizeof(uint32_t)); // should be compiled as a MOV on x64 + outpos++; + } + } + return outpos; +} + +int run_container_to_uint32_array(void *vout, const run_container_t *cont, + uint32_t base) { + if (croaring_hardware_support() & ROARING_SUPPORTS_AVX2) { + return _avx2_run_container_to_uint32_array(vout, cont, base); + } else { + return _scalar_run_container_to_uint32_array(vout, cont, base); + } +} + #else /* Get the cardinality of `run'. Requires an actual computation. */ @@ -18861,6 +18897,25 @@ int run_container_cardinality(const run_container_t *run) { return sum; } + +ALLOW_UNALIGNED +int run_container_to_uint32_array(void *vout, const run_container_t *cont, + uint32_t base) { + int outpos = 0; + uint32_t *out = (uint32_t *)vout; + for (int i = 0; i < cont->n_runs; ++i) { + uint32_t run_start = base + cont->runs[i].value; + uint16_t le = cont->runs[i].length; + for (int j = 0; j <= le; ++j) { + uint32_t val = run_start + j; + memcpy(out + outpos, &val, + sizeof(uint32_t)); // should be compiled as a MOV on x64 + outpos++; + } + } + return outpos; +} + #endif #ifdef __cplusplus @@ -18922,15 +18977,15 @@ POSSIBILITY OF SUCH DAMAGE. #include #include -// Binaries produced by Visual Studio with solely AVX2 routines +// Binaries produced by Visual Studio 19.38 with solely AVX2 routines // can compile to AVX-512 thus causing crashes on non-AVX-512 systems. // This appears to affect VS 17.8 and 17.9. We disable AVX-512 and AVX2 // on these systems. It seems that ClangCL is not affected. // https://github.com/RoaringBitmap/CRoaring/pull/603 #ifndef __clang__ -#if _MSC_VER >= 1938 +#if _MSC_VER == 1938 #define ROARING_DISABLE_AVX 1 -#endif // _MSC_VER >= 1938 +#endif // _MSC_VER == 1938 #endif // __clang__ // We need portability.h to be included first, see diff --git a/croaring-sys/CRoaring/roaring.h b/croaring-sys/CRoaring/roaring.h index d33c13e..faf8587 100644 --- a/croaring-sys/CRoaring/roaring.h +++ b/croaring-sys/CRoaring/roaring.h @@ -1,5 +1,5 @@ // !!! DO NOT EDIT - THIS IS AN AUTO-GENERATED FILE !!! -// Created by amalgamation.sh on 2024-07-03T21:30:32Z +// Created by amalgamation.sh on 2024-07-30T19:32:00Z /* * The CRoaring project is under a dual license (Apache/MIT). @@ -59,11 +59,11 @@ // /include/roaring/roaring_version.h automatically generated by release.py, do not change by hand #ifndef ROARING_INCLUDE_ROARING_VERSION #define ROARING_INCLUDE_ROARING_VERSION -#define ROARING_VERSION "4.0.0" +#define ROARING_VERSION "4.1.1" enum { ROARING_VERSION_MAJOR = 4, - ROARING_VERSION_MINOR = 0, - ROARING_VERSION_REVISION = 0 + ROARING_VERSION_MINOR = 1, + ROARING_VERSION_REVISION = 1 }; #endif // ROARING_INCLUDE_ROARING_VERSION // clang-format on/* end file include/roaring/roaring_version.h */ diff --git a/croaring-sys/CRoaring/roaring.hh b/croaring-sys/CRoaring/roaring.hh index c195ede..1b292ba 100644 --- a/croaring-sys/CRoaring/roaring.hh +++ b/croaring-sys/CRoaring/roaring.hh @@ -1,5 +1,5 @@ // !!! DO NOT EDIT - THIS IS AN AUTO-GENERATED FILE !!! -// Created by amalgamation.sh on 2024-07-03T21:30:32Z +// Created by amalgamation.sh on 2024-07-30T19:32:00Z /* * The CRoaring project is under a dual license (Apache/MIT). diff --git a/croaring-sys/Cargo.toml b/croaring-sys/Cargo.toml index 37606b2..403886a 100644 --- a/croaring-sys/Cargo.toml +++ b/croaring-sys/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "croaring-sys" -version = "4.1.0" +version = "4.1.1" edition = "2021" authors = ["croaring-rs developers"] license = "Apache-2.0" diff --git a/croaring-sys/build.rs b/croaring-sys/build.rs index f37ac53..ab3cc88 100644 --- a/croaring-sys/build.rs +++ b/croaring-sys/build.rs @@ -8,7 +8,7 @@ fn main() { build.file("CRoaring/roaring.c"); if let Ok(target_arch) = env::var("ROARING_ARCH") { - build.flag_if_supported(&format!("-march={target_arch}")); + build.flag_if_supported(format!("-march={target_arch}")); } build.flag_if_supported("-Wno-unused-function"); diff --git a/croaring/src/bitmap/imp.rs b/croaring/src/bitmap/imp.rs index b0b328e..2a1900c 100644 --- a/croaring/src/bitmap/imp.rs +++ b/croaring/src/bitmap/imp.rs @@ -25,7 +25,7 @@ impl Bitmap { // (it can be moved safely), and can be freed with `free`, without freeing the underlying // containers and auxiliary data. Ensure this is still valid every time we update // the version of croaring. - const _: () = assert!(ffi::ROARING_VERSION_MAJOR == 4 && ffi::ROARING_VERSION_MINOR == 0); + const _: () = assert!(ffi::ROARING_VERSION_MAJOR == 4 && ffi::ROARING_VERSION_MINOR == 1); ffi::roaring_free(p.cast::()); result } diff --git a/croaring/src/bitmap/ops.rs b/croaring/src/bitmap/ops.rs index f62b64f..c567415 100644 --- a/croaring/src/bitmap/ops.rs +++ b/croaring/src/bitmap/ops.rs @@ -138,7 +138,7 @@ impl Drop for Bitmap { fn drop(&mut self) { // This depends somewhat heavily on the implementation of croaring, // Ensure this is still valid every time we update the version of croaring. - const _: () = assert!(ffi::ROARING_VERSION_MAJOR == 4 && ffi::ROARING_VERSION_MINOR == 0); + const _: () = assert!(ffi::ROARING_VERSION_MAJOR == 4 && ffi::ROARING_VERSION_MINOR == 1); // Per https://github.com/RoaringBitmap/CRoaring/blob/4f8dbdb0cc884626b20ef0cc9e891f701fe157cf/cpp/roaring.hh#L182 // > By contract, calling roaring_bitmap_clear() is enough to diff --git a/croaring/src/bitmap/view.rs b/croaring/src/bitmap/view.rs index 73fbc43..9309e58 100644 --- a/croaring/src/bitmap/view.rs +++ b/croaring/src/bitmap/view.rs @@ -27,7 +27,7 @@ impl<'a> BitmapView<'a> { // `containers` array is stored immediately after the roaring_bitmap_t data. // Ensure this is still valid every time we update // the version of croaring. - const _: () = assert!(ffi::ROARING_VERSION_MAJOR == 4 && ffi::ROARING_VERSION_MINOR == 0); + const _: () = assert!(ffi::ROARING_VERSION_MAJOR == 4 && ffi::ROARING_VERSION_MINOR == 1); assert!(!p.is_null());