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
1 change: 0 additions & 1 deletion libm/.rustfmt.toml → .rustfmt.toml
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
# This matches rustc
style_edition = "2024"
use_small_heuristics = "Max"
group_imports = "StdExternalCrate"
imports_granularity = "Module"
36 changes: 33 additions & 3 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -7,15 +7,45 @@ members = [
"builtins-test",
"builtins-test-intrinsics",
"compiler-builtins",
"crates/libm-macros",
"libm",
# FIXME(libm): disabled until tests work in CI
# "libm-test",
# "crates/musl-math-sys",
# "crates/util",
]

default-members = [
"compiler-builtins",
"builtins-test",
"compiler-builtins",
"crates/libm-macros",
# FIXME(libm): disabled until tests work in CI
# "crates/libm-test"
"libm",
]

[profile.release]
panic = 'abort'
panic = "abort"

[profile.dev]
panic = 'abort'
panic = "abort"

# FIXME(libm): these profiles are needed for testing
# # The default release profile is unchanged.

# # Release mode with debug assertions
# [profile.release-checked]
# inherits = "release"
# debug-assertions = true
# overflow-checks = true

# # Release with maximum optimizations, which is very slow to build. This is also
# # what is needed to check `no-panic`.
# [profile.release-opt]
# inherits = "release"
# codegen-units = 1
# lto = "fat"

# [profile.bench]
# # Required for iai-callgrind
# debug = true
1 change: 1 addition & 0 deletions builtins-test-intrinsics/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -480,6 +480,7 @@ mod intrinsics {

fn run() {
use core::hint::black_box as bb;

use intrinsics::*;

// FIXME(f16_f128): some PPC f128 <-> int conversion functions have the wrong names
Expand Down
3 changes: 1 addition & 2 deletions builtins-test/benches/float_cmp.rs
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
#![cfg_attr(f128_enabled, feature(f128))]

use builtins_test::float_bench;
use criterion::{Criterion, criterion_main};

use compiler_builtins::float::cmp;
use criterion::{Criterion, criterion_main};

/// `gt` symbols are allowed to return differing results, they just get compared
/// to 0.
Expand Down
3 changes: 2 additions & 1 deletion builtins-test/benches/mem_icount.rs
Original file line number Diff line number Diff line change
Expand Up @@ -239,9 +239,10 @@ mod mcmp {
}

mod mmove {
use super::*;
use Spread::{Aligned, Large, Medium, Small};

use super::*;

struct Cfg {
len: usize,
spread: Spread,
Expand Down
2 changes: 1 addition & 1 deletion builtins-test/src/bench.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use alloc::vec::Vec;
use core::cell::RefCell;

use alloc::vec::Vec;
use compiler_builtins::float::Float;

/// Fuzz with these many items to ensure equal functions
Expand Down
1 change: 0 additions & 1 deletion builtins-test/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@ extern crate alloc;

use compiler_builtins::float::Float;
use compiler_builtins::int::{Int, MinInt};

use rand_xoshiro::Xoshiro128StarStar;
use rand_xoshiro::rand_core::{RngCore, SeedableRng};

Expand Down
1 change: 0 additions & 1 deletion builtins-test/tests/cmp.rs
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,6 @@ mod float_comparisons {
__eqkf2 as __eqtf2, __gekf2 as __getf2, __gtkf2 as __gttf2, __lekf2 as __letf2,
__ltkf2 as __lttf2, __nekf2 as __netf2, __unordkf2 as __unordtf2,
};

#[cfg(not(any(target_arch = "powerpc", target_arch = "powerpc64")))]
use compiler_builtins::float::cmp::{
__eqtf2, __getf2, __gttf2, __letf2, __lttf2, __netf2, __unordtf2,
Expand Down
3 changes: 1 addition & 2 deletions builtins-test/tests/div_rem.rs
Original file line number Diff line number Diff line change
@@ -1,11 +1,10 @@
#![feature(f128)]
#![allow(unused_macros)]

use builtins_test::*;
use compiler_builtins::int::sdiv::{__divmoddi4, __divmodsi4, __divmodti4};
use compiler_builtins::int::udiv::{__udivmoddi4, __udivmodsi4, __udivmodti4, u128_divide_sparc};

use builtins_test::*;

// Division algorithms have by far the nastiest and largest number of edge cases, and experience shows
// that sometimes 100_000 iterations of the random fuzzer is needed.

Expand Down
7 changes: 5 additions & 2 deletions compiler-builtins/build.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,11 @@
mod configure;

use std::{collections::BTreeMap, env, path::PathBuf, sync::atomic::Ordering};
use std::collections::BTreeMap;
use std::env;
use std::path::PathBuf;
use std::sync::atomic::Ordering;

use configure::{configure_aliases, configure_f16_f128, Target};
use configure::{Target, configure_aliases, configure_f16_f128};

fn main() {
println!("cargo::rerun-if-changed=build.rs");
Expand Down
3 changes: 1 addition & 2 deletions compiler-builtins/src/arm_linux.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
use core::arch;
use core::mem;
use core::sync::atomic::{AtomicU32, Ordering};
use core::{arch, mem};

// Kernel-provided user-mode helper functions:
// https://www.kernel.org/doc/Documentation/arm/kernel_user_helpers.txt
Expand Down
3 changes: 1 addition & 2 deletions compiler-builtins/src/float/conv.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
use core::ops::Neg;

use crate::int::{CastFrom, CastInto, Int, MinInt};

use super::Float;
use crate::int::{CastFrom, CastInto, Int, MinInt};

/// Conversions from integers to floats.
///
Expand Down
7 changes: 4 additions & 3 deletions compiler-builtins/src/float/div.rs
Original file line number Diff line number Diff line change
Expand Up @@ -79,11 +79,12 @@
//!
//! [Newton-Raphson method]: https://en.wikipedia.org/wiki/Newton%27s_method

use core::mem::size_of;
use core::ops;

use super::HalfRep;
use crate::float::Float;
use crate::int::{CastFrom, CastInto, DInt, HInt, Int, MinInt};
use core::mem::size_of;
use core::ops;

fn div<F: Float>(a: F, b: F) -> F
where
Expand Down Expand Up @@ -487,7 +488,7 @@ where
};

residual_lo += abs_result & one; // tie to even
// conditionally turns the below LT comparison into LTE
// conditionally turns the below LT comparison into LTE
abs_result += u8::from(residual_lo > b_significand).into();

if F::BITS == 128 || (F::BITS == 32 && half_iterations > 0) {
Expand Down
1 change: 0 additions & 1 deletion compiler-builtins/src/float/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,5 @@ pub mod trunc;

#[cfg(not(feature = "public-test-deps"))]
pub(crate) use traits::{Float, HalfRep};

#[cfg(feature = "public-test-deps")]
pub use traits::{Float, HalfRep};
6 changes: 1 addition & 5 deletions compiler-builtins/src/float/pow.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,7 @@ fn pow<F: Float>(a: F, b: i32) -> F {
a *= a;
}

if recip {
F::ONE / mul
} else {
mul
}
if recip { F::ONE / mul } else { mul }
}

intrinsics! {
Expand Down
3 changes: 2 additions & 1 deletion compiler-builtins/src/int/big.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,10 @@

#![allow(unused)]

use crate::int::{DInt, HInt, Int, MinInt};
use core::{fmt, ops};

use crate::int::{DInt, HInt, Int, MinInt};

const WORD_LO_MASK: u64 = 0x00000000ffffffff;
const WORD_HI_MASK: u64 = 0xffffffff00000000;
const WORD_FULL_MASK: u64 = 0xffffffffffffffff;
Expand Down
6 changes: 1 addition & 5 deletions compiler-builtins/src/int/leading_zeros.rs
Original file line number Diff line number Diff line change
Expand Up @@ -60,11 +60,7 @@ mod implementation {
}
// the last two bisections are combined into one conditional
t = x >> 1;
if t != T::ZERO {
z - 2
} else {
z - x.cast()
}
if t != T::ZERO { z - 2 } else { z - x.cast() }

// We could potentially save a few cycles by using the LUT trick from
// "https://embeddedgurus.com/state-space/2014/09/
Expand Down
2 changes: 0 additions & 2 deletions compiler-builtins/src/int/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,7 @@ mod traits;
pub mod udiv;

pub use big::{i256, u256};

#[cfg(not(feature = "public-test-deps"))]
pub(crate) use traits::{CastFrom, CastInto, DInt, HInt, Int, MinInt};

#[cfg(feature = "public-test-deps")]
pub use traits::{CastFrom, CastInto, DInt, HInt, Int, MinInt};
1 change: 0 additions & 1 deletion compiler-builtins/src/int/specialized_div_rem/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,6 @@ mod delegate;
#[allow(unused_imports)]
#[cfg(not(feature = "public-test-deps"))]
pub(crate) use self::delegate::u128_divide_sparc;

#[cfg(feature = "public-test-deps")]
pub use self::delegate::u128_divide_sparc;

Expand Down
1 change: 0 additions & 1 deletion compiler-builtins/src/int/udiv.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
#[cfg(not(feature = "public-test-deps"))]
pub(crate) use crate::int::specialized_div_rem::*;

#[cfg(feature = "public-test-deps")]
pub use crate::int::specialized_div_rem::*;

Expand Down
3 changes: 1 addition & 2 deletions compiler-builtins/src/mem/x86_64.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,7 @@
// Note that ERMSB does not enhance the backwards (DF=1) "rep movsb".

use core::arch::asm;
use core::intrinsics;
use core::mem;
use core::{intrinsics, mem};

#[inline(always)]
#[cfg(target_feature = "ermsb")]
Expand Down
31 changes: 24 additions & 7 deletions crates/libm-macros/src/enums.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,10 @@ pub fn function_enum(
};

if let Some(tt) = attr.next() {
return Err(syn::Error::new(tt.span(), "unexpected token after identifier"));
return Err(syn::Error::new(
tt.span(),
"unexpected token after identifier",
));
}

let enum_name = &item.ident;
Expand All @@ -46,8 +49,12 @@ pub fn function_enum(
// Match arm for `fn base_name(self)` matcher
base_arms.push(quote! { Self::#ident => #base_enum::#bname_ident });

let variant =
Variant { attrs: Vec::new(), ident, fields: Fields::Unit, discriminant: None };
let variant = Variant {
attrs: Vec::new(),
ident,
fields: Fields::Unit,
discriminant: None,
};

item.variants.push(variant);
}
Expand Down Expand Up @@ -108,7 +115,10 @@ pub fn base_name_enum(
return Err(syn::Error::new(sp.span(), "no attributes expected"));
}

let mut base_names: Vec<_> = ALL_OPERATIONS.iter().map(|func| base_name(func.name)).collect();
let mut base_names: Vec<_> = ALL_OPERATIONS
.iter()
.map(|func| base_name(func.name))
.collect();
base_names.sort_unstable();
base_names.dedup();

Expand All @@ -121,8 +131,12 @@ pub fn base_name_enum(
// Match arm for `fn as_str(self)` matcher
as_str_arms.push(quote! { Self::#ident => #base_name });

let variant =
Variant { attrs: Vec::new(), ident, fields: Fields::Unit, discriminant: None };
let variant = Variant {
attrs: Vec::new(),
ident,
fields: Fields::Unit,
discriminant: None,
};

item.variants.push(variant);
}
Expand All @@ -147,7 +161,10 @@ pub fn base_name_enum(
/// Verify that an enum is empty, otherwise return an error
fn expect_empty_enum(item: &ItemEnum) -> syn::Result<()> {
if !item.variants.is_empty() {
Err(syn::Error::new(item.variants.span(), "expected an empty enum"))
Err(syn::Error::new(
item.variants.span(),
"expected an empty enum",
))
} else {
Ok(())
}
Expand Down
Loading