makepad/libs/relax/compiler/tests/n01_round33_target_feature.rs
Admin b22a714840 makepad run: the Rust JIT (libs/relax) and makepad-remote
The JIT that runs makepad apps from source: lexer, front end, type checker,
lazy borrow checker (Gandalf; `--check-first` opts in), codegen, session and
warm/cold caches keyed by compiler stamp, provided crates bound late,
startup images, live patching. User-facing name is `makepad run` (binary
`makepad`, MAKEPAD_RUN_* env, ~/.makepad-run); libs/relax stays the internal
library name. `makepad check` reports rustc-style diagnostics with rustc
error codes and checks a whole workspace (`--workspace`). Runs on macOS,
Linux, Windows and Android. makepad-remote: one tool schema for apps and the
WM (app/1): grabs, captures, traces, frame profiles and tweaks.

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
2026-10-13 12:26:21 +02:00

30 lines
1.2 KiB
Rust

// L7: #[target_feature] collection (implied features) and adjust_target_feature_sig, as rustc.
#[cfg(target_arch = "x86_64")]
mod x {
#[target_feature(enable = "avx2")]
fn avx2_fn() -> u32 { 2 }
#[target_feature(enable = "avx")]
fn avx_fn() -> u32 { 1 }
// avx is implied by avx2: both coerce to safe fn pointers inside an avx2 body
#[target_feature(enable = "avx2")]
fn caller() -> u32 {
let f: fn() -> u32 = avx_fn;
let g: fn() -> u32 = avx2_fn;
let c = || { let h: fn() -> u32 = avx_fn; h() };
f() + g() + c() - 1
}
#[target_feature(enable = "sse4.2,popcnt", enable = "bmi1")]
unsafe fn multi() -> u32 { 3 }
pub fn run() -> u32 {
// a safe #[target_feature] fn is an unsafe fn pointer anywhere
let u: unsafe fn() -> u32 = avx2_fn;
if std::is_x86_feature_detected!("avx2") && std::is_x86_feature_detected!("popcnt") && std::is_x86_feature_detected!("bmi1") {
unsafe { caller() + u() + multi() - 2 }
} else { 6 }
}
}
#[cfg(not(target_arch = "x86_64"))]
mod x { pub fn run() -> u32 { 6 } }
#[test]
fn target_feature_safety() { assert_eq!(x::run(), 6); }