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(__linux__) && defined(__ppc64__) 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) throw (); 23 #endif 24 25 static __inline void * 26 _mm_malloc (size_t size, size_t alignment) 27 { 28 /* PowerPC64 ELF V2 ABI requires quadword alignment. */ 29 size_t vec_align = sizeof (__vector float); 30 void *ptr; 31 32 if (alignment < vec_align) 33 alignment = vec_align; 34 if (posix_memalign (&ptr, alignment, size) == 0) 35 return ptr; 36 else 37 return NULL; 38 } 39 40 static __inline void 41 _mm_free (void * ptr) 42 { 43 free (ptr); 44 } 45 46 #else 47 #include_next <mm_malloc.h> 48 #endif 49 50 #endif /* _MM_MALLOC_H_INCLUDED */ 51