1 /*===---- mm_malloc.h - Implementation of _mm_malloc and _mm_free ----------=== 2 * 3 * Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. 4 * See https://llvm.org/LICENSE.txt for license information. 5 * SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception 6 * 7 *===-----------------------------------------------------------------------=== 8 */ 9 10 #ifndef _MM_MALLOC_H_INCLUDED 11 #define _MM_MALLOC_H_INCLUDED 12 13 #if defined(__ppc64__) && (defined(__linux__) || defined(__FreeBSD__)) 14 15 #include <stdlib.h> 16 17 /* We can't depend on <stdlib.h> since the prototype of posix_memalign 18 may not be visible. */ 19 #ifndef __cplusplus 20 extern int posix_memalign(void **, size_t, size_t); 21 #else 22 extern "C" int posix_memalign(void **, size_t, size_t); 23 #endif 24 25 static __inline void *_mm_malloc(size_t __size, size_t __alignment) { 26 /* PowerPC64 ELF V2 ABI requires quadword alignment. */ 27 size_t __vec_align = sizeof(__vector float); 28 void *__ptr; 29 30 if (__alignment < __vec_align) 31 __alignment = __vec_align; 32 if (posix_memalign(&__ptr, __alignment, __size) == 0) 33 return __ptr; 34 else 35 return NULL; 36 } 37 38 static __inline void _mm_free(void *__ptr) { free(__ptr); } 39 40 #else 41 #include_next <mm_malloc.h> 42 #endif 43 44 #endif /* _MM_MALLOC_H_INCLUDED */ 45