1 1.1.1.4 mrg /* Copyright (C) 2004-2022 Free Software Foundation, Inc. 2 1.1 mrg 3 1.1 mrg This file is part of GCC. 4 1.1 mrg 5 1.1 mrg GCC is free software; you can redistribute it and/or modify 6 1.1 mrg it under the terms of the GNU General Public License as published by 7 1.1 mrg the Free Software Foundation; either version 3, or (at your option) 8 1.1 mrg any later version. 9 1.1 mrg 10 1.1 mrg GCC is distributed in the hope that it will be useful, 11 1.1 mrg but WITHOUT ANY WARRANTY; without even the implied warranty of 12 1.1 mrg MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 1.1 mrg GNU General Public License for more details. 14 1.1 mrg 15 1.1 mrg Under Section 7 of GPL version 3, you are granted additional 16 1.1 mrg permissions described in the GCC Runtime Library Exception, version 17 1.1 mrg 3.1, as published by the Free Software Foundation. 18 1.1 mrg 19 1.1 mrg You should have received a copy of the GNU General Public License and 20 1.1 mrg a copy of the GCC Runtime Library Exception along with this program; 21 1.1 mrg see the files COPYING3 and COPYING.RUNTIME respectively. If not, see 22 1.1 mrg <http://www.gnu.org/licenses/>. */ 23 1.1 mrg 24 1.1 mrg #ifndef _MM_MALLOC_H_INCLUDED 25 1.1 mrg #define _MM_MALLOC_H_INCLUDED 26 1.1 mrg 27 1.1 mrg #include <stdlib.h> 28 1.1 mrg 29 1.1 mrg /* We can't depend on <stdlib.h> since the prototype of posix_memalign 30 1.1 mrg may not be visible. */ 31 1.1 mrg #ifndef __cplusplus 32 1.1 mrg extern int posix_memalign (void **, size_t, size_t); 33 1.1 mrg #else 34 1.1 mrg extern "C" int posix_memalign (void **, size_t, size_t) throw (); 35 1.1 mrg #endif 36 1.1 mrg 37 1.1 mrg static __inline void * 38 1.1.1.3 mrg _mm_malloc (size_t __size, size_t __alignment) 39 1.1 mrg { 40 1.1 mrg /* PowerPC64 ELF V2 ABI requires quadword alignment. */ 41 1.1.1.3 mrg size_t __vec_align = sizeof (__vector float); 42 1.1 mrg /* Linux GLIBC malloc alignment is at least 2 X ptr size. */ 43 1.1.1.3 mrg size_t __malloc_align = (sizeof (void *) + sizeof (void *)); 44 1.1.1.3 mrg void *__ptr; 45 1.1 mrg 46 1.1.1.3 mrg if (__alignment == __malloc_align && __alignment == __vec_align) 47 1.1.1.3 mrg return malloc (__size); 48 1.1.1.3 mrg if (__alignment < __vec_align) 49 1.1.1.3 mrg __alignment = __vec_align; 50 1.1.1.3 mrg if (posix_memalign (&__ptr, __alignment, __size) == 0) 51 1.1.1.3 mrg return __ptr; 52 1.1 mrg else 53 1.1 mrg return NULL; 54 1.1 mrg } 55 1.1 mrg 56 1.1 mrg static __inline void 57 1.1.1.3 mrg _mm_free (void * __ptr) 58 1.1 mrg { 59 1.1.1.3 mrg free (__ptr); 60 1.1 mrg } 61 1.1 mrg 62 1.1 mrg #endif /* _MM_MALLOC_H_INCLUDED */ 63