linebender / linebender/fearless_simd

Remove the `libm` dependency and inline the functions we use?

Open
#147 1 comment 2 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
Rust
Stars
457
Forks
30
Avg merge
1d 10h
Merged PRs (30d)
25

Description

Right now, we depend on the `libm` crate to implement floating-point math operations like `floor`, `ceil`, and `sqrt` that are implemented as intrinsics in practice but are still [not exposed in `core`](https://github.com/rust-lang/rust/issues/137578).

There are various reasons we might not want `libm`.

It has its own architecture-specific implementations for some operations, but per-architecture support is patchy--some operations are missing even though they are supported by the underlying architecture. [They are also implemented using inline assembly](https://github.com/rust-lang/compiler-builtins/issues/1027) instead of intrinsics, which inhibits potential optimizations. This is apparently done to avoid recursion when using the `libm` crate as the libm implementation for *Rust itself*, but that doesn't apply when using it here.

It also [performs its own feature detection](https://github.com/rust-lang/compiler-builtins/blob/eba1a3f3d2824739f07fe434624b0d2fee917d89/libm/src/math/arch/x86/detect.rs), which is pure overhead and completely redundant with the feature detection we perform here.

I think there's room for a slimmer version of the `libm` crate that implements *only* the operations from the `core_float_math` feature. It shouldn't perform any runtime feature detection, and should use intrinsics when possible and inline assembly if the architecture's intrinsics are not stabilized.

Contributor guide

No contributing guide indexed for this repository

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start by auditing the current libm dependency and the operations covered by the core_float_math feature. Compare the architecture-specific implementations and feature-detection concerns described in the issue; done means an agreed scope for a slimmer implementation and a decision on whether to inline or replace the dependency.

Written by the indexing model from the issue text.

Assessment

Tech stack
rust
Domain
compilers, performance
Issue type
Refactor
Difficulty
5/5
Estimated time
Over a week
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.