blob: 24b14c8e07c019cd29d9a27f3e139efe6039f64f [file] [log] [blame]
Logan Chiendf4f7662019-09-04 16:45:23 -07001/*===---- 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 Chienbedbf4f2020-01-06 19:35:19 -080013#if defined(__linux__) && defined(__ppc64__)
14
Logan Chiendf4f7662019-09-04 16:45:23 -070015#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
20extern int posix_memalign (void **, size_t, size_t);
21#else
22extern "C" int posix_memalign (void **, size_t, size_t) throw ();
23#endif
24
25static __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 Chiendf4f7662019-09-04 16:45:23 -070030 void *ptr;
31
Logan Chiendf4f7662019-09-04 16:45:23 -070032 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
40static __inline void
41_mm_free (void * ptr)
42{
43 free (ptr);
44}
45
Logan Chienbedbf4f2020-01-06 19:35:19 -080046#else
47#include_next <mm_malloc.h>
48#endif
49
Logan Chiendf4f7662019-09-04 16:45:23 -070050#endif /* _MM_MALLOC_H_INCLUDED */