Changes in / [5715d43:762fbc1]


Ignore:
Files:
8 edited

Legend:

Unmodified
Added
Removed
  • driver/cfa.cc

    r5715d43 r762fbc1  
    1010// Created On       : Tue Aug 20 13:44:49 2002
    1111// Last Modified By : Peter A. Buhr
    12 // Last Modified On : Thu Aug 13 17:22:02 2020
    13 // Update Count     : 435
     12// Last Modified On : Fri Aug 14 07:22:03 2020
     13// Update Count     : 437
    1414//
    1515
    1616#include <iostream>
    17 #include <cstdio>      // perror
    18 #include <cstdlib>     // putenv, exit
    19 #include <climits>     // PATH_MAX
    20 #include <unistd.h>    // execvp
    21 #include <string>      // STL version
    22 #include <string.h>    // strcmp
    23 #include <algorithm>   // find
     17#include <cstdio>                                                                               // perror
     18#include <cstdlib>                                                                              // putenv, exit
     19#include <climits>                                                                              // PATH_MAX
     20#include <unistd.h>                                                                             // execvp
     21#include <string>                                                                               // STL version
     22#include <string.h>                                                                             // strcmp
     23#include <algorithm>                                                                    // find
    2424
    2525#include <sys/types.h>
     
    3636// #define __DEBUG_H__
    3737
     38#define xstr(s) str(s)
     39#define str(s) #s
     40
    3841// "N__=" suffix
    3942static string __CFA_FLAGPREFIX__( "__CFA_FLAG" );
    4043
    41 void Putenv( char * argv[], string arg ) {
     44static void Putenv( char * argv[], string arg ) {
    4245        // environment variables must have unique names
    4346        static int flags = 0;
     
    4952} // Putenv
    5053
    51 // check if string has prefix
    52 bool prefix( const string & arg, const string & pre ) {
     54static bool prefix( const string & arg, const string & pre ) { // check if string has prefix
    5355        return arg.substr( 0, pre.size() ) == pre;
    5456} // prefix
    5557
    56 inline bool ends_with(const string & str, const string & sfix) {
     58static inline bool ends_with(const string & str, const string & sfix) {
    5759        if (sfix.size() > str.size()) return false;
    5860        return std::equal(str.rbegin(), str.rbegin() + sfix.size(), sfix.rbegin(), sfix.rend());
     
    6062
    6163// check if string has suffix
    62 bool suffix( const string & arg ) {
     64static bool suffix( const string & arg ) {
    6365        enum { NumSuffixes = 3 };
    6466        static const string suffixes[NumSuffixes] = { "cfa", "hfa", "ifa" };
     
    7072} // suffix
    7173
    72 
    7374static inline bool dirExists( const string & path ) {   // check if directory exists
    7475    struct stat info;
     
    7980static inline string dir(const string & path) {
    8081        return path.substr(0, path.find_last_of('/'));
    81 }
     82} // dir
    8283
    8384// Different path modes
     
    118119}
    119120
    120 
    121 #define xstr(s) str(s)
    122 #define str(s) #s
    123121
    124122int main( int argc, char * argv[] ) {
  • libcfa/src/common.hfa

    r5715d43 r762fbc1  
    1010// Created On       : Wed Jul 11 17:54:36 2018
    1111// Last Modified By : Peter A. Buhr
    12 // Last Modified On : Thu Jul 12 08:02:18 2018
    13 // Update Count     : 5
     12// Last Modified On : Sat Aug 15 08:51:29 2020
     13// Update Count     : 14
    1414//
    1515
     
    6767
    6868static inline {
     69        char min( char t1, char t2 ) { return t1 < t2 ? t1 : t2; } // optimization
     70        intptr_t min( intptr_t t1, intptr_t t2 ) { return t1 < t2 ? t1 : t2; } // optimization
     71        uintptr_t min( uintptr_t t1, uintptr_t t2 ) { return t1 < t2 ? t1 : t2; } // optimization
    6972        forall( otype T | { int ?<?( T, T ); } )
    7073        T min( T t1, T t2 ) { return t1 < t2 ? t1 : t2; }
    7174
     75        char max( char t1, char t2 ) { return t1 > t2 ? t1 : t2; } // optimization
     76        intptr_t max( intptr_t t1, intptr_t t2 ) { return t1 > t2 ? t1 : t2; } // optimization
     77        uintptr_t max( uintptr_t t1, uintptr_t t2 ) { return t1 > t2 ? t1 : t2; } // optimization
    7278        forall( otype T | { int ?>?( T, T ); } )
    7379        T max( T t1, T t2 ) { return t1 > t2 ? t1 : t2; }
  • libcfa/src/heap.cfa

    r5715d43 r762fbc1  
    1010// Created On       : Tue Dec 19 21:58:35 2017
    1111// Last Modified By : Peter A. Buhr
    12 // Last Modified On : Sun Aug  9 12:23:20 2020
    13 // Update Count     : 894
     12// Last Modified On : Wed Aug 12 16:43:38 2020
     13// Update Count     : 902
    1414//
    1515
     
    650650                for ( HeapManager.Storage * p = freeLists[i].freeList; p != 0p; p = p->header.kind.real.next ) {
    651651                #else
    652                 for ( HeapManager.Storage * p = top( freeLists[i].freeList ); p != 0p; p = (p)`next->top ) {
     652                // for ( HeapManager.Storage * p = top( freeLists[i].freeList ); p != 0p; p = (p)`next->top ) {
     653                for ( HeapManager.Storage * p = top( freeLists[i].freeList ); p != 0p; /* p = getNext( p )->top */) {
     654                        typeof(p) temp = (( p )`next)->top;                     // FIX ME: direct assignent fails, initialization works
     655                        p = temp;
    653656                #endif // BUCKETLOCK
    654657                        total += size;
     
    11621165                choose( option ) {
    11631166                  case M_TOP_PAD:
    1164                         heapExpand = ceiling( value, pageSize ); return 1;
     1167                        heapExpand = ceiling2( value, pageSize ); return 1;
    11651168                  case M_MMAP_THRESHOLD:
    11661169                        if ( setMmapStart( value ) ) return 1;
  • libcfa/src/stdlib.hfa

    r5715d43 r762fbc1  
    1010// Created On       : Thu Jan 28 17:12:35 2016
    1111// Last Modified By : Peter A. Buhr
    12 // Last Modified On : Tue Aug 11 21:11:46 2020
    13 // Update Count     : 495
     12// Last Modified On : Fri Aug 14 23:38:50 2020
     13// Update Count     : 504
    1414//
    1515
     
    3939//---------------------------------------
    4040
     41#include "common.hfa"
     42
     43//---------------------------------------
     44
    4145// Macro because of returns
    4246#define $VAR_ALLOC( allocation, alignment ) \
     
    152156        } // alloc_set
    153157
    154         T * alloc_set( size_t dim, const T fill[] ) {
    155                 return (T *)memcpy( (T *)alloc( dim ), fill, dim * sizeof(T) ); // initialize with fill value
     158        T * alloc_set( size_t dimNew, const T fill[], size_t dimOld ) {
     159                return (T *)memcpy( (T *)alloc( dimNew ), fill, min( dimNew, dimOld ) * sizeof(T) ); // initialize with fill value
    156160        } // alloc_set
    157161
     
    220224        } // alloc_align_set
    221225
    222         T * alloc_align_set( size_t align, size_t dim, const T fill[] ) {
    223                 return (T *)memcpy( (T *)alloc_align( align, dim ), fill, dim * sizeof(T) );
     226        T * alloc_align_set( size_t align, size_t dimNew, const T fill[], size_t dimOld ) {
     227                return (T *)memcpy( (T *)alloc_align( align, dimNew ), fill, min( dimNew, dimOld ) * sizeof(T) );
    224228        } // alloc_align_set
    225229
     
    374378//---------------------------------------
    375379
    376 #include "common.hfa"
    377 
    378 //---------------------------------------
    379 
    380380extern bool threading_enabled(void) OPTIONAL_THREAD;
    381381
  • tests/.expect/minmax.txt

    r5715d43 r762fbc1  
    11char                    z a     min a
    2 signed int              4 3     min 3
     2signed int              4 -3    min -3
    33unsigned int            4 3     min 3
    4 signed long int         4 3     min 3
     4signed long int         4 -3    min -3
    55unsigned long int       4 3     min 3
    6 signed long long int    4 3     min 3
     6signed long long int    4 -3    min -3
    77unsigned long long int  4 3     min 3
    88float                   4. 3.1  min 3.1
     
    1111
    1212char                    z a     max z
    13 signed int              4 3     max 4
     13signed int              4 -3    max 4
    1414unsigned int            4 3     max 4
    15 signed long int         4 3     max 4
     15signed long int         4 -3    max 4
    1616unsigned long int       4 3     max 4
    17 signed long long int    4 3     max 4
     17signed long long int    4 -3    max 4
    1818unsigned long long int  4 3     max 4
    1919float                   4. 3.1  max 4.
  • tests/alloc.cfa

    r5715d43 r762fbc1  
    1010// Created On       : Wed Feb  3 07:56:22 2016
    1111// Last Modified By : Peter A. Buhr
    12 // Last Modified On : Mon Apr  6 21:08:23 2020
    13 // Update Count     : 428
     12// Last Modified On : Fri Aug 14 16:59:59 2020
     13// Update Count     : 430
    1414//
    1515
     
    9090        // do not free
    9191
    92         ip1 = alloc_set( 2 * dim, ip );                                         // CFA array alloc, fill
     92        ip1 = alloc_set( 2 * dim, ip, 2 * dim );                                // CFA array alloc, fill
    9393        printf( "CFA array alloc, fill from array\n" );
    9494        for ( i; 2 * dim ) { printf( "%#x %#x, ", ip[i], ip1[i] ); }
     
    288288        // do not free
    289289
    290         stp1 = alloc_align_set( Alignment, dim, stp );          // CFA array memalign, fill
     290        stp1 = alloc_align_set( Alignment, dim, stp, dim );     // CFA array memalign, fill
    291291        assert( (uintptr_t)stp % Alignment == 0 );
    292292        printf( "CFA array alloc_align, fill array\n" );
  • tests/heap.cfa

    r5715d43 r762fbc1  
    1010// Created On       : Tue Nov  6 17:54:56 2018
    1111// Last Modified By : Peter A. Buhr
    12 // Last Modified On : Tue Aug  4 06:36:17 2020
    13 // Update Count     : 56
     12// Last Modified On : Sun Aug  9 08:05:16 2020
     13// Update Count     : 57
    1414//
    1515
     
    232232                size_t s = i + default_mmap_start();                    // cross over point
    233233                char * area = (char *)calloc( 1, s );
    234 //              if ( area == 0p ) abort( "calloc/realloc/free out of memory" );
    235234                if ( area[0] != '\0' || area[s - 1] != '\0' ||
    236235                         area[malloc_size( area ) - 1] != '\0' ||
    237                          ! malloc_zero_fill( area ) ) //abort( "calloc/realloc/free corrupt storage3" );
    238                         printf( "C %zd %d %d %d %d\n", s, area[0] != '\0', area[s - 1] != '\0', area[malloc_size( area ) - 1] != '\0', ! malloc_zero_fill( area ) );
     236                         ! malloc_zero_fill( area ) ) abort( "calloc/realloc/free corrupt storage3" );
    239237
    240238                // Do not start this loop index at 0 because realloc of 0 bytes frees the storage.
    241239                for ( r; i ~ 256 * 1024 ~ 26 ) {                                // start at initial memory request
    242240                        area = (char *)realloc( area, r );                      // attempt to reuse storage
    243 //                      if ( area == 0p ) abort( "calloc/realloc/free out of memory" );
    244241                        if ( area[0] != '\0' || area[r - 1] != '\0' ||
    245242                                 area[malloc_size( area ) - 1] != '\0' ||
     
    255252                // initial N byte allocation
    256253                char * area = (char *)memalign( a, amount );    // aligned N-byte allocation
    257 //              if ( area == 0p ) abort( "memalign/realloc/free out of memory" ); // no storage ?
    258254                //sout | alignments[a] | area;
    259255                if ( (size_t)area % a != 0 || malloc_alignment( area ) != a ) { // check for initial alignment
  • tests/minmax.cfa

    r5715d43 r762fbc1  
    1010// Created On       : Wed May 27 17:56:53 2015
    1111// Last Modified By : Peter A. Buhr
    12 // Last Modified On : Tue Dec  4 21:45:31 2018
    13 // Update Count     : 52
     12// Last Modified On : Sat Aug 15 08:28:01 2020
     13// Update Count     : 54
    1414//
    1515
     
    2323
    2424        sout | "char\t\t\t"                                     | 'z' | ' ' | 'a' | "\tmin " | min( 'z', 'a' );
    25         sout | "signed int\t\t"                         | 4 | 3 | "\tmin" | min( 4, 3 );
     25        sout | "signed int\t\t"                         | 4 | -3 | "\tmin" | min( 4, -3 );
    2626        sout | "unsigned int\t\t"                       | 4u | 3u | "\tmin" | min( 4u, 3u );
    27         sout | "signed long int\t\t"            | 4l | 3l | "\tmin" | min( 4l, 3l );
     27        sout | "signed long int\t\t"            | 4l | -3l | "\tmin" | min( 4l, -3l );
    2828        sout | "unsigned long int\t"            | 4ul | 3ul | "\tmin" | min( 4ul, 3ul );
    29         sout | "signed long long int\t"         | 4ll | 3ll | "\tmin" | min( 4ll, 3ll );
     29        sout | "signed long long int\t"         | 4ll | -3ll | "\tmin" | min( 4ll, -3ll );
    3030        sout | "unsigned long long int\t"       | 4ull | 3ull | "\tmin" | min( 4ull, 3ull );
    3131        sout | "float\t\t\t"                            | 4.0f | 3.1f | "\tmin" | min( 4.0f, 3.1f );
     
    3636
    3737        sout | "char\t\t\t"                                     | 'z' | ' ' | 'a' | "\tmax " | max( 'z', 'a' );
    38         sout | "signed int\t\t"                         | 4 | 3 | "\tmax" | max( 4, 3 );
     38        sout | "signed int\t\t"                         | 4 | -3 | "\tmax" | max( 4, -3 );
    3939        sout | "unsigned int\t\t"                       | 4u | 3u | "\tmax" | max( 4u, 3u );
    40         sout | "signed long int\t\t"            | 4l | 3l | "\tmax" | max( 4l, 3l );
     40        sout | "signed long int\t\t"            | 4l | -3l | "\tmax" | max( 4l, -3l );
    4141        sout | "unsigned long int\t"            | 4ul | 3ul | "\tmax" | max( 4ul, 3ul );
    42         sout | "signed long long int\t"         | 4ll | 3ll | "\tmax" | max( 4ll, 3ll );
     42        sout | "signed long long int\t"         | 4ll | -3ll | "\tmax" | max( 4ll, -3ll );
    4343        sout | "unsigned long long int\t"       | 4ull | 3ull | "\tmax" | max( 4ull, 3ull );
    4444        sout | "float\t\t\t"                            | 4.0f | 3.1f | "\tmax" | max( 4.0f, 3.1f );
Note: See TracChangeset for help on using the changeset viewer.