From b5b1910bf15432d255c28e22178245f329d9e575 Mon Sep 17 00:00:00 2001 From: bruvzg <7645683+bruvzg@users.noreply.github.com> Date: Thu, 20 Jun 2024 15:56:49 +0300 Subject: [PATCH] Fix undefined `_mm_malloc` and `_mm_free` when building with LLVM/MinGW. --- sse2neon.h | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) diff --git a/sse2neon.h b/sse2neon.h index 7bbf4e1a..0e2611f6 100644 --- a/sse2neon.h +++ b/sse2neon.h @@ -120,10 +120,8 @@ #include #include -#if defined(_WIN32) -/* Definitions for _mm_{malloc,free} are provided by - * from both MinGW-w64 and MSVC. - */ +#if defined(_WIN32) && !defined(__MINGW32__) +/* Definitions for _mm_{malloc,free} are provided by from MSVC. */ #define SSE2NEON_ALLOC_DEFINED #endif @@ -1767,7 +1765,11 @@ FORCE_INLINE __m128 _mm_div_ss(__m128 a, __m128 b) #if !defined(SSE2NEON_ALLOC_DEFINED) FORCE_INLINE void _mm_free(void *addr) { +#if defined(_WIN32) + _aligned_free(addr); +#else free(addr); +#endif } #endif @@ -1955,8 +1957,14 @@ FORCE_INLINE void *_mm_malloc(size_t size, size_t align) return malloc(size); if (align == 2 || (sizeof(void *) == 8 && align == 4)) align = sizeof(void *); +#if defined(_WIN32) + ptr = _aligned_malloc(size, align); + if (ptr) + return ptr; +#else if (!posix_memalign(&ptr, align, size)) return ptr; +#endif return NULL; } #endif