diff options
| author | Sebastiano Tronto <sebastiano@tronto.net> | 2026-03-01 18:09:44 +0100 |
|---|---|---|
| committer | Sebastiano Tronto <sebastiano@tronto.net> | 2026-03-01 18:09:44 +0100 |
| commit | 2c291aed4bb80f07e8557284d3399cf1e2a4ccb9 (patch) | |
| tree | 2c009a3ad206842b07b1cd758b8192e2154231e9 /src/utils | |
| parent | dff3a040637f2985b5b5e369148a993183964096 (diff) | |
| download | nissy-core-2c291aed4bb80f07e8557284d3399cf1e2a4ccb9.tar.gz nissy-core-2c291aed4bb80f07e8557284d3399cf1e2a4ccb9.zip | |
Improve Windows build support.
- Use multithreading (works with a sufficiently recent version of
the Microsoft developer tools / C SDK).
- Detect CPU architecture and use AVX2 or NEON when appropriate.
- Automatically detect python installation path.
Diffstat (limited to 'src/utils')
| -rw-r--r-- | src/utils/prefetch.h | 16 | ||||
| -rw-r--r-- | src/utils/wrapthread.h | 86 |
2 files changed, 67 insertions, 35 deletions
diff --git a/src/utils/prefetch.h b/src/utils/prefetch.h index 89b14e8..a2c41ef 100644 --- a/src/utils/prefetch.h +++ b/src/utils/prefetch.h | |||
| @@ -1,15 +1,7 @@ | |||
| 1 | #if defined(AVX2) | ||
| 2 | |||
| 3 | #define prefetch(a, i) _mm_prefetch(a+i, _MM_HINT_T0) | ||
| 4 | |||
| 5 | #else | ||
| 6 | #if defined(__GNUC__) || defined(__clang__) | 1 | #if defined(__GNUC__) || defined(__clang__) |
| 7 | 2 | #define prefetch(a, i) __builtin_prefetch(a+i, 0, 0) | |
| 8 | #define prefetch(a, i) __builtin_prefetch(a+i, 0, 0) | 3 | #elif defined(AVX2) |
| 9 | 4 | #define prefetch(a, i) _mm_prefetch((char *)(a+i), _MM_HINT_T0) | |
| 10 | #else | 5 | #else |
| 11 | 6 | #define prefetch(a, i) (void)i | |
| 12 | #define prefetch(a, i) (void)i | ||
| 13 | |||
| 14 | #endif | ||
| 15 | #endif | 7 | #endif |
diff --git a/src/utils/wrapthread.h b/src/utils/wrapthread.h index 28654fe..4ac72a6 100644 --- a/src/utils/wrapthread.h +++ b/src/utils/wrapthread.h | |||
| @@ -1,37 +1,77 @@ | |||
| 1 | #if THREADS == 1 | 1 | #if THREADS == 1 |
| 2 | #define WRAPTHREAD_NOTHREADS 1 | ||
| 3 | #elif defined(__unix__) | ||
| 4 | #define WRAPTHREAD_PTHREADS 1 | ||
| 5 | #elif defined(__has_include) | ||
| 6 | #if __has_include(<pthreads.h>) | ||
| 7 | #define WRAPTHREAD_PTHREADS 1 | ||
| 8 | #elif __has_include(<threads.h>) | ||
| 9 | #define WRAPTHREAD_C11THREADS 1 | ||
| 10 | #endif | ||
| 11 | #else | ||
| 12 | #define WRAPTHREAD_NOTHREADS 1 | ||
| 13 | #endif | ||
| 14 | |||
| 15 | #if WRAPTHREAD_PTHREADS | ||
| 16 | #include <pthread.h> | ||
| 17 | |||
| 18 | #define wrapthread_atomic _Atomic | ||
| 19 | |||
| 20 | #define wrapthread_return_t void * | ||
| 21 | #define wrapthread_return_val NULL | ||
| 22 | |||
| 23 | #define wrapthread_define_var_thread_t(x) pthread_t x | ||
| 24 | #define wrapthread_define_var_mutex_t(x) pthread_mutex_t x | ||
| 25 | #define wrapthread_define_struct_thread_t(x) pthread_t x | ||
| 26 | #define wrapthread_define_struct_mutex_t(x) pthread_mutex_t x | ||
| 27 | |||
| 28 | #define wrapthread_define_if_threads(T, x) T x | ||
| 29 | |||
| 30 | #define wrapthread_create(a, f, arg) pthread_create(a, NULL, f, arg) | ||
| 31 | #define wrapthread_join(a) pthread_join(a, NULL) | ||
| 32 | #define wrapthread_mutex_init(a) pthread_mutex_init(a, NULL) | ||
| 33 | #define wrapthread_mutex_lock(a) pthread_mutex_lock(a) | ||
| 34 | #define wrapthread_mutex_unlock(a) pthread_mutex_unlock(a) | ||
| 35 | |||
| 36 | #elif WRAPTHREAD_C11THREADS | ||
| 37 | #include <threads.h> | ||
| 38 | |||
| 39 | #define wrapthread_atomic _Atomic | ||
| 2 | 40 | ||
| 3 | #define wrapthread_atomic | 41 | #define wrapthread_return_t int |
| 42 | #define wrapthread_return_val 0 | ||
| 4 | 43 | ||
| 5 | #define wrapthread_define_var_thread_t(x) unused char x | 44 | #define wrapthread_define_var_thread_t(x) thrd_t x |
| 6 | #define wrapthread_define_var_mutex_t(x) unused char x | 45 | #define wrapthread_define_var_mutex_t(x) mtx_t x |
| 7 | #define wrapthread_define_struct_thread_t(x) char x | 46 | #define wrapthread_define_struct_thread_t(x) thrd_t x |
| 8 | #define wrapthread_define_struct_mutex_t(x) char x | 47 | #define wrapthread_define_struct_mutex_t(x) mtx_t x |
| 9 | 48 | ||
| 10 | #define wrapthread_define_if_threads(T, x) T x; (void)(x) | 49 | #define wrapthread_define_if_threads(T, x) T x |
| 11 | 50 | ||
| 12 | #define wrapthread_create(a, b, c, d) c(d) | 51 | #define wrapthread_create(a, f, arg) thrd_create(a, f, arg) |
| 13 | #define wrapthread_join(a, b) | 52 | #define wrapthread_join(a) thrd_join(a, NULL) |
| 14 | #define wrapthread_mutex_init(a, b) | 53 | #define wrapthread_mutex_init(a) mtx_init(a, mtx_plain) |
| 15 | #define wrapthread_mutex_lock(a) | 54 | #define wrapthread_mutex_lock(a) mtx_lock(a) |
| 16 | #define wrapthread_mutex_unlock(a) | 55 | #define wrapthread_mutex_unlock(a) mtx_unlock(a) |
| 17 | 56 | ||
| 18 | #else | 57 | #else |
| 19 | 58 | ||
| 20 | #include <pthread.h> | 59 | #define wrapthread_atomic |
| 21 | 60 | ||
| 22 | #define wrapthread_atomic _Atomic | 61 | #define wrapthread_return_t int |
| 62 | #define wrapthread_return_val 0 | ||
| 23 | 63 | ||
| 24 | #define wrapthread_define_var_thread_t(x) pthread_t x | 64 | #define wrapthread_define_var_thread_t(x) unused char x |
| 25 | #define wrapthread_define_var_mutex_t(x) pthread_mutex_t x | 65 | #define wrapthread_define_var_mutex_t(x) unused char x |
| 26 | #define wrapthread_define_struct_thread_t(x) pthread_t x | 66 | #define wrapthread_define_struct_thread_t(x) char x |
| 27 | #define wrapthread_define_struct_mutex_t(x) pthread_mutex_t x | 67 | #define wrapthread_define_struct_mutex_t(x) char x |
| 28 | 68 | ||
| 29 | #define wrapthread_define_if_threads(T, x) T x | 69 | #define wrapthread_define_if_threads(T, x) T x; (void)(x) |
| 30 | 70 | ||
| 31 | #define wrapthread_create(a, b, c, d) pthread_create(a, b, c, d) | 71 | #define wrapthread_create(t, f, arg) f(arg) |
| 32 | #define wrapthread_join(a, b) pthread_join(a, b) | 72 | #define wrapthread_join(a) |
| 33 | #define wrapthread_mutex_init(a, b) pthread_mutex_init(a, b) | 73 | #define wrapthread_mutex_init(a) |
| 34 | #define wrapthread_mutex_lock(a) pthread_mutex_lock(a) | 74 | #define wrapthread_mutex_lock(a) |
| 35 | #define wrapthread_mutex_unlock(a) pthread_mutex_unlock(a) | 75 | #define wrapthread_mutex_unlock(a) |
| 36 | 76 | ||
| 37 | #endif | 77 | #endif |
