Skip to content

CompilerTestCodeGenFloatingPointEnvironment fails on ARM64x when run under x64 emulation #8793

Description

Description
CodeGenFloatingPointEnvironment is a win32 only test as guarded by defines here:

TEST_F(CompilerTest, CodeGenFloatingPointEnvironment) { VERIFY_IS_TRUE(true); }

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugBug, regression, crashneeds-triageAwaiting triage

    Type

    No type

    Projects

    Status
    No status

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions