Path: blob/master/thirdparty/etcpak/ProcessCommon.hpp
9832 views
#ifndef __PROCESSCOMMON_HPP__1#define __PROCESSCOMMON_HPP__23#include <assert.h>4#include <stddef.h>5#include <stdint.h>67template<class T>8static size_t GetLeastError( const T* err, size_t num )9{10size_t idx = 0;11for( size_t i=1; i<num; i++ )12{13if( err[i] < err[idx] )14{15idx = i;16}17}18return idx;19}2021static uint64_t FixByteOrder( uint64_t d )22{23return ( ( d & 0x00000000FFFFFFFF ) ) |24( ( d & 0xFF00000000000000 ) >> 24 ) |25( ( d & 0x000000FF00000000 ) << 24 ) |26( ( d & 0x00FF000000000000 ) >> 8 ) |27( ( d & 0x0000FF0000000000 ) << 8 );28}2930template<class T, class S>31static uint64_t EncodeSelectors( uint64_t d, const T terr[2][8], const S tsel[16][8], const uint32_t* id )32{33size_t tidx[2];34tidx[0] = GetLeastError( terr[0], 8 );35tidx[1] = GetLeastError( terr[1], 8 );3637d |= tidx[0] << 26;38d |= tidx[1] << 29;39for( int i=0; i<16; i++ )40{41uint64_t t = tsel[i][tidx[id[i]%2]];42d |= ( t & 0x1 ) << ( i + 32 );43d |= ( t & 0x2 ) << ( i + 47 );44}4546return d;47}4849#endif505152