Skip to content
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

Return f32 and f64 in XMM0 instead of FP0 on i686 #115919

Closed
wants to merge 2 commits into from
Closed
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: 1 addition & 0 deletions compiler/rustc_span/src/symbol.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1489,6 +1489,7 @@ symbols! {
sreg,
sreg_low16,
sse,
sse2,
sse4a_target_feature,
stable,
staged_api,
Expand Down
1 change: 1 addition & 0 deletions compiler/rustc_target/src/spec/i686_apple_darwin.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ pub fn target() -> Target {
base.add_pre_link_args(LinkerFlavor::Darwin(Cc::Yes, Lld::No), &["-m32"]);
base.stack_probes = StackProbeType::X86;
base.frame_pointer = FramePointer::Always;
base.x86_use_xmm0 = true;

Target {
// Clang automatically chooses a more specific target based on
Expand Down
1 change: 1 addition & 0 deletions compiler/rustc_target/src/spec/i686_linux_android.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ pub fn target() -> Target {
base.cpu = "pentiumpro".into();
base.features = "+mmx,+sse,+sse2,+sse3,+ssse3".into();
base.stack_probes = StackProbeType::X86;
base.x86_use_xmm0 = true;

Target {
llvm_target: "i686-linux-android".into(),
Expand Down
1 change: 1 addition & 0 deletions compiler/rustc_target/src/spec/i686_pc_windows_gnu.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ pub fn target() -> Target {
&["-m", "i386pe", "--large-address-aware"],
);
base.add_pre_link_args(LinkerFlavor::Gnu(Cc::Yes, Lld::No), &["-Wl,--large-address-aware"]);
base.x86_use_xmm0 = true;

Target {
llvm_target: "i686-pc-windows-gnu".into(),
Expand Down
1 change: 1 addition & 0 deletions compiler/rustc_target/src/spec/i686_pc_windows_gnullvm.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ pub fn target() -> Target {
LinkerFlavor::Gnu(Cc::No, Lld::No),
&["-m", "i386pe", "--large-address-aware"],
);
base.x86_use_xmm0 = true;

Target {
llvm_target: "i686-pc-windows-gnu".into(),
Expand Down
1 change: 1 addition & 0 deletions compiler/rustc_target/src/spec/i686_pc_windows_msvc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ pub fn target() -> Target {
);
// Workaround for #95429
base.has_thread_local = false;
base.x86_use_xmm0 = true;

Target {
llvm_target: "i686-pc-windows-msvc".into(),
Expand Down
1 change: 1 addition & 0 deletions compiler/rustc_target/src/spec/i686_unknown_freebsd.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ pub fn target() -> Target {
base.max_atomic_width = Some(64);
base.add_pre_link_args(LinkerFlavor::Gnu(Cc::Yes, Lld::No), &["-m32", "-Wl,-znotext"]);
base.stack_probes = StackProbeType::X86;
base.x86_use_xmm0 = true;

Target {
llvm_target: "i686-unknown-freebsd".into(),
Expand Down
1 change: 1 addition & 0 deletions compiler/rustc_target/src/spec/i686_unknown_haiku.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ pub fn target() -> Target {
base.max_atomic_width = Some(64);
base.add_pre_link_args(LinkerFlavor::Gnu(Cc::Yes, Lld::No), &["-m32"]);
base.stack_probes = StackProbeType::X86;
base.x86_use_xmm0 = true;

Target {
llvm_target: "i686-unknown-haiku".into(),
Expand Down
1 change: 1 addition & 0 deletions compiler/rustc_target/src/spec/i686_unknown_linux_gnu.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ pub fn target() -> Target {
base.supported_sanitizers = SanitizerSet::ADDRESS;
base.add_pre_link_args(LinkerFlavor::Gnu(Cc::Yes, Lld::No), &["-m32"]);
base.stack_probes = StackProbeType::X86;
base.x86_use_xmm0 = true;

Target {
llvm_target: "i686-unknown-linux-gnu".into(),
Expand Down
1 change: 1 addition & 0 deletions compiler/rustc_target/src/spec/i686_unknown_linux_musl.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ pub fn target() -> Target {
// This may or may not be related to this bug:
// https://llvm.org/bugs/show_bug.cgi?id=30879
base.frame_pointer = FramePointer::Always;
base.x86_use_xmm0 = true;

Target {
llvm_target: "i686-unknown-linux-musl".into(),
Expand Down
1 change: 1 addition & 0 deletions compiler/rustc_target/src/spec/i686_unknown_netbsd.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ pub fn target() -> Target {
base.max_atomic_width = Some(64);
base.add_pre_link_args(LinkerFlavor::Gnu(Cc::Yes, Lld::No), &["-m32"]);
base.stack_probes = StackProbeType::X86;
base.x86_use_xmm0 = true;

Target {
llvm_target: "i686-unknown-netbsdelf".into(),
Expand Down
1 change: 1 addition & 0 deletions compiler/rustc_target/src/spec/i686_unknown_openbsd.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ pub fn target() -> Target {
base.max_atomic_width = Some(64);
base.add_pre_link_args(LinkerFlavor::Gnu(Cc::Yes, Lld::No), &["-m32", "-fuse-ld=lld"]);
base.stack_probes = StackProbeType::X86;
base.x86_use_xmm0 = true;

Target {
llvm_target: "i686-unknown-openbsd".into(),
Expand Down
1 change: 1 addition & 0 deletions compiler/rustc_target/src/spec/i686_uwp_windows_gnu.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ pub fn target() -> Target {
&["-m", "i386pe", "--large-address-aware"],
);
base.add_pre_link_args(LinkerFlavor::Gnu(Cc::Yes, Lld::No), &["-Wl,--large-address-aware"]);
base.x86_use_xmm0 = true;

Target {
llvm_target: "i686-pc-windows-gnu".into(),
Expand Down
1 change: 1 addition & 0 deletions compiler/rustc_target/src/spec/i686_uwp_windows_msvc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ pub fn target() -> Target {
let mut base = super::windows_uwp_msvc_base::opts();
base.cpu = "pentium4".into();
base.max_atomic_width = Some(64);
base.x86_use_xmm0 = true;

Target {
llvm_target: "i686-pc-windows-msvc".into(),
Expand Down
1 change: 1 addition & 0 deletions compiler/rustc_target/src/spec/i686_wrs_vxworks.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ pub fn target() -> Target {
base.max_atomic_width = Some(64);
base.add_pre_link_args(LinkerFlavor::Gnu(Cc::Yes, Lld::No), &["-m32"]);
base.stack_probes = StackProbeType::X86;
base.x86_use_xmm0 = true;

Target {
llvm_target: "i686-unknown-linux-gnu".into(),
Expand Down
6 changes: 6 additions & 0 deletions compiler/rustc_target/src/spec/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1935,6 +1935,9 @@ pub struct TargetOptions {
/// wasm32 where the whole program either has simd or not.
pub simd_types_indirect: bool,

/// On x86, use XMM0 instead of FP0 as float return register for the Rust ABI
pub x86_use_xmm0: bool,

/// Pass a list of symbol which should be exported in the dylib to the linker.
pub limit_rdylib_exports: bool,

Expand Down Expand Up @@ -2213,6 +2216,7 @@ impl Default for TargetOptions {
requires_uwtable: false,
default_uwtable: false,
simd_types_indirect: true,
x86_use_xmm0: false,
limit_rdylib_exports: true,
override_export_symbols: None,
merge_functions: MergeFunctions::Aliases,
Expand Down Expand Up @@ -2878,6 +2882,7 @@ impl Target {
key!(requires_uwtable, bool);
key!(default_uwtable, bool);
key!(simd_types_indirect, bool);
key!(x86_use_xmm0, bool);
key!(limit_rdylib_exports, bool);
key!(override_export_symbols, opt_list);
key!(merge_functions, MergeFunctions)?;
Expand Down Expand Up @@ -3135,6 +3140,7 @@ impl ToJson for Target {
target_option_val!(requires_uwtable);
target_option_val!(default_uwtable);
target_option_val!(simd_types_indirect);
target_option_val!(x86_use_xmm0);
target_option_val!(limit_rdylib_exports);
target_option_val!(override_export_symbols);
target_option_val!(merge_functions);
Expand Down
8 changes: 8 additions & 0 deletions compiler/rustc_ty_utils/src/abi.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ use rustc_middle::ty::layout::{
use rustc_middle::ty::{self, InstanceDef, Ty, TyCtxt};
use rustc_session::config::OptLevel;
use rustc_span::def_id::DefId;
use rustc_span::symbol::sym;
use rustc_target::abi::call::{
ArgAbi, ArgAttribute, ArgAttributes, ArgExtension, Conv, FnAbi, PassMode, Reg, RegKind,
RiscvInterruptKind,
Expand Down Expand Up @@ -371,6 +372,9 @@ fn fn_abi_new_uncached<'tcx>(
let target = &cx.tcx.sess.target;
let target_env_gnu_like = matches!(&target.env[..], "gnu" | "musl" | "uclibc");
let win_x64_gnu = target.os == "windows" && target.arch == "x86_64" && target.env == "gnu";
let x86_sse2 = target.arch == "x86"
&& target.x86_use_xmm0
&& cx.tcx.sess.parse_sess.config.contains(&(sym::target_feature, Some(sym::sse2)));
let linux_s390x_gnu_like =
target.os == "linux" && target.arch == "s390x" && target_env_gnu_like;
let linux_sparc64_gnu_like =
Expand Down Expand Up @@ -415,6 +419,10 @@ fn fn_abi_new_uncached<'tcx>(
is_return,
drop_target_pointee,
);
// Use XMM0 instead of FP0 to preserve NaN payloads
if x86_sse2 && rust_abi && is_return && matches!(scalar.primitive(), F32 | F64) {
attrs.set(ArgAttribute::InReg);
}
attrs
});

Expand Down
4 changes: 2 additions & 2 deletions library/std/src/f32/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -328,7 +328,7 @@ macro_rules! assert_f32_biteq {

// Ignore test on x87 floating point, these platforms do not guarantee NaN
// payloads are preserved and flush denormals to zero, failing the tests.
#[cfg(not(target_arch = "x86"))]
#[cfg(not(all(target_arch = "x86", not(target_feature = "sse2"))))]
#[test]
fn test_next_up() {
let tiny = f32::from_bits(1);
Expand Down Expand Up @@ -361,7 +361,7 @@ fn test_next_up() {

// Ignore test on x87 floating point, these platforms do not guarantee NaN
// payloads are preserved and flush denormals to zero, failing the tests.
#[cfg(not(target_arch = "x86"))]
#[cfg(not(all(target_arch = "x86", not(target_feature = "sse2"))))]
#[test]
fn test_next_down() {
let tiny = f32::from_bits(1);
Expand Down
4 changes: 2 additions & 2 deletions library/std/src/f64/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -318,7 +318,7 @@ macro_rules! assert_f64_biteq {

// Ignore test on x87 floating point, these platforms do not guarantee NaN
// payloads are preserved and flush denormals to zero, failing the tests.
#[cfg(not(target_arch = "x86"))]
#[cfg(not(all(target_arch = "x86", not(target_feature = "sse2"))))]
#[test]
fn test_next_up() {
let tiny = f64::from_bits(1);
Expand Down Expand Up @@ -350,7 +350,7 @@ fn test_next_up() {

// Ignore test on x87 floating point, these platforms do not guarantee NaN
// payloads are preserved and flush denormals to zero, failing the tests.
#[cfg(not(target_arch = "x86"))]
#[cfg(not(all(target_arch = "x86", not(target_feature = "sse2"))))]
#[test]
fn test_next_down() {
let tiny = f64::from_bits(1);
Expand Down
Loading