macOS/M2 fixes

This commit is contained in:
Greg Burd 2024-05-01 09:15:22 -04:00
parent ee695b7243
commit c65fcebaad
No known key found for this signature in database
5 changed files with 25 additions and 15 deletions

View file

@ -6,14 +6,15 @@ SHARED_LIB = libsparsemap.so
#CFLAGS = -Wall -Wextra -Wpedantic -Of -std=c11 -Iinclude/ -fPIC #CFLAGS = -Wall -Wextra -Wpedantic -Of -std=c11 -Iinclude/ -fPIC
#CFLAGS = -Wall -Wextra -Wpedantic -Og -g -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 = -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 = -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 = -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 #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 = -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 -Og -g -std=c11 -Iinclude/ -Itests/ -fPIC
#TEST_FLAGS = -Wall -Wextra -Wpedantic -Ofast -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 #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 TESTS = tests/test

View file

@ -814,7 +814,6 @@ __sm_get_size_impl(sparsemap_t *map)
return SM_SIZEOF_OVERHEAD + p - start; return SM_SIZEOF_OVERHEAD + p - start;
} }
#if 0
/** @brief Aligns to SM_BITS_PER_VECTOR a given index \b idx. /** @brief Aligns to SM_BITS_PER_VECTOR a given index \b idx.
* *
* @param[in] idx The index to align. * @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; const size_t capacity = SM_BITS_PER_VECTOR;
return (idx / capacity) * capacity; return (idx / capacity) * capacity;
} }
#endif
/** @brief Aligns to SM_CHUNK_MAP_CAPACITY a given index \b idx. /** @brief Aligns to SM_CHUNK_MAP_CAPACITY a given index \b idx.
* *

View file

@ -11,10 +11,12 @@
#include <string.h> #include <string.h>
#include <time.h> #include <time.h>
#include <unistd.h> #include <unistd.h>
#ifdef __x86_64__ // Check if running on x86_64 architecture
#ifdef X86_INTRIN #ifdef X86_INTRIN
#include <errno.h> #include <errno.h>
#include <x86intrin.h> #include <x86intrin.h>
#endif #endif
#endif
#include "../include/sparsemap.h" #include "../include/sparsemap.h"
#include "common.h" #include "common.h"
@ -31,6 +33,7 @@
uint64_t uint64_t
tsc(void) tsc(void)
{ {
#ifdef __x86_64__ // Check if running on x86_64 architecture
#ifdef X86_INTRIN #ifdef X86_INTRIN
return __rdtsc(); return __rdtsc();
#else #else
@ -38,10 +41,18 @@ tsc(void)
__asm__ volatile("rdtsc" : "=a"(low), "=d"(high)); __asm__ volatile("rdtsc" : "=a"(low), "=d"(high));
return ((uint64_t)high << 32) | low; return ((uint64_t)high << 32) | low;
#endif #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 double
nsts() nsts(void)
{ {
struct timespec ts; struct timespec ts;
@ -56,7 +67,7 @@ int __xorshift32_state = 0;
// Xorshift algorithm for PRNG // Xorshift algorithm for PRNG
uint32_t uint32_t
xorshift32() xorshift32(void)
{ {
uint32_t x = __xorshift32_state; uint32_t x = __xorshift32_state;
if (x == 0) { if (x == 0) {
@ -70,7 +81,7 @@ xorshift32()
} }
void void
xorshift32_seed() xorshift32_seed(void)
{ {
__xorshift32_state = XORSHIFT_SEED_VALUE; __xorshift32_state = XORSHIFT_SEED_VALUE;
} }
@ -350,7 +361,7 @@ print_bits(char *name, uint64_t value)
printf("%s\t", name); printf("%s\t", name);
} }
for (int i = 63; i >= 0; i--) { for (int i = 63; i >= 0; i--) {
printf("%ld", (value >> i) & 1); printf("%llu", (value >> i) & 1);
if (i % 8 == 0) { if (i % 8 == 0) {
printf(" "); // Add space for better readability printf(" "); // Add space for better readability
} }

View file

@ -25,10 +25,10 @@
uint64_t tsc(void); uint64_t tsc(void);
double tsc_ticks_to_ns(uint64_t tsc_ticks); double tsc_ticks_to_ns(uint64_t tsc_ticks);
double nsts(); double nsts(void);
void xorshift32_seed(); void xorshift32_seed(void);
uint32_t xorshift32(); uint32_t xorshift32(void);
void print_array(int *array, int l); void print_array(int *array, int l);
void print_spans(int *array, int n); void print_spans(int *array, int n);