Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2026-04-09 07:49:23

0001 // ./strid_test.sh 
0002 
0003 #include <cassert>
0004 #include <iostream>
0005 #include <array>
0006 #include <glm/glm.hpp>
0007 #include "strid.h"
0008 
0009 void set( glm::tvec4<uint64_t>& col3, int mode)
0010 {
0011     if( mode == 0 )
0012     {
0013         col3.x = 0 ; 
0014         col3.y = 0 ; 
0015         col3.z = 0 ; 
0016         col3.w = 0 ; 
0017     }
0018     else if(mode == 1)
0019     {
0020         col3.x = 0xffffffffff0fffff ; 
0021         col3.y = 0xaaaaaaaafff0ffff ; 
0022         col3.z = 0xbbbbbbbbffff0fff ; 
0023         col3.w = 0xccccccccfffff0ff ; 
0024     }
0025     else if(mode == -1)
0026     {
0027         col3.x = -1 ; 
0028         col3.y = 0xffffffffffffffff ; 
0029         col3.z = -1 ; 
0030         col3.w = 0xffffffffffffffff ; 
0031     }
0032 }
0033 
0034 void test_Encode_Decode(int mode=0)
0035 {
0036     std::cout << "test_Encode_Decode " << mode << std::endl ;
0037 
0038     glm::tmat4x4<double> tr(1.); 
0039     assert( strid::IsClear(tr)==true );
0040 
0041     glm::tvec4<uint64_t> col3 ;  
0042     set(col3, mode); 
0043      
0044     strid::Encode(tr, col3 ); 
0045     assert( strid::IsClear(tr)==false );
0046     
0047     glm::tvec4<uint64_t> col3_ ; 
0048     strid::Decode(tr, col3_ ); 
0049 
0050     for(unsigned r=0 ; r < 4 ; r++) assert( col3[r] == col3_[r] ); 
0051 
0052     std::cout << strid::Desc<double, uint64_t>(tr) << std::endl ; 
0053 }
0054 
0055 
0056 /**
0057 Decoding 0.,0.,0.,1. is a hazard 
0058 
0059 test_Decode_Unset<double,uint64_t>
0060 
0061                              0 0x                              0
0062                              0 0x                              0
0063                              0 0x                              0
0064            4607182418800017408 0x               3ff0000000000000
0065 
0066 test_Decode_Unset<float, uint32_t>
0067 
0068                              0 0x                              0
0069                              0 0x                              0
0070                              0 0x                              0
0071                     1065353216 0x                       3f800000
0072 **/
0073 
0074 
0075 template <typename T, typename S>   // T:double/float S:uint64_t/uint32_t  
0076 void test_Decode_Unset(const char* label)
0077 {
0078     std::cout << label  << std::endl ;
0079     glm::tmat4x4<T> tr(1.); 
0080     assert( strid::IsClear(tr)==true );
0081 
0082     glm::tvec4<S> col3 ; 
0083     strid::Decode(tr, col3 ); 
0084 
0085     for(unsigned r=0 ; r < 4 ; r++) 
0086         std::cout 
0087             << std::setw(30) << col3[r] 
0088             << " 0x " << std::setw(30) << std::hex << col3[r] << std::dec 
0089             << std::endl 
0090             ; 
0091 
0092     std::cout << strid::Desc<T, S>(tr) << std::endl ; 
0093 }
0094 
0095 
0096 template void test_Decode_Unset<double, uint64_t>(const char* ) ; 
0097 template void test_Decode_Unset<float , uint32_t>(const char* ) ; 
0098 
0099 
0100 
0101 void test_Narrow(int mode)
0102 {
0103     std::cout << "test_Narrow " << mode << std::endl ;
0104 
0105     glm::tmat4x4<double> src(1.); 
0106 
0107     glm::tvec4<uint64_t> col3 ; 
0108     set(col3, mode); 
0109 
0110     strid::Encode(src, col3 ); 
0111     std::cout << "src\n" << strid::Desc<double, uint64_t>(src) << std::endl ; 
0112 
0113     glm::tmat4x4<float>  dst(1.); 
0114     strid::Narrow(dst, src); 
0115     std::cout << "dst\n" << strid::Desc<float,  uint32_t>(dst) << std::endl ; 
0116 }
0117 
0118 
0119 void test_Encode_Decode()
0120 {
0121     for(int mode=-1 ; mode < 2 ; mode++)
0122     {
0123         test_Encode_Decode(mode); 
0124         test_Narrow(mode);  
0125     }
0126 
0127     test_Decode_Unset<double,uint64_t>("test_Decode_Unset<double,uint64_t>"); 
0128     test_Decode_Unset<float, uint32_t>("test_Decode_Unset<float, uint32_t>"); 
0129 }
0130 
0131 
0132 void test_Read_()
0133 {
0134     std::cout << "test_Read_" << std::endl ; 
0135 
0136     std::array<double, 16> src = {{ 
0137          0.,  1.,  2.,  3.,
0138          4.,  5.,  6.,  7.,
0139          8.,  9., 10., 11.,
0140         12., 13., 14., 15.  }} ; 
0141 
0142     glm::tmat4x4<double> d0(1.); 
0143 
0144     strid::Read_( d0, src.data() ); 
0145     std::cout << "d0\n" << strid::Desc_(d0) << std::endl ; 
0146 }
0147 
0148 void test_Read()
0149 {
0150     std::cout << "test_Read" << std::endl ; 
0151 
0152     std::array<float, 16> src = {{ 
0153          0.f,  1.f,  2.f,  3.f,
0154          4.f,  5.f,  6.f,  7.f,
0155          8.f,  9.f, 10.f, 11.f,
0156         12.f, 13.f, 14.f, 15.f  }} ; 
0157 
0158     glm::tmat4x4<double> d0(1.); 
0159     glm::tmat4x4<double> d1(1.); 
0160 
0161     strid::Read( d0, src.data(), false ); 
0162     strid::Read( d1, src.data(), true  ); 
0163 
0164     std::cout << "d0\n" << strid::Desc_(d0) << std::endl ; 
0165     std::cout << "d1\n" << strid::Desc_(d1) << std::endl ; 
0166 }
0167 
0168 
0169 int main(int argc, char** argv)
0170 {
0171     //test_Encode_Decode();  
0172     test_Read(); 
0173     test_Read_(); 
0174 
0175     return 0 ; 
0176 }