From 8e37949a719861baf080bbb79e832b0593d2bad2 Mon Sep 17 00:00:00 2001 From: Georg Lehmann Date: Wed, 3 Aug 2022 19:40:34 +0200 Subject: [PATCH] [util] Use raw tzcnt for BitMask iterator Dereferencing an end iterator is UB, so we don't have to care about the 0 case. --- src/util/util_bit.h | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/src/util/util_bit.h b/src/util/util_bit.h index ee7470a70..4acd9c23a 100644 --- a/src/util/util_bit.h +++ b/src/util/util_bit.h @@ -336,7 +336,16 @@ namespace dxvk::bit { } uint32_t operator * () const { +#if (defined(__GNUC__) || defined(__clang__)) && !defined(__BMI__) + uint32_t res; + asm ("tzcnt %1,%0" + : "=r" (res) + : "r" (m_mask) + : "cc"); + return res; +#else return tzcnt(m_mask); +#endif } bool operator == (iterator other) const { return m_mask == other.m_mask; }