Skip to content

Update the compiler-builtins subtree #142014

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 29 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
29 commits
Select commit Hold shift + click to select a range
11c1522
Enable `__powitf2` on MSVC
beetrees May 21, 2025
7966f1b
fixed typo in readme
Lorl0rd May 10, 2025
db21837
libm: Clean up unused files
tgross35 Apr 22, 2025
4c264c9
Update `CmpResult` to use a pointer-sized return type
tgross35 May 23, 2025
c04f133
Typo in README.md
D-Dario0 May 28, 2025
5978b8b
aarch64: Add a note saying why we use `frintx` rather than `frintn`
tgross35 May 28, 2025
851aa05
cleanup: Reuse `MinInt` and `Int` from `libm` in `compiler-builtins`
tgross35 Apr 21, 2025
877feef
Reuse `libm`'s `Caat` and `CastFrom` in `compiler-builtins`
tgross35 May 29, 2025
97c0beb
Remove unneeded C symbols
tgross35 May 28, 2025
a63f482
Replace the `nm` symbol check with a Rust implementation
tgross35 Apr 19, 2025
8db9bd6
Remove the now-unneeded llvm-tools-preview
tgross35 May 28, 2025
151b1cb
Change `compiler-builtins` to edition 2024
tgross35 May 29, 2025
af16553
symcheck: Print the command to make reproducing errors easier
tgross35 May 29, 2025
7db8cf1
Add benchmarks for float parsing and printing
tgross35 May 29, 2025
c136fb7
Run `builtins-test-intrinsics` when possible
tgross35 Mar 19, 2025
3464b4b
ci: Allow concurrency outside of pull requests
tgross35 May 29, 2025
9f84e99
Increase the benchmark rustc version to 2025-05-28
tgross35 May 29, 2025
8edaa6e
libm-test: Make `extensive` an attribute rather than a test type
tgross35 May 29, 2025
4d325e8
ci: Allow for multiple icount benchmarks in the same run
tgross35 May 29, 2025
3c35505
chore: release
github-actions[bot] May 29, 2025
c6df6a7
Fix new `dead_code` warnings from recent nightlies
tgross35 Jun 1, 2025
0a7e592
Upgrade all dependencies to the latest available version
tgross35 Jun 1, 2025
e83ca86
cleanup: Use `x.biteq(y)` rather than `x.to_bits() == y.to_bits()`
tgross35 Jun 2, 2025
ba7cdb6
ci: Refactor benchmark regression checks
tgross35 Jun 1, 2025
5778643
libm-test: Fix unintentional skips in `binop_common`
tgross35 Jun 2, 2025
76cb316
Add an empty rust-version file
tgross35 May 28, 2025
5225908
Add tooling for `josh` syncs
tgross35 May 18, 2025
dd85096
Update the upstream Rust version
tgross35 Jun 4, 2025
bf0fc23
Merge ref 792fc2b033ae:/library/compiler-builtins from https://github…
tgross35 Jun 4, 2025
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 12 additions & 5 deletions library/compiler-builtins/.github/workflows/main.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,15 @@ on:

concurrency:
# Make sure that new pushes cancel running jobs
group: ${{ github.workflow }}-${{ github.event.pull_request.number || github.ref }}
group: ${{ github.workflow }}-${{ github.event.pull_request.number || github.sha }}
cancel-in-progress: true

env:
CARGO_TERM_COLOR: always
RUSTDOCFLAGS: -Dwarnings
RUSTFLAGS: -Dwarnings
RUST_BACKTRACE: full
BENCHMARK_RUSTC: nightly-2025-01-16 # Pin the toolchain for reproducable results
BENCHMARK_RUSTC: nightly-2025-05-28 # Pin the toolchain for reproducable results

jobs:
# Determine which tests should be run based on changed files.
Expand Down Expand Up @@ -119,7 +119,6 @@ jobs:
rustup update "$channel" --no-self-update
rustup default "$channel"
rustup target add "${{ matrix.target }}"
rustup component add llvm-tools-preview
- uses: taiki-e/install-action@nextest
- uses: Swatinem/rust-cache@v2
with:
Expand Down Expand Up @@ -196,8 +195,14 @@ jobs:

benchmarks:
name: Benchmarks
runs-on: ubuntu-24.04
timeout-minutes: 20
strategy:
fail-fast: false
matrix:
include:
- target: x86_64-unknown-linux-gnu
os: ubuntu-24.04
runs-on: ${{ matrix.os }}
steps:
- uses: actions/checkout@master
with:
Expand All @@ -216,12 +221,14 @@ jobs:
cargo binstall -y iai-callgrind-runner --version "$iai_version"
sudo apt-get install valgrind
- uses: Swatinem/rust-cache@v2
with:
key: ${{ matrix.target }}

- name: Run icount benchmarks
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
PR_NUMBER: ${{ github.event.pull_request.number }}
run: ./ci/bench-icount.sh
run: ./ci/bench-icount.sh ${{ matrix.target }}

- name: Upload the benchmark baseline
uses: actions/upload-artifact@v4
Expand Down
2 changes: 2 additions & 0 deletions library/compiler-builtins/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,11 @@ resolver = "2"
members = [
"builtins-test",
"compiler-builtins",
"crates/josh-sync",
"crates/libm-macros",
"crates/musl-math-sys",
"crates/panic-handler",
"crates/symbol-check",
"crates/util",
"libm",
"libm-test",
Expand Down
2 changes: 1 addition & 1 deletion library/compiler-builtins/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ This repository contains two main crates:
* `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`.
implementations in `core`.

More details are at [compiler-builtins/README.md](compiler-builtins/README.md)
and [libm/README.md](libm/README.md).
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
[package]
name = "builtins-test-intrinsics"
version = "0.1.0"
edition = "2021"
edition = "2024"
publish = false
license = "MIT OR Apache-2.0"

Expand Down
12 changes: 8 additions & 4 deletions library/compiler-builtins/builtins-test-intrinsics/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,14 @@
#![no_std]
#![no_main]

// Ensure this `compiler_builtins` gets used, rather than the version injected from the sysroot.
extern crate compiler_builtins;
extern crate panic_handler;

// SAFETY: no definitions, only used for linking
#[cfg(all(not(thumb), not(windows), not(target_arch = "wasm32")))]
#[link(name = "c")]
extern "C" {}
unsafe extern "C" {}

// Every function in this module maps will be lowered to an intrinsic by LLVM, if the platform
// doesn't have native support for the operation used in the function. ARM has a naming convention
Expand Down Expand Up @@ -651,22 +654,23 @@ fn something_with_a_dtor(f: &dyn Fn()) {

#[unsafe(no_mangle)]
#[cfg(not(thumb))]
fn main(_argc: core::ffi::c_int, _argv: *const *const u8) -> core::ffi::c_int {
extern "C" fn main(_argc: core::ffi::c_int, _argv: *const *const u8) -> core::ffi::c_int {
run();
0
}

#[unsafe(no_mangle)]
#[cfg(thumb)]
pub fn _start() -> ! {
extern "C" fn _start() -> ! {
run();
loop {}
}

// SAFETY: no definitions, only used for linking
#[cfg(windows)]
#[link(name = "kernel32")]
#[link(name = "msvcrt")]
extern "C" {}
unsafe extern "C" {}

// ARM targets need these symbols
#[unsafe(no_mangle)]
Expand Down
8 changes: 4 additions & 4 deletions library/compiler-builtins/builtins-test/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -10,19 +10,19 @@ license = "MIT AND Apache-2.0 WITH LLVM-exception AND (MIT OR Apache-2.0)"
# For fuzzing tests we want a deterministic seedable RNG. We also eliminate potential
# problems with system RNGs on the variety of platforms this crate is tested on.
# `xoshiro128**` is used for its quality, size, and speed at generating `u32` shift amounts.
rand_xoshiro = "0.6"
rand_xoshiro = "0.7"
# To compare float builtins against
rustc_apfloat = "0.2.1"
rustc_apfloat = "0.2.2"
# Really a dev dependency, but dev dependencies can't be optional
iai-callgrind = { version = "0.14.0", optional = true }
iai-callgrind = { version = "0.14.1", optional = true }

[dependencies.compiler_builtins]
path = "../compiler-builtins"
default-features = false
features = ["unstable-public-internals"]

[dev-dependencies]
criterion = { version = "0.5.1", default-features = false, features = ["cargo_bench_support"] }
criterion = { version = "0.6.0", default-features = false, features = ["cargo_bench_support"] }
paste = "1.0.15"

[target.'cfg(all(target_arch = "arm", not(any(target_env = "gnu", target_env = "musl")), target_os = "linux"))'.dev-dependencies]
Expand Down
43 changes: 27 additions & 16 deletions library/compiler-builtins/builtins-test/benches/float_cmp.rs
Original file line number Diff line number Diff line change
@@ -1,27 +1,38 @@
#![cfg_attr(f128_enabled, feature(f128))]

use builtins_test::float_bench;
use compiler_builtins::float::cmp;
use compiler_builtins::float::cmp::{self, CmpResult};
use criterion::{Criterion, criterion_main};

/// `gt` symbols are allowed to return differing results, they just get compared
/// to 0.
fn gt_res_eq(a: i32, b: i32) -> bool {
fn gt_res_eq(mut a: CmpResult, mut b: CmpResult) -> bool {
// FIXME: Our CmpResult used to be `i32`, but GCC/LLVM expect `isize`. on 64-bit platforms,
// this means the top half of the word may be garbage if built with an old version of
// `compiler-builtins`, so add a hack around this.
//
// This can be removed once a version of `compiler-builtins` with the return type fix makes
// it upstream.
if size_of::<CmpResult>() == 8 {
a = a as i32 as CmpResult;
b = b as i32 as CmpResult;
}

let a_lt_0 = a <= 0;
let b_lt_0 = b <= 0;
(a_lt_0 && b_lt_0) || (!a_lt_0 && !b_lt_0)
}

float_bench! {
name: cmp_f32_gt,
sig: (a: f32, b: f32) -> i32,
sig: (a: f32, b: f32) -> CmpResult,
crate_fn: cmp::__gtsf2,
sys_fn: __gtsf2,
sys_available: all(),
output_eq: gt_res_eq,
asm: [
#[cfg(target_arch = "x86_64")] {
let ret: i32;
let ret: CmpResult;
asm!(
"xor {ret:e}, {ret:e}",
"ucomiss {a}, {b}",
Expand All @@ -36,7 +47,7 @@ float_bench! {
};

#[cfg(target_arch = "aarch64")] {
let ret: i32;
let ret: CmpResult;
asm!(
"fcmp {a:s}, {b:s}",
"cset {ret:w}, gt",
Expand All @@ -53,13 +64,13 @@ float_bench! {

float_bench! {
name: cmp_f32_unord,
sig: (a: f32, b: f32) -> i32,
sig: (a: f32, b: f32) -> CmpResult,
crate_fn: cmp::__unordsf2,
sys_fn: __unordsf2,
sys_available: all(),
asm: [
#[cfg(target_arch = "x86_64")] {
let ret: i32;
let ret: CmpResult;
asm!(
"xor {ret:e}, {ret:e}",
"ucomiss {a}, {b}",
Expand All @@ -74,7 +85,7 @@ float_bench! {
};

#[cfg(target_arch = "aarch64")] {
let ret: i32;
let ret: CmpResult;
asm!(
"fcmp {a:s}, {b:s}",
"cset {ret:w}, vs",
Expand All @@ -91,14 +102,14 @@ float_bench! {

float_bench! {
name: cmp_f64_gt,
sig: (a: f64, b: f64) -> i32,
sig: (a: f64, b: f64) -> CmpResult,
crate_fn: cmp::__gtdf2,
sys_fn: __gtdf2,
sys_available: all(),
output_eq: gt_res_eq,
asm: [
#[cfg(target_arch = "x86_64")] {
let ret: i32;
let ret: CmpResult;
asm!(
"xor {ret:e}, {ret:e}",
"ucomisd {a}, {b}",
Expand All @@ -113,7 +124,7 @@ float_bench! {
};

#[cfg(target_arch = "aarch64")] {
let ret: i32;
let ret: CmpResult;
asm!(
"fcmp {a:d}, {b:d}",
"cset {ret:w}, gt",
Expand All @@ -130,13 +141,13 @@ float_bench! {

float_bench! {
name: cmp_f64_unord,
sig: (a: f64, b: f64) -> i32,
sig: (a: f64, b: f64) -> CmpResult,
crate_fn: cmp::__unorddf2,
sys_fn: __unorddf2,
sys_available: all(),
asm: [
#[cfg(target_arch = "x86_64")] {
let ret: i32;
let ret: CmpResult;
asm!(
"xor {ret:e}, {ret:e}",
"ucomisd {a}, {b}",
Expand All @@ -151,7 +162,7 @@ float_bench! {
};

#[cfg(target_arch = "aarch64")] {
let ret: i32;
let ret: CmpResult;
asm!(
"fcmp {a:d}, {b:d}",
"cset {ret:w}, vs",
Expand All @@ -168,7 +179,7 @@ float_bench! {

float_bench! {
name: cmp_f128_gt,
sig: (a: f128, b: f128) -> i32,
sig: (a: f128, b: f128) -> CmpResult,
crate_fn: cmp::__gttf2,
crate_fn_ppc: cmp::__gtkf2,
sys_fn: __gttf2,
Expand All @@ -180,7 +191,7 @@ float_bench! {

float_bench! {
name: cmp_f128_unord,
sig: (a: f128, b: f128) -> i32,
sig: (a: f128, b: f128) -> CmpResult,
crate_fn: cmp::__unordtf2,
crate_fn_ppc: cmp::__unordkf2,
sys_fn: __unordtf2,
Expand Down
4 changes: 2 additions & 2 deletions library/compiler-builtins/builtins-test/src/bench.rs
Original file line number Diff line number Diff line change
Expand Up @@ -358,8 +358,8 @@ impl_testio!(float f16);
impl_testio!(float f32, f64);
#[cfg(f128_enabled)]
impl_testio!(float f128);
impl_testio!(int i16, i32, i64, i128);
impl_testio!(int u16, u32, u64, u128);
impl_testio!(int i8, i16, i32, i64, i128, isize);
impl_testio!(int u8, u16, u32, u64, u128, usize);
impl_testio!((float, int)(f32, i32));
impl_testio!((float, int)(f64, i32));
#[cfg(f128_enabled)]
Expand Down
Loading
Loading