@@ -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,39 @@ 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+ match self . rustc_abi {
777+ None => {
778+ // Default hardfloat ABI.
779+ // x87 must be enabled, soft-float must be disabled.
780+ FeatureConstraints { required : & [ "x87" ] , incompatible : & [ "soft-float" ] }
781+ }
782+ Some ( RustcAbi :: X86Softfloat ) => {
783+ // Softfloat ABI, requires corresponding target feature. That feature trumps
784+ // `x87` and all other FPU features so those do not matter.
785+ // Note that this one requirement is the entire implementation of the ABI!
786+ // LLVM handles the rest.
787+ FeatureConstraints { required : & [ "soft-float" ] , incompatible : & [ ] }
788+ }
780789 }
781790 }
782791 "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 : & [ ] }
792+ // We use our own ABI indicator here; LLVM does not have anything native.
793+ match self . rustc_abi {
794+ None => {
795+ // Default hardfloat ABI. On x86-64, this always includes SSE2.
796+ FeatureConstraints {
797+ required : & [ "x87" , "sse2" ] ,
798+ incompatible : & [ "soft-float" ] ,
799+ }
800+ }
801+ Some ( RustcAbi :: X86Softfloat ) => {
802+ // Softfloat ABI, requires corresponding target feature. That feature trumps
803+ // `x87` and all other FPU features so those do not matter.
804+ // Note that this one requirement is the entire implementation of the ABI!
805+ // LLVM handles the rest.
806+ FeatureConstraints { required : & [ "soft-float" ] , incompatible : & [ ] }
807+ }
790808 }
791809 }
792810 "arm" => {
0 commit comments