Permalink
Browse files

Simplify native little-endian for MVA_UPSIZE, DOCINFO2ID_T, DOCINFOSETID

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 Aug 29, 2018
1 parent 74eeff5 commit efbc0511d6809c4a57453c7283f9bf53f3fb8d97
Showing with 20 additions and 3 deletions.
  1. +14 −0 src/gtests_functions.cpp
  2. +2 −3 src/sphinx.h
  3. +4 −0 src/sphinxint.h
@@ -1211,3 +1211,17 @@ TEST ( functions, valgrind_use )
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
}
@@ -121,7 +121,7 @@ template<> inline DWORD DOCINFO2ID_T ( const DWORD * pDocinfo )
template<> inline uint64_t DOCINFO2ID_T ( const DWORD * pDocinfo )
{
#if USE_LITTLE_ENDIAN
return uint64_t(pDocinfo[0]) + (uint64_t(pDocinfo[1])<<32);
return *(uint64_t *) pDocinfo;
#else
return uint64_t(pDocinfo[1]) + (uint64_t(pDocinfo[0])<<32);
#endif
@@ -135,8 +135,7 @@ inline void DOCINFOSETID ( DWORD * pDocinfo, DWORD uValue )
inline void DOCINFOSETID ( DWORD * pDocinfo, uint64_t uValue )
{
#if USE_LITTLE_ENDIAN
pDocinfo[0] = (DWORD)uValue;
pDocinfo[1] = (DWORD)(uValue>>32);
*( uint64_t * ) pDocinfo = uValue;
#else
pDocinfo[0] = (DWORD)(uValue>>32);
pDocinfo[1] = (DWORD)uValue;
@@ -582,8 +582,12 @@ struct MemTracker_c : ISphNoncopyable
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 ) );
return iMva;
#endif
}

0 comments on commit efbc051

Please sign in to comment.