Re: [Mingw-w64-public] [PATCH] headers: Implement the _bittest* intrinsics for arm and aarch64

2021-07-14 Thread Martin Storsjö

On Wed, 14 Jul 2021, LIU Hao wrote:


在 7/14/21 9:02 PM, Martin Storsjö 写道:

+unsigned char _bittestandset(__LONG32 *__a, __LONG32 __b)
+{
+unsigned char __v = (*__a >> __b) & 1;
+*__a |= (1 << __b);


I suggest `1UL` here, as shifting 1 to the left by 31 is undefined behavior.


Thanks, will update all these.

// Martin

___
Mingw-w64-public mailing list
Mingw-w64-public@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/mingw-w64-public


Re: [Mingw-w64-public] [PATCH] headers: Implement the _bittest* intrinsics for arm and aarch64

2021-07-14 Thread LIU Hao

在 7/14/21 9:02 PM, Martin Storsjö 写道:

+unsigned char _bittestandset(__LONG32 *__a, __LONG32 __b)
+{
+unsigned char __v = (*__a >> __b) & 1;
+*__a |= (1 << __b);


I suggest `1UL` here, as shifting 1 to the left by 31 is undefined behavior.



+unsigned char _bittestandreset(__LONG32 *__a, __LONG32 __b)
+{
+unsigned char __v = (*__a >> __b) & 1;
+*__a &= ~(1 << __b);


Likewise.



+unsigned char _bittestandcomplement(__LONG32 *__a, __LONG32 __b)
+{
+unsigned char __v = (*__a >> __b) & 1;
+*__a = (*__a & ~(1 << __b)) | ((__v ^ 1) << __b);


Likewise.



+unsigned char _bittestandset64(__int64 *__a, __int64 __b)
+{
+unsigned char __v = (*__a >> __b) & 1;
+*__a |= (1LL << __b);


Likewise, but `1ULL`, and more follow.


--
Best regards,
LIU Hao



OpenPGP_signature
Description: OpenPGP digital signature
___
Mingw-w64-public mailing list
Mingw-w64-public@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/mingw-w64-public


[Mingw-w64-public] [PATCH] headers: Implement the _bittest* intrinsics for arm and aarch64

2021-07-14 Thread Martin Storsjö
These are non-atomic versions corresponding to the existing
_interlockedbittest* - therefore they're implemented as plain C
instead of assembly. Additionally, there are plain intrinsics "_bittest"
and "_bittest64", where there's no corresponding interlocked version.

Signed-off-by: Martin Storsjö 
---
 .../include/psdk_inc/intrin-impl.h| 117 ++
 1 file changed, 117 insertions(+)

diff --git a/mingw-w64-headers/include/psdk_inc/intrin-impl.h 
b/mingw-w64-headers/include/psdk_inc/intrin-impl.h
index d59682c18..d0651a654 100644
--- a/mingw-w64-headers/include/psdk_inc/intrin-impl.h
+++ b/mingw-w64-headers/include/psdk_inc/intrin-impl.h
@@ -1424,6 +1424,123 @@ unsigned char _BitScanReverse64(unsigned __LONG32 
*Index, unsigned __int64 Mask)
 #endif /* __INTRINSIC_PROLOG */
 
 #endif /* defined(__aarch64__) || define(_ARM64_) */
+
+#if defined(__arm__) || defined(_ARM_) || defined(__aarch64__) || 
defined(_ARM64_)
+
+#if __INTRINSIC_PROLOG(_bittest)
+unsigned char _bittest(const __LONG32 *__a, __LONG32 __b);
+#if !__has_builtin(_bittest)
+__INTRINSICS_USEINLINE
+unsigned char _bittest(const __LONG32 *__a, __LONG32 __b)
+{
+return (*__a >> __b) & 1;
+}
+#endif
+#define __INTRINSIC_DEFINED__bittest
+#endif /* __INTRINSIC_PROLOG */
+
+#if __INTRINSIC_PROLOG(_bittestandset)
+unsigned char _bittestandset(__LONG32 *__a, __LONG32 __b);
+#if !__has_builtin(_bittestandset)
+__INTRINSICS_USEINLINE
+unsigned char _bittestandset(__LONG32 *__a, __LONG32 __b)
+{
+unsigned char __v = (*__a >> __b) & 1;
+*__a |= (1 << __b);
+return __v;
+}
+#endif
+#define __INTRINSIC_DEFINED__bittestandset
+#endif /* __INTRINSIC_PROLOG */
+
+#if __INTRINSIC_PROLOG(_bittestandreset)
+unsigned char _bittestandreset(__LONG32 *__a, __LONG32 __b);
+#if !__has_builtin(_bittestandreset)
+__INTRINSICS_USEINLINE
+unsigned char _bittestandreset(__LONG32 *__a, __LONG32 __b)
+{
+unsigned char __v = (*__a >> __b) & 1;
+*__a &= ~(1 << __b);
+return __v;
+}
+#endif
+#define __INTRINSIC_DEFINED__bittestandreset
+#endif /* __INTRINSIC_PROLOG */
+
+#if __INTRINSIC_PROLOG(_bittestandcomplement)
+unsigned char _bittestandcomplement(__LONG32 *a, __LONG32 b);
+#if !__has_builtin(_bittestandcomplement)
+__INTRINSICS_USEINLINE
+unsigned char _bittestandcomplement(__LONG32 *__a, __LONG32 __b)
+{
+unsigned char __v = (*__a >> __b) & 1;
+*__a = (*__a & ~(1 << __b)) | ((__v ^ 1) << __b);
+return __v;
+}
+#endif
+#define __INTRINSIC_DEFINED__bittestandcomplement
+#endif /* __INTRINSIC_PROLOG */
+
+#endif /* defined(__arm__) || defined(_ARM_) || defined(__aarch64__) || 
defined(_ARM64_) */
+
+#if defined(__aarch64__) || defined(_ARM64_)
+
+#if __INTRINSIC_PROLOG(_bittest64)
+unsigned char _bittest64(const __int64 *__a, __int64 __b);
+#if !__has_builtin(_bittest64)
+__INTRINSICS_USEINLINE
+unsigned char _bittest64(const __int64 *__a, __int64 __b)
+{
+return (*__a >> __b) & 1;
+}
+#endif
+#define __INTRINSIC_DEFINED__bittest64
+#endif /* __INTRINSIC_PROLOG */
+
+#if __INTRINSIC_PROLOG(_bittestandset64)
+unsigned char _bittestandset64(__int64 *__a, __int64 __b);
+#if !__has_builtin(_bittestandset64)
+__INTRINSICS_USEINLINE
+unsigned char _bittestandset64(__int64 *__a, __int64 __b)
+{
+unsigned char __v = (*__a >> __b) & 1;
+*__a |= (1LL << __b);
+return __v;
+}
+#endif
+#define __INTRINSIC_DEFINED__bittestandset64
+#endif /* __INTRINSIC_PROLOG */
+
+#if __INTRINSIC_PROLOG(_bittestandreset64)
+unsigned char _bittestandreset64(__int64 *__a, __int64 __b);
+#if !__has_builtin(_bittestandreset64)
+__INTRINSICS_USEINLINE
+unsigned char _bittestandreset64(__int64 *__a, __int64 __b)
+{
+unsigned char __v = (*__a >> __b) & 1;
+*__a &= ~(1LL << __b);
+return __v;
+}
+#endif
+#define __INTRINSIC_DEFINED__bittestandreset64
+#endif /* __INTRINSIC_PROLOG */
+
+#if __INTRINSIC_PROLOG(_bittestandcomplement64)
+unsigned char _bittestandcomplement64(__int64 *a, __int64 b);
+#if !__has_builtin(_bittestandcomplement64)
+__INTRINSICS_USEINLINE
+unsigned char _bittestandcomplement64(__int64 *__a, __int64 __b)
+{
+unsigned char __v = (*__a >> __b) & 1;
+*__a = (*__a & ~(1LL << __b)) | ((__int64)(__v ^ 1) << __b);
+return __v;
+}
+#endif
+#define __INTRINSIC_DEFINED__bittestandcomplement64
+#endif /* __INTRINSIC_PROLOG */
+
+#endif /* defined(__aarch64__) || define(_ARM64_) */
+
 /* * */
 
 #if defined(__x86_64__) || defined(_AMD64_) || defined(__i386__) || 
defined(_X86_) || defined(__arm__) || defined(_ARM_) || defined(__aarch64__) || 
defined(_ARM64_)
-- 
2.25.1



___
Mingw-w64-public mailing list
Mingw-w64-public@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/mingw-w64-public