Skip to content

Commit 0567162

Browse files
committed
Add support to new float types
1 parent e3ac2c6 commit 0567162

File tree

2 files changed

+31
-8
lines changed
  • compiler

2 files changed

+31
-8
lines changed

compiler/rustc_smir/src/rustc_smir/convert/abi.rs

+7-4
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,9 @@ use crate::rustc_smir::{Stable, Tables};
66
use rustc_middle::ty;
77
use rustc_target::abi::call::Conv;
88
use stable_mir::abi::{
9-
AddressSpace, ArgAbi, CallConvention, FieldsShape, FnAbi, IntegerLength, Layout, LayoutShape,
10-
PassMode, Primitive, Scalar, TagEncoding, TyAndLayout, ValueAbi, VariantsShape, WrappingRange,
9+
AddressSpace, ArgAbi, CallConvention, FieldsShape, FloatLength, FnAbi, IntegerLength, Layout,
10+
LayoutShape, PassMode, Primitive, Scalar, TagEncoding, TyAndLayout, ValueAbi, VariantsShape,
11+
WrappingRange,
1112
};
1213
use stable_mir::opaque;
1314
use stable_mir::target::MachineSize as Size;
@@ -255,8 +256,10 @@ impl<'tcx> Stable<'tcx> for rustc_abi::Primitive {
255256
rustc_abi::Primitive::Int(length, signed) => {
256257
Primitive::Int { length: length.stable(tables), signed: *signed }
257258
}
258-
rustc_abi::Primitive::F32 => Primitive::F32,
259-
rustc_abi::Primitive::F64 => Primitive::F64,
259+
rustc_abi::Primitive::F16 => Primitive::Float { length: FloatLength::F16 },
260+
rustc_abi::Primitive::F32 => Primitive::Float { length: FloatLength::F32 },
261+
rustc_abi::Primitive::F64 => Primitive::Float { length: FloatLength::F64 },
262+
rustc_abi::Primitive::F128 => Primitive::Float { length: FloatLength::F128 },
260263
rustc_abi::Primitive::Pointer(space) => Primitive::Pointer(space.stable(tables)),
261264
}
262265
}

compiler/stable_mir/src/abi.rs

+24-4
Original file line numberDiff line numberDiff line change
@@ -293,17 +293,17 @@ pub enum Primitive {
293293
length: IntegerLength,
294294
signed: bool,
295295
},
296-
F32,
297-
F64,
296+
Float {
297+
length: FloatLength,
298+
},
298299
Pointer(AddressSpace),
299300
}
300301

301302
impl Primitive {
302303
pub fn size(self, target: &MachineInfo) -> Size {
303304
match self {
304305
Primitive::Int { length, .. } => Size::from_bits(length.bits()),
305-
Primitive::F32 => Size::from_bits(32),
306-
Primitive::F64 => Size::from_bits(64),
306+
Primitive::Float { length } => Size::from_bits(length.bits()),
307307
Primitive::Pointer(_) => target.pointer_width,
308308
}
309309
}
@@ -319,6 +319,15 @@ pub enum IntegerLength {
319319
I128,
320320
}
321321

322+
/// Enum representing the existing float lengths.
323+
#[derive(Copy, Clone, PartialEq, Eq, PartialOrd, Ord, Hash, Debug)]
324+
pub enum FloatLength {
325+
F16,
326+
F32,
327+
F64,
328+
F128,
329+
}
330+
322331
impl IntegerLength {
323332
pub fn bits(self) -> usize {
324333
match self {
@@ -331,6 +340,17 @@ impl IntegerLength {
331340
}
332341
}
333342

343+
impl FloatLength {
344+
pub fn bits(self) -> usize {
345+
match self {
346+
FloatLength::F16 => 16,
347+
FloatLength::F32 => 32,
348+
FloatLength::F64 => 64,
349+
FloatLength::F128 => 128,
350+
}
351+
}
352+
}
353+
334354
/// An identifier that specifies the address space that some operation
335355
/// should operate on. Special address spaces have an effect on code generation,
336356
/// depending on the target and the address spaces it implements.

0 commit comments

Comments
 (0)