Changeset 7042c60 for libcfa/src


Ignore:
Timestamp:
Apr 25, 2024, 3:48:17 PM (21 months ago)
Author:
JiadaL <j82liang@…>
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.
Message:

resolve conflict

Location:
libcfa/src
Files:
6 edited

Legend:

Unmodified
Added
Removed
  • libcfa/src/concurrency/actor.hfa

    rcf191ac r7042c60  
    299299
    300300        if ( seperate_clus ) {
    301                 cluster = alloc();
     301                this.cluster = alloc();
    302302                (*cluster){};
    303303        } else cluster = active_cluster();
     
    360360        adelete( worker_req_queues );
    361361        adelete( processors );
    362         if ( seperate_clus ) delete( cluster );
     362        if ( seperate_clus ) delete( this.cluster );
    363363
    364364        #ifdef ACTOR_STATS // print formatted stats
  • libcfa/src/concurrency/kernel/fwd.hfa

    rcf191ac r7042c60  
    374374                                // since if that is the case, the oneshot was fulfilled (unparking this thread)
    375375                                // 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
    377377                                /* paranoid */ verifyf( was == future_FULFILLED, "Expected this.ptr to be 1p, was %p\n", was );
    378378
  • libcfa/src/device/cpu.cfa

    rcf191ac r7042c60  
    239239// Returns a 2D array of instances of size [cpu count][cache levels]
    240240// 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 {
     241raw_cache_instance ** build_raw_cache_table(unsigned cpus_c, idx_range_t cpus, unsigned idxs, unsigned cache_levels) {
    243242        raw_cache_instance ** raw = alloc(cpus_c, '\0'`fill);
    244243
  • libcfa/src/iostream.hfa

    rcf191ac r7042c60  
    1010// Created On       : Wed May 27 17:56:53 2015
    1111// Last Modified By : Peter A. Buhr
    12 // Last Modified On : Tue Feb  6 18:35:54 2024
    13 // Update Count     : 743
     12// Last Modified On : Sun Apr 21 07:32:19 2024
     13// Update Count     : 744
    1414//
    1515
     
    160160
    161161// tuples
    162 forall( ostype &, T, Params... | writeable( T, ostype ) | { ostype & ?|?( ostype &, Params ); } ) {
    163         ostype & ?|?( ostype & os, T arg, Params rest );
    164         void ?|?( ostype & os, T arg, Params rest );
     162forall( 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 );
    165165} // distribution
    166166
  • libcfa/src/stdlib.cfa

    rcf191ac r7042c60  
    1010// Created On       : Thu Jan 28 17:10:29 2016
    1111// Last Modified By : Peter A. Buhr
    12 // Last Modified On : Sun Mar 17 08:25:32 2024
    13 // Update Count     : 699
     12// Last Modified On : Sun Apr 21 16:17:22 2024
     13// Update Count     : 700
    1414//
    1515
     
    3131// Cforall allocation/deallocation and constructor/destructor, array types
    3232
    33 forall( T & | sized(T), TT... | { void ?{}( T &, TT ); } )
    34 T * anew( size_t dim, TT p ) {
     33forall( T & | sized(T), Parms ... | { void ?{}( T &, Parms ); } )
     34T * anew( size_t dim, Parms p ) {
    3535        T * arr = alloc( dim );
    3636        for ( i; dim ) {
     
    5151} // adelete
    5252
    53 forall( T & | sized(T) | { void ^?{}( T & ); }, TT... | { void adelete( TT ); } )
    54 void adelete( T arr[], TT rest ) {
     53forall( T & | sized(T) | { void ^?{}( T & ); }, List ... | { void adelete( List ); } )
     54void adelete( T arr[], List rest ) {
    5555        if ( arr ) {                                                                            // ignore null
    5656                size_t dim = malloc_size( arr ) / sizeof( T );
  • libcfa/src/stdlib.hfa

    rcf191ac r7042c60  
    1010// Created On       : Thu Jan 28 17:12:35 2016
    1111// Last Modified By : Peter A. Buhr
    12 // Last Modified On : Mon Apr 15 22:11:51 2024
    13 // Update Count     : 817
     12// Last Modified On : Tue Apr 23 14:05:21 2024
     13// Update Count     : 963
    1414//
    1515
     
    4747
    4848static 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
    5050
    5151        T * malloc( void ) {
     
    6464        } // calloc
    6565
    66         T * resize( T * ptr, size_t size ) {                            // CFA resize
    67                 if ( _Alignof(T) <= libAlign() ) return (T *)resize( (void *)ptr, size ); // CFA resize
     66        T * resize( T * ptr, size_t size ) {
     67                if ( _Alignof(T) <= libAlign() ) return (T *)resize( (void *)ptr, size ); // C resize
    6868                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
    6973        } // resize
    7074
     
    7478        } // realloc
    7579
     80        T * realloc( T * ptr, size_t alignment, size_t size ) {
     81                return (T *)realloc( (void *)ptr, alignment, size ); // CFA realloc
     82        } // realloc
     83
    7684        T * reallocarray( T * ptr, size_t dim ) {                       // CFA reallocarray
    7785                if ( _Alignof(T) <= libAlign() ) return (T *)reallocarray( (void *)ptr, dim, sizeof(T) ); // C reallocarray
     
    7987        } // realloc
    8088
     89        T * reallocarray( T * ptr, size_t alignment, size_t dim ) {
     90                return (T *)reallocarray( (void *)ptr, alignment, dim ); // CFA reallocarray
     91        } // realloc
     92
    8193        T * memalign( size_t align ) {
    8294                return (T *)memalign( align, sizeof(T) );               // C memalign
     
    8799        } // amemalign
    88100
    89         T * cmemalign( size_t align, size_t dim  ) {
     101        T * cmemalign( size_t align, size_t dim ) {
    90102                return (T *)cmemalign( align, dim, sizeof(T) ); // CFA cmemalign
    91103        } // cmemalign
     
    109121
    110122/*
    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.
    112125        Or, just follow the instructions below for that.
    113126
     
    153166*/
    154167
    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
     172struct T_align { size_t align; };
     173struct T_resize { void * addr; };
     174struct T_realloc { void * addr; };
     175forall( 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
     189static 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 }; }
    161193}
    162194
    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);
    167195static 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' };
    170199                size_t size = sizeof(T);
    171200                if ( size > sizeof(ret.t) ) {
     
    175204                return ret;
    176205        }
    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);
    187213                size_t copy_end = 0;
    188214
    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 );
    194220                } else {
    195                         ptr = (T *)(void *) memalign( Align, Dim * size );
    196                 }
     221                        ptr = (T *)(void *)memalign( Align, Dim * tsize );
     222                } // if
    197223
    198224                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
    208231                } 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
    214236                return ptr;
    215237        } // alloc_internal$
    216238
    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 );
    220245                }
    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 );
    224248                }
    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 );
    228251                }
    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 );
    232254                }
    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 );
    236258            }
    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 );
    240261            }
    241         } // distribution TT
     262        } // distribution List
    242263} // distribution T
    243264
    244265static inline forall( T & | sized(T) ) {
    245266        // 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
    248269        } // 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
    252285        } // memcpy
    253286
     
    263296
    264297// CFA deallocation for multiple objects
    265 static inline forall( T & )                                                     // FIX ME, problems with 0p in list
     298static inline forall( T & )
    266299void free( T * ptr ) {
    267300        free( (void *)ptr );                                                            // C free
    268301} // free
    269 static inline forall( T &, TT ... | { void free( TT ); } )
    270 void free( T * ptr, TT rest ) {
     302static inline forall( T &, List ... | { void free( List ); } )
     303void free( T * ptr, List rest ) {
    271304        free( ptr );
    272305        free( rest );
     
    274307
    275308// CFA allocation/deallocation and constructor/destructor, non-array types
    276 static inline forall( T & | sized(T), TT ... | { void ?{}( T &, TT ); } )
    277 T * new( TT p ) {
     309static inline forall( T & | sized(T), Parms ... | { void ?{}( T &, Parms ); } )
     310T * new( Parms p ) {
    278311        return &(*(T *)malloc()){ p };                                          // run constructor
    279312} // new
     
    287320        free( ptr );                                                                            // always call free
    288321} // delete
    289 static inline forall( T &, TT ... | { void ^?{}( T & ); void delete( TT ); } )
    290 void delete( T * ptr, TT rest ) {
     322static inline forall( T &, List ... | { void ^?{}( T & ); void delete( List ); } )
     323void delete( T * ptr, List rest ) {
    291324        delete( ptr );
    292325        delete( rest );
     
    294327
    295328// CFA allocation/deallocation and constructor/destructor, array types
    296 forall( T & | sized(T), TT ... | { void ?{}( T &, TT ); } ) T * anew( size_t dim, TT p );
     329forall( T & | sized(T), Parms ... | { void ?{}( T &, Parms ); } ) T * anew( size_t dim, Parms p );
    297330forall( 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 );
     331forall( T & | sized(T) | { void ^?{}( T & ); }, List ... | { void adelete( List ); } ) void adelete( T arr[], List rest );
     332
    299333//---------------------------------------
    300334
Note: See TracChangeset for help on using the changeset viewer.