Changeset 856dff8 for libcfa/src


Ignore:
Timestamp:
Aug 28, 2020, 11:15:36 AM (5 years ago)
Author:
Thierry Delisle <tdelisle@…>
Branches:
ADT, arm-eh, ast-experimental, enum, forall-pointer-decay, jacob/cs343-translation, master, new-ast-unique-expr, pthread-emulation, qualifiedEnum
Children:
3b2f41e
Parents:
b7fe2e6 (diff), 8e2cb4a (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:
3 added
13 edited
1 moved

Legend:

Unmodified
Added
Removed
  • libcfa/src/Makefile.am

    rb7fe2e6 r856dff8  
    9292inst_thread_headers_src = \
    9393        concurrency/coroutine.hfa \
     94        concurrency/exception.hfa \
    9495        concurrency/kernel.hfa \
    9596        concurrency/monitor.hfa \
  • libcfa/src/bitmanip.hfa

    rb7fe2e6 r856dff8  
    1111// Created On       : Sat Mar 14 18:12:27 2020
    1212// Last Modified By : Peter A. Buhr
    13 // Last Modified On : Mon Aug 10 09:21:02 2020
    14 // Update Count     : 139
     13// Last Modified On : Sun Aug 23 21:39:28 2020
     14// Update Count     : 140
    1515//
    1616
     
    103103        // T floor2( T n, T align ) { verify( is_pow2( align ) ); return n & -align; }
    104104
    105         signed char floor( signed char n, signed char align ) { return n / align * align; }
    106         unsigned char floor( unsigned char n, unsigned char align ) { return n / align * align; }
    107         short int floor( short int n, short int align ) { return n / align * align; }
    108         unsigned short int floor( unsigned short int n, unsigned short int align ) { return n / align * align; }
    109         int floor( int n, int align ) { return n / align * align; }
    110         unsigned int floor( unsigned int n, unsigned int align ) { return n / align * align; }
    111         long int floor( long int n, long int align ) { return n / align * align; }
    112         unsigned long int floor( unsigned long int n, unsigned long int align ) { return n / align * align; }
    113         long long int floor( long long int n, long long int align ) { return n / align * align; }
    114         unsigned long long int floor( unsigned long long int n, unsigned long long int align ) { return n / align * align; }
    115 
    116         // forall( otype T | { T ?/?( T, T ); T ?*?( T, T ); } )
    117         // T floor( T n, T align ) { return n / align * align; }
    118 
    119105        // Returns n aligned at the ceiling of align, negate, round down, negate is the same as round up.
    120106        signed char ceiling2( signed char n, signed char align ) { verify( is_pow2( align ) ); return -floor2( -n, align ); }
     
    131117        // forall( otype T | { T floor2( T, T ); T -?( T ); } )
    132118        // T ceiling2( T n, T align ) { verify( is_pow2( align ) ); return -floor2( -n, align ); }
    133 
    134         signed char ceiling_div( signed char n, char align ) { return (n + (align - 1)) / align; }
    135         unsigned char ceiling_div( unsigned char n, unsigned char align ) { return (n + (align - 1)) / align; }
    136         short int ceiling_div( short int n, short int align ) { return (n + (align - 1)) / align; }
    137         unsigned short int ceiling_div( unsigned short int n, unsigned short int align ) { return (n + (align - 1)) / align; }
    138         int ceiling_div( int n, int align ) { return (n + (align - 1)) / align; }
    139         unsigned int ceiling_div( unsigned int n, unsigned int align ) { return (n + (align - 1)) / align; }
    140         long int ceiling_div( long int n, long int align ) { return (n + (align - 1)) / align; }
    141         unsigned long int ceiling_div( unsigned long int n, unsigned long int align ) { return (n + (align - 1)) / align; }
    142         long long int ceiling_div( long long int n, long long int align ) { return (n + (align - 1)) / align; }
    143         unsigned long long int ceiling_div( unsigned long long int n, unsigned long long int align ) { return (n + (align - 1)) / align; }
    144 
    145         // forall( otype T | { T ?+?( T, T ); T ?-?( T, T ); T ?%?( T, T ); } )
    146         // T ceiling_div( T n, T align ) { verify( is_pow2( align ) );return (n + (align - 1)) / align; }
    147        
    148         // gcc notices the div/mod pair and saves both so only one div.
    149         signed char ceiling( signed char n, signed char align ) { return floor( n + (n % align != 0 ? align - 1 : 0), align ); }
    150         unsigned char ceiling( unsigned char n, unsigned char align ) { return floor( n + (n % align != 0 ? align - 1 : 0), align ); }
    151         short int ceiling( short int n, short int align ) { return floor( n + (n % align != 0 ? align - 1 : 0), align ); }
    152         unsigned short int ceiling( unsigned short int n, unsigned short int align ) { return floor( n + (n % align != 0 ? align - 1 : 0), align ); }
    153         int ceiling( int n, int align ) { return floor( n + (n % align != 0 ? align - 1 : 0), align ); }
    154         unsigned int ceiling( unsigned int n, unsigned int align ) { return floor( n + (n % align != 0 ? align - 1 : 0), align ); }
    155         long int ceiling( long int n, long int align ) { return floor( n + (n % align != 0 ? align - 1 : 0), align ); }
    156         unsigned long int ceiling( unsigned long int n, unsigned long int align ) { return floor( n + (n % align != 0 ? align - 1 : 0) , align); }
    157         long long int ceiling( long long int n, long long int align ) { return floor( n + (n % align != 0 ? align - 1 : 0), align ); }
    158         unsigned long long int ceiling( unsigned long long int n, unsigned long long int align ) { return floor( n + (n % align != 0 ? align - 1 : 0), align ); }
    159 
    160         // forall( otype T | { void ?{}( T &, one_t ); T ?+?( T, T ); T ?-?( T, T ); T ?/?( T, T ); } )
    161         // T ceiling( T n, T align ) { return return floor( n + (n % align != 0 ? align - 1 : 0), align ); *}
    162119} // distribution
    163120
  • libcfa/src/concurrency/coroutine.cfa

    rb7fe2e6 r856dff8  
    215215                return cor;
    216216        }
    217 
    218         struct $coroutine * __cfactx_cor_active(void) {
    219                 return active_coroutine();
    220         }
    221217}
    222218
  • libcfa/src/concurrency/invoke.c

    rb7fe2e6 r856dff8  
    2929// Called from the kernel when starting a coroutine or task so must switch back to user mode.
    3030
    31 extern struct $coroutine * __cfactx_cor_active(void);
    3231extern struct $coroutine * __cfactx_cor_finish(void);
    3332extern void __cfactx_cor_leave ( struct $coroutine * );
     
    3635extern void disable_interrupts() OPTIONAL_THREAD;
    3736extern void enable_interrupts( __cfaabi_dbg_ctx_param );
    38 
    39 struct exception_context_t * this_exception_context() {
    40         return &__get_stack( __cfactx_cor_active() )->exception_context;
    41 }
    4237
    4338void __cfactx_invoke_coroutine(
  • libcfa/src/concurrency/invoke.h

    rb7fe2e6 r856dff8  
    9898        }
    9999
    100         struct exception_context_t * this_exception_context();
    101 
    102100        // struct which calls the monitor is accepting
    103101        struct __waitfor_mask_t {
  • libcfa/src/concurrency/io/setup.cfa

    rb7fe2e6 r856dff8  
    384384                        /* paranoid */ verify( is_pow2( params_in.num_ready ) || (params_in.num_ready < 8) );
    385385                        sq.ready_cnt = max( params_in.num_ready, 8 );
    386                         sq.ready = alloc_align( 64, sq.ready_cnt );
     386                        sq.ready = alloc( sq.ready_cnt, 64`align );
    387387                        for(i; sq.ready_cnt) {
    388388                                sq.ready[i] = -1ul32;
  • libcfa/src/concurrency/kernel/startup.cfa

    rb7fe2e6 r856dff8  
    579579
    580580        // Lock the RWlock so no-one pushes/pops while we are changing the queue
     581        disable_interrupts();
    581582        uint_fast32_t last_size = ready_mutate_lock();
    582583
     
    586587        // Unlock the RWlock
    587588        ready_mutate_unlock( last_size );
     589        enable_interrupts_noPoll(); // Don't poll, could be in main cluster
     590
    588591
    589592        this.io.cnt  = num_io;
     
    601604
    602605        // Lock the RWlock so no-one pushes/pops while we are changing the queue
     606        disable_interrupts();
    603607        uint_fast32_t last_size = ready_mutate_lock();
    604608
     
    608612        // Unlock the RWlock
    609613        ready_mutate_unlock( last_size );
     614        enable_interrupts_noPoll(); // Don't poll, could be in main cluster
    610615
    611616        #if !defined(__CFA_NO_STATISTICS__)
  • libcfa/src/concurrency/ready_queue.cfa

    rb7fe2e6 r856dff8  
    215215}
    216216
     217static inline [unsigned, bool] idx_from_r(unsigned r, unsigned preferred) {
     218        unsigned i;
     219        bool local;
     220        #if defined(BIAS)
     221                unsigned rlow  = r % BIAS;
     222                unsigned rhigh = r / BIAS;
     223                if((0 != rlow) && preferred >= 0) {
     224                        // (BIAS - 1) out of BIAS chances
     225                        // Use perferred queues
     226                        i = preferred + (rhigh % 4);
     227                        local = true;
     228                }
     229                else {
     230                        // 1 out of BIAS chances
     231                        // Use all queues
     232                        i = rhigh;
     233                        local = false;
     234                }
     235        #else
     236                i = r;
     237                local = false;
     238        #endif
     239        return [i, local];
     240}
     241
    217242//-----------------------------------------------------------------------
    218243__attribute__((hot)) bool push(struct cluster * cltr, struct $thread * thrd) with (cltr->ready_queue) {
     
    222247        thrd->link.ts = rdtscl();
    223248
    224         #if defined(BIAS) && !defined(__CFA_NO_STATISTICS__)
    225                 bool local = false;
    226                 int preferred =
     249        __attribute__((unused)) bool local;
     250        __attribute__((unused)) int preferred;
     251        #if defined(BIAS)
     252                preferred =
    227253                        //*
    228254                        kernelTLS.this_processor ? kernelTLS.this_processor->id * 4 : -1;
     
    230256                        thrd->link.preferred * 4;
    231257                        //*/
    232 
    233 
    234258        #endif
    235259
     
    238262        do {
    239263                // Pick the index of a lane
    240                 #if defined(BIAS)
    241                         unsigned r = __tls_rand();
    242                         unsigned rlow  = r % BIAS;
    243                         unsigned rhigh = r / BIAS;
    244                         if((0 != rlow) && preferred >= 0) {
    245                                 // (BIAS - 1) out of BIAS chances
    246                                 // Use perferred queues
    247                                 i = preferred + (rhigh % 4);
    248 
    249                                 #if !defined(__CFA_NO_STATISTICS__)
    250                                         local = true;
    251                                         __tls_stats()->ready.pick.push.local++;
    252                                 #endif
    253                         }
    254                         else {
    255                                 // 1 out of BIAS chances
    256                                 // Use all queues
    257                                 i = rhigh;
    258                                 local = false;
    259                         }
    260                 #else
    261                         i = __tls_rand();
     264                // unsigned r = __tls_rand();
     265                unsigned r = __tls_rand_fwd();
     266                [i, local] = idx_from_r(r, preferred);
     267
     268                #if !defined(__CFA_NO_STATISTICS__)
     269                        if(local) {
     270                                __tls_stats()->ready.pick.push.local++;
     271                        }
    262272                #endif
    263273
     
    274284
    275285        // Actually push it
    276         bool lane_first = push(lanes.data[i], thrd);
     286        #ifdef USE_SNZI
     287                bool lane_first =
     288        #endif
     289
     290        push(lanes.data[i], thrd);
    277291
    278292        #ifdef USE_SNZI
     
    287301        #endif
    288302
     303        __tls_rand_advance_bck();
     304
    289305        // Unlock and return
    290306        __atomic_unlock( &lanes.data[i].lock );
     
    311327        /* paranoid */ verify( lanes.count > 0 );
    312328        unsigned count = __atomic_load_n( &lanes.count, __ATOMIC_RELAXED );
     329        int preferred;
    313330        #if defined(BIAS)
    314331                // Don't bother trying locally too much
    315332                int local_tries = 8;
    316         #endif
     333                preferred = kernelTLS.this_processor->id * 4;
     334        #endif
     335
    317336
    318337        // As long as the list is not empty, try finding a lane that isn't empty and pop from it
     
    323342        #endif
    324343                // Pick two lists at random
    325                 unsigned i,j;
    326                 #if defined(BIAS)
    327                         #if !defined(__CFA_NO_STATISTICS__)
    328                                 bool local = false;
    329                         #endif
    330                         uint64_t r = __tls_rand();
    331                         unsigned rlow  = r % BIAS;
    332                         uint64_t rhigh = r / BIAS;
    333                         if(local_tries && 0 != rlow) {
    334                                 // (BIAS - 1) out of BIAS chances
    335                                 // Use perferred queues
    336                                 unsigned pid = kernelTLS.this_processor->id * 4;
    337                                 i = pid + (rhigh % 4);
    338                                 j = pid + ((rhigh >> 32ull) % 4);
    339 
    340                                 // count the tries
    341                                 local_tries--;
    342 
    343                                 #if !defined(__CFA_NO_STATISTICS__)
    344                                         local = true;
    345                                         __tls_stats()->ready.pick.pop.local++;
    346                                 #endif
    347                         }
    348                         else {
    349                                 // 1 out of BIAS chances
    350                                 // Use all queues
    351                                 i = rhigh;
    352                                 j = rhigh >> 32ull;
    353                         }
    354                 #else
    355                         i = __tls_rand();
    356                         j = __tls_rand();
     344                // unsigned ri = __tls_rand();
     345                // unsigned rj = __tls_rand();
     346                unsigned ri = __tls_rand_bck();
     347                unsigned rj = __tls_rand_bck();
     348
     349                unsigned i, j;
     350                __attribute__((unused)) bool locali, localj;
     351                [i, locali] = idx_from_r(ri, preferred);
     352                [j, localj] = idx_from_r(rj, preferred);
     353
     354                #if !defined(__CFA_NO_STATISTICS__)
     355                        if(locali) {
     356                                __tls_stats()->ready.pick.pop.local++;
     357                        }
     358                        if(localj) {
     359                                __tls_stats()->ready.pick.pop.local++;
     360                        }
    357361                #endif
    358362
     
    364368                if(thrd) {
    365369                        #if defined(BIAS) && !defined(__CFA_NO_STATISTICS__)
    366                                 if( local ) __tls_stats()->ready.pick.pop.lsuccess++;
     370                                if( locali || localj ) __tls_stats()->ready.pick.pop.lsuccess++;
    367371                        #endif
    368372                        return thrd;
     
    543547
    544548                // Allocate new array (uses realloc and memcpies the data)
    545                 lanes.data = alloc(lanes.data, ncount);
     549                lanes.data = alloc( ncount, lanes.data`realloc );
    546550
    547551                // Fix the moved data
     
    634638
    635639                // Allocate new array (uses realloc and memcpies the data)
    636                 lanes.data = alloc(lanes.data, lanes.count);
     640                lanes.data = alloc( lanes.count, lanes.data`realloc );
    637641
    638642                // Fix the moved data
  • libcfa/src/exception.c

    rb7fe2e6 r856dff8  
    209209                void * stop_param) {
    210210        // Verify actions follow the rules we expect.
    211         verify((actions & _UA_CLEANUP_PHASE) && (actions & _UA_FORCE_UNWIND));
    212         verify(!(actions & (_UA_SEARCH_PHASE | _UA_HANDLER_FRAME)));
     211        verify(actions & _UA_CLEANUP_PHASE);
     212        verify(actions & _UA_FORCE_UNWIND);
     213        verify(!(actions & _UA_SEARCH_PHASE));
     214        verify(!(actions & _UA_HANDLER_FRAME));
    213215
    214216        if ( actions & _UA_END_OF_STACK ) {
    215                 exit(1);
     217                abort();
    216218        } else {
    217219                return _URC_NO_REASON;
     
    219221}
    220222
    221 static struct _Unwind_Exception cancel_exception_storage;
     223__attribute__((weak)) _Unwind_Reason_Code
     224__cfaehm_cancellation_unwind( struct _Unwind_Exception * exception ) {
     225        return _Unwind_ForcedUnwind( exception, _Stop_Fn, (void*)0x22 );
     226}
    222227
    223228// Cancel the current stack, prefroming approprate clean-up and messaging.
    224229void __cfaehm_cancel_stack( exception_t * exception ) {
    225         // TODO: Detect current stack and pick a particular stop-function.
     230        __cfaehm_allocate_exception( exception );
     231
     232        struct exception_context_t * context = this_exception_context();
     233        struct __cfaehm_node * node = EXCEPT_TO_NODE(context->current_exception);
     234
     235        // Preform clean-up of any extra active exceptions.
     236        while ( node->next ) {
     237                struct __cfaehm_node * to_free = node->next;
     238                node->next = to_free->next;
     239                exception_t * except = NODE_TO_EXCEPT( to_free );
     240                except->virtual_table->free( except );
     241            free( to_free );
     242        }
     243
    226244        _Unwind_Reason_Code ret;
    227         ret = _Unwind_ForcedUnwind( &cancel_exception_storage, _Stop_Fn, (void*)0x22 );
     245        ret = __cfaehm_cancellation_unwind( &node->unwind_exception );
    228246        printf("UNWIND ERROR %d after force unwind\n", ret);
    229247        abort();
  • libcfa/src/heap.cfa

    rb7fe2e6 r856dff8  
    1010// Created On       : Tue Dec 19 21:58:35 2017
    1111// Last Modified By : Peter A. Buhr
    12 // Last Modified On : Wed Aug 12 16:43:38 2020
    13 // Update Count     : 902
     12// Last Modified On : Mon Aug 24 20:29:24 2020
     13// Update Count     : 926
    1414//
    1515
     
    2727#include "bits/locks.hfa"                                                               // __spinlock_t
    2828#include "startup.hfa"                                                                  // STARTUP_PRIORITY_MEMORY
    29 //#include "stdlib.hfa"                                                                 // bsearchl
    30 #include "bitmanip.hfa"                                                                 // ceiling
     29#include "math.hfa"                                                                             // ceiling
     30#include "bitmanip.hfa"                                                                 // is_pow2, ceiling2
    3131
    3232#define MIN(x, y) (y > x ? x : y)
     
    651651                #else
    652652                // 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;
     653//              for ( HeapManager.Storage * p = top( freeLists[i].freeList ); p != 0p; /* p = getNext( p )->top */) {
     654                for ( HeapManager.Storage * p ;; /* p = getNext( p )->top */) {
     655                        HeapManager.Storage * temp = p->header.kind.real.next.top; // FIX ME: direct assignent fails, initialization works`
     656//                      typeof(p) temp = (( p )`next)->top;                     // FIX ME: direct assignent fails, initialization works`
     657//                      p = temp;
    656658                #endif // BUCKETLOCK
    657659                        total += size;
  • libcfa/src/iostream.cfa

    rb7fe2e6 r856dff8  
    1010// Created On       : Wed May 27 17:56:53 2015
    1111// Last Modified By : Peter A. Buhr
    12 // Last Modified On : Tue Aug 11 22:16:33 2020
    13 // Update Count     : 1128
     12// Last Modified On : Mon Aug 24 08:31:35 2020
     13// Update Count     : 1130
    1414//
    1515
     
    2020#include <stdint.h>                                                                             // UINT64_MAX
    2121#include <float.h>                                                                              // DBL_DIG, LDBL_DIG
    22 #include <math.h>                                                                               // isfinite
    2322#include <complex.h>                                                                    // creal, cimag
    24 //#include <string.h>                                                                   // strlen, strcmp
     23//#include <string.h>                                                                   // strlen, strcmp, memcpy
    2524extern "C" {
    2625extern size_t strlen (const char *__s) __attribute__ ((__nothrow__ , __leaf__)) __attribute__ ((__pure__)) __attribute__ ((__nonnull__ (1)));
     
    3029} // extern "C"
    3130
    32 #include <bitmanip.hfa>                                                                 // high1
     31#include "math.hfa"                                                                             // isfinite, floor, ceiling_div
     32#include "bitmanip.hfa"                                                                 // high1
    3333
    3434
  • libcfa/src/math.hfa

    rb7fe2e6 r856dff8  
    1010// Created On       : Mon Apr 18 23:37:04 2016
    1111// Last Modified By : Peter A. Buhr
    12 // Last Modified On : Tue Feb  4 10:27:11 2020
    13 // Update Count     : 117
     12// Last Modified On : Mon Aug 24 08:56:20 2020
     13// Update Count     : 126
    1414//
    1515
     
    1919#include <complex.h>
    2020
     21//---------------------------------------
     22
     23#include "common.hfa"
     24
    2125//---------------------- General ----------------------
    2226
    23 static inline float ?%?( float x, float y ) { return fmodf( x, y ); }
    24 static inline float fmod( float x, float y ) { return fmodf( x, y ); }
    25 static inline double ?%?( double x, double y ) { return fmod( x, y ); }
    26 // extern "C" { double fmod( double, double ); }
    27 static inline long double ?%?( long double x, long double y ) { return fmodl( x, y ); }
    28 static inline long double fmod( long double x, long double y ) { return fmodl( x, y ); }
    29 
    30 static inline float remainder( float x, float y ) { return remainderf( x, y ); }
    31 // extern "C" { double remainder( double, double ); }
    32 static inline long double remainder( long double x, long double y ) { return remainderl( x, y ); }
    33 
    34 static inline float remquo( float x, float y, int * quo ) { return remquof( x, y, quo ); }
    35 // extern "C" { double remquo( double x, double y, int * quo ); }
    36 static inline long double remquo( long double x, long double y, int * quo ) { return remquol( x, y, quo ); }
    37 static inline [ int, float ] remquo( float x, float y ) { int quo; x = remquof( x, y, &quo ); return [ quo, x ]; }
    38 static inline [ int, double ] remquo( double x, double y ) { int quo; x = remquo( x, y, &quo ); return [ quo, x ]; }
    39 static inline [ int, long double ] remquo( long double x, long double y ) { int quo; x = remquol( x, y, &quo ); return [ quo, x ]; }
    40 
    41 static inline [ float, float ] div( float x, float y ) { y = modff( x / y, &x ); return [ x, y ]; }
    42 static inline [ double, double ] div( double x, double y ) { y = modf( x / y, &x ); return [ x, y ]; }
    43 static inline [ long double, long double ] div( long double x, long double y ) { y = modfl( x / y, &x ); return [ x, y ]; }
    44 
    45 static inline float fma( float x, float y, float z ) { return fmaf( x, y, z ); }
    46 // extern "C" { double fma( double, double, double ); }
    47 static inline long double fma( long double x, long double y, long double z ) { return fmal( x, y, z ); }
    48 
    49 static inline float fdim( float x, float y ) { return fdimf( x, y ); }
    50 // extern "C" { double fdim( double, double ); }
    51 static inline long double fdim( long double x, long double y ) { return fdiml( x, y ); }
    52 
    53 static inline float nan( const char tag[] ) { return nanf( tag ); }
    54 // extern "C" { double nan( const char [] ); }
    55 static inline long double nan( const char tag[] ) { return nanl( tag ); }
     27static inline {
     28        float ?%?( float x, float y ) { return fmodf( x, y ); }
     29        float fmod( float x, float y ) { return fmodf( x, y ); }
     30        double ?%?( double x, double y ) { return fmod( x, y ); }
     31        // extern "C" { double fmod( double, double ); }
     32        long double ?%?( long double x, long double y ) { return fmodl( x, y ); }
     33        long double fmod( long double x, long double y ) { return fmodl( x, y ); }
     34
     35        float remainder( float x, float y ) { return remainderf( x, y ); }
     36        // extern "C" { double remainder( double, double ); }
     37        long double remainder( long double x, long double y ) { return remainderl( x, y ); }
     38
     39        float remquo( float x, float y, int * quo ) { return remquof( x, y, quo ); }
     40        // extern "C" { double remquo( double x, double y, int * quo ); }
     41        long double remquo( long double x, long double y, int * quo ) { return remquol( x, y, quo ); }
     42        [ int, float ] remquo( float x, float y ) { int quo; x = remquof( x, y, &quo ); return [ quo, x ]; }
     43        [ int, double ] remquo( double x, double y ) { int quo; x = remquo( x, y, &quo ); return [ quo, x ]; }
     44        [ int, long double ] remquo( long double x, long double y ) { int quo; x = remquol( x, y, &quo ); return [ quo, x ]; }
     45
     46        [ float, float ] div( float x, float y ) { y = modff( x / y, &x ); return [ x, y ]; }
     47        [ double, double ] div( double x, double y ) { y = modf( x / y, &x ); return [ x, y ]; }
     48        [ long double, long double ] div( long double x, long double y ) { y = modfl( x / y, &x ); return [ x, y ]; }
     49
     50        float fma( float x, float y, float z ) { return fmaf( x, y, z ); }
     51        // extern "C" { double fma( double, double, double ); }
     52        long double fma( long double x, long double y, long double z ) { return fmal( x, y, z ); }
     53
     54        float fdim( float x, float y ) { return fdimf( x, y ); }
     55        // extern "C" { double fdim( double, double ); }
     56        long double fdim( long double x, long double y ) { return fdiml( x, y ); }
     57
     58        float nan( const char tag[] ) { return nanf( tag ); }
     59        // extern "C" { double nan( const char [] ); }
     60        long double nan( const char tag[] ) { return nanl( tag ); }
     61} // distribution
    5662
    5763//---------------------- Exponential ----------------------
    5864
    59 static inline float exp( float x ) { return expf( x ); }
    60 // extern "C" { double exp( double ); }
    61 static inline long double exp( long double x ) { return expl( x ); }
    62 static inline float _Complex exp( float _Complex x ) { return cexpf( x ); }
    63 static inline double _Complex exp( double _Complex x ) { return cexp( x ); }
    64 static inline long double _Complex exp( long double _Complex x ) { return cexpl( x ); }
    65 
    66 static inline float exp2( float x ) { return exp2f( x ); }
    67 // extern "C" { double exp2( double ); }
    68 static inline long double exp2( long double x ) { return exp2l( x ); }
    69 //static inline float _Complex exp2( float _Complex x ) { return cexp2f( x ); }
    70 //static inline double _Complex exp2( double _Complex x ) { return cexp2( x ); }
    71 //static inline long double _Complex exp2( long double _Complex x ) { return cexp2l( x ); }
    72 
    73 static inline float expm1( float x ) { return expm1f( x ); }
    74 // extern "C" { double expm1( double ); }
    75 static inline long double expm1( long double x ) { return expm1l( x ); }
    76 
    77 static inline float pow( float x, float y ) { return powf( x, y ); }
    78 // extern "C" { double pow( double, double ); }
    79 static inline long double pow( long double x, long double y ) { return powl( x, y ); }
    80 static inline float _Complex pow( float _Complex x, float _Complex y ) { return cpowf( x, y ); }
    81 static inline double _Complex pow( double _Complex x, double _Complex y ) { return cpow( x, y ); }
    82 static inline long double _Complex pow( long double _Complex x, long double _Complex y ) { return cpowl( x, y ); }
     65static inline {
     66        float exp( float x ) { return expf( x ); }
     67        // extern "C" { double exp( double ); }
     68        long double exp( long double x ) { return expl( x ); }
     69        float _Complex exp( float _Complex x ) { return cexpf( x ); }
     70        double _Complex exp( double _Complex x ) { return cexp( x ); }
     71        long double _Complex exp( long double _Complex x ) { return cexpl( x ); }
     72
     73        float exp2( float x ) { return exp2f( x ); }
     74        // extern "C" { double exp2( double ); }
     75        long double exp2( long double x ) { return exp2l( x ); }
     76        //float _Complex exp2( float _Complex x ) { return cexp2f( x ); }
     77        //double _Complex exp2( double _Complex x ) { return cexp2( x ); }
     78        //long double _Complex exp2( long double _Complex x ) { return cexp2l( x ); }
     79
     80        float expm1( float x ) { return expm1f( x ); }
     81        // extern "C" { double expm1( double ); }
     82        long double expm1( long double x ) { return expm1l( x ); }
     83
     84        float pow( float x, float y ) { return powf( x, y ); }
     85        // extern "C" { double pow( double, double ); }
     86        long double pow( long double x, long double y ) { return powl( x, y ); }
     87        float _Complex pow( float _Complex x, float _Complex y ) { return cpowf( x, y ); }
     88        double _Complex pow( double _Complex x, double _Complex y ) { return cpow( x, y ); }
     89        long double _Complex pow( long double _Complex x, long double _Complex y ) { return cpowl( x, y ); }
     90} // distribution
    8391
    8492//---------------------- Logarithm ----------------------
    8593
    86 static inline float log( float x ) { return logf( x ); }
    87 // extern "C" { double log( double ); }
    88 static inline long double log( long double x ) { return logl( x ); }
    89 static inline float _Complex log( float _Complex x ) { return clogf( x ); }
    90 static inline double _Complex log( double _Complex x ) { return clog( x ); }
    91 static inline long double _Complex log( long double _Complex x ) { return clogl( x ); }
    92 
    93 static inline float log2( float x ) { return log2f( x ); }
    94 // extern "C" { double log2( double ); }
    95 static inline long double log2( long double x ) { return log2l( x ); }
    96 // static inline float _Complex log2( float _Complex x ) { return clog2f( x ); }
    97 // static inline double _Complex log2( double _Complex x ) { return clog2( x ); }
    98 // static inline long double _Complex log2( long double _Complex x ) { return clog2l( x ); }
    99 
    100 static inline float log10( float x ) { return log10f( x ); }
    101 // extern "C" { double log10( double ); }
    102 static inline long double log10( long double x ) { return log10l( x ); }
    103 // static inline float _Complex log10( float _Complex x ) { return clog10f( x ); }
    104 // static inline double _Complex log10( double _Complex x ) { return clog10( x ); }
    105 // static inline long double _Complex log10( long double _Complex x ) { return clog10l( x ); }
    106 
    107 static inline float log1p( float x ) { return log1pf( x ); }
    108 // extern "C" { double log1p( double ); }
    109 static inline long double log1p( long double x ) { return log1pl( x ); }
    110 
    111 static inline int ilogb( float x ) { return ilogbf( x ); }
    112 // extern "C" { int ilogb( double ); }
    113 static inline int ilogb( long double x ) { return ilogbl( x ); }
    114 
    115 static inline float logb( float x ) { return logbf( x ); }
    116 // extern "C" { double logb( double ); }
    117 static inline long double logb( long double x ) { return logbl( x ); }
    118 
    119 static inline float sqrt( float x ) { return sqrtf( x ); }
    120 // extern "C" { double sqrt( double ); }
    121 static inline long double sqrt( long double x ) { return sqrtl( x ); }
    122 static inline float _Complex sqrt( float _Complex x ) { return csqrtf( x ); }
    123 static inline double _Complex sqrt( double _Complex x ) { return csqrt( x ); }
    124 static inline long double _Complex sqrt( long double _Complex x ) { return csqrtl( x ); }
    125 
    126 static inline float cbrt( float x ) { return cbrtf( x ); }
    127 // extern "C" { double cbrt( double ); }
    128 static inline long double cbrt( long double x ) { return cbrtl( x ); }
    129 
    130 static inline float hypot( float x, float y ) { return hypotf( x, y ); }
    131 // extern "C" { double hypot( double, double ); }
    132 static inline long double hypot( long double x, long double y ) { return hypotl( x, y ); }
     94static inline {
     95        float log( float x ) { return logf( x ); }
     96        // extern "C" { double log( double ); }
     97        long double log( long double x ) { return logl( x ); }
     98        float _Complex log( float _Complex x ) { return clogf( x ); }
     99        double _Complex log( double _Complex x ) { return clog( x ); }
     100        long double _Complex log( long double _Complex x ) { return clogl( x ); }
     101
     102        float log2( float x ) { return log2f( x ); }
     103        // extern "C" { double log2( double ); }
     104        long double log2( long double x ) { return log2l( x ); }
     105        // float _Complex log2( float _Complex x ) { return clog2f( x ); }
     106        // double _Complex log2( double _Complex x ) { return clog2( x ); }
     107        // long double _Complex log2( long double _Complex x ) { return clog2l( x ); }
     108
     109        float log10( float x ) { return log10f( x ); }
     110        // extern "C" { double log10( double ); }
     111        long double log10( long double x ) { return log10l( x ); }
     112        // float _Complex log10( float _Complex x ) { return clog10f( x ); }
     113        // double _Complex log10( double _Complex x ) { return clog10( x ); }
     114        // long double _Complex log10( long double _Complex x ) { return clog10l( x ); }
     115
     116        float log1p( float x ) { return log1pf( x ); }
     117        // extern "C" { double log1p( double ); }
     118        long double log1p( long double x ) { return log1pl( x ); }
     119
     120        int ilogb( float x ) { return ilogbf( x ); }
     121        // extern "C" { int ilogb( double ); }
     122        int ilogb( long double x ) { return ilogbl( x ); }
     123
     124        float logb( float x ) { return logbf( x ); }
     125        // extern "C" { double logb( double ); }
     126        long double logb( long double x ) { return logbl( x ); }
     127
     128        float sqrt( float x ) { return sqrtf( x ); }
     129        // extern "C" { double sqrt( double ); }
     130        long double sqrt( long double x ) { return sqrtl( x ); }
     131        float _Complex sqrt( float _Complex x ) { return csqrtf( x ); }
     132        double _Complex sqrt( double _Complex x ) { return csqrt( x ); }
     133        long double _Complex sqrt( long double _Complex x ) { return csqrtl( x ); }
     134
     135        float cbrt( float x ) { return cbrtf( x ); }
     136        // extern "C" { double cbrt( double ); }
     137        long double cbrt( long double x ) { return cbrtl( x ); }
     138
     139        float hypot( float x, float y ) { return hypotf( x, y ); }
     140        // extern "C" { double hypot( double, double ); }
     141        long double hypot( long double x, long double y ) { return hypotl( x, y ); }
     142} // distribution
    133143
    134144//---------------------- Trigonometric ----------------------
    135145
    136 static inline float sin( float x ) { return sinf( x ); }
    137 // extern "C" { double sin( double ); }
    138 static inline long double sin( long double x ) { return sinl( x ); }
    139 static inline float _Complex sin( float _Complex x ) { return csinf( x ); }
    140 static inline double _Complex sin( double _Complex x ) { return csin( x ); }
    141 static inline long double _Complex sin( long double _Complex x ) { return csinl( x ); }
    142 
    143 static inline float cos( float x ) { return cosf( x ); }
    144 // extern "C" { double cos( double ); }
    145 static inline long double cos( long double x ) { return cosl( x ); }
    146 static inline float _Complex cos( float _Complex x ) { return ccosf( x ); }
    147 static inline double _Complex cos( double _Complex x ) { return ccos( x ); }
    148 static inline long double _Complex cos( long double _Complex x ) { return ccosl( x ); }
    149 
    150 static inline float tan( float x ) { return tanf( x ); }
    151 // extern "C" { double tan( double ); }
    152 static inline long double tan( long double x ) { return tanl( x ); }
    153 static inline float _Complex tan( float _Complex x ) { return ctanf( x ); }
    154 static inline double _Complex tan( double _Complex x ) { return ctan( x ); }
    155 static inline long double _Complex tan( long double _Complex x ) { return ctanl( x ); }
    156 
    157 static inline float asin( float x ) { return asinf( x ); }
    158 // extern "C" { double asin( double ); }
    159 static inline long double asin( long double x ) { return asinl( x ); }
    160 static inline float _Complex asin( float _Complex x ) { return casinf( x ); }
    161 static inline double _Complex asin( double _Complex x ) { return casin( x ); }
    162 static inline long double _Complex asin( long double _Complex x ) { return casinl( x ); }
    163 
    164 static inline float acos( float x ) { return acosf( x ); }
    165 // extern "C" { double acos( double ); }
    166 static inline long double acos( long double x ) { return acosl( x ); }
    167 static inline float _Complex acos( float _Complex x ) { return cacosf( x ); }
    168 static inline double _Complex acos( double _Complex x ) { return cacos( x ); }
    169 static inline long double _Complex acos( long double _Complex x ) { return cacosl( x ); }
    170 
    171 static inline float atan( float x ) { return atanf( x ); }
    172 // extern "C" { double atan( double ); }
    173 static inline long double atan( long double x ) { return atanl( x ); }
    174 static inline float _Complex atan( float _Complex x ) { return catanf( x ); }
    175 static inline double _Complex atan( double _Complex x ) { return catan( x ); }
    176 static inline long double _Complex atan( long double _Complex x ) { return catanl( x ); }
    177 
    178 static inline float atan2( float x, float y ) { return atan2f( x, y ); }
    179 // extern "C" { double atan2( double, double ); }
    180 static inline long double atan2( long double x, long double y ) { return atan2l( x, y ); }
    181 
    182 // alternative name for atan2
    183 static inline float atan( float x, float y ) { return atan2f( x, y ); }
    184 static inline double atan( double x, double y ) { return atan2( x, y ); }
    185 static inline long double atan( long double x, long double y ) { return atan2l( x, y ); }
     146static inline {
     147        float sin( float x ) { return sinf( x ); }
     148        // extern "C" { double sin( double ); }
     149        long double sin( long double x ) { return sinl( x ); }
     150        float _Complex sin( float _Complex x ) { return csinf( x ); }
     151        double _Complex sin( double _Complex x ) { return csin( x ); }
     152        long double _Complex sin( long double _Complex x ) { return csinl( x ); }
     153
     154        float cos( float x ) { return cosf( x ); }
     155        // extern "C" { double cos( double ); }
     156        long double cos( long double x ) { return cosl( x ); }
     157        float _Complex cos( float _Complex x ) { return ccosf( x ); }
     158        double _Complex cos( double _Complex x ) { return ccos( x ); }
     159        long double _Complex cos( long double _Complex x ) { return ccosl( x ); }
     160
     161        float tan( float x ) { return tanf( x ); }
     162        // extern "C" { double tan( double ); }
     163        long double tan( long double x ) { return tanl( x ); }
     164        float _Complex tan( float _Complex x ) { return ctanf( x ); }
     165        double _Complex tan( double _Complex x ) { return ctan( x ); }
     166        long double _Complex tan( long double _Complex x ) { return ctanl( x ); }
     167
     168        float asin( float x ) { return asinf( x ); }
     169        // extern "C" { double asin( double ); }
     170        long double asin( long double x ) { return asinl( x ); }
     171        float _Complex asin( float _Complex x ) { return casinf( x ); }
     172        double _Complex asin( double _Complex x ) { return casin( x ); }
     173        long double _Complex asin( long double _Complex x ) { return casinl( x ); }
     174
     175        float acos( float x ) { return acosf( x ); }
     176        // extern "C" { double acos( double ); }
     177        long double acos( long double x ) { return acosl( x ); }
     178        float _Complex acos( float _Complex x ) { return cacosf( x ); }
     179        double _Complex acos( double _Complex x ) { return cacos( x ); }
     180        long double _Complex acos( long double _Complex x ) { return cacosl( x ); }
     181
     182        float atan( float x ) { return atanf( x ); }
     183        // extern "C" { double atan( double ); }
     184        long double atan( long double x ) { return atanl( x ); }
     185        float _Complex atan( float _Complex x ) { return catanf( x ); }
     186        double _Complex atan( double _Complex x ) { return catan( x ); }
     187        long double _Complex atan( long double _Complex x ) { return catanl( x ); }
     188
     189        float atan2( float x, float y ) { return atan2f( x, y ); }
     190        // extern "C" { double atan2( double, double ); }
     191        long double atan2( long double x, long double y ) { return atan2l( x, y ); }
     192
     193        // alternative name for atan2
     194        float atan( float x, float y ) { return atan2f( x, y ); }
     195        double atan( double x, double y ) { return atan2( x, y ); }
     196        long double atan( long double x, long double y ) { return atan2l( x, y ); }
     197} // distribution
    186198
    187199//---------------------- Hyperbolic ----------------------
    188200
    189 static inline float sinh( float x ) { return sinhf( x ); }
    190 // extern "C" { double sinh( double ); }
    191 static inline long double sinh( long double x ) { return sinhl( x ); }
    192 static inline float _Complex sinh( float _Complex x ) { return csinhf( x ); }
    193 static inline double _Complex sinh( double _Complex x ) { return csinh( x ); }
    194 static inline long double _Complex sinh( long double _Complex x ) { return csinhl( x ); }
    195 
    196 static inline float cosh( float x ) { return coshf( x ); }
    197 // extern "C" { double cosh( double ); }
    198 static inline long double cosh( long double x ) { return coshl( x ); }
    199 static inline float _Complex cosh( float _Complex x ) { return ccoshf( x ); }
    200 static inline double _Complex cosh( double _Complex x ) { return ccosh( x ); }
    201 static inline long double _Complex cosh( long double _Complex x ) { return ccoshl( x ); }
    202 
    203 static inline float tanh( float x ) { return tanhf( x ); }
    204 // extern "C" { double tanh( double ); }
    205 static inline long double tanh( long double x ) { return tanhl( x ); }
    206 static inline float _Complex tanh( float _Complex x ) { return ctanhf( x ); }
    207 static inline double _Complex tanh( double _Complex x ) { return ctanh( x ); }
    208 static inline long double _Complex tanh( long double _Complex x ) { return ctanhl( x ); }
    209 
    210 static inline float asinh( float x ) { return asinhf( x ); }
    211 // extern "C" { double asinh( double ); }
    212 static inline long double asinh( long double x ) { return asinhl( x ); }
    213 static inline float _Complex asinh( float _Complex x ) { return casinhf( x ); }
    214 static inline double _Complex asinh( double _Complex x ) { return casinh( x ); }
    215 static inline long double _Complex asinh( long double _Complex x ) { return casinhl( x ); }
    216 
    217 static inline float acosh( float x ) { return acoshf( x ); }
    218 // extern "C" { double acosh( double ); }
    219 static inline long double acosh( long double x ) { return acoshl( x ); }
    220 static inline float _Complex acosh( float _Complex x ) { return cacoshf( x ); }
    221 static inline double _Complex acosh( double _Complex x ) { return cacosh( x ); }
    222 static inline long double _Complex acosh( long double _Complex x ) { return cacoshl( x ); }
    223 
    224 static inline float atanh( float x ) { return atanhf( x ); }
    225 // extern "C" { double atanh( double ); }
    226 static inline long double atanh( long double x ) { return atanhl( x ); }
    227 static inline float _Complex atanh( float _Complex x ) { return catanhf( x ); }
    228 static inline double _Complex atanh( double _Complex x ) { return catanh( x ); }
    229 static inline long double _Complex atanh( long double _Complex x ) { return catanhl( x ); }
     201static inline {
     202        float sinh( float x ) { return sinhf( x ); }
     203        // extern "C" { double sinh( double ); }
     204        long double sinh( long double x ) { return sinhl( x ); }
     205        float _Complex sinh( float _Complex x ) { return csinhf( x ); }
     206        double _Complex sinh( double _Complex x ) { return csinh( x ); }
     207        long double _Complex sinh( long double _Complex x ) { return csinhl( x ); }
     208
     209        float cosh( float x ) { return coshf( x ); }
     210        // extern "C" { double cosh( double ); }
     211        long double cosh( long double x ) { return coshl( x ); }
     212        float _Complex cosh( float _Complex x ) { return ccoshf( x ); }
     213        double _Complex cosh( double _Complex x ) { return ccosh( x ); }
     214        long double _Complex cosh( long double _Complex x ) { return ccoshl( x ); }
     215
     216        float tanh( float x ) { return tanhf( x ); }
     217        // extern "C" { double tanh( double ); }
     218        long double tanh( long double x ) { return tanhl( x ); }
     219        float _Complex tanh( float _Complex x ) { return ctanhf( x ); }
     220        double _Complex tanh( double _Complex x ) { return ctanh( x ); }
     221        long double _Complex tanh( long double _Complex x ) { return ctanhl( x ); }
     222
     223        float asinh( float x ) { return asinhf( x ); }
     224        // extern "C" { double asinh( double ); }
     225        long double asinh( long double x ) { return asinhl( x ); }
     226        float _Complex asinh( float _Complex x ) { return casinhf( x ); }
     227        double _Complex asinh( double _Complex x ) { return casinh( x ); }
     228        long double _Complex asinh( long double _Complex x ) { return casinhl( x ); }
     229
     230        float acosh( float x ) { return acoshf( x ); }
     231        // extern "C" { double acosh( double ); }
     232        long double acosh( long double x ) { return acoshl( x ); }
     233        float _Complex acosh( float _Complex x ) { return cacoshf( x ); }
     234        double _Complex acosh( double _Complex x ) { return cacosh( x ); }
     235        long double _Complex acosh( long double _Complex x ) { return cacoshl( x ); }
     236
     237        float atanh( float x ) { return atanhf( x ); }
     238        // extern "C" { double atanh( double ); }
     239        long double atanh( long double x ) { return atanhl( x ); }
     240        float _Complex atanh( float _Complex x ) { return catanhf( x ); }
     241        double _Complex atanh( double _Complex x ) { return catanh( x ); }
     242        long double _Complex atanh( long double _Complex x ) { return catanhl( x ); }
     243} // distribution
    230244
    231245//---------------------- Error / Gamma ----------------------
    232246
    233 static inline float erf( float x ) { return erff( x ); }
    234 // extern "C" { double erf( double ); }
    235 static inline long double erf( long double x ) { return erfl( x ); }
    236 // float _Complex erf( float _Complex );
    237 // double _Complex erf( double _Complex );
    238 // long double _Complex erf( long double _Complex );
    239 
    240 static inline float erfc( float x ) { return erfcf( x ); }
    241 // extern "C" { double erfc( double ); }
    242 static inline long double erfc( long double x ) { return erfcl( x ); }
    243 // float _Complex erfc( float _Complex );
    244 // double _Complex erfc( double _Complex );
    245 // long double _Complex erfc( long double _Complex );
    246 
    247 static inline float lgamma( float x ) { return lgammaf( x ); }
    248 // extern "C" { double lgamma( double ); }
    249 static inline long double lgamma( long double x ) { return lgammal( x ); }
    250 static inline float lgamma( float x, int * sign ) { return lgammaf_r( x, sign ); }
    251 static inline double lgamma( double x, int * sign ) { return lgamma_r( x, sign ); }
    252 static inline long double lgamma( long double x, int * sign ) { return lgammal_r( x, sign ); }
    253 
    254 static inline float tgamma( float x ) { return tgammaf( x ); }
    255 // extern "C" { double tgamma( double ); }
    256 static inline long double tgamma( long double x ) { return tgammal( x ); }
     247static inline {
     248        float erf( float x ) { return erff( x ); }
     249        // extern "C" { double erf( double ); }
     250        long double erf( long double x ) { return erfl( x ); }
     251        // float _Complex erf( float _Complex );
     252        // double _Complex erf( double _Complex );
     253        // long double _Complex erf( long double _Complex );
     254
     255        float erfc( float x ) { return erfcf( x ); }
     256        // extern "C" { double erfc( double ); }
     257        long double erfc( long double x ) { return erfcl( x ); }
     258        // float _Complex erfc( float _Complex );
     259        // double _Complex erfc( double _Complex );
     260        // long double _Complex erfc( long double _Complex );
     261
     262        float lgamma( float x ) { return lgammaf( x ); }
     263        // extern "C" { double lgamma( double ); }
     264        long double lgamma( long double x ) { return lgammal( x ); }
     265        float lgamma( float x, int * sign ) { return lgammaf_r( x, sign ); }
     266        double lgamma( double x, int * sign ) { return lgamma_r( x, sign ); }
     267        long double lgamma( long double x, int * sign ) { return lgammal_r( x, sign ); }
     268
     269        float tgamma( float x ) { return tgammaf( x ); }
     270        // extern "C" { double tgamma( double ); }
     271        long double tgamma( long double x ) { return tgammal( x ); }
     272} // distribution
    257273
    258274//---------------------- Nearest Integer ----------------------
    259275
    260 static inline float floor( float x ) { return floorf( x ); }
    261 // extern "C" { double floor( double ); }
    262 static inline long double floor( long double x ) { return floorl( x ); }
    263 
    264 static inline float ceil( float x ) { return ceilf( x ); }
    265 // extern "C" { double ceil( double ); }
    266 static inline long double ceil( long double x ) { return ceill( x ); }
    267 
    268 static inline float trunc( float x ) { return truncf( x ); }
    269 // extern "C" { double trunc( double ); }
    270 static inline long double trunc( long double x ) { return truncl( x ); }
    271 
    272 static inline float rint( float x ) { return rintf( x ); }
    273 // extern "C" { double rint( double x ); }
    274 static inline long double rint( long double x ) { return rintl( x ); }
    275 static inline long int rint( float x ) { return lrintf( x ); }
    276 static inline long int rint( double x ) { return lrint( x ); }
    277 static inline long int rint( long double x ) { return lrintl( x ); }
    278 static inline long long int rint( float x ) { return llrintf( x ); }
    279 static inline long long int rint( double x ) { return llrint( x ); }
    280 static inline long long int rint( long double x ) { return llrintl( x ); }
    281 
    282 static inline long int lrint( float x ) { return lrintf( x ); }
    283 // extern "C" { long int lrint( double ); }
    284 static inline long int lrint( long double x ) { return lrintl( x ); }
    285 static inline long long int llrint( float x ) { return llrintf( x ); }
    286 // extern "C" { long long int llrint( double ); }
    287 static inline long long int llrint( long double x ) { return llrintl( x ); }
    288 
    289 static inline float nearbyint( float x ) { return nearbyintf( x ); }
    290 // extern "C" { double nearbyint( double ); }
    291 static inline long double nearbyint( long double x ) { return nearbyintl( x ); }
    292 
    293 static inline float round( float x ) { return roundf( x ); }
    294 // extern "C" { double round( double x ); }
    295 static inline long double round( long double x ) { return roundl( x ); }
    296 static inline long int round( float x ) { return lroundf( x ); }
    297 static inline long int round( double x ) { return lround( x ); }
    298 static inline long int round( long double x ) { return lroundl( x ); }
    299 static inline long long int round( float x ) { return llroundf( x ); }
    300 static inline long long int round( double x ) { return llround( x ); }
    301 static inline long long int round( long double x ) { return llroundl( x ); }
    302 
    303 static inline long int lround( float x ) { return lroundf( x ); }
    304 // extern "C" { long int lround( double ); }
    305 static inline long int lround( long double x ) { return lroundl( x ); }
    306 static inline long long int llround( float x ) { return llroundf( x ); }
    307 // extern "C" { long long int llround( double ); }
    308 static inline long long int llround( long double x ) { return llroundl( x ); }
     276static inline {
     277        signed char floor( signed char n, signed char align ) { return n / align * align; }
     278        unsigned char floor( unsigned char n, unsigned char align ) { return n / align * align; }
     279        short int floor( short int n, short int align ) { return n / align * align; }
     280        unsigned short int floor( unsigned short int n, unsigned short int align ) { return n / align * align; }
     281        int floor( int n, int align ) { return n / align * align; }
     282        unsigned int floor( unsigned int n, unsigned int align ) { return n / align * align; }
     283        long int floor( long int n, long int align ) { return n / align * align; }
     284        unsigned long int floor( unsigned long int n, unsigned long int align ) { return n / align * align; }
     285        long long int floor( long long int n, long long int align ) { return n / align * align; }
     286        unsigned long long int floor( unsigned long long int n, unsigned long long int align ) { return n / align * align; }
     287
     288        // forall( otype T | { T ?/?( T, T ); T ?*?( T, T ); } )
     289        // T floor( T n, T align ) { return n / align * align; }
     290
     291        signed char ceiling_div( signed char n, char align ) { return (n + (align - 1)) / align; }
     292        unsigned char ceiling_div( unsigned char n, unsigned char align ) { return (n + (align - 1)) / align; }
     293        short int ceiling_div( short int n, short int align ) { return (n + (align - 1)) / align; }
     294        unsigned short int ceiling_div( unsigned short int n, unsigned short int align ) { return (n + (align - 1)) / align; }
     295        int ceiling_div( int n, int align ) { return (n + (align - 1)) / align; }
     296        unsigned int ceiling_div( unsigned int n, unsigned int align ) { return (n + (align - 1)) / align; }
     297        long int ceiling_div( long int n, long int align ) { return (n + (align - 1)) / align; }
     298        unsigned long int ceiling_div( unsigned long int n, unsigned long int align ) { return (n + (align - 1)) / align; }
     299        long long int ceiling_div( long long int n, long long int align ) { return (n + (align - 1)) / align; }
     300        unsigned long long int ceiling_div( unsigned long long int n, unsigned long long int align ) { return (n + (align - 1)) / align; }
     301
     302        // forall( otype T | { T ?+?( T, T ); T ?-?( T, T ); T ?%?( T, T ); } )
     303        // T ceiling_div( T n, T align ) { verify( is_pow2( align ) );return (n + (align - 1)) / align; }
     304       
     305        // gcc notices the div/mod pair and saves both so only one div.
     306        signed char ceiling( signed char n, signed char align ) { return floor( n + (n % align != 0 ? align - 1 : 0), align ); }
     307        unsigned char ceiling( unsigned char n, unsigned char align ) { return floor( n + (n % align != 0 ? align - 1 : 0), align ); }
     308        short int ceiling( short int n, short int align ) { return floor( n + (n % align != 0 ? align - 1 : 0), align ); }
     309        unsigned short int ceiling( unsigned short int n, unsigned short int align ) { return floor( n + (n % align != 0 ? align - 1 : 0), align ); }
     310        int ceiling( int n, int align ) { return floor( n + (n % align != 0 ? align - 1 : 0), align ); }
     311        unsigned int ceiling( unsigned int n, unsigned int align ) { return floor( n + (n % align != 0 ? align - 1 : 0), align ); }
     312        long int ceiling( long int n, long int align ) { return floor( n + (n % align != 0 ? align - 1 : 0), align ); }
     313        unsigned long int ceiling( unsigned long int n, unsigned long int align ) { return floor( n + (n % align != 0 ? align - 1 : 0) , align); }
     314        long long int ceiling( long long int n, long long int align ) { return floor( n + (n % align != 0 ? align - 1 : 0), align ); }
     315        unsigned long long int ceiling( unsigned long long int n, unsigned long long int align ) { return floor( n + (n % align != 0 ? align - 1 : 0), align ); }
     316
     317        // forall( otype T | { void ?{}( T &, one_t ); T ?+?( T, T ); T ?-?( T, T ); T ?/?( T, T ); } )
     318        // T ceiling( T n, T align ) { return return floor( n + (n % align != 0 ? align - 1 : 0), align ); *}
     319
     320        float floor( float x ) { return floorf( x ); }
     321        // extern "C" { double floor( double ); }
     322        long double floor( long double x ) { return floorl( x ); }
     323
     324        float ceil( float x ) { return ceilf( x ); }
     325        // extern "C" { double ceil( double ); }
     326        long double ceil( long double x ) { return ceill( x ); }
     327
     328        float trunc( float x ) { return truncf( x ); }
     329        // extern "C" { double trunc( double ); }
     330        long double trunc( long double x ) { return truncl( x ); }
     331
     332        float rint( float x ) { return rintf( x ); }
     333        // extern "C" { double rint( double x ); }
     334        long double rint( long double x ) { return rintl( x ); }
     335        long int rint( float x ) { return lrintf( x ); }
     336        long int rint( double x ) { return lrint( x ); }
     337        long int rint( long double x ) { return lrintl( x ); }
     338        long long int rint( float x ) { return llrintf( x ); }
     339        long long int rint( double x ) { return llrint( x ); }
     340        long long int rint( long double x ) { return llrintl( x ); }
     341
     342        long int lrint( float x ) { return lrintf( x ); }
     343        // extern "C" { long int lrint( double ); }
     344        long int lrint( long double x ) { return lrintl( x ); }
     345        long long int llrint( float x ) { return llrintf( x ); }
     346        // extern "C" { long long int llrint( double ); }
     347        long long int llrint( long double x ) { return llrintl( x ); }
     348
     349        float nearbyint( float x ) { return nearbyintf( x ); }
     350        // extern "C" { double nearbyint( double ); }
     351        long double nearbyint( long double x ) { return nearbyintl( x ); }
     352
     353        float round( float x ) { return roundf( x ); }
     354        // extern "C" { double round( double x ); }
     355        long double round( long double x ) { return roundl( x ); }
     356        long int round( float x ) { return lroundf( x ); }
     357        long int round( double x ) { return lround( x ); }
     358        long int round( long double x ) { return lroundl( x ); }
     359        long long int round( float x ) { return llroundf( x ); }
     360        long long int round( double x ) { return llround( x ); }
     361        long long int round( long double x ) { return llroundl( x ); }
     362
     363        long int lround( float x ) { return lroundf( x ); }
     364        // extern "C" { long int lround( double ); }
     365        long int lround( long double x ) { return lroundl( x ); }
     366        long long int llround( float x ) { return llroundf( x ); }
     367        // extern "C" { long long int llround( double ); }
     368        long long int llround( long double x ) { return llroundl( x ); }
     369} // distribution
    309370
    310371//---------------------- Manipulation ----------------------
    311372
    312 static inline float copysign( float x, float y ) { return copysignf( x, y ); }
    313 // extern "C" { double copysign( double, double ); }
    314 static inline long double copysign( long double x, long double y ) { return copysignl( x, y ); }
    315 
    316 static inline float frexp( float x, int * ip ) { return frexpf( x, ip ); }
    317 // extern "C" { double frexp( double, int * ); }
    318 static inline long double frexp( long double x, int * ip ) { return frexpl( x, ip ); }
    319 
    320 static inline float ldexp( float x, int exp2 ) { return ldexpf( x, exp2 ); }
    321 // extern "C" { double ldexp( double, int ); }
    322 static inline long double ldexp( long double x, int exp2 ) { return ldexpl( x, exp2 ); }
    323 
    324 static inline [ float, float ] modf( float x ) { float i; x = modff( x, &i ); return [ i, x ]; }
    325 static inline float modf( float x, float * i ) { return modff( x, i ); }
    326 static inline [ double, double ] modf( double x ) { double i; x = modf( x, &i ); return [ i, x ]; }
    327 // extern "C" { double modf( double, double * ); }
    328 static inline [ long double, long double ] modf( long double x ) { long double i; x = modfl( x, &i ); return [ i, x ]; }
    329 static inline long double modf( long double x, long double * i ) { return modfl( x, i ); }
    330 
    331 static inline float nextafter( float x, float y ) { return nextafterf( x, y ); }
    332 // extern "C" { double nextafter( double, double ); }
    333 static inline long double nextafter( long double x, long double y ) { return nextafterl( x, y ); }
    334 
    335 static inline float nexttoward( float x, long double y ) { return nexttowardf( x, y ); }
    336 // extern "C" { double nexttoward( double, long double ); }
    337 static inline long double nexttoward( long double x, long double y ) { return nexttowardl( x, y ); }
    338 
    339 static inline float scalbn( float x, int exp ) { return scalbnf( x, exp ); }
    340 // extern "C" { double scalbn( double, int ); }
    341 static inline long double scalbn( long double x, int exp ) { return scalbnl( x, exp ); }
    342 static inline float scalbn( float x, long int exp ) { return scalblnf( x, exp ); }
    343 static inline double scalbn( double x, long int exp ) { return scalbln( x, exp ); }
    344 static inline long double scalbn( long double x, long int exp ) { return scalblnl( x, exp ); }
    345 
    346 static inline float scalbln( float x, long int exp ) { return scalblnf( x, exp ); }
    347 // extern "C" { double scalbln( double, long int ); }
    348 static inline long double scalbln( long double x, long int exp ) { return scalblnl( x, exp ); }
     373static inline {
     374        float copysign( float x, float y ) { return copysignf( x, y ); }
     375        // extern "C" { double copysign( double, double ); }
     376        long double copysign( long double x, long double y ) { return copysignl( x, y ); }
     377
     378        float frexp( float x, int * ip ) { return frexpf( x, ip ); }
     379        // extern "C" { double frexp( double, int * ); }
     380        long double frexp( long double x, int * ip ) { return frexpl( x, ip ); }
     381
     382        float ldexp( float x, int exp2 ) { return ldexpf( x, exp2 ); }
     383        // extern "C" { double ldexp( double, int ); }
     384        long double ldexp( long double x, int exp2 ) { return ldexpl( x, exp2 ); }
     385
     386        [ float, float ] modf( float x ) { float i; x = modff( x, &i ); return [ i, x ]; }
     387        float modf( float x, float * i ) { return modff( x, i ); }
     388        [ double, double ] modf( double x ) { double i; x = modf( x, &i ); return [ i, x ]; }
     389        // extern "C" { double modf( double, double * ); }
     390        [ long double, long double ] modf( long double x ) { long double i; x = modfl( x, &i ); return [ i, x ]; }
     391        long double modf( long double x, long double * i ) { return modfl( x, i ); }
     392
     393        float nextafter( float x, float y ) { return nextafterf( x, y ); }
     394        // extern "C" { double nextafter( double, double ); }
     395        long double nextafter( long double x, long double y ) { return nextafterl( x, y ); }
     396
     397        float nexttoward( float x, long double y ) { return nexttowardf( x, y ); }
     398        // extern "C" { double nexttoward( double, long double ); }
     399        long double nexttoward( long double x, long double y ) { return nexttowardl( x, y ); }
     400
     401        float scalbn( float x, int exp ) { return scalbnf( x, exp ); }
     402        // extern "C" { double scalbn( double, int ); }
     403        long double scalbn( long double x, int exp ) { return scalbnl( x, exp ); }
     404        float scalbn( float x, long int exp ) { return scalblnf( x, exp ); }
     405        double scalbn( double x, long int exp ) { return scalbln( x, exp ); }
     406        long double scalbn( long double x, long int exp ) { return scalblnl( x, exp ); }
     407
     408        float scalbln( float x, long int exp ) { return scalblnf( x, exp ); }
     409        // extern "C" { double scalbln( double, long int ); }
     410        long double scalbln( long double x, long int exp ) { return scalblnl( x, exp ); }
     411} // distribution
    349412
    350413//---------------------------------------
    351414
    352 #include "common.hfa"
    353 
    354 //---------------------------------------
    355 
    356 forall( otype T | { void ?{}( T &, one_t ); T ?+?( T, T ); T ?-?( T, T );T ?*?( T, T ); } )
    357 T lerp( T x, T y, T a ) { return x * ((T){1} - a) + y * a; }
    358 
    359 forall( otype T | { void ?{}( T &, zero_t ); void ?{}( T &, one_t ); int ?<?( T, T ); } )
    360 T step( T edge, T x ) { return x < edge ? (T){0} : (T){1}; }
    361 
    362 forall( otype T | { void ?{}( T &, int ); T clamp( T, T, T ); T ?-?( T, T ); T ?*?( T, T ); T ?/?( T, T ); } )
    363 T smoothstep( T edge0, T edge1, T x ) { T t = clamp( (x - edge0) / (edge1 - edge0), (T){0}, (T){1} ); return t * t * ((T){3} - (T){2} * t); }
     415static inline {
     416        forall( otype T | { void ?{}( T &, one_t ); T ?+?( T, T ); T ?-?( T, T );T ?*?( T, T ); } )
     417        T lerp( T x, T y, T a ) { return x * ((T){1} - a) + y * a; }
     418
     419        forall( otype T | { void ?{}( T &, zero_t ); void ?{}( T &, one_t ); int ?<?( T, T ); } )
     420        T step( T edge, T x ) { return x < edge ? (T){0} : (T){1}; }
     421
     422        forall( otype T | { void ?{}( T &, int ); T clamp( T, T, T ); T ?-?( T, T ); T ?*?( T, T ); T ?/?( T, T ); } )
     423        T smoothstep( T edge0, T edge1, T x ) { T t = clamp( (x - edge0) / (edge1 - edge0), (T){0}, (T){1} ); return t * t * ((T){3} - (T){2} * t); }
     424} // distribution
    364425
    365426// Local Variables: //
  • libcfa/src/stdlib.hfa

    rb7fe2e6 r856dff8  
    114114} // distribution
    115115
     116/*
     117        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.
     118        Or, just follow the instructions below for that.
     119
     120        1. Replace the current forall-block that contains defintions of S_fill and S_realloc with following:
     121                forall( dtype T | sized(T) ) {
     122                        union  U_fill           { char c; T * a; T t; };
     123                        struct S_fill           { char tag; char c; size_t size; T * at; char t[50]; };
     124                        struct S_realloc        { inline T *; };
     125                }
     126
     127        2. Replace all current postfix-fill functions with following for updated S_fill:
     128                S_fill(T) ?`fill( char a )                                      { S_fill(T) ret = {'c'}; ret.fill.c = a; return ret; }
     129                S_fill(T) ?`fill( T    a )                                      { S_fill(T) ret = {'t'}; memcpy(&ret.fill.t, &a, sizeof(T)); return ret; }
     130                S_fill(T) ?`fill( T    a[], size_t nmemb )      { S_fill(T) ret = {'a', nmemb}; ret.fill.a = a; return ret; }
     131
     132        3. Replace the $alloc_internal function which is outside ttype forall-block with following function:
     133                T * $alloc_internal( void * Resize, T * Realloc, size_t Align, size_t Dim, S_fill(T) Fill) {
     134                        T * ptr = NULL;
     135                        size_t size = sizeof(T);
     136                        size_t copy_end = 0;
     137
     138                        if(Resize) {
     139                                ptr = (T*) (void *) resize( (int *)Resize, Align, Dim * size );
     140                        } else if (Realloc) {
     141                                if (Fill.tag != '0') copy_end = min(malloc_size( Realloc ), Dim * size);
     142                                ptr = (T*) (void *) realloc( (int *)Realloc, Align, Dim * size );
     143                        } else {
     144                                ptr = (T*) (void *) memalign( Align, Dim * size );
     145                        }
     146
     147                        if(Fill.tag == 'c') {
     148                                memset( (char *)ptr + copy_end, (int)Fill.fill.c, Dim * size - copy_end );
     149                        } else if(Fill.tag == 't') {
     150                                for ( int i = copy_end; i <= Dim * size - size ; i += size ) {
     151                                        memcpy( (char *)ptr + i, &Fill.fill.t, size );
     152                                }
     153                        } else if(Fill.tag == 'a') {
     154                                memcpy( (char *)ptr + copy_end, Fill.fill.a, min(Dim * size - copy_end, size * Fill.nmemb) );
     155                        }
     156
     157                        return ptr;
     158                } // $alloc_internal
     159*/
     160
     161typedef struct S_align                  { inline size_t;  } T_align;
     162typedef struct S_resize                 { inline void *;  }     T_resize;
     163
     164forall( dtype T ) {
     165        struct S_fill           { char tag; char c; size_t size; T * at; char t[50]; };
     166        struct S_realloc        { inline T *; };
     167}
     168
     169static inline T_align   ?`align   ( size_t a )  { return (T_align){a}; }
     170static inline T_resize  ?`resize  ( void * a )  { return (T_resize){a}; }
    116171static inline forall( dtype T | sized(T) ) {
    117         // Cforall safe general allocation, fill, resize, array
    118 
    119         T * alloc( void ) {
    120                 return malloc();
    121         } // alloc
    122 
    123         T * alloc( size_t dim ) {
    124                 return aalloc( dim );
    125         } // alloc
    126 
    127         forall( dtype S | sized(S) )
    128         T * alloc( S ptr[], size_t dim = 1 ) {                          // singleton/array resize
    129                 return resize( (T *)ptr, dim * sizeof(T) );             // CFA resize
    130         } // alloc
    131 
    132         T * alloc( T ptr[], size_t dim = 1, bool copy = true ) {
    133                 if ( copy ) {
    134                         return realloc( ptr, dim * sizeof(T) );         // CFA realloc
     172
     173        S_fill(T) ?`fill ( T t ) {
     174                S_fill(T) ret = { 't' };
     175                size_t size = sizeof(T);
     176                if(size > sizeof(ret.t)) { printf("ERROR: const object of size greater than 50 bytes given for dynamic memory fill\n"); exit(1); }
     177                memcpy( &ret.t, &t, size );
     178                return ret;
     179        }
     180        S_fill(T)               ?`fill ( char c )                               { return (S_fill(T)){ 'c', c }; }
     181        S_fill(T)               ?`fill ( T * a )                                { return (S_fill(T)){ 'T', '0', 0, a }; }
     182        S_fill(T)               ?`fill ( T a[], size_t nmemb )  { return (S_fill(T)){ 'a', '0', nmemb * sizeof(T), a }; }
     183
     184        S_realloc(T)    ?`realloc ( T * a )                             { return (S_realloc(T)){a}; }
     185
     186        T * $alloc_internal( void * Resize, T * Realloc, size_t Align, size_t Dim, S_fill(T) Fill) {
     187                T * ptr = NULL;
     188                size_t size = sizeof(T);
     189                size_t copy_end = 0;
     190
     191                if(Resize) {
     192                        ptr = (T*) (void *) resize( (int *)Resize, Align, Dim * size );
     193                } else if (Realloc) {
     194                        if (Fill.tag != '0') copy_end = min(malloc_size( Realloc ), Dim * size);
     195                        ptr = (T*) (void *) realloc( (int *)Realloc, Align, Dim * size );
    135196                } else {
    136                         return resize( ptr, dim * sizeof(T) );          // CFA resize
    137                 } // if
    138         } // alloc
    139 
    140         T * alloc_set( char fill ) {
    141                 return (T *)memset( (T *)alloc(), (int)fill, sizeof(T) ); // initialize with fill value
    142         } // alloc_set
    143 
    144         T * alloc_set( const T & fill ) {
    145                 return (T *)memcpy( (T *)alloc(), &fill, sizeof(T) ); // initialize with fill value
    146         } // alloc_set
    147 
    148         T * alloc_set( size_t dim, char fill ) {
    149                 return (T *)memset( (T *)alloc( dim ), (int)fill, dim * sizeof(T) ); // initialize with fill value
    150         } // alloc_set
    151 
    152         T * alloc_set( size_t dim, const T & fill ) {
    153                 T * r = (T *)alloc( dim );
    154                 for ( i; dim ) { memcpy( &r[i], &fill, sizeof(T) ); } // initialize with fill value
    155                 return r;
    156         } // alloc_set
    157 
    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
    160         } // alloc_set
    161 
    162         T * alloc_set( T ptr[], size_t dim, char fill ) {       // realloc array with fill
    163                 size_t osize = malloc_size( ptr );                              // current allocation
    164                 size_t nsize = dim * sizeof(T);                                 // new allocation
    165                 T * nptr = realloc( ptr, nsize );                               // CFA realloc
    166                 if ( nsize > osize ) {                                                  // larger ?
    167                         memset( (char *)nptr + osize, (int)fill, nsize - osize ); // initialize added storage
    168                 } // if
    169                 return nptr;
    170         } // alloc_set
    171 
    172         T * alloc_set( T ptr[], size_t dim, const T & fill ) {  // realloc array with fill
    173                 size_t odim = malloc_size( ptr ) / sizeof(T);   // current dimension
    174                 size_t nsize = dim * sizeof(T);                                 // new allocation
    175                 size_t ndim = nsize / sizeof(T);                                // new dimension
    176                 T * nptr = realloc( ptr, nsize );                               // CFA realloc
    177                 if ( ndim > odim ) {                                                    // larger ?
    178                         for ( i; odim ~ ndim ) {
    179                                 memcpy( &nptr[i], &fill, sizeof(T) );   // initialize with fill value
    180                         } // for
    181                 } // if
    182                 return nptr;
    183         } // alloc_set
    184 } // distribution
    185 
    186 static inline forall( dtype T | sized(T) ) {
    187         T * alloc_align( size_t align ) {
    188                 return (T *)memalign( align, sizeof(T) );
    189         } // alloc_align
    190 
    191         T * alloc_align( size_t align, size_t dim ) {
    192                 return (T *)memalign( align, dim * sizeof(T) );
    193         } // alloc_align
    194 
    195         T * alloc_align( T * ptr, size_t align ) {                      // aligned realloc array
    196                 return (T *)(void *)realloc( (void *)ptr, align, sizeof(T) ); // CFA C realloc
    197         } // alloc_align
    198 
    199         forall( dtype S | sized(S) )
    200         T * alloc_align( S ptr[], size_t align ) {                      // aligned reuse array
    201                 return (T *)(void *)resize( (void *)ptr, align, sizeof(T) ); // CFA realloc
    202         } // alloc_align
    203 
    204         T * alloc_align( T ptr[], size_t align, size_t dim ) { // aligned realloc array
    205                 return (T *)(void *)realloc( (void *)ptr, align, dim * sizeof(T) ); // CFA realloc
    206         } // alloc_align
    207 
    208         T * alloc_align_set( size_t align, char fill ) {
    209                 return (T *)memset( (T *)alloc_align( align ), (int)fill, sizeof(T) ); // initialize with fill value
    210         } // alloc_align_set
    211 
    212         T * alloc_align_set( size_t align, const T & fill ) {
    213                 return (T *)memcpy( (T *)alloc_align( align ), &fill, sizeof(T) ); // initialize with fill value
    214         } // alloc_align_set
    215 
    216         T * alloc_align_set( size_t align, size_t dim, char fill ) {
    217                 return (T *)memset( (T *)alloc_align( align, dim ), (int)fill, dim * sizeof(T) ); // initialize with fill value
    218         } // alloc_align_set
    219 
    220         T * alloc_align_set( size_t align, size_t dim, const T & fill ) {
    221                 T * r = (T *)alloc_align( align, dim );
    222                 for ( i; dim ) { memcpy( &r[i], &fill, sizeof(T) ); } // initialize with fill value
    223                 return r;
    224         } // alloc_align_set
    225 
    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) );
    228         } // alloc_align_set
    229 
    230         T * alloc_align_set( T ptr[], size_t align, size_t dim, char fill ) {
    231                 size_t osize = malloc_size( ptr );                              // current allocation
    232                 size_t nsize = dim * sizeof(T);                                 // new allocation
    233                 T * nptr = alloc_align( ptr, align, nsize );
    234                 if ( nsize > osize ) {                                                  // larger ?
    235                         memset( (char *)nptr + osize, (int)fill, nsize - osize ); // initialize added storage
    236                 } // if
    237                 return nptr;
    238         } // alloc_align_set
    239 
    240         T * alloc_align_set( T ptr[], size_t align, size_t dim, const T & fill ) {
    241                 size_t odim = malloc_size( ptr ) / sizeof(T);   // current dimension
    242                 size_t nsize = dim * sizeof(T);                                 // new allocation
    243                 size_t ndim = nsize / sizeof(T);                                // new dimension
    244                 T * nptr = alloc_align( ptr, align, nsize );
    245                 if ( ndim > odim ) {                                                    // larger ?
    246                         for ( i; odim ~ ndim ) {
    247                                 memcpy( &nptr[i], &fill, sizeof(T) );   // initialize with fill value
    248                         } // for
    249                 } // if
    250                 return nptr;
    251         } // alloc_align_set
    252 } // distribution
     197                        ptr = (T*) (void *) memalign( Align, Dim * size );
     198                }
     199
     200                if(Fill.tag == 'c') {
     201                        memset( (char *)ptr + copy_end, (int)Fill.c, Dim * size - copy_end );
     202                } else if(Fill.tag == 't') {
     203                        for ( int i = copy_end; i <= Dim * size - size ; i += size ) {
     204                                memcpy( (char *)ptr + i, &Fill.t, size );
     205                        }
     206                } else if(Fill.tag == 'a') {
     207                        memcpy( (char *)ptr + copy_end, Fill.at, min(Dim * size - copy_end, Fill.size) );
     208                } else if(Fill.tag == 'T') {
     209                        for ( int i = copy_end; i <= Dim * size - size ; i += size ) {
     210                                memcpy( (char *)ptr + i, Fill.at, size );
     211                        }
     212                }
     213
     214                return ptr;
     215        } // $alloc_internal
     216
     217        forall( ttype TT | { T * $alloc_internal( void *, T *, size_t, size_t, S_fill(T), TT ); } ) {
     218
     219                T * $alloc_internal( void *       , T * Realloc, size_t Align, size_t Dim, S_fill(T) Fill, T_resize Resize, TT rest) {
     220                return $alloc_internal( Resize, (T*)0p, Align, Dim, Fill, rest);
     221                }
     222
     223                T * $alloc_internal( void * Resize, T *        , size_t Align, size_t Dim, S_fill(T) Fill, S_realloc(T) Realloc, TT rest) {
     224                return $alloc_internal( (void*)0p, Realloc, Align, Dim, Fill, rest);
     225                }
     226
     227                T * $alloc_internal( void * Resize, T * Realloc, size_t      , size_t Dim, S_fill(T) Fill, T_align Align, TT rest) {
     228                return $alloc_internal( Resize, Realloc, Align, Dim, Fill, rest);
     229                }
     230
     231                T * $alloc_internal( void * Resize, T * Realloc, size_t Align, size_t Dim, S_fill(T)     , S_fill(T) Fill, TT rest) {
     232                return $alloc_internal( Resize, Realloc, Align, Dim, Fill, rest);
     233                }
     234
     235            T * alloc( TT all ) {
     236                return $alloc_internal( (void*)0p, (T*)0p, (_Alignof(T) > libAlign() ? _Alignof(T) : libAlign()), (size_t)1, (S_fill(T)){'0'}, all);
     237            }
     238
     239            T * alloc( size_t dim, TT all ) {
     240                return $alloc_internal( (void*)0p, (T*)0p, (_Alignof(T) > libAlign() ? _Alignof(T) : libAlign()), dim, (S_fill(T)){'0'}, all);
     241            }
     242
     243        } // distribution TT
     244
     245} // distribution T
    253246
    254247static inline forall( dtype T | sized(T) ) {
Note: See TracChangeset for help on using the changeset viewer.