pub enum Float {
F16,
F32,
F64,
F80,
F128,
D32,
D64,
D128,
}Expand description
A floating point format, named by its width in bits.
The names are the widths because that is what the textual form uses, and a reader who sees
f80 should not have to know that it occupies sixteen bytes on the stack. That is a layout
question and it belongs to the target, not to the type.
Variants§
F16
IEEE binary16, which is _Float16 and __fp16.
F32
IEEE binary32, which is float everywhere we care about.
F64
IEEE binary64, which is double.
F80
The x87 80-bit extended format, which is long double on x86 SysV.
F128
IEEE binary128, which is _Float128, and long double on AArch64 Linux.
D32
IEEE decimal32 in the binary integer encoding, which is _Decimal32.
D64
IEEE decimal64 in the binary integer encoding, which is _Decimal64.
D128
IEEE decimal128 in the binary integer encoding, which is _Decimal128.
Implementations§
Source§impl Float
impl Float
Sourcepub const fn bits(self) -> u32
pub const fn bits(self) -> u32
The width of the format in bits.
This is the width of the format and not the size of the object. F80 is eighty bits of
format in a ten, twelve or sixteen byte object depending on the target.
Sourcepub const fn is_decimal(self) -> bool
pub const fn is_decimal(self) -> bool
Whether this is one of the three decimal formats.
A decimal shares its width with a binary format, and it travels in the same registers as the binary format of that width does, which is why most of the back end never has to ask. What must ask is anything that computes with the value or reads its bits as a number, because the same sixty four bits are a different number in the two encodings.
Sourcepub const fn from_bits(bits: u32) -> Option<Self>
pub const fn from_bits(bits: u32) -> Option<Self>
The binary format of that width, if there is one.
Never a decimal one, because a width alone does not say decimal, and a caller that has a width and wants a type has a binary type in mind.
Sourcepub const fn encoding(self) -> Format
pub const fn encoding(self) -> Format
The encoding this is, as rucc_base::float spells it.
The inverse of the map rucc-lower keeps in the other direction, and total where that one
is not. Every format the IR has a type for is an IEEE encoding, so the two that map to
nothing there, the brain float and the double-double, are not among these and there is no
case here to return nothing for.
It is on the type rather than in the crate that wants it because which encoding an f80 is
is a fact about f80 and not about whoever is asking. Anything that has to interpret the
bits of an fconst needs it, and a copy of the table in each of them is a table that can
disagree with itself.
use rucc_base::float::Format;
use rucc_ir::Float;
assert_eq!(Float::F64.encoding(), Format::Double);
assert_eq!(Float::F80.encoding(), Format::X87Extended);