mm_malloc.h 1.7 KB

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