Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
3 changes: 1 addition & 2 deletions library/compiler-builtins/.github/workflows/main.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -51,8 +51,7 @@ jobs:
- target: aarch64-unknown-linux-gnu
os: ubuntu-24.04-arm
- target: aarch64-pc-windows-msvc
os: windows-2025
build_only: 1
os: windows-11-arm
- target: arm-unknown-linux-gnueabi
os: ubuntu-24.04
- target: arm-unknown-linux-gnueabihf
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
#![allow(improper_ctypes)]
#![cfg_attr(f128_enabled, feature(f128))]

use builtins_test::float_bench;
Expand Down
24 changes: 11 additions & 13 deletions library/compiler-builtins/builtins-test/tests/addsub.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
#![allow(unused_macros)]
#![cfg_attr(f16_enabled, feature(f16))]
#![cfg_attr(f128_enabled, feature(f128))]

use builtins_test::*;
Expand Down Expand Up @@ -115,28 +116,25 @@ macro_rules! float_sum {
mod float_addsub {
use super::*;

#[cfg(f16_enabled)]
float_sum! {
f16, __addhf3, __subhf3, Half, all();
}

float_sum! {
f32, __addsf3, __subsf3, Single, all();
f64, __adddf3, __subdf3, Double, all();
}
}

#[cfg(f128_enabled)]
#[cfg(not(x86_no_sse))]
#[cfg(not(any(target_arch = "powerpc", target_arch = "powerpc64")))]
mod float_addsub_f128 {
use super::*;

#[cfg(f128_enabled)]
#[cfg(not(x86_no_sse))]
#[cfg(not(any(target_arch = "powerpc", target_arch = "powerpc64")))]
float_sum! {
f128, __addtf3, __subtf3, Quad, not(feature = "no-sys-f128");
}
}

#[cfg(f128_enabled)]
#[cfg(any(target_arch = "powerpc", target_arch = "powerpc64"))]
mod float_addsub_f128_ppc {
use super::*;

#[cfg(f128_enabled)]
#[cfg(any(target_arch = "powerpc", target_arch = "powerpc64"))]
float_sum! {
f128, __addkf3, __subkf3, Quad, not(feature = "no-sys-f128");
}
Expand Down
21 changes: 21 additions & 0 deletions library/compiler-builtins/builtins-test/tests/cmp.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
#![allow(unused_macros)]
#![allow(unreachable_code)]
#![cfg_attr(f16_enabled, feature(f16))]
#![cfg_attr(f128_enabled, feature(f128))]

use builtins_test::*;
Expand Down Expand Up @@ -51,6 +52,26 @@ mod float_comparisons {
};
}

#[test]
#[cfg(f16_enabled)]
fn cmp_f16() {
use compiler_builtins::float::cmp::{
__eqhf2, __gehf2, __gthf2, __lehf2, __lthf2, __nehf2, __unordhf2,
};

fuzz_float_2(N, |x: f16, y: f16| {
assert_eq!(__unordhf2(x, y) != 0, x.is_nan() || y.is_nan());
cmp!(f16, x, y, Half, all(),
1, __lthf2;
1, __lehf2;
1, __eqhf2;
-1, __gehf2;
-1, __gthf2;
1, __nehf2;
);
});
}

#[test]
fn cmp_f32() {
use compiler_builtins::float::cmp::{
Expand Down
8 changes: 7 additions & 1 deletion library/compiler-builtins/builtins-test/tests/mul.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
#![allow(unused_macros)]
#![cfg_attr(f16_enabled, feature(f16))]
#![cfg_attr(f128_enabled, feature(f128))]
#![allow(unused_macros)]

use builtins_test::*;

Expand Down Expand Up @@ -117,6 +118,11 @@ macro_rules! float_mul {
mod float_mul {
use super::*;

#[cfg(f16_enabled)]
float_mul! {
f16, __mulhf3, Half, all();
}

// FIXME(#616): Stop ignoring arches that don't have native support once fix for builtins is in
// nightly.
float_mul! {
Expand Down
7 changes: 6 additions & 1 deletion library/compiler-builtins/compiler-builtins/src/float/add.rs
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,7 @@ where
return F::from_bits(MinInt::ZERO);
}

// If partial cancellation occured, we need to left-shift the result
// If partial cancellation occurred, we need to left-shift the result
// and adjust the exponent:
if a_significand < implicit_bit << 3 {
let shift = a_significand.leading_zeros() as i32
Expand Down Expand Up @@ -191,6 +191,11 @@ where
}

intrinsics! {
#[cfg(f16_enabled)]
pub extern "C" fn __addhf3(a: f16, b: f16) -> f16 {
add(a, b)
}

#[aapcs_on_arm]
#[arm_aeabi_alias = __aeabi_fadd]
pub extern "C" fn __addsf3(a: f32, b: f32) -> f32 {
Expand Down
31 changes: 31 additions & 0 deletions library/compiler-builtins/compiler-builtins/src/float/cmp.rs
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,37 @@ fn unord<F: Float>(a: F, b: F) -> bool {
a_abs > inf_rep || b_abs > inf_rep
}

#[cfg(f16_enabled)]
intrinsics! {
pub extern "C" fn __lehf2(a: f16, b: f16) -> crate::float::cmp::CmpResult {
cmp(a, b).to_le_abi()
}

pub extern "C" fn __gehf2(a: f16, b: f16) -> crate::float::cmp::CmpResult {
cmp(a, b).to_ge_abi()
}

pub extern "C" fn __unordhf2(a: f16, b: f16) -> crate::float::cmp::CmpResult {
unord(a, b) as crate::float::cmp::CmpResult
}

pub extern "C" fn __eqhf2(a: f16, b: f16) -> crate::float::cmp::CmpResult {
cmp(a, b).to_le_abi()
}

pub extern "C" fn __lthf2(a: f16, b: f16) -> crate::float::cmp::CmpResult {
cmp(a, b).to_le_abi()
}

pub extern "C" fn __nehf2(a: f16, b: f16) -> crate::float::cmp::CmpResult {
cmp(a, b).to_le_abi()
}

pub extern "C" fn __gthf2(a: f16, b: f16) -> crate::float::cmp::CmpResult {
cmp(a, b).to_ge_abi()
}
}

intrinsics! {
pub extern "C" fn __lesf2(a: f32, b: f32) -> crate::float::cmp::CmpResult {
cmp(a, b).to_le_abi()
Expand Down
5 changes: 5 additions & 0 deletions library/compiler-builtins/compiler-builtins/src/float/mul.rs
Original file line number Diff line number Diff line change
Expand Up @@ -180,6 +180,11 @@ where
}

intrinsics! {
#[cfg(f16_enabled)]
pub extern "C" fn __mulhf3(a: f16, b: f16) -> f16 {
mul(a, b)
}

#[aapcs_on_arm]
#[arm_aeabi_alias = __aeabi_fmul]
pub extern "C" fn __mulsf3(a: f32, b: f32) -> f32 {
Expand Down
5 changes: 5 additions & 0 deletions library/compiler-builtins/compiler-builtins/src/float/sub.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,11 @@
use crate::float::Float;

intrinsics! {
#[cfg(f16_enabled)]
pub extern "C" fn __subhf3(a: f16, b: f16) -> f16 {
crate::float::add::__addhf3(a, f16::from_bits(b.to_bits() ^ f16::SIGN_MASK))
}

#[arm_aeabi_alias = __aeabi_fsub]
pub extern "C" fn __subsf3(a: f32, b: f32) -> f32 {
crate::float::add::__addsf3(a, f32::from_bits(b.to_bits() ^ f32::SIGN_MASK))
Expand Down
4 changes: 0 additions & 4 deletions library/compiler-builtins/compiler-builtins/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,6 @@
#![no_std]
#![allow(unused_features)]
#![allow(internal_features)]
// We use `u128` in a whole bunch of places which we currently agree with the
// compiler on ABIs and such, so we should be "good enough" for now and changes
// to the `u128` ABI will be reflected here.
#![allow(improper_ctypes, improper_ctypes_definitions)]
// `mem::swap` cannot be used because it may generate references to memcpy in unoptimized code.
#![allow(clippy::manual_swap)]
// Support compiling on both stage0 and stage1 which may differ in supported stable features.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ pub unsafe extern "custom" fn __rust_probestack() {
// page needed.
//
// Note that we're also testing against `8(%rsp)` to account for the 8
// bytes pushed on the stack orginally with our return address. Using
// bytes pushed on the stack originally with our return address. Using
// `8(%rsp)` simulates us testing the stack pointer in the caller's
// context.
Expand Down
37 changes: 26 additions & 11 deletions library/compiler-builtins/crates/symbol-check/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ use std::process::{Command, Stdio};

use object::read::archive::{ArchiveFile, ArchiveMember};
use object::{
File as ObjFile, Object, ObjectSymbol, Symbol, SymbolKind, SymbolScope, SymbolSection,
File as ObjFile, Object, ObjectSection, ObjectSymbol, Symbol, SymbolKind, SymbolScope,
};
use serde_json::Value;

Expand Down Expand Up @@ -154,7 +154,7 @@ struct SymInfo {
name: String,
kind: SymbolKind,
scope: SymbolScope,
section: SymbolSection,
section: String,
is_undefined: bool,
is_global: bool,
is_local: bool,
Expand All @@ -165,12 +165,22 @@ struct SymInfo {
}

impl SymInfo {
fn new(sym: &Symbol, member: &ArchiveMember) -> Self {
fn new(sym: &Symbol, obj: &ObjFile, member: &ArchiveMember) -> Self {
// Include the section name if possible. Fall back to the `Section` debug impl if not.
let section = sym.section();
let section_name = sym
.section()
.index()
.and_then(|idx| obj.section_by_index(idx).ok())
.and_then(|sec| sec.name().ok())
.map(ToString::to_string)
.unwrap_or_else(|| format!("{section:?}"));

Self {
name: sym.name().expect("missing name").to_owned(),
kind: sym.kind(),
scope: sym.scope(),
section: sym.section(),
section: section_name,
is_undefined: sym.is_undefined(),
is_global: sym.is_global(),
is_local: sym.is_local(),
Expand All @@ -192,22 +202,27 @@ fn verify_no_duplicates(archive: &Archive) {
let mut dups = Vec::new();
let mut found_any = false;

archive.for_each_symbol(|symbol, member| {
archive.for_each_symbol(|symbol, obj, member| {
// Only check defined globals
if !symbol.is_global() || symbol.is_undefined() {
return;
}

let sym = SymInfo::new(&symbol, member);
let sym = SymInfo::new(&symbol, obj, member);

// x86-32 includes multiple copies of thunk symbols
if sym.name.starts_with("__x86.get_pc_thunk") {
return;
}

// GDB pretty printing symbols may show up more than once but are weak.
if sym.section == ".debug_gdb_scripts" && sym.is_weak {
return;
}

// Windows has symbols for literal numeric constants, string literals, and MinGW pseudo-
// relocations. These are allowed to have repeated definitions.
let win_allowed_dup_pfx = ["__real@", "__xmm@", "??_C@_", ".refptr"];
let win_allowed_dup_pfx = ["__real@", "__xmm@", "__ymm@", "??_C@_", ".refptr"];
if win_allowed_dup_pfx
.iter()
.any(|pfx| sym.name.starts_with(pfx))
Expand Down Expand Up @@ -244,15 +259,15 @@ fn verify_core_symbols(archive: &Archive) {
let mut undefined = Vec::new();
let mut has_symbols = false;

archive.for_each_symbol(|symbol, member| {
archive.for_each_symbol(|symbol, obj, member| {
has_symbols = true;

// Find only symbols from `core`
if !symbol.name().unwrap().contains("_ZN4core") {
return;
}

let sym = SymInfo::new(&symbol, member);
let sym = SymInfo::new(&symbol, obj, member);
if sym.is_undefined {
undefined.push(sym);
} else {
Expand Down Expand Up @@ -304,9 +319,9 @@ impl Archive {
}

/// For a given archive, do something with each symbol.
fn for_each_symbol(&self, mut f: impl FnMut(Symbol, &ArchiveMember)) {
fn for_each_symbol(&self, mut f: impl FnMut(Symbol, &ObjFile, &ArchiveMember)) {
self.for_each_object(|obj, member| {
obj.symbols().for_each(|sym| f(sym, member));
obj.symbols().for_each(|sym| f(sym, &obj, member));
});
}
}
2 changes: 1 addition & 1 deletion library/compiler-builtins/etc/update-api-list.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ def eprint(*args, **kwargs):

@dataclass
class Crate:
"""Representation of public interfaces and function defintion locations in
"""Representation of public interfaces and function definition locations in
`libm`.
"""

Expand Down
2 changes: 1 addition & 1 deletion library/compiler-builtins/libm/src/math/rem_pio2_large.rs
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,7 @@ const PIO2: [f64; 8] = [
// x[i] = floor(z)
// z = (z-x[i])*2**24
//
// y[] ouput result in an array of double precision numbers.
// y[] output result in an array of double precision numbers.
// The dimension of y[] is:
// 24-bit precision 1
// 53-bit precision 2
Expand Down
2 changes: 1 addition & 1 deletion library/compiler-builtins/rust-version
Original file line number Diff line number Diff line change
@@ -1 +1 @@
82310651b93a594a3fd69015e1562186a080d94c
d36f964125163c2e698de5559efefb8217b8b7f0
Loading