From 0b001f5f36579e8aea07efa5af139ca18dad9505 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Branimir=20Karad=C5=BEi=C4=87?= Date: Mon, 27 Jul 2026 15:08:49 -0700 Subject: [PATCH] MSVC: Added ARM64 target. (#412) --- .github/workflows/main.yml | 20 +++++++++++--------- include/bx/inline/math.inl | 7 ++++--- include/bx/platform.h | 3 ++- include/bx/simd_t.h | 2 +- scripts/toolchain.lua | 13 ++++++++++++- tests/vsnprintf_test.cpp | 4 +++- 6 files changed, 33 insertions(+), 16 deletions(-) diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index a8b9294..2c640d1 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -14,18 +14,20 @@ jobs: fail-fast: true matrix: include: [ - { config: Debug, platform: x64, bindir: 'win64_vs2022', genie-action: 'vs2022', solution-ext: 'sln' }, - { config: Release, platform: x64, bindir: 'win64_vs2022', genie-action: 'vs2022', solution-ext: 'sln' }, + { config: Debug, platform: x64, runs-on: windows-latest, bindir: 'win64_vs2022', genie-action: 'vs2022', solution-ext: 'sln' }, + { config: Release, platform: x64, runs-on: windows-latest, bindir: 'win64_vs2022', genie-action: 'vs2022', solution-ext: 'sln' }, + { config: Debug, platform: ARM64, runs-on: windows-11-arm, bindir: 'arm64_vs2022', genie-action: 'vs2022', solution-ext: 'sln' }, + { config: Release, platform: ARM64, runs-on: windows-11-arm, bindir: 'arm64_vs2022', genie-action: 'vs2022', solution-ext: 'sln' }, # { config: Debug, platform: x64, bindir: 'win64_vs2026', genie-action: 'vs2026', solution-ext: 'slnx' }, # { config: Release, platform: x64, bindir: 'win64_vs2026', genie-action: 'vs2026', solution-ext: 'slnx' }, ] name: msvc-${{ matrix.config }}-${{ matrix.platform }} - runs-on: windows-latest + runs-on: ${{ matrix.runs-on }} steps: - name: Checkout bx uses: actions/checkout@v6 with: - repository: bkaradzic/bx + repository: ${{ github.repository }} path: bx - name: Prepare uses: microsoft/setup-msbuild@v2 @@ -54,7 +56,7 @@ jobs: - name: Checkout bx uses: actions/checkout@v6 with: - repository: bkaradzic/bx + repository: ${{ github.repository }} path: bx - name: Prepare uses: msys2/setup-msys2@v2 @@ -90,7 +92,7 @@ jobs: - name: Checkout bx uses: actions/checkout@v6 with: - repository: bkaradzic/bx + repository: ${{ github.repository }} path: bx - name: Build run: | @@ -115,7 +117,7 @@ jobs: - name: Checkout bx uses: actions/checkout@v6 with: - repository: bkaradzic/bx + repository: ${{ github.repository }} path: bx - name: Build run: | @@ -140,7 +142,7 @@ jobs: - name: Checkout bx uses: actions/checkout@v6 with: - repository: bkaradzic/bx + repository: ${{ github.repository }} path: bx - uses: nttld/setup-ndk@v1 id: setup-ndk @@ -169,7 +171,7 @@ jobs: - name: Checkout bx uses: actions/checkout@v6 with: - repository: bkaradzic/bx + repository: ${{ github.repository }} path: bx - uses: mymindstorm/setup-emsdk@v14 with: diff --git a/include/bx/inline/math.inl b/include/bx/inline/math.inl index aa262ca..4c913a7 100644 --- a/include/bx/inline/math.inl +++ b/include/bx/inline/math.inl @@ -357,9 +357,10 @@ namespace bx const float absA = abs(aa); const float cosA = cos(absA); const float cosASq = square(cosA); - const float tmp0 = sqrt(1.0f - cosASq); - const float tmp1 = aa > 0.0f && aa < kPi ? 1.0f : -1.0f; - const float sinA = mul(tmp0, tmp1); + const float tmp0 = max(0.0f, 1.0f - cosASq); + const float tmp1 = sqrt(tmp0); + const float tmp2 = aa > 0.0f && aa < kPi ? 1.0f : -1.0f; + const float sinA = mul(tmp1, tmp2); _outSinApprox = sinA; _outCos = cosA; diff --git a/include/bx/platform.h b/include/bx/platform.h index ea699b2..1365f50 100644 --- a/include/bx/platform.h +++ b/include/bx/platform.h @@ -85,7 +85,8 @@ // http://sourceforge.net/apps/mediawiki/predef/index.php?title=Architectures #if defined(__arm__) \ || defined(__aarch64__) \ - || defined(_M_ARM) + || defined(_M_ARM) \ + || defined(_M_ARM64) # undef BX_CPU_ARM # define BX_CPU_ARM 1 # define BX_CACHE_LINE_SIZE 64 diff --git a/include/bx/simd_t.h b/include/bx/simd_t.h index 769b416..4f1c667 100644 --- a/include/bx/simd_t.h +++ b/include/bx/simd_t.h @@ -72,7 +72,7 @@ # define BX_SIMD_AVX 1 #endif // -#if defined(__SSE2__) || (BX_COMPILER_MSVC && (BX_ARCH_64BIT || _M_IX86_FP >= 2) ) +#if BX_CPU_X86 && (defined(__SSE2__) || (BX_COMPILER_MSVC && (BX_ARCH_64BIT || _M_IX86_FP >= 2) ) ) # include # include // SSE4.1 minspec is SSE4.2 so always available # if defined(__SSE4_2__) || BX_COMPILER_MSVC diff --git a/scripts/toolchain.lua b/scripts/toolchain.lua index 2cbffea..feb2b77 100644 --- a/scripts/toolchain.lua +++ b/scripts/toolchain.lua @@ -435,6 +435,9 @@ function toolchain(_buildDir, _libDir) action.vstudio.windowsTargetPlatformMinVersion = windowsPlatform end + -- Windows on ARM64 is a desktop target for MSVC. + platforms { "ARM64" } + if (_ACTION .. "-clang") == _OPTIONS["vs"] then if "vs2017-clang" == _OPTIONS["vs"] then premake.vstudio.toolset = "v141_clang_c2" @@ -548,7 +551,7 @@ function toolchain(_buildDir, _libDir) "-Wno-tautological-constant-compare", } - configuration { "vs*", "not NX32", "not NX64" } + configuration { "vs*", "not ARM64", "not NX32", "not NX64" } flags { "EnableAVX", } @@ -592,6 +595,14 @@ function toolchain(_buildDir, _libDir) path.join(_libDir, "lib/win64_" .. _ACTION), } + configuration { "ARM64", "vs*" } + defines { "_WIN64" } + targetdir (path.join(_buildDir, "arm64_" .. _ACTION, "bin")) + objdir (path.join(_buildDir, "arm64_" .. _ACTION, "obj")) + libdirs { + path.join(_libDir, "lib/arm64_" .. _ACTION), + } + configuration { "x32", "vs2017" } targetdir (path.join(_buildDir, "win32_" .. _ACTION, "bin")) objdir (path.join(_buildDir, "win32_" .. _ACTION, "obj")) diff --git a/tests/vsnprintf_test.cpp b/tests/vsnprintf_test.cpp index 3c218cf..f63987a 100644 --- a/tests/vsnprintf_test.cpp +++ b/tests/vsnprintf_test.cpp @@ -226,7 +226,9 @@ TEST_CASE("Format %f", "[string][printf]") REQUIRE(test("4.1", "%.1f", 4.1) ); REQUIRE(test("0.00", "%.2f", 1e-4) ); REQUIRE(test("-5.20", "%+4.2f", -5.2) ); - REQUIRE(test("0.0 ", "%-10.1f", 0.) ); + + volatile double zero = 0.0; // /fp:fast allows the compiler to disregard the sign of zero. + REQUIRE(test("0.0 ", "%-10.1f", zero) ); REQUIRE(test("-8.8888888800", "%.10f", -8.88888888) ); REQUIRE(test("880.0888888800", "%.10f", 880.08888888) ); REQUIRE(test("100056789.0", "%.1f", 100056789.0) );