Skip to content

Commit

Permalink
honour big-endian arch
Browse files Browse the repository at this point in the history
  • Loading branch information
klirichek committed Dec 17, 2024
1 parent fd3cfa4 commit 96b5a5c
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 12 deletions.
3 changes: 2 additions & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -188,7 +188,8 @@ if (CMAKE_CROSSCOMPILING)
if (CMAKE_SYSTEM_PROCESSOR MATCHES "^(i.86|x86(_64)?)$"
OR CMAKE_SYSTEM_PROCESSOR STREQUAL amd64
OR CMAKE_SYSTEM_PROCESSOR STREQUAL arm64
OR CMAKE_SYSTEM_PROCESSOR STREQUAL aarch64)
OR CMAKE_SYSTEM_PROCESSOR STREQUAL aarch64
OR CMAKE_SYSTEM_PROCESSOR STREQUAL s390x)
set ( UNALIGNED_RAM_ACCESS_EXITCODE "0" CACHE STRING "Result from TRY_RUN" )
set ( UNALIGNED_RAM_ACCESS_EXITCODE__TRYRUN_OUTPUT "" CACHE STRING "Output from TRY_RUN" )
endif ()
Expand Down
6 changes: 5 additions & 1 deletion src/attribute.h
Original file line number Diff line number Diff line change
Expand Up @@ -156,7 +156,11 @@ bool IsNotRealAttribute ( const CSphColumnInfo & tColumn );
inline DocID_t sphGetDocID ( const CSphRowitem * pData )
{
assert ( pData );
return sphUnalignedRead ( *(DocID_t*)(const_cast<CSphRowitem *>(pData)) );
#if USE_LITTLE_ENDIAN
return *(DocID_t *) ( const_cast<CSphRowitem *>(pData) );
#else
return DocID_t ( pData[0] )+( DocID_t ( pData[1] ) << ROWITEM_BITS );
#endif
}

const char * AttrType2Str ( ESphAttr eAttrType );
Expand Down
16 changes: 6 additions & 10 deletions src/schema/helper.h
Original file line number Diff line number Diff line change
Expand Up @@ -60,22 +60,17 @@ void CSphSchemaHelper::CloneMatchSpecial ( CSphMatch & tDst, const CSphMatch & r
CopyPtrsSpecial ( tDst, rhs, dSpecials );
}

// fixme! direct reinterpreting rows is not good idea. Use sphGetAttr/sphSetAttr!
/*
* wide (64bit) attributes occupies 2 rows and placed order lo,high
* On LE arch (intel) it is ok to reinterpret them back as 64-bit pointer
* However on BE (mips) you have problems since such cast gives garbage.
*/
void CSphSchemaHelper::FreeDataSpecial ( CSphMatch & tMatch, const VecTraits_T<int> & dSpecials )
{
if ( !tMatch.m_pDynamic )
return;

for ( auto iOffset : dSpecials )
{
BYTE*& pData = *(BYTE**)( tMatch.m_pDynamic + iOffset );
const SmallAttrLocator_t tLoc { iOffset*ROWITEM_BITS, ROWITEMPTR_BITS };
const auto * pData = (const BYTE *) sphGetRowAttr ( tMatch.m_pDynamic, tLoc );
sphDeallocatePacked ( pData );
pData = nullptr;
sphSetRowAttr ( tMatch.m_pDynamic, tLoc, (SphAttr_t) nullptr );
}
}

Expand All @@ -86,8 +81,9 @@ void CSphSchemaHelper::CopyPtrsSpecial ( CSphMatch & tDst, const CSphMatch & tSr
assert ( pSrc || dSpecials.IsEmpty() );
for ( auto i : dSpecials )
{
const BYTE* pData = *(BYTE**)( pSrc + i );
const SmallAttrLocator_t tLoc { i*ROWITEM_BITS, ROWITEMPTR_BITS };
const auto* pData = (const BYTE*) sphGetRowAttr ( pSrc, tLoc );
if ( pData )
*(BYTE**)( tDst.m_pDynamic + i ) = sph::CopyPackedAttr ( pData );
sphSetRowAttr ( tDst.m_pDynamic, tLoc, (SphAttr_t) sph::CopyPackedAttr ( pData ) );
}
}

0 comments on commit 96b5a5c

Please sign in to comment.