Skip to content

Commit

Permalink
chore: const eval
Browse files Browse the repository at this point in the history
  • Loading branch information
FL33TW00D committed Jun 14, 2024
1 parent 733fd15 commit 9c6a9b3
Showing 1 changed file with 18 additions and 8 deletions.
26 changes: 18 additions & 8 deletions naga/src/proc/constant_evaluator.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1536,19 +1536,16 @@ impl<'a> ConstantEvaluator<'a> {
Literal::AbstractFloat(v) => u64::try_from_abstract(v)?,
}),
Sc::F16 => Literal::F16(match literal {
//TODO: remove unwraps
Literal::F16(v) => v,
Literal::F32(v) => f16::from_f32(v),
Literal::F64(v) => f16::from_f64(v),
Literal::Bool(v) => f16::from_u32(v as u32).unwrap(),
Literal::I64(_)
| Literal::U64(_)
| Literal::U32(_)
| Literal::I32(_)
| Literal::AbstractInt(_) => {
return make_error();
}
Literal::I64(v) => f16::from_i64(v).unwrap(),
Literal::U64(v) => f16::from_u64(v).unwrap(),
Literal::I32(v) => f16::from_i32(v).unwrap(),
Literal::U32(v) => f16::from_u32(v).unwrap(),
Literal::AbstractFloat(v) => f16::try_from_abstract(v)?,
Literal::AbstractInt(v) => f16::try_from_abstract(v)?,
}),
Sc::F32 => Literal::F32(match literal {
Literal::I32(v) => v as f32,
Expand Down Expand Up @@ -2278,6 +2275,19 @@ impl TryFromAbstract<f64> for f16 {
}
}

impl TryFromAbstract<i64> for f16 {
fn try_from_abstract(value: i64) -> Result<f16, ConstantEvaluatorError> {
let f = f16::from_i64(value);
if f.is_none() {
return Err(ConstantEvaluatorError::AutomaticConversionLossy {
value: format!("{value:?}"),
to_type: "f16",
});
}
Ok(f.unwrap())
}
}

#[cfg(test)]
mod tests {
use std::vec;
Expand Down

0 comments on commit 9c6a9b3

Please sign in to comment.