Skip to content

Commit

Permalink
Exclude _mm_malloc/free definitions on Windows
Browse files Browse the repository at this point in the history
Definitions for these functions are provided by malloc.h from both
MinGW-w64 and MSVC. When they are defined again by sse2neon, it causes
multiple definition errors. Furthermore, the implementation in sse2neon
relies on posix_memalign which is unavailable on Windows.
  • Loading branch information
invertego committed Oct 18, 2022
1 parent e8108fc commit 9941d31
Showing 1 changed file with 11 additions and 0 deletions.
11 changes: 11 additions & 0 deletions sse2neon.h
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,13 @@
#include <stdint.h>
#include <stdlib.h>

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

/* Architecture-specific build options */
/* FIXME: #pragma GCC push_options is only available on GCC */
#if defined(__GNUC__)
Expand Down Expand Up @@ -1773,10 +1780,12 @@ FORCE_INLINE __m128 _mm_div_ss(__m128 a, __m128 b)

// Free aligned memory that was allocated with _mm_malloc.
// https://software.intel.com/sites/landingpage/IntrinsicsGuide/#text=_mm_free
#if !defined(SSE2NEON_ALLOC_DEFINED)
FORCE_INLINE void _mm_free(void *addr)
{
free(addr);
}
#endif

// Macro: Get the flush zero bits from the MXCSR control and status register.
// The flush zero may contain any of the following flags: _MM_FLUSH_ZERO_ON or
Expand Down Expand Up @@ -1958,6 +1967,7 @@ FORCE_INLINE __m128i _mm_loadu_si64(const void *p)
// Allocate aligned blocks of memory.
// https://software.intel.com/en-us/
// cpp-compiler-developer-guide-and-reference-allocating-and-freeing-aligned-memory-blocks
#if !defined(SSE2NEON_ALLOC_DEFINED)
FORCE_INLINE void *_mm_malloc(size_t size, size_t align)
{
void *ptr;
Expand All @@ -1969,6 +1979,7 @@ FORCE_INLINE void *_mm_malloc(size_t size, size_t align)
return ptr;
return NULL;
}
#endif

// Conditionally store 8-bit integer elements from a into memory using mask
// (elements are not stored when the highest bit is not set in the corresponding
Expand Down

0 comments on commit 9941d31

Please sign in to comment.