Skip to content

Commit

Permalink
Merge GH #3534 Small cleanups for mul128.h
Browse files Browse the repository at this point in the history
  • Loading branch information
randombit committed Apr 29, 2023
2 parents 7427ef8 + dff2a52 commit 8a8dec9
Showing 1 changed file with 6 additions and 16 deletions.
22 changes: 6 additions & 16 deletions src/lib/utils/mul128.h
Original file line number Diff line number Diff line change
Expand Up @@ -12,24 +12,15 @@

#if defined(BOTAN_BUILD_COMPILER_IS_MSVC) && defined(BOTAN_TARGET_CPU_HAS_NATIVE_64BIT)
#include <intrin.h>
#if defined(_M_ARM64)
#pragma intrinsic(__umulh)
#else
#pragma intrinsic(_umul128)
#endif
#endif

namespace Botan {

#if defined(__SIZEOF_INT128__) && defined(BOTAN_TARGET_CPU_HAS_NATIVE_64BIT)
#define BOTAN_TARGET_HAS_NATIVE_UINT128

// Prefer TI mode over __int128 as GCC rejects the latter in pendantic mode
#if defined(__GNUG__)
typedef unsigned int uint128_t __attribute__((mode(TI)));
#else
typedef unsigned __int128 uint128_t;
#endif
// GCC complains if this isn't marked with __extension__
__extension__ typedef unsigned __int128 uint128_t;
#endif

/**
Expand All @@ -43,13 +34,12 @@ inline void mul64x64_128(uint64_t a, uint64_t b, uint64_t* lo, uint64_t* hi)
*hi = (r >> 64) & 0xFFFFFFFFFFFFFFFF;
*lo = (r ) & 0xFFFFFFFFFFFFFFFF;

#elif defined(BOTAN_BUILD_COMPILER_IS_MSVC) && defined(BOTAN_TARGET_CPU_HAS_NATIVE_64BIT)
#if defined(_M_ARM64)
#elif defined(BOTAN_BUILD_COMPILER_IS_MSVC) && defined(BOTAN_TARGET_ARCH_IS_X86_64)
*lo = _umul128(a, b, hi);

#elif defined(BOTAN_BUILD_COMPILER_IS_MSVC) && defined(BOTAN_TARGET_ARCH_IS_ARM64)
*lo = a * b;
*hi = __umulh(a, b);
#else
*lo = _umul128(a, b, hi);
#endif

#elif defined(BOTAN_USE_GCC_INLINE_ASM) && defined(BOTAN_TARGET_ARCH_IS_X86_64)
asm("mulq %3"
Expand Down

0 comments on commit 8a8dec9

Please sign in to comment.