]> granicus.if.org Git - clang/commitdiff
Implement __umulh with __int128 arithmetic
authorReid Kleckner <reid@kleckner.net>
Wed, 3 Dec 2014 23:36:14 +0000 (23:36 +0000)
committerReid Kleckner <reid@kleckner.net>
Wed, 3 Dec 2014 23:36:14 +0000 (23:36 +0000)
Use the same approach as _umul128, but just return the high half.

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@223316 91177308-0d34-0410-b5e6-96231b3b80d8

lib/Headers/Intrin.h

index 8cd4a0dbf0107092a5e91407028c23742edd2645..84bc4303a133cb245c48e1c062921445ea2e62b8 100644 (file)
@@ -330,7 +330,6 @@ unsigned __int64 __shiftright128(unsigned __int64 _LowPart,
                                  unsigned char _Shift);
 static __inline__
 void __stosq(unsigned __int64 *, unsigned __int64, size_t);
-unsigned __int64 __umulh(unsigned __int64, unsigned __int64);
 unsigned char __vmx_on(unsigned __int64 *);
 unsigned char __vmx_vmclear(unsigned __int64 *);
 unsigned char __vmx_vmlaunch(void);
@@ -429,6 +428,12 @@ _umul128(unsigned __int64 _Multiplier, unsigned __int64 _Multiplicand,
   *_HighProduct = _FullProduct >> 64;
   return _FullProduct;
 }
+static __inline__ unsigned __int64 __attribute__((__always_inline__, __nodebug__))
+__umulh(unsigned __int64 _Multiplier, unsigned __int64 _Multiplicand) {
+  unsigned __int128 _FullProduct =
+      (unsigned __int128)_Multiplier * (unsigned __int128)_Multiplicand;
+  return _FullProduct >> 64;
+}
 void __cdecl _xrstor64(void const *, unsigned __int64);
 void __cdecl _xsave64(void *, unsigned __int64);
 void __cdecl _xsaveopt64(void *, unsigned __int64);