Repository navigation
rust: Port util/util_uint64.h (util_mul_div64) to obs-util - #122
Merged
Merged
Conversation
swilk19
force-pushed
the
port/util-uint64
branch
from
October 10, 2026 22:08
56c315f to
47e2779
Compare
Pins util_mul_div64 from util/util_uint64.h before the Rust port: the audio frames <-> ns conversions audio-io.h and obs-source.c use it for, a 30000/1001 frame interval, zero operands, div 1, and operands whose num * mul exceeds 64 bits while rem * mul does not, which both platform paths compute exactly. The header does the math two ways. MSVC x64 uses _umul128/_udiv128 (exact 128-bit), everything else (num / div) * mul + (rem * mul) / div in u64. Once rem * mul overflows, the results differ, so those cases are guarded with the header's own condition and pinned per path. The non-MSVC path also pins a quotient that does not fit in 64 bits wrapping; on MSVC x64 _udiv128 faults there, so it is not tested. Both are characterized, not endorsed. div == 0 is UB on both paths and is left out. util_uint64.h uses uint64_t without including <stdint.h>, so the test includes util/c99defs.h first. Co-Authored-By: Claude Opus 5.5 <[email protected]>
Tier 1 and Tier 3 tests for util_mul_div64 against a todo!() core, obs_util::util_uint64::mul_div64. util_uint64.h is header-inline and defines no struct, so there is no shim, no layout test and no symbol swap; Tier 2 is the unchanged characterization test passing OFF/ON. The oracle wraps the header in a non-inline oracle_util_mul_div64, including util/c99defs.h first because the header uses uint64_t without including <stdint.h>. Tier 1 ports test_util_uint64.c case for case, with the same split between the MSVC x64 path (exact 128-bit) and the wrapping u64 path, and adds div == 0 panicking (UB in C) and, on MSVC x64, a quotient past 64 bits panicking (_udiv128 faults). Parity sweeps every combination of 16 values around the 32- and 64-bit edges and runs proptest over arbitrary u64s, edge-biased u64s and inputs with a large remainder, so rem * mul overflows. It runs against each platform's own C, so Windows CI covers the MSVC path. Excluded, and listed in the test file: div == 0, and on MSVC x64 quotients that do not fit in 64 bits. Co-Authored-By: Claude Opus 5.5 <[email protected]>
util_mul_div64 gets a Rust equivalent, obs_util::util_uint64::mul_div64, for Rust ports such as audio-io.h's audio_frames_to_ns and ns_to_audio_frames. The header is static inline, so nothing is swapped or exported. No intentional differences. Like the header, the core picks its math per platform: on MSVC x64 (target_env = "msvc", target_arch = "x86_64") it multiplies and divides in u128, matching _umul128/_udiv128; everywhere else it computes (num / div) * mul + (rem * mul) / div with wrapping u64 ops. Where the C is UB or faults it panics: div == 0, and on MSVC x64 a quotient that does not fit in 64 bits. Parity excludes exactly those. Mutation check: computing the exact quotient off MSVC fails every parity test, and dividing the remainder term by (div | 1) fails the edge sweep and the edge-biased proptest. Co-Authored-By: Claude Opus 5.5 <[email protected]> Local-Gate: v1 tree=26b4bc2f1b9accd67421acf0f84aec1e94470b17 secs=36 lanes=lint:run,rust-test:run,tier2-linux:run Ci-Attestation: {"at":1791670992,"gate":"rust/all/fmt","host":"linux-x86_64","key":"162bd981bc82885ba3fdd4801e4b0542cf6d911831a3566a4e22a21c08f15313","lane":"lint","parents":["95a719e8bcb6d1e4a08cd5ac45f84f5ed89f5c78"],"secs":9,"stamp":"18b3d4b29f200159761b21c6e26986a0","tree":"26b4bc2f1b9accd67421acf0f84aec1e94470b17","v":1,"via":"run"} Ci-Attestation: {"at":1791670992,"gate":"rust/x86_64-unknown-linux-gnu/clippy","host":"linux-x86_64","key":"162bd981bc82885ba3fdd4801e4b0542cf6d911831a3566a4e22a21c08f15313","lane":"lint","parents":["95a719e8bcb6d1e4a08cd5ac45f84f5ed89f5c78"],"secs":9,"stamp":"f92880c8169ef7654be289e9cca5275a","tree":"26b4bc2f1b9accd67421acf0f84aec1e94470b17","v":1,"via":"run"} Ci-Attestation: {"at":1791670992,"gate":"rust/x86_64-unknown-linux-gnu/test","host":"linux-x86_64","key":"a75ecddbf3f8b1643cc5c4421abe29a4a40ddd34a9ffd45022589a391753be1c","lane":"rust-test","parents":["95a719e8bcb6d1e4a08cd5ac45f84f5ed89f5c78"],"secs":14,"stamp":"53485b115ea98676f203864e12b04415","tree":"26b4bc2f1b9accd67421acf0f84aec1e94470b17","v":1,"via":"run"} Ci-Attestation: {"at":1791670992,"gate":"cpp/linux-x64/tier2","host":"linux-x86_64","key":"a203c1c8f8d5c3d49733ac29363792f930029fd582faa968232f5e9f5e679e3d","lane":"tier2-linux","parents":["95a719e8bcb6d1e4a08cd5ac45f84f5ed89f5c78"],"secs":12,"stamp":"72328cdf2e4b534330bfab8c2e893e75","tree":"26b4bc2f1b9accd67421acf0f84aec1e94470b17","v":1,"via":"run"}
swilk19
force-pushed
the
port/util-uint64
branch
from
October 10, 2026 22:23
47e2779 to
daad7cd
Compare
This was referenced Oct 10, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Description
Ports
util_mul_div64fromlibobs/util/util_uint64.htoobs-util(obs_util::util_uint64::mul_div64), as item 2 of the media-io part 2 order on #45.audio_frames_to_ns/ns_to_audio_framesinaudio-io.hare thin wrappers around it, so it comes before theaudio-io.hinlines. No intentional differences.Header-inline exemption. The function is
static inline, so nothing is swapped or exported, there is noENABLE_RUST_LIBOBSguard and norust-exports.txtentry, and the header is unmodified. The header defines no struct, so Tier 2 is just the unchanged cmocka test passing OFF and ON. Tier 1 and Tier 3 run against a non-inlineoracle_util_mul_div64wrapper.Per-platform math. The C does different math per platform, and the port matches each:
_MSC_VER >= 1920):_umul128+_udiv128, exact 128-bit. Rust:u128undercfg(all(target_env = "msvc", target_arch = "x86_64")).(num / div) * mul + (rem * mul) / divin u64. Rust:wrapping_mul/wrapping_add.The two differ once
rem * muloverflows, so the cmocka test pins those cases per path with the header's own#if, and parity runs against each platform's own C (Windows CI covers the MSVC path).Exclusions (listed in
tests/util_uint64_parity.rs, the README row and here for #45). The port panics on both instead of guessing:div == 0: UB on both paths._udiv128faults. Off MSVC they wrap, and are compared.Oracle.
oracle/util_uint64.cwith its own binding module (src/util_uint64.rs).util_uint64.husesuint64_twithout including<stdint.h>, so the wrapper and the cmocka test includeutil/c99defs.hfirst.Motivation and Context
Item 2 of the order approved on #45 (#45 (comment)). It touches none of the obs-media-io files, so per that comment it doesn't count toward the two-PR limit. The
audio-io.hport will use it.Refs #45
How Has This Been Tested?
Linux x86_64 (WSL2), Rust via soldr.
test/cmocka/test_util_uint64.c(C characterization, passes OFF and ON before any Rust), then RED (todo!()core), then GREEN.div == 1, and inputs whosenum * mulexceeds 64 bits whilerem * muldoes not (both paths exact). Per path: threerem * muloverflow cases, and off MSVC a quotient past 64 bits wrapping. Characterized, not endorsed.soldr cargo test -p obs-util: Tier 1 ports the cmocka cases 1:1 with the same platform split, plusdiv == 0panicking, the MSVC-only overflow panic, and exactness wheneverrem * mulfits. Tier 3 sweeps all 16³ combinations of values around the 32- and 64-bit edges and runs proptest (20,000 cases each) over arbitrary u64s, edge-biased u64s, and small-quotient/large-remainder inputs that forcerem * multo overflow.util_uint64fails 9/10 (the passing one is theshould_panicdiv == 0test) andutil_uint64_parityfails 4/4; at head both pass.div | 1fails the edge sweep and the edge-biased proptest. Both reverted.--target x86_64-pc-windows-msvc(checked that the branch is actually type-checked); it runs in the Windows Rust Tests job../lintand./unittest: ok. tier2-linux rantest_util_uint64with ENABLE_RUST_LIBOBS OFF and ON (46/46 each, rebased onto master after plugins: Reconnect Linux capture after PipeWire restarts #109 and rust: Port media-io video-io.h and frame-rate.h inlines to obs-media-io #114). The libobs exported symbols are identical OFF vs ON (1752). HEAD carries the local-gate stamp.rust-tier2CI jobs cover them.Types of changes
Checklist:
🤖 Generated with Claude Code