- File:
-
- 1 edited
-
libcfa/src/containers/array.hfa (modified) (5 diffs)
Legend:
- Unmodified
- Added
- Removed
-
libcfa/src/containers/array.hfa
r9fa538c rb9dae14c 21 21 }; 22 22 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 ) { 42 24 return (Timmed &) a.strides[i]; 43 25 } 44 26 45 static inline Timmed & ?[?]( arpk(N, S, Timmed, Tbase) & a, unsignedint i ) {27 Timmed & ?[?]( arpk(N, S, Timmed, Tbase) & a, int i ) { 46 28 return (Timmed &) a.strides[i]; 47 29 } 48 30 49 static inline Timmed & ?[?]( arpk(N, S, Timmed, Tbase) & a, long int i ) {31 Timmed & ?[?]( arpk(N, S, Timmed, Tbase) & a, size_t i ) { 50 32 return (Timmed &) a.strides[i]; 51 33 } 52 34 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 ) { 58 36 return z(N); 59 37 } 60 38 61 39 // workaround #226 (and array relevance thereof demonstrated in mike102/otype-slow-ndims.cfa) 62 static inlinevoid ?{}( arpk(N, S, Timmed, Tbase) & this ) {40 void ?{}( arpk(N, S, Timmed, Tbase) & this ) { 63 41 void ?{}( S (&inner)[z(N)] ) {} 64 42 ?{}(this.strides); 65 43 } 66 static inlinevoid ^?{}( arpk(N, S, Timmed, Tbase) & this ) {44 void ^?{}( arpk(N, S, Timmed, Tbase) & this ) { 67 45 void ^?{}( S (&inner)[z(N)] ) {} 68 46 ^?{}(this.strides); … … 75 53 76 54 forall( Te ) 77 static inlineTe mkar_( tag(Te) ) {}55 Te mkar_( tag(Te) ) {} 78 56 79 57 forall( [N], ZTags ... , Trslt &, Tatom & | { Trslt mkar_( tag(Tatom), ZTags ); } ) 80 static inlinearpk(N, Trslt, Trslt, Tatom) mkar_( tag(Tatom), tag(N), ZTags ) {}58 arpk(N, Trslt, Trslt, Tatom) mkar_( tag(Tatom), tag(N), ZTags ) {} 81 59 82 60 // based on https://stackoverflow.com/questions/1872220/is-it-possible-to-iterate-over-arguments-in-variadic-macros … … 112 90 113 91 forall( TA &, TB &, TC &, IxAB, IxBC ... | { TB & ?[?]( TA &, IxAB ); TC & ?[?]( TB &, IxBC ); } ) 114 static inlineTC & ?[?]( TA & this, IxAB ab, IxBC bc ) {92 TC & ?[?]( TA & this, IxAB ab, IxBC bc ) { 115 93 return this[ab][bc]; 116 94 } … … 121 99 122 100 forall( TA &, TB &, TC &, IxAB_0, IxBC | { TB & ?[?]( TA &, IxAB_0 ); TC & ?[?]( TB &, IxBC ); } ) 123 static inlineTC & ?[?]( TA & this, IxAB_0 ab, IxBC bc ) {101 TC & ?[?]( TA & this, IxAB_0 ab, IxBC bc ) { 124 102 return this[ab][bc]; 125 103 } 126 104 127 105 forall( TA &, TB &, TC &, IxAB_0, IxAB_1, IxBC | { TB & ?[?]( TA &, IxAB_0, IxAB_1 ); TC & ?[?]( TB &, IxBC ); } ) 128 static inlineTC & ?[?]( TA & this, IxAB_0 ab0, IxAB_1 ab1, IxBC bc ) {106 TC & ?[?]( TA & this, IxAB_0 ab0, IxAB_1 ab1, IxBC bc ) { 129 107 return this[[ab0,ab1]][bc]; 130 108 } 131 109 132 110 forall( TA &, TB &, TC &, IxAB_0, IxAB_1, IxAB_2, IxBC | { TB & ?[?]( TA &, IxAB_0, IxAB_1, IxAB_2 ); TC & ?[?]( TB &, IxBC ); } ) 133 static inlineTC & ?[?]( TA & this, IxAB_0 ab0, IxAB_1 ab1, IxAB_2 ab2, IxBC bc ) {111 TC & ?[?]( TA & this, IxAB_0 ab0, IxAB_1 ab1, IxAB_2 ab2, IxBC bc ) { 134 112 return this[[ab0,ab1,ab2]][bc]; 135 113 } … … 143 121 // Base 144 122 forall( [Nq], [Sq], Tbase & ) 145 static inlinetag(arpk(Nq, Sq, Tbase, Tbase)) enq_( tag(Tbase), tag(Nq), tag(Sq), tag(Tbase) ) {}123 tag(arpk(Nq, Sq, Tbase, Tbase)) enq_( tag(Tbase), tag(Nq), tag(Sq), tag(Tbase) ) {} 146 124 147 125 // Rec 148 126 forall( [Nq], [Sq], [N], [S], recq &, recr &, Tbase & | { tag(recr) enq_( tag(Tbase), tag(Nq), tag(Sq), tag(recq) ); } ) 149 static inlinetag(arpk(N, S, recr, Tbase)) enq_( tag(Tbase), tag(Nq), tag(Sq), tag(arpk(N, S, recq, Tbase)) ) {}127 tag(arpk(N, S, recr, Tbase)) enq_( tag(Tbase), tag(Nq), tag(Sq), tag(arpk(N, S, recq, Tbase)) ) {} 150 128 151 129 // Wrapper 152 130 struct all_t {} all; 153 131 forall( [N], [S], Te &, result &, Tbase & | { tag(result) enq_( tag(Tbase), tag(N), tag(S), tag(Te) ); } ) 154 static inlineresult & ?[?]( arpk(N, S, Te, Tbase) & this, all_t ) {132 result & ?[?]( arpk(N, S, Te, Tbase) & this, all_t ) { 155 133 return (result&) this; 156 134 }
Note:
See TracChangeset
for help on using the changeset viewer.