|
11 | 11 | #include <stdlib.h> |
12 | 12 | #include <string.h> |
13 | 13 | #include <float.h> |
| 14 | + |
| 15 | +#ifdef _WIN32 |
| 16 | +#include <windows.h> |
| 17 | +/* pthread compat for MSVC (using Windows threads) */ |
| 18 | +typedef HANDLE pthread_t; |
| 19 | +typedef CRITICAL_SECTION pthread_mutex_t; |
| 20 | +typedef CONDITION_VARIABLE pthread_cond_t; |
| 21 | +#define pthread_mutex_init(m, a) InitializeCriticalSection(m) |
| 22 | +#define pthread_mutex_lock(m) EnterCriticalSection(m) |
| 23 | +#define pthread_mutex_unlock(m) LeaveCriticalSection(m) |
| 24 | +#define pthread_mutex_destroy(m) DeleteCriticalSection(m) |
| 25 | +#define pthread_cond_init(c, a) InitializeConditionVariable(c) |
| 26 | +#define pthread_cond_wait(c, m) SleepConditionVariableCS(c, m, INFINITE) |
| 27 | +#define pthread_cond_broadcast(c) WakeAllConditionVariable(c) |
| 28 | +#define pthread_cond_destroy(c) ((void)0) |
| 29 | +/* __thread → __declspec(thread) */ |
| 30 | +#define __thread __declspec(thread) |
| 31 | +#else |
14 | 32 | #include <pthread.h> |
| 33 | +#endif |
15 | 34 |
|
16 | 35 | #ifdef __ARM_NEON |
17 | 36 | #include <arm_neon.h> |
|
29 | 48 | * Workers sleep between dispatches, wake via cond_broadcast. |
30 | 49 | * Main thread does task[0], workers do task[1..n-1]. |
31 | 50 | * ============================================================ */ |
32 | | -#include <stdatomic.h> |
| 51 | +#if defined(_MSC_VER) |
| 52 | + /* MSVC: use interlocked intrinsics instead of C11 atomics */ |
| 53 | + #include <intrin.h> |
| 54 | + typedef volatile long atomic_int; |
| 55 | + #define atomic_store(p, v) _InterlockedExchange((p), (v)) |
| 56 | + #define atomic_load(p) _InterlockedCompareExchange((p), 0, 0) |
| 57 | + #define atomic_fetch_add(p, v) _InterlockedExchangeAdd((p), (v)) |
| 58 | +#else |
| 59 | + #include <stdatomic.h> |
| 60 | +#endif |
33 | 61 |
|
34 | 62 | /* Forward declaration for 1-bit matmul (defined at end of file) */ |
35 | 63 | void tq_matmul_1bit(float* out, const float* x, const uint8_t* sign_data, const float* norms, |
|
0 commit comments