From df4cf5b6d2d8c4f862f6153e069289244b08e251 Mon Sep 17 00:00:00 2001 From: Lucian Popescu Date: Mon, 25 May 2026 13:11:37 +0100 Subject: [PATCH] Add support for arch-specific rules --- rule-preprocessor/src/syntactic.rs | 5 +++++ rules/builtin/src.cpp | 3 +++ rules/builtin/tgt_unsafe.rs | 4 ++++ 3 files changed, 12 insertions(+) diff --git a/rule-preprocessor/src/syntactic.rs b/rule-preprocessor/src/syntactic.rs index 855ffc05..191dac3c 100644 --- a/rule-preprocessor/src/syntactic.rs +++ b/rule-preprocessor/src/syntactic.rs @@ -56,6 +56,11 @@ fn cfg_matches_host(fn_item: &ast::Fn) -> bool { "macos" => cfg!(target_os = "macos"), other => panic!("unsupported target_os in cfg: {other}"), }, + Predicate::Target(TargetPredicate::Arch(arch)) => match arch.as_str() { + "x86_64" => cfg!(target_arch = "x86_64"), + "x86" => cfg!(target_arch = "x86"), + other => panic!("unsupported target_arch in cfg: {other}"), + }, _ => panic!("unsupported cfg predicate in `{meta_text}`"), }); if !matches { diff --git a/rules/builtin/src.cpp b/rules/builtin/src.cpp index 26da1699..f52cf5a8 100644 --- a/rules/builtin/src.cpp +++ b/rules/builtin/src.cpp @@ -23,3 +23,6 @@ int f7(unsigned long x) { return __builtin_ctzl(x); } int f8(unsigned long x) { return __builtin_popcountl(x); } bool f9(long a, long b, long *r) { return __builtin_mul_overflow(a, b, r); } bool f10(long long a, long long b, long long *r) { return __builtin_mul_overflow(a, b, r); } +#if defined(__x86_64__) || defined(__i386__) +void f11(void) { return __builtin_ia32_pause(); } +#endif diff --git a/rules/builtin/tgt_unsafe.rs b/rules/builtin/tgt_unsafe.rs index d2f94f66..16638e3f 100644 --- a/rules/builtin/tgt_unsafe.rs +++ b/rules/builtin/tgt_unsafe.rs @@ -35,3 +35,7 @@ unsafe fn f10(a0: i64, a1: i64, a2: *mut i64) -> bool { *a2 = val; ovf } +#[cfg(any(target_arch = "x86_64", target_arch = "x86"))] +unsafe fn f11() { + std::hint::spin_loop(); +}