Changes in libcfa/src/stdlib.hfa [e3fea42:d6b03b7]
- File:
-
- 1 edited
-
libcfa/src/stdlib.hfa (modified) (7 diffs)
Legend:
- Unmodified
- Added
- Removed
-
libcfa/src/stdlib.hfa
re3fea42 rd6b03b7 10 10 // Created On : Thu Jan 28 17:12:35 2016 11 11 // Last Modified By : Peter A. Buhr 12 // Last Modified On : Tue Feb 4 08:27:01 202013 // Update Count : 40112 // Last Modified On : Tue Jul 23 14:14:59 2019 13 // Update Count : 373 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 heap27 void * cmemalign( size_t alignment, size_t noOfElems, size_t elemSize ); // CFA 28 28 } // extern "C" 29 30 void * realloc( void * oaddr, size_t nalign, size_t size ); // CFA heap31 29 32 30 //--------------------------------------- … … 52 50 } // calloc 53 51 54 T * realloc( T * ptr, size_t size ) { // CFA realloc, eliminate return-type cast 55 return (T *)(void *)realloc( (void *)ptr, size ); // C realloc 52 T * realloc( T * ptr, size_t size ) { 53 if ( unlikely( ptr == 0 ) ) return malloc(); 54 return (T *)(void *)realloc( (void *)ptr, size ); 56 55 } // realloc 57 56 58 57 T * memalign( size_t align ) { 59 return (T *)memalign( align, sizeof(T) ); // C memalign58 return (T *)memalign( align, sizeof(T) ); 60 59 } // memalign 61 60 62 T * cmemalign( size_t align, size_t dim ) {63 return (T *)cmemalign( align, dim, sizeof(T) ); // CFA cmemalign64 } // cmemalign65 66 61 T * aligned_alloc( size_t align ) { 67 return (T *)aligned_alloc( align, sizeof(T) ); // C aligned_alloc62 return (T *)aligned_alloc( align, sizeof(T) ); 68 63 } // aligned_alloc 69 64 … … 72 67 } // posix_memalign 73 68 69 74 70 // Cforall dynamic allocation 75 71 … … 78 74 } // alloc 79 75 76 T * alloc( char fill ) { 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) ); 80 return (T *)memset( ptr, (int)fill, sizeof(T) ); // initialize with fill value 81 } // alloc 82 80 83 T * alloc( size_t dim ) { 81 if ( _Alignof(T) <= libAlign() ) return (T *)(void *)malloc( dim * (size_t)sizeof(T) ); 84 if ( _Alignof(T) <= libAlign() ) return (T *)(void *)malloc( dim * (size_t)sizeof(T) ); // C malloc 82 85 else return (T *)memalign( _Alignof(T), dim * sizeof(T) ); 83 86 } // alloc 84 87 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 ) { 88 T * alloc( size_t dim, char fill ) { 98 89 return (T *)memset( (T *)alloc( dim ), (int)fill, dim * sizeof(T) ); // initialize with fill value 99 90 } // alloc 100 91 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 ) { 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 ) { 118 100 return (T *)memalign( align, sizeof(T) ); 119 } // alloc_align 120 121 T * alloc_align( size_t align, size_t dim ) { 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 ) { 122 109 return (T *)memalign( align, dim * sizeof(T) ); 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 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 159 123 160 124 static inline forall( dtype T | sized(T) ) { 161 125 // data, non-array types 126 162 127 T * memset( T * dest, char fill ) { 163 128 return (T *)memset( dest, fill, sizeof(T) ); … … 171 136 static inline forall( dtype T | sized(T) ) { 172 137 // data, array types 138 173 139 T * amemset( T dest[], char fill, size_t dim ) { 174 140 return (T *)(void *)memset( dest, fill, dim * sizeof(T) ); // C memset … … 193 159 194 160 static inline { 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 );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 ); 210 176 211 177 static inline { 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); }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 ); } 226 192 } // distribution 227 193
Note:
See TracChangeset
for help on using the changeset viewer.