Repository navigation
Description
Part of #1295. Follows #1298 / #1394.
Context and reproduction
Class: performance regression on a release target.
#1394 replaced f32::floor/f32::ceil in the vec2 cores with inline add-and-subtract-2²³ rounding (rust/obs-graphics/src/round.rs). That fixed x86_64 baseline builds, where LLVM lowers f32::floor to a libm call. On aarch64, though, f32::floor and C floorf are a single native instruction (frintm/frintp), and the portable sequence is much slower.
origin/master at 194cb8a38, port_comparison filtered to vec2/(floor|ceil), recorder Criterion settings, 5 passes:
| Machine | Benchmark | Rust ns | C ns | Rust/C | Per-pass range |
|---|---|---|---|---|---|
| Apple M2 Pro, macOS arm64 | vec2/floor |
2.985 | 0.858 | 3.48× | 3.47–3.48× |
| Apple M2 Pro, macOS arm64 | vec2/ceil |
2.984 | 0.860 | 3.47× | 3.43–3.48× |
| Xeon Platinum 8358 (Ice Lake), dedicated, 10 × 2 s passes | vec2/ceil |
4.312 | 3.543 | 1.22× | 1.21–1.36× |
| Xeon Platinum 8358 (Ice Lake), dedicated, 10 × 2 s passes | vec2/floor |
4.245 | 3.757 | 1.13× | 1.10–1.31× |
| EPYC Rome (Zen 2), shared | vec2/floor / ceil |
3.760 / 3.726 | 3.656 / 3.567 | 1.03× / 1.04× | 0.86–1.10× |
| i7-12700KF (WSL2) | vec2/floor / ceil |
1.948 / 1.987 | 1.869 / 1.875 | 1.04× / 1.06× | 1.03–1.22× / 1.03–1.11× |
Location
- rust/obs-graphics/src/round.rs:34 (
ceil_f32) - rust/obs-graphics/src/round.rs:50 (
floor_f32)
aarch64 disassembly from the same build:
_oracle_vec2_floor: ldr d0,[x1] ; frintm.2s v0,v0 ; str d0,[x0] ; ret
_vec2_floor: ldp s0,s1,[x1] ; fabs ; movi ; ... (40 instructions: 2^23 add/sub,
fcmp/fcsel adjust, NaN quieting, copysign via bif) ... ; str x8,[x0] ; ret
On x86_64, GCC inlines a cvttss2si-based truncate-and-adjust sequence for the C original. The Rust version uses addss/subss with ±2²³, which adds two dependent FP adds (about 4 cycles each on Ice Lake). That fits the steady ceil residual on Ice Lake, but this is not confirmed.
Proposed fix and failing-test sketch
- On targets with a native single-instruction round (aarch64; also x86_64 when
sse4.1is enabled at compile time), usef32::floor/f32::ceil. Keep the portable sequence for baseline x86_64. The target split belongs insrc/platform/(the singlecfg_select!inplatform/mod.rs), next to the existingplatform::round_large, under the platform-boundary rule. NaN handling should still match:round.rsalready says macOS and MSVC quiet signaling NaNs, whichfrintmdoes too. - Optional: look at the x86 Ice Lake
ceilresidual (try a truncation-based sequence matching GCC's), but only if it holds up on a second Intel part.
RED: the existing vec2/floor and vec2/ceil benches on aarch64 (macOS or Linux) at 3.5×. Bit-exactness stays covered by the category suite's exhaustive 2³² check.
Acceptance criteria
- aarch64
vec2/floorandvec2/ceilmedian Rust/C ≤ 1.10 over five paired passes, with absolute times recorded. - No regression on baseline x86_64 compared with obs-graphics: vec2 ceil/floor round inline instead of calling libm (#1298) #1394's numbers.
- Exhaustive bit-exact tests pass on both targets. The C ABI and headers are unchanged. Tier 2 passes against both libobs variants.
Metadata
Metadata
Assignees
Labels
Type
Projects
- StatusShow more project fieldsDone
Activity
swilk19 commentedon Oct 18, 2026
Claiming: #1428 (aarch64
vec2_floor/vec2_ceil)Plan, one PR:
target_arch = "aarch64",ceil_f32/floor_f32usef32::ceil/f32::floor(singlefrintp/frintm, which also quiets signaling NaNs, the conventionplatform::round_largealready uses on aarch64). The target choice lives inobs-graphics/src/platform/. Baseline x86_64 keeps obs-graphics: vec2 ceil/floor round inline instead of calling libm (#1298) #1394's inline sequence unchanged, and I'll show its codegen is byte-identical.Decisions: x86_64 with SSE4.1 (
roundss, e.g. thex86_64-apple-darwindefault CPU) is left for later. I can't measure it here, and on Linux it would change sNaN bits compared with GCC's inline C sequence. The Ice Lakeceilresidual stays as noted in the issue.I expect to open the PR today.
obs-graphics: aarch64 vec2 ceil/floor keep both lanes in one vector (o…
obs-graphics: aarch64 vec2 ceil/floor use the native round (obs-rust#…
obs-graphics: aarch64 vec2 ceil/floor keep both lanes in one vector (o…
obs-graphics: aarch64 vec2 ceil/floor use the native round (obs-rust#…