Add support to new float types
This commit is contained in:
parent
e3ac2c68b8
commit
0567162933
2 changed files with 31 additions and 8 deletions
|
@ -6,8 +6,9 @@ use crate::rustc_smir::{Stable, Tables};
|
||||||
use rustc_middle::ty;
|
use rustc_middle::ty;
|
||||||
use rustc_target::abi::call::Conv;
|
use rustc_target::abi::call::Conv;
|
||||||
use stable_mir::abi::{
|
use stable_mir::abi::{
|
||||||
AddressSpace, ArgAbi, CallConvention, FieldsShape, FnAbi, IntegerLength, Layout, LayoutShape,
|
AddressSpace, ArgAbi, CallConvention, FieldsShape, FloatLength, FnAbi, IntegerLength, Layout,
|
||||||
PassMode, Primitive, Scalar, TagEncoding, TyAndLayout, ValueAbi, VariantsShape, WrappingRange,
|
LayoutShape, PassMode, Primitive, Scalar, TagEncoding, TyAndLayout, ValueAbi, VariantsShape,
|
||||||
|
WrappingRange,
|
||||||
};
|
};
|
||||||
use stable_mir::opaque;
|
use stable_mir::opaque;
|
||||||
use stable_mir::target::MachineSize as Size;
|
use stable_mir::target::MachineSize as Size;
|
||||||
|
@ -255,8 +256,10 @@ impl<'tcx> Stable<'tcx> for rustc_abi::Primitive {
|
||||||
rustc_abi::Primitive::Int(length, signed) => {
|
rustc_abi::Primitive::Int(length, signed) => {
|
||||||
Primitive::Int { length: length.stable(tables), signed: *signed }
|
Primitive::Int { length: length.stable(tables), signed: *signed }
|
||||||
}
|
}
|
||||||
rustc_abi::Primitive::F32 => Primitive::F32,
|
rustc_abi::Primitive::F16 => Primitive::Float { length: FloatLength::F16 },
|
||||||
rustc_abi::Primitive::F64 => Primitive::F64,
|
rustc_abi::Primitive::F32 => Primitive::Float { length: FloatLength::F32 },
|
||||||
|
rustc_abi::Primitive::F64 => Primitive::Float { length: FloatLength::F64 },
|
||||||
|
rustc_abi::Primitive::F128 => Primitive::Float { length: FloatLength::F128 },
|
||||||
rustc_abi::Primitive::Pointer(space) => Primitive::Pointer(space.stable(tables)),
|
rustc_abi::Primitive::Pointer(space) => Primitive::Pointer(space.stable(tables)),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -293,8 +293,9 @@ pub enum Primitive {
|
||||||
length: IntegerLength,
|
length: IntegerLength,
|
||||||
signed: bool,
|
signed: bool,
|
||||||
},
|
},
|
||||||
F32,
|
Float {
|
||||||
F64,
|
length: FloatLength,
|
||||||
|
},
|
||||||
Pointer(AddressSpace),
|
Pointer(AddressSpace),
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -302,8 +303,7 @@ impl Primitive {
|
||||||
pub fn size(self, target: &MachineInfo) -> Size {
|
pub fn size(self, target: &MachineInfo) -> Size {
|
||||||
match self {
|
match self {
|
||||||
Primitive::Int { length, .. } => Size::from_bits(length.bits()),
|
Primitive::Int { length, .. } => Size::from_bits(length.bits()),
|
||||||
Primitive::F32 => Size::from_bits(32),
|
Primitive::Float { length } => Size::from_bits(length.bits()),
|
||||||
Primitive::F64 => Size::from_bits(64),
|
|
||||||
Primitive::Pointer(_) => target.pointer_width,
|
Primitive::Pointer(_) => target.pointer_width,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -319,6 +319,15 @@ pub enum IntegerLength {
|
||||||
I128,
|
I128,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Enum representing the existing float lengths.
|
||||||
|
#[derive(Copy, Clone, PartialEq, Eq, PartialOrd, Ord, Hash, Debug)]
|
||||||
|
pub enum FloatLength {
|
||||||
|
F16,
|
||||||
|
F32,
|
||||||
|
F64,
|
||||||
|
F128,
|
||||||
|
}
|
||||||
|
|
||||||
impl IntegerLength {
|
impl IntegerLength {
|
||||||
pub fn bits(self) -> usize {
|
pub fn bits(self) -> usize {
|
||||||
match self {
|
match self {
|
||||||
|
@ -331,6 +340,17 @@ impl IntegerLength {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
impl FloatLength {
|
||||||
|
pub fn bits(self) -> usize {
|
||||||
|
match self {
|
||||||
|
FloatLength::F16 => 16,
|
||||||
|
FloatLength::F32 => 32,
|
||||||
|
FloatLength::F64 => 64,
|
||||||
|
FloatLength::F128 => 128,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/// An identifier that specifies the address space that some operation
|
/// An identifier that specifies the address space that some operation
|
||||||
/// should operate on. Special address spaces have an effect on code generation,
|
/// should operate on. Special address spaces have an effect on code generation,
|
||||||
/// depending on the target and the address spaces it implements.
|
/// depending on the target and the address spaces it implements.
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue