diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md new file mode 100644 index 000000000..9f67cfc31 --- /dev/null +++ b/CONTRIBUTING.md @@ -0,0 +1,167 @@ +# How to contribute + +## compiler-builtins + +1. From the [pending list](compiler-builtins/README.md#progress), pick one or + more intrinsics. +2. Port the version from [`compiler-rt`] and, if applicable, their + [tests][rt-tests]. Note that this crate has generic implementations for a lot + of routines, which may be usable without porting the entire implementation. +3. Add a test to `builtins-test`, comparing the behavior of the ported + intrinsic(s) with their implementation on the testing host. +4. Add the intrinsic to `builtins-test-intrinsics/src/main.rs` to verify it can + be linked on all targets. +5. Send a Pull Request (PR) :tada:. + +[`compiler-rt`]: https://github.com/llvm/llvm-project/tree/b6820c35c59a4da3e59c11f657093ffbd79ae1db/compiler-rt/lib/builtins +[rt-tests]: https://github.com/llvm/llvm-project/tree/b6820c35c59a4da3e59c11f657093ffbd79ae1db/compiler-rt/test/builtins + +## Porting Reminders + +1. [Rust][prec-rust] and [C][prec-c] have slightly different operator + precedence. C evaluates comparisons (`== !=`) before bitwise operations + (`& | ^`), while Rust evaluates the other way. +2. C assumes wrapping operations everywhere. Rust panics on overflow when in + debug mode. Consider using the [Wrapping][wrap-ty] type or the explicit + [wrapping_*][wrap-fn] functions where applicable. +3. Note [C implicit casts][casts], especially integer promotion. Rust is much + more explicit about casting, so be sure that any cast which affects the + output is ported to the Rust implementation. +4. Rust has [many functions][i32] for integer or floating point manipulation in + the standard library. Consider using one of these functions rather than + porting a new one. + +[prec-rust]: https://doc.rust-lang.org/reference/expressions.html#expression-precedence +[prec-c]: http://en.cppreference.com/w/c/language/operator_precedence +[wrap-ty]: https://doc.rust-lang.org/core/num/struct.Wrapping.html +[wrap-fn]: https://doc.rust-lang.org/std/primitive.i32.html#method.wrapping_add +[casts]: http://en.cppreference.com/w/cpp/language/implicit_conversion +[i32]: https://doc.rust-lang.org/std/primitive.i32.html + +## Tips and tricks + +- _IMPORTANT_ The code in this crate will end up being used in the `core` crate + so it can **not** have any external dependencies (other than a subset of + `core` itself). +- Only use relative imports within the `math` directory / module, e.g. + `use self::fabs::fabs` or `use super::k_cos`. Absolute imports from core are + OK, e.g. `use core::u64`. +- To reinterpret a float as an integer use the `to_bits` method. The MUSL code + uses the `GET_FLOAT_WORD` macro, or a union, to do this operation. +- To reinterpret an integer as a float use the `f32::from_bits` constructor. The + MUSL code uses the `SET_FLOAT_WORD` macro, or a union, to do this operation. +- You may use other methods from core like `f64::is_nan`, etc. as appropriate. +- Rust does not have hex float literals. This crate provides two `hf16!`, + `hf32!`, `hf64!`, and `hf128!` which convert string literals to floats at + compile time. + + ```rust + assert_eq!(hf32!("0x1.ffep+8").to_bits(), 0x43fff000); + assert_eq!(hf64!("0x1.ffep+8").to_bits(), 0x407ffe0000000000); + ``` + +- Rust code panics on arithmetic overflows when not optimized. You may need to + use the [`Wrapping`] newtype to avoid this problem, or individual methods like + [`wrapping_add`]. + +[`Wrapping`]: https://doc.rust-lang.org/std/num/struct.Wrapping.html +[`wrapping_add`]: https://doc.rust-lang.org/std/primitive.u32.html#method.wrapping_add + +## Testing + +Testing for these crates can be somewhat complex, so feel free to rely on CI. + +The easiest way replicate CI testing is using Docker. This can be done by +running `./ci/run-docker.sh [target]`. If no target is specified, all targets +will be run. + +Tests can also be run without Docker: + +```sh +# Run basic tests +# +# --no-default-features always needs to be passed, an unfortunate limitation +# since the `#![compiler_builtins]` feature is enabled by default. +cargo test --workspace --no-default-features + +# Test with all interesting features +cargo test --workspace --no-default-features \ + --features arch,unstable-float,unstable-intrinsics,mem + +# Run with more detailed tests for libm +cargo test --workspace --no-default-features \ + --features arch,unstable-float,unstable-intrinsics,mem \ + --features build-mpfr,build-musl \ + --profile release-checked +``` + +The multiprecision tests use the [`rug`] crate for bindings to MPFR. MPFR can be +difficult to build on non-Unix systems, refer to [`gmp_mpfr_sys`] for help. + +`build-musl` does not build with MSVC, Wasm, or Thumb. + +[`rug`]: https://docs.rs/rug/latest/rug/ +[`gmp_mpfr_sys`]: https://docs.rs/gmp-mpfr-sys/1.6.4/gmp_mpfr_sys/ + +In order to run all tests, some dependencies may be required: + +```sh +# Allow testing compiler-builtins +./ci/download-compiler-rt.sh + +# Optional, initialize musl for `--features build-musl` +git submodule init +git submodule update + +# `--release` ables more test cases +cargo test --release +``` + +### Extensive tests + +Libm also has tests that are exhaustive (for single-argument `f32` and 1- or 2- +argument `f16`) or extensive (for all other float and argument combinations). +These take quite a long time to run, but are launched in CI when relevant files +are changed. + +Exhaustive tests can be selected by passing an environment variable: + +```sh +LIBM_EXTENSIVE_TESTS=sqrt,sqrtf cargo test --features build-mpfr \ + --test z_extensive \ + --profile release-checked + +# Run all tests for one type +LIBM_EXTENSIVE_TESTS=all_f16 cargo test ... + +# Ensure `f64` tests can run exhaustively. Estimated completion test for a +# single test is 57306 years on my machine so this may be worth skipping. +LIBM_EXTENSIVE_TESTS=all LIBM_EXTENSIVE_ITERATIONS=18446744073709551615 cargo test ... +``` + +## Benchmarking + +Regular walltime benchmarks can be run with `cargo bench`: + +```sh +cargo bench --no-default-features \ + --features arch,unstable-float,unstable-intrinsics,mem \ + --features benchmarking-reports +``` + +There are also benchmarks that check instruction count behind the `icount` +feature. These require [`iai-callgrind-runner`] (via Cargo) and [Valgrind] +to be installed, which means these only run on limited platforms. + +Instruction count benchmarks are run as part of CI to flag performance +regresions. + +```sh +cargo bench --no-default-features \ + --features arch,unstable-float,unstable-intrinsics,mem \ + --features icount \ + --bench icount --bench mem_icount +``` + +[`iai-callgrind-runner`]: https://crates.io/crates/iai-callgrind-runner +[Valgrind]: https://valgrind.org/ diff --git a/LICENSE.txt b/LICENSE.txt index 367e3538d..00ae6140b 100644 --- a/LICENSE.txt +++ b/LICENSE.txt @@ -1,10 +1,14 @@ -compiler-builtins as a whole is available for use under both the MIT license +The compiler-builtins crate is available for use under both the MIT license and the Apache-2.0 license with the LLVM exception (MIT AND Apache-2.0 WITH LLVM-exception). -As a contributor, you agree that your code can be used under either the MIT -license, or the Apache-2.0 license, or the Apache-2.0 license with the LLVM -exception. +The libm crate is available for use under the MIT license. + +As a contributor, you agree that your code may be used under any of the +following: the MIT license, the Apache-2.0 license, or the Apache-2.0 license +with the LLVM exception. In other words, original (non-derivative) work is +licensed under MIT OR Apache-2.0 OR Apache-2.0 WITH LLVM-exception. This is +the default license for all other source in this repository. Text of the relevant licenses is provided below: @@ -263,8 +267,9 @@ license: * Work derived from compiler-rt after 2019-01-19 is usable under the Apache-2.0 license with the LLVM exception. -* The bundled `math` module is from rust-lang/libm, usable under the MIT - license. See https://github.com/rust-lang/libm for details. +* The bundled `math` module is from the libm crate, usable under the MIT + license. For further details and copyrights, see see libm/LICENSE.txt at + https://github.com/rust-lang/compiler-builtins. Additionally, some source files may contain comments with specific copyrights or licenses. diff --git a/README.md b/README.md index e5350d58c..3130ff7b7 100644 --- a/README.md +++ b/README.md @@ -1,476 +1,27 @@ -# `compiler-builtins` +# `compiler-builtins` and `libm` -This crate provides external symbols that the compiler expects to be available when -building Rust projects, typically software routines for basic operations that do not -have hardware support. It is largely a port of LLVM's [`compiler-rt`]. +This repository contains two main crates: -It is distributed as part of Rust's sysroot. +* `compiler-builtins`: symbols that the compiler expects to be available at + link time +* `libm`: a Rust implementation of C math libraries, used to provide + implementations in `ocre`. -[`compiler-rt`]: https://github.com/llvm/llvm-project/tree/1b1dc505057322f4fa1110ef4f53c44347f52986/compiler-rt +More details are at [compiler-builtins/README.md](compiler-builtins/README.md) +and [libm/README.md](libm/README.md). -## Contributing - -1. Pick one or more intrinsics from the [pending list](#progress). -2. Fork this repository. -3. Port the intrinsic(s) and their corresponding [unit tests][1] from their - [C implementation][2] to Rust. -4. Add a test to compare the behavior of the ported intrinsic(s) with their - implementation on the testing host. -5. Add the intrinsic to `builtins-test-intrinsics/src/main.rs` to verify it - can be linked on all targets. -6. Send a Pull Request (PR). -7. Once the PR passes our extensive testing infrastructure, we'll merge it! -8. Celebrate :tada: - -[1]: https://github.com/rust-lang/llvm-project/tree/9e3de9490ff580cd484fbfa2908292b4838d56e7/compiler-rt/test/builtins/Unit -[2]: https://github.com/rust-lang/llvm-project/tree/9e3de9490ff580cd484fbfa2908292b4838d56e7/compiler-rt/lib/builtins -[3]: https://github.com/rust-lang/compiler-builtins/actions - -### Porting Reminders - -1. [Rust][5a] and [C][5b] have slightly different operator precedence. C evaluates comparisons (`== !=`) before bitwise operations (`& | ^`), while Rust evaluates the other way. -2. C assumes wrapping operations everywhere. Rust panics on overflow when in debug mode. Consider using the [Wrapping][6] type or the explicit [wrapping_*][7] functions where applicable. -3. Note [C implicit casts][8], especially integer promotion. Rust is much more explicit about casting, so be sure that any cast which affects the output is ported to the Rust implementation. -4. Rust has [many functions][9] for integer or floating point manipulation in the standard library. Consider using one of these functions rather than porting a new one. - -[5a]: https://doc.rust-lang.org/reference/expressions.html#expression-precedence -[5b]: http://en.cppreference.com/w/c/language/operator_precedence -[6]: https://doc.rust-lang.org/core/num/struct.Wrapping.html -[7]: https://doc.rust-lang.org/std/primitive.i32.html#method.wrapping_add -[8]: http://en.cppreference.com/w/cpp/language/implicit_conversion -[9]: https://doc.rust-lang.org/std/primitive.i32.html - -## Testing - -The easiest way to test locally is using Docker. This can be done by running -`./ci/run-docker.sh [target]`. If no target is specified, all targets will be -run. - -In order to run the full test suite, you will also need the C compiler runtime -to test against, located in a directory called `compiler-rt`. This can be -obtained with the following: - -```sh -curl -L -o rustc-llvm-20.1.tar.gz https://github.com/rust-lang/llvm-project/archive/rustc/20.1-2025-02-13.tar.gz -tar xzf rustc-llvm-20.1.tar.gz --strip-components 1 llvm-project-rustc-20.1-2025-02-13/compiler-rt -``` - -Local targets may also be tested with `./ci/run.sh [target]`. - -Note that testing may not work on all hosts, in which cases it is acceptable to -rely on CI. - -## Progress - -- [x] aarch64/chkstk.S -- [x] adddf3.c -- [x] addsf3.c -- [x] arm/addsf3.S -- [x] arm/aeabi_dcmp.S -- [x] arm/aeabi_fcmp.S -- [x] arm/aeabi_idivmod.S -- [x] arm/aeabi_ldivmod.S -- [x] arm/aeabi_memcpy.S -- [x] arm/aeabi_memmove.S -- [x] arm/aeabi_memset.S -- [x] arm/aeabi_uidivmod.S -- [x] arm/aeabi_uldivmod.S -- [ ] arm/chkstk.S -- [ ] arm/divmodsi4.S (generic version is done) -- [ ] arm/divsi3.S (generic version is done) -- [ ] arm/modsi3.S (generic version is done) -- [x] arm/softfloat-alias.list -- [ ] arm/udivmodsi4.S (generic version is done) -- [ ] arm/udivsi3.S (generic version is done) -- [ ] arm/umodsi3.S (generic version is done) -- [x] ashldi3.c -- [x] ashrdi3.c -- [ ] avr/divmodhi4.S -- [ ] avr/divmodqi4.S -- [ ] avr/mulhi3.S -- [ ] avr/mulqi3.S -- [ ] avr/udivmodhi4.S -- [ ] avr/udivmodqi4.S -- [x] bswapdi2.c -- [x] bswapsi2.c -- [x] bswapti2.c -- [x] clzdi2.c -- [x] clzsi2.c -- [x] clzti2.c -- [x] comparedf2.c -- [x] comparesf2.c -- [x] ctzdi2.c -- [x] ctzsi2.c -- [x] ctzti2.c -- [x] divdf3.c -- [x] divdi3.c -- [x] divmoddi4.c -- [x] divmodsi4.c -- [x] divmodti4.c -- [x] divsf3.c -- [x] divsi3.c -- [x] extendsfdf2.c -- [x] fixdfdi.c -- [x] fixdfsi.c -- [x] fixsfdi.c -- [x] fixsfsi.c -- [x] fixunsdfdi.c -- [x] fixunsdfsi.c -- [x] fixunssfdi.c -- [x] fixunssfsi.c -- [x] floatdidf.c -- [x] floatdisf.c -- [x] floatsidf.c -- [x] floatsisf.c -- [x] floatundidf.c -- [x] floatundisf.c -- [x] floatunsidf.c -- [x] floatunsisf.c -- [ ] i386/ashldi3.S -- [ ] i386/ashrdi3.S -- [x] i386/chkstk.S -- [ ] i386/divdi3.S -- [ ] i386/lshrdi3.S -- [ ] i386/moddi3.S -- [ ] i386/muldi3.S -- [ ] i386/udivdi3.S -- [ ] i386/umoddi3.S -- [x] lshrdi3.c -- [x] moddi3.c -- [x] modsi3.c -- [x] muldf3.c -- [x] muldi3.c -- [x] mulodi4.c -- [x] mulosi4.c -- [x] mulsf3.c -- [x] powidf2.c -- [x] powisf2.c -- [ ] riscv/muldi3.S -- [ ] riscv/mulsi3.S -- [x] subdf3.c -- [x] subsf3.c -- [x] truncdfsf2.c -- [x] udivdi3.c -- [x] udivmoddi4.c -- [x] udivmodsi4.c -- [x] udivsi3.c -- [x] umoddi3.c -- [x] umodsi3.c -- [x] x86_64/chkstk.S - -These builtins are needed to support 128-bit integers. - -- [x] ashlti3.c -- [x] ashrti3.c -- [x] divti3.c -- [x] fixdfti.c -- [x] fixsfti.c -- [x] fixunsdfti.c -- [x] fixunssfti.c -- [x] floattidf.c -- [x] floattisf.c -- [x] floatuntidf.c -- [x] floatuntisf.c -- [x] lshrti3.c -- [x] modti3.c -- [x] muloti4.c -- [x] multi3.c -- [x] udivmodti4.c -- [x] udivti3.c -- [x] umodti3.c - -These builtins are needed to support `f16` and `f128`, which are in the process -of being added to Rust. - -- [x] addtf3.c -- [x] comparetf2.c -- [x] divtf3.c -- [x] extenddftf2.c -- [x] extendhfsf2.c -- [x] extendhftf2.c -- [x] extendsftf2.c -- [x] fixtfdi.c -- [x] fixtfsi.c -- [x] fixtfti.c -- [x] fixunstfdi.c -- [x] fixunstfsi.c -- [x] fixunstfti.c -- [x] floatditf.c -- [x] floatsitf.c -- [x] floattitf.c -- [x] floatunditf.c -- [x] floatunsitf.c -- [x] floatuntitf.c -- [x] multf3.c -- [x] powitf2.c -- [x] subtf3.c -- [x] truncdfhf2.c -- [x] truncsfhf2.c -- [x] trunctfdf2.c -- [x] trunctfhf2.c -- [x] trunctfsf2.c - - -These builtins are used by the Hexagon DSP - -- [ ] hexagon/common_entry_exit_abi1.S -- [ ] hexagon/common_entry_exit_abi2.S -- [ ] hexagon/common_entry_exit_legacy.S -- [x] hexagon/dfaddsub.S~~ -- [x] hexagon/dfdiv.S~~ -- [x] hexagon/dffma.S~~ -- [x] hexagon/dfminmax.S~~ -- [x] hexagon/dfmul.S~~ -- [x] hexagon/dfsqrt.S~~ -- [x] hexagon/divdi3.S~~ -- [x] hexagon/divsi3.S~~ -- [x] hexagon/fastmath2_dlib_asm.S~~ -- [x] hexagon/fastmath2_ldlib_asm.S~~ -- [x] hexagon/fastmath_dlib_asm.S~~ -- [x] hexagon/memcpy_forward_vp4cp4n2.S~~ -- [x] hexagon/memcpy_likely_aligned.S~~ -- [x] hexagon/moddi3.S~~ -- [x] hexagon/modsi3.S~~ -- [x] hexagon/sfdiv_opt.S~~ -- [x] hexagon/sfsqrt_opt.S~~ -- [x] hexagon/udivdi3.S~~ -- [x] hexagon/udivmoddi4.S~~ -- [x] hexagon/udivmodsi4.S~~ -- [x] hexagon/udivsi3.S~~ -- [x] hexagon/umoddi3.S~~ -- [x] hexagon/umodsi3.S~~ - -## Unimplemented functions - -These builtins are for x87 `f80` floating-point numbers that are not supported -by Rust. - -- ~~extendxftf2.c~~ -- ~~fixunsxfdi.c~~ -- ~~fixunsxfsi.c~~ -- ~~fixunsxfti.c~~ -- ~~fixxfdi.c~~ -- ~~fixxfti.c~~ -- ~~floatdixf.c~~ -- ~~floattixf.c~~ -- ~~floatundixf.c~~ -- ~~floatuntixf.c~~ -- ~~i386/floatdixf.S~~ -- ~~i386/floatundixf.S~~ -- ~~x86_64/floatdixf.c~~ -- ~~x86_64/floatundixf.S~~ - -These builtins are for IBM "extended double" non-IEEE 128-bit floating-point -numbers. - -- ~~ppc/divtc3.c~~ -- ~~ppc/fixtfdi.c~~ -- ~~ppc/fixtfti.c~~ -- ~~ppc/fixunstfdi.c~~ -- ~~ppc/fixunstfti.c~~ -- ~~ppc/floatditf.c~~ -- ~~ppc/floattitf.c~~ -- ~~ppc/floatunditf.c~~ -- ~~ppc/gcc_qadd.c~~ -- ~~ppc/gcc_qdiv.c~~ -- ~~ppc/gcc_qmul.c~~ -- ~~ppc/gcc_qsub.c~~ -- ~~ppc/multc3.c~~ - -These builtins are for 16-bit brain floating-point numbers that are not -supported by Rust. - -- ~~truncdfbf2.c~~ -- ~~truncsfbf2.c~~ -- ~~trunctfxf2.c~~ - -These builtins involve complex floating-point types that are not supported by -Rust. - -- ~~divdc3.c~~ -- ~~divsc3.c~~ -- ~~divtc3.c~~ -- ~~divxc3.c~~ -- ~~muldc3.c~~ -- ~~mulsc3.c~~ -- ~~multc3.c~~ -- ~~mulxc3.c~~ -- ~~powixf2.c~~ - -These builtins are never called by LLVM. - -- ~~absvdi2.c~~ -- ~~absvsi2.c~~ -- ~~absvti2.c~~ -- ~~addvdi3.c~~ -- ~~addvsi3.c~~ -- ~~addvti3.c~~ -- ~~arm/aeabi_cdcmp.S~~ -- ~~arm/aeabi_cdcmpeq_check_nan.c~~ -- ~~arm/aeabi_cfcmp.S~~ -- ~~arm/aeabi_cfcmpeq_check_nan.c~~ -- ~~arm/aeabi_div0.c~~ -- ~~arm/aeabi_drsub.c~~ -- ~~arm/aeabi_frsub.c~~ -- ~~arm/aeabi_memcmp.S~~ -- ~~arm/bswapdi2.S~~ -- ~~arm/bswapsi2.S~~ -- ~~arm/clzdi2.S~~ -- ~~arm/clzsi2.S~~ -- ~~arm/comparesf2.S~~ -- ~~arm/restore_vfp_d8_d15_regs.S~~ -- ~~arm/save_vfp_d8_d15_regs.S~~ -- ~~arm/switch16.S~~ -- ~~arm/switch32.S~~ -- ~~arm/switch8.S~~ -- ~~arm/switchu8.S~~ -- ~~cmpdi2.c~~ -- ~~cmpti2.c~~ -- ~~ffssi2.c~~ -- ~~ffsdi2.c~~ - this is [called by gcc][jemalloc-fail] though! -- ~~ffsti2.c~~ -- ~~mulvdi3.c~~ -- ~~mulvsi3.c~~ -- ~~mulvti3.c~~ -- ~~negdf2.c~~ -- ~~negdi2.c~~ -- ~~negsf2.c~~ -- ~~negti2.c~~ -- ~~negvdi2.c~~ -- ~~negvsi2.c~~ -- ~~negvti2.c~~ -- ~~paritydi2.c~~ -- ~~paritysi2.c~~ -- ~~parityti2.c~~ -- ~~popcountdi2.c~~ -- ~~popcountsi2.c~~ -- ~~popcountti2.c~~ -- ~~ppc/restFP.S~~ -- ~~ppc/saveFP.S~~ -- ~~subvdi3.c~~ -- ~~subvsi3.c~~ -- ~~subvti3.c~~ -- ~~ucmpdi2.c~~ -- ~~ucmpti2.c~~ -- ~~udivmodti4.c~~ - -[jemalloc-fail]: https://travis-ci.org/rust-lang/rust/jobs/249772758 - -Rust only exposes atomic types on platforms that support them, and therefore does not need to fall back to software implementations. - -- ~~arm/sync_fetch_and_add_4.S~~ -- ~~arm/sync_fetch_and_add_8.S~~ -- ~~arm/sync_fetch_and_and_4.S~~ -- ~~arm/sync_fetch_and_and_8.S~~ -- ~~arm/sync_fetch_and_max_4.S~~ -- ~~arm/sync_fetch_and_max_8.S~~ -- ~~arm/sync_fetch_and_min_4.S~~ -- ~~arm/sync_fetch_and_min_8.S~~ -- ~~arm/sync_fetch_and_nand_4.S~~ -- ~~arm/sync_fetch_and_nand_8.S~~ -- ~~arm/sync_fetch_and_or_4.S~~ -- ~~arm/sync_fetch_and_or_8.S~~ -- ~~arm/sync_fetch_and_sub_4.S~~ -- ~~arm/sync_fetch_and_sub_8.S~~ -- ~~arm/sync_fetch_and_umax_4.S~~ -- ~~arm/sync_fetch_and_umax_8.S~~ -- ~~arm/sync_fetch_and_umin_4.S~~ -- ~~arm/sync_fetch_and_umin_8.S~~ -- ~~arm/sync_fetch_and_xor_4.S~~ -- ~~arm/sync_fetch_and_xor_8.S~~ -- ~~arm/sync_synchronize.S~~ -- ~~atomic.c~~ -- ~~atomic_flag_clear.c~~ -- ~~atomic_flag_clear_explicit.c~~ -- ~~atomic_flag_test_and_set.c~~ -- ~~atomic_flag_test_and_set_explicit.c~~ -- ~~atomic_signal_fence.c~~ -- ~~atomic_thread_fence.c~~ - -Miscellaneous functionality that is not used by Rust. - -- ~~aarch64/fp_mode.c~~ -- ~~aarch64/lse.S~~ (LSE atomics) -- ~~aarch64/sme-abi-init.c~~ (matrix extension) -- ~~aarch64/sme-abi.S~~ (matrix extension) -- ~~aarch64/sme-libc-routines.c~~ (matrix extension) -- ~~apple_versioning.c~~ -- ~~arm/fp_mode.c~~ -- ~~avr/exit.S~~ -- ~~clear_cache.c~~ -- ~~cpu_model/aarch64.c~~ -- ~~cpu_model/x86.c~~ -- ~~crtbegin.c~~ -- ~~crtend.c~~ -- ~~emutls.c~~ -- ~~enable_execute_stack.c~~ -- ~~eprintf.c~~ -- ~~fp_mode.c~~ (float exception handling) -- ~~gcc_personality_v0.c~~ -- ~~i386/fp_mode.c~~ -- ~~int_util.c~~ -- ~~loongarch/fp_mode.c~~ -- ~~os_version_check.c~~ -- ~~riscv/fp_mode.c~~ -- ~~riscv/restore.S~~ (callee-saved registers) -- ~~riscv/save.S~~ (callee-saved registers) -- ~~trampoline_setup.c~~ -- ~~ve/grow_stack.S~~ -- ~~ve/grow_stack_align.S~~ - -Floating-point implementations of builtins that are only called from soft-float code. It would be better to simply use the generic soft-float versions in this case. - -- ~~i386/floatdidf.S~~ -- ~~i386/floatdisf.S~~ -- ~~i386/floatundidf.S~~ -- ~~i386/floatundisf.S~~ -- ~~x86_64/floatundidf.S~~ -- ~~x86_64/floatundisf.S~~ -- ~~x86_64/floatdidf.c~~ -- ~~x86_64/floatdisf.c~~ - -Unsupported in any current target: used on old versions of 32-bit iOS with ARMv5. - -- ~~arm/adddf3vfp.S~~ -- ~~arm/addsf3vfp.S~~ -- ~~arm/divdf3vfp.S~~ -- ~~arm/divsf3vfp.S~~ -- ~~arm/eqdf2vfp.S~~ -- ~~arm/eqsf2vfp.S~~ -- ~~arm/extendsfdf2vfp.S~~ -- ~~arm/fixdfsivfp.S~~ -- ~~arm/fixsfsivfp.S~~ -- ~~arm/fixunsdfsivfp.S~~ -- ~~arm/fixunssfsivfp.S~~ -- ~~arm/floatsidfvfp.S~~ -- ~~arm/floatsisfvfp.S~~ -- ~~arm/floatunssidfvfp.S~~ -- ~~arm/floatunssisfvfp.S~~ -- ~~arm/gedf2vfp.S~~ -- ~~arm/gesf2vfp.S~~ -- ~~arm/gtdf2vfp.S~~ -- ~~arm/gtsf2vfp.S~~ -- ~~arm/ledf2vfp.S~~ -- ~~arm/lesf2vfp.S~~ -- ~~arm/ltdf2vfp.S~~ -- ~~arm/ltsf2vfp.S~~ -- ~~arm/muldf3vfp.S~~ -- ~~arm/mulsf3vfp.S~~ -- ~~arm/nedf2vfp.S~~ -- ~~arm/negdf2vfp.S~~ -- ~~arm/negsf2vfp.S~~ -- ~~arm/nesf2vfp.S~~ -- ~~arm/subdf3vfp.S~~ -- ~~arm/subsf3vfp.S~~ -- ~~arm/truncdfsf2vfp.S~~ -- ~~arm/unorddf2vfp.S~~ -- ~~arm/unordsf2vfp.S~~ +For instructions on contributing, see [CONTRIBUTING.md](CONTRIBUTING.md). ## License -The compiler-builtins crate is dual licensed under both the University of -Illinois "BSD-Like" license and the MIT license. As a user of this code you may -choose to use it under either license. As a contributor, you agree to allow -your code to be used under both. +* `libm` may be used under the [MIT License] +* `compiler-builtins` may be used under the [MIT License] and the + [Apache License, Version 2.0] with the LLVM exception. +* All original contributions must be under all of: the MIT license, the + Apache-2.0 license, and the Apache-2.0 license with the LLVM exception. + +More details are in [LICENSE.txt](LICENSE.txt) and +[libm/LICENSE.txt](libm/LICENSE.txt). -Full text of the relevant licenses is in LICENSE.TXT. +[MIT License]: https://opensource.org/license/mit +[Apache License, Version 2.0]: htps://www.apache.org/licenses/LICENSE-2.0 diff --git a/builtins-test-intrinsics/Cargo.toml b/builtins-test-intrinsics/Cargo.toml index 6d88cbec9..6e10628a4 100644 --- a/builtins-test-intrinsics/Cargo.toml +++ b/builtins-test-intrinsics/Cargo.toml @@ -3,6 +3,7 @@ name = "builtins-test-intrinsics" version = "0.1.0" edition = "2021" publish = false +license = "MIT OR Apache-2.0" [dependencies] compiler_builtins = { path = "../compiler-builtins", features = ["compiler-builtins"]} diff --git a/builtins-test/Cargo.toml b/builtins-test/Cargo.toml index 18185d8fe..f7bcb52b4 100644 --- a/builtins-test/Cargo.toml +++ b/builtins-test/Cargo.toml @@ -4,6 +4,7 @@ version = "0.1.0" authors = ["Alex Crichton "] edition = "2024" publish = false +license = "MIT AND Apache-2.0 WITH LLVM-exception AND (MIT OR Apache-2.0)" [dependencies] # For fuzzing tests we want a deterministic seedable RNG. We also eliminate potential diff --git a/compiler-builtins/Cargo.toml b/compiler-builtins/Cargo.toml index a014baf04..1de37bd86 100644 --- a/compiler-builtins/Cargo.toml +++ b/compiler-builtins/Cargo.toml @@ -3,25 +3,12 @@ authors = ["Jorge Aparicio "] name = "compiler_builtins" version = "0.1.155" license = "MIT AND Apache-2.0 WITH LLVM-exception AND (MIT OR Apache-2.0)" -readme = "../README.md" +readme = "README.md" repository = "https://github.com/rust-lang/compiler-builtins" homepage = "https://github.com/rust-lang/compiler-builtins" documentation = "https://docs.rs/compiler_builtins" edition = "2021" -description = """ -Compiler intrinsics used by the Rust compiler. Also available for other targets -if necessary! -""" -include = [ - '/Cargo.toml', - '/build.rs', - '/configure.rs', - '/src/*', - '../LICENSE.txt', - '../README.md', - '../compiler-rt/*', - 'libm/src/math/*', -] +description = "Compiler intrinsics used by the Rust compiler." links = 'compiler-rt' [lib] diff --git a/compiler-builtins/LICENSE.txt b/compiler-builtins/LICENSE.txt new file mode 120000 index 000000000..4ab43736a --- /dev/null +++ b/compiler-builtins/LICENSE.txt @@ -0,0 +1 @@ +../LICENSE.txt \ No newline at end of file diff --git a/compiler-builtins/README.md b/compiler-builtins/README.md new file mode 100644 index 000000000..387b70c04 --- /dev/null +++ b/compiler-builtins/README.md @@ -0,0 +1,436 @@ +# `compiler-builtins` + +This crate provides external symbols that the compiler expects to be available +when building Rust projects, typically software routines for basic operations +that do not have hardware support. It is largely a port of LLVM's +[`compiler-rt`]. + +It is distributed as part of Rust's sysroot. `compiler-builtins` does not need +to be added as an explicit dependency in `Cargo.toml`. + +[`compiler-rt`]: https://github.com/llvm/llvm-project/tree/1b1dc505057322f4fa1110ef4f53c44347f52986/compiler-rt + +## Contributing + +See [CONTRIBUTING.md](CONTRIBUTING.md). + +## Progress + +- [x] aarch64/chkstk.S +- [x] adddf3.c +- [x] addsf3.c +- [x] arm/addsf3.S +- [x] arm/aeabi_dcmp.S +- [x] arm/aeabi_fcmp.S +- [x] arm/aeabi_idivmod.S +- [x] arm/aeabi_ldivmod.S +- [x] arm/aeabi_memcpy.S +- [x] arm/aeabi_memmove.S +- [x] arm/aeabi_memset.S +- [x] arm/aeabi_uidivmod.S +- [x] arm/aeabi_uldivmod.S +- [ ] arm/chkstk.S +- [ ] arm/divmodsi4.S (generic version is done) +- [ ] arm/divsi3.S (generic version is done) +- [ ] arm/modsi3.S (generic version is done) +- [x] arm/softfloat-alias.list +- [ ] arm/udivmodsi4.S (generic version is done) +- [ ] arm/udivsi3.S (generic version is done) +- [ ] arm/umodsi3.S (generic version is done) +- [x] ashldi3.c +- [x] ashrdi3.c +- [ ] avr/divmodhi4.S +- [ ] avr/divmodqi4.S +- [ ] avr/mulhi3.S +- [ ] avr/mulqi3.S +- [ ] avr/udivmodhi4.S +- [ ] avr/udivmodqi4.S +- [x] bswapdi2.c +- [x] bswapsi2.c +- [x] bswapti2.c +- [x] clzdi2.c +- [x] clzsi2.c +- [x] clzti2.c +- [x] comparedf2.c +- [x] comparesf2.c +- [x] ctzdi2.c +- [x] ctzsi2.c +- [x] ctzti2.c +- [x] divdf3.c +- [x] divdi3.c +- [x] divmoddi4.c +- [x] divmodsi4.c +- [x] divmodti4.c +- [x] divsf3.c +- [x] divsi3.c +- [x] extendsfdf2.c +- [x] fixdfdi.c +- [x] fixdfsi.c +- [x] fixsfdi.c +- [x] fixsfsi.c +- [x] fixunsdfdi.c +- [x] fixunsdfsi.c +- [x] fixunssfdi.c +- [x] fixunssfsi.c +- [x] floatdidf.c +- [x] floatdisf.c +- [x] floatsidf.c +- [x] floatsisf.c +- [x] floatundidf.c +- [x] floatundisf.c +- [x] floatunsidf.c +- [x] floatunsisf.c +- [ ] i386/ashldi3.S +- [ ] i386/ashrdi3.S +- [x] i386/chkstk.S +- [ ] i386/divdi3.S +- [ ] i386/lshrdi3.S +- [ ] i386/moddi3.S +- [ ] i386/muldi3.S +- [ ] i386/udivdi3.S +- [ ] i386/umoddi3.S +- [x] lshrdi3.c +- [x] moddi3.c +- [x] modsi3.c +- [x] muldf3.c +- [x] muldi3.c +- [x] mulodi4.c +- [x] mulosi4.c +- [x] mulsf3.c +- [x] powidf2.c +- [x] powisf2.c +- [ ] riscv/muldi3.S +- [ ] riscv/mulsi3.S +- [x] subdf3.c +- [x] subsf3.c +- [x] truncdfsf2.c +- [x] udivdi3.c +- [x] udivmoddi4.c +- [x] udivmodsi4.c +- [x] udivsi3.c +- [x] umoddi3.c +- [x] umodsi3.c +- [x] x86_64/chkstk.S + +These builtins are needed to support 128-bit integers. + +- [x] ashlti3.c +- [x] ashrti3.c +- [x] divti3.c +- [x] fixdfti.c +- [x] fixsfti.c +- [x] fixunsdfti.c +- [x] fixunssfti.c +- [x] floattidf.c +- [x] floattisf.c +- [x] floatuntidf.c +- [x] floatuntisf.c +- [x] lshrti3.c +- [x] modti3.c +- [x] muloti4.c +- [x] multi3.c +- [x] udivmodti4.c +- [x] udivti3.c +- [x] umodti3.c + +These builtins are needed to support `f16` and `f128`, which are in the process +of being added to Rust. + +- [x] addtf3.c +- [x] comparetf2.c +- [x] divtf3.c +- [x] extenddftf2.c +- [x] extendhfsf2.c +- [x] extendhftf2.c +- [x] extendsftf2.c +- [x] fixtfdi.c +- [x] fixtfsi.c +- [x] fixtfti.c +- [x] fixunstfdi.c +- [x] fixunstfsi.c +- [x] fixunstfti.c +- [x] floatditf.c +- [x] floatsitf.c +- [x] floattitf.c +- [x] floatunditf.c +- [x] floatunsitf.c +- [x] floatuntitf.c +- [x] multf3.c +- [x] powitf2.c +- [x] subtf3.c +- [x] truncdfhf2.c +- [x] truncsfhf2.c +- [x] trunctfdf2.c +- [x] trunctfhf2.c +- [x] trunctfsf2.c + + +These builtins are used by the Hexagon DSP + +- [ ] hexagon/common_entry_exit_abi1.S +- [ ] hexagon/common_entry_exit_abi2.S +- [ ] hexagon/common_entry_exit_legacy.S +- [x] hexagon/dfaddsub.S~~ +- [x] hexagon/dfdiv.S~~ +- [x] hexagon/dffma.S~~ +- [x] hexagon/dfminmax.S~~ +- [x] hexagon/dfmul.S~~ +- [x] hexagon/dfsqrt.S~~ +- [x] hexagon/divdi3.S~~ +- [x] hexagon/divsi3.S~~ +- [x] hexagon/fastmath2_dlib_asm.S~~ +- [x] hexagon/fastmath2_ldlib_asm.S~~ +- [x] hexagon/fastmath_dlib_asm.S~~ +- [x] hexagon/memcpy_forward_vp4cp4n2.S~~ +- [x] hexagon/memcpy_likely_aligned.S~~ +- [x] hexagon/moddi3.S~~ +- [x] hexagon/modsi3.S~~ +- [x] hexagon/sfdiv_opt.S~~ +- [x] hexagon/sfsqrt_opt.S~~ +- [x] hexagon/udivdi3.S~~ +- [x] hexagon/udivmoddi4.S~~ +- [x] hexagon/udivmodsi4.S~~ +- [x] hexagon/udivsi3.S~~ +- [x] hexagon/umoddi3.S~~ +- [x] hexagon/umodsi3.S~~ + +## Unimplemented functions + +These builtins are for x87 `f80` floating-point numbers that are not supported +by Rust. + +- ~~extendxftf2.c~~ +- ~~fixunsxfdi.c~~ +- ~~fixunsxfsi.c~~ +- ~~fixunsxfti.c~~ +- ~~fixxfdi.c~~ +- ~~fixxfti.c~~ +- ~~floatdixf.c~~ +- ~~floattixf.c~~ +- ~~floatundixf.c~~ +- ~~floatuntixf.c~~ +- ~~i386/floatdixf.S~~ +- ~~i386/floatundixf.S~~ +- ~~x86_64/floatdixf.c~~ +- ~~x86_64/floatundixf.S~~ + +These builtins are for IBM "extended double" non-IEEE 128-bit floating-point +numbers. + +- ~~ppc/divtc3.c~~ +- ~~ppc/fixtfdi.c~~ +- ~~ppc/fixtfti.c~~ +- ~~ppc/fixunstfdi.c~~ +- ~~ppc/fixunstfti.c~~ +- ~~ppc/floatditf.c~~ +- ~~ppc/floattitf.c~~ +- ~~ppc/floatunditf.c~~ +- ~~ppc/gcc_qadd.c~~ +- ~~ppc/gcc_qdiv.c~~ +- ~~ppc/gcc_qmul.c~~ +- ~~ppc/gcc_qsub.c~~ +- ~~ppc/multc3.c~~ + +These builtins are for 16-bit brain floating-point numbers that are not +supported by Rust. + +- ~~truncdfbf2.c~~ +- ~~truncsfbf2.c~~ +- ~~trunctfxf2.c~~ + +These builtins involve complex floating-point types that are not supported by +Rust. + +- ~~divdc3.c~~ +- ~~divsc3.c~~ +- ~~divtc3.c~~ +- ~~divxc3.c~~ +- ~~muldc3.c~~ +- ~~mulsc3.c~~ +- ~~multc3.c~~ +- ~~mulxc3.c~~ +- ~~powixf2.c~~ + +These builtins are never called by LLVM. + +- ~~absvdi2.c~~ +- ~~absvsi2.c~~ +- ~~absvti2.c~~ +- ~~addvdi3.c~~ +- ~~addvsi3.c~~ +- ~~addvti3.c~~ +- ~~arm/aeabi_cdcmp.S~~ +- ~~arm/aeabi_cdcmpeq_check_nan.c~~ +- ~~arm/aeabi_cfcmp.S~~ +- ~~arm/aeabi_cfcmpeq_check_nan.c~~ +- ~~arm/aeabi_div0.c~~ +- ~~arm/aeabi_drsub.c~~ +- ~~arm/aeabi_frsub.c~~ +- ~~arm/aeabi_memcmp.S~~ +- ~~arm/bswapdi2.S~~ +- ~~arm/bswapsi2.S~~ +- ~~arm/clzdi2.S~~ +- ~~arm/clzsi2.S~~ +- ~~arm/comparesf2.S~~ +- ~~arm/restore_vfp_d8_d15_regs.S~~ +- ~~arm/save_vfp_d8_d15_regs.S~~ +- ~~arm/switch16.S~~ +- ~~arm/switch32.S~~ +- ~~arm/switch8.S~~ +- ~~arm/switchu8.S~~ +- ~~cmpdi2.c~~ +- ~~cmpti2.c~~ +- ~~ffssi2.c~~ +- ~~ffsdi2.c~~ - this is [called by gcc][jemalloc-fail] though! +- ~~ffsti2.c~~ +- ~~mulvdi3.c~~ +- ~~mulvsi3.c~~ +- ~~mulvti3.c~~ +- ~~negdf2.c~~ +- ~~negdi2.c~~ +- ~~negsf2.c~~ +- ~~negti2.c~~ +- ~~negvdi2.c~~ +- ~~negvsi2.c~~ +- ~~negvti2.c~~ +- ~~paritydi2.c~~ +- ~~paritysi2.c~~ +- ~~parityti2.c~~ +- ~~popcountdi2.c~~ +- ~~popcountsi2.c~~ +- ~~popcountti2.c~~ +- ~~ppc/restFP.S~~ +- ~~ppc/saveFP.S~~ +- ~~subvdi3.c~~ +- ~~subvsi3.c~~ +- ~~subvti3.c~~ +- ~~ucmpdi2.c~~ +- ~~ucmpti2.c~~ +- ~~udivmodti4.c~~ + +[jemalloc-fail]: https://travis-ci.org/rust-lang/rust/jobs/249772758 + +Rust only exposes atomic types on platforms that support them, and therefore does not need to fall back to software implementations. + +- ~~arm/sync_fetch_and_add_4.S~~ +- ~~arm/sync_fetch_and_add_8.S~~ +- ~~arm/sync_fetch_and_and_4.S~~ +- ~~arm/sync_fetch_and_and_8.S~~ +- ~~arm/sync_fetch_and_max_4.S~~ +- ~~arm/sync_fetch_and_max_8.S~~ +- ~~arm/sync_fetch_and_min_4.S~~ +- ~~arm/sync_fetch_and_min_8.S~~ +- ~~arm/sync_fetch_and_nand_4.S~~ +- ~~arm/sync_fetch_and_nand_8.S~~ +- ~~arm/sync_fetch_and_or_4.S~~ +- ~~arm/sync_fetch_and_or_8.S~~ +- ~~arm/sync_fetch_and_sub_4.S~~ +- ~~arm/sync_fetch_and_sub_8.S~~ +- ~~arm/sync_fetch_and_umax_4.S~~ +- ~~arm/sync_fetch_and_umax_8.S~~ +- ~~arm/sync_fetch_and_umin_4.S~~ +- ~~arm/sync_fetch_and_umin_8.S~~ +- ~~arm/sync_fetch_and_xor_4.S~~ +- ~~arm/sync_fetch_and_xor_8.S~~ +- ~~arm/sync_synchronize.S~~ +- ~~atomic.c~~ +- ~~atomic_flag_clear.c~~ +- ~~atomic_flag_clear_explicit.c~~ +- ~~atomic_flag_test_and_set.c~~ +- ~~atomic_flag_test_and_set_explicit.c~~ +- ~~atomic_signal_fence.c~~ +- ~~atomic_thread_fence.c~~ + +Miscellaneous functionality that is not used by Rust. + +- ~~aarch64/fp_mode.c~~ +- ~~aarch64/lse.S~~ (LSE atomics) +- ~~aarch64/sme-abi-init.c~~ (matrix extension) +- ~~aarch64/sme-abi.S~~ (matrix extension) +- ~~aarch64/sme-libc-routines.c~~ (matrix extension) +- ~~apple_versioning.c~~ +- ~~arm/fp_mode.c~~ +- ~~avr/exit.S~~ +- ~~clear_cache.c~~ +- ~~cpu_model/aarch64.c~~ +- ~~cpu_model/x86.c~~ +- ~~crtbegin.c~~ +- ~~crtend.c~~ +- ~~emutls.c~~ +- ~~enable_execute_stack.c~~ +- ~~eprintf.c~~ +- ~~fp_mode.c~~ (float exception handling) +- ~~gcc_personality_v0.c~~ +- ~~i386/fp_mode.c~~ +- ~~int_util.c~~ +- ~~loongarch/fp_mode.c~~ +- ~~os_version_check.c~~ +- ~~riscv/fp_mode.c~~ +- ~~riscv/restore.S~~ (callee-saved registers) +- ~~riscv/save.S~~ (callee-saved registers) +- ~~trampoline_setup.c~~ +- ~~ve/grow_stack.S~~ +- ~~ve/grow_stack_align.S~~ + +Floating-point implementations of builtins that are only called from soft-float code. It would be better to simply use the generic soft-float versions in this case. + +- ~~i386/floatdidf.S~~ +- ~~i386/floatdisf.S~~ +- ~~i386/floatundidf.S~~ +- ~~i386/floatundisf.S~~ +- ~~x86_64/floatundidf.S~~ +- ~~x86_64/floatundisf.S~~ +- ~~x86_64/floatdidf.c~~ +- ~~x86_64/floatdisf.c~~ + +Unsupported in any current target: used on old versions of 32-bit iOS with ARMv5. + +- ~~arm/adddf3vfp.S~~ +- ~~arm/addsf3vfp.S~~ +- ~~arm/divdf3vfp.S~~ +- ~~arm/divsf3vfp.S~~ +- ~~arm/eqdf2vfp.S~~ +- ~~arm/eqsf2vfp.S~~ +- ~~arm/extendsfdf2vfp.S~~ +- ~~arm/fixdfsivfp.S~~ +- ~~arm/fixsfsivfp.S~~ +- ~~arm/fixunsdfsivfp.S~~ +- ~~arm/fixunssfsivfp.S~~ +- ~~arm/floatsidfvfp.S~~ +- ~~arm/floatsisfvfp.S~~ +- ~~arm/floatunssidfvfp.S~~ +- ~~arm/floatunssisfvfp.S~~ +- ~~arm/gedf2vfp.S~~ +- ~~arm/gesf2vfp.S~~ +- ~~arm/gtdf2vfp.S~~ +- ~~arm/gtsf2vfp.S~~ +- ~~arm/ledf2vfp.S~~ +- ~~arm/lesf2vfp.S~~ +- ~~arm/ltdf2vfp.S~~ +- ~~arm/ltsf2vfp.S~~ +- ~~arm/muldf3vfp.S~~ +- ~~arm/mulsf3vfp.S~~ +- ~~arm/nedf2vfp.S~~ +- ~~arm/negdf2vfp.S~~ +- ~~arm/negsf2vfp.S~~ +- ~~arm/nesf2vfp.S~~ +- ~~arm/subdf3vfp.S~~ +- ~~arm/subsf3vfp.S~~ +- ~~arm/truncdfsf2vfp.S~~ +- ~~arm/unorddf2vfp.S~~ +- ~~arm/unordsf2vfp.S~~ + +## License + +Usage is allowed under the [MIT License] and the [Apache License, Version 2.0] +with the LLVM exception. + +[MIT License]: https://opensource.org/license/mit +[Apache License, Version 2.0]: htps://www.apache.org/licenses/LICENSE-2.0 + +### Contribution + +Contributions are licensed under the MIT License, the Apache License, +Version 2.0, and the Apache-2.0 license with the LLVM exception. + +See [LICENSE.txt](../LICENSE.txt) for full details. diff --git a/compiler-builtins/src/lib.rs b/compiler-builtins/src/lib.rs index 067855603..7523a00cf 100644 --- a/compiler-builtins/src/lib.rs +++ b/compiler-builtins/src/lib.rs @@ -45,7 +45,7 @@ pub mod math; pub mod mem; // `libm` expects its `support` module to be available in the crate root. -use math::libm::support; +use math::libm_math::support; #[cfg(target_arch = "arm")] pub mod arm; diff --git a/compiler-builtins/src/math/libm_math b/compiler-builtins/src/math/libm_math new file mode 120000 index 000000000..4d65313c2 --- /dev/null +++ b/compiler-builtins/src/math/libm_math @@ -0,0 +1 @@ +../../../libm/src/math \ No newline at end of file diff --git a/compiler-builtins/src/math.rs b/compiler-builtins/src/math/mod.rs similarity index 96% rename from compiler-builtins/src/math.rs rename to compiler-builtins/src/math/mod.rs index 722374f8e..078feb9ff 100644 --- a/compiler-builtins/src/math.rs +++ b/compiler-builtins/src/math/mod.rs @@ -2,15 +2,14 @@ #[allow(dead_code)] #[allow(unused_imports)] #[allow(clippy::all)] -#[path = "../../libm/src/math/mod.rs"] -pub(crate) mod libm; +pub(crate) mod libm_math; macro_rules! libm_intrinsics { ($(fn $fun:ident($($iid:ident : $ity:ty),+) -> $oty:ty;)+) => { intrinsics! { $( pub extern "C" fn $fun($($iid: $ity),+) -> $oty { - $crate::math::libm::$fun($($iid),+) + $crate::math::libm_math::$fun($($iid),+) } )+ } @@ -185,13 +184,13 @@ pub mod partial_availability { // allow for windows (and other targets) intrinsics! { pub extern "C" fn lgamma_r(x: f64, s: &mut i32) -> f64 { - let r = super::libm::lgamma_r(x); + let r = super::libm_math::lgamma_r(x); *s = r.1; r.0 } pub extern "C" fn lgammaf_r(x: f32, s: &mut i32) -> f32 { - let r = super::libm::lgammaf_r(x); + let r = super::libm_math::lgammaf_r(x); *s = r.1; r.0 } diff --git a/crates/libm-macros/Cargo.toml b/crates/libm-macros/Cargo.toml index 50c869db7..3929854f0 100644 --- a/crates/libm-macros/Cargo.toml +++ b/crates/libm-macros/Cargo.toml @@ -3,6 +3,7 @@ name = "libm-macros" version = "0.1.0" edition = "2024" publish = false +license = "MIT OR Apache-2.0" [lib] proc-macro = true diff --git a/crates/musl-math-sys/Cargo.toml b/crates/musl-math-sys/Cargo.toml index 9e866a970..d3fb147e5 100644 --- a/crates/musl-math-sys/Cargo.toml +++ b/crates/musl-math-sys/Cargo.toml @@ -3,6 +3,7 @@ name = "musl-math-sys" version = "0.1.0" edition = "2024" publish = false +license = "MIT OR Apache-2.0" [dependencies] diff --git a/crates/util/Cargo.toml b/crates/util/Cargo.toml index ae37a7238..614c54bd8 100644 --- a/crates/util/Cargo.toml +++ b/crates/util/Cargo.toml @@ -3,6 +3,7 @@ name = "util" version = "0.1.0" edition = "2024" publish = false +license = "MIT OR Apache-2.0" [features] default = ["build-musl", "build-mpfr", "unstable-float"] diff --git a/libm-test/Cargo.toml b/libm-test/Cargo.toml index 6fd49774e..7a306e735 100644 --- a/libm-test/Cargo.toml +++ b/libm-test/Cargo.toml @@ -3,6 +3,7 @@ name = "libm-test" version = "0.1.0" edition = "2024" publish = false +license = "MIT OR Apache-2.0" [features] default = ["build-mpfr", "build-musl", "unstable-float"] diff --git a/libm/CONTRIBUTING.md b/libm/CONTRIBUTING.md deleted file mode 100644 index dc4006035..000000000 --- a/libm/CONTRIBUTING.md +++ /dev/null @@ -1,82 +0,0 @@ -# How to contribute - -- Pick your favorite math function from the [issue tracker]. -- Look for the C implementation of the function in the [MUSL source code][src]. -- Copy paste the C code into a Rust file in the `src/math` directory and adjust - `src/math/mod.rs` accordingly. Also, uncomment the corresponding trait method - in `src/lib.rs`. -- Write some simple tests in your module (using `#[test]`) -- Run `cargo test` to make sure it works. Full tests are only run when enabling - features, see [Testing](#testing) below. -- Send us a pull request! Make sure to run `cargo fmt` on your code before - sending the PR. Also include "closes #42" in the PR description to close the - corresponding issue. -- :tada: - -[issue tracker]: https://github.com/rust-lang/libm/issues -[src]: https://git.musl-libc.org/cgit/musl/tree/src/math -[`src/math/truncf.rs`]: https://github.com/rust-lang/libm/blob/master/src/math/truncf.rs - -Check [PR #65] for an example. - -[PR #65]: https://github.com/rust-lang/libm/pull/65 - -## Tips and tricks - -- *IMPORTANT* The code in this crate will end up being used in the `core` crate so it can **not** - have any external dependencies (other than `core` itself). - -- Only use relative imports within the `math` directory / module, e.g. `use self::fabs::fabs` or -`use super::k_cos`. Absolute imports from core are OK, e.g. `use core::u64`. - -- To reinterpret a float as an integer use the `to_bits` method. The MUSL code uses the - `GET_FLOAT_WORD` macro, or a union, to do this operation. - -- To reinterpret an integer as a float use the `f32::from_bits` constructor. The MUSL code uses the - `SET_FLOAT_WORD` macro, or a union, to do this operation. - -- You may use other methods from core like `f64::is_nan`, etc. as appropriate. - -- If you're implementing one of the private double-underscore functions, take a look at the - "source" name in the comment at the top for an idea for alternate naming. For example, `__sin` - was renamed to `k_sin` after the FreeBSD source code naming. Do `use` these private functions in - `mod.rs`. - -- You may encounter weird literals like `0x1p127f` in the MUSL code. These are hexadecimal floating - point literals. Rust (the language) doesn't support these kind of literals. This crate provides - two macros, `hf32!` and `hf64!`, which convert string literals to floats at compile time. - - ```rust - assert_eq!(hf32!("0x1.ffep+8").to_bits(), 0x43fff000); - assert_eq!(hf64!("0x1.ffep+8").to_bits(), 0x407ffe0000000000); - ``` - -- Rust code panics on arithmetic overflows when not optimized. You may need to use the [`Wrapping`] - newtype to avoid this problem, or individual methods like [`wrapping_add`]. - -[`Wrapping`]: https://doc.rust-lang.org/std/num/struct.Wrapping.html -[`wrapping_add`]: https://doc.rust-lang.org/std/primitive.u32.html#method.wrapping_add - -## Testing - -Normal tests can be executed with: - -```sh -# Tests against musl require that the submodule is up to date. -git submodule init -git submodule update - -# `--release` ables more test cases -cargo test --release -``` - -If you are on a system that cannot build musl or MPFR, passing -`--no-default-features` will run some limited tests. - -The multiprecision tests use the [`rug`] crate for bindings to MPFR. MPFR can -be difficult to build on non-Unix systems, refer to [`gmp_mpfr_sys`] for help. - -`build-musl` does not build with MSVC, Wasm, or Thumb. - -[`rug`]: https://docs.rs/rug/latest/rug/ -[`gmp_mpfr_sys`]: https://docs.rs/gmp-mpfr-sys/1.6.4/gmp_mpfr_sys/ diff --git a/libm/Cargo.toml b/libm/Cargo.toml index 44154c1a8..4e3850bbf 100644 --- a/libm/Cargo.toml +++ b/libm/Cargo.toml @@ -7,7 +7,7 @@ keywords = ["libm", "math"] license = "MIT" name = "libm" readme = "README.md" -repository = "https://github.com/rust-lang/libm" +repository = "https://github.com/rust-lang/compiler-builtins" version = "0.2.11" edition = "2021" rust-version = "1.63" diff --git a/libm/README.md b/libm/README.md index 52d760a4f..349e892df 100644 --- a/libm/README.md +++ b/libm/README.md @@ -1,38 +1,26 @@ # `libm` -A port of [MUSL]'s libm to Rust. +A Rust implementations of the C math library. -[MUSL]: https://musl.libc.org/ +## Usage -## Goals +`libm` provides fallback implementations for Rust's [float math functions] in +`core`, and the [`core_float_math`] feature. If what is available suits your +needs, there is no need to add `libm` as a dependency. -The short term goal of this library is to [enable math support (e.g. `sin`, `atan2`) for the -`wasm32-unknown-unknown` target][wasm] (cf. [rust-lang/compiler-builtins][pr]). The longer -term goal is to enable [math support in the `core` crate][core]. +If more functionality is needed, this crate can also be used directly: -[wasm]: https://github.com/rust-lang/libm/milestone/1 -[pr]: https://github.com/rust-lang/compiler-builtins/pull/248 -[core]: https://github.com/rust-lang/libm/milestone/2 +```toml +[dependencies] +libm = "0.2.11" +``` -## Already usable - -This crate is [on crates.io] and can be used today in stable `#![no_std]` programs. - -The API documentation can be found [here](https://docs.rs/libm). - -[on crates.io]: https://crates.io/crates/libm - -## Benchmark -[benchmark]: #benchmark - -The benchmarks are located in `crates/libm-bench` and require a nightly Rust toolchain. -To run all benchmarks: - -> cargo +nightly bench --all +[float math functions]: https://doc.rust-lang.org/std/primitive.f32.html +[`core_float_math`]: https://github.com/rust-lang/rust/issues/137578 ## Contributing -Please check [CONTRIBUTING.md](CONTRIBUTING.md) +Please check [CONTRIBUTING.md](../CONTRIBUTING.md) ## Minimum Rust version policy @@ -40,17 +28,15 @@ This crate supports rustc 1.63 and newer. ## License -Usage is licensed under the MIT license ([LICENSE-MIT](LICENSE-MIT) or -https://opensource.org/licenses/MIT). - +Usage is under the MIT license, available at +. ### Contribution Contributions are licensed under both the MIT license and the Apache License, -Version 2.0 ([LICENSE-APACHE](LICENSE-APACHE) or -https://www.apache.org/licenses/LICENSE-2.0). Unless you explicitly state -otherwise, any contribution intentionally submitted for inclusion in the work -by you, as defined in the Apache-2.0 license, shall be dual licensed as -mentioned, without any additional terms or conditions. +Version 2.0, available at . Unless +you explicitly state otherwise, any contribution intentionally submitted for +inclusion in the work by you, as defined in the Apache-2.0 license, shall be +dual licensed as mentioned, without any additional terms or conditions. -See `LICENSE.txt` for full details. +See [LICENSE.txt](LICENSE.txt) for full details.