Skip to content

Commit 4c65eef

Browse files
authored
Rollup merge of rust-lang#121841 - tgross35:f16-f128-step2-intrinsics, r=compiler-errors
`f16` and `f128` step 2: intrinsics Continuation of rust-lang#121728, another portion of rust-lang#114607. This PR adds `f16` and `f128` intrinsics, and hooks them up to both HIR and LLVM. This is all still unexposed to the frontend, which will probably be the next step. Also update itanium mangling per `@rcvalle's` in https://github.com/rust-lang/rust/pull/121728/files#r1506570300, and fix a typo from step 1. Once these types are usable in code, I will add the codegen tests from rust-lang#114607 (codegen is passing on that branch) This does add more `unimplemented!`s to Clippy, but I still don't think we can do better until library support is added. r? `@compiler-errors` cc `@Nilstrieb` `@rustbot` label +T-compiler +F-f16_and_f128
2 parents 200019c + 01755e3 commit 4c65eef

File tree

14 files changed

+273
-10
lines changed

14 files changed

+273
-10
lines changed

compiler/rustc_ast/src/ast.rs

+6
Original file line numberDiff line numberDiff line change
@@ -1920,22 +1920,28 @@ pub struct FnSig {
19201920
#[derive(Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash, Debug)]
19211921
#[derive(Encodable, Decodable, HashStable_Generic)]
19221922
pub enum FloatTy {
1923+
F16,
19231924
F32,
19241925
F64,
1926+
F128,
19251927
}
19261928

19271929
impl FloatTy {
19281930
pub fn name_str(self) -> &'static str {
19291931
match self {
1932+
FloatTy::F16 => "f16",
19301933
FloatTy::F32 => "f32",
19311934
FloatTy::F64 => "f64",
1935+
FloatTy::F128 => "f128",
19321936
}
19331937
}
19341938

19351939
pub fn name(self) -> Symbol {
19361940
match self {
1941+
FloatTy::F16 => sym::f16,
19371942
FloatTy::F32 => sym::f32,
19381943
FloatTy::F64 => sym::f64,
1944+
FloatTy::F128 => sym::f128,
19391945
}
19401946
}
19411947
}

compiler/rustc_codegen_llvm/src/context.rs

+48
Original file line numberDiff line numberDiff line change
@@ -685,8 +685,10 @@ impl<'ll> CodegenCx<'ll, '_> {
685685
let t_i64 = self.type_i64();
686686
let t_i128 = self.type_i128();
687687
let t_isize = self.type_isize();
688+
let t_f16 = self.type_f16();
688689
let t_f32 = self.type_f32();
689690
let t_f64 = self.type_f64();
691+
let t_f128 = self.type_f128();
690692
let t_metadata = self.type_metadata();
691693
let t_token = self.type_token();
692694

@@ -728,69 +730,115 @@ impl<'ll> CodegenCx<'ll, '_> {
728730
ifn!("llvm.debugtrap", fn() -> void);
729731
ifn!("llvm.frameaddress", fn(t_i32) -> ptr);
730732

733+
ifn!("llvm.powi.f16", fn(t_f16, t_i32) -> t_f16);
731734
ifn!("llvm.powi.f32", fn(t_f32, t_i32) -> t_f32);
732735
ifn!("llvm.powi.f64", fn(t_f64, t_i32) -> t_f64);
736+
ifn!("llvm.powi.f128", fn(t_f128, t_i32) -> t_f128);
733737

738+
ifn!("llvm.pow.f16", fn(t_f16, t_f16) -> t_f16);
734739
ifn!("llvm.pow.f32", fn(t_f32, t_f32) -> t_f32);
735740
ifn!("llvm.pow.f64", fn(t_f64, t_f64) -> t_f64);
741+
ifn!("llvm.pow.f128", fn(t_f128, t_f128) -> t_f128);
736742

743+
ifn!("llvm.sqrt.f16", fn(t_f16) -> t_f16);
737744
ifn!("llvm.sqrt.f32", fn(t_f32) -> t_f32);
738745
ifn!("llvm.sqrt.f64", fn(t_f64) -> t_f64);
746+
ifn!("llvm.sqrt.f128", fn(t_f128) -> t_f128);
739747

748+
ifn!("llvm.sin.f16", fn(t_f16) -> t_f16);
740749
ifn!("llvm.sin.f32", fn(t_f32) -> t_f32);
741750
ifn!("llvm.sin.f64", fn(t_f64) -> t_f64);
751+
ifn!("llvm.sin.f128", fn(t_f128) -> t_f128);
742752

753+
ifn!("llvm.cos.f16", fn(t_f16) -> t_f16);
743754
ifn!("llvm.cos.f32", fn(t_f32) -> t_f32);
744755
ifn!("llvm.cos.f64", fn(t_f64) -> t_f64);
756+
ifn!("llvm.cos.f128", fn(t_f128) -> t_f128);
745757

758+
ifn!("llvm.exp.f16", fn(t_f16) -> t_f16);
746759
ifn!("llvm.exp.f32", fn(t_f32) -> t_f32);
747760
ifn!("llvm.exp.f64", fn(t_f64) -> t_f64);
761+
ifn!("llvm.exp.f128", fn(t_f128) -> t_f128);
748762

763+
ifn!("llvm.exp2.f16", fn(t_f16) -> t_f16);
749764
ifn!("llvm.exp2.f32", fn(t_f32) -> t_f32);
750765
ifn!("llvm.exp2.f64", fn(t_f64) -> t_f64);
766+
ifn!("llvm.exp2.f128", fn(t_f128) -> t_f128);
751767

768+
ifn!("llvm.log.f16", fn(t_f16) -> t_f16);
752769
ifn!("llvm.log.f32", fn(t_f32) -> t_f32);
753770
ifn!("llvm.log.f64", fn(t_f64) -> t_f64);
771+
ifn!("llvm.log.f128", fn(t_f128) -> t_f128);
754772

773+
ifn!("llvm.log10.f16", fn(t_f16) -> t_f16);
755774
ifn!("llvm.log10.f32", fn(t_f32) -> t_f32);
756775
ifn!("llvm.log10.f64", fn(t_f64) -> t_f64);
776+
ifn!("llvm.log10.f128", fn(t_f128) -> t_f128);
757777

778+
ifn!("llvm.log2.f16", fn(t_f16) -> t_f16);
758779
ifn!("llvm.log2.f32", fn(t_f32) -> t_f32);
759780
ifn!("llvm.log2.f64", fn(t_f64) -> t_f64);
781+
ifn!("llvm.log2.f128", fn(t_f128) -> t_f128);
760782

783+
ifn!("llvm.fma.f16", fn(t_f16, t_f16, t_f16) -> t_f16);
761784
ifn!("llvm.fma.f32", fn(t_f32, t_f32, t_f32) -> t_f32);
762785
ifn!("llvm.fma.f64", fn(t_f64, t_f64, t_f64) -> t_f64);
786+
ifn!("llvm.fma.f128", fn(t_f128, t_f128, t_f128) -> t_f128);
763787

788+
ifn!("llvm.fabs.f16", fn(t_f16) -> t_f16);
764789
ifn!("llvm.fabs.f32", fn(t_f32) -> t_f32);
765790
ifn!("llvm.fabs.f64", fn(t_f64) -> t_f64);
791+
ifn!("llvm.fabs.f128", fn(t_f128) -> t_f128);
766792

793+
ifn!("llvm.minnum.f16", fn(t_f16, t_f16) -> t_f16);
767794
ifn!("llvm.minnum.f32", fn(t_f32, t_f32) -> t_f32);
768795
ifn!("llvm.minnum.f64", fn(t_f64, t_f64) -> t_f64);
796+
ifn!("llvm.minnum.f128", fn(t_f128, t_f128) -> t_f128);
797+
798+
ifn!("llvm.maxnum.f16", fn(t_f16, t_f16) -> t_f16);
769799
ifn!("llvm.maxnum.f32", fn(t_f32, t_f32) -> t_f32);
770800
ifn!("llvm.maxnum.f64", fn(t_f64, t_f64) -> t_f64);
801+
ifn!("llvm.maxnum.f128", fn(t_f128, t_f128) -> t_f128);
771802

803+
ifn!("llvm.floor.f16", fn(t_f16) -> t_f16);
772804
ifn!("llvm.floor.f32", fn(t_f32) -> t_f32);
773805
ifn!("llvm.floor.f64", fn(t_f64) -> t_f64);
806+
ifn!("llvm.floor.f128", fn(t_f128) -> t_f128);
774807

808+
ifn!("llvm.ceil.f16", fn(t_f16) -> t_f16);
775809
ifn!("llvm.ceil.f32", fn(t_f32) -> t_f32);
776810
ifn!("llvm.ceil.f64", fn(t_f64) -> t_f64);
811+
ifn!("llvm.ceil.f128", fn(t_f128) -> t_f128);
777812

813+
ifn!("llvm.trunc.f16", fn(t_f16) -> t_f16);
778814
ifn!("llvm.trunc.f32", fn(t_f32) -> t_f32);
779815
ifn!("llvm.trunc.f64", fn(t_f64) -> t_f64);
816+
ifn!("llvm.trunc.f128", fn(t_f128) -> t_f128);
780817

818+
ifn!("llvm.copysign.f16", fn(t_f16, t_f16) -> t_f16);
781819
ifn!("llvm.copysign.f32", fn(t_f32, t_f32) -> t_f32);
782820
ifn!("llvm.copysign.f64", fn(t_f64, t_f64) -> t_f64);
821+
ifn!("llvm.copysign.f128", fn(t_f128, t_f128) -> t_f128);
783822

823+
ifn!("llvm.round.f16", fn(t_f16) -> t_f16);
784824
ifn!("llvm.round.f32", fn(t_f32) -> t_f32);
785825
ifn!("llvm.round.f64", fn(t_f64) -> t_f64);
826+
ifn!("llvm.round.f128", fn(t_f128) -> t_f128);
786827

828+
ifn!("llvm.roundeven.f16", fn(t_f16) -> t_f16);
787829
ifn!("llvm.roundeven.f32", fn(t_f32) -> t_f32);
788830
ifn!("llvm.roundeven.f64", fn(t_f64) -> t_f64);
831+
ifn!("llvm.roundeven.f128", fn(t_f128) -> t_f128);
789832

833+
ifn!("llvm.rint.f16", fn(t_f16) -> t_f16);
790834
ifn!("llvm.rint.f32", fn(t_f32) -> t_f32);
791835
ifn!("llvm.rint.f64", fn(t_f64) -> t_f64);
836+
ifn!("llvm.rint.f128", fn(t_f128) -> t_f128);
837+
838+
ifn!("llvm.nearbyint.f16", fn(t_f16) -> t_f16);
792839
ifn!("llvm.nearbyint.f32", fn(t_f32) -> t_f32);
793840
ifn!("llvm.nearbyint.f64", fn(t_f64) -> t_f64);
841+
ifn!("llvm.nearbyint.f128", fn(t_f128) -> t_f128);
794842

795843
ifn!("llvm.ctpop.i8", fn(t_i8) -> t_i8);
796844
ifn!("llvm.ctpop.i16", fn(t_i16) -> t_i16);

compiler/rustc_codegen_llvm/src/debuginfo/metadata.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -695,7 +695,7 @@ impl MsvcBasicName for ty::UintTy {
695695

696696
impl MsvcBasicName for ty::FloatTy {
697697
fn msvc_basic_name(self) -> &'static str {
698-
// FIXME: f16 and f128 have no MSVE representation. We could improve the debuginfo.
698+
// FIXME: f16 and f128 have no MSVC representation. We could improve the debuginfo.
699699
// See: <https://github.com/rust-lang/rust/pull/114607/files#r1454683264>
700700
match self {
701701
ty::FloatTy::F16 => "half",

compiler/rustc_codegen_llvm/src/intrinsic.rs

+67
Original file line numberDiff line numberDiff line change
@@ -28,51 +28,118 @@ fn get_simple_intrinsic<'ll>(
2828
name: Symbol,
2929
) -> Option<(&'ll Type, &'ll Value)> {
3030
let llvm_name = match name {
31+
sym::sqrtf16 => "llvm.sqrt.f16",
3132
sym::sqrtf32 => "llvm.sqrt.f32",
3233
sym::sqrtf64 => "llvm.sqrt.f64",
34+
sym::sqrtf128 => "llvm.sqrt.f128",
35+
36+
sym::powif16 => "llvm.powi.f16",
3337
sym::powif32 => "llvm.powi.f32",
3438
sym::powif64 => "llvm.powi.f64",
39+
sym::powif128 => "llvm.powi.f128",
40+
41+
sym::sinf16 => "llvm.sin.f16",
3542
sym::sinf32 => "llvm.sin.f32",
3643
sym::sinf64 => "llvm.sin.f64",
44+
sym::sinf128 => "llvm.sin.f128",
45+
46+
sym::cosf16 => "llvm.cos.f16",
3747
sym::cosf32 => "llvm.cos.f32",
3848
sym::cosf64 => "llvm.cos.f64",
49+
sym::cosf128 => "llvm.cos.f128",
50+
51+
sym::powf16 => "llvm.pow.f16",
3952
sym::powf32 => "llvm.pow.f32",
4053
sym::powf64 => "llvm.pow.f64",
54+
sym::powf128 => "llvm.pow.f128",
55+
56+
sym::expf16 => "llvm.exp.f16",
4157
sym::expf32 => "llvm.exp.f32",
4258
sym::expf64 => "llvm.exp.f64",
59+
sym::expf128 => "llvm.exp.f128",
60+
61+
sym::exp2f16 => "llvm.exp2.f16",
4362
sym::exp2f32 => "llvm.exp2.f32",
4463
sym::exp2f64 => "llvm.exp2.f64",
64+
sym::exp2f128 => "llvm.exp2.f128",
65+
66+
sym::logf16 => "llvm.log.f16",
4567
sym::logf32 => "llvm.log.f32",
4668
sym::logf64 => "llvm.log.f64",
69+
sym::logf128 => "llvm.log.f128",
70+
71+
sym::log10f16 => "llvm.log10.f16",
4772
sym::log10f32 => "llvm.log10.f32",
4873
sym::log10f64 => "llvm.log10.f64",
74+
sym::log10f128 => "llvm.log10.f128",
75+
76+
sym::log2f16 => "llvm.log2.f16",
4977
sym::log2f32 => "llvm.log2.f32",
5078
sym::log2f64 => "llvm.log2.f64",
79+
sym::log2f128 => "llvm.log2.f128",
80+
81+
sym::fmaf16 => "llvm.fma.f16",
5182
sym::fmaf32 => "llvm.fma.f32",
5283
sym::fmaf64 => "llvm.fma.f64",
84+
sym::fmaf128 => "llvm.fma.f128",
85+
86+
sym::fabsf16 => "llvm.fabs.f16",
5387
sym::fabsf32 => "llvm.fabs.f32",
5488
sym::fabsf64 => "llvm.fabs.f64",
89+
sym::fabsf128 => "llvm.fabs.f128",
90+
91+
sym::minnumf16 => "llvm.minnum.f16",
5592
sym::minnumf32 => "llvm.minnum.f32",
5693
sym::minnumf64 => "llvm.minnum.f64",
94+
sym::minnumf128 => "llvm.minnum.f128",
95+
96+
sym::maxnumf16 => "llvm.maxnum.f16",
5797
sym::maxnumf32 => "llvm.maxnum.f32",
5898
sym::maxnumf64 => "llvm.maxnum.f64",
99+
sym::maxnumf128 => "llvm.maxnum.f128",
100+
101+
sym::copysignf16 => "llvm.copysign.f16",
59102
sym::copysignf32 => "llvm.copysign.f32",
60103
sym::copysignf64 => "llvm.copysign.f64",
104+
sym::copysignf128 => "llvm.copysign.f128",
105+
106+
sym::floorf16 => "llvm.floor.f16",
61107
sym::floorf32 => "llvm.floor.f32",
62108
sym::floorf64 => "llvm.floor.f64",
109+
sym::floorf128 => "llvm.floor.f128",
110+
111+
sym::ceilf16 => "llvm.ceil.f16",
63112
sym::ceilf32 => "llvm.ceil.f32",
64113
sym::ceilf64 => "llvm.ceil.f64",
114+
sym::ceilf128 => "llvm.ceil.f128",
115+
116+
sym::truncf16 => "llvm.trunc.f16",
65117
sym::truncf32 => "llvm.trunc.f32",
66118
sym::truncf64 => "llvm.trunc.f64",
119+
sym::truncf128 => "llvm.trunc.f128",
120+
121+
sym::rintf16 => "llvm.rint.f16",
67122
sym::rintf32 => "llvm.rint.f32",
68123
sym::rintf64 => "llvm.rint.f64",
124+
sym::rintf128 => "llvm.rint.f128",
125+
126+
sym::nearbyintf16 => "llvm.nearbyint.f16",
69127
sym::nearbyintf32 => "llvm.nearbyint.f32",
70128
sym::nearbyintf64 => "llvm.nearbyint.f64",
129+
sym::nearbyintf128 => "llvm.nearbyint.f128",
130+
131+
sym::roundf16 => "llvm.round.f16",
71132
sym::roundf32 => "llvm.round.f32",
72133
sym::roundf64 => "llvm.round.f64",
134+
sym::roundf128 => "llvm.round.f128",
135+
73136
sym::ptr_mask => "llvm.ptrmask",
137+
138+
sym::roundevenf16 => "llvm.roundeven.f16",
74139
sym::roundevenf32 => "llvm.roundeven.f32",
75140
sym::roundevenf64 => "llvm.roundeven.f64",
141+
sym::roundevenf128 => "llvm.roundeven.f128",
142+
76143
_ => return None,
77144
};
78145
Some(cx.get_intrinsic(llvm_name))

compiler/rustc_hir/src/hir.rs

+5
Original file line numberDiff line numberDiff line change
@@ -2460,6 +2460,7 @@ impl PrimTy {
24602460
Self::Uint(UintTy::Usize),
24612461
Self::Float(FloatTy::F32),
24622462
Self::Float(FloatTy::F64),
2463+
// FIXME(f16_f128): add these when enabled below
24632464
Self::Bool,
24642465
Self::Char,
24652466
Self::Str,
@@ -2509,6 +2510,10 @@ impl PrimTy {
25092510
sym::usize => Self::Uint(UintTy::Usize),
25102511
sym::f32 => Self::Float(FloatTy::F32),
25112512
sym::f64 => Self::Float(FloatTy::F64),
2513+
// FIXME(f16_f128): enabling these will open the gates of f16 and f128 being
2514+
// understood by rustc.
2515+
// sym::f16 => Self::Float(FloatTy::F16),
2516+
// sym::f128 => Self::Float(FloatTy::F128),
25122517
sym::bool => Self::Bool,
25132518
sym::char => Self::Char,
25142519
sym::str => Self::Str,

0 commit comments

Comments
 (0)