On Wed, 23 May 2018, Liu Hao wrote:
在 2018/5/23 18:40, Martin Storsjö 写道:
Signed-off-by: Martin Storsjö <[email protected]>
---
mingw-w64-headers/include/psdk_inc/intrin-impl.h | 79
++++++++++++++++++++++++
mingw-w64-headers/include/winnt.h | 2 +
2 files changed, 81 insertions(+)
diff --git a/mingw-w64-headers/include/psdk_inc/intrin-impl.h
b/mingw-w64-headers/include/psdk_inc/intrin-impl.h
index 88af804..90c55f9 100644
--- a/mingw-w64-headers/include/psdk_inc/intrin-impl.h
+++ b/mingw-w64-headers/include/psdk_inc/intrin-impl.h
@@ -1084,6 +1084,32 @@ __buildbittesti(InterlockedBitTestAndComplement,
__LONG32, "eor", /* unused para
#define __INTRINSIC_DEFINED_InterlockedBitTestAndComplement
#endif /* __INTRINSIC_PROLOG */
+#if __INTRINSIC_PROLOG(_BitScanForward)
+__MINGW_EXTENSION unsigned char _BitScanForward(unsigned __LONG32 *Index,
unsigned __LONG32 Mask);
+#if !__has_builtin(_BitScanForward)
+__MINGW_EXTENSION __INTRINSICS_USEINLINE
+unsigned char _BitScanForward(unsigned __LONG32 *Index, unsigned __LONG32
Mask)
+{
+ *Index = __builtin_ctz(Mask);
+ return Mask != 0;
+}
+#endif
+#define __INTRINSIC_DEFINED__BitScanForward
+#endif /* __INTRINSIC_PROLOG */
+
Is this a correct implementation? According to GCC manual [1], if the
argument to `__builtin_clz()` or `__builtin_ctz()` is zero, the result is
undefined. Basing on the 'undefined results never occur' principle it is
consequently possible that the compiler can assume `Mask` can never be zero
and optimize the return value as a constant.
Fair enough; I wanted to avoid the conditional since it's undefined
whether the function actually updates the output parameter if Mask is zero
(in MSVC, the behaviour varies across platforms), but I agree that the
compiler could do such an optimization, and some sort of condition is
needed.
// Martin
------------------------------------------------------------------------------
Check out the vibrant tech community on one of the world's most
engaging tech sites, Slashdot.org! http://sdm.link/slashdot
_______________________________________________
Mingw-w64-public mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/mingw-w64-public