Details | Last modification | View Log | RSS feed
| Rev | Author | Line No. | Line |
|---|---|---|---|
| 14 | pmbaty | 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(__powerpc64__) && \ |
||
| 14 | (defined(__linux__) || defined(__FreeBSD__) || defined(_AIX)) |
||
| 15 | |||
| 16 | #include <stdlib.h> |
||
| 17 | |||
| 18 | /* We can't depend on <stdlib.h> since the prototype of posix_memalign |
||
| 19 | may not be visible. */ |
||
| 20 | #ifndef __cplusplus |
||
| 21 | extern int posix_memalign(void **, size_t, size_t); |
||
| 22 | #else |
||
| 23 | extern "C" int posix_memalign(void **, size_t, size_t); |
||
| 24 | #endif |
||
| 25 | |||
| 26 | static __inline void *_mm_malloc(size_t __size, size_t __alignment) { |
||
| 27 | /* PowerPC64 ELF V2 ABI requires quadword alignment. */ |
||
| 28 | size_t __vec_align = sizeof(__vector float); |
||
| 29 | void *__ptr; |
||
| 30 | |||
| 31 | if (__alignment < __vec_align) |
||
| 32 | __alignment = __vec_align; |
||
| 33 | if (posix_memalign(&__ptr, __alignment, __size) == 0) |
||
| 34 | return __ptr; |
||
| 35 | else |
||
| 36 | return NULL; |
||
| 37 | } |
||
| 38 | |||
| 39 | static __inline void _mm_free(void *__ptr) { free(__ptr); } |
||
| 40 | |||
| 41 | #else |
||
| 42 | #include_next <mm_malloc.h> |
||
| 43 | #endif |
||
| 44 | |||
| 45 | #endif /* _MM_MALLOC_H_INCLUDED */ |