diff options
| author | Trevor Gross <tmgross@umich.edu> | 2024-03-02 21:40:18 -0500 |
|---|---|---|
| committer | Trevor Gross <tmgross@umich.edu> | 2024-03-14 00:40:22 -0500 |
| commit | 80bb15ed91d728e39acc2dcb5a3ed5db59862687 (patch) | |
| tree | bda179f4fe65e7d51eaac139d4caab052a4ccf0e /compiler/rustc_middle/src/mir/interpret | |
| parent | 5ac0b2d0219de2fd6fef86c69ef0cfa1e6c36f3b (diff) | |
| download | rust-80bb15ed91d728e39acc2dcb5a3ed5db59862687.tar.gz rust-80bb15ed91d728e39acc2dcb5a3ed5db59862687.zip | |
Add compiler support for parsing `f16` and `f128`
Diffstat (limited to 'compiler/rustc_middle/src/mir/interpret')
| -rw-r--r-- | compiler/rustc_middle/src/mir/interpret/value.rs | 22 |
1 files changed, 21 insertions, 1 deletions
diff --git a/compiler/rustc_middle/src/mir/interpret/value.rs b/compiler/rustc_middle/src/mir/interpret/value.rs index e937c17c8ac..24d4a79c7d7 100644 --- a/compiler/rustc_middle/src/mir/interpret/value.rs +++ b/compiler/rustc_middle/src/mir/interpret/value.rs @@ -3,7 +3,7 @@ use std::fmt; use either::{Either, Left, Right}; use rustc_apfloat::{ - ieee::{Double, Single}, + ieee::{Double, Half, Quad, Single}, Float, }; use rustc_macros::HashStable; @@ -202,6 +202,11 @@ impl<Prov> Scalar<Prov> { } #[inline] + pub fn from_f16(f: Half) -> Self { + Scalar::Int(f.into()) + } + + #[inline] pub fn from_f32(f: Single) -> Self { Scalar::Int(f.into()) } @@ -211,6 +216,11 @@ impl<Prov> Scalar<Prov> { Scalar::Int(f.into()) } + #[inline] + pub fn from_f128(f: Quad) -> Self { + Scalar::Int(f.into()) + } + /// This is almost certainly not the method you want! You should dispatch on the type /// and use `to_{u8,u16,...}`/`scalar_to_ptr` to perform ptr-to-int / int-to-ptr casts as needed. /// @@ -423,6 +433,11 @@ impl<'tcx, Prov: Provenance> Scalar<Prov> { } #[inline] + pub fn to_f16(self) -> InterpResult<'tcx, Half> { + self.to_float() + } + + #[inline] pub fn to_f32(self) -> InterpResult<'tcx, Single> { self.to_float() } @@ -431,4 +446,9 @@ impl<'tcx, Prov: Provenance> Scalar<Prov> { pub fn to_f64(self) -> InterpResult<'tcx, Double> { self.to_float() } + + #[inline] + pub fn to_f128(self) -> InterpResult<'tcx, Quad> { + self.to_float() + } } |
