Skip to content

Commit

Permalink
Enable compiles with clang-cl on windows
Browse files Browse the repository at this point in the history
  • Loading branch information
williamyang98 committed Aug 1, 2023
1 parent 70c0bb5 commit cce9484
Show file tree
Hide file tree
Showing 8 changed files with 64 additions and 85 deletions.
14 changes: 10 additions & 4 deletions .github/workflows/x86-windows.yml
Original file line number Diff line number Diff line change
Expand Up @@ -35,23 +35,29 @@ jobs:
with:
submodules: recursive

- uses: ilammy/msvc-dev-cmd@v1
with:
arch: x64

- name: Setup vcpkg with caching
uses: friendlyanon/setup-vcpkg@v1
with:
committish: c9f906558f9bb12ee9811d6edc98ec9255c6cda5
path: vcpkg

- name: Configure CMake
run: cmake -B ${{github.workspace}}/build-windows -DCMAKE_BUILD_TYPE=${{env.BUILD_TYPE}} -DCMAKE_TOOLCHAIN_FILE:STRING=${{github.workspace}}/vcpkg/scripts/buildsystems/vcpkg.cmake -DCMAKE_EXPORT_COMPILE_COMMANDS:BOOL=TRUE -A"x64" -G"Visual Studio 17 2022"
shell: bash
run: VCPKG_ROOT=./vcpkg ./toolchains/windows/cmake_configure.sh

- name: Build
run: cmake --build ${{github.workspace}}/build-windows --config ${{env.BUILD_TYPE}}
shell: bash
run: ninja -C build-windows

- name: Copy files (Release)
- name: Copy files
shell: bash
run: ./toolchains/windows/create_package.sh

- name: Upload files (Release)
- name: Upload files
uses: actions/upload-artifact@v3
with:
name: dab_radio_windows_x64
Expand Down
8 changes: 4 additions & 4 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ find_package(implot REQUIRED)
set(viterbi_DIR ${CMAKE_CURRENT_SOURCE_DIR}/vendor/viterbi_decoder)
find_package(viterbi CONFIG REQUIRED)

if(DEFINED WIN32)
if(WIN32)
set(rtlsdr_DIR ${CMAKE_CURRENT_SOURCE_DIR}/vendor/librtlsdr)
find_package(rtlsdr CONFIG REQUIRED)
set(RTLSDR_LIBS rtlsdr::rtlsdr)
Expand All @@ -23,7 +23,7 @@ else()
set(RTLSDR_LIBS PkgConfig::rtlsdr)
endif()

if(MSVC)
if(WIN32)
find_package(portaudio CONFIG REQUIRED)
find_package(FFTW3f CONFIG REQUIRED)
set(PORTAUDIO_LIBS portaudio)
Expand All @@ -39,15 +39,15 @@ endif()
target_compile_definitions(easyloggingpp PRIVATE ELPP_THREAD_SAFE)

# for posix threads
if(NOT DEFINED WIN32)
if(NOT WIN32)
find_package(Threads REQUIRED)
add_compile_options(-pthread)
link_libraries(Threads::Threads)
endif()

# simd and math compile options
if(NOT ${CMAKE_SYSTEM_PROCESSOR} STREQUAL "aarch64")
if(DEFINED MSVC)
if(MSVC)
add_compile_definitions(_CRT_SECURE_NO_WARNINGS)
add_compile_definitions(_SILENCE_NONFLOATING_COMPLEX_DEPRECATION_WARNING)
# for msvc multi processor compilation
Expand Down
8 changes: 6 additions & 2 deletions src/ofdm/dsp/apply_pll.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -50,9 +50,13 @@ void create_dt_step_simd(float* arr, const size_t K, const float dt) {
}
}

#if defined(_MSC_VER) && !defined(__clang__)
#define IS_INTEL_SVML 1
#endif

#if defined(__SSE3__)

#if !defined(_MSC_VER)
#if !IS_INTEL_SVML
#define USE_SSE_AUTO
#define SSE_MATHFUN_WITH_CODE
#include "./x86/sse_mathfun.h"
Expand Down Expand Up @@ -104,7 +108,7 @@ float apply_pll_sse3(

#if defined(__AVX__)

#if !defined(_MSC_VER)
#if !IS_INTEL_SVML
#include "./x86/avx_mathfun.h"
#define _mm256_cos_ps(x) cos256_ps(x)
#endif
Expand Down
10 changes: 5 additions & 5 deletions src/ofdm/dsp/x86/sse_mathfun.h
Original file line number Diff line number Diff line change
Expand Up @@ -200,8 +200,8 @@ _PS_CONST(cephes_log_q2, 0.693359375);
// _PD_CONST_TYPE(mant_mask, int, 0x7f800000);
// _PD_CONST_TYPE(inv_mant_mask, int, ~0x7f800000);

_PD_CONST_TYPE(sign_mask, uint64_t, 0x8000000000000000LL);
_PD_CONST_TYPE(inv_sign_mask, uint64_t, ~0x8000000000000000LL);
_PD_CONST_TYPE(sign_mask, uint64_t, 0x8000000000000000ULL);
_PD_CONST_TYPE(inv_sign_mask, uint64_t, ~0x8000000000000000ULL);

#endif

Expand Down Expand Up @@ -1307,18 +1307,18 @@ static inline double scalCumSumSumSq( double *xa, int n, double *sumSQ )

# if defined(__x86_64__) || defined(x86_64) || defined(_LP64)
// static inline v2df _mm_abs_pd( v2df a )
// { _PD_CONST_TYPE(abs_mask, uint64_t, ~0x8000000000000000LL);
// { _PD_CONST_TYPE(abs_mask, uint64_t, ~0x8000000000000000ULL);
// return _mm_and_pd(a, *(v2df*)_pd_abs_mask);
// }
/*!
SSE2 'intrinsic' to take the absolute value of a
*/
static inline v2df _mm_abs_pd( v2df a )
{ const static uint64_t am1[2] = {~0x8000000000000000LL,~0x8000000000000000LL};
{ const static uint64_t am1[2] = {~0x8000000000000000ULL,~0x8000000000000000ULL};
return _mm_and_pd(a, *((v2df*)am1) );
}
static inline double _mm_abs_sd( double a )
{ const static uint64_t am2 = {~0x8000000000000000LL};
{ const static uint64_t am2 = {~0x8000000000000000ULL};
v2si r = _mm_and_si64( *((v2si*)&a), *((v2si*)&am2) );
return *((double*) &r);
}
Expand Down
21 changes: 18 additions & 3 deletions toolchains/windows/README.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,19 @@
## Instructions
1. <code>./toolchains/windows/cmake_configure.bat</code>
2. <code>./toolchains/windows/build.bat</code>
3. <code>./build-windows/\<program\></code>
1. ```./toolchains/windows/cmake_configure.sh```
2. ```ninja -C build-windows```
3. ```./build-windows/\<program\>```

## Compiling with clang-cl
Compiling with clang gives better performing binaries compared to MSVC cl.

1. Setup x64 developer environment for C++ for MSVC.
2. Make sure clang for C++ is installed through Visual Studio.
3. Enter a bash shell.
4. ```CC=clang CXX=clang++ ./toolchains/windows/cmake_configure.sh```

## Compiling with different SIMD flags
The default windows build compiles with AVX2 instructions. If your CPU doesn't support these then you will have to modify the scripts.

```vcpkg.json``` contains ```fftw3f``` which uses the ```avx2``` feature. Change this to ```[avx, sse2, sse]```.

```CMakeLists.txt``` contains ```/arch:AVX2```. Change this to ```/arch:AVX``` or remove this compiler option.
50 changes: 0 additions & 50 deletions toolchains/windows/build.bat

This file was deleted.

17 changes: 0 additions & 17 deletions toolchains/windows/cmake_configure.bat

This file was deleted.

21 changes: 21 additions & 0 deletions toolchains/windows/cmake_configure.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
#!/bin/sh
if [[ -z "$VCPKG_ROOT" ]]; then
TOOLCHAIN_FILE="C:/tools/vcpkg/scripts/buildsystems/vcpkg.cmake"
else
TOOLCHAIN_FILE="$VCPKG_ROOT/scripts/buildsystems/vcpkg.cmake"
fi

if [[ -z "$BUILD_OUT" ]]; then
BUILD_OUT="build-windows"
fi

if [[ -z "$BUILD_TYPE" ]]; then
BUILD_TYPE="Release"
fi

cmake .\
-B $BUILD_OUT\
-G Ninja\
-DCMAKE_BUILD_TYPE:STRING=$BUILD_TYPE\
-DCMAKE_TOOLCHAIN_FILE:STRING=$TOOLCHAIN_FILE\
-DCMAKE_EXPORT_COMPILE_COMMANDS:BOOL=TRUE

0 comments on commit cce9484

Please sign in to comment.