From 1b9535bdb886a7adfa5d62ed8401c698f682453e Mon Sep 17 00:00:00 2001 From: dword64 <74870446+dword64@users.noreply.github.com> Date: Wed, 1 Apr 2026 17:46:21 +0200 Subject: [PATCH] add ci build parallelism & cross platform intrinsics --- .github/workflows/build.yml | 12 +++++++++--- VTIL-Common/util/intrinsics.hpp | 29 ++++++++++++++++++++++++++++- VTIL-Tests/main.cpp | 5 +++++ 3 files changed, 42 insertions(+), 4 deletions(-) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index c336d81..96aafb7 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -10,7 +10,13 @@ jobs: strategy: fail-fast: false matrix: - os: [windows-2022, ubuntu-24.04, macos-14] + include: + - os: windows-2022 + build_parallel: 4 + - os: ubuntu-24.04 + build_parallel: 2 + - os: macos-14 + build_parallel: 2 env: BUILD_TYPE: Release steps: @@ -37,8 +43,8 @@ jobs: - name: Build run: | - cmake -S . -B build -G Ninja -DCMAKE_BUILD_TYPE=${{ env.BUILD_TYPE }} -DVTIL_BUILD_TESTS=ON - cmake --build build --config ${{ env.BUILD_TYPE }} --parallel + cmake -S . -B build -G Ninja -DCMAKE_BUILD_TYPE=${{ env.BUILD_TYPE }} -DVTIL_BUILD_TESTS=ON -DCMAKE_VERBOSE_MAKEFILE:BOOL=ON + cmake --build build --config ${{ env.BUILD_TYPE }} --parallel ${{ matrix.build_parallel }} --verbose - name: Test run: | diff --git a/VTIL-Common/util/intrinsics.hpp b/VTIL-Common/util/intrinsics.hpp index eda78d5..c97dd56 100644 --- a/VTIL-Common/util/intrinsics.hpp +++ b/VTIL-Common/util/intrinsics.hpp @@ -57,16 +57,32 @@ #define unreachable() __assume(0) #define FUNCTION_NAME __FUNCSIG__ #else - #include + #if defined(__i386__) || defined(__x86_64__) + #include + #endif + #define unreachable() __builtin_unreachable() #define __forceinline __attribute__((always_inline)) #define _AddressOfReturnAddress() ((void*)__builtin_frame_address(0)) #define FUNCTION_NAME __PRETTY_FUNCTION__ + // _mm_pause is x86-specific; provide a lightweight fallback on other targets. + #if !defined(__i386__) && !defined(__x86_64__) + __forceinline static void _mm_pause() + { + #if defined(__aarch64__) || defined(__arm__) + __asm__ __volatile__("yield"); + #else + __asm__ __volatile__("" ::: "memory"); + #endif + } + #endif + // Declare _?mul128 // __forceinline static uint64_t _umul128( uint64_t _Multiplier, uint64_t _Multiplicand, uint64_t* _HighProduct ) { +#if defined(__x86_64__) uint64_t LowProduct; uint64_t HighProduct; @@ -76,10 +92,16 @@ *_HighProduct = HighProduct; return LowProduct; +#else + unsigned __int128 product = (unsigned __int128) _Multiplier * (unsigned __int128) _Multiplicand; + *_HighProduct = (uint64_t) ( product >> 64 ); + return (uint64_t) product; +#endif } __forceinline static int64_t _mul128( int64_t _Multiplier, int64_t _Multiplicand, int64_t* _HighProduct ) { +#if defined(__x86_64__) int64_t LowProduct; int64_t HighProduct; @@ -89,6 +111,11 @@ *_HighProduct = HighProduct; return LowProduct; +#else + __int128 product = (__int128) _Multiplier * (__int128) _Multiplicand; + *_HighProduct = (int64_t) ( product >> 64 ); + return (int64_t) product; +#endif } // Declare _?mulh diff --git a/VTIL-Tests/main.cpp b/VTIL-Tests/main.cpp index 77be614..1ac4575 100644 --- a/VTIL-Tests/main.cpp +++ b/VTIL-Tests/main.cpp @@ -1,2 +1,7 @@ +#if defined(__linux__) +// on some glibc toolchains SIGSTKSZ is not a constant expression... +#define DOCTEST_CONFIG_NO_POSIX_SIGNALS +#endif + #define DOCTEST_CONFIG_IMPLEMENT_WITH_MAIN #include "doctest.h" \ No newline at end of file