diff --git a/library/compiler-builtins/libm/.travis.yml b/library/compiler-builtins/libm/.travis.yml deleted file mode 100644 index 758316178196..000000000000 --- a/library/compiler-builtins/libm/.travis.yml +++ /dev/null @@ -1,58 +0,0 @@ -language: rust -services: docker -sudo: required - -matrix: - include: - - env: TARGET=aarch64-unknown-linux-gnu - rust: nightly - - env: TARGET=armv7-unknown-linux-gnueabihf - rust: nightly - - env: TARGET=i686-unknown-linux-gnu - rust: nightly - - env: TARGET=mips-unknown-linux-gnu - rust: nightly - - env: TARGET=mips64-unknown-linux-gnuabi64 - rust: nightly - - env: TARGET=mips64el-unknown-linux-gnuabi64 - rust: nightly - - env: TARGET=mipsel-unknown-linux-gnu - rust: nightly - - env: TARGET=powerpc-unknown-linux-gnu - rust: nightly - - env: TARGET=powerpc64-unknown-linux-gnu - rust: nightly - - env: TARGET=powerpc64le-unknown-linux-gnu - rust: nightly - - env: TARGET=x86_64-unknown-linux-gnu - rust: nightly - - env: TARGET=cargo-fmt - rust: beta - - - env: TARGET=wasm32-unknown-unknown - rust: nightly - install: rustup target add $TARGET - script: - - cargo build --target $TARGET - - cargo build --no-default-features --target $TARGET - -before_install: set -e - -install: - - bash ci/install.sh - -script: - - export PATH=$HOME/.local/bin:$PATH - - bash ci/script.sh - -after_script: set +e - -cache: cargo - -before_cache: - - chmod -R a+r $HOME/.cargo; - -branches: - only: - - staging - - trying diff --git a/library/compiler-builtins/libm/Cargo.toml b/library/compiler-builtins/libm/Cargo.toml index f28024d041c5..45fad8230a06 100644 --- a/library/compiler-builtins/libm/Cargo.toml +++ b/library/compiler-builtins/libm/Cargo.toml @@ -6,23 +6,30 @@ documentation = "https://docs.rs/libm" keywords = ["libm", "math"] license = "MIT OR Apache-2.0" name = "libm" -repository = "https://github.com/japaric/libm" +repository = "https://github.com/rust-lang-nursery/libm" version = "0.1.2" +edition = "2018" [features] # only used to run our test suite -checked = [] default = ['stable'] stable = [] +# Generate tests which are random inputs and the outputs are calculated with +# musl libc. +musl-reference-tests = ['rand'] + +# Used checked array indexing instead of unchecked array indexing in this +# library. +checked = [] + [workspace] members = [ - "cb", - "input-generator", - "musl-generator", - "newlib-generator", - "shared", + "crates/compiler-builtins-smoke-test", ] [dev-dependencies] -shared = { path = "shared" } +no-panic = "0.1.8" + +[build-dependencies] +rand = { version = "0.6.5", optional = true } diff --git a/library/compiler-builtins/libm/README.md b/library/compiler-builtins/libm/README.md index 24b816c351b8..568a049f0c58 100644 --- a/library/compiler-builtins/libm/README.md +++ b/library/compiler-builtins/libm/README.md @@ -1,5 +1,7 @@ # `libm` +[![Build Status](https://dev.azure.com/rust-lang/libm/_apis/build/status/rust-lang-nursery.libm?branchName=master)](https://dev.azure.com/rust-lang/libm/_build/latest?definitionId=7&branchName=master) + A port of [MUSL]'s libm to Rust. [MUSL]: https://www.musl-libc.org/ diff --git a/library/compiler-builtins/libm/azure-pipelines.yml b/library/compiler-builtins/libm/azure-pipelines.yml new file mode 100644 index 000000000000..d8068e023b4c --- /dev/null +++ b/library/compiler-builtins/libm/azure-pipelines.yml @@ -0,0 +1,73 @@ +trigger: + - master + +jobs: + - job: Docker + pool: + vmImage: ubuntu-16.04 + steps: + - template: ci/azure-install-rust.yml + - bash: rustup target add $TARGET + displayName: "add cross target" + - bash: rustup target add x86_64-unknown-linux-musl + displayName: "add musl target" + - bash: cargo generate-lockfile && ./ci/run-docker.sh $TARGET + displayName: "run tests" + strategy: + matrix: + aarch64: + TARGET: aarch64-unknown-linux-gnu + arm: + TARGET: arm-unknown-linux-gnueabi + armhf: + TARGET: arm-unknown-linux-gnueabihf + armv7: + TARGET: armv7-unknown-linux-gnueabihf + i686: + TARGET: i686-unknown-linux-gnu + mips: + TARGET: mips-unknown-linux-gnu + mips64: + TARGET: mips64-unknown-linux-gnuabi64 + mips64el: + TARGET: mips64el-unknown-linux-gnuabi64 + powerpc: + TARGET: powerpc-unknown-linux-gnu + powerpc64: + TARGET: powerpc64-unknown-linux-gnu + powerpc64le: + TARGET: powerpc64le-unknown-linux-gnu + x86_64: + TARGET: x86_64-unknown-linux-gnu + + - job: wasm + pool: + vmImage: ubuntu-16.04 + steps: + - template: ci/azure-install-rust.yml + - script: rustup target add wasm32-unknown-unknown + displayName: "Install rust wasm target" + - script: cargo build --target wasm32-unknown-unknown + displayName: "Build for wasm" + - script: cargo build --target wasm32-unknown-unknown --no-default-features + displayName: "Build for wasm (no default features)" + variables: + TOOLCHAIN: nightly + + - job: rustfmt + pool: + vmImage: ubuntu-16.04 + steps: + - template: ci/azure-install-rust.yml + - bash: rustup component add rustfmt + displayName: "install rustfmt" + - bash: cargo fmt --all -- --check + displayName: "check formatting" + + - job: compiler_builtins_works + pool: + vmImage: ubuntu-16.04 + steps: + - template: ci/azure-install-rust.yml + - bash: cargo build -p cb + displayName: "Check compiler-builtins still probably builds" diff --git a/library/compiler-builtins/libm/build.rs b/library/compiler-builtins/libm/build.rs new file mode 100644 index 000000000000..23e1178e3607 --- /dev/null +++ b/library/compiler-builtins/libm/build.rs @@ -0,0 +1,353 @@ +use std::env; + +fn main() { + println!("cargo:rerun-if-changed=build.rs"); + + #[cfg(feature = "musl-reference-tests")] + musl_reference_tests::generate(); + + if !cfg!(feature = "checked") { + let lvl = env::var("OPT_LEVEL").unwrap(); + if lvl != "0" { + println!("cargo:rustc-cfg=assert_no_panic"); + } + } +} + +#[cfg(feature = "musl-reference-tests")] +mod musl_reference_tests { + use rand::seq::SliceRandom; + use rand::Rng; + use std::fs; + use std::process::Command; + + // Number of tests to generate for each function + const NTESTS: usize = 500; + + // These files are all internal functions or otherwise miscellaneous, not + // defining a function we want to test. + const IGNORED_FILES: &[&str] = &[ + "expo2.rs", + "fenv.rs", + "k_cos.rs", + "k_cosf.rs", + "k_expo2.rs", + "k_expo2f.rs", + "k_sin.rs", + "k_sinf.rs", + "k_tan.rs", + "k_tanf.rs", + "mod.rs", + "rem_pio2.rs", + "rem_pio2_large.rs", + "rem_pio2f.rs", + ]; + + struct Function { + name: String, + args: Vec, + ret: Ty, + tests: Vec, + } + + enum Ty { + F32, + F64, + I32, + Bool, + } + + struct Test { + inputs: Vec, + output: i64, + } + + pub fn generate() { + let files = fs::read_dir("src/math") + .unwrap() + .map(|f| f.unwrap().path()) + .collect::>(); + + let mut math = Vec::new(); + for file in files { + if IGNORED_FILES.iter().any(|f| file.ends_with(f)) { + continue; + } + + println!("generating musl reference tests in {:?}", file); + + let contents = fs::read_to_string(file).unwrap(); + let mut functions = contents.lines().filter(|f| f.starts_with("pub fn")); + let function_to_test = functions.next().unwrap(); + if functions.next().is_some() { + panic!("more than one function in"); + } + + math.push(parse(function_to_test)); + } + + // Generate a bunch of random inputs for each function. This will + // attempt to generate a good set of uniform test cases for exercising + // all the various functionality. + generate_random_tests(&mut math, &mut rand::thread_rng()); + + // After we have all our inputs, use the x86_64-unknown-linux-musl + // target to generate the expected output. + generate_test_outputs(&mut math); + + // ... and now that we have both inputs and expected outputs, do a bunch + // of codegen to create the unit tests which we'll actually execute. + generate_unit_tests(&math); + } + + /// A "poor man's" parser for the signature of a function + fn parse(s: &str) -> Function { + let s = eat(s, "pub fn "); + let pos = s.find('(').unwrap(); + let name = &s[..pos]; + let s = &s[pos + 1..]; + let end = s.find(')').unwrap(); + let args = s[..end] + .split(',') + .map(|arg| { + let colon = arg.find(':').unwrap(); + parse_ty(arg[colon + 1..].trim()) + }) + .collect::>(); + let tail = &s[end + 1..]; + let tail = eat(tail, " -> "); + let ret = parse_ty(tail.trim().split(' ').next().unwrap()); + + return Function { + name: name.to_string(), + args, + ret, + tests: Vec::new(), + }; + + fn parse_ty(s: &str) -> Ty { + match s { + "f32" => Ty::F32, + "f64" => Ty::F64, + "i32" => Ty::I32, + "bool" => Ty::Bool, + other => panic!("unknown type `{}`", other), + } + } + + fn eat<'a>(s: &'a str, prefix: &str) -> &'a str { + if s.starts_with(prefix) { + &s[prefix.len()..] + } else { + panic!("{:?} didn't start with {:?}", s, prefix) + } + } + } + + fn generate_random_tests(functions: &mut [Function], rng: &mut R) { + for function in functions { + for _ in 0..NTESTS { + function.tests.push(generate_test(&function.args, rng)); + } + } + + fn generate_test(args: &[Ty], rng: &mut R) -> Test { + let inputs = args.iter().map(|ty| ty.gen_i64(rng)).collect(); + // zero output for now since we'll generate it later + Test { inputs, output: 0 } + } + } + + impl Ty { + fn gen_i64(&self, r: &mut R) -> i64 { + match self { + Ty::F32 => r.gen::().to_bits().into(), + Ty::F64 => r.gen::().to_bits() as i64, + Ty::I32 => { + if r.gen_range(0, 10) < 1 { + let i = *[i32::max_value(), 0, i32::min_value()].choose(r).unwrap(); + i.into() + } else { + r.gen::().into() + } + } + Ty::Bool => r.gen::() as i64, + } + } + + fn libc_ty(&self) -> &'static str { + match self { + Ty::F32 => "f32", + Ty::F64 => "f64", + Ty::I32 => "i32", + Ty::Bool => "i32", + } + } + } + + fn generate_test_outputs(functions: &mut [Function]) { + let mut src = String::new(); + let dst = std::env::var("OUT_DIR").unwrap(); + + // Generate a program which will run all tests with all inputs in + // `functions`. This program will write all outputs to stdout (in a + // binary format). + src.push_str("use std::io::Write;"); + src.push_str("fn main() {"); + src.push_str("let mut result = Vec::new();"); + for function in functions.iter_mut() { + src.push_str("unsafe {"); + src.push_str("extern { fn "); + src.push_str(&function.name); + src.push_str("("); + for (i, arg) in function.args.iter().enumerate() { + src.push_str(&format!("arg{}: {},", i, arg.libc_ty())); + } + src.push_str(") -> "); + src.push_str(function.ret.libc_ty()); + src.push_str("; }"); + + src.push_str(&format!("static TESTS: &[[i64; {}]]", function.args.len())); + src.push_str(" = &["); + for test in function.tests.iter() { + src.push_str("["); + for val in test.inputs.iter() { + src.push_str(&val.to_string()); + src.push_str(","); + } + src.push_str("],"); + } + src.push_str("];"); + + src.push_str("for test in TESTS {"); + src.push_str("let output = "); + src.push_str(&function.name); + src.push_str("("); + for (i, arg) in function.args.iter().enumerate() { + src.push_str(&match arg { + Ty::F32 => format!("f32::from_bits(test[{}] as u32)", i), + Ty::F64 => format!("f64::from_bits(test[{}] as u64)", i), + Ty::I32 => format!("test[{}] as i32", i), + Ty::Bool => format!("test[{}] as i32", i), + }); + src.push_str(","); + } + src.push_str(");"); + src.push_str("let output = "); + src.push_str(match function.ret { + Ty::F32 => "output.to_bits() as i64", + Ty::F64 => "output.to_bits() as i64", + Ty::I32 => "output as i64", + Ty::Bool => "output as i64", + }); + src.push_str(";"); + src.push_str("result.extend_from_slice(&output.to_le_bytes());"); + + src.push_str("}"); + + src.push_str("}"); + } + + src.push_str("std::io::stdout().write_all(&result).unwrap();"); + + src.push_str("}"); + + let path = format!("{}/gen.rs", dst); + fs::write(&path, src).unwrap(); + + // Make it somewhat pretty if something goes wrong + drop(Command::new("rustfmt").arg(&path).status()); + + // Compile and execute this tests for the musl target, assuming we're an + // x86_64 host effectively. + let status = Command::new("rustc") + .current_dir(&dst) + .arg(&path) + .arg("--target=x86_64-unknown-linux-musl") + .status() + .unwrap(); + assert!(status.success()); + let output = Command::new("./gen").current_dir(&dst).output().unwrap(); + assert!(output.status.success()); + assert!(output.stderr.is_empty()); + + // Map all the output bytes back to an `i64` and then shove it all into + // the expected results. + let mut results = output.stdout.chunks_exact(8).map(|buf| { + let mut exact = [0; 8]; + exact.copy_from_slice(buf); + i64::from_le_bytes(exact) + }); + + for test in functions.iter_mut().flat_map(|f| f.tests.iter_mut()) { + test.output = results.next().unwrap(); + } + assert!(results.next().is_none()); + } + + /// Codegens a file which has a ton of `#[test]` annotations for all the + /// tests that we generated above. + fn generate_unit_tests(functions: &[Function]) { + let mut src = String::new(); + let dst = std::env::var("OUT_DIR").unwrap(); + + for function in functions { + src.push_str("#[test]"); + src.push_str("fn "); + src.push_str(&function.name); + src.push_str("_matches_musl() {"); + src.push_str(&format!( + "static TESTS: &[([i64; {}], i64)]", + function.args.len() + )); + src.push_str(" = &["); + for test in function.tests.iter() { + src.push_str("(["); + for val in test.inputs.iter() { + src.push_str(&val.to_string()); + src.push_str(","); + } + src.push_str("],"); + src.push_str(&test.output.to_string()); + src.push_str("),"); + } + src.push_str("];"); + + src.push_str("for (test, expected) in TESTS {"); + src.push_str("let output = "); + src.push_str(&function.name); + src.push_str("("); + for (i, arg) in function.args.iter().enumerate() { + src.push_str(&match arg { + Ty::F32 => format!("f32::from_bits(test[{}] as u32)", i), + Ty::F64 => format!("f64::from_bits(test[{}] as u64)", i), + Ty::I32 => format!("test[{}] as i32", i), + Ty::Bool => format!("test[{}] as i32", i), + }); + src.push_str(","); + } + src.push_str(");"); + src.push_str(match function.ret { + Ty::F32 => "if _eqf(output, f32::from_bits(*expected as u32)).is_ok() { continue }", + Ty::F64 => "if _eq(output, f64::from_bits(*expected as u64)).is_ok() { continue }", + Ty::I32 => "if output as i64 == expected { continue }", + Ty::Bool => unreachable!(), + }); + + src.push_str( + r#" + panic!("INPUT: {:?} EXPECTED: {:?} ACTUAL {:?}", test, expected, output); + "#, + ); + src.push_str("}"); + + src.push_str("}"); + } + + let path = format!("{}/musl-tests.rs", dst); + fs::write(&path, src).unwrap(); + + // Try to make it somewhat pretty + drop(Command::new("rustfmt").arg(&path).status()); + } +} diff --git a/library/compiler-builtins/libm/ci/azure-install-rust.yml b/library/compiler-builtins/libm/ci/azure-install-rust.yml new file mode 100644 index 000000000000..fa7eae459b79 --- /dev/null +++ b/library/compiler-builtins/libm/ci/azure-install-rust.yml @@ -0,0 +1,23 @@ +steps: + - bash: | + set -e + toolchain=$TOOLCHAIN + if [ "$toolchain" = "" ]; then + toolchain=stable + fi + curl https://sh.rustup.rs -sSf | sh -s -- -y --default-toolchain $toolchain + echo "##vso[task.prependpath]$HOME/.cargo/bin" + displayName: Install rust (unix) + condition: ne( variables['Agent.OS'], 'Windows_NT' ) + + - script: | + curl -sSf -o rustup-init.exe https://win.rustup.rs + rustup-init.exe -y --default-toolchain stable-%TARGET% + echo ##vso[task.prependpath]%USERPROFILE%\.cargo\bin + displayName: Install rust (windows) + condition: eq( variables['Agent.OS'], 'Windows_NT' ) + + - script: | + rustc -Vv + cargo -V + displayName: Query rust and cargo versions diff --git a/library/compiler-builtins/libm/ci/docker/aarch64-unknown-linux-gnu/Dockerfile b/library/compiler-builtins/libm/ci/docker/aarch64-unknown-linux-gnu/Dockerfile new file mode 100644 index 000000000000..9e2559f4ab3a --- /dev/null +++ b/library/compiler-builtins/libm/ci/docker/aarch64-unknown-linux-gnu/Dockerfile @@ -0,0 +1,10 @@ +FROM ubuntu:18.04 +RUN apt-get update && \ + apt-get install -y --no-install-recommends \ + gcc libc6-dev ca-certificates \ + gcc-aarch64-linux-gnu libc6-dev-arm64-cross \ + qemu-user-static +ENV CARGO_TARGET_AARCH64_UNKNOWN_LINUX_GNU_LINKER=aarch64-linux-gnu-gcc \ + CARGO_TARGET_AARCH64_UNKNOWN_LINUX_GNU_RUNNER=qemu-aarch64-static \ + QEMU_LD_PREFIX=/usr/aarch64-linux-gnu \ + RUST_TEST_THREADS=1 diff --git a/library/compiler-builtins/libm/ci/docker/arm-unknown-linux-gnueabi/Dockerfile b/library/compiler-builtins/libm/ci/docker/arm-unknown-linux-gnueabi/Dockerfile new file mode 100644 index 000000000000..afab874bc281 --- /dev/null +++ b/library/compiler-builtins/libm/ci/docker/arm-unknown-linux-gnueabi/Dockerfile @@ -0,0 +1,9 @@ +FROM ubuntu:18.04 +RUN apt-get update && \ + apt-get install -y --no-install-recommends \ + gcc libc6-dev ca-certificates \ + gcc-arm-linux-gnueabi libc6-dev-armel-cross qemu-user-static +ENV CARGO_TARGET_ARM_UNKNOWN_LINUX_GNUEABI_LINKER=arm-linux-gnueabi-gcc \ + CARGO_TARGET_ARM_UNKNOWN_LINUX_GNUEABI_RUNNER=qemu-arm-static \ + QEMU_LD_PREFIX=/usr/arm-linux-gnueabi \ + RUST_TEST_THREADS=1 diff --git a/library/compiler-builtins/libm/ci/docker/arm-unknown-linux-gnueabihf/Dockerfile b/library/compiler-builtins/libm/ci/docker/arm-unknown-linux-gnueabihf/Dockerfile new file mode 100644 index 000000000000..3ed3602b0dc9 --- /dev/null +++ b/library/compiler-builtins/libm/ci/docker/arm-unknown-linux-gnueabihf/Dockerfile @@ -0,0 +1,9 @@ +FROM ubuntu:18.04 +RUN apt-get update && \ + apt-get install -y --no-install-recommends \ + gcc libc6-dev ca-certificates \ + gcc-arm-linux-gnueabihf libc6-dev-armhf-cross qemu-user-static +ENV CARGO_TARGET_ARM_UNKNOWN_LINUX_GNUEABIHF_LINKER=arm-linux-gnueabihf-gcc \ + CARGO_TARGET_ARM_UNKNOWN_LINUX_GNUEABIHF_RUNNER=qemu-arm-static \ + QEMU_LD_PREFIX=/usr/arm-linux-gnueabihf \ + RUST_TEST_THREADS=1 diff --git a/library/compiler-builtins/libm/ci/docker/armv7-unknown-linux-gnueabihf/Dockerfile b/library/compiler-builtins/libm/ci/docker/armv7-unknown-linux-gnueabihf/Dockerfile new file mode 100644 index 000000000000..6617af1558c9 --- /dev/null +++ b/library/compiler-builtins/libm/ci/docker/armv7-unknown-linux-gnueabihf/Dockerfile @@ -0,0 +1,9 @@ +FROM ubuntu:18.04 +RUN apt-get update && \ + apt-get install -y --no-install-recommends \ + gcc libc6-dev ca-certificates \ + gcc-arm-linux-gnueabihf libc6-dev-armhf-cross qemu-user-static +ENV CARGO_TARGET_ARMV7_UNKNOWN_LINUX_GNUEABIHF_LINKER=arm-linux-gnueabihf-gcc \ + CARGO_TARGET_ARMV7_UNKNOWN_LINUX_GNUEABIHF_RUNNER=qemu-arm-static \ + QEMU_LD_PREFIX=/usr/arm-linux-gnueabihf \ + RUST_TEST_THREADS=1 diff --git a/library/compiler-builtins/libm/ci/docker/i686-unknown-linux-gnu/Dockerfile b/library/compiler-builtins/libm/ci/docker/i686-unknown-linux-gnu/Dockerfile new file mode 100644 index 000000000000..5783e28e1220 --- /dev/null +++ b/library/compiler-builtins/libm/ci/docker/i686-unknown-linux-gnu/Dockerfile @@ -0,0 +1,4 @@ +FROM ubuntu:18.04 +RUN apt-get update && \ + apt-get install -y --no-install-recommends \ + gcc-multilib libc6-dev ca-certificates diff --git a/library/compiler-builtins/libm/ci/docker/mips-unknown-linux-gnu/Dockerfile b/library/compiler-builtins/libm/ci/docker/mips-unknown-linux-gnu/Dockerfile new file mode 100644 index 000000000000..f47e8f5227b4 --- /dev/null +++ b/library/compiler-builtins/libm/ci/docker/mips-unknown-linux-gnu/Dockerfile @@ -0,0 +1,12 @@ +FROM ubuntu:18.04 + +RUN apt-get update && \ + apt-get install -y --no-install-recommends \ + gcc libc6-dev ca-certificates \ + gcc-mips-linux-gnu libc6-dev-mips-cross \ + binfmt-support qemu-user-static qemu-system-mips + +ENV CARGO_TARGET_MIPS_UNKNOWN_LINUX_GNU_LINKER=mips-linux-gnu-gcc \ + CARGO_TARGET_MIPS_UNKNOWN_LINUX_GNU_RUNNER=qemu-mips-static \ + QEMU_LD_PREFIX=/usr/mips-linux-gnu \ + RUST_TEST_THREADS=1 diff --git a/library/compiler-builtins/libm/ci/docker/mips64-unknown-linux-gnuabi64/Dockerfile b/library/compiler-builtins/libm/ci/docker/mips64-unknown-linux-gnuabi64/Dockerfile new file mode 100644 index 000000000000..8fa77c7bd073 --- /dev/null +++ b/library/compiler-builtins/libm/ci/docker/mips64-unknown-linux-gnuabi64/Dockerfile @@ -0,0 +1,15 @@ +FROM ubuntu:18.04 +RUN apt-get update && \ + apt-get install -y --no-install-recommends \ + ca-certificates \ + gcc \ + gcc-mips64-linux-gnuabi64 \ + libc6-dev \ + libc6-dev-mips64-cross \ + qemu-user-static \ + qemu-system-mips +ENV CARGO_TARGET_MIPS64_UNKNOWN_LINUX_GNUABI64_LINKER=mips64-linux-gnuabi64-gcc \ + CARGO_TARGET_MIPS64_UNKNOWN_LINUX_GNUABI64_RUNNER=qemu-mips64-static \ + CC_mips64_unknown_linux_gnuabi64=mips64-linux-gnuabi64-gcc \ + QEMU_LD_PREFIX=/usr/mips64-linux-gnuabi64 \ + RUST_TEST_THREADS=1 diff --git a/library/compiler-builtins/libm/ci/docker/mips64el-unknown-linux-gnuabi64/Dockerfile b/library/compiler-builtins/libm/ci/docker/mips64el-unknown-linux-gnuabi64/Dockerfile new file mode 100644 index 000000000000..c6611d9ac899 --- /dev/null +++ b/library/compiler-builtins/libm/ci/docker/mips64el-unknown-linux-gnuabi64/Dockerfile @@ -0,0 +1,14 @@ +FROM ubuntu:18.04 +RUN apt-get update && \ + apt-get install -y --no-install-recommends \ + ca-certificates \ + gcc \ + gcc-mips64el-linux-gnuabi64 \ + libc6-dev \ + libc6-dev-mips64el-cross \ + qemu-user-static +ENV CARGO_TARGET_MIPS64EL_UNKNOWN_LINUX_GNUABI64_LINKER=mips64el-linux-gnuabi64-gcc \ + CARGO_TARGET_MIPS64EL_UNKNOWN_LINUX_GNUABI64_RUNNER=qemu-mips64el-static \ + CC_mips64el_unknown_linux_gnuabi64=mips64el-linux-gnuabi64-gcc \ + QEMU_LD_PREFIX=/usr/mips64el-linux-gnuabi64 \ + RUST_TEST_THREADS=1 diff --git a/library/compiler-builtins/libm/ci/docker/mipsel-unknown-linux-gnu/Dockerfile b/library/compiler-builtins/libm/ci/docker/mipsel-unknown-linux-gnu/Dockerfile new file mode 100644 index 000000000000..0bc695624620 --- /dev/null +++ b/library/compiler-builtins/libm/ci/docker/mipsel-unknown-linux-gnu/Dockerfile @@ -0,0 +1,12 @@ +FROM ubuntu:18.04 + +RUN apt-get update && \ + apt-get install -y --no-install-recommends \ + gcc libc6-dev ca-certificates \ + gcc-mipsel-linux-gnu libc6-dev-mipsel-cross \ + binfmt-support qemu-user-static + +ENV CARGO_TARGET_MIPSEL_UNKNOWN_LINUX_GNU_LINKER=mipsel-linux-gnu-gcc \ + CARGO_TARGET_MIPSEL_UNKNOWN_LINUX_GNU_RUNNER=qemu-mipsel-static \ + QEMU_LD_PREFIX=/usr/mipsel-linux-gnu \ + RUST_TEST_THREADS=1 diff --git a/library/compiler-builtins/libm/ci/docker/powerpc-unknown-linux-gnu/Dockerfile b/library/compiler-builtins/libm/ci/docker/powerpc-unknown-linux-gnu/Dockerfile new file mode 100644 index 000000000000..2d39fef6142b --- /dev/null +++ b/library/compiler-builtins/libm/ci/docker/powerpc-unknown-linux-gnu/Dockerfile @@ -0,0 +1,12 @@ +FROM ubuntu:18.04 + +RUN apt-get update && \ + apt-get install -y --no-install-recommends \ + gcc libc6-dev qemu-user-static ca-certificates \ + gcc-powerpc-linux-gnu libc6-dev-powerpc-cross \ + qemu-system-ppc + +ENV CARGO_TARGET_POWERPC_UNKNOWN_LINUX_GNU_LINKER=powerpc-linux-gnu-gcc \ + CARGO_TARGET_POWERPC_UNKNOWN_LINUX_GNU_RUNNER=qemu-ppc-static \ + QEMU_LD_PREFIX=/usr/powerpc-linux-gnu \ + RUST_TEST_THREADS=1 diff --git a/library/compiler-builtins/libm/ci/docker/powerpc64-unknown-linux-gnu/Dockerfile b/library/compiler-builtins/libm/ci/docker/powerpc64-unknown-linux-gnu/Dockerfile new file mode 100644 index 000000000000..653cd351156e --- /dev/null +++ b/library/compiler-builtins/libm/ci/docker/powerpc64-unknown-linux-gnu/Dockerfile @@ -0,0 +1,13 @@ +FROM ubuntu:18.04 + +RUN apt-get update && \ + apt-get install -y --no-install-recommends \ + gcc libc6-dev ca-certificates \ + gcc-powerpc64-linux-gnu libc6-dev-ppc64-cross \ + binfmt-support qemu-user-static qemu-system-ppc + +ENV CARGO_TARGET_POWERPC64_UNKNOWN_LINUX_GNU_LINKER=powerpc64-linux-gnu-gcc \ + CARGO_TARGET_POWERPC64_UNKNOWN_LINUX_GNU_RUNNER=qemu-ppc64-static \ + CC_powerpc64_unknown_linux_gnu=powerpc64-linux-gnu-gcc \ + QEMU_LD_PREFIX=/usr/powerpc64-linux-gnu \ + RUST_TEST_THREADS=1 diff --git a/library/compiler-builtins/libm/ci/docker/powerpc64le-unknown-linux-gnu/Dockerfile b/library/compiler-builtins/libm/ci/docker/powerpc64le-unknown-linux-gnu/Dockerfile new file mode 100644 index 000000000000..63ea9af9d202 --- /dev/null +++ b/library/compiler-builtins/libm/ci/docker/powerpc64le-unknown-linux-gnu/Dockerfile @@ -0,0 +1,13 @@ +FROM ubuntu:18.04 + +RUN apt-get update && \ + apt-get install -y --no-install-recommends \ + gcc libc6-dev qemu-user-static ca-certificates \ + gcc-powerpc64le-linux-gnu libc6-dev-ppc64el-cross \ + qemu-system-ppc + +ENV CARGO_TARGET_POWERPC64LE_UNKNOWN_LINUX_GNU_LINKER=powerpc64le-linux-gnu-gcc \ + CARGO_TARGET_POWERPC64LE_UNKNOWN_LINUX_GNU_RUNNER=qemu-ppc64le-static \ + QEMU_CPU=POWER8 \ + QEMU_LD_PREFIX=/usr/powerpc64le-linux-gnu \ + RUST_TEST_THREADS=1 diff --git a/library/compiler-builtins/libm/ci/docker/x86_64-unknown-linux-gnu/Dockerfile b/library/compiler-builtins/libm/ci/docker/x86_64-unknown-linux-gnu/Dockerfile new file mode 100644 index 000000000000..98000f4eb81a --- /dev/null +++ b/library/compiler-builtins/libm/ci/docker/x86_64-unknown-linux-gnu/Dockerfile @@ -0,0 +1,4 @@ +FROM ubuntu:18.04 +RUN apt-get update && \ + apt-get install -y --no-install-recommends \ + gcc libc6-dev ca-certificates diff --git a/library/compiler-builtins/libm/ci/install.sh b/library/compiler-builtins/libm/ci/install.sh deleted file mode 100644 index af26e2d4c30e..000000000000 --- a/library/compiler-builtins/libm/ci/install.sh +++ /dev/null @@ -1,25 +0,0 @@ -set -euxo pipefail - -main() { - if [ $TARGET = cargo-fmt ]; then - rustup component add rustfmt-preview - return - fi - - if ! hash cross >/dev/null 2>&1; then - cargo install cross - fi - - rustup target add x86_64-unknown-linux-musl - - if [ $TARGET != x86_64-unknown-linux-gnu ]; then - rustup target add $TARGET - fi - - mkdir -p ~/.local/bin - curl -L https://github.com/japaric/qemu-bin/raw/master/14.04/qemu-arm-2.12.0 > ~/.local/bin/qemu-arm - chmod +x ~/.local/bin/qemu-arm - qemu-arm --version -} - -main diff --git a/library/compiler-builtins/libm/ci/run-docker.sh b/library/compiler-builtins/libm/ci/run-docker.sh new file mode 100755 index 000000000000..95bd3db4836e --- /dev/null +++ b/library/compiler-builtins/libm/ci/run-docker.sh @@ -0,0 +1,37 @@ +# Small script to run tests for a target (or all targets) inside all the +# respective docker images. + +set -ex + +run() { + local target=$1 + + echo $target + + # This directory needs to exist before calling docker, otherwise docker will create it but it + # will be owned by root + mkdir -p target + + docker build -t $target ci/docker/$target + docker run \ + --rm \ + --user $(id -u):$(id -g) \ + -e CARGO_HOME=/cargo \ + -e CARGO_TARGET_DIR=/target \ + -v $HOME/.cargo:/cargo \ + -v `pwd`/target:/target \ + -v `pwd`:/checkout:ro \ + -v `rustc --print sysroot`:/rust:ro \ + --init \ + -w /checkout \ + $target \ + sh -c "HOME=/tmp PATH=\$PATH:/rust/bin exec ci/run.sh $target" +} + +if [ -z "$1" ]; then + for d in `ls ci/docker/`; do + run $d + done +else + run $1 +fi diff --git a/library/compiler-builtins/libm/ci/run.sh b/library/compiler-builtins/libm/ci/run.sh new file mode 100755 index 000000000000..d28811300399 --- /dev/null +++ b/library/compiler-builtins/libm/ci/run.sh @@ -0,0 +1,12 @@ +#!/bin/sh + +set -ex +TARGET=$1 + +cargo test --target $TARGET +cargo test --target $TARGET --release + +# FIXME(#4) overflow checks in non-release currently cause issues +#cargo test --features 'checked musl-reference-tests' --target $TARGET + +cargo test --features 'checked musl-reference-tests' --target $TARGET --release diff --git a/library/compiler-builtins/libm/ci/script.sh b/library/compiler-builtins/libm/ci/script.sh deleted file mode 100644 index c3b6faa6cac6..000000000000 --- a/library/compiler-builtins/libm/ci/script.sh +++ /dev/null @@ -1,37 +0,0 @@ -set -euxo pipefail - -main() { - if [ $TARGET = cargo-fmt ]; then - cargo fmt -- --check - return - fi - - # quick check - cargo check - - # check that we can source import libm into compiler-builtins - cargo check --package cb - - # generate tests - cargo run -p input-generator --target x86_64-unknown-linux-musl - cargo run -p musl-generator --target x86_64-unknown-linux-musl - cargo run -p newlib-generator - - # test that the functions don't contain invocations of `panic!` - case $TARGET in - armv7-unknown-linux-gnueabihf) - cross build --release --target $TARGET --example no-panic - ;; - esac - - # run unit tests - cross test --lib --features checked --target $TARGET --release - - # run generated tests - cross test --tests --features checked --target $TARGET --release - - # TODO need to fix overflow issues (cf. issue #4) - # cross test --target $TARGET -} - -main diff --git a/library/compiler-builtins/libm/cb/Cargo.toml b/library/compiler-builtins/libm/crates/compiler-builtins-smoke-test/Cargo.toml similarity index 100% rename from library/compiler-builtins/libm/cb/Cargo.toml rename to library/compiler-builtins/libm/crates/compiler-builtins-smoke-test/Cargo.toml diff --git a/library/compiler-builtins/libm/cb/src/lib.rs b/library/compiler-builtins/libm/crates/compiler-builtins-smoke-test/src/lib.rs similarity index 82% rename from library/compiler-builtins/libm/cb/src/lib.rs rename to library/compiler-builtins/libm/crates/compiler-builtins-smoke-test/src/lib.rs index 439ba7dc4e63..7fad301b9834 100644 --- a/library/compiler-builtins/libm/cb/src/lib.rs +++ b/library/compiler-builtins/libm/crates/compiler-builtins-smoke-test/src/lib.rs @@ -5,5 +5,5 @@ #![allow(dead_code)] #![no_std] -#[path = "../../src/math/mod.rs"] +#[path = "../../../src/math/mod.rs"] mod libm; diff --git a/library/compiler-builtins/libm/examples/no-panic.rs b/library/compiler-builtins/libm/examples/no-panic.rs deleted file mode 100644 index fb79f99afa12..000000000000 --- a/library/compiler-builtins/libm/examples/no-panic.rs +++ /dev/null @@ -1,115 +0,0 @@ -#![feature(lang_items)] -#![feature(panic_implementation)] -#![no_main] -#![no_std] - -extern crate libm; - -use core::panic::PanicInfo; -use core::ptr; - -macro_rules! force_eval { - ($e:expr) => { - unsafe { - core::ptr::read_volatile(&$e); - } - }; -} - -#[no_mangle] -pub fn main() { - force_eval!(libm::acos(random())); - force_eval!(libm::acosf(random())); - force_eval!(libm::asin(random())); - force_eval!(libm::asinf(random())); - force_eval!(libm::atan(random())); - force_eval!(libm::atan2(random(), random())); - force_eval!(libm::atan2f(random(), random())); - force_eval!(libm::atanf(random())); - force_eval!(libm::cbrt(random())); - force_eval!(libm::cbrtf(random())); - force_eval!(libm::ceil(random())); - force_eval!(libm::ceilf(random())); - force_eval!(libm::cos(random())); - force_eval!(libm::cosf(random())); - force_eval!(libm::cosh(random())); - force_eval!(libm::coshf(random())); - force_eval!(libm::exp(random())); - force_eval!(libm::exp2(random())); - force_eval!(libm::exp2f(random())); - force_eval!(libm::expf(random())); - force_eval!(libm::expm1(random())); - force_eval!(libm::expm1f(random())); - force_eval!(libm::fabs(random())); - force_eval!(libm::fabsf(random())); - force_eval!(libm::fdim(random(), random())); - force_eval!(libm::fdimf(random(), random())); - force_eval!(libm::floor(random())); - force_eval!(libm::floorf(random())); - force_eval!(libm::fma(random(), random(), random())); - force_eval!(libm::fmaf(random(), random(), random())); - force_eval!(libm::fmod(random(), random())); - force_eval!(libm::fmodf(random(), random())); - force_eval!(libm::hypot(random(), random())); - force_eval!(libm::hypotf(random(), random())); - force_eval!(libm::log(random())); - force_eval!(libm::log2(random())); - force_eval!(libm::log10(random())); - force_eval!(libm::log10f(random())); - force_eval!(libm::log1p(random())); - force_eval!(libm::log1pf(random())); - force_eval!(libm::log2f(random())); - force_eval!(libm::logf(random())); - force_eval!(libm::pow(random(), random())); - force_eval!(libm::powf(random(), random())); - force_eval!(libm::round(random())); - force_eval!(libm::roundf(random())); - force_eval!(libm::scalbn(random(), random())); - force_eval!(libm::scalbnf(random(), random())); - force_eval!(libm::sin(random())); - force_eval!(libm::sinf(random())); - force_eval!(libm::sinh(random())); - force_eval!(libm::sinhf(random())); - force_eval!(libm::sqrt(random())); - force_eval!(libm::sqrtf(random())); - force_eval!(libm::tan(random())); - force_eval!(libm::tanf(random())); - force_eval!(libm::tanh(random())); - force_eval!(libm::tanhf(random())); - force_eval!(libm::trunc(random())); - force_eval!(libm::truncf(random())); -} - -fn random() -> T -where - T: Copy, -{ - unsafe { - static mut X: usize = 0; - X += 8; - ptr::read_volatile(X as *const T) - } -} - -#[panic_implementation] -#[no_mangle] -pub fn panic(_info: &PanicInfo) -> ! { - // loop {} - extern "C" { - fn thou_shalt_not_panic() -> !; - } - - unsafe { thou_shalt_not_panic() } -} - -#[link(name = "c")] -extern "C" {} - -#[lang = "eh_personality"] -fn eh() {} - -#[no_mangle] -pub extern "C" fn __aeabi_unwind_cpp_pr0() {} - -#[no_mangle] -pub extern "C" fn __aeabi_unwind_cpp_pr1() {} diff --git a/library/compiler-builtins/libm/input-generator/Cargo.toml b/library/compiler-builtins/libm/input-generator/Cargo.toml deleted file mode 100644 index fef2558a8b09..000000000000 --- a/library/compiler-builtins/libm/input-generator/Cargo.toml +++ /dev/null @@ -1,7 +0,0 @@ -[package] -name = "input-generator" -version = "0.1.0" -authors = ["Jorge Aparicio "] - -[dependencies] -rand = "0.5.4" diff --git a/library/compiler-builtins/libm/input-generator/src/main.rs b/library/compiler-builtins/libm/input-generator/src/main.rs deleted file mode 100644 index b4a6ad142258..000000000000 --- a/library/compiler-builtins/libm/input-generator/src/main.rs +++ /dev/null @@ -1,189 +0,0 @@ -extern crate rand; - -use std::collections::BTreeSet; -use std::error::Error; -use std::fs::{self, File}; -use std::io::Write; - -use rand::{RngCore, SeedableRng, XorShiftRng}; - -const NTESTS: usize = 10_000; - -fn main() -> Result<(), Box> { - let mut rng = XorShiftRng::from_rng(&mut rand::thread_rng())?; - - fs::remove_dir_all("bin").ok(); - fs::create_dir_all("bin/input")?; - fs::create_dir_all("bin/output")?; - - f32(&mut rng)?; - f32f32(&mut rng)?; - f32f32f32(&mut rng)?; - f32i16(&mut rng)?; - f64(&mut rng)?; - f64f64(&mut rng)?; - f64f64f64(&mut rng)?; - f64i16(&mut rng)?; - - Ok(()) -} - -fn f32(rng: &mut XorShiftRng) -> Result<(), Box> { - let mut set = BTreeSet::new(); - - while set.len() < NTESTS { - let f = f32::from_bits(rng.next_u32()); - - if f.is_nan() { - continue; - } - - set.insert(f.to_bits()); - } - - let mut f = File::create("bin/input/f32")?; - for i in set { - f.write_all(&i.to_bytes())?; - } - - Ok(()) -} - -fn f32f32(rng: &mut XorShiftRng) -> Result<(), Box> { - let mut f = File::create("bin/input/f32f32")?; - let mut i = 0; - while i < NTESTS { - let x0 = f32::from_bits(rng.next_u32()); - let x1 = f32::from_bits(rng.next_u32()); - - if x0.is_nan() || x1.is_nan() { - continue; - } - - i += 1; - f.write_all(&x0.to_bits().to_bytes())?; - f.write_all(&x1.to_bits().to_bytes())?; - } - - Ok(()) -} - -fn f32i16(rng: &mut XorShiftRng) -> Result<(), Box> { - let mut f = File::create("bin/input/f32i16")?; - let mut i = 0; - while i < NTESTS { - let x0 = f32::from_bits(rng.next_u32()); - let x1 = rng.next_u32() as i16; - - if x0.is_nan() { - continue; - } - - i += 1; - f.write_all(&x0.to_bits().to_bytes())?; - f.write_all(&x1.to_bytes())?; - } - - Ok(()) -} - -fn f32f32f32(rng: &mut XorShiftRng) -> Result<(), Box> { - let mut f = File::create("bin/input/f32f32f32")?; - let mut i = 0; - while i < NTESTS { - let x0 = f32::from_bits(rng.next_u32()); - let x1 = f32::from_bits(rng.next_u32()); - let x2 = f32::from_bits(rng.next_u32()); - - if x0.is_nan() || x1.is_nan() || x2.is_nan() { - continue; - } - - i += 1; - f.write_all(&x0.to_bits().to_bytes())?; - f.write_all(&x1.to_bits().to_bytes())?; - f.write_all(&x2.to_bits().to_bytes())?; - } - - Ok(()) -} - -fn f64(rng: &mut XorShiftRng) -> Result<(), Box> { - let mut set = BTreeSet::new(); - - while set.len() < NTESTS { - let f = f64::from_bits(rng.next_u64()); - - if f.is_nan() { - continue; - } - - set.insert(f.to_bits()); - } - - let mut f = File::create("bin/input/f64")?; - for i in set { - f.write_all(&i.to_bytes())?; - } - - Ok(()) -} - -fn f64f64(rng: &mut XorShiftRng) -> Result<(), Box> { - let mut f = File::create("bin/input/f64f64")?; - let mut i = 0; - while i < NTESTS { - let x0 = f64::from_bits(rng.next_u64()); - let x1 = f64::from_bits(rng.next_u64()); - - if x0.is_nan() || x1.is_nan() { - continue; - } - - i += 1; - f.write_all(&x0.to_bits().to_bytes())?; - f.write_all(&x1.to_bits().to_bytes())?; - } - - Ok(()) -} - -fn f64f64f64(rng: &mut XorShiftRng) -> Result<(), Box> { - let mut f = File::create("bin/input/f64f64f64")?; - let mut i = 0; - while i < NTESTS { - let x0 = f64::from_bits(rng.next_u64()); - let x1 = f64::from_bits(rng.next_u64()); - let x2 = f64::from_bits(rng.next_u64()); - - if x0.is_nan() || x1.is_nan() || x2.is_nan() { - continue; - } - - i += 1; - f.write_all(&x0.to_bits().to_bytes())?; - f.write_all(&x1.to_bits().to_bytes())?; - f.write_all(&x2.to_bits().to_bytes())?; - } - - Ok(()) -} - -fn f64i16(rng: &mut XorShiftRng) -> Result<(), Box> { - let mut f = File::create("bin/input/f64i16")?; - let mut i = 0; - while i < NTESTS { - let x0 = f64::from_bits(rng.next_u64()); - let x1 = rng.next_u32() as i16; - - if x0.is_nan() { - continue; - } - - i += 1; - f.write_all(&x0.to_bits().to_bytes())?; - f.write_all(&x1.to_bytes())?; - } - - Ok(()) -} diff --git a/library/compiler-builtins/libm/math/.cargo/config b/library/compiler-builtins/libm/math/.cargo/config deleted file mode 100644 index be79c453ad69..000000000000 --- a/library/compiler-builtins/libm/math/.cargo/config +++ /dev/null @@ -1,11 +0,0 @@ -[target.thumbv7em-none-eabi] -rustflags = [ - "-C", "link-arg=-Wl,-Tlink.x", - "-C", "link-arg=-nostartfiles", - "-C", "link-arg=-mthumb", - "-C", "link-arg=-march=armv7e-m", - "-C", "link-arg=-mfloat-abi=soft", -] - -[build] -target = "thumbv7em-none-eabi" \ No newline at end of file diff --git a/library/compiler-builtins/libm/math/Cargo.toml b/library/compiler-builtins/libm/math/Cargo.toml deleted file mode 100644 index 5bca038a9c3c..000000000000 --- a/library/compiler-builtins/libm/math/Cargo.toml +++ /dev/null @@ -1,8 +0,0 @@ -[package] -name = "math" -version = "0.0.0" - -[dependencies] -qemu-arm-rt = { git = "https://github.com/japaric/qemu-arm-rt" } - -[workspace] \ No newline at end of file diff --git a/library/compiler-builtins/libm/math/Cross.toml b/library/compiler-builtins/libm/math/Cross.toml deleted file mode 100644 index 471770b528b4..000000000000 --- a/library/compiler-builtins/libm/math/Cross.toml +++ /dev/null @@ -1,2 +0,0 @@ -[target.thumbv7em-none-eabi] -xargo = false \ No newline at end of file diff --git a/library/compiler-builtins/libm/musl-generator/Cargo.toml b/library/compiler-builtins/libm/musl-generator/Cargo.toml deleted file mode 100644 index 0564f3536116..000000000000 --- a/library/compiler-builtins/libm/musl-generator/Cargo.toml +++ /dev/null @@ -1,9 +0,0 @@ -[package] -name = "musl-generator" -version = "0.1.0" -authors = ["Jorge Aparicio "] - -[dependencies] -lazy_static = "1.0.2" -shared = { path = "../shared" } -libm = { path = ".." } diff --git a/library/compiler-builtins/libm/musl-generator/src/macros.rs b/library/compiler-builtins/libm/musl-generator/src/macros.rs deleted file mode 100644 index 16ba99d640c6..000000000000 --- a/library/compiler-builtins/libm/musl-generator/src/macros.rs +++ /dev/null @@ -1,191 +0,0 @@ -macro_rules! f32 { - ($($fun:ident,)+) => {{ - $( - // check type signature - let _: fn(f32) -> f32 = libm::$fun; - let mut $fun = File::create(concat!("bin/output/musl.", stringify!($fun)))?; - )+ - - for x in shared::F32.iter() { - $( - let y = unsafe { - extern "C" { - fn $fun(_: f32) -> f32; - } - - $fun(*x) - }; - - $fun.write_all(&y.to_bits().to_bytes())?; - )+ - } - }}; -} - -macro_rules! f32f32 { - ($($fun:ident,)+) => {{ - $( - // check type signature - let _: fn(f32, f32) -> f32 = libm::$fun; - let mut $fun = File::create(concat!("bin/output/musl.", stringify!($fun)))?; - )+ - - for (x0, x1) in shared::F32F32.iter() { - $( - let y = unsafe { - extern "C" { - fn $fun(_: f32, _: f32) -> f32; - } - - $fun(*x0, *x1) - }; - - $fun.write_all(&y.to_bits().to_bytes())?; - )+ - } - }}; -} - -macro_rules! f32f32f32 { - ($($fun:ident,)+) => {{ - $( - // check type signature - let _: fn(f32, f32, f32) -> f32 = libm::$fun; - let mut $fun = File::create(concat!("bin/output/musl.", stringify!($fun)))?; - )+ - - for (x0, x1, x2) in shared::F32F32F32.iter() { - $( - let y = unsafe { - extern "C" { - fn $fun(_: f32, _: f32, _: f32) -> f32; - } - - $fun(*x0, *x1, *x2) - }; - - $fun.write_all(&y.to_bits().to_bytes())?; - )+ - } - }}; -} - -macro_rules! f32i32 { - ($($fun:ident,)+) => {{ - $( - // check type signature - let _: fn(f32, i32) -> f32 = libm::$fun; - let mut $fun = File::create(concat!("bin/output/musl.", stringify!($fun)))?; - )+ - - for (x0, x1) in shared::F32I32.iter() { - $( - let y = unsafe { - extern "C" { - fn $fun(_: f32, _: i32) -> f32; - } - - $fun(*x0, *x1 as i32) - }; - - $fun.write_all(&y.to_bits().to_bytes())?; - )+ - } - }}; -} - -macro_rules! f64 { - ($($fun:ident,)+) => {{ - $( - // check type signature - let _: fn(f64) -> f64 = libm::$fun; - let mut $fun = File::create(concat!("bin/output/musl.", stringify!($fun)))?; - )+ - - for x in shared::F64.iter() { - $( - let y = unsafe { - extern "C" { - fn $fun(_: f64) -> f64; - } - - $fun(*x) - }; - - $fun.write_all(&y.to_bits().to_bytes())?; - )+ - } - }}; -} - -macro_rules! f64f64 { - ($($fun:ident,)+) => {{ - $( - // check type signature - let _: fn(f64, f64) -> f64 = libm::$fun; - let mut $fun = File::create(concat!("bin/output/musl.", stringify!($fun)))?; - )+ - - for (x0, x1) in shared::F64F64.iter() { - $( - let y = unsafe { - extern "C" { - fn $fun(_: f64, _: f64) -> f64; - } - - $fun(*x0, *x1) - }; - - $fun.write_all(&y.to_bits().to_bytes())?; - )+ - } - }}; -} - -macro_rules! f64f64f64 { - ($($fun:ident,)+) => {{ - $( - // check type signature - let _: fn(f64, f64, f64) -> f64 = libm::$fun; - let mut $fun = File::create(concat!("bin/output/musl.", stringify!($fun)))?; - )+ - - for (x0, x1, x2) in shared::F64F64F64.iter() { - $( - let y = unsafe { - extern "C" { - fn $fun(_: f64, _: f64, _: f64) -> f64; - } - - $fun(*x0, *x1, *x2) - }; - - $fun.write_all(&y.to_bits().to_bytes())?; - )+ - } - }}; -} - -macro_rules! f64i32 { - ($($fun:ident,)+) => {{ - $( - // check type signature - let _: fn(f64, i32) -> f64 = libm::$fun; - let mut $fun = File::create(concat!("bin/output/musl.", stringify!($fun)))?; - )+ - - for (x0, x1) in shared::F64I32.iter() { - $( - let y = unsafe { - extern "C" { - fn $fun(_: f64, _: i32) -> f64; - } - - $fun(*x0, *x1 as i32) - }; - - $fun.write_all(&y.to_bits().to_bytes())?; - )+ - } - }}; -} diff --git a/library/compiler-builtins/libm/musl-generator/src/main.rs b/library/compiler-builtins/libm/musl-generator/src/main.rs deleted file mode 100644 index 6e57e856dc64..000000000000 --- a/library/compiler-builtins/libm/musl-generator/src/main.rs +++ /dev/null @@ -1,97 +0,0 @@ -extern crate libm; -extern crate shared; - -use std::error::Error; -use std::fs::File; -use std::io::Write; - -#[macro_use] -mod macros; - -fn main() -> Result<(), Box> { - f32! { - acosf, - asinf, - atanf, - cbrtf, - ceilf, - cosf, - coshf, - exp2f, - expf, - expm1f, - fabsf, - floorf, - log10f, - log1pf, - log2f, - logf, - roundf, - sinf, - sinhf, - sqrtf, - tanf, - tanhf, - truncf, - } - - f32f32! { - atan2f, - fdimf, - fmodf, - hypotf, - powf, - } - - f32i32! { - scalbnf, - } - - f32f32f32! { - fmaf, - } - - f64! { - acos, - asin, - atan, - cbrt, - ceil, - cos, - cosh, - exp, - exp2, - expm1, - fabs, - floor, - log, - log10, - log1p, - log2, - round, - sin, - sinh, - sqrt, - tan, - tanh, - trunc, - } - - f64f64! { - atan2, - fdim, - fmod, - hypot, - pow, - } - - f64i32! { - scalbn, - } - - f64f64f64! { - fma, - } - - Ok(()) -} diff --git a/library/compiler-builtins/libm/newlib-generator/Cargo.toml b/library/compiler-builtins/libm/newlib-generator/Cargo.toml deleted file mode 100644 index 5766cb4b7a05..000000000000 --- a/library/compiler-builtins/libm/newlib-generator/Cargo.toml +++ /dev/null @@ -1,7 +0,0 @@ -[package] -name = "newlib-generator" -version = "0.1.0" -authors = ["Jorge Aparicio "] - -[dependencies] -shared = { path = "../shared" } diff --git a/library/compiler-builtins/libm/newlib-generator/src/macros.rs b/library/compiler-builtins/libm/newlib-generator/src/macros.rs deleted file mode 100644 index 84315a777bde..000000000000 --- a/library/compiler-builtins/libm/newlib-generator/src/macros.rs +++ /dev/null @@ -1,245 +0,0 @@ -macro_rules! f32 { - ($($fun:ident,)+) => { - $( - let fun = stringify!($fun); - - fs::create_dir_all("math/src")?; - - let main = format!(" -#![no_main] -#![no_std] - -#[macro_use] -extern crate qemu_arm_rt as rt; - -use core::u32; - -use rt::{{io, process}}; - -entry!(main); - -fn main() {{ - run().unwrap_or_else(|e| {{ - eprintln!(\"error: {{}}\", e); - process::exit(1); - }}) -}} - -fn run() -> Result<(), usize> {{ - #[link(name = \"m\")] - extern \"C\" {{ - fn {0}(_: f32) -> f32; - }} - - let mut buf = [0; 4]; - while let Ok(()) = io::Stdin.read_exact(&mut buf) {{ - let x = f32::from_bits(u32::from_bytes(buf)); - let y = unsafe {{ {0}(x) }}; - - io::Stdout.write_all(&y.to_bits().to_bytes())?; - }} - - Ok(()) -}} - -#[no_mangle] -pub fn __errno() -> *mut i32 {{ - static mut ERRNO: i32 = 0; - unsafe {{ &mut ERRNO }} -}} -", fun); - - File::create("math/src/main.rs")?.write_all(main.as_bytes())?; - - assert!( - Command::new("cross") - .args(&["build", "--target", "thumbv7em-none-eabi", "--release"]) - .current_dir("math") - .status()? - .success() - ); - - let mut qemu = Command::new("qemu-arm") - .arg("math/target/thumbv7em-none-eabi/release/math") - .stdin(Stdio::piped()) - .stdout(Stdio::piped()) - .spawn()?; - - qemu.stdin.as_mut().take().unwrap().write_all(F32)?; - - let output = qemu.wait_with_output()?; - - File::create(concat!("bin/output/newlib.", stringify!($fun)))? - .write_all(&output.stdout)?; - )+ - } -} - -macro_rules! f32f32 { - ($($fun:ident,)+) => { - $( - let fun = stringify!($fun); - - fs::create_dir_all("math/src")?; - - let main = format!(" -#![no_main] -#![no_std] - -#[macro_use] -extern crate qemu_arm_rt as rt; - -use core::u32; - -use rt::{{io, process}}; - -entry!(main); - -fn main() {{ - run().unwrap_or_else(|e| {{ - eprintln!(\"error: {{}}\", e); - process::exit(1); - }}) -}} - -fn run() -> Result<(), usize> {{ - #[link(name = \"m\")] - extern \"C\" {{ - fn {0}(_: f32, _: f32) -> f32; - }} - - let mut chunk = [0; 8]; - while let Ok(()) = io::Stdin.read_exact(&mut chunk) {{ - let mut buf = [0; 4]; - buf.copy_from_slice(&chunk[..4]); - let x0 = f32::from_bits(u32::from_bytes(buf)); - - buf.copy_from_slice(&chunk[4..]); - let x1 = f32::from_bits(u32::from_bytes(buf)); - - let y = unsafe {{ {0}(x0, x1) }}; - - io::Stdout.write_all(&y.to_bits().to_bytes())?; - }} - - Ok(()) -}} - -#[no_mangle] -pub fn __errno() -> *mut i32 {{ - static mut ERRNO: i32 = 0; - unsafe {{ &mut ERRNO }} -}} -", fun); - - File::create("math/src/main.rs")?.write_all(main.as_bytes())?; - - assert!( - Command::new("cross") - .args(&["build", "--target", "thumbv7em-none-eabi", "--release"]) - .current_dir("math") - .status()? - .success() - ); - - let mut qemu = Command::new("qemu-arm") - .arg("math/target/thumbv7em-none-eabi/release/math") - .stdin(Stdio::piped()) - .stdout(Stdio::piped()) - .spawn()?; - - qemu.stdin.as_mut().take().unwrap().write_all(F32)?; - - let output = qemu.wait_with_output()?; - - File::create(concat!("bin/output/newlib.", stringify!($fun)))? - .write_all(&output.stdout)?; - )+ - } -} - -macro_rules! f32f32f32 { - ($($fun:ident,)+) => { - $( - let fun = stringify!($fun); - - fs::create_dir_all("math/src")?; - - let main = format!(" -#![no_main] -#![no_std] - -#[macro_use] -extern crate qemu_arm_rt as rt; - -use core::u32; - -use rt::{{io, process}}; - -entry!(main); - -fn main() {{ - run().unwrap_or_else(|e| {{ - eprintln!(\"error: {{}}\", e); - process::exit(1); - }}) -}} - -fn run() -> Result<(), usize> {{ - #[link(name = \"m\")] - extern \"C\" {{ - fn {0}(_: f32, _: f32, _: f32) -> f32; - }} - - let mut chunk = [0; 12]; - while let Ok(()) = io::Stdin.read_exact(&mut chunk) {{ - let mut buf = [0; 4]; - buf.copy_from_slice(&chunk[..4]); - let x0 = f32::from_bits(u32::from_bytes(buf)); - - buf.copy_from_slice(&chunk[4..8]); - let x1 = f32::from_bits(u32::from_bytes(buf)); - - buf.copy_from_slice(&chunk[8..]); - let x2 = f32::from_bits(u32::from_bytes(buf)); - - let y = unsafe {{ {0}(x0, x1, x2) }}; - - io::Stdout.write_all(&y.to_bits().to_bytes())?; - }} - - Ok(()) -}} - -#[no_mangle] -pub fn __errno() -> *mut i32 {{ - static mut ERRNO: i32 = 0; - unsafe {{ &mut ERRNO }} -}} -", fun); - - File::create("math/src/main.rs")?.write_all(main.as_bytes())?; - - assert!( - Command::new("cross") - .args(&["build", "--target", "thumbv7em-none-eabi", "--release"]) - .current_dir("math") - .status()? - .success() - ); - - let mut qemu = Command::new("qemu-arm") - .arg("math/target/thumbv7em-none-eabi/release/math") - .stdin(Stdio::piped()) - .stdout(Stdio::piped()) - .spawn()?; - - qemu.stdin.as_mut().take().unwrap().write_all(F32)?; - - let output = qemu.wait_with_output()?; - - File::create(concat!("bin/output/newlib.", stringify!($fun)))? - .write_all(&output.stdout)?; - )+ - } -} diff --git a/library/compiler-builtins/libm/newlib-generator/src/main.rs b/library/compiler-builtins/libm/newlib-generator/src/main.rs deleted file mode 100644 index 52a97cabbfd4..000000000000 --- a/library/compiler-builtins/libm/newlib-generator/src/main.rs +++ /dev/null @@ -1,32 +0,0 @@ -extern crate shared; - -use std::error::Error; -use std::fs::{self, File}; -use std::io::Write; -use std::process::{Command, Stdio}; - -#[macro_use] -mod macros; - -fn main() -> Result<(), Box> { - const F32: &[u8] = include_bytes!("../../bin/input/f32"); - - f32! { - asinf, - cbrtf, - cosf, - exp2f, - sinf, - tanf, - } - - f32f32! { - hypotf, - } - - f32f32f32! { - fmaf, - } - - Ok(()) -} diff --git a/library/compiler-builtins/libm/shared/Cargo.toml b/library/compiler-builtins/libm/shared/Cargo.toml deleted file mode 100644 index d77823781016..000000000000 --- a/library/compiler-builtins/libm/shared/Cargo.toml +++ /dev/null @@ -1,7 +0,0 @@ -[package] -name = "shared" -version = "0.1.0" -authors = ["Jorge Aparicio "] - -[dependencies] -lazy_static = "1.0.2" diff --git a/library/compiler-builtins/libm/shared/src/lib.rs b/library/compiler-builtins/libm/shared/src/lib.rs deleted file mode 100644 index 84676f94f747..000000000000 --- a/library/compiler-builtins/libm/shared/src/lib.rs +++ /dev/null @@ -1,471 +0,0 @@ -#![feature(exact_chunks)] - -#[macro_use] -extern crate lazy_static; - -lazy_static! { - pub static ref F32: Vec = { - let bytes = include_bytes!("../../bin/input/f32"); - - bytes - .exact_chunks(4) - .map(|chunk| { - let mut buf = [0; 4]; - buf.copy_from_slice(chunk); - f32::from_bits(u32::from_le(u32::from_bytes(buf))) - }) - .collect() - }; - pub static ref F32F32: Vec<(f32, f32)> = { - let bytes = include_bytes!("../../bin/input/f32f32"); - - bytes - .exact_chunks(8) - .map(|chunk| { - let mut x0 = [0; 4]; - let mut x1 = [0; 4]; - x0.copy_from_slice(&chunk[..4]); - x1.copy_from_slice(&chunk[4..]); - - ( - f32::from_bits(u32::from_le(u32::from_bytes(x0))), - f32::from_bits(u32::from_le(u32::from_bytes(x1))), - ) - }) - .collect() - }; - pub static ref F32F32F32: Vec<(f32, f32, f32)> = { - let bytes = include_bytes!("../../bin/input/f32f32f32"); - - bytes - .exact_chunks(12) - .map(|chunk| { - let mut x0 = [0; 4]; - let mut x1 = [0; 4]; - let mut x2 = [0; 4]; - x0.copy_from_slice(&chunk[..4]); - x1.copy_from_slice(&chunk[4..8]); - x2.copy_from_slice(&chunk[8..]); - - ( - f32::from_bits(u32::from_le(u32::from_bytes(x0))), - f32::from_bits(u32::from_le(u32::from_bytes(x1))), - f32::from_bits(u32::from_le(u32::from_bytes(x2))), - ) - }) - .collect() - }; - pub static ref F32I32: Vec<(f32, i32)> = { - let bytes = include_bytes!("../../bin/input/f32i16"); - - bytes - .exact_chunks(6) - .map(|chunk| { - let mut x0 = [0; 4]; - let mut x1 = [0; 2]; - x0.copy_from_slice(&chunk[..4]); - x1.copy_from_slice(&chunk[4..]); - - ( - f32::from_bits(u32::from_le(u32::from_bytes(x0))), - i16::from_le(i16::from_bytes(x1)) as i32, - ) - }) - .collect() - }; - pub static ref F64: Vec = { - let bytes = include_bytes!("../../bin/input/f64"); - - bytes - .exact_chunks(8) - .map(|chunk| { - let mut buf = [0; 8]; - buf.copy_from_slice(chunk); - f64::from_bits(u64::from_le(u64::from_bytes(buf))) - }) - .collect() - }; - pub static ref F64F64: Vec<(f64, f64)> = { - let bytes = include_bytes!("../../bin/input/f64f64"); - - bytes - .exact_chunks(16) - .map(|chunk| { - let mut x0 = [0; 8]; - let mut x1 = [0; 8]; - x0.copy_from_slice(&chunk[..8]); - x1.copy_from_slice(&chunk[8..]); - - ( - f64::from_bits(u64::from_le(u64::from_bytes(x0))), - f64::from_bits(u64::from_le(u64::from_bytes(x1))), - ) - }) - .collect() - }; - pub static ref F64F64F64: Vec<(f64, f64, f64)> = { - let bytes = include_bytes!("../../bin/input/f64f64f64"); - - bytes - .exact_chunks(24) - .map(|chunk| { - let mut x0 = [0; 8]; - let mut x1 = [0; 8]; - let mut x2 = [0; 8]; - x0.copy_from_slice(&chunk[..8]); - x1.copy_from_slice(&chunk[8..16]); - x2.copy_from_slice(&chunk[16..]); - - ( - f64::from_bits(u64::from_le(u64::from_bytes(x0))), - f64::from_bits(u64::from_le(u64::from_bytes(x1))), - f64::from_bits(u64::from_le(u64::from_bytes(x2))), - ) - }) - .collect() - }; - pub static ref F64I32: Vec<(f64, i32)> = { - let bytes = include_bytes!("../../bin/input/f64i16"); - - bytes - .exact_chunks(10) - .map(|chunk| { - let mut x0 = [0; 8]; - let mut x1 = [0; 2]; - x0.copy_from_slice(&chunk[..8]); - x1.copy_from_slice(&chunk[8..]); - - ( - f64::from_bits(u64::from_le(u64::from_bytes(x0))), - i16::from_le(i16::from_bytes(x1)) as i32, - ) - }) - .collect() - }; -} - -#[macro_export] -macro_rules! f32 { - ($lib:expr, $($fun:ident),+) => { - $( - #[test] - fn $fun() { - let expected = include_bytes!(concat!("../bin/output/", $lib, ".", stringify!($fun))) - .exact_chunks(4) - .map(|chunk| { - let mut buf = [0; 4]; - buf.copy_from_slice(chunk); - f32::from_bits(u32::from_le(u32::from_bytes(buf))) - }) - .collect::>(); - - for (input, expected) in $crate::F32.iter().zip(&expected) { - if let Ok(output) = panic::catch_unwind(|| libm::$fun(*input)) { - if let Err(error) = libm::_eqf(output, *expected) { - panic!( - "INPUT: {:#x}, OUTPUT: {:#x}, EXPECTED: {:#x}, ERROR: {}", - input.to_bits(), - output.to_bits(), - expected.to_bits(), - error - ); - } - } else { - panic!( - "INPUT: {:#x}, OUTPUT: PANIC!, EXPECTED: {:#x}", - input.to_bits(), - expected.to_bits() - ); - } - } - } - )+ - } -} - -#[macro_export] -macro_rules! f32f32 { - ($lib:expr, $($fun:ident),+) => { - $( - #[test] - fn $fun() { - let expected = include_bytes!(concat!("../bin/output/", $lib, ".", stringify!($fun))) - .exact_chunks(4) - .map(|chunk| { - let mut buf = [0; 4]; - buf.copy_from_slice(chunk); - f32::from_bits(u32::from_le(u32::from_bytes(buf))) - }) - .collect::>(); - - for ((i0, i1), expected) in $crate::F32F32.iter().zip(&expected) { - if let Ok(output) = panic::catch_unwind(|| libm::$fun(*i0, *i1)) { - if let Err(error) = libm::_eqf(output, *expected) { - panic!( - "INPUT: ({:#x}, {:#x}), OUTPUT: {:#x}, EXPECTED: {:#x}, ERROR: {}", - i0.to_bits(), - i1.to_bits(), - output.to_bits(), - expected.to_bits(), - error - ); - } - } else { - panic!( - "INPUT: ({:#x}, {:#x}), OUTPUT: PANIC!, EXPECTED: {:#x}", - i0.to_bits(), - i1.to_bits(), - expected.to_bits() - ); - } - } - } - )+ - } -} - -#[macro_export] -macro_rules! f32f32f32 { - ($lib:expr, $($fun:ident),+) => { - $( - #[test] - fn $fun() { - let expected = include_bytes!(concat!("../bin/output/", $lib, ".", stringify!($fun))) - .exact_chunks(4) - .map(|chunk| { - let mut buf = [0; 4]; - buf.copy_from_slice(chunk); - f32::from_bits(u32::from_le(u32::from_bytes(buf))) - }) - .collect::>(); - - for ((i0, i1, i2), expected) in $crate::F32F32F32.iter().zip(&expected) { - if let Ok(output) = panic::catch_unwind(|| libm::$fun(*i0, *i1, *i2)) { - if let Err(error) = libm::_eqf(output, *expected) { - panic!( - "INPUT: ({:#x}, {:#x}, {:#x}), OUTPUT: {:#x}, EXPECTED: {:#x}, ERROR: {}", - i0.to_bits(), - i1.to_bits(), - i2.to_bits(), - output.to_bits(), - expected.to_bits(), - error - ); - } - } else { - panic!( - "INPUT: ({:#x}, {:#x}), OUTPUT: PANIC!, EXPECTED: {:#x}", - i0.to_bits(), - i1.to_bits(), - expected.to_bits() - ); - } - } - } - )+ - } -} - -#[macro_export] -macro_rules! f32i32 { - ($lib:expr, $($fun:ident),+) => { - $( - #[test] - fn $fun() { - let expected = include_bytes!(concat!("../bin/output/", $lib, ".", stringify!($fun))) - .exact_chunks(4) - .map(|chunk| { - let mut buf = [0; 4]; - buf.copy_from_slice(chunk); - f32::from_bits(u32::from_le(u32::from_bytes(buf))) - }) - .collect::>(); - - for ((i0, i1), expected) in $crate::F32I32.iter().zip(&expected) { - if let Ok(output) = panic::catch_unwind(|| libm::$fun(*i0, *i1)) { - if let Err(error) = libm::_eqf(output, *expected) { - panic!( - "INPUT: ({:#x}, {:#x}), OUTPUT: {:#x}, EXPECTED: {:#x}, ERROR: {}", - i0.to_bits(), - i1, - output.to_bits(), - expected.to_bits(), - error - ); - } - } else { - panic!( - "INPUT: ({:#x}, {:#x}), OUTPUT: PANIC!, EXPECTED: {:#x}", - i0.to_bits(), - i1, - expected.to_bits() - ); - } - } - } - )+ - } -} - -#[macro_export] -macro_rules! f64 { - ($lib:expr, $($fun:ident),+) => { - $( - #[test] - fn $fun() { - let expected = include_bytes!(concat!("../bin/output/", $lib, ".", stringify!($fun))) - .exact_chunks(8) - .map(|chunk| { - let mut buf = [0; 8]; - buf.copy_from_slice(chunk); - f64::from_bits(u64::from_le(u64::from_bytes(buf))) - }) - .collect::>(); - - for (input, expected) in shared::F64.iter().zip(&expected) { - if let Ok(output) = panic::catch_unwind(|| libm::$fun(*input)) { - if let Err(error) = libm::_eq(output, *expected) { - panic!( - "INPUT: {:#x}, OUTPUT: {:#x}, EXPECTED: {:#x}, ERROR: {}", - input.to_bits(), - output.to_bits(), - expected.to_bits(), - error - ); - } - } else { - panic!( - "INPUT: {:#x}, OUTPUT: PANIC!, EXPECTED: {:#x}", - input.to_bits(), - expected.to_bits() - ); - } - } - } - )+ - } -} - -#[macro_export] -macro_rules! f64f64 { - ($lib:expr, $($fun:ident),+) => { - $( - #[test] - fn $fun() { - let expected = include_bytes!(concat!("../bin/output/", $lib, ".", stringify!($fun))) - .exact_chunks(8) - .map(|chunk| { - let mut buf = [0; 8]; - buf.copy_from_slice(chunk); - f64::from_bits(u64::from_le(u64::from_bytes(buf))) - }) - .collect::>(); - - for ((i0, i1), expected) in shared::F64F64.iter().zip(&expected) { - if let Ok(output) = panic::catch_unwind(|| libm::$fun(*i0, *i1)) { - if let Err(error) = libm::_eq(output, *expected) { - panic!( - "INPUT: ({:#x}, {:#x}), OUTPUT: {:#x}, EXPECTED: {:#x}, ERROR: {}", - i0.to_bits(), - i1.to_bits(), - output.to_bits(), - expected.to_bits(), - error - ); - } - } else { - panic!( - "INPUT: ({:#x}, {:#x}), OUTPUT: PANIC!, EXPECTED: {:#x}", - i0.to_bits(), - i1.to_bits(), - expected.to_bits() - ); - } - } - } - )+ - } -} - -#[macro_export] -macro_rules! f64f64f64 { - ($lib:expr, $($fun:ident),+) => { - $( - #[test] - fn $fun() { - let expected = include_bytes!(concat!("../bin/output/", $lib, ".", stringify!($fun))) - .exact_chunks(8) - .map(|chunk| { - let mut buf = [0; 8]; - buf.copy_from_slice(chunk); - f64::from_bits(u64::from_le(u64::from_bytes(buf))) - }) - .collect::>(); - - for ((i0, i1, i2), expected) in shared::F64F64F64.iter().zip(&expected) { - if let Ok(output) = panic::catch_unwind(|| libm::$fun(*i0, *i1, *i2)) { - if let Err(error) = libm::_eq(output, *expected) { - panic!( - "INPUT: ({:#x}, {:#x}, {:#x}), OUTPUT: {:#x}, EXPECTED: {:#x}, ERROR: {}", - i0.to_bits(), - i1.to_bits(), - i2.to_bits(), - output.to_bits(), - expected.to_bits(), - error - ); - } - } else { - panic!( - "INPUT: ({:#x}, {:#x}), OUTPUT: PANIC!, EXPECTED: {:#x}", - i0.to_bits(), - i1.to_bits(), - expected.to_bits() - ); - } - } - } - )+ - } -} - -#[macro_export] -macro_rules! f64i32 { - ($lib:expr, $($fun:ident),+) => { - $( - #[test] - fn $fun() { - let expected = include_bytes!(concat!("../bin/output/", $lib, ".", stringify!($fun))) - .exact_chunks(8) - .map(|chunk| { - let mut buf = [0; 8]; - buf.copy_from_slice(chunk); - f64::from_bits(u64::from_le(u64::from_bytes(buf))) - }) - .collect::>(); - - for ((i0, i1), expected) in shared::F64I32.iter().zip(&expected) { - if let Ok(output) = panic::catch_unwind(|| libm::$fun(*i0, *i1)) { - if let Err(error) = libm::_eq(output, *expected) { - panic!( - "INPUT: ({:#x}, {:#x}), OUTPUT: {:#x}, EXPECTED: {:#x}, ERROR: {}", - i0.to_bits(), - i1, - output.to_bits(), - expected.to_bits(), - error - ); - } - } else { - panic!( - "INPUT: ({:#x}, {:#x}), OUTPUT: PANIC!, EXPECTED: {:#x}", - i0.to_bits(), - i1, - expected.to_bits() - ); - } - } - } - )+ - } -} diff --git a/library/compiler-builtins/libm/src/lib.rs b/library/compiler-builtins/libm/src/lib.rs index 6be458728197..5e94541ab1a3 100644 --- a/library/compiler-builtins/libm/src/lib.rs +++ b/library/compiler-builtins/libm/src/lib.rs @@ -625,3 +625,6 @@ mod private { impl Sealed for f32 {} impl Sealed for f64 {} } + +#[cfg(all(test, feature = "musl-reference-tests"))] +include!(concat!(env!("OUT_DIR"), "/musl-tests.rs")); diff --git a/library/compiler-builtins/libm/src/math/acos.rs b/library/compiler-builtins/libm/src/math/acos.rs index 276e361f3d5c..a0d1450e3a85 100644 --- a/library/compiler-builtins/libm/src/math/acos.rs +++ b/library/compiler-builtins/libm/src/math/acos.rs @@ -56,6 +56,7 @@ fn r(z: f64) -> f64 { } #[inline] +#[cfg_attr(all(test, assert_no_panic), no_panic::no_panic)] pub fn acos(x: f64) -> f64 { let x1p_120f = f64::from_bits(0x3870000000000000); // 0x1p-120 === 2 ^ -120 let z: f64; diff --git a/library/compiler-builtins/libm/src/math/acosf.rs b/library/compiler-builtins/libm/src/math/acosf.rs index 469601caba4d..a6061ae8027b 100644 --- a/library/compiler-builtins/libm/src/math/acosf.rs +++ b/library/compiler-builtins/libm/src/math/acosf.rs @@ -30,6 +30,7 @@ fn r(z: f32) -> f32 { } #[inline] +#[cfg_attr(all(test, assert_no_panic), no_panic::no_panic)] pub fn acosf(x: f32) -> f32 { let x1p_120 = f32::from_bits(0x03800000); // 0x1p-120 === 2 ^ (-120) diff --git a/library/compiler-builtins/libm/src/math/asin.rs b/library/compiler-builtins/libm/src/math/asin.rs index a0bb4918c5a4..855300837266 100644 --- a/library/compiler-builtins/libm/src/math/asin.rs +++ b/library/compiler-builtins/libm/src/math/asin.rs @@ -63,6 +63,7 @@ fn comp_r(z: f64) -> f64 { } #[inline] +#[cfg_attr(all(test, assert_no_panic), no_panic::no_panic)] pub fn asin(mut x: f64) -> f64 { let z: f64; let r: f64; diff --git a/library/compiler-builtins/libm/src/math/asinf.rs b/library/compiler-builtins/libm/src/math/asinf.rs index 79c85d81d006..979f1a6548fa 100644 --- a/library/compiler-builtins/libm/src/math/asinf.rs +++ b/library/compiler-builtins/libm/src/math/asinf.rs @@ -32,6 +32,7 @@ fn r(z: f32) -> f32 { } #[inline] +#[cfg_attr(all(test, assert_no_panic), no_panic::no_panic)] pub fn asinf(mut x: f32) -> f32 { let x1p_120 = f64::from_bits(0x3870000000000000); // 0x1p-120 === 2 ^ (-120) diff --git a/library/compiler-builtins/libm/src/math/atan.rs b/library/compiler-builtins/libm/src/math/atan.rs index cf6a62a54591..ad1d57c1fe79 100644 --- a/library/compiler-builtins/libm/src/math/atan.rs +++ b/library/compiler-builtins/libm/src/math/atan.rs @@ -61,6 +61,7 @@ const AT: [f64; 11] = [ ]; #[inline] +#[cfg_attr(all(test, assert_no_panic), no_panic::no_panic)] pub fn atan(x: f64) -> f64 { let mut x = x; let mut ix = (x.to_bits() >> 32) as u32; @@ -147,7 +148,8 @@ mod tests { (-3.0_f64.sqrt() / 3.0, -f64::consts::FRAC_PI_6), (-1.0, -f64::consts::FRAC_PI_4), (-3.0_f64.sqrt(), -f64::consts::FRAC_PI_3), - ].iter() + ] + .iter() { assert!( (atan(*input) - answer) / answer < 1e-5, diff --git a/library/compiler-builtins/libm/src/math/atan2.rs b/library/compiler-builtins/libm/src/math/atan2.rs index a91ddd84d0d7..a702ec39fe69 100644 --- a/library/compiler-builtins/libm/src/math/atan2.rs +++ b/library/compiler-builtins/libm/src/math/atan2.rs @@ -44,6 +44,7 @@ const PI: f64 = 3.1415926535897931160E+00; /* 0x400921FB, 0x54442D18 */ const PI_LO: f64 = 1.2246467991473531772E-16; /* 0x3CA1A626, 0x33145C07 */ #[inline] +#[cfg_attr(all(test, assert_no_panic), no_panic::no_panic)] pub fn atan2(y: f64, x: f64) -> f64 { if x.is_nan() || y.is_nan() { return x + y; diff --git a/library/compiler-builtins/libm/src/math/atan2f.rs b/library/compiler-builtins/libm/src/math/atan2f.rs index 211a992a0656..94e3c7718676 100644 --- a/library/compiler-builtins/libm/src/math/atan2f.rs +++ b/library/compiler-builtins/libm/src/math/atan2f.rs @@ -20,6 +20,7 @@ const PI: f32 = 3.1415927410e+00; /* 0x40490fdb */ const PI_LO: f32 = -8.7422776573e-08; /* 0xb3bbbd2e */ #[inline] +#[cfg_attr(all(test, assert_no_panic), no_panic::no_panic)] pub fn atan2f(y: f32, x: f32) -> f32 { if x.is_nan() || y.is_nan() { return x + y; diff --git a/library/compiler-builtins/libm/src/math/atanf.rs b/library/compiler-builtins/libm/src/math/atanf.rs index b05152e2bc3e..5d9024022b98 100644 --- a/library/compiler-builtins/libm/src/math/atanf.rs +++ b/library/compiler-builtins/libm/src/math/atanf.rs @@ -38,6 +38,7 @@ const A_T: [f32; 5] = [ ]; #[inline] +#[cfg_attr(all(test, assert_no_panic), no_panic::no_panic)] pub fn atanf(mut x: f32) -> f32 { let x1p_120 = f32::from_bits(0x03800000); // 0x1p-120 === 2 ^ (-120) diff --git a/library/compiler-builtins/libm/src/math/cbrt.rs b/library/compiler-builtins/libm/src/math/cbrt.rs index 8c37f0b266b8..ab11c497e12d 100644 --- a/library/compiler-builtins/libm/src/math/cbrt.rs +++ b/library/compiler-builtins/libm/src/math/cbrt.rs @@ -28,6 +28,7 @@ const P3: f64 = -0.758397934778766047437; /* 0xbfe844cb, 0xbee751d9 */ const P4: f64 = 0.145996192886612446982; /* 0x3fc2b000, 0xd4e4edd7 */ #[inline] +#[cfg_attr(all(test, assert_no_panic), no_panic::no_panic)] pub fn cbrt(x: f64) -> f64 { let x1p54 = f64::from_bits(0x4350000000000000); // 0x1p54 === 2 ^ 54 diff --git a/library/compiler-builtins/libm/src/math/cbrtf.rs b/library/compiler-builtins/libm/src/math/cbrtf.rs index 878372eefbf8..19215b8587bd 100644 --- a/library/compiler-builtins/libm/src/math/cbrtf.rs +++ b/library/compiler-builtins/libm/src/math/cbrtf.rs @@ -23,6 +23,7 @@ const B1: u32 = 709958130; /* B1 = (127-127.0/3-0.03306235651)*2**23 */ const B2: u32 = 642849266; /* B2 = (127-127.0/3-24/3-0.03306235651)*2**23 */ #[inline] +#[cfg_attr(all(test, assert_no_panic), no_panic::no_panic)] pub fn cbrtf(x: f32) -> f32 { let x1p24 = f32::from_bits(0x4b800000); // 0x1p24f === 2 ^ 24 diff --git a/library/compiler-builtins/libm/src/math/ceil.rs b/library/compiler-builtins/libm/src/math/ceil.rs index 5dbfa6a2c0ad..c2b11e4e74dc 100644 --- a/library/compiler-builtins/libm/src/math/ceil.rs +++ b/library/compiler-builtins/libm/src/math/ceil.rs @@ -3,6 +3,7 @@ use core::f64; const TOINT: f64 = 1. / f64::EPSILON; #[inline] +#[cfg_attr(all(test, assert_no_panic), no_panic::no_panic)] pub fn ceil(x: f64) -> f64 { // On wasm32 we know that LLVM's intrinsic will compile to an optimized // `f64.ceil` native instruction, so we can leverage this for both code size diff --git a/library/compiler-builtins/libm/src/math/ceilf.rs b/library/compiler-builtins/libm/src/math/ceilf.rs index c8cd4b5aa5b5..5eb6a35a6ec6 100644 --- a/library/compiler-builtins/libm/src/math/ceilf.rs +++ b/library/compiler-builtins/libm/src/math/ceilf.rs @@ -1,6 +1,7 @@ use core::f32; #[inline] +#[cfg_attr(all(test, assert_no_panic), no_panic::no_panic)] pub fn ceilf(x: f32) -> f32 { // On wasm32 we know that LLVM's intrinsic will compile to an optimized // `f32.ceil` native instruction, so we can leverage this for both code size diff --git a/library/compiler-builtins/libm/src/math/cos.rs b/library/compiler-builtins/libm/src/math/cos.rs index df16b5c36a84..fe5a89919b2b 100644 --- a/library/compiler-builtins/libm/src/math/cos.rs +++ b/library/compiler-builtins/libm/src/math/cos.rs @@ -42,6 +42,7 @@ use super::{k_cos, k_sin, rem_pio2}; // TRIG(x) returns trig(x) nearly rounded // #[inline] +#[cfg_attr(all(test, assert_no_panic), no_panic::no_panic)] pub fn cos(x: f64) -> f64 { let ix = (f64::to_bits(x) >> 32) as u32 & 0x7fffffff; diff --git a/library/compiler-builtins/libm/src/math/cosf.rs b/library/compiler-builtins/libm/src/math/cosf.rs index 23faacdc26cf..615746a31f7f 100644 --- a/library/compiler-builtins/libm/src/math/cosf.rs +++ b/library/compiler-builtins/libm/src/math/cosf.rs @@ -25,6 +25,7 @@ const C3_PIO2: f64 = 3. * FRAC_PI_2; /* 0x4012D97C, 0x7F3321D2 */ const C4_PIO2: f64 = 4. * FRAC_PI_2; /* 0x401921FB, 0x54442D18 */ #[inline] +#[cfg_attr(all(test, assert_no_panic), no_panic::no_panic)] pub fn cosf(x: f32) -> f32 { let x64 = x as f64; diff --git a/library/compiler-builtins/libm/src/math/cosh.rs b/library/compiler-builtins/libm/src/math/cosh.rs index f3f7fbfbeb16..b6ba338b55f2 100644 --- a/library/compiler-builtins/libm/src/math/cosh.rs +++ b/library/compiler-builtins/libm/src/math/cosh.rs @@ -3,6 +3,7 @@ use super::expm1; use super::k_expo2; #[inline] +#[cfg_attr(all(test, assert_no_panic), no_panic::no_panic)] pub fn cosh(mut x: f64) -> f64 { /* |x| */ let mut ix = x.to_bits(); diff --git a/library/compiler-builtins/libm/src/math/coshf.rs b/library/compiler-builtins/libm/src/math/coshf.rs index bd468f5da712..b37ee1f3271b 100644 --- a/library/compiler-builtins/libm/src/math/coshf.rs +++ b/library/compiler-builtins/libm/src/math/coshf.rs @@ -3,6 +3,7 @@ use super::expm1f; use super::k_expo2f; #[inline] +#[cfg_attr(all(test, assert_no_panic), no_panic::no_panic)] pub fn coshf(mut x: f32) -> f32 { let x1p120 = f32::from_bits(0x7b800000); // 0x1p120f === 2 ^ 120 diff --git a/library/compiler-builtins/libm/src/math/exp.rs b/library/compiler-builtins/libm/src/math/exp.rs index cd63b8fb3f15..c32773186796 100644 --- a/library/compiler-builtins/libm/src/math/exp.rs +++ b/library/compiler-builtins/libm/src/math/exp.rs @@ -78,6 +78,7 @@ const P4: f64 = -1.65339022054652515390e-06; /* 0xBEBBBD41, 0xC5D26BF1 */ const P5: f64 = 4.13813679705723846039e-08; /* 0x3E663769, 0x72BEA4D0 */ #[inline] +#[cfg_attr(all(test, assert_no_panic), no_panic::no_panic)] pub fn exp(mut x: f64) -> f64 { let x1p1023 = f64::from_bits(0x7fe0000000000000); // 0x1p1023 === 2 ^ 1023 let x1p_149 = f64::from_bits(0x36a0000000000000); // 0x1p-149 === 2 ^ -149 diff --git a/library/compiler-builtins/libm/src/math/exp2.rs b/library/compiler-builtins/libm/src/math/exp2.rs index 3952e93007e1..be6a003c6eeb 100644 --- a/library/compiler-builtins/libm/src/math/exp2.rs +++ b/library/compiler-builtins/libm/src/math/exp2.rs @@ -319,6 +319,7 @@ static TBL: [u64; TBLSIZE * 2] = [ // Gal, S. and Bachelis, B. An Accurate Elementary Mathematical Library // for the IEEE Floating Point Standard. TOMS 17(1), 26-46 (1991). #[inline] +#[cfg_attr(all(test, assert_no_panic), no_panic::no_panic)] pub fn exp2(mut x: f64) -> f64 { let redux = f64::from_bits(0x4338000000000000) / TBLSIZE as f64; let p1 = f64::from_bits(0x3fe62e42fefa39ef); diff --git a/library/compiler-builtins/libm/src/math/exp2f.rs b/library/compiler-builtins/libm/src/math/exp2f.rs index a3f6db8c5b36..32816104b5c6 100644 --- a/library/compiler-builtins/libm/src/math/exp2f.rs +++ b/library/compiler-builtins/libm/src/math/exp2f.rs @@ -70,6 +70,7 @@ static EXP2FT: [u64; TBLSIZE] = [ // Tang, P. Table-driven Implementation of the Exponential Function // in IEEE Floating-Point Arithmetic. TOMS 15(2), 144-157 (1989). #[inline] +#[cfg_attr(all(test, assert_no_panic), no_panic::no_panic)] pub fn exp2f(mut x: f32) -> f32 { let redux = f32::from_bits(0x4b400000) / TBLSIZE as f32; let p1 = f32::from_bits(0x3f317218); diff --git a/library/compiler-builtins/libm/src/math/expf.rs b/library/compiler-builtins/libm/src/math/expf.rs index 8ecc3b6abd61..baade2552e12 100644 --- a/library/compiler-builtins/libm/src/math/expf.rs +++ b/library/compiler-builtins/libm/src/math/expf.rs @@ -27,10 +27,10 @@ const P1: f32 = 1.6666625440e-1; /* 0xaaaa8f.0p-26 */ const P2: f32 = -2.7667332906e-3; /* -0xb55215.0p-32 */ #[inline] +#[cfg_attr(all(test, assert_no_panic), no_panic::no_panic)] pub fn expf(mut x: f32) -> f32 { let x1p127 = f32::from_bits(0x7f000000); // 0x1p127f === 2 ^ 127 let x1p_126 = f32::from_bits(0x800000); // 0x1p-126f === 2 ^ -126 /*original 0x1p-149f ??????????? */ - let mut hx = x.to_bits(); let sign = (hx >> 31) as i32; /* sign bit of x */ let signb: bool = sign != 0; diff --git a/library/compiler-builtins/libm/src/math/expm1.rs b/library/compiler-builtins/libm/src/math/expm1.rs index 9da064ee7736..42616399066c 100644 --- a/library/compiler-builtins/libm/src/math/expm1.rs +++ b/library/compiler-builtins/libm/src/math/expm1.rs @@ -24,6 +24,7 @@ const Q4: f64 = 4.00821782732936239552e-06; /* 3ED0CFCA 86E65239 */ const Q5: f64 = -2.01099218183624371326e-07; /* BE8AFDB7 6E09C32D */ #[inline] +#[cfg_attr(all(test, assert_no_panic), no_panic::no_panic)] pub fn expm1(mut x: f64) -> f64 { let hi: f64; let lo: f64; diff --git a/library/compiler-builtins/libm/src/math/expm1f.rs b/library/compiler-builtins/libm/src/math/expm1f.rs index 8f581733acd6..4daa83c85654 100644 --- a/library/compiler-builtins/libm/src/math/expm1f.rs +++ b/library/compiler-builtins/libm/src/math/expm1f.rs @@ -26,6 +26,7 @@ const Q1: f32 = -3.3333212137e-2; /* -0x888868.0p-28 */ const Q2: f32 = 1.5807170421e-3; /* 0xcf3010.0p-33 */ #[inline] +#[cfg_attr(all(test, assert_no_panic), no_panic::no_panic)] pub fn expm1f(mut x: f32) -> f32 { let x1p127 = f32::from_bits(0x7f000000); // 0x1p127f === 2 ^ 127 diff --git a/library/compiler-builtins/libm/src/math/expo2.rs b/library/compiler-builtins/libm/src/math/expo2.rs index 39f9815c4047..b5369fbbe56e 100644 --- a/library/compiler-builtins/libm/src/math/expo2.rs +++ b/library/compiler-builtins/libm/src/math/expo2.rs @@ -2,6 +2,7 @@ use super::{combine_words, exp}; /* exp(x)/2 for x >= log(DBL_MAX), slightly better than 0.5*exp(x/2)*exp(x/2) */ #[inline] +#[cfg_attr(all(test, assert_no_panic), no_panic::no_panic)] pub fn expo2(x: f64) -> f64 { /* k is such that k*ln2 has minimal relative error and x - kln2 > log(DBL_MIN) */ const K: i32 = 2043; diff --git a/library/compiler-builtins/libm/src/math/fabs.rs b/library/compiler-builtins/libm/src/math/fabs.rs index 7c804653c996..0824bd593586 100644 --- a/library/compiler-builtins/libm/src/math/fabs.rs +++ b/library/compiler-builtins/libm/src/math/fabs.rs @@ -1,6 +1,7 @@ use core::u64; #[inline] +#[cfg_attr(all(test, assert_no_panic), no_panic::no_panic)] pub fn fabs(x: f64) -> f64 { // On wasm32 we know that LLVM's intrinsic will compile to an optimized // `f64.abs` native instruction, so we can leverage this for both code size diff --git a/library/compiler-builtins/libm/src/math/fabsf.rs b/library/compiler-builtins/libm/src/math/fabsf.rs index 884c20f6c410..859508f9b539 100644 --- a/library/compiler-builtins/libm/src/math/fabsf.rs +++ b/library/compiler-builtins/libm/src/math/fabsf.rs @@ -1,4 +1,5 @@ #[inline] +#[cfg_attr(all(test, assert_no_panic), no_panic::no_panic)] pub fn fabsf(x: f32) -> f32 { // On wasm32 we know that LLVM's intrinsic will compile to an optimized // `f32.abs` native instruction, so we can leverage this for both code size diff --git a/library/compiler-builtins/libm/src/math/fdim.rs b/library/compiler-builtins/libm/src/math/fdim.rs index 1daae4ebc227..32ae306e2efb 100644 --- a/library/compiler-builtins/libm/src/math/fdim.rs +++ b/library/compiler-builtins/libm/src/math/fdim.rs @@ -1,6 +1,7 @@ use core::f64; #[inline] +#[cfg_attr(all(test, assert_no_panic), no_panic::no_panic)] pub fn fdim(x: f64, y: f64) -> f64 { if x.is_nan() { x diff --git a/library/compiler-builtins/libm/src/math/fdimf.rs b/library/compiler-builtins/libm/src/math/fdimf.rs index 953e0c8dfafc..7db01932626f 100644 --- a/library/compiler-builtins/libm/src/math/fdimf.rs +++ b/library/compiler-builtins/libm/src/math/fdimf.rs @@ -1,6 +1,7 @@ use core::f32; #[inline] +#[cfg_attr(all(test, assert_no_panic), no_panic::no_panic)] pub fn fdimf(x: f32, y: f32) -> f32 { if x.is_nan() { x diff --git a/library/compiler-builtins/libm/src/math/floor.rs b/library/compiler-builtins/libm/src/math/floor.rs index b14a48d55bc7..f5ac8006f0eb 100644 --- a/library/compiler-builtins/libm/src/math/floor.rs +++ b/library/compiler-builtins/libm/src/math/floor.rs @@ -3,6 +3,7 @@ use core::f64; const TOINT: f64 = 1. / f64::EPSILON; #[inline] +#[cfg_attr(all(test, assert_no_panic), no_panic::no_panic)] pub fn floor(x: f64) -> f64 { // On wasm32 we know that LLVM's intrinsic will compile to an optimized // `f64.floor` native instruction, so we can leverage this for both code size diff --git a/library/compiler-builtins/libm/src/math/floorf.rs b/library/compiler-builtins/libm/src/math/floorf.rs index 71b5953df3e2..8699be060269 100644 --- a/library/compiler-builtins/libm/src/math/floorf.rs +++ b/library/compiler-builtins/libm/src/math/floorf.rs @@ -1,6 +1,7 @@ use core::f32; #[inline] +#[cfg_attr(all(test, assert_no_panic), no_panic::no_panic)] pub fn floorf(x: f32) -> f32 { // On wasm32 we know that LLVM's intrinsic will compile to an optimized // `f32.floor` native instruction, so we can leverage this for both code size diff --git a/library/compiler-builtins/libm/src/math/fma.rs b/library/compiler-builtins/libm/src/math/fma.rs index 99a27164a81e..acf99a5d4e23 100644 --- a/library/compiler-builtins/libm/src/math/fma.rs +++ b/library/compiler-builtins/libm/src/math/fma.rs @@ -49,6 +49,7 @@ fn mul(x: u64, y: u64) -> (u64, u64) { } #[inline] +#[cfg_attr(all(test, assert_no_panic), no_panic::no_panic)] pub fn fma(x: f64, y: f64, z: f64) -> f64 { let x1p63: f64 = f64::from_bits(0x43e0000000000000); // 0x1p63 === 2 ^ 63 let x0_ffffff8p_63 = f64::from_bits(0x3bfffffff0000000); // 0x0.ffffff8p-63 @@ -165,13 +166,13 @@ pub fn fma(x: f64, y: f64, z: f64) -> f64 { } if r == c { /* min normal after rounding, underflow depends - on arch behaviour which can be imitated by - a double to float conversion */ + on arch behaviour which can be imitated by + a double to float conversion */ let fltmin: f32 = (x0_ffffff8p_63 * f32::MIN_POSITIVE as f64 * r) as f32; return f64::MIN_POSITIVE / f32::MIN_POSITIVE as f64 * fltmin as f64; } /* one bit is lost when scaled, add another top bit to - only round once at conversion if it is inexact */ + only round once at conversion if it is inexact */ if (rhi << 53) != 0 { i = (rhi >> 1 | (rhi & 1) | 1 << 62) as i64; if sign != 0 { @@ -181,7 +182,7 @@ pub fn fma(x: f64, y: f64, z: f64) -> f64 { r = 2. * r - c; /* remove top bit */ /* raise underflow portably, such that it - cannot be optimized away */ + cannot be optimized away */ { let tiny: f64 = f64::MIN_POSITIVE / f32::MIN_POSITIVE as f64 * r; r += (tiny * tiny) * (r - r); diff --git a/library/compiler-builtins/libm/src/math/fmaf.rs b/library/compiler-builtins/libm/src/math/fmaf.rs index 25b04fc23966..9e5a55f44b64 100644 --- a/library/compiler-builtins/libm/src/math/fmaf.rs +++ b/library/compiler-builtins/libm/src/math/fmaf.rs @@ -41,6 +41,7 @@ use super::fenv::{ * rounding occurs. */ #[inline] +#[cfg_attr(all(test, assert_no_panic), no_panic::no_panic)] pub fn fmaf(x: f32, y: f32, mut z: f32) -> f32 { let xy: f64; let mut result: f64; diff --git a/library/compiler-builtins/libm/src/math/fmod.rs b/library/compiler-builtins/libm/src/math/fmod.rs index 23f0c4846c4b..ecc9b39a5c1e 100644 --- a/library/compiler-builtins/libm/src/math/fmod.rs +++ b/library/compiler-builtins/libm/src/math/fmod.rs @@ -1,6 +1,7 @@ use core::u64; #[inline] +#[cfg_attr(all(test, assert_no_panic), no_panic::no_panic)] pub fn fmod(x: f64, y: f64) -> f64 { let mut uxi = x.to_bits(); let mut uyi = y.to_bits(); diff --git a/library/compiler-builtins/libm/src/math/fmodf.rs b/library/compiler-builtins/libm/src/math/fmodf.rs index d84cfeb01b83..98f51f455b88 100644 --- a/library/compiler-builtins/libm/src/math/fmodf.rs +++ b/library/compiler-builtins/libm/src/math/fmodf.rs @@ -2,6 +2,7 @@ use core::f32; use core::u32; #[inline] +#[cfg_attr(all(test, assert_no_panic), no_panic::no_panic)] pub fn fmodf(x: f32, y: f32) -> f32 { let mut uxi = x.to_bits(); let mut uyi = y.to_bits(); diff --git a/library/compiler-builtins/libm/src/math/hypot.rs b/library/compiler-builtins/libm/src/math/hypot.rs index f011415fdc64..dee9bbf42402 100644 --- a/library/compiler-builtins/libm/src/math/hypot.rs +++ b/library/compiler-builtins/libm/src/math/hypot.rs @@ -19,6 +19,7 @@ fn sq(x: f64) -> (f64, f64) { } #[inline] +#[cfg_attr(all(test, assert_no_panic), no_panic::no_panic)] pub fn hypot(mut x: f64, mut y: f64) -> f64 { let x1p700 = f64::from_bits(0x6bb0000000000000); // 0x1p700 === 2 ^ 700 let x1p_700 = f64::from_bits(0x1430000000000000); // 0x1p-700 === 2 ^ -700 diff --git a/library/compiler-builtins/libm/src/math/hypotf.rs b/library/compiler-builtins/libm/src/math/hypotf.rs index d59710ada395..4636b8f1d8b7 100644 --- a/library/compiler-builtins/libm/src/math/hypotf.rs +++ b/library/compiler-builtins/libm/src/math/hypotf.rs @@ -3,6 +3,7 @@ use core::f32; use super::sqrtf; #[inline] +#[cfg_attr(all(test, assert_no_panic), no_panic::no_panic)] pub fn hypotf(mut x: f32, mut y: f32) -> f32 { let x1p90 = f32::from_bits(0x6c800000); // 0x1p90f === 2 ^ 90 let x1p_90 = f32::from_bits(0x12800000); // 0x1p-90f === 2 ^ -90 diff --git a/library/compiler-builtins/libm/src/math/k_cos.rs b/library/compiler-builtins/libm/src/math/k_cos.rs index 693950d1d418..8876fac2143c 100644 --- a/library/compiler-builtins/libm/src/math/k_cos.rs +++ b/library/compiler-builtins/libm/src/math/k_cos.rs @@ -52,6 +52,7 @@ const C6: f64 = -1.13596475577881948265e-11; /* 0xBDA8FAE9, 0xBE8838D4 */ // under FreeBSD, so don't pessimize things by forcibly clipping // any extra precision in w. #[inline] +#[cfg_attr(all(test, assert_no_panic), no_panic::no_panic)] pub fn k_cos(x: f64, y: f64) -> f64 { let z = x * x; let w = z * z; diff --git a/library/compiler-builtins/libm/src/math/k_cosf.rs b/library/compiler-builtins/libm/src/math/k_cosf.rs index 4aa10c0f0894..9b48e190ddd5 100644 --- a/library/compiler-builtins/libm/src/math/k_cosf.rs +++ b/library/compiler-builtins/libm/src/math/k_cosf.rs @@ -21,6 +21,7 @@ const C2: f64 = -0.00138867637746099294692; /* -0x16c087e80f1e27.0p-62 */ const C3: f64 = 0.0000243904487962774090654; /* 0x199342e0ee5069.0p-68 */ #[inline] +#[cfg_attr(all(test, assert_no_panic), no_panic::no_panic)] pub fn k_cosf(x: f64) -> f32 { let z = x * x; let w = z * z; diff --git a/library/compiler-builtins/libm/src/math/k_expo2.rs b/library/compiler-builtins/libm/src/math/k_expo2.rs index e295c7a53462..0a9562eaeaad 100644 --- a/library/compiler-builtins/libm/src/math/k_expo2.rs +++ b/library/compiler-builtins/libm/src/math/k_expo2.rs @@ -5,6 +5,7 @@ const K: i32 = 2043; /* expf(x)/2 for x >= log(FLT_MAX), slightly better than 0.5f*expf(x/2)*expf(x/2) */ #[inline] +#[cfg_attr(all(test, assert_no_panic), no_panic::no_panic)] pub(crate) fn k_expo2(x: f64) -> f64 { let k_ln2 = f64::from_bits(0x40962066151add8b); /* note that k is odd and scale*scale overflows */ diff --git a/library/compiler-builtins/libm/src/math/k_expo2f.rs b/library/compiler-builtins/libm/src/math/k_expo2f.rs index ec2a2c5e2b8a..68a7a50325c1 100644 --- a/library/compiler-builtins/libm/src/math/k_expo2f.rs +++ b/library/compiler-builtins/libm/src/math/k_expo2f.rs @@ -5,6 +5,7 @@ const K: i32 = 235; /* expf(x)/2 for x >= log(FLT_MAX), slightly better than 0.5f*expf(x/2)*expf(x/2) */ #[inline] +#[cfg_attr(all(test, assert_no_panic), no_panic::no_panic)] pub fn k_expo2f(x: f32) -> f32 { let k_ln2 = f32::from_bits(0x4322e3bc); /* note that k is odd and scale*scale overflows */ diff --git a/library/compiler-builtins/libm/src/math/k_sin.rs b/library/compiler-builtins/libm/src/math/k_sin.rs index 3e07c3594475..15718c4c9265 100644 --- a/library/compiler-builtins/libm/src/math/k_sin.rs +++ b/library/compiler-builtins/libm/src/math/k_sin.rs @@ -44,6 +44,7 @@ const S6: f64 = 1.58969099521155010221e-10; /* 0x3DE5D93A, 0x5ACFD57C */ // then 3 2 // sin(x) = x + (S1*x + (x *(r-y/2)+y)) #[inline] +#[cfg_attr(all(test, assert_no_panic), no_panic::no_panic)] pub fn k_sin(x: f64, y: f64, iy: i32) -> f64 { let z = x * x; let w = z * z; diff --git a/library/compiler-builtins/libm/src/math/k_sinf.rs b/library/compiler-builtins/libm/src/math/k_sinf.rs index 1c5f5f98a48f..157fc104cc75 100644 --- a/library/compiler-builtins/libm/src/math/k_sinf.rs +++ b/library/compiler-builtins/libm/src/math/k_sinf.rs @@ -21,6 +21,7 @@ const S3: f64 = -0.000198393348360966317347; /* -0x1a00f9e2cae774.0p-65 */ const S4: f64 = 0.0000027183114939898219064; /* 0x16cd878c3b46a7.0p-71 */ #[inline] +#[cfg_attr(all(test, assert_no_panic), no_panic::no_panic)] pub fn k_sinf(x: f64) -> f32 { let z = x * x; let w = z * z; diff --git a/library/compiler-builtins/libm/src/math/k_tan.rs b/library/compiler-builtins/libm/src/math/k_tan.rs index e9ba21499d01..684e937b93ca 100644 --- a/library/compiler-builtins/libm/src/math/k_tan.rs +++ b/library/compiler-builtins/libm/src/math/k_tan.rs @@ -59,6 +59,7 @@ const PIO4: f64 = 7.85398163397448278999e-01; /* 3FE921FB, 54442D18 */ const PIO4_LO: f64 = 3.06161699786838301793e-17; /* 3C81A626, 33145C07 */ #[inline] +#[cfg_attr(all(test, assert_no_panic), no_panic::no_panic)] pub fn k_tan(mut x: f64, mut y: f64, odd: i32) -> f64 { let hx = (f64::to_bits(x) >> 32) as u32; let big = (hx & 0x7fffffff) >= 0x3FE59428; /* |x| >= 0.6744 */ diff --git a/library/compiler-builtins/libm/src/math/k_tanf.rs b/library/compiler-builtins/libm/src/math/k_tanf.rs index b9ccf2570f35..96a591007083 100644 --- a/library/compiler-builtins/libm/src/math/k_tanf.rs +++ b/library/compiler-builtins/libm/src/math/k_tanf.rs @@ -20,6 +20,7 @@ const T: [f64; 6] = [ ]; #[inline] +#[cfg_attr(all(test, assert_no_panic), no_panic::no_panic)] pub fn k_tanf(x: f64, odd: bool) -> f32 { let z = x * x; /* diff --git a/library/compiler-builtins/libm/src/math/log.rs b/library/compiler-builtins/libm/src/math/log.rs index 48e9fa79a46f..948065abf3b8 100644 --- a/library/compiler-builtins/libm/src/math/log.rs +++ b/library/compiler-builtins/libm/src/math/log.rs @@ -71,6 +71,7 @@ const LG6: f64 = 1.531383769920937332e-01; /* 3FC39A09 D078C69F */ const LG7: f64 = 1.479819860511658591e-01; /* 3FC2F112 DF3E5244 */ #[inline] +#[cfg_attr(all(test, assert_no_panic), no_panic::no_panic)] pub fn log(mut x: f64) -> f64 { let x1p54 = f64::from_bits(0x4350000000000000); // 0x1p54 === 2 ^ 54 diff --git a/library/compiler-builtins/libm/src/math/log10.rs b/library/compiler-builtins/libm/src/math/log10.rs index 7c7afefa3456..100618a0281d 100644 --- a/library/compiler-builtins/libm/src/math/log10.rs +++ b/library/compiler-builtins/libm/src/math/log10.rs @@ -32,6 +32,7 @@ const LG6: f64 = 1.531383769920937332e-01; /* 3FC39A09 D078C69F */ const LG7: f64 = 1.479819860511658591e-01; /* 3FC2F112 DF3E5244 */ #[inline] +#[cfg_attr(all(test, assert_no_panic), no_panic::no_panic)] pub fn log10(mut x: f64) -> f64 { let x1p54 = f64::from_bits(0x4350000000000000); // 0x1p54 === 2 ^ 54 diff --git a/library/compiler-builtins/libm/src/math/log10f.rs b/library/compiler-builtins/libm/src/math/log10f.rs index 82b87c044b25..9cf89deb9576 100644 --- a/library/compiler-builtins/libm/src/math/log10f.rs +++ b/library/compiler-builtins/libm/src/math/log10f.rs @@ -26,6 +26,7 @@ const LG3: f32 = 0.28498786688; /* 0x91e9ee.0p-25 */ const LG4: f32 = 0.24279078841; /* 0xf89e26.0p-26 */ #[inline] +#[cfg_attr(all(test, assert_no_panic), no_panic::no_panic)] pub fn log10f(mut x: f32) -> f32 { let x1p25f = f32::from_bits(0x4c000000); // 0x1p25f === 2 ^ 25 diff --git a/library/compiler-builtins/libm/src/math/log1p.rs b/library/compiler-builtins/libm/src/math/log1p.rs index f42669deeaee..fb35e90db14c 100644 --- a/library/compiler-builtins/libm/src/math/log1p.rs +++ b/library/compiler-builtins/libm/src/math/log1p.rs @@ -66,6 +66,7 @@ const LG6: f64 = 1.531383769920937332e-01; /* 3FC39A09 D078C69F */ const LG7: f64 = 1.479819860511658591e-01; /* 3FC2F112 DF3E5244 */ #[inline] +#[cfg_attr(all(test, assert_no_panic), no_panic::no_panic)] pub fn log1p(x: f64) -> f64 { let mut ui: u64 = x.to_bits(); let hfsq: f64; diff --git a/library/compiler-builtins/libm/src/math/log1pf.rs b/library/compiler-builtins/libm/src/math/log1pf.rs index e6e1c14c8c5f..9fc399d956ee 100644 --- a/library/compiler-builtins/libm/src/math/log1pf.rs +++ b/library/compiler-builtins/libm/src/math/log1pf.rs @@ -21,6 +21,7 @@ const LG3: f32 = 0.28498786688; /* 0x91e9ee.0p-25 */ const LG4: f32 = 0.24279078841; /* 0xf89e26.0p-26 */ #[inline] +#[cfg_attr(all(test, assert_no_panic), no_panic::no_panic)] pub fn log1pf(x: f32) -> f32 { let mut ui: u32 = x.to_bits(); let hfsq: f32; diff --git a/library/compiler-builtins/libm/src/math/log2.rs b/library/compiler-builtins/libm/src/math/log2.rs index 35eb9bf72b27..b513928ccb12 100644 --- a/library/compiler-builtins/libm/src/math/log2.rs +++ b/library/compiler-builtins/libm/src/math/log2.rs @@ -30,6 +30,7 @@ const LG6: f64 = 1.531383769920937332e-01; /* 3FC39A09 D078C69F */ const LG7: f64 = 1.479819860511658591e-01; /* 3FC2F112 DF3E5244 */ #[inline] +#[cfg_attr(all(test, assert_no_panic), no_panic::no_panic)] pub fn log2(mut x: f64) -> f64 { let x1p54 = f64::from_bits(0x4350000000000000); // 0x1p54 === 2 ^ 54 diff --git a/library/compiler-builtins/libm/src/math/log2f.rs b/library/compiler-builtins/libm/src/math/log2f.rs index 8684b142f8be..07a00dc3dae9 100644 --- a/library/compiler-builtins/libm/src/math/log2f.rs +++ b/library/compiler-builtins/libm/src/math/log2f.rs @@ -24,6 +24,7 @@ const LG3: f32 = 0.28498786688; /* 0x91e9ee.0p-25 */ const LG4: f32 = 0.24279078841; /* 0xf89e26.0p-26 */ #[inline] +#[cfg_attr(all(test, assert_no_panic), no_panic::no_panic)] pub fn log2f(mut x: f32) -> f32 { let x1p25f = f32::from_bits(0x4c000000); // 0x1p25f === 2 ^ 25 diff --git a/library/compiler-builtins/libm/src/math/logf.rs b/library/compiler-builtins/libm/src/math/logf.rs index 09519104174b..95195601c2d7 100644 --- a/library/compiler-builtins/libm/src/math/logf.rs +++ b/library/compiler-builtins/libm/src/math/logf.rs @@ -22,6 +22,7 @@ const LG3: f32 = 0.28498786688; /* 0x91e9ee.0p-25 */ const LG4: f32 = 0.24279078841; /* 0xf89e26.0p-26 */ #[inline] +#[cfg_attr(all(test, assert_no_panic), no_panic::no_panic)] pub fn logf(mut x: f32) -> f32 { let x1p25 = f32::from_bits(0x4c000000); // 0x1p25f === 2 ^ 25 diff --git a/library/compiler-builtins/libm/src/math/pow.rs b/library/compiler-builtins/libm/src/math/pow.rs index 329b3955d883..b5b0407efa19 100644 --- a/library/compiler-builtins/libm/src/math/pow.rs +++ b/library/compiler-builtins/libm/src/math/pow.rs @@ -90,6 +90,7 @@ const IVLN2_H: f64 = 1.44269502162933349609e+00; /* 0x3ff71547_60000000 =24b 1/l const IVLN2_L: f64 = 1.92596299112661746887e-08; /* 0x3e54ae0b_f85ddf44 =1/ln2 tail*/ #[inline] +#[cfg_attr(all(test, assert_no_panic), no_panic::no_panic)] pub fn pow(x: f64, y: f64) -> f64 { let t1: f64; let t2: f64; @@ -261,7 +262,7 @@ pub fn pow(x: f64, y: f64) -> f64 { } /* now |1-x| is TINY <= 2**-20, suffice to compute - log(x) by x-x^2/2+x^3/3-x^4/4 */ + log(x) by x-x^2/2+x^3/3-x^4/4 */ let t: f64 = ax - 1.0; /* t has 20 trailing zeros */ let w: f64 = (t * t) * (0.5 - t * (0.3333333333333333333333 - t * 0.25)); let u: f64 = IVLN2_H * t; /* ivln2_h has 21 sig. bits */ diff --git a/library/compiler-builtins/libm/src/math/powf.rs b/library/compiler-builtins/libm/src/math/powf.rs index 8d0afe6693cf..0a26573a3d10 100644 --- a/library/compiler-builtins/libm/src/math/powf.rs +++ b/library/compiler-builtins/libm/src/math/powf.rs @@ -44,6 +44,7 @@ const IVLN2_H: f32 = 1.4426879883e+00; const IVLN2_L: f32 = 7.0526075433e-06; #[inline] +#[cfg_attr(all(test, assert_no_panic), no_panic::no_panic)] pub fn powf(x: f32, y: f32) -> f32 { let mut z: f32; let mut ax: f32; @@ -197,7 +198,7 @@ pub fn powf(x: f32, y: f32) -> f32 { } /* now |1-x| is TINY <= 2**-20, suffice to compute - log(x) by x-x^2/2+x^3/3-x^4/4 */ + log(x) by x-x^2/2+x^3/3-x^4/4 */ t = ax - 1.; /* t has 20 trailing zeros */ w = (t * t) * (0.5 - t * (0.333333333333 - t * 0.25)); u = IVLN2_H * t; /* IVLN2_H has 16 sig. bits */ diff --git a/library/compiler-builtins/libm/src/math/rem_pio2.rs b/library/compiler-builtins/libm/src/math/rem_pio2.rs index 5c1685877b67..82faf5da97a6 100644 --- a/library/compiler-builtins/libm/src/math/rem_pio2.rs +++ b/library/compiler-builtins/libm/src/math/rem_pio2.rs @@ -10,7 +10,6 @@ // ==================================================== // // Optimized by Bruce D. Evans. */ - use super::rem_pio2_large; // #if FLT_EVAL_METHOD==0 || FLT_EVAL_METHOD==1 @@ -43,6 +42,7 @@ const PIO2_3T: f64 = 8.47842766036889956997e-32; /* 0x397B839A, 0x252049C1 */ // // caller must handle the case when reduction is not needed: |x| ~<= pi/4 */ #[inline] +#[cfg_attr(all(test, assert_no_panic), no_panic::no_panic)] pub fn rem_pio2(x: f64) -> (i32, f64, f64) { let x1p24 = f64::from_bits(0x4170000000000000); diff --git a/library/compiler-builtins/libm/src/math/rem_pio2_large.rs b/library/compiler-builtins/libm/src/math/rem_pio2_large.rs index 4d9146af9d62..8bab485695ef 100644 --- a/library/compiler-builtins/libm/src/math/rem_pio2_large.rs +++ b/library/compiler-builtins/libm/src/math/rem_pio2_large.rs @@ -223,6 +223,7 @@ const PIO2: [f64; 8] = [ /// more accurately, = 0 mod 8 ). Thus the number of operations are /// independent of the exponent of the input. #[inline] +#[cfg_attr(all(test, assert_no_panic), no_panic::no_panic)] pub fn rem_pio2_large(x: &[f64], y: &mut [f64], e0: i32, prec: usize) -> i32 { let x1p24 = f64::from_bits(0x4170000000000000); // 0x1p24 === 2 ^ 24 let x1p_24 = f64::from_bits(0x3e70000000000000); // 0x1p_24 === 2 ^ (-24) diff --git a/library/compiler-builtins/libm/src/math/rem_pio2f.rs b/library/compiler-builtins/libm/src/math/rem_pio2f.rs index 5e7a7d43904d..054c311841f2 100644 --- a/library/compiler-builtins/libm/src/math/rem_pio2f.rs +++ b/library/compiler-builtins/libm/src/math/rem_pio2f.rs @@ -32,6 +32,7 @@ const PIO2_1T: f64 = 1.58932547735281966916e-08; /* 0x3E5110b4, 0x611A6263 */ /// use double precision for everything except passing x /// use __rem_pio2_large() for large x #[inline] +#[cfg_attr(all(test, assert_no_panic), no_panic::no_panic)] pub fn rem_pio2f(x: f32) -> (i32, f64) { let x64 = x as f64; diff --git a/library/compiler-builtins/libm/src/math/round.rs b/library/compiler-builtins/libm/src/math/round.rs index 1a6e754489c1..9a9723cfbb65 100644 --- a/library/compiler-builtins/libm/src/math/round.rs +++ b/library/compiler-builtins/libm/src/math/round.rs @@ -3,6 +3,7 @@ use core::f64; const TOINT: f64 = 1.0 / f64::EPSILON; #[inline] +#[cfg_attr(all(test, assert_no_panic), no_panic::no_panic)] pub fn round(mut x: f64) -> f64 { let (f, i) = (x, x.to_bits()); let e: u64 = i >> 52 & 0x7ff; diff --git a/library/compiler-builtins/libm/src/math/roundf.rs b/library/compiler-builtins/libm/src/math/roundf.rs index 7dd79557a9d3..839d9469a49e 100644 --- a/library/compiler-builtins/libm/src/math/roundf.rs +++ b/library/compiler-builtins/libm/src/math/roundf.rs @@ -3,6 +3,7 @@ use core::f32; const TOINT: f32 = 1.0 / f32::EPSILON; #[inline] +#[cfg_attr(all(test, assert_no_panic), no_panic::no_panic)] pub fn roundf(mut x: f32) -> f32 { let i = x.to_bits(); let e: u32 = i >> 23 & 0xff; diff --git a/library/compiler-builtins/libm/src/math/scalbn.rs b/library/compiler-builtins/libm/src/math/scalbn.rs index ad81072ddc98..d8c8409ac10c 100644 --- a/library/compiler-builtins/libm/src/math/scalbn.rs +++ b/library/compiler-builtins/libm/src/math/scalbn.rs @@ -1,4 +1,5 @@ #[inline] +#[cfg_attr(all(test, assert_no_panic), no_panic::no_panic)] pub fn scalbn(x: f64, mut n: i32) -> f64 { let x1p1023 = f64::from_bits(0x7fe0000000000000); // 0x1p1023 === 2 ^ 1023 let x1p53 = f64::from_bits(0x4340000000000000); // 0x1p53 === 2 ^ 53 @@ -18,7 +19,7 @@ pub fn scalbn(x: f64, mut n: i32) -> f64 { } } else if n < -1022 { /* make sure final n < -53 to avoid double - rounding in the subnormal range */ + rounding in the subnormal range */ y *= x1p_1022 * x1p53; n += 1022 - 53; if n < -1022 { diff --git a/library/compiler-builtins/libm/src/math/scalbnf.rs b/library/compiler-builtins/libm/src/math/scalbnf.rs index 901497e5e51d..4e9771175d29 100644 --- a/library/compiler-builtins/libm/src/math/scalbnf.rs +++ b/library/compiler-builtins/libm/src/math/scalbnf.rs @@ -1,4 +1,5 @@ #[inline] +#[cfg_attr(all(test, assert_no_panic), no_panic::no_panic)] pub fn scalbnf(mut x: f32, mut n: i32) -> f32 { let x1p127 = f32::from_bits(0x7f000000); // 0x1p127f === 2 ^ 127 let x1p_126 = f32::from_bits(0x800000); // 0x1p-126f === 2 ^ -126 diff --git a/library/compiler-builtins/libm/src/math/sin.rs b/library/compiler-builtins/libm/src/math/sin.rs index e749094e6681..b7307441646f 100644 --- a/library/compiler-builtins/libm/src/math/sin.rs +++ b/library/compiler-builtins/libm/src/math/sin.rs @@ -41,6 +41,7 @@ use super::{k_cos, k_sin, rem_pio2}; // Accuracy: // TRIG(x) returns trig(x) nearly rounded #[inline] +#[cfg_attr(all(test, assert_no_panic), no_panic::no_panic)] pub fn sin(x: f64) -> f64 { let x1p120 = f64::from_bits(0x4770000000000000); // 0x1p120f === 2 ^ 120 diff --git a/library/compiler-builtins/libm/src/math/sinf.rs b/library/compiler-builtins/libm/src/math/sinf.rs index c9b02bcdc513..b8fc8d6f4bec 100644 --- a/library/compiler-builtins/libm/src/math/sinf.rs +++ b/library/compiler-builtins/libm/src/math/sinf.rs @@ -25,6 +25,7 @@ const S3_PIO2: f64 = 3. * FRAC_PI_2; /* 0x4012D97C, 0x7F3321D2 */ const S4_PIO2: f64 = 4. * FRAC_PI_2; /* 0x401921FB, 0x54442D18 */ #[inline] +#[cfg_attr(all(test, assert_no_panic), no_panic::no_panic)] pub fn sinf(x: f32) -> f32 { let x64 = x as f64; diff --git a/library/compiler-builtins/libm/src/math/sinh.rs b/library/compiler-builtins/libm/src/math/sinh.rs index 684e8e30984a..25ff3daaccbb 100644 --- a/library/compiler-builtins/libm/src/math/sinh.rs +++ b/library/compiler-builtins/libm/src/math/sinh.rs @@ -5,6 +5,7 @@ use super::{expm1, expo2}; // = x + x^3/6 + o(x^5) // #[inline] +#[cfg_attr(all(test, assert_no_panic), no_panic::no_panic)] pub fn sinh(x: f64) -> f64 { // union {double f; uint64_t i;} u = {.f = x}; // uint32_t w; diff --git a/library/compiler-builtins/libm/src/math/sinhf.rs b/library/compiler-builtins/libm/src/math/sinhf.rs index 90c4b9312819..fd0b2bfc8943 100644 --- a/library/compiler-builtins/libm/src/math/sinhf.rs +++ b/library/compiler-builtins/libm/src/math/sinhf.rs @@ -2,6 +2,7 @@ use super::expm1f; use super::k_expo2f; #[inline] +#[cfg_attr(all(test, assert_no_panic), no_panic::no_panic)] pub fn sinhf(x: f32) -> f32 { let mut h = 0.5f32; let mut ix = x.to_bits(); diff --git a/library/compiler-builtins/libm/src/math/sqrt.rs b/library/compiler-builtins/libm/src/math/sqrt.rs index b2387a26e750..a05a521fb4b7 100644 --- a/library/compiler-builtins/libm/src/math/sqrt.rs +++ b/library/compiler-builtins/libm/src/math/sqrt.rs @@ -81,6 +81,7 @@ use core::f64; const TINY: f64 = 1.0e-300; #[inline] +#[cfg_attr(all(test, assert_no_panic), no_panic::no_panic)] pub fn sqrt(x: f64) -> f64 { // On wasm32 we know that LLVM's intrinsic will compile to an optimized // `f64.sqrt` native instruction, so we can leverage this for both code size diff --git a/library/compiler-builtins/libm/src/math/sqrtf.rs b/library/compiler-builtins/libm/src/math/sqrtf.rs index 33cafbcbda36..b9365c617161 100644 --- a/library/compiler-builtins/libm/src/math/sqrtf.rs +++ b/library/compiler-builtins/libm/src/math/sqrtf.rs @@ -16,6 +16,7 @@ const TINY: f32 = 1.0e-30; #[inline] +#[cfg_attr(all(test, assert_no_panic), no_panic::no_panic)] pub fn sqrtf(x: f32) -> f32 { // On wasm32 we know that LLVM's intrinsic will compile to an optimized // `f32.sqrt` native instruction, so we can leverage this for both code size diff --git a/library/compiler-builtins/libm/src/math/tan.rs b/library/compiler-builtins/libm/src/math/tan.rs index 5a5f178a51cc..e5c94cbb1565 100644 --- a/library/compiler-builtins/libm/src/math/tan.rs +++ b/library/compiler-builtins/libm/src/math/tan.rs @@ -40,6 +40,7 @@ use super::{k_tan, rem_pio2}; // Accuracy: // TRIG(x) returns trig(x) nearly rounded #[inline] +#[cfg_attr(all(test, assert_no_panic), no_panic::no_panic)] pub fn tan(x: f64) -> f64 { let x1p120 = f32::from_bits(0x7b800000); // 0x1p120f === 2 ^ 120 diff --git a/library/compiler-builtins/libm/src/math/tanf.rs b/library/compiler-builtins/libm/src/math/tanf.rs index 15a462d4e19f..c286cdeb419e 100644 --- a/library/compiler-builtins/libm/src/math/tanf.rs +++ b/library/compiler-builtins/libm/src/math/tanf.rs @@ -25,6 +25,7 @@ const T3_PIO2: f64 = 3. * FRAC_PI_2; /* 0x4012D97C, 0x7F3321D2 */ const T4_PIO2: f64 = 4. * FRAC_PI_2; /* 0x401921FB, 0x54442D18 */ #[inline] +#[cfg_attr(all(test, assert_no_panic), no_panic::no_panic)] pub fn tanf(x: f32) -> f32 { let x64 = x as f64; diff --git a/library/compiler-builtins/libm/src/math/tanh.rs b/library/compiler-builtins/libm/src/math/tanh.rs index 1c3dd0be438e..75d695cf7e9d 100644 --- a/library/compiler-builtins/libm/src/math/tanh.rs +++ b/library/compiler-builtins/libm/src/math/tanh.rs @@ -5,6 +5,7 @@ use super::expm1; * = (1 - exp(-2*x))/(exp(-2*x) - 1 + 2) */ #[inline] +#[cfg_attr(all(test, assert_no_panic), no_panic::no_panic)] pub fn tanh(mut x: f64) -> f64 { let mut uf: f64 = x; let mut ui: u64 = f64::to_bits(uf); diff --git a/library/compiler-builtins/libm/src/math/tanhf.rs b/library/compiler-builtins/libm/src/math/tanhf.rs index 98a1b60c29be..ac4657b5abdb 100644 --- a/library/compiler-builtins/libm/src/math/tanhf.rs +++ b/library/compiler-builtins/libm/src/math/tanhf.rs @@ -1,6 +1,7 @@ use super::expm1f; #[inline] +#[cfg_attr(all(test, assert_no_panic), no_panic::no_panic)] pub fn tanhf(mut x: f32) -> f32 { /* x = |x| */ let mut ix = x.to_bits(); diff --git a/library/compiler-builtins/libm/src/math/trunc.rs b/library/compiler-builtins/libm/src/math/trunc.rs index 8eecfcf538e5..1ee46fc7dae6 100644 --- a/library/compiler-builtins/libm/src/math/trunc.rs +++ b/library/compiler-builtins/libm/src/math/trunc.rs @@ -1,6 +1,7 @@ use core::f64; #[inline] +#[cfg_attr(all(test, assert_no_panic), no_panic::no_panic)] pub fn trunc(x: f64) -> f64 { // On wasm32 we know that LLVM's intrinsic will compile to an optimized // `f64.trunc` native instruction, so we can leverage this for both code size diff --git a/library/compiler-builtins/libm/src/math/truncf.rs b/library/compiler-builtins/libm/src/math/truncf.rs index 0d74fea9c9ee..f93383269057 100644 --- a/library/compiler-builtins/libm/src/math/truncf.rs +++ b/library/compiler-builtins/libm/src/math/truncf.rs @@ -1,6 +1,7 @@ use core::f32; #[inline] +#[cfg_attr(all(test, assert_no_panic), no_panic::no_panic)] pub fn truncf(x: f32) -> f32 { // On wasm32 we know that LLVM's intrinsic will compile to an optimized // `f32.trunc` native instruction, so we can leverage this for both code size