xref: /freebsd-src/contrib/llvm-project/clang/lib/Headers/ppc_wrappers/mm_malloc.h (revision bdd1243df58e60e85101c09001d9812a789b6bc4)
10b57cec5SDimitry Andric /*===---- mm_malloc.h - Implementation of _mm_malloc and _mm_free ----------===
20b57cec5SDimitry Andric  *
30b57cec5SDimitry Andric  * Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
40b57cec5SDimitry Andric  * See https://llvm.org/LICENSE.txt for license information.
50b57cec5SDimitry Andric  * SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
60b57cec5SDimitry Andric  *
70b57cec5SDimitry Andric  *===-----------------------------------------------------------------------===
80b57cec5SDimitry Andric  */
90b57cec5SDimitry Andric 
100b57cec5SDimitry Andric #ifndef _MM_MALLOC_H_INCLUDED
110b57cec5SDimitry Andric #define _MM_MALLOC_H_INCLUDED
120b57cec5SDimitry Andric 
13*bdd1243dSDimitry Andric #if defined(__powerpc64__) &&                                                  \
14fcaf7f86SDimitry Andric     (defined(__linux__) || defined(__FreeBSD__) || defined(_AIX))
15a7dea167SDimitry Andric 
160b57cec5SDimitry Andric #include <stdlib.h>
170b57cec5SDimitry Andric 
180b57cec5SDimitry Andric /* We can't depend on <stdlib.h> since the prototype of posix_memalign
190b57cec5SDimitry Andric    may not be visible.  */
200b57cec5SDimitry Andric #ifndef __cplusplus
210b57cec5SDimitry Andric extern int posix_memalign(void **, size_t, size_t);
220b57cec5SDimitry Andric #else
23d56accc7SDimitry Andric extern "C" int posix_memalign(void **, size_t, size_t);
240b57cec5SDimitry Andric #endif
250b57cec5SDimitry Andric 
_mm_malloc(size_t __size,size_t __alignment)2681ad6265SDimitry Andric static __inline void *_mm_malloc(size_t __size, size_t __alignment) {
270b57cec5SDimitry Andric   /* PowerPC64 ELF V2 ABI requires quadword alignment.  */
2881ad6265SDimitry Andric   size_t __vec_align = sizeof(__vector float);
2981ad6265SDimitry Andric   void *__ptr;
300b57cec5SDimitry Andric 
3181ad6265SDimitry Andric   if (__alignment < __vec_align)
3281ad6265SDimitry Andric     __alignment = __vec_align;
3381ad6265SDimitry Andric   if (posix_memalign(&__ptr, __alignment, __size) == 0)
3481ad6265SDimitry Andric     return __ptr;
350b57cec5SDimitry Andric   else
360b57cec5SDimitry Andric     return NULL;
370b57cec5SDimitry Andric }
380b57cec5SDimitry Andric 
_mm_free(void * __ptr)3981ad6265SDimitry Andric static __inline void _mm_free(void *__ptr) { free(__ptr); }
400b57cec5SDimitry Andric 
41a7dea167SDimitry Andric #else
42a7dea167SDimitry Andric #include_next <mm_malloc.h>
43a7dea167SDimitry Andric #endif
44a7dea167SDimitry Andric 
450b57cec5SDimitry Andric #endif /* _MM_MALLOC_H_INCLUDED */
46