mirror of
https://github.com/opelly27/Stockfish.git
synced 2026-05-20 03:57:45 +00:00
More aligned_alloc changes to support Android
Move to posix_memalign for those platforms, in particular android, that do not fully support c++17 std::aligned_alloc() (and are not windows) see https://github.com/official-stockfish/Stockfish/issues/2860 closes https://github.com/official-stockfish/Stockfish/pull/2973 No functional change
This commit is contained in:
+11
-3
@@ -51,6 +51,11 @@ typedef bool(*fun3_t)(HANDLE, CONST GROUP_AFFINITY*, PGROUP_AFFINITY);
|
|||||||
#include <sys/mman.h>
|
#include <sys/mman.h>
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
#if (defined(__APPLE__) && defined(_LIBCPP_HAS_C11_FEATURES)) || defined(__ANDROID__) || defined(__OpenBSD__) || (defined(__GLIBCXX__) && !defined(_GLIBCXX_HAVE_ALIGNED_ALLOC) && !defined(_WIN32))
|
||||||
|
#define POSIXALIGNEDALLOC
|
||||||
|
#include <stdlib.h>
|
||||||
|
#endif
|
||||||
|
|
||||||
#include "misc.h"
|
#include "misc.h"
|
||||||
#include "thread.h"
|
#include "thread.h"
|
||||||
|
|
||||||
@@ -318,8 +323,11 @@ void prefetch(void* addr) {
|
|||||||
///
|
///
|
||||||
|
|
||||||
void* std_aligned_alloc(size_t alignment, size_t size) {
|
void* std_aligned_alloc(size_t alignment, size_t size) {
|
||||||
#if (defined(__APPLE__) && defined(_LIBCPP_HAS_C11_FEATURES)) || defined(__ANDROID__) || defined(__OpenBSD__) || (defined(__GLIBCXX__) && !defined(_GLIBCXX_HAVE_ALIGNED_ALLOC) && !defined(_WIN32))
|
#if defined(POSIXALIGNEDALLOC)
|
||||||
return aligned_alloc(alignment, size);
|
void *pointer;
|
||||||
|
if(posix_memalign(&pointer, alignment, size) == 0)
|
||||||
|
return pointer;
|
||||||
|
return nullptr;
|
||||||
#elif (defined(_WIN32) || (defined(__APPLE__) && !defined(_LIBCPP_HAS_C11_FEATURES)))
|
#elif (defined(_WIN32) || (defined(__APPLE__) && !defined(_LIBCPP_HAS_C11_FEATURES)))
|
||||||
return _mm_malloc(size, alignment);
|
return _mm_malloc(size, alignment);
|
||||||
#else
|
#else
|
||||||
@@ -328,7 +336,7 @@ void* std_aligned_alloc(size_t alignment, size_t size) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void std_aligned_free(void* ptr) {
|
void std_aligned_free(void* ptr) {
|
||||||
#if (defined(__APPLE__) && defined(_LIBCPP_HAS_C11_FEATURES)) || defined(__ANDROID__) || defined(__OpenBSD__) || (defined(__GLIBCXX__) && !defined(_GLIBCXX_HAVE_ALIGNED_ALLOC) && !defined(_WIN32))
|
#if defined(POSIXALIGNEDALLOC)
|
||||||
free(ptr);
|
free(ptr);
|
||||||
#elif (defined(_WIN32) || (defined(__APPLE__) && !defined(_LIBCPP_HAS_C11_FEATURES)))
|
#elif (defined(_WIN32) || (defined(__APPLE__) && !defined(_LIBCPP_HAS_C11_FEATURES)))
|
||||||
_mm_free(ptr);
|
_mm_free(ptr);
|
||||||
|
|||||||
Reference in New Issue
Block a user