Changeset 289a21c


Ignore:
Timestamp:
Jul 20, 2020, 10:40:25 AM (4 years ago)
Author:
Thierry Delisle <tdelisle@…>
Branches:
ADT, arm-eh, ast-experimental, enum, forall-pointer-decay, jacob/cs343-translation, master, new-ast, new-ast-unique-expr, pthread-emulation, qualifiedEnum
Children:
03ed863
Parents:
e95a117 (diff), e93cbfa (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

Files:
4 edited

Legend:

Unmodified
Added
Removed
  • libcfa/src/heap.cfa

    re95a117 r289a21c  
    1010// Created On       : Tue Dec 19 21:58:35 2017
    1111// Last Modified By : Peter A. Buhr
    12 // Last Modified On : Sat Jun 13 22:42:15 2020
    13 // Update Count     : 805
     12// Last Modified On : Sun Jul 19 17:37:21 2020
     13// Update Count     : 806
    1414//
    1515
     
    10981098        // Returns original total allocation size (not bucket size) => array size is dimension * sizeif(T).
    10991099        size_t malloc_size( void * addr ) {
    1100           if ( unlikely( addr == 0p ) ) return false;           // null allocation is not zero fill
     1100          if ( unlikely( addr == 0p ) ) return 0;                       // null allocation has zero size
    11011101                HeapManager.Storage.Header * header = headerAddr( addr );
    11021102                if ( (header->kind.fake.alignment & 1) == 1 ) { // fake header ?
     
    11081108        // Set allocation size and return previous size.
    11091109        size_t $malloc_size_set( void * addr, size_t size ) {
    1110           if ( unlikely( addr == 0p ) ) return false;           // null allocation is not zero fill
     1110          if ( unlikely( addr == 0p ) ) return 0;                       // null allocation has 0 size
    11111111                HeapManager.Storage.Header * header = headerAddr( addr );
    11121112                if ( (header->kind.fake.alignment & 1) == 1 ) { // fake header ?
  • libcfa/src/stdlib.cfa

    re95a117 r289a21c  
    99// Author           : Peter A. Buhr
    1010// Created On       : Thu Jan 28 17:10:29 2016
    11 // Last Modified By : Andrew Beach
    12 // Last Modified On : Tue Jun  2 16:46:00 2020
    13 // Update Count     : 500
     11// Last Modified By : Peter A. Buhr
     12// Last Modified On : Sun Jul 19 15:05:28 2020
     13// Update Count     : 501
    1414//
    1515
     
    2525
    2626//---------------------------------------
    27 
    28 forall( dtype T | sized(T) ) {
    29         T * alloc_set( T ptr[], size_t dim, char fill ) {       // realloc array with fill
    30                 size_t olen = malloc_usable_size( ptr );                // current allocation
    31                 void * nptr = (void *)realloc( (void *)ptr, dim * sizeof(T) ); // C realloc
    32                 size_t nlen = malloc_usable_size( nptr );               // new allocation
    33                 if ( nlen > olen ) {                                                    // larger ?
    34                         memset( (char *)nptr + olen, (int)fill, nlen - olen ); // initialize added storage
    35                 } // if
    36                 return (T *)nptr;
    37         } // alloc_set
    38 
    39         T * alloc_set( T ptr[], size_t dim, T fill ) {          // realloc array with fill
    40                 size_t olen = malloc_usable_size( ptr );                // current allocation
    41                 void * nptr = (void *)realloc( (void *)ptr, dim * sizeof(T) ); // C realloc
    42                 size_t nlen = malloc_usable_size( nptr );               // new allocation
    43                 if ( nlen > olen ) {                                                    // larger ?
    44                         for ( i; malloc_size( ptr ) / sizeof(T) ~ dim ) {
    45                                 memcpy( &ptr[i], &fill, sizeof(T) );    // initialize with fill value
    46                         } // for
    47                 } // if
    48                 return (T *)nptr;
    49         } // alloc_align_set
    50 
    51         T * alloc_align_set( T ptr[], size_t align, char fill ) { // aligned realloc with fill
    52                 size_t olen = malloc_usable_size( ptr );                // current allocation
    53                 void * nptr = (void *)realloc( (void *)ptr, align, sizeof(T) ); // CFA realloc
    54                 // char * nptr = alloc_align( ptr, align );
    55                 size_t nlen = malloc_usable_size( nptr );               // new allocation
    56                 if ( nlen > olen ) {                                                    // larger ?
    57                         memset( (char *)nptr + olen, (int)fill, nlen - olen ); // initialize added storage
    58                 } // if
    59                 return (T *)nptr;
    60         } // alloc_align_set
    61 
    62         T * alloc_align_set( T ptr[], size_t align, size_t dim, T fill ) { // aligned realloc with fill
    63                 size_t olen = malloc_usable_size( ptr );                // current allocation
    64                 void * nptr = (void *)realloc( (void *)ptr, align, sizeof(T) ); // CFA realloc
    65                 // char * nptr = alloc_align( ptr, align );
    66                 size_t nlen = malloc_usable_size( nptr );               // new allocation
    67                 if ( nlen > olen ) {                                                    // larger ?
    68                         for ( i; dim ) { memcpy( &ptr[i], &fill, sizeof(T) ); } // initialize with fill value
    69                 } // if
    70                 return (T *)nptr;
    71         } // alloc_align_set
    72 } // distribution
    7327
    7428// allocation/deallocation and constructor/destructor, non-array types
  • libcfa/src/stdlib.hfa

    re95a117 r289a21c  
    99// Author           : Peter A. Buhr
    1010// Created On       : Thu Jan 28 17:12:35 2016
    11 // Last Modified By : Andrew Beach
    12 // Last Modified On : Tue Jun  2 16:47:00 2020
    13 // Update Count     : 451
     11// Last Modified By : Peter A. Buhr
     12// Last Modified On : Sun Jul 19 18:29:34 2020
     13// Update Count     : 463
    1414//
    1515
     
    5757        } // calloc
    5858
    59         T * resize( T * ptr, size_t size ) {                            // CFA realloc, eliminate return-type cast
    60                 return (T *)(void *)resize( (void *)ptr, size ); // C realloc
     59        T * resize( T * ptr, size_t size ) {                            // CFA resize, eliminate return-type cast
     60                if ( unlikely( size == 0 ) || unlikely( ptr == 0p ) ) { // special cases
     61                        if ( unlikely( size == 0 ) ) free( ptr );
     62                        if ( _Alignof(T) <= libAlign() ) return (T *)(void *)malloc( (size_t)sizeof(T) ); // C malloc
     63                        else return (T *)memalign( _Alignof(T), sizeof(T) );
     64                } // if
     65                return (T *)(void *)resize( (void *)ptr, size ); // CFA resize
    6166        } // resize
    6267
    6368        T * realloc( T * ptr, size_t size ) {                           // CFA realloc, eliminate return-type cast
     69                if ( unlikely( size == 0 ) || unlikely( ptr == 0p ) ) { // special cases
     70                        if ( unlikely( size == 0 ) ) free( ptr );
     71                        if ( _Alignof(T) <= libAlign() ) return (T *)(void *)malloc( (size_t)sizeof(T) ); // C malloc
     72                        else return (T *)memalign( _Alignof(T), sizeof(T) );
     73                } // if
    6474                return (T *)(void *)realloc( (void *)ptr, size ); // C realloc
    6575        } // realloc
     
    118128
    119129        T * alloc( T ptr[], size_t dim, bool copy = true ) {
    120                 if ( copy ) {                                                                   // realloc
    121                         return (T *)(void *)realloc( (void *)ptr, dim * sizeof(T) ); // C realloc
     130                if ( copy ) {
     131                        return realloc( ptr, dim * sizeof(T) );         // CFA realloc
    122132                } else {
    123                         return resize( ptr, dim * sizeof(T) );          // resize
     133                        return resize( ptr, dim * sizeof(T) );          // CFA resize
    124134                } // if
    125135        } // alloc
     
    146156                return (T *)memcpy( (T *)alloc( dim ), fill, dim * sizeof(T) ); // initialize with fill value
    147157        } // alloc
    148 } // distribution
    149 
    150 forall( dtype T | sized(T) ) {
    151         T * alloc_set( T ptr[], size_t dim, char fill );        // realloc array with fill
    152         T * alloc_set( T ptr[], size_t dim, T fill );           // realloc array with fill
     158
     159        T * alloc_set( T ptr[], size_t dim, char fill ) {       // realloc array with fill
     160                size_t osize = malloc_size( ptr );                              // current allocation
     161                T * nptr = realloc( ptr, dim * sizeof(T) );             // CFA realloc
     162                size_t nsize = malloc_size( nptr );                             // new allocation
     163                if ( nsize > osize ) {                                                  // larger ?
     164                        memset( (char *)nptr + osize, (int)fill, nsize - osize ); // initialize added storage
     165                } // if
     166                return (T *)nptr;
     167        } // alloc_set
     168
     169        T * alloc_set( T ptr[], size_t dim, T & fill ) {        // realloc array with fill
     170                size_t odim = malloc_size( ptr ) / sizeof(T);   // current allocation
     171                T * nptr = realloc( ptr, dim * sizeof(T) );             // CFA realloc
     172                size_t ndim = malloc_size( nptr ) / sizeof(T);  // new allocation
     173                if ( ndim > odim ) {                                                    // larger ?
     174                        for ( i; odim ~ ndim ) {
     175                                memcpy( &nptr[i], &fill, sizeof(T) );   // initialize with fill value
     176                        } // for
     177                } // if
     178                return (T *)nptr;
     179        } // alloc_align_set
    153180} // distribution
    154181
     
    196223                return (T *)memcpy( (T *)alloc_align( align, dim ), fill, dim * sizeof(T) );
    197224        } // alloc_align
    198 } // distribution
    199 
    200 forall( dtype T | sized(T) ) {
    201         T * alloc_align_set( T ptr[], size_t align, char fill ); // aligned realloc with fill
    202         T * alloc_align_set( T ptr[], size_t align, T fill ); // aligned realloc with fill
    203         T * alloc_align_set( T ptr[], size_t align, size_t dim, char fill ); // aligned realloc array with fill
    204         T * alloc_align_set( T ptr[], size_t align, size_t dim, T fill ); // aligned realloc array with fill
     225
     226        T * alloc_align_set( T ptr[], size_t align, size_t dim, char fill ) {
     227                size_t osize = malloc_size( ptr );                              // current allocation
     228                T * nptr = realloc( ptr, align, dim * sizeof(T) ); // CFA realloc
     229                size_t nsize = malloc_size( nptr );                             // new allocation
     230                if ( nsize > osize ) {                                                  // larger ?
     231                        memset( (char *)nptr + osize, (int)fill, nsize - osize ); // initialize added storage
     232                } // if
     233                return (T *)nptr;
     234        } // alloc_align_set
     235
     236        T * alloc_align_set( T ptr[], size_t align, size_t dim, T & fill ) {
     237                size_t odim = malloc_size( ptr ) / sizeof(T);   // current allocation
     238                T * nptr = realloc( ptr, align, dim * sizeof(T) ); // CFA realloc
     239                size_t ndim = malloc_size( nptr );                              // new allocation
     240                if ( ndim > odim ) {                                                    // larger ?
     241                        for ( i; odim ~ ndim ) {
     242                                memcpy( &nptr[i], &fill, sizeof(T) );   // initialize with fill value
     243                        } // for
     244                } // if
     245                return (T *)nptr;
     246        } // alloc_align_set
    205247} // distribution
    206248
  • tests/.expect/alloc.txt

    re95a117 r289a21c  
    34340xdeadbeef 0xdeadbeef 0xdeadbeef 0xdeadbeef 0xdeadbeef 0xdeadbeef 0xdeadbeef 0xdeadbeef 0xdeadbeef 0xdeadbeef
    3535CFA realloc array alloc, fill
    36 0xdeadbeef 0xdeadbeef 0xdeadbeef 0xdeadbeef 0xdeadbeef 0xdeadbeef 0xdeadbeef 0xdeadbeef 0xdeadbeef 0xdeadbeef 0x1010101 0x1010101 0x1010101 0x1010101 0x1010101 0x1010101 0xdededede 0xdededede 0xdededede 0xdededede 0xdededede 0xdededede 0xdededede 0xdededede 0xdededede 0xdededede 0xdededede 0xdededede 0xdededede 0xdededede
     360xdeadbeef 0xdeadbeef 0xdeadbeef 0xdeadbeef 0xdeadbeef 0xdeadbeef 0xdeadbeef 0xdeadbeef 0xdeadbeef 0xdeadbeef 0xdededede 0xdededede 0xdededede 0xdededede 0xdededede 0xdededede 0xdededede 0xdededede 0xdededede 0xdededede 0xdededede 0xdededede 0xdededede 0xdededede 0xdededede 0xdededede 0xdededede 0xdededede 0xdededede 0xdededede
    3737
    3838C   memalign 42 42.5
Note: See TracChangeset for help on using the changeset viewer.