Skip to content
This repository was archived by the owner on Apr 28, 2025. It is now read-only.

Commit 5ba41f0

Browse files
committed
refactor: Move the libm crate to a subdirectory
In preparation for switching to a virtual manifest, move the `libm` crate into a subdirectory and update paths to match. Updating `Cargo.toml` is done in the next commit so git tracks the moved file correctly.
1 parent 9b25961 commit 5ba41f0

File tree

183 files changed

+334
-23
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

183 files changed

+334
-23
lines changed

.github/workflows/main.yaml

+1-1
Original file line numberDiff line numberDiff line change
@@ -213,7 +213,7 @@ jobs:
213213
steps:
214214
- uses: actions/checkout@master
215215
- run: |
216-
msrv="$(perl -ne 'print if s/rust-version\s*=\s*"(.*)"/\1/g' Cargo.toml)"
216+
msrv="$(perl -ne 'print if s/rust-version\s*=\s*"(.*)"/\1/g' libm/Cargo.toml)"
217217
echo "MSRV: $msrv"
218218
echo "MSRV=$msrv" >> "$GITHUB_ENV"
219219
- name: Install Rust

ci/ci-util.py

+3-3
Original file line numberDiff line numberDiff line change
@@ -63,9 +63,9 @@
6363
# Don't run exhaustive tests if these files change, even if they contaiin a function
6464
# definition.
6565
IGNORE_FILES = [
66-
"src/math/support/",
67-
"src/libm_helper.rs",
68-
"src/math/arch/intrinsics.rs",
66+
"libm/src/math/support/",
67+
"libm/src/libm_helper.rs",
68+
"libm/src/math/arch/intrinsics.rs",
6969
]
7070

7171
TYPES = ["f16", "f32", "f64", "f128"]
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
1-
#[path = "../../configure.rs"]
1+
#[path = "../../libm/configure.rs"]
22
mod configure;
33

44
fn main() {
5-
println!("cargo:rerun-if-changed=../../configure.rs");
5+
println!("cargo:rerun-if-changed=../../libm/configure.rs");
66
let cfg = configure::Config::from_env();
77
configure::emit_libm_config(&cfg);
88
}

crates/compiler-builtins-smoke-test/src/math.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ use core::ffi::c_int;
33
#[allow(dead_code)]
44
#[allow(clippy::all)] // We don't get `libm`'s list of `allow`s, so just ignore Clippy.
55
#[allow(unused_imports)]
6-
#[path = "../../../src/math/mod.rs"]
6+
#[path = "../../../libm/src/math/mod.rs"]
77
pub mod libm;
88

99
/// Mark functions `#[no_mangle]` and with the C ABI.

crates/libm-test/Cargo.toml

+1-1
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ anyhow = "1.0.97"
3232
gmp-mpfr-sys = { version = "1.6.4", optional = true, default-features = false }
3333
iai-callgrind = { version = "0.14.0", optional = true }
3434
indicatif = { version = "0.17.11", default-features = false }
35-
libm = { path = "../..", features = ["unstable-public-internals"] }
35+
libm = { path = "../../libm", features = ["unstable-public-internals"] }
3636
libm-macros = { path = "../libm-macros" }
3737
musl-math-sys = { path = "../musl-math-sys", optional = true }
3838
paste = "1.0.15"

crates/libm-test/build.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
1-
#[path = "../../configure.rs"]
1+
#[path = "../../libm/configure.rs"]
22
mod configure;
33
use configure::Config;
44

55
fn main() {
6-
println!("cargo:rerun-if-changed=../../configure.rs");
6+
println!("cargo:rerun-if-changed=../../libm/configure.rs");
77
let cfg = Config::from_env();
88
configure::emit_test_config(&cfg);
99
}

crates/musl-math-sys/Cargo.toml

+1-1
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ publish = false
77
[dependencies]
88

99
[dev-dependencies]
10-
libm = { path = "../../" }
10+
libm = { path = "../../libm" }
1111

1212
[build-dependencies]
1313
cc = "1.2.16"

crates/util/Cargo.toml

+1-1
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ build-mpfr = ["libm-test/build-mpfr", "dep:rug"]
1111
unstable-float = ["libm/unstable-float", "libm-test/unstable-float", "rug?/nightly-float"]
1212

1313
[dependencies]
14-
libm = { path = "../..", default-features = false }
14+
libm = { path = "../../libm", default-features = false }
1515
libm-macros = { path = "../libm-macros" }
1616
libm-test = { path = "../libm-test", default-features = false }
1717
musl-math-sys = { path = "../musl-math-sys", optional = true }

crates/util/build.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
#![allow(unexpected_cfgs)]
22

3-
#[path = "../../configure.rs"]
3+
#[path = "../../libm/configure.rs"]
44
mod configure;
55

66
fn main() {
7-
println!("cargo:rerun-if-changed=../../configure.rs");
7+
println!("cargo:rerun-if-changed=../../libm/configure.rs");
88
let cfg = configure::Config::from_env();
99
configure::emit_libm_config(&cfg);
1010
}

etc/update-api-list.py

+9-9
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818

1919
SELF_PATH = Path(__file__)
2020
ETC_DIR = SELF_PATH.parent
21-
ROOT_DIR = ETC_DIR.parent
21+
LIBM_DIR = ETC_DIR.parent.joinpath("libm")
2222

2323
# These files do not trigger a retest.
2424
IGNORED_SOURCES = ["src/libm_helper.rs", "src/math/support/float_traits.rs"]
@@ -75,7 +75,7 @@ def get_rustdoc_json() -> dict[Any, Any]:
7575
"-Zunstable-options",
7676
"-o-",
7777
],
78-
cwd=ROOT_DIR,
78+
cwd=LIBM_DIR,
7979
text=True,
8080
)
8181
j = json.loads(j)
@@ -121,8 +121,8 @@ def _init_defs(self, index: IndexTy) -> None:
121121

122122
# A lot of the `arch` module is often configured out so doesn't show up in docs. Use
123123
# string matching as a fallback.
124-
for fname in glob("src/math/arch/**.rs", root_dir=ROOT_DIR):
125-
contents = (ROOT_DIR.joinpath(fname)).read_text()
124+
for fname in glob("src/math/arch/**.rs", root_dir=LIBM_DIR):
125+
contents = (LIBM_DIR.joinpath(fname)).read_text()
126126

127127
for name in self.public_functions:
128128
if f"fn {name}" in contents:
@@ -188,10 +188,10 @@ def tidy_lists(self) -> None:
188188
include all public API.
189189
"""
190190

191-
flist = sp.check_output(["git", "ls-files"], cwd=ROOT_DIR, text=True)
191+
flist = sp.check_output(["git", "ls-files"], cwd=LIBM_DIR, text=True)
192192

193193
for path in flist.splitlines():
194-
fpath = ROOT_DIR.joinpath(path)
194+
fpath = LIBM_DIR.joinpath(path)
195195
if fpath.is_dir() or fpath == SELF_PATH:
196196
continue
197197

@@ -229,7 +229,7 @@ def ensure_contains_api(self, fpath: Path, line_num: int, lines: list[str]):
229229
if len(not_found) == 0:
230230
return
231231

232-
relpath = fpath.relative_to(ROOT_DIR)
232+
relpath = fpath.relative_to(LIBM_DIR)
233233
eprint(f"functions not found at {relpath}:{line_num}: {not_found}")
234234
exit(1)
235235

@@ -244,7 +244,7 @@ def validate_delimited_block(
244244
"""Identify blocks of code wrapped within `start` and `end`, collect their contents
245245
to a list of strings, and call `validate` for each of those lists.
246246
"""
247-
relpath = fpath.relative_to(ROOT_DIR)
247+
relpath = fpath.relative_to(LIBM_DIR)
248248
block_lines = []
249249
block_start_line: None | int = None
250250
for line_num, line in enumerate(lines):
@@ -274,7 +274,7 @@ def validate_delimited_block(
274274

275275
def ensure_sorted(fpath: Path, block_start_line: int, lines: list[str]) -> None:
276276
"""Ensure that a list of lines is sorted, otherwise print a diff and exit."""
277-
relpath = fpath.relative_to(ROOT_DIR)
277+
relpath = fpath.relative_to(LIBM_DIR)
278278
diff_and_exit(
279279
"\n".join(lines),
280280
"\n".join(sorted(lines)),
File renamed without changes.

build.rs renamed to libm/build.rs

+1
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ fn main() {
66
let cfg = configure::Config::from_env();
77

88
println!("cargo:rerun-if-changed=build.rs");
9+
println!("cargo:rerun-if-changed=configure.rs");
910
println!("cargo:rustc-check-cfg=cfg(assert_no_panic)");
1011

1112
// If set, enable `no-panic`. Requires LTO (`release-opt` profile).
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.

libm/src/math/copysignf.rs

+8
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
/// Sign of Y, magnitude of X (f32)
2+
///
3+
/// Constructs a number with the magnitude (absolute value) of its
4+
/// first argument, `x`, and the sign of its second argument, `y`.
5+
#[cfg_attr(all(test, assert_no_panic), no_panic::no_panic)]
6+
pub fn copysignf(x: f32, y: f32) -> f32 {
7+
super::generic::copysign(x, y)
8+
}

libm/src/math/copysignf128.rs

+8
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
/// Sign of Y, magnitude of X (f128)
2+
///
3+
/// Constructs a number with the magnitude (absolute value) of its
4+
/// first argument, `x`, and the sign of its second argument, `y`.
5+
#[cfg_attr(all(test, assert_no_panic), no_panic::no_panic)]
6+
pub fn copysignf128(x: f128, y: f128) -> f128 {
7+
super::generic::copysign(x, y)
8+
}

libm/src/math/copysignf16.rs

+8
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
/// Sign of Y, magnitude of X (f16)
2+
///
3+
/// Constructs a number with the magnitude (absolute value) of its
4+
/// first argument, `x`, and the sign of its second argument, `y`.
5+
#[cfg_attr(all(test, assert_no_panic), no_panic::no_panic)]
6+
pub fn copysignf16(x: f16, y: f16) -> f16 {
7+
super::generic::copysign(x, y)
8+
}
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.

libm/src/math/fabsf.rs

+39
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
/// Absolute value (magnitude) (f32)
2+
///
3+
/// Calculates the absolute value (magnitude) of the argument `x`,
4+
/// by direct manipulation of the bit representation of `x`.
5+
#[cfg_attr(all(test, assert_no_panic), no_panic::no_panic)]
6+
pub fn fabsf(x: f32) -> f32 {
7+
select_implementation! {
8+
name: fabsf,
9+
use_arch: all(target_arch = "wasm32", intrinsics_enabled),
10+
args: x,
11+
}
12+
13+
super::generic::fabs(x)
14+
}
15+
16+
// PowerPC tests are failing on LLVM 13: https://github.com/rust-lang/rust/issues/88520
17+
#[cfg(not(target_arch = "powerpc64"))]
18+
#[cfg(test)]
19+
mod tests {
20+
use super::*;
21+
22+
#[test]
23+
fn sanity_check() {
24+
assert_eq!(fabsf(-1.0), 1.0);
25+
assert_eq!(fabsf(2.8), 2.8);
26+
}
27+
28+
/// The spec: https://en.cppreference.com/w/cpp/numeric/math/fabs
29+
#[test]
30+
fn spec_tests() {
31+
assert!(fabsf(f32::NAN).is_nan());
32+
for f in [0.0, -0.0].iter().copied() {
33+
assert_eq!(fabsf(f), 0.0);
34+
}
35+
for f in [f32::INFINITY, f32::NEG_INFINITY].iter().copied() {
36+
assert_eq!(fabsf(f), f32::INFINITY);
37+
}
38+
}
39+
}

libm/src/math/fabsf128.rs

+31
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
/// Absolute value (magnitude) (f128)
2+
///
3+
/// Calculates the absolute value (magnitude) of the argument `x`,
4+
/// by direct manipulation of the bit representation of `x`.
5+
#[cfg_attr(all(test, assert_no_panic), no_panic::no_panic)]
6+
pub fn fabsf128(x: f128) -> f128 {
7+
super::generic::fabs(x)
8+
}
9+
10+
#[cfg(test)]
11+
mod tests {
12+
use super::*;
13+
14+
#[test]
15+
fn sanity_check() {
16+
assert_eq!(fabsf128(-1.0), 1.0);
17+
assert_eq!(fabsf128(2.8), 2.8);
18+
}
19+
20+
/// The spec: https://en.cppreference.com/w/cpp/numeric/math/fabs
21+
#[test]
22+
fn spec_tests() {
23+
assert!(fabsf128(f128::NAN).is_nan());
24+
for f in [0.0, -0.0].iter().copied() {
25+
assert_eq!(fabsf128(f), 0.0);
26+
}
27+
for f in [f128::INFINITY, f128::NEG_INFINITY].iter().copied() {
28+
assert_eq!(fabsf128(f), f128::INFINITY);
29+
}
30+
}
31+
}

libm/src/math/fabsf16.rs

+31
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
/// Absolute value (magnitude) (f16)
2+
///
3+
/// Calculates the absolute value (magnitude) of the argument `x`,
4+
/// by direct manipulation of the bit representation of `x`.
5+
#[cfg_attr(all(test, assert_no_panic), no_panic::no_panic)]
6+
pub fn fabsf16(x: f16) -> f16 {
7+
super::generic::fabs(x)
8+
}
9+
10+
#[cfg(test)]
11+
mod tests {
12+
use super::*;
13+
14+
#[test]
15+
fn sanity_check() {
16+
assert_eq!(fabsf16(-1.0), 1.0);
17+
assert_eq!(fabsf16(2.8), 2.8);
18+
}
19+
20+
/// The spec: https://en.cppreference.com/w/cpp/numeric/math/fabs
21+
#[test]
22+
fn spec_tests() {
23+
assert!(fabsf16(f16::NAN).is_nan());
24+
for f in [0.0, -0.0].iter().copied() {
25+
assert_eq!(fabsf16(f), 0.0);
26+
}
27+
for f in [f16::INFINITY, f16::NEG_INFINITY].iter().copied() {
28+
assert_eq!(fabsf16(f), f16::INFINITY);
29+
}
30+
}
31+
}
File renamed without changes.

libm/src/math/fdimf.rs

+12
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
/// Positive difference (f32)
2+
///
3+
/// Determines the positive difference between arguments, returning:
4+
/// * x - y if x > y, or
5+
/// * +0 if x <= y, or
6+
/// * NAN if either argument is NAN.
7+
///
8+
/// A range error may occur.
9+
#[cfg_attr(all(test, assert_no_panic), no_panic::no_panic)]
10+
pub fn fdimf(x: f32, y: f32) -> f32 {
11+
super::generic::fdim(x, y)
12+
}

libm/src/math/fdimf128.rs

+12
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
/// Positive difference (f128)
2+
///
3+
/// Determines the positive difference between arguments, returning:
4+
/// * x - y if x > y, or
5+
/// * +0 if x <= y, or
6+
/// * NAN if either argument is NAN.
7+
///
8+
/// A range error may occur.
9+
#[cfg_attr(all(test, assert_no_panic), no_panic::no_panic)]
10+
pub fn fdimf128(x: f128, y: f128) -> f128 {
11+
super::generic::fdim(x, y)
12+
}

libm/src/math/fdimf16.rs

+12
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
/// Positive difference (f16)
2+
///
3+
/// Determines the positive difference between arguments, returning:
4+
/// * x - y if x > y, or
5+
/// * +0 if x <= y, or
6+
/// * NAN if either argument is NAN.
7+
///
8+
/// A range error may occur.
9+
#[cfg_attr(all(test, assert_no_panic), no_panic::no_panic)]
10+
pub fn fdimf16(x: f16, y: f16) -> f16 {
11+
super::generic::fdim(x, y)
12+
}
File renamed without changes.

libm/src/math/floorf.rs

+13
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
/// Floor (f32)
2+
///
3+
/// Finds the nearest integer less than or equal to `x`.
4+
#[cfg_attr(all(test, assert_no_panic), no_panic::no_panic)]
5+
pub fn floorf(x: f32) -> f32 {
6+
select_implementation! {
7+
name: floorf,
8+
use_arch: all(target_arch = "wasm32", intrinsics_enabled),
9+
args: x,
10+
}
11+
12+
return super::generic::floor(x);
13+
}

libm/src/math/floorf128.rs

+7
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
/// Floor (f128)
2+
///
3+
/// Finds the nearest integer less than or equal to `x`.
4+
#[cfg_attr(all(test, assert_no_panic), no_panic::no_panic)]
5+
pub fn floorf128(x: f128) -> f128 {
6+
return super::generic::floor(x);
7+
}

libm/src/math/floorf16.rs

+7
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
/// Floor (f16)
2+
///
3+
/// Finds the nearest integer less than or equal to `x`.
4+
#[cfg_attr(all(test, assert_no_panic), no_panic::no_panic)]
5+
pub fn floorf16(x: f16) -> f16 {
6+
return super::generic::floor(x);
7+
}
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.

libm/src/math/fmodf.rs

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
/// Calculate the remainder of `x / y`, the precise result of `x - trunc(x / y) * y`.
2+
#[cfg_attr(all(test, assert_no_panic), no_panic::no_panic)]
3+
pub fn fmodf(x: f32, y: f32) -> f32 {
4+
super::generic::fmod(x, y)
5+
}

libm/src/math/fmodf128.rs

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
/// Calculate the remainder of `x / y`, the precise result of `x - trunc(x / y) * y`.
2+
#[cfg_attr(all(test, assert_no_panic), no_panic::no_panic)]
3+
pub fn fmodf128(x: f128, y: f128) -> f128 {
4+
super::generic::fmod(x, y)
5+
}

libm/src/math/fmodf16.rs

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
/// Calculate the remainder of `x / y`, the precise result of `x - trunc(x / y) * y`.
2+
#[cfg_attr(all(test, assert_no_panic), no_panic::no_panic)]
3+
pub fn fmodf16(x: f16, y: f16) -> f16 {
4+
super::generic::fmod(x, y)
5+
}
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.

libm/src/math/ldexpf.rs

+4
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
#[cfg_attr(all(test, assert_no_panic), no_panic::no_panic)]
2+
pub fn ldexpf(x: f32, n: i32) -> f32 {
3+
super::scalbnf(x, n)
4+
}

libm/src/math/ldexpf128.rs

+4
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
#[cfg_attr(all(test, assert_no_panic), no_panic::no_panic)]
2+
pub fn ldexpf128(x: f128, n: i32) -> f128 {
3+
super::scalbnf128(x, n)
4+
}

0 commit comments

Comments
 (0)