Changeset d6b03b7 for libcfa/src
- Timestamp:
- Jul 23, 2019, 4:46:27 PM (5 years ago)
- Branches:
- ADT, arm-eh, ast-experimental, enum, forall-pointer-decay, jacob/cs343-translation, jenkins-sandbox, master, new-ast, new-ast-unique-expr, pthread-emulation, qualifiedEnum
- Children:
- 8fc15cf
- Parents:
- b5ce31e
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
libcfa/src/stdlib.hfa
rb5ce31e rd6b03b7 10 10 // Created On : Thu Jan 28 17:12:35 2016 11 11 // Last Modified By : Peter A. Buhr 12 // Last Modified On : Wed Apr 24 17:35:43201913 // Update Count : 3 5212 // Last Modified On : Tue Jul 23 14:14:59 2019 13 // Update Count : 373 14 14 // 15 15 … … 17 17 18 18 #include "bits/defs.hfa" 19 #include "bits/align.hfa" 19 20 20 21 #include <stdlib.h> // *alloc, strto*, ato* 22 21 23 extern "C" { 22 24 void * memalign( size_t align, size_t size ); // malloc.h … … 39 41 40 42 T * malloc( void ) { 41 return (T *)(void *)malloc( (size_t)sizeof(T) ); // C malloc 43 if ( _Alignof(T) <= libAlign() ) return (T *)(void *)malloc( (size_t)sizeof(T) ); // C malloc 44 else return (T *)memalign( _Alignof(T), sizeof(T) ); 42 45 } // malloc 43 46 44 47 T * calloc( size_t dim ) { 45 return (T *)(void *)calloc( dim, sizeof(T) ); // C calloc 48 if ( _Alignof(T) <= libAlign() )return (T *)(void *)calloc( dim, sizeof(T) ); // C calloc 49 else return (T *)cmemalign( _Alignof(T), dim, sizeof(T) ); 46 50 } // calloc 47 51 48 52 T * realloc( T * ptr, size_t size ) { 53 if ( unlikely( ptr == 0 ) ) return malloc(); 49 54 return (T *)(void *)realloc( (void *)ptr, size ); 50 55 } // realloc … … 66 71 67 72 T * alloc( void ) { 68 return (T *)(void *)malloc( (size_t)sizeof(T) ); // C malloc73 return malloc(); 69 74 } // alloc 70 75 71 76 T * alloc( char fill ) { 72 T * ptr = (T *)(void *)malloc( (size_t)sizeof(T) ); // C malloc 77 T * ptr; 78 if ( _Alignof(T) <= libAlign() ) ptr = (T *)(void *)malloc( (size_t)sizeof(T) ); // C malloc 79 else ptr = (T *)memalign( _Alignof(T), sizeof(T) ); 73 80 return (T *)memset( ptr, (int)fill, sizeof(T) ); // initialize with fill value 74 81 } // alloc 75 82 76 83 T * alloc( size_t dim ) { 77 return (T *)(void *)malloc( dim * (size_t)sizeof(T) ); // C malloc 84 if ( _Alignof(T) <= libAlign() ) return (T *)(void *)malloc( dim * (size_t)sizeof(T) ); // C malloc 85 else return (T *)memalign( _Alignof(T), dim * sizeof(T) ); 78 86 } // alloc 79 87 80 88 T * alloc( size_t dim, char fill ) { 81 T * ptr = (T *)(void *)malloc( dim * (size_t)sizeof(T) ); // C calloc 82 return (T *)memset( ptr, (int)fill, dim * sizeof(T) ); // initialize with fill value 89 return (T *)memset( (T *)alloc( dim ), (int)fill, dim * sizeof(T) ); // initialize with fill value 83 90 } // alloc 84 91 85 92 T * alloc( T ptr[], size_t dim ) { 86 return (T *)(void *)realloc( (void *)ptr, dim * (size_t)sizeof(T) ); // C realloc 87 } // alloc 88 } // distribution 89 90 91 forall( dtype T | sized(T) ) T * alloc( T ptr[], size_t dim, char fill ); 93 return realloc( ptr, dim * sizeof(T) ); 94 } // alloc 95 } // distribution 92 96 93 97 … … 107 111 108 112 T * align_alloc( size_t align, size_t dim, char fill ) { 109 T * ptr;110 113 if ( fill == '\0' ) { 111 ptr =(T *)cmemalign( align, dim, sizeof(T) );114 return (T *)cmemalign( align, dim, sizeof(T) ); 112 115 } else { 113 ptr = (T *)memalign( align, dim * sizeof(T) ); 114 return (T *)memset( ptr, (int)fill, dim * sizeof(T) ); 116 return (T *)memset( (T *)memalign( align, dim * sizeof(T) ), (int)fill, dim * sizeof(T) ); 115 117 } // if 116 return ptr; 117 } // align_alloc 118 } // distribution 118 } // align_alloc 119 } // distribution 120 121 forall( dtype T | sized(T) ) T * alloc( T ptr[], size_t dim, char fill ); 119 122 120 123
Note: See TracChangeset
for help on using the changeset viewer.