@@ -5,7 +5,7 @@ use rustc_data_structures::fx::{FxHashMap, FxHashSet};
55use rustc_data_structures:: stable_hasher:: { HashStable , StableHasher } ;
66use rustc_span:: { Symbol , sym} ;
77
8- use crate :: spec:: { FloatAbi , Target } ;
8+ use crate :: spec:: { FloatAbi , RustcAbi , Target } ;
99
1010/// Features that control behaviour of rustc, rather than the codegen.
1111/// These exist globally and are not in the target-specific lists below.
@@ -419,7 +419,9 @@ const X86_FEATURES: &[(&str, Stability, ImpliedFeatures)] = &[
419419 ( "sha512" , Unstable ( sym:: sha512_sm_x86) , & [ "avx2" ] ) ,
420420 ( "sm3" , Unstable ( sym:: sha512_sm_x86) , & [ "avx" ] ) ,
421421 ( "sm4" , Unstable ( sym:: sha512_sm_x86) , & [ "avx2" ] ) ,
422- ( "soft-float" , Stability :: Forbidden { reason : "unsound because it changes float ABI" } , & [ ] ) ,
422+ // This cannot actually be toggled, the ABI always fixes it, so it'd make little sense to
423+ // stabilize. It must be in this list for the ABI check to be able to use it.
424+ ( "soft-float" , Stability :: Unstable ( sym:: x87_target_feature) , & [ ] ) ,
423425 ( "sse" , Stable , & [ ] ) ,
424426 ( "sse2" , Stable , & [ "sse" ] ) ,
425427 ( "sse3" , Stable , & [ "sse2" ] ) ,
@@ -770,23 +772,41 @@ impl Target {
770772 // questions "which ABI is used".
771773 match & * self . arch {
772774 "x86" => {
773- // We support 2 ABIs, hardfloat (default) and softfloat.
774- // x86 has no sane ABI indicator so we have to use the target feature.
775- if self . has_feature ( "soft-float" ) {
776- NOTHING
777- } else {
778- // Hardfloat ABI. x87 must be enabled.
779- FeatureConstraints { required : & [ "x87" ] , incompatible : & [ ] }
775+ // We use our own ABI indicator here; LLVM does not have anything native.
776+ // Every case should require or forbid `soft-float`!
777+ match self . rustc_abi {
778+ None => {
779+ // Default hardfloat ABI.
780+ // x87 must be enabled, soft-float must be disabled.
781+ FeatureConstraints { required : & [ "x87" ] , incompatible : & [ "soft-float" ] }
782+ }
783+ Some ( RustcAbi :: X86Softfloat ) => {
784+ // Softfloat ABI, requires corresponding target feature. That feature trumps
785+ // `x87` and all other FPU features so those do not matter.
786+ // Note that this one requirement is the entire implementation of the ABI!
787+ // LLVM handles the rest.
788+ FeatureConstraints { required : & [ "soft-float" ] , incompatible : & [ ] }
789+ }
780790 }
781791 }
782792 "x86_64" => {
783- // We support 2 ABIs, hardfloat (default) and softfloat.
784- // x86 has no sane ABI indicator so we have to use the target feature.
785- if self . has_feature ( "soft-float" ) {
786- NOTHING
787- } else {
788- // Hardfloat ABI. x87 and SSE2 must be enabled.
789- FeatureConstraints { required : & [ "x87" , "sse2" ] , incompatible : & [ ] }
793+ // We use our own ABI indicator here; LLVM does not have anything native.
794+ // Every case should require or forbid `soft-float`!
795+ match self . rustc_abi {
796+ None => {
797+ // Default hardfloat ABI. On x86-64, this always includes SSE2.
798+ FeatureConstraints {
799+ required : & [ "x87" , "sse2" ] ,
800+ incompatible : & [ "soft-float" ] ,
801+ }
802+ }
803+ Some ( RustcAbi :: X86Softfloat ) => {
804+ // Softfloat ABI, requires corresponding target feature. That feature trumps
805+ // `x87` and all other FPU features so those do not matter.
806+ // Note that this one requirement is the entire implementation of the ABI!
807+ // LLVM handles the rest.
808+ FeatureConstraints { required : & [ "soft-float" ] , incompatible : & [ ] }
809+ }
790810 }
791811 }
792812 "arm" => {
0 commit comments