_lrotr, _lrotl: Fix bug caused by ia32intrin.h when longs are 4 bytes long.
The problem here is that ia32intrin.h always maps _lrotr to __rorq for
x64. This is correct in linux world, but not for Windows where longs
are only 4 bytes long.
If someone were on good terms with the gcc team, a patch like
http://pastebin.com/DsEzNxRx might be a good idea, but we still need to
deal with it in the meantime.
dw
Index: mingw-w64-headers/crt/intrin.h
===================================================================
--- mingw-w64-headers/crt/intrin.h (revision 6283)
+++ mingw-w64-headers/crt/intrin.h (working copy)
@@ -38,7 +38,6 @@
#include <setjmp.h>
#endif
#include <stddef.h>
-#include <psdk_inc/intrin-impl.h>
#if defined(__GNUC__) && \
(defined(__i386__) || defined(__x86_64__))
@@ -58,12 +57,24 @@
#include <x86intrin.h>
+/* As of gcc 4.8.0, x86intrin doesn't correctly define _lrotr/_lrotl if longs are 4 bytes */
+#if __SIZEOF_LONG__ == 4
+#undef _lrotl
+#undef _lrotr
+
+#define _lrotl(a,b) __rold((a), (b))
+#define _lrotr(a,b) __rord((a), (b))
+
+#endif
+
#if defined(__cplusplus)
}
#endif
#endif
+#include <psdk_inc/intrin-impl.h>
+
#ifndef __MMX__
typedef union __m64 { char v[7]; } __m64;
#endif
@@ -395,13 +406,11 @@
#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
+ /* Note that we are deliberately NOT using __LONG32 here.
+ These signatures will change depending on the compiler's definition
+ of "long." For size-specific rotates, look at rotl and _rotl64 */
+ __MACHINE(unsigned long __cdecl _lrotl(unsigned long,int))
+ __MACHINE(unsigned long __cdecl _lrotr(unsigned long,int))
#pragma pop_macro ("_lrotl")
#pragma pop_macro ("_lrotr")
Index: mingw-w64-headers/crt/stdlib.h
===================================================================
--- mingw-w64-headers/crt/stdlib.h (revision 6265)
+++ mingw-w64-headers/crt/stdlib.h (working copy)
@@ -528,13 +528,11 @@
#pragma push_macro ("_lrotl")
#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
+ /* Note that we are deliberately NOT using __LONG32 here.
+ These signatures will change depending on the compiler's definition
+ of "long." For size-specific rotates, look at rotl and _rotl64 */
+unsigned long __cdecl _lrotl(unsigned long _Val,int _Shift);
+unsigned long __cdecl _lrotr(unsigned long _Val,int _Shift);
#pragma pop_macro ("_lrotl")
#pragma pop_macro ("_lrotr")
Index: mingw-w64-headers/include/winnt.h
===================================================================
--- mingw-w64-headers/include/winnt.h (revision 6277)
+++ mingw-w64-headers/include/winnt.h (working copy)
@@ -1492,7 +1492,16 @@
# if defined(__cplusplus)
extern "C" {
# endif
+/* We need implementations for _mm_lfence, _mm_mfence, _mm_sfence, _mm_pause, _mm_prefetch */
# include <x86intrin.h>
+/* As of gcc 4.8.0, x86intrin doesn't correctly define _lrotr/_lrotl if longs are 4 bytes */
+#if __SIZEOF_LONG__ == 4
+#undef _lrotl
+#undef _lrotr
+
+#define _lrotl(a,b) __rold((a), (b))
+#define _lrotr(a,b) __rord((a), (b))
+#endif
# if defined(__cplusplus)
}
# endif
------------------------------------------------------------------------------
How ServiceNow helps IT people transform IT departments:
1. Consolidate legacy IT systems to a single system of record for IT
2. Standardize and globalize service processes across IT
3. Implement zero-touch automation to replace manual, redundant tasks
http://pubads.g.doubleclick.net/gampad/clk?id=51271111&iu=/4140/ostg.clktrk
_______________________________________________
Mingw-w64-public mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/mingw-w64-public