comparison gcc/config/i386/gmm_malloc.h @ 111:04ced10e8804

gcc 7
author kono
date Fri, 27 Oct 2017 22:46:09 +0900
parents a06113de4d67
children 84e7813d76e9
comparison
equal deleted inserted replaced
68:561a7518be6b 111:04ced10e8804
1 /* Copyright (C) 2004, 2009 Free Software Foundation, Inc. 1 /* Copyright (C) 2004-2017 Free Software Foundation, Inc.
2 2
3 This file is part of GCC. 3 This file is part of GCC.
4 4
5 GCC is free software; you can redistribute it and/or modify 5 GCC is free software; you can redistribute it and/or modify
6 it under the terms of the GNU General Public License as published by 6 it under the terms of the GNU General Public License as published by
25 #define _MM_MALLOC_H_INCLUDED 25 #define _MM_MALLOC_H_INCLUDED
26 26
27 #include <stdlib.h> 27 #include <stdlib.h>
28 #include <errno.h> 28 #include <errno.h>
29 29
30 static __inline__ void* 30 static __inline__ void *
31 _mm_malloc (size_t size, size_t align) 31 _mm_malloc (size_t __size, size_t __align)
32 { 32 {
33 void * malloc_ptr; 33 void * __malloc_ptr;
34 void * aligned_ptr; 34 void * __aligned_ptr;
35 35
36 /* Error if align is not a power of two. */ 36 /* Error if align is not a power of two. */
37 if (align & (align - 1)) 37 if (__align & (__align - 1))
38 { 38 {
39 errno = EINVAL; 39 errno = EINVAL;
40 return ((void*) 0); 40 return ((void *) 0);
41 } 41 }
42 42
43 if (size == 0) 43 if (__size == 0)
44 return ((void *) 0); 44 return ((void *) 0);
45 45
46 /* Assume malloc'd pointer is aligned at least to sizeof (void*). 46 /* Assume malloc'd pointer is aligned at least to sizeof (void*).
47 If necessary, add another sizeof (void*) to store the value 47 If necessary, add another sizeof (void*) to store the value
48 returned by malloc. Effectively this enforces a minimum alignment 48 returned by malloc. Effectively this enforces a minimum alignment
49 of sizeof double. */ 49 of sizeof double. */
50 if (align < 2 * sizeof (void *)) 50 if (__align < 2 * sizeof (void *))
51 align = 2 * sizeof (void *); 51 __align = 2 * sizeof (void *);
52 52
53 malloc_ptr = malloc (size + align); 53 __malloc_ptr = malloc (__size + __align);
54 if (!malloc_ptr) 54 if (!__malloc_ptr)
55 return ((void *) 0); 55 return ((void *) 0);
56 56
57 /* Align We have at least sizeof (void *) space below malloc'd ptr. */ 57 /* Align We have at least sizeof (void *) space below malloc'd ptr. */
58 aligned_ptr = (void *) (((size_t) malloc_ptr + align) 58 __aligned_ptr = (void *) (((size_t) __malloc_ptr + __align)
59 & ~((size_t) (align) - 1)); 59 & ~((size_t) (__align) - 1));
60 60
61 /* Store the original pointer just before p. */ 61 /* Store the original pointer just before p. */
62 ((void **) aligned_ptr) [-1] = malloc_ptr; 62 ((void **) __aligned_ptr)[-1] = __malloc_ptr;
63 63
64 return aligned_ptr; 64 return __aligned_ptr;
65 } 65 }
66 66
67 static __inline__ void 67 static __inline__ void
68 _mm_free (void * aligned_ptr) 68 _mm_free (void *__aligned_ptr)
69 { 69 {
70 if (aligned_ptr) 70 if (__aligned_ptr)
71 free (((void **) aligned_ptr) [-1]); 71 free (((void **) __aligned_ptr)[-1]);
72 } 72 }
73 73
74 #endif /* _MM_MALLOC_H_INCLUDED */ 74 #endif /* _MM_MALLOC_H_INCLUDED */