Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix building with Windows SDK and Clang-CL #7337

Merged
merged 5 commits into from
Aug 15, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 23 additions & 0 deletions .github/workflows/msvc-static-build-clang-cl.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
name: MSVC Clang-CL Static Build

on:
push:
pull_request:

permissions:
contents: read # to fetch code (actions/checkout)

jobs:
build:
runs-on: windows-2019
env:
BUILD_TYPE: Release
steps:
- name: Checkout Repo
uses: actions/checkout@v4

- name: Build
run: |
cmake -B build -DCMAKE_BUILD_TYPE=${{ env.BUILD_TYPE }} -DZ3_BUILD_LIBZ3_SHARED=OFF -DZ3_BUILD_LIBZ3_MSVC_STATIC=ON -T ClangCL -DCMAKE_C_FLAGS="/EHsc" -DCMAKE_CXX_FLAGS="/EHsc"
cmake --build build --config ${{ env.BUILD_TYPE }} --parallel

22 changes: 14 additions & 8 deletions src/util/mpz.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -46,10 +46,14 @@ Revision History:
#define LEHMER_GCD
#endif


#if defined(__GNUC__)
#ifdef __has_builtin
#define HAS_BUILTIN(X) __has_builtin(X)
#else
#define HAS_BUILTIN(X) 0
#endif
#if HAS_BUILTIN(__builtin_ctz)
#define _trailing_zeros32(X) __builtin_ctz(X)
#elif defined(_WINDOWS) && (defined(_M_X86) || (defined(_M_X64) && !defined(_M_ARM64EC)))
#elif defined(_WINDOWS) && (defined(_M_X86) || (defined(_M_X64) && !defined(_M_ARM64EC))) && !defined(__clang__)
// This is needed for _tzcnt_u32 and friends.
#include <immintrin.h>
#define _trailing_zeros32(X) _tzcnt_u32(X)
Expand All @@ -62,11 +66,11 @@ static uint32_t _trailing_zeros32(uint32_t x) {
#endif

#if (defined(__LP64__) || defined(_WIN64)) && defined(_M_X64) && !defined(_M_ARM64EC)
#if defined(__GNUC__)
#define _trailing_zeros64(X) __builtin_ctzll(X)
#else
#define _trailing_zeros64(X) _tzcnt_u64(X)
#endif
#if HAS_BUILTIN(__builtin_ctzll)
#define _trailing_zeros64(X) __builtin_ctzll(X)
#elif !defined(__clang__)
#define _trailing_zeros64(X) _tzcnt_u64(X)
#endif
#else
static uint64_t _trailing_zeros64(uint64_t x) {
uint64_t r = 0;
Expand All @@ -75,6 +79,8 @@ static uint64_t _trailing_zeros64(uint64_t x) {
}
#endif

#undef HAS_BUILTIN

unsigned trailing_zeros(uint32_t x) {
return static_cast<unsigned>(_trailing_zeros32(x));
}
Expand Down
Loading