I wasn't completely satisfied with my previous patch for lrotl (which is
why I didn't push to get it committed). The changes for intrin.h and
intrin-impl.h were fine, but I wasn't satisfied with the changes to
stdlib.h. Now that I've had a chance to think about it again, I finally
settled on this (attached).
It performs pretty much the same as what's in the current file (to avoid
potential breakage) while making at least some attempt to fix the
problem that can occur with old (broken) versions of x86intrin.h.
My previous post attempted to try to do mappings, but that just leads to
conflicts with other headers and undefined symbols.
Comments? Suggestions? Or can we finally call this done?
dw
>From d11d4e0560e9c086d9b8d85005bee28a1a0de787 Mon Sep 17 00:00:00 2001
From: David Wohlferd <[email protected]>
Date: Wed, 11 Feb 2015 01:20:30 -0800
Subject: [PATCH] Signed-off-by: David Wohlferd <[email protected]>
---
mingw-w64-headers/crt/intrin.h | 19 +++++----------
mingw-w64-headers/crt/stdlib.h | 30 +++++++++++++++---------
mingw-w64-headers/include/psdk_inc/intrin-impl.h | 24 +++++++++++++++++++
3 files changed, 49 insertions(+), 24 deletions(-)
diff --git a/mingw-w64-headers/crt/intrin.h b/mingw-w64-headers/crt/intrin.h
index db4d7cd..0b2343f 100644
--- a/mingw-w64-headers/crt/intrin.h
+++ b/mingw-w64-headers/crt/intrin.h
@@ -72,6 +72,10 @@ extern "C" {
#include <x86intrin.h>
+/* Before 4.9.2, x86intrin.h had broken versions of these. */
+#undef _lrotl
+#undef _lrotr
+
#if defined(__cplusplus)
}
#endif
@@ -430,19 +434,8 @@ extern "C" {
__MACHINEIA64(__MINGW_EXTENSION __int64 __load128_acq(void *,__int64 *))
__MACHINEZ(void __cdecl longjmp(jmp_buf,int))
-#pragma push_macro ("_lrotl")
-#undef _lrotl
-#pragma push_macro ("_lrotr")
-#undef _lrotr
-#ifdef __x86_64__
- __MACHINE(__MINGW_EXTENSION unsigned long long __cdecl _lrotl(unsigned long long,int))
- __MACHINE(__MINGW_EXTENSION unsigned long long __cdecl _lrotr(unsigned long long,int))
-#else
- __MACHINE(unsigned __LONG32 __cdecl _lrotl(unsigned __LONG32,int))
- __MACHINE(unsigned __LONG32 __cdecl _lrotr(unsigned __LONG32,int))
-#endif
-#pragma pop_macro ("_lrotl")
-#pragma pop_macro ("_lrotr")
+ /* __MACHINE(unsigned long __cdecl _lrotl(unsigned long,int)) moved to psdk_inc/intrin-impl.h */
+ /* __MACHINE(unsigned long __cdecl _lrotr(unsigned long,int)) moved to psdk_inc/intrin-impl.h */
__MACHINEI(__MINGW_EXTENSION unsigned __int64 __ll_lshift(unsigned __int64,int))
__MACHINEI(__MINGW_EXTENSION __int64 __ll_rshift(__int64,int))
diff --git a/mingw-w64-headers/crt/stdlib.h b/mingw-w64-headers/crt/stdlib.h
index 492f2dd..dfc5ae4 100644
--- a/mingw-w64-headers/crt/stdlib.h
+++ b/mingw-w64-headers/crt/stdlib.h
@@ -536,19 +536,27 @@ float __cdecl __MINGW_NOTHROW strtof(const char * __restrict__ _Str,char ** __re
_CRTIMP int __cdecl _atodbl_l(_CRT_DOUBLE *_Result,char *_Str,_locale_t _Locale);
_CRTIMP int __cdecl _atoldbl_l(_LDOUBLE *_Result,char *_Str,_locale_t _Locale);
_CRTIMP int __cdecl _atoflt_l(_CRT_FLOAT *_Result,char *_Str,_locale_t _Locale);
-#pragma push_macro ("_lrotr")
-#pragma push_macro ("_lrotl")
+
+#if defined(__INTRIN_H_) || \
+ (defined(_X86INTRIN_H_INCLUDED) && \
+ ((__MINGW_GCC_VERSION >= 40902) || defined(__LP64__) || defined(_X86_)))
+
+/* We already have bug-free prototypes and inline definitions for _lrotl
+ and _lrotr from either intrin.h or x86intrin.h. */
+
+#else
+
+/* Remove buggy x86intrin.h definitions if present (see gcc bug 61662). */
#undef _lrotr
#undef _lrotl
-#ifdef __x86_64__
- __MINGW_EXTENSION unsigned long long __cdecl _lrotl(unsigned long long _Val,int _Shift);
- __MINGW_EXTENSION unsigned long long __cdecl _lrotr(unsigned long long _Val,int _Shift);
-#else
- unsigned long __cdecl _lrotl(unsigned long _Val,int _Shift);
- unsigned long __cdecl _lrotr(unsigned long _Val,int _Shift);
-#endif
-#pragma pop_macro ("_lrotl")
-#pragma pop_macro ("_lrotr")
+
+/* These prototypes work for x86, x64 (native Windows), and cyginwin64. */
+unsigned long __cdecl _lrotl(unsigned long,int);
+unsigned long __cdecl _lrotr(unsigned long,int);
+
+#endif /* defined(__INTRIN_H_) || \
+ (defined(_X86INTRIN_H_INCLUDED) && \
+ ((__MINGW_GCC_VERSION >= 40902) || defined(__LP64__))) */
_CRTIMP void __cdecl _makepath(char *_Path,const char *_Drive,const char *_Dir,const char *_Filename,const char *_Ext);
_onexit_t __cdecl _onexit(_onexit_t _Func);
diff --git a/mingw-w64-headers/include/psdk_inc/intrin-impl.h b/mingw-w64-headers/include/psdk_inc/intrin-impl.h
index 71d6096..fd7d38a 100644
--- a/mingw-w64-headers/include/psdk_inc/intrin-impl.h
+++ b/mingw-w64-headers/include/psdk_inc/intrin-impl.h
@@ -509,6 +509,30 @@ supports ReadWriteBarrier, map all 3 to do the same. */
extern "C" {
#endif
+/* Before 4.9.2, ia32intrin.h had broken versions of these. */
+#undef _lrotl
+#undef _lrotr
+
+#if __INTRINSIC_PROLOG(_lrotl)
+unsigned long _lrotl(unsigned long __X, int __C);
+__INTRINSICS_USEINLINE
+unsigned long _lrotl(unsigned long __X, int __C)
+{
+ return (__X << __C) | (__X >> ((sizeof(long) * 8) - __C));
+}
+#define __INTRINSIC_DEFINED__lrotl
+#endif /* __INTRINSIC_PROLOG */
+
+#if __INTRINSIC_PROLOG(_lrotr)
+unsigned long _lrotr(unsigned long __X, int __C);
+__INTRINSICS_USEINLINE
+unsigned long _lrotr(unsigned long __X, int __C)
+{
+ return (__X >> __C) | (__X << ((sizeof(long) * 8) - __C));
+}
+#define __INTRINSIC_DEFINED__lrotr
+#endif /* __INTRINSIC_PROLOG */
+
#if defined(__x86_64__) || defined(_AMD64_)
#if __INTRINSIC_PROLOG(__faststorefence)
--
1.9.4.msysgit.0
------------------------------------------------------------------------------
Dive into the World of Parallel Programming. The Go Parallel Website,
sponsored by Intel and developed in partnership with Slashdot Media, is your
hub for all things parallel software development, from weekly thought
leadership blogs to news, videos, case studies, tutorials and more. Take a
look and join the conversation now. http://goparallel.sourceforge.net/
_______________________________________________
Mingw-w64-public mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/mingw-w64-public