From c65fcebaada17e2789d8f9139736fdd7e8ee2502 Mon Sep 17 00:00:00 2001 From: Greg Burd Date: Wed, 1 May 2024 09:15:22 -0400 Subject: [PATCH] macOS/M2 fixes --- Makefile | 7 ++++--- include/popcount.h | 6 +++--- src/sparsemap.c | 2 -- tests/common.c | 19 +++++++++++++++---- tests/common.h | 6 +++--- 5 files changed, 25 insertions(+), 15 deletions(-) diff --git a/Makefile b/Makefile index d9736d2..94aa600 100644 --- a/Makefile +++ b/Makefile @@ -6,14 +6,15 @@ SHARED_LIB = libsparsemap.so #CFLAGS = -Wall -Wextra -Wpedantic -Of -std=c11 -Iinclude/ -fPIC #CFLAGS = -Wall -Wextra -Wpedantic -Og -g -std=c11 -Iinclude/ -fPIC #CFLAGS = -DSPARSEMAP_DIAGNOSTIC -DDEBUG -Wall -Wextra -Wpedantic -O0 -g -std=c11 -Iinclude/ -fPIC -CFLAGS = -Wall -Wextra -Wpedantic -Og -g -std=c11 -Iinclude/ -fPIC +CFLAGS = -DSPARSEMAP_DIAGNOSTIC -DDEBUG -Wall -Wextra -Wpedantic -Ofast -g -std=c11 -Iinclude/ -fPIC +#CFLAGS = -Wall -Wextra -Wpedantic -Og -g -std=c11 -Iinclude/ -fPIC #CFLAGS = -Wall -Wextra -Wpedantic -Ofast -g -std=c11 -Iinclude/ -fPIC #CFLAGS = -DSPARSEMAP_DIAGNOSTIC -DDEBUG -Wall -Wextra -Wpedantic -Og -g -fsanitize=address,leak,object-size,pointer-compare,pointer-subtract,null,return,bounds,pointer-overflow,undefined -fsanitize-address-use-after-scope -std=c11 -Iinclude/ -fPIC #CFLAGS = -Wall -Wextra -Wpedantic -Og -g -fsanitize=all -fhardened -std=c11 -Iinclude/ -fPIC #TEST_FLAGS = -DDEBUG -Wall -Wextra -Wpedantic -O0 -g -std=c11 -Iinclude/ -Itests/ -fPIC -TEST_FLAGS = -Wall -Wextra -Wpedantic -Og -g -std=c11 -Iinclude/ -Itests/ -fPIC -#TEST_FLAGS = -Wall -Wextra -Wpedantic -Ofast -g -std=c11 -Iinclude/ -Itests/ -fPIC +#TEST_FLAGS = -Wall -Wextra -Wpedantic -Og -g -std=c11 -Iinclude/ -Itests/ -fPIC +TEST_FLAGS = -Wall -Wextra -Wpedantic -Ofast -g -std=c11 -Iinclude/ -Itests/ -fPIC #TEST_FLAGS = -DDEBUG -Wall -Wextra -Wpedantic -Og -g -fsanitize=address,leak,object-size,pointer-compare,pointer-subtract,null,return,bounds,pointer-overflow,undefined -fsanitize-address-use-after-scope -std=c11 -Iinclude/ -fPIC TESTS = tests/test diff --git a/include/popcount.h b/include/popcount.h index 715f141..cdc1f17 100644 --- a/include/popcount.h +++ b/include/popcount.h @@ -26,7 +26,7 @@ #define G2 0xAAAAAAAAAAAAAAAAULL // Every highest 2nd bit: 101010... #define G4 0x3333333333333333ULL // 00110011 ... used to group the sum of 4 bits. #define G8 0x0F0F0F0F0F0F0F0FULL -#define H8 0x8080808080808080ULL +#define H8 0x8080808080808080ULL #define L9 0x0040201008040201ULL #define H9 (L9 << 8) #define L16 0x0001000100010001ULL @@ -44,7 +44,7 @@ #define ONES_STEP_32 ( 0x0000000100000001ULL ) #define MSBS_STEP_32 ( 0x8000000080000000ULL ) - + #define COMPARE_STEP_8(x,y) ( ( ( ( ( (x) | MSBS_STEP_8 ) - ( (y) & ~MSBS_STEP_8 ) ) ^ (x) ^ ~(y) ) & MSBS_STEP_8 ) >> 7 ) #define LEQ_STEP_8(x,y) ( ( ( ( ( (y) | MSBS_STEP_8 ) - ( (x) & ~MSBS_STEP_8 ) ) ^ (x) ^ (y) ) & MSBS_STEP_8 ) >> 7 ) @@ -72,4 +72,4 @@ inline int sux_popcountll(uint64_t x) { } #endif /* _FASTRANK_POPCOUNT_H_ */ -#endif \ No newline at end of file +#endif diff --git a/src/sparsemap.c b/src/sparsemap.c index fe3249c..718c4ef 100644 --- a/src/sparsemap.c +++ b/src/sparsemap.c @@ -814,7 +814,6 @@ __sm_get_size_impl(sparsemap_t *map) return SM_SIZEOF_OVERHEAD + p - start; } -#if 0 /** @brief Aligns to SM_BITS_PER_VECTOR a given index \b idx. * * @param[in] idx The index to align. @@ -826,7 +825,6 @@ __sm_get_aligned_offset(size_t idx) const size_t capacity = SM_BITS_PER_VECTOR; return (idx / capacity) * capacity; } -#endif /** @brief Aligns to SM_CHUNK_MAP_CAPACITY a given index \b idx. * diff --git a/tests/common.c b/tests/common.c index 1b5d241..169fae2 100644 --- a/tests/common.c +++ b/tests/common.c @@ -11,10 +11,12 @@ #include #include #include +#ifdef __x86_64__ // Check if running on x86_64 architecture #ifdef X86_INTRIN #include #include #endif +#endif #include "../include/sparsemap.h" #include "common.h" @@ -31,6 +33,7 @@ uint64_t tsc(void) { +#ifdef __x86_64__ // Check if running on x86_64 architecture #ifdef X86_INTRIN return __rdtsc(); #else @@ -38,10 +41,18 @@ tsc(void) __asm__ volatile("rdtsc" : "=a"(low), "=d"(high)); return ((uint64_t)high << 32) | low; #endif +#ifdef __arm__ // Check if compiling for ARM architecture + uint64_t result; + __asm__ volatile("mrs %0, pmccntr_el0" : "=r"(result)); + return result; +} +#endif +#endif +return 0; } double -nsts() +nsts(void) { struct timespec ts; @@ -56,7 +67,7 @@ int __xorshift32_state = 0; // Xorshift algorithm for PRNG uint32_t -xorshift32() +xorshift32(void) { uint32_t x = __xorshift32_state; if (x == 0) { @@ -70,7 +81,7 @@ xorshift32() } void -xorshift32_seed() +xorshift32_seed(void) { __xorshift32_state = XORSHIFT_SEED_VALUE; } @@ -350,7 +361,7 @@ print_bits(char *name, uint64_t value) printf("%s\t", name); } for (int i = 63; i >= 0; i--) { - printf("%ld", (value >> i) & 1); + printf("%llu", (value >> i) & 1); if (i % 8 == 0) { printf(" "); // Add space for better readability } diff --git a/tests/common.h b/tests/common.h index 02dda1a..aeb5c63 100644 --- a/tests/common.h +++ b/tests/common.h @@ -25,10 +25,10 @@ uint64_t tsc(void); double tsc_ticks_to_ns(uint64_t tsc_ticks); -double nsts(); +double nsts(void); -void xorshift32_seed(); -uint32_t xorshift32(); +void xorshift32_seed(void); +uint32_t xorshift32(void); void print_array(int *array, int l); void print_spans(int *array, int n);