Skip to content

Commit a4a2b43

Browse files
unamedkrclaude
andcommitted
Fix Windows CI: MSVC __builtin_* shims, pthread_create/join, M_PI, timespec
- tq_gguf_quants.c: shim __builtin_prefetch and __builtin_return_address - tq_moe.c: shim __builtin_prefetch for MSVC - tq_ops.c: add pthread_create/join/cond_signal via _beginthreadex - test_neon_scalar.cpp: define _USE_MATH_DEFINES before cmath for M_PI - tools/quant.c: skip timespec redefinition on MSVC >= 2015 Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
1 parent aa6386e commit a4a2b43

5 files changed

Lines changed: 23 additions & 1 deletion

File tree

src/engine/tq_gguf_quants.c

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,12 @@
2424
#define TQ_HAS_NEON 0
2525
#endif
2626

27+
/* MSVC: no __builtin_* intrinsics */
28+
#ifdef _MSC_VER
29+
#define __builtin_prefetch(addr, ...) ((void)0)
30+
#define __builtin_return_address(n) ((void*)0)
31+
#endif
32+
2733
/* ============================================================
2834
* FP16 / BF16 helpers
2935
* ============================================================ */

src/engine/tq_moe.c

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,10 @@
2222
#define TQ_MOE_HAS_NEON 0
2323
#endif
2424

25+
#ifdef _MSC_VER
26+
#define __builtin_prefetch(addr, ...) ((void)0)
27+
#endif
28+
2529
#ifdef TQ_HAS_ACCELERATE
2630
#include <Accelerate/Accelerate.h>
2731
#endif

src/engine/tq_ops.c

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,15 @@ typedef SRWLOCK pthread_mutex_srw_t;
4141
#undef pthread_mutex_destroy
4242
#define pthread_mutex_destroy(m) ((void)0)
4343
#define PTHREAD_MUTEX_INITIALIZER SRWLOCK_INIT
44+
#define pthread_cond_signal(c) WakeConditionVariable(c)
45+
#include <process.h>
46+
static inline int pthread_create(pthread_t* t, const void* a, void*(*fn)(void*), void* arg) {
47+
(void)a; *t = (HANDLE)_beginthreadex(NULL,0,(unsigned(__stdcall*)(void*))fn,arg,0,NULL);
48+
return *t ? 0 : -1;
49+
}
50+
static inline int pthread_join(pthread_t t, void** r) {
51+
(void)r; WaitForSingleObject(t, INFINITE); CloseHandle(t); return 0;
52+
}
4453
#else
4554
#include <pthread.h>
4655
#endif

tests/test_neon_scalar.cpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,9 @@
1313
* - uniform_4b quantize/dequantize: KV cache uniform quantization
1414
*/
1515

16+
#ifdef _MSC_VER
17+
#define _USE_MATH_DEFINES
18+
#endif
1619
#include <gtest/gtest.h>
1720
#include <cmath>
1821
#include <vector>

tools/quant.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@
4343
#ifndef CLOCK_MONOTONIC
4444
#define CLOCK_MONOTONIC 1
4545
#endif
46-
#if defined(_WIN32) && !defined(_TIMESPEC_DEFINED) && !defined(__struct_timespec_defined)
46+
#if defined(_WIN32) && !defined(_TIMESPEC_DEFINED) && !defined(__struct_timespec_defined) && (!defined(_MSC_VER) || _MSC_VER < 1900)
4747
#define _TIMESPEC_DEFINED 1
4848
#define __struct_timespec_defined 1
4949
struct timespec { long tv_sec; long tv_nsec; };

0 commit comments

Comments
 (0)