Changeset 5bc81e9 for libcfa/src


Ignore:
Timestamp:
Apr 23, 2024, 2:28:45 PM (18 months ago)
Author:
Peter A. Buhr <pabuhr@…>
Branches:
master
Children:
566cc33, bab42de
Parents:
58e2ce34 (diff), 4a3eb1c (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:

Merge branch 'master' of plg.uwaterloo.ca:software/cfa/cfa-cc

Location:
libcfa/src
Files:
5 edited

Legend:

Unmodified
Added
Removed
  • libcfa/src/concurrency/kernel/fwd.hfa

    r58e2ce34 r5bc81e9  
    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

    r58e2ce34 r5bc81e9  
    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

    r58e2ce34 r5bc81e9  
    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

    r58e2ce34 r5bc81e9  
    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

    r58e2ce34 r5bc81e9  
    1010// Created On       : Thu Jan 28 17:12:35 2016
    1111// Last Modified By : Peter A. Buhr
    12 // Last Modified On : Fri Apr 19 09:47:55 2024
    13 // Update Count     : 826
     12// Last Modified On : Tue Apr 23 14:05:21 2024
     13// Update Count     : 963
    1414//
    1515
     
    121121
    122122/*
    123         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.
    124125        Or, just follow the instructions below for that.
    125126
     
    165166*/
    166167
    167 typedef struct S_align { inline size_t;  } T_align;
    168 typedef struct S_resize { inline void *;  }     T_resize;
    169 
    170 forall( T & ) {
    171         struct S_fill { char tag; char c; size_t size; T * at; char t[50]; };
    172         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 }; }
    173193}
    174194
    175 static inline T_align ?`align( size_t a ) { return (T_align){a}; }
    176 static inline T_resize ?`resize( void * a )     { return (T_resize){a}; }
    177 
    178195static inline forall( T & | sized(T) ) {
    179         S_fill(T) ?`fill( T t ) {
    180                 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' };
    181199                size_t size = sizeof(T);
    182200                if ( size > sizeof(ret.t) ) {
     
    186204                return ret;
    187205        }
    188         S_fill(T) ?`fill( zero_t ) = void; // FIX ME: remove this once ticket 214 is resolved
    189         S_fill(T) ?`fill( T * a ) { return (S_fill(T)){ 'T', '0', 0, a }; } // FIX ME: remove this once ticket 214 is resolved
    190         S_fill(T) ?`fill( char c ) { return (S_fill(T)){ 'c', c };      }
    191         S_fill(T) ?`fill( T a[], size_t nmemb ) { return (S_fill(T)){ 'a', '0', nmemb * sizeof(T), a }; }
    192 
    193         S_realloc(T) ?`realloc ( T * a ) { return (S_realloc(T)){a}; }
    194 
    195         T * alloc_internal$( void * Resize, T * Realloc, size_t Align, size_t Dim, S_fill(T) Fill ) {
    196                 T * ptr = NULL;
    197                 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);
    198213                size_t copy_end = 0;
    199214
    200                 if ( Resize ) {
    201                         ptr = (T*)(void *)resize( (void *)Resize, Align, Dim * size );
    202                 } else if ( Realloc ) {
    203                         if ( Fill.tag != '0' ) copy_end = min(malloc_size( Realloc ), Dim * size );
    204                         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 );
    205220                } else {
    206                         ptr = (T *)(void *) memalign( Align, Dim * size );
    207                 }
     221                        ptr = (T *)(void *)memalign( Align, Dim * tsize );
     222                } // if
    208223
    209224                if ( Fill.tag == 'c' ) {
    210                         memset( (char *)ptr + copy_end, (int)Fill.c, Dim * size - copy_end );
    211                 } else if ( Fill.tag == 't' ) {
    212                         for ( i; copy_end ~ Dim * size ~ size ) {
    213                                 #pragma GCC diagnostic push
    214                                 #pragma GCC diagnostic ignored "-Wmaybe-uninitialized"
    215                                 assert( size <= sizeof(Fill.t) );
    216                                 memcpy( (char *)ptr + i, &Fill.t, size );
    217                                 #pragma GCC diagnostic pop
    218                         }
     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
    219231                } else if ( Fill.tag == 'a' ) {
    220                         memcpy( (char *)ptr + copy_end, Fill.at, min(Dim * size - copy_end, Fill.size) );
    221                 } else if ( Fill.tag == 'T' ) {
    222                         memcpy( (char *)ptr + copy_end, Fill.at, Dim * size );
    223                 }
    224 
     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
    225236                return ptr;
    226237        } // alloc_internal$
    227238
    228         forall( List ... | { T * alloc_internal$( void *, T *, size_t, size_t, S_fill(T), List ); } ) {
    229                 T * alloc_internal$( void *, T *, size_t Align, size_t Dim, S_fill(T) Fill, T_resize Resize, List rest ) {
    230                 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 );
    231245                }
    232 
    233                 T * alloc_internal$( void *, T *, size_t Align, size_t Dim, S_fill(T) Fill, S_realloc(T) Realloc, List rest ) {
    234                 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 );
    235248                }
    236 
    237                 T * alloc_internal$( void * Resize, T * Realloc, size_t, size_t Dim, S_fill(T) Fill, T_align Align, List rest ) {
    238                 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 );
    239251                }
    240 
    241                 T * alloc_internal$( void * Resize, T * Realloc, size_t Align, size_t Dim, S_fill(T), S_fill(T) Fill, List rest ) {
    242                 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 );
    243254                }
    244 
    245             T * alloc( List all ) {
    246                 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 );
    247258            }
    248 
    249             T * alloc( size_t dim, List all ) {
    250                 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 );
    251261            }
    252262        } // distribution List
     
    255265static inline forall( T & | sized(T) ) {
    256266        // CFA safe initialization/copy, i.e., implicit size specification, non-array types
    257         T * memset( T * dest, char fill ) {
    258                 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
    259269        } // memset
    260 
    261         T * memcpy( T * dest, const T * src ) {
    262                 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
    263285        } // memcpy
    264286
Note: See TracChangeset for help on using the changeset viewer.