| 1 | #ifndef __PROCESSCOMMON_HPP__ | 
|---|
| 2 | #define __PROCESSCOMMON_HPP__ | 
|---|
| 3 |  | 
|---|
| 4 | #include <assert.h> | 
|---|
| 5 | #include <stddef.h> | 
|---|
| 6 | #include <stdint.h> | 
|---|
| 7 |  | 
|---|
| 8 | template<class T> | 
|---|
| 9 | static size_t GetLeastError( const T* err, size_t num ) | 
|---|
| 10 | { | 
|---|
| 11 | size_t idx = 0; | 
|---|
| 12 | for( size_t i=1; i<num; i++ ) | 
|---|
| 13 | { | 
|---|
| 14 | if( err[i] < err[idx] ) | 
|---|
| 15 | { | 
|---|
| 16 | idx = i; | 
|---|
| 17 | } | 
|---|
| 18 | } | 
|---|
| 19 | return idx; | 
|---|
| 20 | } | 
|---|
| 21 |  | 
|---|
| 22 | static uint64_t FixByteOrder( uint64_t d ) | 
|---|
| 23 | { | 
|---|
| 24 | return ( ( d & 0x00000000FFFFFFFF ) ) | | 
|---|
| 25 | ( ( d & 0xFF00000000000000 ) >> 24 ) | | 
|---|
| 26 | ( ( d & 0x000000FF00000000 ) << 24 ) | | 
|---|
| 27 | ( ( d & 0x00FF000000000000 ) >> 8 ) | | 
|---|
| 28 | ( ( d & 0x0000FF0000000000 ) << 8 ); | 
|---|
| 29 | } | 
|---|
| 30 |  | 
|---|
| 31 | template<class T, class S> | 
|---|
| 32 | static uint64_t EncodeSelectors( uint64_t d, const T terr[2][8], const S tsel[16][8], const uint32_t* id ) | 
|---|
| 33 | { | 
|---|
| 34 | size_t tidx[2]; | 
|---|
| 35 | tidx[0] = GetLeastError( terr[0], 8 ); | 
|---|
| 36 | tidx[1] = GetLeastError( terr[1], 8 ); | 
|---|
| 37 |  | 
|---|
| 38 | d |= tidx[0] << 26; | 
|---|
| 39 | d |= tidx[1] << 29; | 
|---|
| 40 | for( int i=0; i<16; i++ ) | 
|---|
| 41 | { | 
|---|
| 42 | uint64_t t = tsel[i][tidx[id[i]%2]]; | 
|---|
| 43 | d |= ( t & 0x1 ) << ( i + 32 ); | 
|---|
| 44 | d |= ( t & 0x2 ) << ( i + 47 ); | 
|---|
| 45 | } | 
|---|
| 46 |  | 
|---|
| 47 | return d; | 
|---|
| 48 | } | 
|---|
| 49 |  | 
|---|
| 50 | #endif | 
|---|
| 51 |  | 
|---|