Skip to content

Commit ddb7d4e

Browse files
committed
[Memory Observer] Replace all_equal
1 parent b9fa522 commit ddb7d4e

File tree

1 file changed

+10
-7
lines changed

1 file changed

+10
-7
lines changed

src/gui/widgets/memory_observer.cc

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -289,13 +289,16 @@ int PCSX::Widgets::MemoryObserver::getMemValue(uint32_t absoluteAddress, const u
289289
}
290290

291291
#ifdef MEMORY_OBSERVER_X86
292-
bool PCSX::Widgets::MemoryObserver::all_equal(__m256i input) {
293-
const auto lane0 = _mm256_castsi256_si128(input);
294-
const auto tmp = _mm_shuffle_epi8(lane0, _mm_setzero_si128());
295-
const auto populated_0th_byte = _mm256_set_m128i(tmp, tmp);
296-
const auto eq = _mm256_cmpeq_epi8(input, populated_0th_byte);
297-
298-
return (static_cast<uint32_t>(_mm256_movemask_epi8(eq)) == 0xffffffff);
292+
// Check if all bytes in a 256-bit vector are equal
293+
// Broadcasts byte 0 of the vector to 256 bits, then xors the result with the starting vector
294+
// If the resulting vector is 0, then all bytes in the 256-bit vector are equal
295+
bool PCSX::Widgets::MemoryObserver::all_equal(__m256i vec) {
296+
const __m128i vec128 = _mm256_castsi256_si128(vec);
297+
const __m256i broadcasted = _mm256_broadcastb_epi8(vec128);
298+
const __m256i res = _mm256_xor_epi32(vec, broadcasted);
299+
300+
// Check if the vector after xoring is 0
301+
return _mm256_testz_si256(res, res) != 0;
299302
}
300303
#endif // MEMORY_OBSERVER_X86
301304

0 commit comments

Comments
 (0)