Skip to content

Commit 54b6e57

Browse files
authored
Merge pull request rust-lang#431 from tgross35/generic-sqrt
Port musl's Goldschmidt `sqrt`; add `sqrtf16` and `sqrtf128`
2 parents e4cfb0d + 839c72a commit 54b6e57

File tree

21 files changed

+996
-397
lines changed

21 files changed

+996
-397
lines changed

.github/workflows/main.yaml

+1-1
Original file line numberDiff line numberDiff line change
@@ -270,7 +270,7 @@ jobs:
270270
fi
271271
272272
LIBM_EXTENSIVE_TESTS="$CHANGED" cargo t \
273-
--features build-mpfr,unstable \
273+
--features build-mpfr,unstable,force-soft-floats \
274274
--profile release-checked \
275275
-- extensive
276276
- name: Print test logs if available

crates/libm-macros/src/shared.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ const ALL_OPERATIONS_NESTED: &[(FloatTy, Signature, Option<Signature>, &[&str])]
99
FloatTy::F16,
1010
Signature { args: &[Ty::F16], returns: &[Ty::F16] },
1111
None,
12-
&["fabsf16", "truncf16"],
12+
&["fabsf16", "sqrtf16", "truncf16"],
1313
),
1414
(
1515
// `fn(f32) -> f32`
@@ -40,7 +40,7 @@ const ALL_OPERATIONS_NESTED: &[(FloatTy, Signature, Option<Signature>, &[&str])]
4040
FloatTy::F128,
4141
Signature { args: &[Ty::F128], returns: &[Ty::F128] },
4242
None,
43-
&["fabsf128", "truncf128"],
43+
&["fabsf128", "sqrtf128", "truncf128"],
4444
),
4545
(
4646
// `(f16, f16) -> f16`

crates/libm-test/benches/icount.rs

+2
Original file line numberDiff line numberDiff line change
@@ -155,6 +155,8 @@ main!(
155155
icount_bench_sinh_group,
156156
icount_bench_sinhf_group,
157157
icount_bench_sqrt_group,
158+
icount_bench_sqrtf128_group,
159+
icount_bench_sqrtf16_group,
158160
icount_bench_sqrtf_group,
159161
icount_bench_tan_group,
160162
icount_bench_tanf_group,

crates/libm-test/benches/random.rs

+2
Original file line numberDiff line numberDiff line change
@@ -123,6 +123,8 @@ libm_macros::for_each_function! {
123123
| fabsf16
124124
| fdimf128
125125
| fdimf16
126+
| sqrtf16
127+
| sqrtf128
126128
| truncf128
127129
| truncf16 => (false, None),
128130

crates/libm-test/tests/compare_built_musl.rs

+2
Original file line numberDiff line numberDiff line change
@@ -87,5 +87,7 @@ libm_macros::for_each_function! {
8787
fdimf16,
8888
truncf128,
8989
truncf16,
90+
sqrtf16,
91+
sqrtf128,
9092
],
9193
}

crates/musl-math-sys/build.rs

-1
Original file line numberDiff line numberDiff line change
@@ -151,7 +151,6 @@ fn build_musl_math(cfg: &Config) {
151151
.flag_if_supported("-ffreestanding")
152152
.flag_if_supported("-nostdinc")
153153
.define("_ALL_SOURCE", "1")
154-
.opt_level(3)
155154
.define(
156155
"ROOT_INCLUDE_FEATURES",
157156
Some(musl_dir.join("include/features.h").to_str().unwrap()),

crates/util/src/main.rs

+2
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,8 @@ fn do_eval(basis: &str, op: &str, inputs: &[&str]) {
9090
| fabsf16
9191
| fdimf128
9292
| fdimf16
93+
| sqrtf128
94+
| sqrtf16
9395
| truncf128
9496
| truncf16 => None,
9597
_ => Some(musl_math_sys::MACRO_FN_NAME)

etc/function-definitions.json

+16
Original file line numberDiff line numberDiff line change
@@ -704,6 +704,7 @@
704704
"src/libm_helper.rs",
705705
"src/math/arch/i686.rs",
706706
"src/math/arch/wasm32.rs",
707+
"src/math/generic/sqrt.rs",
707708
"src/math/sqrt.rs"
708709
],
709710
"type": "f64"
@@ -712,10 +713,25 @@
712713
"sources": [
713714
"src/math/arch/i686.rs",
714715
"src/math/arch/wasm32.rs",
716+
"src/math/generic/sqrt.rs",
715717
"src/math/sqrtf.rs"
716718
],
717719
"type": "f32"
718720
},
721+
"sqrtf128": {
722+
"sources": [
723+
"src/math/generic/sqrt.rs",
724+
"src/math/sqrtf128.rs"
725+
],
726+
"type": "f128"
727+
},
728+
"sqrtf16": {
729+
"sources": [
730+
"src/math/generic/sqrt.rs",
731+
"src/math/sqrtf16.rs"
732+
],
733+
"type": "f16"
734+
},
719735
"tan": {
720736
"sources": [
721737
"src/libm_helper.rs",

etc/function-list.txt

+2
Original file line numberDiff line numberDiff line change
@@ -105,6 +105,8 @@ sinh
105105
sinhf
106106
sqrt
107107
sqrtf
108+
sqrtf128
109+
sqrtf16
108110
tan
109111
tanf
110112
tanh

src/math/generic/mod.rs

+2
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,11 @@
11
mod copysign;
22
mod fabs;
33
mod fdim;
4+
mod sqrt;
45
mod trunc;
56

67
pub use copysign::copysign;
78
pub use fabs::fabs;
89
pub use fdim::fdim;
10+
pub use sqrt::sqrt;
911
pub use trunc::trunc;

0 commit comments

Comments
 (0)