Skip to content

Commit

Permalink
Simplify native little-endian for MVA_UPSIZE, DOCINFO2ID_T, DOCINFOSETID
Browse files Browse the repository at this point in the history
64-bit ints in LE order are by arch placed from low to hi bytes in the memory. This is no need to manually split a number to halves and perform manual placing
  • Loading branch information
klirichek committed Sep 6, 2018
1 parent 74eeff5 commit efbc051
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 3 deletions.
14 changes: 14 additions & 0 deletions src/gtests_functions.cpp
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -1211,3 +1211,17 @@ TEST ( functions, valgrind_use )
ASSERT_TRUE (true) << "intended leak"; ASSERT_TRUE (true) << "intended leak";
} }


TEST ( functions, int64_le )
{
DWORD pMva[2] = {0x01020304, 0x05060708};

// expression from MVA_UPSIZE
auto iTest = ( int64_t ) ( ( uint64_t ) pMva[0] | ( ( ( uint64_t ) pMva[1] ) << 32 ) );
auto iTest2 = MVA_UPSIZE ( pMva );
ASSERT_EQ ( iTest, iTest2 );

#if USE_LITTLE_ENDIAN
auto iTestLE = *( int64_t * ) pMva;
ASSERT_EQ ( iTest, iTestLE ) << "little endian allows simplify";
#endif
}
5 changes: 2 additions & 3 deletions src/sphinx.h
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@ template<> inline DWORD DOCINFO2ID_T ( const DWORD * pDocinfo )
template<> inline uint64_t DOCINFO2ID_T ( const DWORD * pDocinfo ) template<> inline uint64_t DOCINFO2ID_T ( const DWORD * pDocinfo )
{ {
#if USE_LITTLE_ENDIAN #if USE_LITTLE_ENDIAN
return uint64_t(pDocinfo[0]) + (uint64_t(pDocinfo[1])<<32); return *(uint64_t *) pDocinfo;
#else #else
return uint64_t(pDocinfo[1]) + (uint64_t(pDocinfo[0])<<32); return uint64_t(pDocinfo[1]) + (uint64_t(pDocinfo[0])<<32);
#endif #endif
Expand All @@ -135,8 +135,7 @@ inline void DOCINFOSETID ( DWORD * pDocinfo, DWORD uValue )
inline void DOCINFOSETID ( DWORD * pDocinfo, uint64_t uValue ) inline void DOCINFOSETID ( DWORD * pDocinfo, uint64_t uValue )
{ {
#if USE_LITTLE_ENDIAN #if USE_LITTLE_ENDIAN
pDocinfo[0] = (DWORD)uValue; *( uint64_t * ) pDocinfo = uValue;
pDocinfo[1] = (DWORD)(uValue>>32);
#else #else
pDocinfo[0] = (DWORD)(uValue>>32); pDocinfo[0] = (DWORD)(uValue>>32);
pDocinfo[1] = (DWORD)uValue; pDocinfo[1] = (DWORD)uValue;
Expand Down
4 changes: 4 additions & 0 deletions src/sphinxint.h
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -582,8 +582,12 @@ struct MemTracker_c : ISphNoncopyable


inline int64_t MVA_UPSIZE ( const DWORD * pMva ) inline int64_t MVA_UPSIZE ( const DWORD * pMva )
{ {
#if USE_LITTLE_ENDIAN
return *(int64_t*)pMva;
#else
int64_t iMva = (int64_t)( (uint64_t)pMva[0] | ( ( (uint64_t)pMva[1] )<<32 ) ); int64_t iMva = (int64_t)( (uint64_t)pMva[0] | ( ( (uint64_t)pMva[1] )<<32 ) );
return iMva; return iMva;
#endif
} }




Expand Down

0 comments on commit efbc051

Please sign in to comment.