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