Skip to content

Commit f1fe0c9

Browse files
IpsitKalraclaude
andcommitted
fix: make the benchmark core compile on Linux x86-64
CI caught two defects that an Apple arm64 machine structurally cannot: the invariant-TSC probe called __get_cpuid and __get_cpuid_max, which GCC and Clang declare in <cpuid.h> rather than <x86intrin.h>, and the JSON writer declared separate std::size_t and std::uint64_t overloads, which are the same type on the Linux x86-64 ABI and therefore a redefinition there, although they are distinct types on Apple arm64. The x86 header is now included on that path, and the writer keeps only the fixed-width overloads, which is unambiguous on both ABIs since no call site passes a bare size_t. Verified by cross-compiling the header with -target x86_64-apple-macos13, which exercises the TSC path that the host build compiles out entirely. CI had been red since the bench CLI landed and I did not check it between pushes; the failure was a build error on all three presets, so no test result was affected, and the local macOS battery stayed green throughout. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
1 parent a0eff6e commit f1fe0c9

1 file changed

Lines changed: 7 additions & 2 deletions

File tree

include/nanobook/bench.hpp

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,8 @@
5252

5353
#if defined(__x86_64__) || defined(_M_X64)
5454
#define NANOBOOK_HAS_X86_TSC 1
55-
#include <x86intrin.h>
55+
#include <cpuid.h> // __get_cpuid, __get_cpuid_max
56+
#include <x86intrin.h> // __rdtscp
5657
#else
5758
#define NANOBOOK_HAS_X86_TSC 0
5859
#endif
@@ -678,9 +679,13 @@ class JsonWriter {
678679
void value(const std::string& text) { raw("\"" + escape(text) + "\""); }
679680
void value(const char* text) { value(std::string(text)); }
680681
void value(bool flag) { raw(flag ? "true" : "false"); }
682+
// Only fixed-width overloads: on the Linux x86-64 ABI std::size_t is the
683+
// same type as std::uint64_t, so a separate size_t overload would be a
684+
// redefinition there, while on Apple arm64 the two are distinct types and
685+
// an unqualified size_t argument would be ambiguous. Callers convert
686+
// explicitly, which is unambiguous everywhere.
681687
void value(std::uint64_t number) { raw(std::to_string(number)); }
682688
void value(std::int64_t number) { raw(std::to_string(number)); }
683-
void value(std::size_t number) { raw(std::to_string(static_cast<std::uint64_t>(number))); }
684689
void value(double number, int precision = 6) {
685690
char buffer[64];
686691
std::snprintf(buffer, sizeof buffer, "%.*f", precision, number);

0 commit comments

Comments
 (0)