Skip to content

Guard CPUID/rdtsc for non-x86 and add stubs - #182

Open
chemiskyy wants to merge 1 commit into
romeric:masterfrom
3MAH:master
Open

Guard CPUID/rdtsc for non-x86 and add stubs#182
chemiskyy wants to merge 1 commit into
romeric:masterfrom
3MAH:master

Conversation

@chemiskyy

Copy link
Copy Markdown

Proposed fix for ARM:

Fastor/config/cpuid.h — The CPUID class constructor uses x86 cpuid asm in an unguarded #else. Fix: gate it with #elif defined(x86_64) || defined(i386)
and add an #else that zeros the registers on ARM.

Fastor/util/timeit.h — The rdtsc() / rdtsc_begin() / rdtsc_end() functions use x86 rdtsc/rdtscp asm in an unguarded #else. Fix: same #elif x86 gate, plus ARM
stubs that return 0.

Add explicit x86/x86_64 guards and non-x86 fallbacks for CPUID and rdtsc. In Fastor/config/cpuid.h, avoid using inline asm on non-x86 targets by checking for __x86_64__/__i386__ and provide a safe zeroed fallback for regs otherwise. In Fastor/util/timeit.h, restrict the GCC inline-asm rdtsc implementation to x86 and add ARM/non-x86 stub implementations that return 0. These changes prevent build failures on non-x86 platforms and make the codebase more portable.
mitrlk added a commit to mitrlk/mitrlk-Marmot that referenced this pull request Aug 10, 2026
Mirrors build_ubuntu, but on GitHub's Apple Silicon runner (macos-latest is
arm64 since macos-14). This exercises clang/libc++ rather than GCC/libstdc++,
which is what makes the three fixes in this PR necessary — all of them are
accepted silently by libstdc++ and rejected or trapped by libc++.

Without this job the same problems can reappear unnoticed, since nothing else
in CI compiles Marmot with libc++.

CC/CXX are pinned to clang/clang++ rather than left to CMake's default: the
macOS runners also ship Homebrew GCC, and silently picking that up would build
against libstdc++ and defeat the purpose of the job while still reporting
green. No compiler version is pinned, so the job tracks whatever Apple clang
the runner provides. A first step prints the toolchain so the log records
which compiler actually ran.

One deviation from build_ubuntu: Fastor is cloned from an arm64-compatible
fork rather than upstream V0.6.4. Upstream Fastor does not compile on arm64 —
it reaches x86 `cpuid` and `rdtsc` inline assembly on every non-Windows
platform, and its scalar fallback backend has further defects that only
surface off x86. The fork is upstream `master` plus the minimal patch fixing
exactly that, and nothing else. Those fixes are offered upstream in
romeric/Fastor#182 and #183; the step carries a comment to switch back once
either is merged.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
mitrlk added a commit to mitrlk/mitrlk-Marmot that referenced this pull request Aug 10, 2026
Mirrors build_ubuntu, but on GitHub's Apple Silicon runner (macos-latest is
arm64 since macos-14). This exercises clang/libc++ rather than GCC/libstdc++,
which is what makes the three fixes in this PR necessary — all of them are
accepted silently by libstdc++ and rejected or trapped by libc++.

Without this job the same problems can reappear unnoticed, since nothing else
in CI compiles Marmot with libc++.

Deviations from build_ubuntu, each deliberate:

* The autodiff build directory is called `build-cmake`, not `build`. autodiff
  ships a Bazel `BUILD` file in its repository root, and the macOS filesystem
  is case-insensitive, so `mkdir build` fails with "File exists" and `cd build`
  with "Not a directory". On Linux the two names are distinct, which is why
  build_ubuntu is unaffected.

* `shell: bash -leo pipefail {0}` rather than `bash -l {0}`. Specifying a
  shell replaces GitHub's default `bash -e {0}`, so `-l` alone silently drops
  errexit and only the last command of a `run:` block decides the step result.
  Since the dependency steps end in `cd ../..`, the autodiff failure above was
  reported as success and only surfaced later as a confusing "autodiff include
  directory not found". The same pattern is present in build_ubuntu, where it
  is currently latent because those steps all succeed.

* `ctest --no-tests=error`. ctest exits 0 when no tests exist, so a build that
  produced no test binaries at all still reported success.

* CC/CXX pinned to clang/clang++ rather than left to CMake's default: the
  macOS runners also ship Homebrew GCC, and silently picking that up would
  build against libstdc++ and defeat the purpose of the job while still
  reporting green. No compiler version is pinned, so the job tracks whatever
  Apple clang the runner provides. A first step prints the toolchain so the
  log records which compiler actually ran.

* Fastor is cloned from an arm64-compatible fork rather than upstream V0.6.4.
  Upstream Fastor does not compile on arm64 — it reaches x86 `cpuid` and
  `rdtsc` inline assembly on every non-Windows platform, and its scalar
  fallback backend has further defects that only surface off x86. The fork is
  upstream `master` plus the minimal patch fixing exactly that, and nothing
  else. Those fixes are offered upstream in romeric/Fastor#182 and #183; the
  step carries a comment to switch back once either is merged.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant