From 7806cceb3345d09a12843461785a173027aad9b4 Mon Sep 17 00:00:00 2001 From: Kawe Mazidjatari <48657826+Mauler125@users.noreply.github.com> Date: Sat, 23 Sep 2023 16:34:37 +0200 Subject: [PATCH] Swap SSE4.1 instruction with an SSE2 instruction The min spec is SSSE3, using SSE4.1 instructions (_mm_extract_epi64) will break compatibility. The code containing the defect is debug only, and %90+ of the user base uses an SSE4.1 capable processor. --- src/game/shared/ai_utility_shared.cpp | 9 ++++++--- src/game/shared/ai_utility_shared.h | 2 +- 2 files changed, 7 insertions(+), 4 deletions(-) diff --git a/src/game/shared/ai_utility_shared.cpp b/src/game/shared/ai_utility_shared.cpp index de9d5aa2..f2e76f6e 100644 --- a/src/game/shared/ai_utility_shared.cpp +++ b/src/game/shared/ai_utility_shared.cpp @@ -138,7 +138,10 @@ void CAI_Utility::DrawAIScriptNetwork( int nNearest = GetNearestNodeToPos(pNetwork, &pScriptNode->m_vOrigin); if (nNearest != NO_NODE) // NO_NODE = -1 { - auto p = uLinkSet.insert(_mm_extract_epi64(PackNodeLink(i, nNearest), 1)); + shortx8 packedLinks = PackNodeLink(i, nNearest); + packedLinks = _mm_srli_si128(packedLinks, 8); // Only the upper 64bits are used. + + auto p = uLinkSet.insert(reinterpret_cast(packedLinks)); if (p.second) // Only render if link hasn't already been rendered. { const CAI_ScriptNode* pNearestNode = &pNetwork->m_ScriptNode[nNearest]; @@ -536,9 +539,9 @@ void CAI_Utility::DrawNavMeshPolyBoundaries(const dtNavMesh* pMesh, // d - // Output : packed node set as i64x2 //------------------------------------------------------------------------------ -__m128i CAI_Utility::PackNodeLink(int32_t a, int32_t b, int32_t c, int32_t d) const +shortx8 CAI_Utility::PackNodeLink(int32_t a, int32_t b, int32_t c, int32_t d) const { - __m128i xResult = _mm_set_epi32(a, b, c, d); + shortx8 xResult = _mm_set_epi32(a, b, c, d); // We shuffle a b and c d if following condition is met, this is to // ensure we always end up with one possible combination of indices. diff --git a/src/game/shared/ai_utility_shared.h b/src/game/shared/ai_utility_shared.h index 071a534f..d8e32b81 100644 --- a/src/game/shared/ai_utility_shared.h +++ b/src/game/shared/ai_utility_shared.h @@ -57,7 +57,7 @@ public: const int nTileRange, const bool bDepthBuffer) const; - __m128i PackNodeLink(int32_t a, int32_t b, int32_t c = 0, int32_t d = 0) const; + shortx8 PackNodeLink(int32_t a, int32_t b, int32_t c = 0, int32_t d = 0) const; int GetNearestNodeToPos(const CAI_Network* pAINetwork, const Vector3D* vec) const; bool IsTileWithinRange(const dtMeshTile* pTile, const VPlane& vPlane, const Vector3D& vCamera, const float flCameraRadius) const;