Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Testing amalgamation files #573

Merged
merged 10 commits into from
Jan 26, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 0 additions & 28 deletions .github/workflows/vs16-arm-ci.yml

This file was deleted.

36 changes: 0 additions & 36 deletions .github/workflows/vs16-ci.yml

This file was deleted.

48 changes: 48 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,9 @@ project(RoaringBitmap
DESCRIPTION "Roaring bitmaps in C (and C++)"
LANGUAGES CXX C
)
set (CMAKE_C_STANDARD 11)
set (CMAKE_CXX_STANDARD 11)

include(GNUInstallDirs)

if (NOT CMAKE_BUILD_TYPE)
Expand Down Expand Up @@ -110,6 +113,51 @@ if(ENABLE_ROARING_TESTS)
endif()
add_subdirectory(tests)
endif()
find_program(BASH bash)

if(ENABLE_ROARING_TESTS AND BASH)
message(STATUS "Amalgamation tests enabled")
set(CROARING_SINGLEHEADER_FILES
${CMAKE_CURRENT_BINARY_DIR}/amalgamation_demo.c
${CMAKE_CURRENT_BINARY_DIR}/amalgamation_demo.cpp
${CMAKE_CURRENT_BINARY_DIR}/roaring.c
${CMAKE_CURRENT_BINARY_DIR}/roaring.h
${CMAKE_CURRENT_BINARY_DIR}/roaring.hh
)
set_source_files_properties(${CROARING_SINGLEHEADER_FILES} PROPERTIES GENERATED TRUE)

add_custom_command(
OUTPUT ${CROARING_SINGLEHEADER_FILES}
COMMAND ${BASH} ${CMAKE_CURRENT_SOURCE_DIR}/amalgamation.sh ${CMAKE_CURRENT_BINARY_DIR}
WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}
DEPENDS ${CMAKE_CURRENT_SOURCE_DIR}/amalgamation.sh roaring
)
set_source_files_properties(${CMAKE_CURRENT_BINARY_DIR}/amalgamation_demo.c PROPERTIES LANGUAGE C CMAKE_C_STANDARD 11)
set_source_files_properties(${CMAKE_CURRENT_BINARY_DIR}/amalgamation_demo.cpp PROPERTIES LANGUAGE CXX CXX_STANDARD 11)
add_custom_target(croaring-singleheader-files DEPENDS ${CROARING_SINGLEHEADER_FILES})

add_library(croaring-singleheader-include-source INTERFACE)
target_include_directories(croaring-singleheader-include-source INTERFACE $<BUILD_INTERFACE:${CMAKE_CURRENT_BINARY_DIR}>)
add_dependencies(croaring-singleheader-include-source croaring-singleheader-files)

add_executable(amalgamate_demo $<BUILD_INTERFACE:${CMAKE_CURRENT_BINARY_DIR}/amalgamation_demo.c>)
target_link_libraries(amalgamate_demo croaring-singleheader-include-source)
add_test(amalgamate_demo amalgamate_demo)

add_library(croaring-singleheader-source-lib $<BUILD_INTERFACE:${CMAKE_CURRENT_BINARY_DIR}/roaring.c>)
target_include_directories(croaring-singleheader-source-lib PUBLIC $<BUILD_INTERFACE:${CMAKE_CURRENT_BINARY_DIR}>)

add_executable(amalgamate_demo_cpp $<BUILD_INTERFACE:${CMAKE_CURRENT_BINARY_DIR}/amalgamation_demo.cpp>)
target_link_libraries(amalgamate_demo_cpp croaring-singleheader-include-source croaring-singleheader-source-lib)
if(ROARING_EXCEPTIONS)
target_compile_definitions(amalgamate_demo_cpp PUBLIC ROARING_EXCEPTIONS=1)
else()
target_compile_definitions(amalgamate_demo_cpp PUBLIC ROARING_EXCEPTIONS=0)
endif()
add_test(amalgamate_demo_cpp amalgamate_demo_cpp)
else()
message(STATUS "Amalgamation tests disabled")
endif()
option(ENABLE_ROARING_MICROBENCHMARKS "Enable microbenchmarks" OFF)
if(ENABLE_ROARING_MICROBENCHMARKS)
add_subdirectory(microbenchmarks)
Expand Down
42 changes: 33 additions & 9 deletions amalgamation.sh
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@
########################################################################
SCRIPTPATH="$( cd "$(dirname "$0")" ; pwd -P )"

DESTINATION=${1:-.}

case $SCRIPTPATH in
(*\ *) echo "Path ($SCRIPTPATH) cannot contain whitespace"; exit 1 ;;
esac
Expand Down Expand Up @@ -141,7 +143,7 @@ echo "Creating ${AMAL_H}..."
for h in ${ALL_PUBLIC_H}; do
dofile $h
done
} > "${AMAL_H}"
} > "${DESTINATION}/${AMAL_H}"


echo "Creating ${AMAL_C}..."
Expand All @@ -163,7 +165,7 @@ echo "Creating ${AMAL_C}..."
for h in ${ALL_PRIVATE_H} ${ALL_PRIVATE_C}; do
dofile $h
done
} > "${AMAL_C}"
} > "${DESTINATION}/${AMAL_C}"


echo "Creating ${DEMOC}..."
Expand All @@ -174,6 +176,25 @@ echo "Creating ${DEMOC}..."
#include <stdio.h>
#include <stdlib.h>
#include "roaring.c"


static inline void or_many(void) {
roaring_bitmap_t *r1 = roaring_bitmap_from(500, 1000);
roaring_bitmap_t *r2 = roaring_bitmap_from(1000, 2000);

const roaring_bitmap_t *bitmap_arr[2] = {r1, r2};
fprintf(stderr, "Going to or many\n");
for (int i = 0; i < 10000; i++) {
roaring_bitmap_t *r = roaring_bitmap_or_many(2, bitmap_arr);
roaring_bitmap_free(r);
}

fprintf(stderr, "Got done\n");

roaring_bitmap_free(r2);
roaring_bitmap_free(r1);
}

int main() {
roaring_bitmap_t *r1 = roaring_bitmap_create();
for (uint32_t i = 100; i < 1000; i++) roaring_bitmap_add(r1, i);
Expand All @@ -191,10 +212,11 @@ int main() {
}
printf("%zu \n", bitset_count(b));
bitset_free(b);
or_many();
return EXIT_SUCCESS;
}
'
} > "${DEMOC}"
} > "${DESTINATION}/${DEMOC}"


echo "Creating ${AMAL_HH}..."
Expand All @@ -218,7 +240,7 @@ echo "Creating ${AMAL_HH}..."
for hh in ${ALL_PUBLIC_HH}; do
dofile $hh
done
} > "${AMAL_HH}"
} > "${DESTINATION}/${AMAL_HH}"


echo "Creating ${DEMOCPP}..."
Expand All @@ -229,7 +251,8 @@ echo "Creating ${DEMOCPP}..."
cat <<< '
#include <iostream>
#include "roaring.hh"
#include "roaring.c"
//#include "roaring.c"

int main() {
roaring::Roaring r1;
for (uint32_t i = 100; i < 1000; i++) {
Expand All @@ -245,26 +268,27 @@ int main() {
return 0;
}
'
} > "${DEMOCPP}"
} > "${DESTINATION}/${DEMOCPP}"


# Print out a directory listing of the output files and their sizes
#
newline
echo "Files have been written to current directory: $PWD "
ls -la ${AMAL_C} ${AMAL_H} ${AMAL_HH} ${DEMOC} ${DEMOCPP}
echo "Files have been written to ${DESTINATION} "
ls -la ${DESTINATION}/${AMAL_C} ${DESTINATION}/${AMAL_H} ${DESTINATION}/${AMAL_HH} ${DESTINATION}/${DEMOC} ${DESTINATION}/${DEMOCPP}
newline

CBIN=${DEMOC%%.*}
CPPBIN=${DEMOCPP%%.*}

echo "The interface is found in the file 'include/roaring/roaring.h'."
newline
echo "Go to ${DESTINATION}/."
echo "For C, try:"
echo "cc -O3 -std=c11 -o ${CBIN} ${DEMOC} && ./${CBIN} "
newline
echo "For C++, try:"
echo "c++ -O3 -std=c++11 -o ${CPPBIN} ${DEMOCPP} && ./${CPPBIN} "
echo "c++ -O3 -std=c++11 -o ${CPPBIN} ${DEMOCPP} ${AMAL_C} && ./${CPPBIN} "

lowercase(){
echo "$1" | tr 'A-Z' 'a-z'
Expand Down
4 changes: 2 additions & 2 deletions benchmarks/adversarialunions_benchmark.c
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
#include <roaring/roaring.h>
#include <stdio.h>
#include "benchmark.h"
int quickfull() {
static inline int quickfull() {
printf("The naive approach works well when the bitmaps quickly become full\n");
uint64_t cycles_start, cycles_final;
size_t bitmapcount = 100;
Expand Down Expand Up @@ -47,7 +47,7 @@ int quickfull() {
return 0;
}

int notsofull() {
static inline int notsofull() {
printf("The naive approach works less well when the bitmaps do not quickly become full\n");
uint64_t cycles_start, cycles_final;
size_t bitmapcount = 100;
Expand Down
6 changes: 3 additions & 3 deletions benchmarks/equals_benchmark.c
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,9 @@
#include "benchmark.h"
#include "random.h"

int32_t array_container_get_nruns(const array_container_t *c) { (void) c; return -1; }
int32_t bitset_container_get_nruns(const bitset_container_t *c) { (void) c; return -1; }
int32_t run_container_get_nruns(const run_container_t *c) { return c->n_runs; }
static inline int32_t array_container_get_nruns(const array_container_t *c) { (void) c; return -1; }
static inline int32_t bitset_container_get_nruns(const bitset_container_t *c) { (void) c; return -1; }
static inline int32_t run_container_get_nruns(const run_container_t *c) { return c->n_runs; }

#define BENCHMARK_CONTAINER(cname1, cname2, fname, n) \
{ \
Expand Down
16 changes: 8 additions & 8 deletions benchmarks/run_container_benchmark.c
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ enum { TESTSIZE = 2048 };

#if defined(CROARING_IS_X64) && !(defined(_MSC_VER) && !defined(__clang__))
// flushes the array from cache
void run_cache_flush(run_container_t* B) {
static inline void run_cache_flush(run_container_t* B) {
const int32_t CACHELINESIZE =
computecacheline(); // 64 bytes per cache line
for (int32_t k = 0; k < B->n_runs * 2;
Expand All @@ -17,11 +17,11 @@ void run_cache_flush(run_container_t* B) {
}
}
#else
void run_cache_flush(run_container_t* B) { (void)B; }
static inline void run_cache_flush(run_container_t* B) { (void)B; }
#endif

// tries to put array in cache
void run_cache_prefetch(run_container_t* B) {
static inline void run_cache_prefetch(run_container_t* B) {
#if !CROARING_REGULAR_VISUAL_STUDIO
#if CROARING_IS_X64
const int32_t CACHELINESIZE =
Expand All @@ -36,23 +36,23 @@ void run_cache_prefetch(run_container_t* B) {
#endif // !CROARING_REGULAR_VISUAL_STUDIO
}

int add_test(run_container_t* B) {
static inline int add_test(run_container_t* B) {
int x;
for (x = 0; x < (1 << 16); x += 3) {
run_container_add(B, (uint16_t)x);
}
return 0;
}

int remove_test(run_container_t* B) {
static inline int remove_test(run_container_t* B) {
int x;
for (x = 0; x < (1 << 16); x += 3) {
run_container_remove(B, (uint16_t)x);
}
return 0;
}

int contains_test(run_container_t* B) {
static inline int contains_test(run_container_t* B) {
int card = 0;
int x;
for (x = 0; x < (1 << 16); x++) {
Expand All @@ -61,12 +61,12 @@ int contains_test(run_container_t* B) {
return card;
}

int union_test(run_container_t* B1, run_container_t* B2, run_container_t* BO) {
static inline int union_test(run_container_t* B1, run_container_t* B2, run_container_t* BO) {
run_container_union(B1, B2, BO);
return run_container_cardinality(BO);
}

int intersection_test(run_container_t* B1, run_container_t* B2,
static inline int intersection_test(run_container_t* B1, run_container_t* B2,
run_container_t* BO) {
run_container_intersection(B1, B2, BO);
return run_container_cardinality(BO);
Expand Down
10 changes: 8 additions & 2 deletions include/roaring/array_util.h
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,11 @@
#error "CROARING_COMPILER_SUPPORTS_AVX512 needs to be defined."
#endif // CROARING_COMPILER_SUPPORTS_AVX512
#endif

#if defined(__GNUC__) && !defined(__clang__)
#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Wuninitialized"
#pragma GCC diagnostic ignored "-Wmaybe-uninitialized"
#endif
#ifdef __cplusplus
extern "C" { namespace roaring { namespace internal {
#endif
Expand Down Expand Up @@ -259,5 +263,7 @@ bool memequals(const void *s1, const void *s2, size_t n);
#ifdef __cplusplus
} } } // extern "C" { namespace roaring { namespace internal {
#endif

#if defined(__GNUC__) && !defined(__clang__)
#pragma GCC diagnostic pop
#endif
#endif
10 changes: 8 additions & 2 deletions include/roaring/bitset_util.h
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,11 @@
#error "CROARING_COMPILER_SUPPORTS_AVX512 needs to be defined."
#endif // CROARING_COMPILER_SUPPORTS_AVX512
#endif

#if defined(__GNUC__) && !defined(__clang__)
#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Wuninitialized"
#pragma GCC diagnostic ignored "-Wmaybe-uninitialized"
#endif
#ifdef __cplusplus
extern "C" { namespace roaring { namespace internal {
#endif
Expand Down Expand Up @@ -710,5 +714,7 @@ CROARING_UNTARGET_AVX512
#ifdef __cplusplus
} } } // extern "C" { namespace roaring { namespace internal
#endif

#if defined(__GNUC__) && !defined(__clang__)
#pragma GCC diagnostic pop
#endif
#endif
Loading
Loading