map in ir_vec_fp.c extracts lanes, calls lane through ir_vec_call, and inserts each result. Several
operations first try whole-vector arithmetic, but a guard failure sends the vector to this scalar path. One
exceptional lane can therefore cause calls for every lane. The helper declarations are opaque to LLVM and can
update CPU state.opt -S -passes='default<O2>,function(sink,simplifycfg)' with -vectorize-slp=false and true. The helper model
retained four calls for four float lanes and two calls for two double lanes in both modes. Controls with scalar
fadd operations became vector additions in both modes. Four scalar llvm.fma calls combined into a vector FMA
only with SLP enabled. These are compiler experiments, not game benchmarks or a proof of guest FP semantics.FABD
(subtraction followed by absolute value), rounding and conversions, then the estimates of I8 and shifts of I9.
Classify NaNs, zeros and denormals as vector masks. Preserve guest NaN selection and payloads, FZ behavior, signed
zero, rounding and every observable FPSR flag. Reduce per-lane exception masks once and combine with existing
FPSR flags. Keep an exact fallback wherever the vector proof is incomplete.llc output for every target and relevant feature level. Count scalar helper calls,
lane extraction, spills and vector instructions. A vector intrinsic may lower to scalar code or library calls.
Keep existing code where LLVM already produces the proposed sequence. Add a target-specific lowering only for a
measured gap, with a portable exact path for other hosts. SLP remains a separately tested option while its known
compiler issue is unresolved (slp_vectorizer in settings.txt).ir_vec_fp.c, ir_vec.c, tools/sailgen/llvm.h, ir_vec_crypto.c where applicable, and tests/ for compiler
fixtures, exactness tests and benchmarks. New helper contracts also touch cpu.h and helpers/.tests/ when implementation starts, including both the opaque helper and pure scalar controls.The first SIMD milestone turns these ideas into a bounded experiment. Use the conditional performance model, then compare its assumptions with the actual scene.
How Rosetta informs the design. The sources below describe observed Rosetta behavior. The final column is the proposed adaptation for ScarletNX, which must be proven independently.
| Documented Rosetta behavior | Evidence | Proposed application to ScarletNX |
|---|---|---|
| Common SSE2 operations map to short NEON sequences. | Dougall Johnson, SSE2 discussion | Emit a whole-vector sequence for the selected AdvSIMD group rather than calling a scalar helper for every lane. |
| The analyzed AOT convention maps XMM0 through XMM15 to q0 through q15. | Champollion, calling conventions | Keep operands as vector SSA values within the generated function and inspect spills. Do not require the separate custom-ABI project for the first milestone. |
| Code expansion and instruction-cache cost influence translation choices. | Dougall Johnson, one-to-one translation discussion | Compare instruction count and generated bytes as well as helper calls. Reject oversized inline fixups without a measured benefit. |
| Apple hardware supports alternative FP behavior used by Rosetta. | Dougall Johnson, floating-point discussion | Use matching hardware only where guest bits and flags are proven. Otherwise use vector masks and exact fallback. Never assume a portable Arm-compatibility FP mode. |
These observations do not establish Rosetta's exact exceptional-lane algorithm. Batched helpers, lane masks and FPSR reductions in this plan are ScarletNX proposals. Borrow the compact SIMD mapping principle without assuming access to Apple's hardware or host OS integration.
The following comparison was rerun with LLVM 23.1.4. These small model functions isolate compiler behavior. They establish which transformations LLVM performs, without measuring a complete emitted guest function or a game.
| Input IR shape | O2, SLP off | O2, SLP on | Consequence |
|---|---|---|---|
| Four float lanes calling the opaque FP helper | Four calls remain | Four calls remain | Replace the helper boundary to expose vector work. |
| Two double lanes calling the opaque FP helper | Two calls remain | Two calls remain | The same obstacle exists for double precision. |
Extract, scalar fadd, insert, for four floats or two doubles | One vector fadd | One vector fadd | LLVM already handles this case. A manual rewrite needs a separate benefit. |
Four scalar llvm.fma.f32 operations | Four scalar intrinsics | One llvm.fma.v4f32 | Emit the vector intrinsic directly where exact FMA is justified and the host supports it. |
The unknown helpers can update memory reachable through CPU*. Successive calls can therefore depend on earlier
state changes, including sticky FPSR updates. The extract/insert syntax alone is not the obstacle.
Representative llc -O2 checks of four-float vector intrinsics show why each target needs inspection:
| Operation | Baseline x86-64 | Zen 4 | Cortex-A57 | Required decision |
|---|---|---|---|---|
llvm.sqrt.v4f32 | sqrtps | vsqrtps | fsqrt v0.4s | Use existing vector lowering wherever guest result and flags are proven. |
llvm.fma.v4f32 | Four fmaf library calls and spills | vfmadd213ps | Vector fmla plus a register move | Retain the host-FMA capability guard. Avoid introducing library calls on baseline x86. |
llvm.fptosi.sat.v4i32.v4f32 | Four scalar conversions plus fixups | Four scalar conversions plus fixups | fcvtzs v0.4s | Investigate an x86 vector conversion with exact masks. A vector intrinsic alone is insufficient here. |
These instruction forms describe lowering only. In particular, an intrinsic's numeric result does not provide Arm's
NaN payload rules or FPSR behavior. A conversion sequence with the right integer result still needs correct IOC and
IXC handling. Likewise, a vector select does not suppress evaluation of either operand. Sanitize lanes before unsafe
shifts or float-to-int operations, avoid LLVM poison, and account for host exceptions if either path can trap.
Implement I15 in this order:
FABD, then audit rounding and conversions against the target
lowering table. Reuse existing vector arithmetic and add only the missing operations and exact fixups.tests/llvm_perf/ during implementation, with the opaque-call,
scalar arithmetic and scalar-intrinsic controls above. Keep semantic tests separate from lowering checks. Compare
helper calls, spills, code size and repeated timings after each instruction group, including mixed-lane inputs.Rosetta's SIMD-to-SIMD mapping is documented in Dougall Johnson's SSE2 discussion. Its Apple-specific FP hardware is a separate advantage. The lane masks, batched helpers and FPSR reductions above are proposed ScarletNX adaptations, not claims about Rosetta's undocumented implementation. They do not depend on a cooperative Horizon kernel.
ir_vec_fp.c, tools/sailgen/llvm.h.--sweep on these rows.ir_vec.c.Rosetta 2. x86 and Arm both follow IEEE 754 but differ in NaN propagation and in when tininess is detected. Dougall Johnson writes that the M1 has a non-standard mode, close to the later FEAT_AFP of Armv8.7, that gives the x86 behavior in hardware. x87 is a full but slow software emulation.
Made from docs/layers/cpu/plan.md at 69237645142c. GPL-3.0-or-later.