Changeset 7042c60 for libcfa/src
- Timestamp:
- Apr 25, 2024, 3:48:17 PM (21 months ago)
- Branches:
- master
- Children:
- eb7586e
- Parents:
- cf191ac (diff), 55c97e4 (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. - Location:
- libcfa/src
- Files:
-
- 6 edited
-
concurrency/actor.hfa (modified) (2 diffs)
-
concurrency/kernel/fwd.hfa (modified) (1 diff)
-
device/cpu.cfa (modified) (1 diff)
-
iostream.hfa (modified) (2 diffs)
-
stdlib.cfa (modified) (3 diffs)
-
stdlib.hfa (modified) (13 diffs)
Legend:
- Unmodified
- Added
- Removed
-
libcfa/src/concurrency/actor.hfa
rcf191ac r7042c60 299 299 300 300 if ( seperate_clus ) { 301 cluster = alloc();301 this.cluster = alloc(); 302 302 (*cluster){}; 303 303 } else cluster = active_cluster(); … … 360 360 adelete( worker_req_queues ); 361 361 adelete( processors ); 362 if ( seperate_clus ) delete( cluster );362 if ( seperate_clus ) delete( this.cluster ); 363 363 364 364 #ifdef ACTOR_STATS // print formatted stats -
libcfa/src/concurrency/kernel/fwd.hfa
rcf191ac r7042c60 374 374 // since if that is the case, the oneshot was fulfilled (unparking this thread) 375 375 // and the oneshot should not be needed any more 376 __attribute__((unused)) struct oneshot * was = this.ptr;376 struct oneshot * was __attribute__((unused)) = this.ptr; // used in option verify 377 377 /* paranoid */ verifyf( was == future_FULFILLED, "Expected this.ptr to be 1p, was %p\n", was ); 378 378 -
libcfa/src/device/cpu.cfa
rcf191ac r7042c60 239 239 // Returns a 2D array of instances of size [cpu count][cache levels] 240 240 // where cache level doesn't include instruction caches 241 raw_cache_instance ** build_raw_cache_table(unsigned cpus_c, idx_range_t cpus, unsigned idxs, unsigned cache_levels) 242 { 241 raw_cache_instance ** build_raw_cache_table(unsigned cpus_c, idx_range_t cpus, unsigned idxs, unsigned cache_levels) { 243 242 raw_cache_instance ** raw = alloc(cpus_c, '\0'`fill); 244 243 -
libcfa/src/iostream.hfa
rcf191ac r7042c60 10 10 // Created On : Wed May 27 17:56:53 2015 11 11 // Last Modified By : Peter A. Buhr 12 // Last Modified On : Tue Feb 6 18:35:54202413 // Update Count : 74 312 // Last Modified On : Sun Apr 21 07:32:19 2024 13 // Update Count : 744 14 14 // 15 15 … … 160 160 161 161 // tuples 162 forall( ostype &, T, Params... | writeable( T, ostype ) | { ostype & ?|?( ostype &, Params); } ) {163 ostype & ?|?( ostype & os, T arg, Paramsrest );164 void ?|?( ostype & os, T arg, Paramsrest );162 forall( ostype &, T, List ... | writeable( T, ostype ) | { ostype & ?|?( ostype &, List ); } ) { 163 ostype & ?|?( ostype & os, T arg, List rest ); 164 void ?|?( ostype & os, T arg, List rest ); 165 165 } // distribution 166 166 -
libcfa/src/stdlib.cfa
rcf191ac r7042c60 10 10 // Created On : Thu Jan 28 17:10:29 2016 11 11 // Last Modified By : Peter A. Buhr 12 // Last Modified On : Sun Mar 17 08:25:32 202413 // Update Count : 69912 // Last Modified On : Sun Apr 21 16:17:22 2024 13 // Update Count : 700 14 14 // 15 15 … … 31 31 // Cforall allocation/deallocation and constructor/destructor, array types 32 32 33 forall( T & | sized(T), TT... | { void ?{}( T &, TT); } )34 T * anew( size_t dim, TTp ) {33 forall( T & | sized(T), Parms ... | { void ?{}( T &, Parms ); } ) 34 T * anew( size_t dim, Parms p ) { 35 35 T * arr = alloc( dim ); 36 36 for ( i; dim ) { … … 51 51 } // adelete 52 52 53 forall( T & | sized(T) | { void ^?{}( T & ); }, TT... | { void adelete( TT); } )54 void adelete( T arr[], TTrest ) {53 forall( T & | sized(T) | { void ^?{}( T & ); }, List ... | { void adelete( List ); } ) 54 void adelete( T arr[], List rest ) { 55 55 if ( arr ) { // ignore null 56 56 size_t dim = malloc_size( arr ) / sizeof( T ); -
libcfa/src/stdlib.hfa
rcf191ac r7042c60 10 10 // Created On : Thu Jan 28 17:12:35 2016 11 11 // Last Modified By : Peter A. Buhr 12 // Last Modified On : Mon Apr 15 22:11:51 202413 // Update Count : 81712 // Last Modified On : Tue Apr 23 14:05:21 2024 13 // Update Count : 963 14 14 // 15 15 … … 47 47 48 48 static inline forall( T & | sized(T) ) { 49 // CFA safe equivalents, i.e., implicit size specification 49 // CFA safe equivalents, i.e., implicit size specification, eliminate return-type cast 50 50 51 51 T * malloc( void ) { … … 64 64 } // calloc 65 65 66 T * resize( T * ptr, size_t size ) { // CFA resize67 if ( _Alignof(T) <= libAlign() ) return (T *)resize( (void *)ptr, size ); // C FAresize66 T * resize( T * ptr, size_t size ) { 67 if ( _Alignof(T) <= libAlign() ) return (T *)resize( (void *)ptr, size ); // C resize 68 68 else return (T *)resize( (void *)ptr, _Alignof(T), size ); // CFA resize 69 } // resize 70 71 T * resize( T * ptr, size_t alignment, size_t size ) { 72 return (T *)resize( (void *)ptr, alignment, size ); // CFA resize 69 73 } // resize 70 74 … … 74 78 } // realloc 75 79 80 T * realloc( T * ptr, size_t alignment, size_t size ) { 81 return (T *)realloc( (void *)ptr, alignment, size ); // CFA realloc 82 } // realloc 83 76 84 T * reallocarray( T * ptr, size_t dim ) { // CFA reallocarray 77 85 if ( _Alignof(T) <= libAlign() ) return (T *)reallocarray( (void *)ptr, dim, sizeof(T) ); // C reallocarray … … 79 87 } // realloc 80 88 89 T * reallocarray( T * ptr, size_t alignment, size_t dim ) { 90 return (T *)reallocarray( (void *)ptr, alignment, dim ); // CFA reallocarray 91 } // realloc 92 81 93 T * memalign( size_t align ) { 82 94 return (T *)memalign( align, sizeof(T) ); // C memalign … … 87 99 } // amemalign 88 100 89 T * cmemalign( size_t align, size_t dim ) {101 T * cmemalign( size_t align, size_t dim ) { 90 102 return (T *)cmemalign( align, dim, sizeof(T) ); // CFA cmemalign 91 103 } // cmemalign … … 109 121 110 122 /* 111 FIX ME : fix alloc interface after Ticker Number 214 is resolved, define and add union to S_fill. Then, modify postfix-fill functions to support T * with nmemb, char, and T object of any size. Finally, change alloc_internal. 123 FIX ME : fix alloc interface after Ticker Number 214 is resolved, define and add union to S_fill. Then, modify 124 postfix-fill functions to support T * with nmemb, char, and T object of any size. Finally, change alloc_internal. 112 125 Or, just follow the instructions below for that. 113 126 … … 153 166 */ 154 167 155 typedef struct S_align { inline size_t; } T_align; 156 typedef struct S_resize { inline void *; } T_resize; 157 158 forall( T & ) { 159 struct S_fill { char tag; char c; size_t size; T * at; char t[50]; }; 160 struct S_realloc { inline T *; }; 168 #pragma GCC diagnostic push 169 #pragma GCC diagnostic ignored "-Wmaybe-uninitialized" 170 #pragma GCC diagnostic ignored "-Wuninitialized" 171 172 struct T_align { size_t align; }; 173 struct T_resize { void * addr; }; 174 struct T_realloc { void * addr; }; 175 forall( T & ) struct T_fill { 176 // 'N' => no fill, 'c' => fill with character c, 'a' => fill first N array elements from another array, 177 // 'A' => fill all array elements from another array, 'T' => fill using a T value. 178 char tag; 179 size_t nelem; // number of elements copied from "at" (used with tag 'a') 180 // union { 181 char c; 182 T * at; 183 char t[64]; // T t; 184 // }; 185 }; 186 187 #pragma GCC diagnostic pop 188 189 static inline { 190 T_align ?`align( size_t a ) { return (T_align){ a }; } 191 T_resize ?`resize( void * a ) { return (T_resize){ a }; } 192 T_realloc ?`realloc( void * a ) { return (T_realloc){ a }; } 161 193 } 162 194 163 static inline T_align ?`align( size_t a ) { return (T_align){a}; }164 static inline T_resize ?`resize( void * a ) { return (T_resize){a}; }165 166 extern "C" ssize_t write(int fd, const void *buf, size_t count);167 195 static inline forall( T & | sized(T) ) { 168 S_fill(T) ?`fill ( T t ) { 169 S_fill(T) ret = { 't' }; 196 T_fill(T) ?`fill( char c ) { return (T_fill(T)){ 'c', 0, c }; } 197 T_fill(T) ?`fill( T t ) { 198 T_fill(T) ret = { 'T' }; 170 199 size_t size = sizeof(T); 171 200 if ( size > sizeof(ret.t) ) { … … 175 204 return ret; 176 205 } 177 S_fill(T) ?`fill ( zero_t ) = void; // FIX ME: remove this once ticket 214 is resolved 178 S_fill(T) ?`fill ( T * a ) { return (S_fill(T)){ 'T', '0', 0, a }; } // FIX ME: remove this once ticket 214 is resolved 179 S_fill(T) ?`fill ( char c ) { return (S_fill(T)){ 'c', c }; } 180 S_fill(T) ?`fill ( T a[], size_t nmemb ) { return (S_fill(T)){ 'a', '0', nmemb * sizeof(T), a }; } 181 182 S_realloc(T) ?`realloc ( T * a ) { return (S_realloc(T)){a}; } 183 184 T * alloc_internal$( void * Resize, T * Realloc, size_t Align, size_t Dim, S_fill(T) Fill ) { 185 T * ptr = NULL; 186 size_t size = sizeof(T); 206 T_fill(T) ?`fill( T a[] ) { return (T_fill(T)){ 'A', 0, '\0', a }; } // FIX ME: remove this once ticket 214 is resolved 207 T_fill(T) ?`fill( T a[], size_t nelem ) { return (T_fill(T)){ 'a', nelem * sizeof(T), '\0', a }; } 208 209 // private interface 210 T * alloc_internal$( size_t Dim, T_resize Resize, T_realloc Realloc, size_t Align, T_fill(T) Fill ) { 211 T * ptr; 212 size_t tsize = sizeof(T); 187 213 size_t copy_end = 0; 188 214 189 if ( Resize ) {190 ptr = (T *)(void *)resize( (void *)Resize, Align, Dim *size );191 } else if ( Realloc ) {192 if ( Fill.tag != ' 0' ) copy_end = min(malloc_size( Realloc ), Dim *size );193 ptr = (T *)(void *)realloc( (void *)Realloc, Align, Dim *size );215 if ( Resize.addr ) { 216 ptr = (T *)(void *)resize( Resize.addr, Align, Dim * tsize ); 217 } else if ( Realloc.addr ) { 218 if ( Fill.tag != 'N' ) copy_end = min(malloc_size( Realloc.addr ), Dim * tsize ); 219 ptr = (T *)(void *)realloc( Realloc.addr, Align, Dim * tsize ); 194 220 } else { 195 ptr = (T *)(void *) memalign( Align, Dim *size );196 } 221 ptr = (T *)(void *)memalign( Align, Dim * tsize ); 222 } // if 197 223 198 224 if ( Fill.tag == 'c' ) { 199 memset( (char *)ptr + copy_end, (int)Fill.c, Dim * size - copy_end ); 200 } else if ( Fill.tag == 't' ) { 201 for ( i; copy_end ~ Dim * size ~ size ) { 202 #pragma GCC diagnostic push 203 #pragma GCC diagnostic ignored "-Wmaybe-uninitialized" 204 assert( size <= sizeof(Fill.t) ); 205 memcpy( (char *)ptr + i, &Fill.t, size ); 206 #pragma GCC diagnostic pop 207 } 225 memset( (char *)ptr + copy_end, (int)Fill.c, Dim * tsize - copy_end ); 226 } else if ( Fill.tag == 'T' ) { 227 for ( i; copy_end ~ Dim * tsize ~ tsize ) { 228 assert( tsize <= sizeof(Fill.t) ); 229 memcpy( (char *)ptr + i, &Fill.t, tsize ); 230 } // for 208 231 } else if ( Fill.tag == 'a' ) { 209 memcpy( (char *)ptr + copy_end, Fill.at, min(Dim * size - copy_end, Fill.size) ); 210 } else if ( Fill.tag == 'T' ) { 211 memcpy( (char *)ptr + copy_end, Fill.at, Dim * size ); 212 } 213 232 memcpy( (char *)ptr + copy_end, Fill.at, min( Dim * tsize - copy_end, Fill.nelem ) ); 233 } else if ( Fill.tag == 'A' ) { 234 memcpy( (char *)ptr + copy_end, Fill.at, Dim * tsize ); 235 } // if 214 236 return ptr; 215 237 } // alloc_internal$ 216 238 217 forall( TT ... | { T * alloc_internal$( void *, T *, size_t, size_t, S_fill(T), TT ); } ) { 218 T * alloc_internal$( void *, T *, size_t Align, size_t Dim, S_fill(T) Fill, T_resize Resize, TT rest ) { 219 return alloc_internal$( Resize, (T*)0p, Align, Dim, Fill, rest); 239 // Dim is a fixed (optional first) parameter, and hence is not set using a postfix function. A dummy parameter is 240 // being overwritten by the postfix argument in the ttype. 241 forall( List ... | { T * alloc_internal$( size_t Dim, T_resize Resize, T_realloc Realloc, size_t Align, T_fill(T) Fill, List ); } ) { 242 // middle interface 243 T * alloc_internal$( size_t Dim, T_resize dummy, T_realloc Realloc, size_t Align, T_fill(T) Fill, T_resize Resize, List rest ) { 244 return alloc_internal$( Dim, Resize, (T_realloc){0p}, Align, Fill, rest ); 220 245 } 221 222 T * alloc_internal$( void *, T *, size_t Align, size_t Dim, S_fill(T) Fill, S_realloc(T) Realloc, TT rest ) { 223 return alloc_internal$( (void*)0p, Realloc, Align, Dim, Fill, rest); 246 T * alloc_internal$( size_t Dim, T_resize Resize, T_realloc dummy, size_t Align, T_fill(T) Fill, T_realloc Realloc, List rest ) { 247 return alloc_internal$( Dim, (T_resize){0p}, Realloc, Align, Fill, rest ); 224 248 } 225 226 T * alloc_internal$( void * Resize, T * Realloc, size_t, size_t Dim, S_fill(T) Fill, T_align Align, TT rest ) { 227 return alloc_internal$( Resize, Realloc, Align, Dim, Fill, rest); 249 T * alloc_internal$( size_t Dim, T_resize Resize, T_realloc Realloc, size_t dummy, T_fill(T) Fill, T_align Align, List rest ) { 250 return alloc_internal$( Dim, Resize, Realloc, Align.align, Fill, rest ); 228 251 } 229 230 T * alloc_internal$( void * Resize, T * Realloc, size_t Align, size_t Dim, S_fill(T), S_fill(T) Fill, TT rest ) { 231 return alloc_internal$( Resize, Realloc, Align, Dim, Fill, rest ); 252 T * alloc_internal$( size_t Dim, T_resize Resize, T_realloc Realloc, size_t Align, T_fill(T) dummy, T_fill(T) Fill, List rest ) { 253 return alloc_internal$( Dim, Resize, Realloc, Align, Fill, rest ); 232 254 } 233 234 T * alloc( TT all) {235 return alloc_internal$( ( void*)0p, (T*)0p, (_Alignof(T) > libAlign() ? _Alignof(T) : libAlign()), (size_t)1, (S_fill(T)){'0'}, all);255 // public interface 256 T * alloc( List rest ) { 257 return alloc_internal$( (size_t)1, (T_resize){0p}, (T_realloc){0p}, (_Alignof(T) > libAlign() ? _Alignof(T) : libAlign()), (T_fill(T)){'N'}, rest ); 236 258 } 237 238 T * alloc( size_t dim, TT all ) { 239 return alloc_internal$( (void*)0p, (T*)0p, (_Alignof(T) > libAlign() ? _Alignof(T) : libAlign()), dim, (S_fill(T)){'0'}, all ); 259 T * alloc( size_t Dim, List rest ) { 260 return alloc_internal$( Dim, (T_resize){0p}, (T_realloc){0p}, (_Alignof(T) > libAlign() ? _Alignof(T) : libAlign()), (T_fill(T)){'N'}, rest ); 240 261 } 241 } // distribution TT262 } // distribution List 242 263 } // distribution T 243 264 244 265 static inline forall( T & | sized(T) ) { 245 266 // CFA safe initialization/copy, i.e., implicit size specification, non-array types 246 T * memset( T * dest, char fill ) { 247 return (T *)memset( dest, fill, sizeof(T) ); 267 T * memset( T * dest, char fill ) { // all combinations of pointer/reference 268 return (T *)memset( dest, fill, sizeof(T) ); // C memset 248 269 } // memset 249 250 T * memcpy( T * dest, const T * src ) { 251 return (T *)memcpy( dest, src, sizeof(T) ); 270 T * memset( T & dest, char fill ) { 271 return (T *)memset( &dest, fill, sizeof(T) ); // C memset 272 } // memset 273 274 T * memcpy( T * dest, const T * src ) { // all combinations of pointer/reference 275 return (T *)memcpy( dest, src, sizeof(T) ); // C memcpy 276 } // memcpy 277 T * memcpy( T & dest, const T & src ) { 278 return (T *)memcpy( &dest, &src, sizeof(T) ); // C memcpy 279 } // memcpy 280 T * memcpy( T * dest, const T & src ) { 281 return (T *)memcpy( dest, &src, sizeof(T) ); // C memcpy 282 } // memcpy 283 T * memcpy( T & dest, const T * src ) { 284 return (T *)memcpy( &dest, src, sizeof(T) ); // C memcpy 252 285 } // memcpy 253 286 … … 263 296 264 297 // CFA deallocation for multiple objects 265 static inline forall( T & ) // FIX ME, problems with 0p in list298 static inline forall( T & ) 266 299 void free( T * ptr ) { 267 300 free( (void *)ptr ); // C free 268 301 } // free 269 static inline forall( T &, TT ... | { void free( TT); } )270 void free( T * ptr, TTrest ) {302 static inline forall( T &, List ... | { void free( List ); } ) 303 void free( T * ptr, List rest ) { 271 304 free( ptr ); 272 305 free( rest ); … … 274 307 275 308 // CFA allocation/deallocation and constructor/destructor, non-array types 276 static inline forall( T & | sized(T), TT ... | { void ?{}( T &, TT); } )277 T * new( TTp ) {309 static inline forall( T & | sized(T), Parms ... | { void ?{}( T &, Parms ); } ) 310 T * new( Parms p ) { 278 311 return &(*(T *)malloc()){ p }; // run constructor 279 312 } // new … … 287 320 free( ptr ); // always call free 288 321 } // delete 289 static inline forall( T &, TT ... | { void ^?{}( T & ); void delete( TT); } )290 void delete( T * ptr, TTrest ) {322 static inline forall( T &, List ... | { void ^?{}( T & ); void delete( List ); } ) 323 void delete( T * ptr, List rest ) { 291 324 delete( ptr ); 292 325 delete( rest ); … … 294 327 295 328 // CFA allocation/deallocation and constructor/destructor, array types 296 forall( T & | sized(T), TT ... | { void ?{}( T &, TT ); } ) T * anew( size_t dim, TTp );329 forall( T & | sized(T), Parms ... | { void ?{}( T &, Parms ); } ) T * anew( size_t dim, Parms p ); 297 330 forall( T & | sized(T) | { void ^?{}( T & ); } ) void adelete( T arr[] ); 298 forall( T & | sized(T) | { void ^?{}( T & ); }, TT ... | { void adelete( TT ); } ) void adelete( T arr[], TT rest ); 331 forall( T & | sized(T) | { void ^?{}( T & ); }, List ... | { void adelete( List ); } ) void adelete( T arr[], List rest ); 332 299 333 //--------------------------------------- 300 334
Note:
See TracChangeset
for help on using the changeset viewer.