Skip to content

Commit bdf8523

Browse files
authored
Merge pull request #56 from Kobzol/compiler-builtins
Compiler builtins push
2 parents 03e83cb + f9f6b57 commit bdf8523

Some content is hidden

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

86 files changed

+883
-1046
lines changed

library/compiler-builtins/.github/workflows/main.yaml

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,15 +5,15 @@ on:
55

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

1111
env:
1212
CARGO_TERM_COLOR: always
1313
RUSTDOCFLAGS: -Dwarnings
1414
RUSTFLAGS: -Dwarnings
1515
RUST_BACKTRACE: full
16-
BENCHMARK_RUSTC: nightly-2025-01-16 # Pin the toolchain for reproducable results
16+
BENCHMARK_RUSTC: nightly-2025-05-28 # Pin the toolchain for reproducable results
1717

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

197196
benchmarks:
198197
name: Benchmarks
199-
runs-on: ubuntu-24.04
200198
timeout-minutes: 20
199+
strategy:
200+
fail-fast: false
201+
matrix:
202+
include:
203+
- target: x86_64-unknown-linux-gnu
204+
os: ubuntu-24.04
205+
runs-on: ${{ matrix.os }}
201206
steps:
202207
- uses: actions/checkout@master
203208
with:
@@ -216,12 +221,14 @@ jobs:
216221
cargo binstall -y iai-callgrind-runner --version "$iai_version"
217222
sudo apt-get install valgrind
218223
- uses: Swatinem/rust-cache@v2
224+
with:
225+
key: ${{ matrix.target }}
219226

220227
- name: Run icount benchmarks
221228
env:
222229
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
223230
PR_NUMBER: ${{ github.event.pull_request.number }}
224-
run: ./ci/bench-icount.sh
231+
run: ./ci/bench-icount.sh ${{ matrix.target }}
225232

226233
- name: Upload the benchmark baseline
227234
uses: actions/upload-artifact@v4

library/compiler-builtins/Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ members = [
66
"crates/libm-macros",
77
"crates/musl-math-sys",
88
"crates/panic-handler",
9+
"crates/symbol-check",
910
"crates/util",
1011
"libm",
1112
"libm-test",

library/compiler-builtins/PUBLISHING.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,3 +14,5 @@ greatly appreciated!
1414
7. Push the tag
1515
8. Push the commit
1616
9. Undo changes to `Cargo.toml` and the `libm` submodule
17+
18+
FOO

library/compiler-builtins/README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ This repository contains two main crates:
55
* `compiler-builtins`: symbols that the compiler expects to be available at
66
link time
77
* `libm`: a Rust implementation of C math libraries, used to provide
8-
implementations in `ocre`.
8+
implementations in `core`.
99

1010
More details are at [compiler-builtins/README.md](compiler-builtins/README.md)
1111
and [libm/README.md](libm/README.md).

library/compiler-builtins/builtins-test-intrinsics/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
[package]
22
name = "builtins-test-intrinsics"
33
version = "0.1.0"
4-
edition = "2021"
4+
edition = "2024"
55
publish = false
66
license = "MIT OR Apache-2.0"
77

library/compiler-builtins/builtins-test-intrinsics/src/main.rs

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,11 +13,14 @@
1313
#![no_std]
1414
#![no_main]
1515

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

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

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

652655
#[unsafe(no_mangle)]
653656
#[cfg(not(thumb))]
654-
fn main(_argc: core::ffi::c_int, _argv: *const *const u8) -> core::ffi::c_int {
657+
extern "C" fn main(_argc: core::ffi::c_int, _argv: *const *const u8) -> core::ffi::c_int {
655658
run();
656659
0
657660
}
658661

659662
#[unsafe(no_mangle)]
660663
#[cfg(thumb)]
661-
pub fn _start() -> ! {
664+
extern "C" fn _start() -> ! {
662665
run();
663666
loop {}
664667
}
665668

669+
// SAFETY: no definitions, only used for linking
666670
#[cfg(windows)]
667671
#[link(name = "kernel32")]
668672
#[link(name = "msvcrt")]
669-
extern "C" {}
673+
unsafe extern "C" {}
670674

671675
// ARM targets need these symbols
672676
#[unsafe(no_mangle)]

library/compiler-builtins/builtins-test/Cargo.toml

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,19 +10,19 @@ license = "MIT AND Apache-2.0 WITH LLVM-exception AND (MIT OR Apache-2.0)"
1010
# For fuzzing tests we want a deterministic seedable RNG. We also eliminate potential
1111
# problems with system RNGs on the variety of platforms this crate is tested on.
1212
# `xoshiro128**` is used for its quality, size, and speed at generating `u32` shift amounts.
13-
rand_xoshiro = "0.6"
13+
rand_xoshiro = "0.7"
1414
# To compare float builtins against
15-
rustc_apfloat = "0.2.1"
15+
rustc_apfloat = "0.2.2"
1616
# Really a dev dependency, but dev dependencies can't be optional
17-
iai-callgrind = { version = "0.14.0", optional = true }
17+
iai-callgrind = { version = "0.14.1", optional = true }
1818

1919
[dependencies.compiler_builtins]
2020
path = "../compiler-builtins"
2121
default-features = false
2222
features = ["unstable-public-internals"]
2323

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

2828
[target.'cfg(all(target_arch = "arm", not(any(target_env = "gnu", target_env = "musl")), target_os = "linux"))'.dev-dependencies]

library/compiler-builtins/builtins-test/benches/float_cmp.rs

Lines changed: 27 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,27 +1,38 @@
11
#![cfg_attr(f128_enabled, feature(f128))]
22

33
use builtins_test::float_bench;
4-
use compiler_builtins::float::cmp;
4+
use compiler_builtins::float::cmp::{self, CmpResult};
55
use criterion::{Criterion, criterion_main};
66

77
/// `gt` symbols are allowed to return differing results, they just get compared
88
/// to 0.
9-
fn gt_res_eq(a: i32, b: i32) -> bool {
9+
fn gt_res_eq(mut a: CmpResult, mut b: CmpResult) -> bool {
10+
// FIXME: Our CmpResult used to be `i32`, but GCC/LLVM expect `isize`. on 64-bit platforms,
11+
// this means the top half of the word may be garbage if built with an old version of
12+
// `compiler-builtins`, so add a hack around this.
13+
//
14+
// This can be removed once a version of `compiler-builtins` with the return type fix makes
15+
// it upstream.
16+
if size_of::<CmpResult>() == 8 {
17+
a = a as i32 as CmpResult;
18+
b = b as i32 as CmpResult;
19+
}
20+
1021
let a_lt_0 = a <= 0;
1122
let b_lt_0 = b <= 0;
1223
(a_lt_0 && b_lt_0) || (!a_lt_0 && !b_lt_0)
1324
}
1425

1526
float_bench! {
1627
name: cmp_f32_gt,
17-
sig: (a: f32, b: f32) -> i32,
28+
sig: (a: f32, b: f32) -> CmpResult,
1829
crate_fn: cmp::__gtsf2,
1930
sys_fn: __gtsf2,
2031
sys_available: all(),
2132
output_eq: gt_res_eq,
2233
asm: [
2334
#[cfg(target_arch = "x86_64")] {
24-
let ret: i32;
35+
let ret: CmpResult;
2536
asm!(
2637
"xor {ret:e}, {ret:e}",
2738
"ucomiss {a}, {b}",
@@ -36,7 +47,7 @@ float_bench! {
3647
};
3748

3849
#[cfg(target_arch = "aarch64")] {
39-
let ret: i32;
50+
let ret: CmpResult;
4051
asm!(
4152
"fcmp {a:s}, {b:s}",
4253
"cset {ret:w}, gt",
@@ -53,13 +64,13 @@ float_bench! {
5364

5465
float_bench! {
5566
name: cmp_f32_unord,
56-
sig: (a: f32, b: f32) -> i32,
67+
sig: (a: f32, b: f32) -> CmpResult,
5768
crate_fn: cmp::__unordsf2,
5869
sys_fn: __unordsf2,
5970
sys_available: all(),
6071
asm: [
6172
#[cfg(target_arch = "x86_64")] {
62-
let ret: i32;
73+
let ret: CmpResult;
6374
asm!(
6475
"xor {ret:e}, {ret:e}",
6576
"ucomiss {a}, {b}",
@@ -74,7 +85,7 @@ float_bench! {
7485
};
7586

7687
#[cfg(target_arch = "aarch64")] {
77-
let ret: i32;
88+
let ret: CmpResult;
7889
asm!(
7990
"fcmp {a:s}, {b:s}",
8091
"cset {ret:w}, vs",
@@ -91,14 +102,14 @@ float_bench! {
91102

92103
float_bench! {
93104
name: cmp_f64_gt,
94-
sig: (a: f64, b: f64) -> i32,
105+
sig: (a: f64, b: f64) -> CmpResult,
95106
crate_fn: cmp::__gtdf2,
96107
sys_fn: __gtdf2,
97108
sys_available: all(),
98109
output_eq: gt_res_eq,
99110
asm: [
100111
#[cfg(target_arch = "x86_64")] {
101-
let ret: i32;
112+
let ret: CmpResult;
102113
asm!(
103114
"xor {ret:e}, {ret:e}",
104115
"ucomisd {a}, {b}",
@@ -113,7 +124,7 @@ float_bench! {
113124
};
114125

115126
#[cfg(target_arch = "aarch64")] {
116-
let ret: i32;
127+
let ret: CmpResult;
117128
asm!(
118129
"fcmp {a:d}, {b:d}",
119130
"cset {ret:w}, gt",
@@ -130,13 +141,13 @@ float_bench! {
130141

131142
float_bench! {
132143
name: cmp_f64_unord,
133-
sig: (a: f64, b: f64) -> i32,
144+
sig: (a: f64, b: f64) -> CmpResult,
134145
crate_fn: cmp::__unorddf2,
135146
sys_fn: __unorddf2,
136147
sys_available: all(),
137148
asm: [
138149
#[cfg(target_arch = "x86_64")] {
139-
let ret: i32;
150+
let ret: CmpResult;
140151
asm!(
141152
"xor {ret:e}, {ret:e}",
142153
"ucomisd {a}, {b}",
@@ -151,7 +162,7 @@ float_bench! {
151162
};
152163

153164
#[cfg(target_arch = "aarch64")] {
154-
let ret: i32;
165+
let ret: CmpResult;
155166
asm!(
156167
"fcmp {a:d}, {b:d}",
157168
"cset {ret:w}, vs",
@@ -168,7 +179,7 @@ float_bench! {
168179

169180
float_bench! {
170181
name: cmp_f128_gt,
171-
sig: (a: f128, b: f128) -> i32,
182+
sig: (a: f128, b: f128) -> CmpResult,
172183
crate_fn: cmp::__gttf2,
173184
crate_fn_ppc: cmp::__gtkf2,
174185
sys_fn: __gttf2,
@@ -180,7 +191,7 @@ float_bench! {
180191

181192
float_bench! {
182193
name: cmp_f128_unord,
183-
sig: (a: f128, b: f128) -> i32,
194+
sig: (a: f128, b: f128) -> CmpResult,
184195
crate_fn: cmp::__unordtf2,
185196
crate_fn_ppc: cmp::__unordkf2,
186197
sys_fn: __unordtf2,

library/compiler-builtins/builtins-test/src/bench.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -358,8 +358,8 @@ impl_testio!(float f16);
358358
impl_testio!(float f32, f64);
359359
#[cfg(f128_enabled)]
360360
impl_testio!(float f128);
361-
impl_testio!(int i16, i32, i64, i128);
362-
impl_testio!(int u16, u32, u64, u128);
361+
impl_testio!(int i8, i16, i32, i64, i128, isize);
362+
impl_testio!(int u8, u16, u32, u64, u128, usize);
363363
impl_testio!((float, int)(f32, i32));
364364
impl_testio!((float, int)(f64, i32));
365365
#[cfg(f128_enabled)]

0 commit comments

Comments
 (0)