CompilerTestCodeGenFloatingPointEnvironment fails on ARM64x when run under x64 emulation

Open Beginner friendly
#8,793 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Assessment

Difficulty
2/5
Estimated time
1-3 hours
Newbie friendliness
72/100
Issue type
Bug
Clarity
Mostly clear
Activity status
Quiet
Tech stack
cpp

Research direction

Start in tools/clang/unittests/HLSL/CompilerTest.cpp at CompilerTest::CodeGenFloatingPointEnvironment and review its existing Win32 guards. Run the test under x64 emulation on Windows ARM64 and verify that runtime detection skips only that case while preserving compatibility on older Windows versions and other platforms.

Written by the indexing model from the issue text.

Description

bug needs-triage

Description
CodeGenFloatingPointEnvironment is a win32 only test as guarded by defines here:
https://github.com/microsoft/DirectXShaderCompiler/blob/c1104ee6ff393378f9d75f3326d5c56fac8e95b7/tools/clang/unittests/HLSL/CompilerTest.cpp#L4405

This doesn't appropriately guard against running the x64 version of this test on an ARM64 machine though.
So, this test fails in arm64x pipelines when targeting x64.

StartGroup: CompilerTest::CodeGenFloatingPointEnvironment

Verify: IsTrue(_controlfp_s(&fpOriginal, 0, 0) == 0)

Verify: IsTrue(_controlfp_s(&fpSavedState, 0, 0) == 0)

Verify: IsTrue(_controlfp_s(&newValue, fpTestState, fpTestMask) == 0)

Verify: IsTrue(_controlfp_s(&fpBeforeCompile, 0, 0) == 0)

Error: Verify: AreEqual((fpBeforeCompile & fpTestMask), fpTestState) - Values (34079263, 34079255) [File: C:\__w\1\s\DirectXShaderCompiler\tools\clang\unittests\HLSL\CompilerTest.cpp, 
Function: CompilerTest::CodeGenFloatingPointEnvironment, Line: 4377]

EndGroup: CompilerTest::CodeGenFloatingPointEnvironment [Failed]

Environment

  • DXC version: 1.9.2607
  • Host Operating System: Windows ARM64

How to fix
We will need to add runtime detection to skip this test. Copilot had a few suggestions that wouldn't work. And then arrived at this, which I think will work. But we'll want to verify it.
https://learn.microsoft.com/en-us/windows/win32/api/wow64apiset/nf-wow64apiset-iswow64process2

static bool IsX64EmulatedOnArm64() {
  using Fn = BOOL(WINAPI *)(HANDLE, USHORT *, USHORT *);

  auto fn = reinterpret_cast<Fn>(GetProcAddress(
      GetModuleHandleW(L"kernel32.dll"), "IsWow64Process2"));
  if (!fn)
    return false;

  USHORT processMachine = 0;
  USHORT nativeMachine = 0;
  return fn(GetCurrentProcess(), &processMachine, &nativeMachine) &&
         processMachine == IMAGE_FILE_MACHINE_AMD64 &&
         nativeMachine == IMAGE_FILE_MACHINE_ARM64;
}

Dynamic lookup preserves compatibility with Windows versions predating  IsWow64Process2 . This detects the exact failing case: x64 TAEF running through emulation on ARM64.
Dominant language
C++
Stars
3.7k
Forks
900
Avg merge
2d 14h
Merged PRs (30d)
39

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from microsoft/DirectXShaderCompiler

All issues in microsoft/DirectXShaderCompiler

Similar issues

More C++ issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.