Ignore:
Timestamp:
Dec 20, 2025, 4:52:54 AM (29 hours ago)
Author:
Michael Brooks <mlbrooks@…>
Branches:
master
Parents:
0210a543
Message:

Improve libcfa-array's bound-check removal and write that thesis section.

The libcfa change adds a more performant alternative for a subset of multidimensional indexing cases that were already functionally correct.
That the new alternative is more performant is not shown in the test suite.
There is an associated new high-performance option for passing an array-or-slice to a function.
The added test cases cover those options.

The added in-thesis demos rely on the new more-performant alternative for multidimensional indexing.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • tests/array-collections/array-md-sbscr-cases.cfa

    r0210a543 reb0d9b7  
    231231}
    232232
     233// common function body, working on parameter wxyz, but for wxyz being different types
     234#define CHECK_NUM_SUBSCR_TYPE_COMPAT                                         \
     235    valExpected = getMagicNumber(2, 3, 4, 5);                                \
     236    assert(( wxyz[2] [3] [4] [5] == valExpected ));                          \
     237    assert(( wxyz[2,  3] [4] [5] == valExpected ));                          \
     238    assert(( wxyz[2] [3,  4] [5] == valExpected ));                          \
     239    assert(( wxyz[2] [3] [4,  5] == valExpected ));                          \
     240    assert(( wxyz[2,  3,  4] [5] == valExpected ));                          \
     241    assert(( wxyz[2] [3,  4,  5] == valExpected ));                          \
     242    assert(( wxyz[2,  3,  4,  5] == valExpected ));                          \
     243    for ( i; Nw ) {                                                          \
     244        assert(( wxyz[ i, 3, 4, 5 ] == getMagicNumber(i, 3, 4, 5) ));        \
     245    }                                                                        \
     246    for ( i; Nx ) {                                                          \
     247        assert(( wxyz[ 2, i, 4, 5 ] == getMagicNumber(2, i, 4, 5) ));        \
     248    }                                                                        \
     249    for ( i; Ny ) {                                                          \
     250        assert(( wxyz[ 2, 3, i, 5 ] == getMagicNumber(2, 3, i, 5) ));        \
     251    }                                                                        \
     252    for ( i; Nz ) {                                                          \
     253        assert(( wxyz[ 2, 3, 4, i ] == getMagicNumber(2, 3, 4, i) ));        \
     254    }
     255#define CHECK_NUM_SUBSCR_TYPE_COMPAT_ADDENDUM_RESHAPE                        \
     256    for ( i; Nw ) {                                                          \
     257        assert(( wxyz[ i, all, 4, 5 ][3] == getMagicNumber(i, 3, 4, 5) ));   \
     258    }                                                                        \
     259    for ( i; Nw ) {                                                          \
     260        assert(( wxyz[ all, 3, 4, 5 ][i] == getMagicNumber(i, 3, 4, 5) ));   \
     261    }
     262
     263// Low abstraction: simple declaration, cannot send a slice, can make a slice, runs fast
     264forall( [Nw], [Nx], [Ny], [Nz] )
     265void test_numSubscrTypeCompatibility_lo( array( float, Nw, Nx, Ny, Nz ) & wxyz ) {
     266    CHECK_NUM_SUBSCR_TYPE_COMPAT
     267    CHECK_NUM_SUBSCR_TYPE_COMPAT_ADDENDUM_RESHAPE
     268}
     269
     270// Medium abstraction: complex declaration, can send or make a slice, runs fast
     271forall( [Nw], Sw*
     272      , [Nx], Sx*
     273      , [Ny], Sy*
     274      , [Nz], Sz* )
     275void test_numSubscrTypeCompatibility_mid(
     276        arpk( Nw, Sw,
     277        arpk( Nx, Sx,
     278        arpk( Ny, Sy,
     279        arpk( Nz, Sz, float, float)
     280                           , float)
     281                           , float)
     282                           , float) & wxyz
     283    ) {
     284    CHECK_NUM_SUBSCR_TYPE_COMPAT
     285    CHECK_NUM_SUBSCR_TYPE_COMPAT_ADDENDUM_RESHAPE
     286}
     287
     288// High abstraction: mid-complexity declaration, can send a slice or a non-arpk, cannot make a slice, may not run fast
     289forall( [Nw], Awxyz &
     290      , [Nx], Axyz &
     291      , [Ny], Ayz &
     292      , [Nz], Az &
     293      | ar( Awxyz, Axyz, Nw )
     294      | ar( Axyz, Ayz, Nx )
     295      | ar( Ayz, Az, Ny )
     296      | ar( Az, float, Nz ) )
     297void test_numSubscrTypeCompatibility_hi( Awxyz & wxyz ) {
     298    CHECK_NUM_SUBSCR_TYPE_COMPAT
     299}
     300
    233301forall( [Nw], [Nx], [Ny], [Nz] )
    234302void test_numSubscrTypeCompatibility( tag(Nw), tag(Nx), tag(Ny), tag(Nz) ) {
     
    237305    fillHelloData(wxyz);
    238306
    239     valExpected = getMagicNumber(2, 3, 4, 5);
    240     assert(( wxyz [2] [3] [4] [5]  == valExpected ));
    241     assert(( wxyz[2,  3][4] [5]  == valExpected ));
    242     assert(( wxyz [2][3,  4][5]  == valExpected ));
    243     assert(( wxyz [2] [3][4,  5] == valExpected ));
    244     assert(( wxyz[2,  3,  4][5]  == valExpected ));
    245     assert(( wxyz [2][3,  4,  5] == valExpected ));
    246     assert(( wxyz[2,  3,  4,  5] == valExpected ));
    247 
    248     for ( i; Nw ) {
    249         assert(( wxyz[ i, 3, 4, 5 ] == getMagicNumber(i, 3, 4, 5) ));
    250     }
    251 
    252     for ( i; Nx ) {
    253         assert(( wxyz[ 2, i, 4, 5 ] == getMagicNumber(2, i, 4, 5) ));
    254     }
    255 
    256     for ( i; Ny ) {
    257         assert(( wxyz[ 2, 3, i, 5 ] == getMagicNumber(2, 3, i, 5) ));
    258     }
    259 
    260     for ( i; Nz ) {
    261         assert(( wxyz[ 2, 3, 4, i ] == getMagicNumber(2, 3, 4, i) ));
    262     }
    263 
    264     for ( i; Nw ) {
    265         assert(( wxyz[ i, all, 4, 5 ][3] == getMagicNumber(i, 3, 4, 5) ));
    266     }
    267 
    268     for ( i; Nw ) {
    269         assert(( wxyz[ all, 3, 4, 5 ][i] == getMagicNumber(i, 3, 4, 5) ));
    270     }
     307    test_numSubscrTypeCompatibility_lo ( wxyz );
     308    test_numSubscrTypeCompatibility_mid( wxyz );
     309    test_numSubscrTypeCompatibility_hi ( wxyz );
    271310}
    272311
Note: See TracChangeset for help on using the changeset viewer.