Ralith / oddio

Lightweight game audio
Apache License 2.0
150 stars 9 forks source link

Mark oddio as no_std Fixes #64 #65

Closed mooman219 closed 2 years ago

mooman219 commented 3 years ago

This is kind of ugly with libm. It's probably fine enough to just be soft no_std by not taking a direct dependency on std (the first commit). This PR commits to #![no_std] with all the caveats.

Ralith commented 3 years ago

Honestly, the libm stuff seems pretty inoffensive; just the extra dep is the worst of it. Tests are failing, though.

mooman219 commented 3 years ago

Overlooked the tests in stream, resolved.

The only thing I'm actually worried about is powf performance wise. I'm sure that can be replaced with an approx function if it was actually an issue.

Ralith commented 3 years ago

Is there reason to believe that libm::powf might be slower than std?

mooman219 commented 3 years ago

Is there reason to believe that libm::powf might be slower than std?

The standard implementation either calls on a hardware implementation, or uses basically the C implementation libm.a. The problems are: The rust libm isn't yet up to par with the c libm, and currently doesn't attempt to use a hardware implementation. An accurate implementation of powf is incredibly slow. I'm assuming the hardware implementation is fast because between F2XM1 and FSCALE, x86 can do this pretty fast.

CI / miri (pull_request) Failing after 2m — miri

libm has some target specific implementations, and in this case it's using the square root x86 intrinsic. The miri test doesn't support seem to support that so it's failing CI.

Ralith commented 3 years ago

An accurate implementation of powf is incredibly slow.

Ah, that's annoying. I don't suppose rewriting it in terms of exp would help? It's hard to imagine it being on a hotpath, in any case.

The miri test doesn't support [libm intrinsics] so it's failing CI.

Hmm, that's a problem; oddio is much too cheeky with unsafe to get by without miri. Could we hack around this with #[cfg(miri)] somehow? Maybe disable no_std under miri via cfg_attr (if needed) and fall back on the std impl?

ProfElements commented 3 years ago

Alot of the code-style that was before could be kept if you also added num-traits as a dependency. I don't know how much num-traits adds to build times and others. It even has powi from the looks of it. And it seems to fix miri when I test it on my machine somehow??

Ralith commented 2 years ago

Since this seems to have stalled, I merged the first commit in https://github.com/Ralith/oddio/pull/77 to reduce rebase hazards.

mooman219 commented 2 years ago

I've updated the PR