1
Fork 0

Rollup merge of #124797 - beetrees:primitive-float, r=davidtwco

Refactor float `Primitive`s to a separate `Float` type

Now there are 4 of them, it makes sense to refactor `F16`, `F32`, `F64` and `F128` out of `Primitive` and into a separate `Float` type (like integers already are). This allows patterns like `F16 | F32 | F64 | F128` to be simplified into `Float(_)`, and is consistent with `ty::FloatTy`.

As a side effect, this PR also makes the `Ty::primitive_size` method work with `f16` and `f128`.

Tracking issue: #116909

`@rustbot` label +F-f16_and_f128
This commit is contained in:
Matthias Krüger 2024-05-10 16:10:46 +02:00 committed by GitHub
commit 1ae0d90b72
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
23 changed files with 156 additions and 96 deletions

View file

@ -59,7 +59,7 @@ where
_ => return Err(CannotUseFpConv),
}
}
abi::F16 | abi::F32 | abi::F64 | abi::F128 => {
abi::Float(_) => {
if arg_layout.size.bits() > flen {
return Err(CannotUseFpConv);
}

View file

@ -26,8 +26,8 @@ where
{
match ret.layout.field(cx, i).abi {
abi::Abi::Scalar(scalar) => match scalar.primitive() {
abi::F32 => Some(Reg::f32()),
abi::F64 => Some(Reg::f64()),
abi::Float(abi::F32) => Some(Reg::f32()),
abi::Float(abi::F64) => Some(Reg::f64()),
_ => None,
},
_ => None,
@ -110,7 +110,7 @@ where
// We only care about aligned doubles
if let abi::Abi::Scalar(scalar) = field.abi {
if let abi::F64 = scalar.primitive() {
if scalar.primitive() == abi::Float(abi::F64) {
if offset.is_aligned(dl.f64_align.abi) {
// Insert enough integers to cover [last_offset, offset)
assert!(last_offset.is_aligned(dl.f64_align.abi));

View file

@ -443,7 +443,7 @@ impl<'a, Ty> TyAndLayout<'a, Ty> {
Abi::Scalar(scalar) => {
let kind = match scalar.primitive() {
abi::Int(..) | abi::Pointer(_) => RegKind::Integer,
abi::F16 | abi::F32 | abi::F64 | abi::F128 => RegKind::Float,
abi::Float(_) => RegKind::Float,
};
Ok(HomogeneousAggregate::Homogeneous(Reg { kind, size: self.size }))
}

View file

@ -65,7 +65,7 @@ where
_ => return Err(CannotUseFpConv),
}
}
abi::F16 | abi::F32 | abi::F64 | abi::F128 => {
abi::Float(_) => {
if arg_layout.size.bits() > flen {
return Err(CannotUseFpConv);
}

View file

@ -20,7 +20,7 @@ where
{
let dl = cx.data_layout();
if !matches!(scalar.primitive(), abi::F32 | abi::F64) {
if !matches!(scalar.primitive(), abi::Float(abi::F32 | abi::F64)) {
return data;
}
@ -56,7 +56,7 @@ where
return data;
}
if scalar.primitive() == abi::F32 {
if scalar.primitive() == abi::Float(abi::F32) {
data.arg_attribute = ArgAttribute::InReg;
data.prefix[data.prefix_index] = Some(Reg::f32());
data.last_offset = offset + Reg::f32().size;
@ -80,14 +80,14 @@ where
{
data = arg_scalar(cx, scalar1, offset, data);
match (scalar1.primitive(), scalar2.primitive()) {
(abi::F32, _) => offset += Reg::f32().size,
(_, abi::F64) => offset += Reg::f64().size,
(abi::Float(abi::F32), _) => offset += Reg::f32().size,
(_, abi::Float(abi::F64)) => offset += Reg::f64().size,
(abi::Int(i, _signed), _) => offset += i.size(),
(abi::Pointer(_), _) => offset += Reg::i64().size,
_ => {}
}
if (offset.bytes() % 4) != 0 && matches!(scalar2.primitive(), abi::F32 | abi::F64) {
if (offset.bytes() % 4) != 0 && matches!(scalar2.primitive(), abi::Float(abi::F32 | abi::F64)) {
offset += Size::from_bytes(4 - (offset.bytes() % 4));
}
data = arg_scalar(cx, scalar2, offset, data);

View file

@ -51,7 +51,7 @@ where
Abi::Scalar(scalar) => match scalar.primitive() {
abi::Int(..) | abi::Pointer(_) => Class::Int,
abi::F16 | abi::F32 | abi::F64 | abi::F128 => Class::Sse,
abi::Float(_) => Class::Sse,
},
Abi::Vector { .. } => Class::Sse,

View file

@ -1,4 +1,5 @@
use rustc_data_structures::intern::Interned;
pub use Float::*;
pub use Integer::*;
pub use Primitive::*;
@ -11,7 +12,8 @@ use rustc_macros::HashStable_Generic;
pub mod call;
pub use rustc_abi::*;
// Explicitly import `Float` to avoid ambiguity with `Primitive::Float`.
pub use rustc_abi::{Float, *};
impl ToJson for Endian {
fn to_json(&self) -> Json {
@ -207,7 +209,7 @@ impl<'a, Ty> TyAndLayout<'a, Ty> {
C: HasDataLayout,
{
match self.abi {
Abi::Scalar(scalar) => matches!(scalar.primitive(), F32 | F64),
Abi::Scalar(scalar) => matches!(scalar.primitive(), Float(F32 | F64)),
Abi::Aggregate { .. } => {
if self.fields.count() == 1 && self.fields.offset(0).bytes() == 0 {
self.field(cx, 0).is_single_fp_element(cx)