Ignore:
File:
1 edited

Legend:

Unmodified
Added
Removed
  • libcfa/src/containers/array.hfa

    r9fa538c rb9dae14c  
    2121    };
    2222
    23     // About the choice of integral types offered as subscript overloads:
    24     // Intent is to cover these use cases:
    25     //    float foo( ptrdiff_t i ) { return a[i]; }           // i : ptrdiff_t
    26     //    forall( [N] ) ... for( i; N ) { total += a[i]; }    // i : typeof( sizeof(42) )
    27     //    for( i; 5 ) { total += a[i]; }                      // i : int
    28     // It gets complicated by:
    29     // -  CFA does overloading on concrete types, like int and unsigned int, not on typedefed
    30     //    types like size_t.  So trying to overload on ptrdiff_t vs int works in 64-bit mode
    31     //    but not in 32-bit mode.
    32     // -  Given bug of Trac #247, CFA gives sizeof expressions type unsigned long int, when it
    33     //    should give them type size_t.
    34     //   
    35     //                          gcc -m32         cfa -m32 given bug         gcc -m64
    36     // ptrdiff_t                int              int                        long int
    37     // size_t                   unsigned int     unsigned int               unsigned long int
    38     // typeof( sizeof(42) )     unsigned int     unsigned long int          unsigned long int
    39     // int                      int              int                        int
    40 
    41     static inline Timmed & ?[?]( arpk(N, S, Timmed, Tbase) & a, int i ) {
     23    Timmed & ?[?]( arpk(N, S, Timmed, Tbase) & a, ptrdiff_t i ) {
    4224        return (Timmed &) a.strides[i];
    4325    }
    4426
    45     static inline Timmed & ?[?]( arpk(N, S, Timmed, Tbase) & a, unsigned int i ) {
     27    Timmed & ?[?]( arpk(N, S, Timmed, Tbase) & a, int i ) {
    4628        return (Timmed &) a.strides[i];
    4729    }
    4830
    49     static inline Timmed & ?[?]( arpk(N, S, Timmed, Tbase) & a, long int i ) {
     31    Timmed & ?[?]( arpk(N, S, Timmed, Tbase) & a, size_t i ) {
    5032        return (Timmed &) a.strides[i];
    5133    }
    5234
    53     static inline Timmed & ?[?]( arpk(N, S, Timmed, Tbase) & a, unsigned long int i ) {
    54         return (Timmed &) a.strides[i];
    55     }
    56 
    57     static inline size_t ?`len( arpk(N, S, Timmed, Tbase) & a ) {
     35    size_t ?`len( arpk(N, S, Timmed, Tbase) & a ) {
    5836        return z(N);
    5937    }
    6038
    6139    // workaround #226 (and array relevance thereof demonstrated in mike102/otype-slow-ndims.cfa)
    62     static inline void ?{}( arpk(N, S, Timmed, Tbase) & this ) {
     40    void ?{}( arpk(N, S, Timmed, Tbase) & this ) {
    6341        void ?{}( S (&inner)[z(N)] ) {}
    6442        ?{}(this.strides);
    6543    }
    66     static inline void ^?{}( arpk(N, S, Timmed, Tbase) & this ) {
     44    void ^?{}( arpk(N, S, Timmed, Tbase) & this ) {
    6745        void ^?{}( S (&inner)[z(N)] ) {}
    6846        ^?{}(this.strides);
     
    7553
    7654forall( Te )
    77 static inline Te mkar_( tag(Te) ) {}
     55Te mkar_( tag(Te) ) {}
    7856
    7957forall( [N], ZTags ... , Trslt &, Tatom & | { Trslt mkar_( tag(Tatom), ZTags ); } )
    80 static inline arpk(N, Trslt, Trslt, Tatom) mkar_( tag(Tatom), tag(N), ZTags ) {}
     58arpk(N, Trslt, Trslt, Tatom) mkar_( tag(Tatom), tag(N), ZTags ) {}
    8159
    8260// based on https://stackoverflow.com/questions/1872220/is-it-possible-to-iterate-over-arguments-in-variadic-macros
     
    11290
    11391forall( TA &, TB &, TC &, IxAB, IxBC ... | { TB & ?[?]( TA &, IxAB ); TC & ?[?]( TB &, IxBC ); } )
    114 static inline TC & ?[?]( TA & this, IxAB ab, IxBC bc ) {
     92TC & ?[?]( TA & this, IxAB ab, IxBC bc ) {
    11593    return this[ab][bc];
    11694}
     
    12199
    122100forall( TA &, TB &, TC &, IxAB_0, IxBC | { TB & ?[?]( TA &, IxAB_0 ); TC & ?[?]( TB &, IxBC ); } )
    123 static inline TC & ?[?]( TA & this, IxAB_0 ab, IxBC bc ) {
     101TC & ?[?]( TA & this, IxAB_0 ab, IxBC bc ) {
    124102    return this[ab][bc];
    125103}
    126104
    127105forall( TA &, TB &, TC &, IxAB_0, IxAB_1, IxBC | { TB & ?[?]( TA &, IxAB_0, IxAB_1 ); TC & ?[?]( TB &, IxBC ); } )
    128 static inline TC & ?[?]( TA & this, IxAB_0 ab0, IxAB_1 ab1, IxBC bc ) {
     106TC & ?[?]( TA & this, IxAB_0 ab0, IxAB_1 ab1, IxBC bc ) {
    129107    return this[[ab0,ab1]][bc];
    130108}
    131109
    132110forall( TA &, TB &, TC &, IxAB_0, IxAB_1, IxAB_2, IxBC | { TB & ?[?]( TA &, IxAB_0, IxAB_1, IxAB_2 ); TC & ?[?]( TB &, IxBC ); } )
    133 static inline TC & ?[?]( TA & this, IxAB_0 ab0, IxAB_1 ab1, IxAB_2 ab2, IxBC bc ) {
     111TC & ?[?]( TA & this, IxAB_0 ab0, IxAB_1 ab1, IxAB_2 ab2, IxBC bc ) {
    134112    return this[[ab0,ab1,ab2]][bc];
    135113}
     
    143121// Base
    144122forall( [Nq], [Sq], Tbase & )
    145 static inline tag(arpk(Nq, Sq, Tbase, Tbase)) enq_( tag(Tbase), tag(Nq), tag(Sq), tag(Tbase) ) {}
     123tag(arpk(Nq, Sq, Tbase, Tbase)) enq_( tag(Tbase), tag(Nq), tag(Sq), tag(Tbase) ) {}
    146124
    147125// Rec
    148126forall( [Nq], [Sq], [N], [S], recq &, recr &, Tbase & | { tag(recr) enq_( tag(Tbase), tag(Nq), tag(Sq), tag(recq) ); } )
    149 static inline tag(arpk(N, S, recr, Tbase)) enq_( tag(Tbase), tag(Nq), tag(Sq), tag(arpk(N, S, recq, Tbase)) ) {}
     127tag(arpk(N, S, recr, Tbase)) enq_( tag(Tbase), tag(Nq), tag(Sq), tag(arpk(N, S, recq, Tbase)) ) {}
    150128
    151129// Wrapper
    152130struct all_t {} all;
    153131forall( [N], [S], Te &, result &, Tbase & | { tag(result) enq_( tag(Tbase), tag(N), tag(S), tag(Te) ); } )
    154 static inline result & ?[?]( arpk(N, S, Te, Tbase) & this, all_t ) {
     132result & ?[?]( arpk(N, S, Te, Tbase) & this, all_t ) {
    155133    return (result&) this;
    156134}
Note: See TracChangeset for help on using the changeset viewer.