diff options
author | RĂ©mi Verschelde <remi@verschelde.fr> | 2021-04-13 01:09:38 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2021-04-13 01:09:38 +0200 |
commit | 8793a464d312c5a48490fbec03c26f2835318063 (patch) | |
tree | 8be39ad26992b0bc10ee69fef5f0c5cadb6a0760 /thirdparty/etcpak/ProcessCommon.hpp | |
parent | 075f358fcddbb3df8417ef85baabdf3684a4efd2 (diff) | |
parent | d840165a324b5c218ca3a4882f030986855c8383 (diff) |
Merge pull request #47370 from fire/etcpak
Add thirdparty library etcpak for faster imports.
Diffstat (limited to 'thirdparty/etcpak/ProcessCommon.hpp')
-rw-r--r-- | thirdparty/etcpak/ProcessCommon.hpp | 50 |
1 files changed, 50 insertions, 0 deletions
diff --git a/thirdparty/etcpak/ProcessCommon.hpp b/thirdparty/etcpak/ProcessCommon.hpp new file mode 100644 index 0000000000..657d68888f --- /dev/null +++ b/thirdparty/etcpak/ProcessCommon.hpp @@ -0,0 +1,50 @@ +#ifndef __PROCESSCOMMON_HPP__ +#define __PROCESSCOMMON_HPP__ + +#include <assert.h> +#include <stddef.h> +#include <stdint.h> + +template<class T> +static size_t GetLeastError( const T* err, size_t num ) +{ + size_t idx = 0; + for( size_t i=1; i<num; i++ ) + { + if( err[i] < err[idx] ) + { + idx = i; + } + } + return idx; +} + +static uint64_t FixByteOrder( uint64_t d ) +{ + return ( ( d & 0x00000000FFFFFFFF ) ) | + ( ( d & 0xFF00000000000000 ) >> 24 ) | + ( ( d & 0x000000FF00000000 ) << 24 ) | + ( ( d & 0x00FF000000000000 ) >> 8 ) | + ( ( d & 0x0000FF0000000000 ) << 8 ); +} + +template<class T, class S> +static uint64_t EncodeSelectors( uint64_t d, const T terr[2][8], const S tsel[16][8], const uint32_t* id ) +{ + size_t tidx[2]; + tidx[0] = GetLeastError( terr[0], 8 ); + tidx[1] = GetLeastError( terr[1], 8 ); + + d |= tidx[0] << 26; + d |= tidx[1] << 29; + for( int i=0; i<16; i++ ) + { + uint64_t t = tsel[i][tidx[id[i]%2]]; + d |= ( t & 0x1 ) << ( i + 32 ); + d |= ( t & 0x2 ) << ( i + 47 ); + } + + return d; +} + +#endif |