Changeset 3d5701e for libcfa/src/stdlib.hfa
- Timestamp:
- Feb 25, 2020, 1:17:33 PM (6 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:
- 7dc2e015
- Parents:
- 9fb8f01 (diff), dd9e1ca (diff)
Note: this is a merge changeset, the changes displayed below correspond to the merge itself.
Use the(diff)links above to see all the changes relative to each parent. - File:
-
- 1 edited
-
libcfa/src/stdlib.hfa (modified) (7 diffs)
Legend:
- Unmodified
- Added
- Removed
-
libcfa/src/stdlib.hfa
r9fb8f01 r3d5701e 10 10 // Created On : Thu Jan 28 17:12:35 2016 11 11 // Last Modified By : Peter A. Buhr 12 // Last Modified On : Tue Jul 23 14:14:59 201913 // Update Count : 37312 // Last Modified On : Tue Feb 4 08:27:01 2020 13 // Update Count : 401 14 14 // 15 15 … … 25 25 void * memset( void * dest, int fill, size_t size ); // string.h 26 26 void * memcpy( void * dest, const void * src, size_t size ); // string.h 27 void * cmemalign( size_t alignment, size_t noOfElems, size_t elemSize ); // CFA 27 void * cmemalign( size_t alignment, size_t noOfElems, size_t elemSize ); // CFA heap 28 28 } // extern "C" 29 30 void * realloc( void * oaddr, size_t nalign, size_t size ); // CFA heap 29 31 30 32 //--------------------------------------- … … 50 52 } // calloc 51 53 52 T * realloc( T * ptr, size_t size ) { 53 if ( unlikely( ptr == 0 ) ) return malloc(); 54 return (T *)(void *)realloc( (void *)ptr, size ); 54 T * realloc( T * ptr, size_t size ) { // CFA realloc, eliminate return-type cast 55 return (T *)(void *)realloc( (void *)ptr, size ); // C realloc 55 56 } // realloc 56 57 57 58 T * memalign( size_t align ) { 58 return (T *)memalign( align, sizeof(T) ); 59 return (T *)memalign( align, sizeof(T) ); // C memalign 59 60 } // memalign 60 61 62 T * cmemalign( size_t align, size_t dim ) { 63 return (T *)cmemalign( align, dim, sizeof(T) ); // CFA cmemalign 64 } // cmemalign 65 61 66 T * aligned_alloc( size_t align ) { 62 return (T *)aligned_alloc( align, sizeof(T) ); 67 return (T *)aligned_alloc( align, sizeof(T) ); // C aligned_alloc 63 68 } // aligned_alloc 64 69 … … 67 72 } // posix_memalign 68 73 69 70 74 // Cforall dynamic allocation 71 75 … … 74 78 } // alloc 75 79 76 T * alloc( char fill ) {77 T * ptr;78 if ( _Alignof(T) <= libAlign() ) ptr = (T *)(void *)malloc( (size_t)sizeof(T) ); // C malloc79 else ptr = (T *)memalign( _Alignof(T), sizeof(T) );80 return (T *)memset( ptr, (int)fill, sizeof(T) ); // initialize with fill value81 } // alloc82 83 80 T * alloc( size_t dim ) { 84 if ( _Alignof(T) <= libAlign() ) return (T *)(void *)malloc( dim * (size_t)sizeof(T) ); // C malloc81 if ( _Alignof(T) <= libAlign() ) return (T *)(void *)malloc( dim * (size_t)sizeof(T) ); 85 82 else return (T *)memalign( _Alignof(T), dim * sizeof(T) ); 86 83 } // alloc 87 84 88 T * alloc( size_t dim, char fill ) { 85 T * alloc( T ptr[], size_t dim ) { // realloc 86 return (T *)(void *)realloc( (void *)ptr, dim * sizeof(T) ); // C realloc 87 } // alloc 88 89 T * alloc_set( char fill ) { 90 return (T *)memset( (T *)alloc(), (int)fill, sizeof(T) ); // initialize with fill value 91 } // alloc 92 93 T * alloc_set( T fill ) { 94 return (T *)memcpy( (T *)alloc(), &fill, sizeof(T) ); // initialize with fill value 95 } // alloc 96 97 T * alloc_set( size_t dim, char fill ) { 89 98 return (T *)memset( (T *)alloc( dim ), (int)fill, dim * sizeof(T) ); // initialize with fill value 90 99 } // alloc 91 100 92 T * alloc( T ptr[], size_t dim ) { 93 return realloc( ptr, dim * sizeof(T) ); 94 } // alloc 95 } // distribution 96 97 98 static inline forall( dtype T | sized(T) ) { 99 T * align_alloc( size_t align ) { 101 T * alloc_set( size_t dim, T fill ) { 102 T * r = (T *)alloc( dim ); 103 for ( i; dim ) { memcpy( &r[i], &fill, sizeof(T) ); } // initialize with fill value 104 return r; 105 } // alloc 106 107 T * alloc_set( size_t dim, const T fill[] ) { 108 return (T *)memcpy( (T *)alloc( dim ), fill, dim * sizeof(T) ); // initialize with fill value 109 } // alloc 110 } // distribution 111 112 forall( dtype T | sized(T) ) { 113 T * alloc_set( T ptr[], size_t dim, char fill ); // realloc array with fill 114 } // distribution 115 116 static inline forall( dtype T | sized(T) ) { 117 T * alloc_align( size_t align ) { 100 118 return (T *)memalign( align, sizeof(T) ); 101 } // align_alloc 102 103 T * align_alloc( size_t align, char fill ) { 104 T * ptr = (T *)memalign( align, sizeof(T) ); 105 return (T *)memset( ptr, (int)fill, sizeof(T) ); 106 } // align_alloc 107 108 T * align_alloc( size_t align, size_t dim ) { 119 } // alloc_align 120 121 T * alloc_align( size_t align, size_t dim ) { 109 122 return (T *)memalign( align, dim * sizeof(T) ); 110 } // align_alloc 111 112 T * align_alloc( size_t align, size_t dim, char fill ) { 113 if ( fill == '\0' ) { 114 return (T *)cmemalign( align, dim, sizeof(T) ); 115 } else { 116 return (T *)memset( (T *)memalign( align, dim * sizeof(T) ), (int)fill, dim * sizeof(T) ); 117 } // if 118 } // align_alloc 119 } // distribution 120 121 forall( dtype T | sized(T) ) T * alloc( T ptr[], size_t dim, char fill ); 122 123 } // alloc_align 124 125 T * alloc_align( T ptr[], size_t align ) { // aligned realloc array 126 return (T *)(void *)realloc( (void *)ptr, align, sizeof(T) ); // CFA realloc 127 } // alloc_align 128 129 T * alloc_align( T ptr[], size_t align, size_t dim ) { // aligned realloc array 130 return (T *)(void *)realloc( (void *)ptr, align, dim * sizeof(T) ); // CFA realloc 131 } // alloc_align 132 133 T * alloc_align_set( size_t align, char fill ) { 134 return (T *)memset( (T *)alloc_align( align ), (int)fill, sizeof(T) ); // initialize with fill value 135 } // alloc_align 136 137 T * alloc_align_set( size_t align, T fill ) { 138 return (T *)memcpy( (T *)alloc_align( align ), &fill, sizeof(T) ); // initialize with fill value 139 } // alloc_align 140 141 T * alloc_align_set( size_t align, size_t dim, char fill ) { 142 return (T *)memset( (T *)alloc_align( align, dim ), (int)fill, dim * sizeof(T) ); // initialize with fill value 143 } // alloc_align 144 145 T * alloc_align_set( size_t align, size_t dim, T fill ) { 146 T * r = (T *)alloc_align( align, dim ); 147 for ( i; dim ) { memcpy( &r[i], &fill, sizeof(T) ); } // initialize with fill value 148 return r; 149 } // alloc_align 150 151 T * alloc_align_set( size_t align, size_t dim, const T fill[] ) { 152 return (T *)memcpy( (T *)alloc_align( align, dim ), fill, dim * sizeof(T) ); 153 } // alloc_align 154 } // distribution 155 156 forall( dtype T | sized(T) ) { 157 T * alloc_align_set( T ptr[], size_t align, size_t dim, char fill ); // aligned realloc array with fill 158 } // distribution 123 159 124 160 static inline forall( dtype T | sized(T) ) { 125 161 // data, non-array types 126 127 162 T * memset( T * dest, char fill ) { 128 163 return (T *)memset( dest, fill, sizeof(T) ); … … 136 171 static inline forall( dtype T | sized(T) ) { 137 172 // data, array types 138 139 173 T * amemset( T dest[], char fill, size_t dim ) { 140 174 return (T *)(void *)memset( dest, fill, dim * sizeof(T) ); // C memset … … 159 193 160 194 static inline { 161 int strto( const char * sptr, char ** eptr, int base ) { return (int)strtol( sptr, eptr, base ); }162 unsigned int strto( const char * sptr, char ** eptr, int base ) { return (unsigned int)strtoul( sptr, eptr, base ); }163 long int strto( const char * sptr, char ** eptr, int base ) { return strtol( sptr, eptr, base ); }164 unsigned long int strto( const char * sptr, char ** eptr, int base ) { return strtoul( sptr, eptr, base ); }165 long long int strto( const char * sptr, char ** eptr, int base ) { return strtoll( sptr, eptr, base ); }166 unsigned long long int strto( const char * sptr, char ** eptr, int base ) { return strtoull( sptr, eptr, base ); }167 168 float strto( const char * sptr, char ** eptr ) { return strtof( sptr, eptr ); }169 double strto( const char * sptr, char ** eptr ) { return strtod( sptr, eptr ); }170 long double strto( const char * sptr, char ** eptr ) { return strtold( sptr, eptr ); }171 } // distribution 172 173 float _Complex strto( const char * sptr, char ** eptr );174 double _Complex strto( const char * sptr, char ** eptr );175 long double _Complex strto( const char * sptr, char ** eptr );195 int strto( const char sptr[], char ** eptr, int base ) { return (int)strtol( sptr, eptr, base ); } 196 unsigned int strto( const char sptr[], char ** eptr, int base ) { return (unsigned int)strtoul( sptr, eptr, base ); } 197 long int strto( const char sptr[], char ** eptr, int base ) { return strtol( sptr, eptr, base ); } 198 unsigned long int strto( const char sptr[], char ** eptr, int base ) { return strtoul( sptr, eptr, base ); } 199 long long int strto( const char sptr[], char ** eptr, int base ) { return strtoll( sptr, eptr, base ); } 200 unsigned long long int strto( const char sptr[], char ** eptr, int base ) { return strtoull( sptr, eptr, base ); } 201 202 float strto( const char sptr[], char ** eptr ) { return strtof( sptr, eptr ); } 203 double strto( const char sptr[], char ** eptr ) { return strtod( sptr, eptr ); } 204 long double strto( const char sptr[], char ** eptr ) { return strtold( sptr, eptr ); } 205 } // distribution 206 207 float _Complex strto( const char sptr[], char ** eptr ); 208 double _Complex strto( const char sptr[], char ** eptr ); 209 long double _Complex strto( const char sptr[], char ** eptr ); 176 210 177 211 static inline { 178 int ato( const char * sptr ) { return (int)strtol( sptr, 0, 10 ); }179 unsigned int ato( const char * sptr ) { return (unsigned int)strtoul( sptr, 0, 10 ); }180 long int ato( const char * sptr ) { return strtol( sptr, 0, 10 ); }181 unsigned long int ato( const char * sptr ) { return strtoul( sptr, 0, 10 ); }182 long long int ato( const char * sptr ) { return strtoll( sptr, 0, 10 ); }183 unsigned long long int ato( const char * sptr ) { return strtoull( sptr, 0, 10 ); }184 185 float ato( const char * sptr ) { return strtof( sptr, 0); }186 double ato( const char * sptr ) { return strtod( sptr, 0); }187 long double ato( const char * sptr ) { return strtold( sptr, 0); }188 189 float _Complex ato( const char * sptr ) { return strto( sptr, NULL); }190 double _Complex ato( const char * sptr ) { return strto( sptr, NULL); }191 long double _Complex ato( const char * sptr ) { return strto( sptr, NULL); }212 int ato( const char sptr[] ) { return (int)strtol( sptr, 0p, 10 ); } 213 unsigned int ato( const char sptr[] ) { return (unsigned int)strtoul( sptr, 0p, 10 ); } 214 long int ato( const char sptr[] ) { return strtol( sptr, 0p, 10 ); } 215 unsigned long int ato( const char sptr[] ) { return strtoul( sptr, 0p, 10 ); } 216 long long int ato( const char sptr[] ) { return strtoll( sptr, 0p, 10 ); } 217 unsigned long long int ato( const char sptr[] ) { return strtoull( sptr, 0p, 10 ); } 218 219 float ato( const char sptr[] ) { return strtof( sptr, 0p ); } 220 double ato( const char sptr[] ) { return strtod( sptr, 0p ); } 221 long double ato( const char sptr[] ) { return strtold( sptr, 0p ); } 222 223 float _Complex ato( const char sptr[] ) { return strto( sptr, 0p ); } 224 double _Complex ato( const char sptr[] ) { return strto( sptr, 0p ); } 225 long double _Complex ato( const char sptr[] ) { return strto( sptr, 0p ); } 192 226 } // distribution 193 227
Note:
See TracChangeset
for help on using the changeset viewer.