Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2026-04-09 07:48:54

0001 // name=f4_stack_test ; gcc $name.cc -I.. -I$OPTICKS_PREFIX/include/SysRap -I/usr/local/cuda/include  -o /tmp/$name  && /tmp/$name
0002 
0003 #include "stdio.h"
0004 #include "assert.h"
0005 
0006 #include "scuda.h"
0007 #include "f4_stack.h"
0008 
0009 void test_1( F4_Stack& s )
0010 {
0011     printf("//test_1\n"); 
0012 
0013     float a0, a1 ;
0014  
0015     for(int i=0 ; i < 10 ; i++)
0016     {
0017        a0 = float(i); 
0018        s.push(a0) ; 
0019        s.pop(a1); 
0020        printf("  a0 %10.4f a1 %10.4f \n", a0, a1 ); 
0021        assert( a0 == a1 ); 
0022     }
0023 
0024     assert( s.curr == -1 ); 
0025 }
0026 
0027 void test_2( F4_Stack& s, int mode )
0028 {
0029     printf("//test_2\n"); 
0030     float a0, b0 ; 
0031     float a1, b1 ;
0032  
0033     for(int i=0 ; i < 10 ; i++)
0034     {
0035        a0 = float(i); 
0036        b0 = float(10*i); 
0037 
0038        if( mode == 1 )
0039        {
0040            s.push(a0) ; 
0041            s.push(b0) ; 
0042 
0043            s.pop(b1);
0044            s.pop(a1);
0045        }
0046        else if( mode == 2)
0047        {
0048            s.push2(a0, b0); 
0049            s.pop2( a1, b1); 
0050        }
0051  
0052        printf("  mode %d a0 %10.4f b0 %10.4f b1 %10.4f a1 %10.4f  \n", mode, a0, b0, b1, a1 ); 
0053        assert( b1 == b0 );
0054        assert( a1 == a0 );
0055     }
0056     assert( s.curr == -1 ); 
0057 }
0058 
0059 void test_3( F4_Stack& s, int mode)
0060 {
0061     printf("//test_3\n"); 
0062     float a0, b0, c0 ; 
0063     float a1, b1, c1 ; 
0064  
0065     for(int i=0 ; i < 10 ; i++)
0066     {
0067        a0 = float(i); 
0068        b0 = float(10*i); 
0069        c0 = float(100*i); 
0070 
0071        if( mode == 1 )
0072        {
0073            s.push(a0) ; 
0074            s.push(b0) ; 
0075            s.push(c0) ; 
0076 
0077            s.pop(c1);
0078            s.pop(b1);
0079            s.pop(a1);
0080        }
0081        else if( mode == 2 )
0082        {
0083            s.push2(a0, b0); 
0084            s.push(c0); 
0085 
0086            s.pop(c1); 
0087            s.pop2(a1,b1); 
0088        }
0089 
0090  
0091        printf(" mode %d  a0 %10.4f b0 %10.4f c0 %10.4f c1 %10.4f b1 %10.4f a1 %10.4f  \n", mode, a0, b0, c0, c1, b1, a1 ); 
0092        assert( c1 == c0 );
0093        assert( b1 == b0 );
0094        assert( a1 == a0 );
0095     }
0096     assert( s.curr == -1 ); 
0097 }
0098 
0099 void test_4( F4_Stack& s, int mode )
0100 {
0101     printf("//test_4\n"); 
0102     float a0, b0, c0, d0 ;
0103     float a1, b1, c1, d1 ;
0104  
0105     for(int i=0 ; i < 10 ; i++)
0106     {
0107        a0 = float(i); 
0108        b0 = float(10*i); 
0109        c0 = float(100*i); 
0110        d0 = float(1000*i); 
0111 
0112        if( mode == 1 )
0113        {
0114            s.push(a0) ; 
0115            s.push(b0) ; 
0116            s.push(c0) ; 
0117            s.push(d0) ; 
0118 
0119            s.pop(d1);
0120            s.pop(c1);
0121            s.pop(b1);
0122            s.pop(a1);
0123        }
0124        else if( mode == 2 )
0125        {
0126            s.push2( a0, b0 ); 
0127            s.push2( c0, d0 ); 
0128            s.pop2(  c1, d1 ); 
0129            s.pop2(  a1, b1 ); 
0130        }
0131  
0132        printf(" mode %d a0 %10.4f b0 %10.4f c0 %10.4f d0 %10.4f d1 %10.4f c1 %10.4f b1 %10.4f a1 %10.4f  \n", mode, a0, b0, c0, d0, d1, c1, b1, a1 ); 
0133 
0134        assert( d1 == d0 );
0135        assert( c1 == c0 );
0136        assert( b1 == b0 );
0137        assert( a1 == a0 );
0138     }
0139     assert( s.curr == -1 ); 
0140 }
0141 
0142 
0143 int main(int argc, char** argv)
0144 {
0145     printf("%s\n", argv[0] ); 
0146 
0147     F4_Stack s ; 
0148     s.curr = -1 ; 
0149 
0150     test_1(s); 
0151 
0152     test_2(s, 1);
0153     test_2(s, 2);
0154  
0155     test_3(s, 1);
0156     test_3(s, 2);
0157  
0158     test_4(s, 1);
0159     test_4(s, 2);
0160 
0161     return 0 ; 
0162 }