From ccfd44155c838572063bbafa0fd11f54d40d4f68 Mon Sep 17 00:00:00 2001 From: aeiouaeiouaeiouaeiouaeiouaeiou Date: Fri, 13 Dec 2024 22:47:07 +0300 Subject: [PATCH] Add LEGACY_MACOS macros, use _mm_free() for KRML_ALIGNED_FREE on macOS <10.15 --- include/krml/internal/target.h | 23 +++++++++++++++-------- 1 file changed, 15 insertions(+), 8 deletions(-) diff --git a/include/krml/internal/target.h b/include/krml/internal/target.h index 9627e3bf..f385010d 100644 --- a/include/krml/internal/target.h +++ b/include/krml/internal/target.h @@ -19,9 +19,18 @@ # define inline __inline__ #endif -/* Include Apple-specific macros for use in defining KRML_ALIGNED_MALLOC. */ +/* There is no support for aligned_alloc() in macOS before Catalina, so + * let's make a macro to use _mm_malloc() and _mm_free() functions + * from mm_malloc.h. */ #if defined(__APPLE__) && defined(__MACH__) -#include +# include +# if defined(MAC_OS_X_VERSION_MIN_REQUIRED) && \ + (MAC_OS_X_VERSION_MIN_REQUIRED < 101500) +# include +# define LEGACY_MACOS +# else +# undef LEGACY_MACOS +#endif #endif /******************************************************************************/ @@ -128,8 +137,7 @@ #endif /* MinGW-W64 does not support C11 aligned_alloc, but it supports - * MSVC's _aligned_malloc. Also, fallback to use mm_malloc.h - * implementation for macOS systems prior to 10.15 Catalina. + * MSVC's _aligned_malloc. */ #ifndef KRML_ALIGNED_MALLOC # ifdef __MINGW32__ @@ -139,10 +147,7 @@ defined(_MSC_VER) || \ (defined(__MINGW32__) && defined(__MINGW64_VERSION_MAJOR))) # define KRML_ALIGNED_MALLOC(X, Y) _aligned_malloc(Y, X) -# elif defined(__APPLE__) && defined(__MACH__) && \ - defined(MAC_OS_X_VERSION_MIN_REQUIRED) && \ - (MAC_OS_X_VERSION_MIN_REQUIRED < 101500) -# include +# elif defined(LEGACY_MACOS) # define KRML_ALIGNED_MALLOC(X, Y) _mm_malloc(Y, X) # else # define KRML_ALIGNED_MALLOC(X, Y) aligned_alloc(X, Y) @@ -161,6 +166,8 @@ defined(_MSC_VER) || \ (defined(__MINGW32__) && defined(__MINGW64_VERSION_MAJOR))) # define KRML_ALIGNED_FREE(X) _aligned_free(X) +# elif defined(LEGACY_MACOS) +# define KRML_ALIGNED_FREE(X) _mm_free(X) # else # define KRML_ALIGNED_FREE(X) free(X) # endif