__shiftright128 & __shiftleft128: Re-written as asm, moved from library-only to intrin-impl.h.

Note that the code that is being replaced would not always return the same results as MS's intrinsics. This patch resolves this issue as well as producing more efficient code.

dw
Index: mingw-w64-crt/intrincs/__shiftleft128.c
===================================================================
--- mingw-w64-crt/intrincs/__shiftleft128.c	(revision 6265)
+++ mingw-w64-crt/intrincs/__shiftleft128.c	(working copy)
@@ -1,27 +1,10 @@
-#include <_mingw.h>
+/**
+ * This file has no copyright assigned and is placed in the Public Domain.
+ * This file is part of the mingw-w64 runtime package.
+ * No warranty is given; refer to the file DISCLAIMER.PD within this package.
+ */
 
-#ifdef _WIN64
+#define __INTRINSIC_ONLYSPECIAL
+#define __INTRINSIC_SPECIAL___shiftleft128 /* Causes code generation in intrin-impl.h */
 
-unsigned __int64 __shiftleft128 (unsigned __int64  LowPart,
- unsigned __int64 HighPart, unsigned char Shift);
-
-unsigned __int64 __shiftleft128 (unsigned __int64  LowPart,
- unsigned __int64 HighPart, unsigned char Shift)
-{
-  if (Shift >= 128)
-    return 0ULL;
-  if (!Shift)
-    return HighPart;
-  if (Shift >= 64)
-    {
-      HighPart = LowPart;
-      Shift -= 64;
-      LowPart = 0;
-    }
-  HighPart <<= Shift;
-  LowPart >>= (64 - Shift);
-  return (HighPart | LowPart);
-}
-
-#endif
-
+#include <intrin.h>
Index: mingw-w64-crt/intrincs/__shiftright128.c
===================================================================
--- mingw-w64-crt/intrincs/__shiftright128.c	(revision 6265)
+++ mingw-w64-crt/intrincs/__shiftright128.c	(working copy)
@@ -1,27 +1,10 @@
-#include <_mingw.h>
+/**
+ * This file has no copyright assigned and is placed in the Public Domain.
+ * This file is part of the mingw-w64 runtime package.
+ * No warranty is given; refer to the file DISCLAIMER.PD within this package.
+ */
 
-#ifdef _WIN64
+#define __INTRINSIC_ONLYSPECIAL
+#define __INTRINSIC_SPECIAL___shiftright128 /* Causes code generation in intrin-impl.h */
 
-unsigned __int64 __shiftright128 (unsigned __int64  LowPart,
- unsigned __int64 HighPart, unsigned char Shift);
-
-unsigned __int64 __shiftright128 (unsigned __int64  LowPart,
- unsigned __int64 HighPart, unsigned char Shift)
-{
-  if (Shift >= 128)
-    return 0ULL;
-  if (!Shift)
-    return LowPart;
-  if (Shift >= 64)
-    {
-      LowPart = HighPart;
-      Shift -= 64;
-      HighPart = 0;
-    }
-  LowPart >>= Shift;
-  HighPart <<= (64 - Shift);
-  return (HighPart | LowPart);
-}
-
-#endif
-
+#include <intrin.h>
Index: mingw-w64-headers/crt/intrin.h
===================================================================
--- mingw-w64-headers/crt/intrin.h	(revision 6277)
+++ mingw-w64-headers/crt/intrin.h	(working copy)
@@ -1102,8 +1102,8 @@
     /* __MACHINEW64(__MINGW_EXTENSION unsigned char _BitScanForward64(unsigned __LONG32 *Index,unsigned __int64 Mask)) moved to psdk_inc/intrin-impl.h */
     /* __MACHINEW64(__MINGW_EXTENSION unsigned char _BitScanReverse64(unsigned __LONG32 *Index,unsigned __int64 Mask)) moved to psdk_inc/intrin-impl.h */
     __MACHINEIW64(_CRTIMP wchar_t *__cdecl _wcsset(wchar_t *,wchar_t))
-    __MACHINEW64(__MINGW_EXTENSION unsigned __int64 __shiftleft128(unsigned __int64 LowPart,unsigned __int64 HighPart,unsigned char Shift))
-    __MACHINEW64(__MINGW_EXTENSION unsigned __int64 __shiftright128(unsigned __int64 LowPart,unsigned __int64 HighPart,unsigned char Shift))
+    /* __MACHINEW64(__MINGW_EXTENSION unsigned __int64 __shiftleft128(unsigned __int64 LowPart,unsigned __int64 HighPart,unsigned char Shift)) moved to psdk_inc/intrin-impl.h */
+    /* __MACHINEW64(__MINGW_EXTENSION unsigned __int64 __shiftright128(unsigned __int64 LowPart,unsigned __int64 HighPart,unsigned char Shift)) moved to psdk_inc/intrin-impl.h */
     __MACHINEW64(__MINGW_EXTENSION unsigned __int64 _umul128(unsigned __int64 multiplier,unsigned __int64 multiplicand,unsigned __int64 *highproduct))
     __MACHINEW64(__MINGW_EXTENSION __int64 _mul128(__int64 multiplier,__int64 multiplicand,__int64 *highproduct))
     /* __MACHINEI(void __int2c(void)) moved to psdk_inc/intrin-impl.h */
Index: mingw-w64-headers/include/psdk_inc/intrin-impl.h
===================================================================
--- mingw-w64-headers/include/psdk_inc/intrin-impl.h	(revision 6277)
+++ mingw-w64-headers/include/psdk_inc/intrin-impl.h	(working copy)
@@ -766,6 +766,40 @@
 #define __INTRINSIC_DEFINED___movsq
 #endif /* __INTRINSIC_PROLOG */
 
+#if __INTRINSIC_PROLOG(__shiftleft128)
+unsigned __int64 __shiftleft128(unsigned __int64  LowPart, unsigned __int64 HighPart, unsigned char Shift);
+__INTRINSICS_USEINLINE
+unsigned __int64 __shiftleft128 (unsigned __int64  LowPart, unsigned __int64 HighPart, unsigned char Shift)
+{
+   unsigned __int64 ret;
+
+   __asm__ ("shld {%[Shift],%[LowPart],%[HighPart]|%[HighPart], %[LowPart], %[Shift]}" 
+      : [ret] "=r" (ret)
+      : [LowPart] "r" (LowPart), [HighPart] "0" (HighPart), [Shift] "Jc" (Shift)
+      : "cc");
+
+   return ret;
+}
+#define __INTRINSIC_DEFINED___shiftleft128
+#endif /* __INTRINSIC_PROLOG */
+
+#if __INTRINSIC_PROLOG(__shiftright128)
+unsigned __int64 __shiftright128 (unsigned __int64  LowPart, unsigned __int64 HighPart, unsigned char Shift);
+__INTRINSICS_USEINLINE
+unsigned __int64 __shiftright128 (unsigned __int64  LowPart, unsigned __int64 HighPart, unsigned char Shift)
+{
+   unsigned __int64 ret;
+
+   __asm__ ("shrd {%[Shift],%[HighPart],%[LowPart]|%[LowPart], %[HighPart], %[Shift]}" 
+      : [ret] "=r" (ret)
+      : [LowPart] "0" (LowPart), [HighPart] "r" (HighPart), [Shift] "Jc" (Shift)
+      : "cc");
+
+   return ret;
+}
+#define __INTRINSIC_DEFINED___shiftright128
+#endif /* __INTRINSIC_PROLOG */
+
 #endif /* __x86_64__ */
 
 /* ***************************************************** */
------------------------------------------------------------------------------
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

Reply via email to