Skip to content

Commit

Permalink
clang-cl: disable __umulh/__mulh intrinsics prior to VS2022
Browse files Browse the repository at this point in the history
  • Loading branch information
adbancroft committed Oct 16, 2024
1 parent b132def commit e3a6263
Showing 1 changed file with 8 additions and 4 deletions.
12 changes: 8 additions & 4 deletions libdivide.h
Original file line number Diff line number Diff line change
Expand Up @@ -34,9 +34,13 @@
#include <arm_neon.h>
#endif

// Clang-cl prior to Visual Studio 2022 doesn't include __umulh/__mulh intrinsics
#if defined(_MSC_VER) && defined(LIBDIVIDE_X86_64) && (!defined(__clang__) || _MSC_VER>1930)
#define LIBDIVIDE_X64_INTRINSICS
#endif

#if defined(_MSC_VER)
// Clang-cl prior to Visual Studio 2022 barfs on this
#if !defined(__clang__) || _MSC_VER>1930
#if defined(LIBDIVIDE_X64_INTRINSICS)
#include <intrin.h>
#endif
#pragma warning(push)
Expand Down Expand Up @@ -328,7 +332,7 @@ static LIBDIVIDE_INLINE int32_t libdivide_mullhi_s32(int32_t x, int32_t y) {
}

static LIBDIVIDE_INLINE uint64_t libdivide_mullhi_u64(uint64_t x, uint64_t y) {
#if defined(LIBDIVIDE_VC) && defined(LIBDIVIDE_X86_64)
#if defined(LIBDIVIDE_X64_INTRINSICS)
return __umulh(x, y);
#elif defined(HAS_INT128_T)
__uint128_t xl = x, yl = y;
Expand All @@ -354,7 +358,7 @@ static LIBDIVIDE_INLINE uint64_t libdivide_mullhi_u64(uint64_t x, uint64_t y) {
}

static LIBDIVIDE_INLINE int64_t libdivide_mullhi_s64(int64_t x, int64_t y) {
#if defined(LIBDIVIDE_VC) && defined(LIBDIVIDE_X86_64)
#if defined(LIBDIVIDE_X64_INTRINSICS)
return __mulh(x, y);
#elif defined(HAS_INT128_T)
__int128_t xl = x, yl = y;
Expand Down

0 comments on commit e3a6263

Please sign in to comment.