Changes in / [ad89296:34b2796]
- Files:
-
- 2 deleted
- 4 edited
-
libcfa/src/containers/array.hfa (modified) (5 diffs)
-
src/Parser/DeclarationNode.cc (modified) (1 diff)
-
tests/array-container/.expect/array-basic.x64.txt (modified) (1 diff)
-
tests/array-container/.expect/array-md-sbscr-cases.x64.txt (deleted)
-
tests/array-container/array-basic.cfa (modified) (6 diffs)
-
tests/array-container/array-md-sbscr-cases.cfa (deleted)
Legend:
- Unmodified
- Added
- Removed
-
libcfa/src/containers/array.hfa
rad89296 r34b2796 5 5 6 6 // the inverse of Z(-) 7 #define z(N) sizeof(N) 7 #define z(Zn) sizeof(Zn) 8 9 // if you're expecting a Z(n), say so, by asking for a ztype, instead of dtype or otype 10 #define ztype(Zn) Zn & | sized(Zn) 8 11 9 12 forall( T & ) struct tag {}; … … 16 19 // 17 20 18 forall( [N], [S], Timmed &, Tbase & ) {21 forall( ztype(Zn), ztype(S), Timmed &, Tbase & ) { 19 22 struct arpk { 20 S strides[z( N)];23 S strides[z(Zn)]; 21 24 }; 22 25 23 Timmed & ?[?]( arpk( N, S, Timmed, Tbase) & a, ptrdiff_t i ) {26 Timmed & ?[?]( arpk(Zn, S, Timmed, Tbase) & a, ptrdiff_t i ) { 24 27 return (Timmed &) a.strides[i]; 25 28 } 26 29 27 Timmed & ?[?]( arpk(N, S, Timmed, Tbase) & a, int i ) { 28 return (Timmed &) a.strides[i]; 29 } 30 31 Timmed & ?[?]( arpk(N, S, Timmed, Tbase) & a, size_t i ) { 32 return (Timmed &) a.strides[i]; 33 } 34 35 size_t ?`len( arpk(N, S, Timmed, Tbase) & a ) { 36 return z(N); 30 size_t ?`len( arpk(Zn, S, Timmed, Tbase) & a ) { 31 return z(Zn); 37 32 } 38 33 39 34 // workaround #226 (and array relevance thereof demonstrated in mike102/otype-slow-ndims.cfa) 40 void ?{}( arpk( N, S, Timmed, Tbase) & this ) {41 void ?{}( S (&inner)[z( N)] ) {}35 void ?{}( arpk(Zn, S, Timmed, Tbase) & this ) { 36 void ?{}( S (&inner)[z(Zn)] ) {} 42 37 ?{}(this.strides); 43 38 } 44 void ^?{}( arpk( N, S, Timmed, Tbase) & this ) {45 void ^?{}( S (&inner)[z( N)] ) {}39 void ^?{}( arpk(Zn, S, Timmed, Tbase) & this ) { 40 void ^?{}( S (&inner)[z(Zn)] ) {} 46 41 ^?{}(this.strides); 47 42 } … … 55 50 Te mkar_( tag(Te) ) {} 56 51 57 forall( [N], ZTags ... , Trslt &, Tatom & | { Trslt mkar_( tag(Tatom), ZTags ); } )58 arpk( N, Trslt, Trslt, Tatom) mkar_( tag(Tatom), tag(N), ZTags ) {}52 forall( ztype(Zn), ZTags ... , Trslt &, Tatom & | { Trslt mkar_( tag(Tatom), ZTags ); } ) 53 arpk(Zn, Trslt, Trslt, Tatom) mkar_( tag(Tatom), tag(Zn), ZTags ) {} 59 54 60 55 // based on https://stackoverflow.com/questions/1872220/is-it-possible-to-iterate-over-arguments-in-variadic-macros … … 85 80 // Core -[[-,-,-]] operator 86 81 87 #ifdef TRY_BROKEN_DESIRED_MD_SUBSCRIPT 82 // Desired form. One definition with recursion on IxBC (worked until Jan 2021, see trac #__TODO__) 83 // forall( TA &, TB &, TC &, IxAB, IxBC ... | { TB & ?[?]( TA &, IxAB ); TC & ?[?]( TB &, IxBC ); } ) 84 // TC & ?[?]( TA & this, IxAB ab, IxBC bc ) { 85 // return this[ab][bc]; 86 // } 88 87 89 // Desired form. One definition with recursion on IxBC (worked until Jan 2021, see trac #__TODO__)90 91 forall( TA &, TB &, TC &, IxAB, IxBC ... | { TB & ?[?]( TA &, IxAB );TC & ?[?]( TB &, IxBC ); } )88 // Workaround form. Listing all possibilities up to 4 dims. 89 forall( TA &, TB &, IxAB | { TB & ?[?]( TA &, IxAB ); } 90 , TC &, IxBC | { TC & ?[?]( TB &, IxBC ); } ) 92 91 TC & ?[?]( TA & this, IxAB ab, IxBC bc ) { 93 92 return this[ab][bc]; 94 93 } 95 96 #else 97 98 // Workaround form. Listing all possibilities up to 4 dims. 99 100 forall( TA &, TB &, TC &, IxAB_0, IxBC | { TB & ?[?]( TA &, IxAB_0 ); TC & ?[?]( TB &, IxBC ); } ) 101 TC & ?[?]( TA & this, IxAB_0 ab, IxBC bc ) { 102 return this[ab][bc]; 94 forall( TA &, TB &, IxAB | { TB & ?[?]( TA &, IxAB ); } 95 , TC &, IxBC | { TC & ?[?]( TB &, IxBC ); } 96 , TD &, IxCD | { TD & ?[?]( TC &, IxCD ); } ) 97 TD & ?[?]( TA & this, IxAB ab, IxBC bc, IxCD cd ) { 98 return this[ab][bc][cd]; 99 } 100 forall( TA &, TB &, IxAB | { TB & ?[?]( TA &, IxAB ); } 101 , TC &, IxBC | { TC & ?[?]( TB &, IxBC ); } 102 , TD &, IxCD | { TD & ?[?]( TC &, IxCD ); } 103 , TE &, IxDE | { TE & ?[?]( TD &, IxDE ); } ) 104 TE & ?[?]( TA & this, IxAB ab, IxBC bc, IxCD cd, IxDE de ) { 105 return this[ab][bc][cd][de]; 103 106 } 104 107 105 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 ) { 107 return this[[ab0,ab1]][bc]; 108 // Adapters for "indexed by ptrdiff_t" implies "indexed by [this other integral type]" 109 // Work around restriction that assertions underlying -[[-,-,-]] must match excatly 110 forall( C &, E & | { E & ?[?]( C &, ptrdiff_t ); } ) { 111 112 // Targeted to support: for( i; z(N) ) ... a[[ ..., i, ... ]] 113 E & ?[?]( C & this, size_t i ) { 114 return this[ (ptrdiff_t) i ]; 115 } 116 117 // Targeted to support: for( i; 5 ) ... a[[ ..., i, ... ]] 118 E & ?[?]( C & this, int i ) { 119 return this[ (ptrdiff_t) i ]; 120 } 108 121 } 109 110 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 ) {112 return this[[ab0,ab1,ab2]][bc];113 }114 115 #endif116 122 117 123 // … … 120 126 121 127 // Base 122 forall( [Nq], [Sq], Tbase & )123 tag(arpk( Nq, Sq, Tbase, Tbase)) enq_( tag(Tbase), tag(Nq), tag(Sq), tag(Tbase) ) {}128 forall( ztype(Zq), ztype(Sq), Tbase & ) 129 tag(arpk(Zq, Sq, Tbase, Tbase)) enq_( tag(Tbase), tag(Zq), tag(Sq), tag(Tbase) ) {} 124 130 125 131 // Rec 126 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)) ) {}132 forall( ztype(Zq), ztype(Sq), ztype(Z), ztype(S), recq &, recr &, Tbase & | { tag(recr) enq_( tag(Tbase), tag(Zq), tag(Sq), tag(recq) ); } ) 133 tag(arpk(Z, S, recr, Tbase)) enq_( tag(Tbase), tag(Zq), tag(Sq), tag(arpk(Z, S, recq, Tbase)) ) {} 128 134 129 135 // Wrapper 130 136 struct all_t {} all; 131 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 ) {137 forall( ztype(Z), ztype(S), Te &, result &, Tbase & | { tag(result) enq_( tag(Tbase), tag(Z), tag(S), tag(Te) ); } ) 138 result & ?[?]( arpk(Z, S, Te, Tbase) & this, all_t ) { 133 139 return (result&) this; 134 140 } -
src/Parser/DeclarationNode.cc
rad89296 r34b2796 1076 1076 if ( variable.tyClass != TypeDecl::NUMBER_OF_KINDS ) { 1077 1077 // otype is internally converted to dtype + otype parameters 1078 static const TypeDecl::Kind kindMap[] = { TypeDecl::Dtype, TypeDecl::DStype, TypeDecl::Dtype, TypeDecl::Ftype, TypeDecl::Ttype, TypeDecl:: Dtype };1078 static const TypeDecl::Kind kindMap[] = { TypeDecl::Dtype, TypeDecl::DStype, TypeDecl::Dtype, TypeDecl::Ftype, TypeDecl::Ttype, TypeDecl::ALtype }; 1079 1079 static_assert( sizeof(kindMap) / sizeof(kindMap[0]) == TypeDecl::NUMBER_OF_KINDS, "DeclarationNode::build: kindMap is out of sync." ); 1080 1080 assertf( variable.tyClass < sizeof(kindMap)/sizeof(kindMap[0]), "Variable's tyClass is out of bounds." ); 1081 TypeDecl * ret = new TypeDecl( *name, Type::StorageClasses(), nullptr, kindMap[ variable.tyClass ], variable.tyClass == TypeDecl::Otype || variable.tyClass == TypeDecl::ALtype, variable.initializer ? variable.initializer->buildType() : nullptr );1081 TypeDecl * ret = new TypeDecl( *name, Type::StorageClasses(), nullptr, kindMap[ variable.tyClass ], variable.tyClass == TypeDecl::Otype, variable.initializer ? variable.initializer->buildType() : nullptr ); 1082 1082 buildList( variable.assertions, ret->get_assertions() ); 1083 1083 return ret; -
tests/array-container/.expect/array-basic.x64.txt
rad89296 r34b2796 1 1 expect Ws = 7.060606 2 2 result Ws [][][][] lo = 7.060606 3 result Ws [,,,] lo = 7.0606064 3 result Ws [][][][] hi = 7.060606 5 result Ws [,,,] hi = 7.0606066 4 expect Xs = 8.150808 7 5 result Xs [][][][] lo = 8.150808 8 result Xs [,,,] lo = 8.1508089 6 result Xs [][][][] hi = 8.150808 10 result Xs [,,,] hi = 8.150808 -
tests/array-container/array-basic.cfa
rad89296 r34b2796 5 5 // 6 6 7 forall( [Nx], [Ny], [Nz])7 forall( ztype(Nx), ztype(Ny), ztype(Nz) ) 8 8 void typesTest( tag(Nx), tag(Ny), tag(Nz) ) { 9 9 … … 59 59 } 60 60 61 forall( [Nw], [Nx], [Ny], [Nz])61 forall( ztype(Nw), ztype(Nx), ztype(Ny), ztype(Nz) ) 62 62 void fillHelloData( array( float, Nw, Nx, Ny, Nz ) & wxyz ) { 63 63 for (w; z(Nw)) … … 68 68 } 69 69 70 forall( [Zn]70 forall( ztype(Zn) 71 71 , S & | sized(S) 72 72 ) … … 86 86 } 87 87 88 forall( [Nw], [Nx], [Ny], [Nz])88 forall( ztype(Nw), ztype(Nx), ztype(Ny), ztype(Nz) ) 89 89 void runtimeTest( tag(Nw), tag(Nx), tag(Ny), tag(Nz) ) { 90 90 … … 105 105 printf("result Ws [][][][] lo = %f\n", result); 106 106 107 result = total1d_low( wxyz[[all, slice_ix, slice_ix, slice_ix]] ); 108 printf("result Ws [,,,] lo = %f\n", result); 107 // fixme: -[[-,-,-,-]] not working 108 // result = total1d_low( wxyz[[all, slice_ix, slice_ix, slice_ix]] ); 109 // printf("result Ws [,,,] lo = %f\n", result); 109 110 110 111 result = total1d_hi( wxyz[all][slice_ix][slice_ix][slice_ix] ); 111 112 printf("result Ws [][][][] hi = %f\n", result); 112 113 113 result = total1d_hi( wxyz[[all, slice_ix, slice_ix, slice_ix]] ); 114 printf("result Ws [,,,] hi = %f\n", result); 114 // fixme: -[[-,-,-,-]] not working 115 // result = total1d_hi( wxyz[[all, slice_ix, slice_ix, slice_ix]] ); 116 // printf("result Ws [,,,] hi = %f\n", result); 115 117 116 118 // summing across X, with w=y=z=1 … … 124 126 printf("result Xs [][][][] lo = %f\n", result); 125 127 126 result = total1d_low( wxyz[[slice_ix, all, slice_ix, slice_ix]] ); 127 printf("result Xs [,,,] lo = %f\n", result); 128 // fixme: -[[-,-,-,-]] not working 129 // result = total1d_low( wxyz[[slice_ix, all, slice_ix, slice_ix]] ); 130 // printf("result Xs [,,,] lo = %f\n", result); 128 131 129 132 result = total1d_hi( wxyz[slice_ix][all][slice_ix][slice_ix] ); 130 133 printf("result Xs [][][][] hi = %f\n", result); 131 134 132 result = total1d_hi( wxyz[[slice_ix, all, slice_ix, slice_ix]] ); 133 printf("result Xs [,,,] hi = %f\n", result); 135 // fixme: -[[-,-,-,-]] not working 136 // result = total1d_hi( wxyz[[slice_ix, all, slice_ix, slice_ix]] ); 137 // printf("result Xs [,,,] hi = %f\n", result); 134 138 135 139 }
Note:
See TracChangeset
for help on using the changeset viewer.