Skip to content

Commit

Permalink
Merge pull request #657 from DLTcollab/mingw-fixes
Browse files Browse the repository at this point in the history
Fix undefined _mm_{malloc,free} with LLVM/MinGW
  • Loading branch information
jserv authored Dec 25, 2024
2 parents e6c03b4 + d30b525 commit 21fa0a7
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 5 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ jobs:
- armv7
- aarch64
env:
LLVM_MINGW_URL: https://github.com/mstorsjo/llvm-mingw/releases/download/20220906/llvm-mingw-20220906-ucrt-x86_64.zip
LLVM_MINGW_URL: https://github.com/mstorsjo/llvm-mingw/releases/download/20241217/llvm-mingw-20241217-msvcrt-x86_64.zip
defaults:
run:
shell: bash
Expand Down
16 changes: 12 additions & 4 deletions sse2neon.h
Original file line number Diff line number Diff line change
Expand Up @@ -140,10 +140,8 @@ FORCE_INLINE int64_t sse2neon_recast_f64_s64(double f64)
return i64;
}

#if defined(_WIN32)
/* Definitions for _mm_{malloc,free} are provided by <malloc.h>
* from both MinGW-w64 and MSVC.
*/
#if defined(_WIN32) && !defined(__MINGW32__)
/* Definitions for _mm_{malloc,free} are provided by <malloc.h> from MSVC. */
#define SSE2NEON_ALLOC_DEFINED
#endif

Expand Down Expand Up @@ -1796,7 +1794,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

Expand Down Expand Up @@ -1979,8 +1981,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
Expand Down

0 comments on commit 21fa0a7

Please sign in to comment.