Logan Chien | df4f766 | 2019-09-04 16:45:23 -0700 | [diff] [blame] | 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 | |
Logan Chien | bedbf4f | 2020-01-06 19:35:19 -0800 | [diff] [blame] | 13 | #if defined(__linux__) && defined(__ppc64__) |
| 14 | |
Logan Chien | df4f766 | 2019-09-04 16:45:23 -0700 | [diff] [blame] | 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); |
Logan Chien | df4f766 | 2019-09-04 16:45:23 -0700 | [diff] [blame] | 30 | void *ptr; |
| 31 | |
Logan Chien | df4f766 | 2019-09-04 16:45:23 -0700 | [diff] [blame] | 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 | |
Logan Chien | bedbf4f | 2020-01-06 19:35:19 -0800 | [diff] [blame] | 46 | #else |
| 47 | #include_next <mm_malloc.h> |
| 48 | #endif |
| 49 | |
Logan Chien | df4f766 | 2019-09-04 16:45:23 -0700 | [diff] [blame] | 50 | #endif /* _MM_MALLOC_H_INCLUDED */ |