(self, kind: ValueConversionKind)
| 390 | } |
| 391 | |
| 392 | fn convert(self, kind: ValueConversionKind) -> ValueResult<Self> { |
| 393 | Ok(match kind { |
| 394 | ValueConversionKind::Exact(ty) => match (self, ty) { |
| 395 | // TODO a lot to do here: from bmask to ireduce to bitcast... |
| 396 | (val, ty) if val.ty().is_int() && ty.is_int() => { |
| 397 | DataValue::from_integer(val.into_int_signed()?, ty)? |
| 398 | } |
| 399 | (DataValue::I16(n), types::F16) => DataValue::F16(Ieee16::with_bits(n as u16)), |
| 400 | (DataValue::I32(n), types::F32) => DataValue::F32(f32::from_bits(n as u32).into()), |
| 401 | (DataValue::I64(n), types::F64) => DataValue::F64(f64::from_bits(n as u64).into()), |
| 402 | (DataValue::I128(n), types::F128) => DataValue::F128(Ieee128::with_bits(n as u128)), |
| 403 | (DataValue::F16(n), types::I16) => DataValue::I16(n.bits() as i16), |
| 404 | (DataValue::F32(n), types::I32) => DataValue::I32(n.bits() as i32), |
| 405 | (DataValue::F64(n), types::I64) => DataValue::I64(n.bits() as i64), |
| 406 | (DataValue::F128(n), types::I128) => DataValue::I128(n.bits() as i128), |
| 407 | (DataValue::F32(n), types::F64) => DataValue::F64((n.as_f32() as f64).into()), |
| 408 | (dv, t) if (t.is_int() || t.is_float()) && dv.ty() == t => dv, |
| 409 | (dv, _) => unimplemented!("conversion: {} -> {:?}", dv.ty(), kind), |
| 410 | }, |
| 411 | ValueConversionKind::Truncate(ty) => { |
| 412 | assert!( |
| 413 | ty.is_int(), |
| 414 | "unimplemented conversion: {} -> {:?}", |
| 415 | self.ty(), |
| 416 | kind |
| 417 | ); |
| 418 | |
| 419 | let mask = (1 << (ty.bytes() * 8)) - 1i128; |
| 420 | let truncated = self.into_int_signed()? & mask; |
| 421 | Self::from_integer(truncated, ty)? |
| 422 | } |
| 423 | ValueConversionKind::ExtractUpper(ty) => { |
| 424 | assert!( |
| 425 | ty.is_int(), |
| 426 | "unimplemented conversion: {} -> {:?}", |
| 427 | self.ty(), |
| 428 | kind |
| 429 | ); |
| 430 | |
| 431 | let shift_amt = (self.ty().bytes() * 8) - (ty.bytes() * 8); |
| 432 | let mask = (1 << (ty.bytes() * 8)) - 1i128; |
| 433 | let shifted_mask = mask << shift_amt; |
| 434 | |
| 435 | let extracted = (self.into_int_signed()? & shifted_mask) >> shift_amt; |
| 436 | Self::from_integer(extracted, ty)? |
| 437 | } |
| 438 | ValueConversionKind::SignExtend(ty) => match (self, ty) { |
| 439 | (DataValue::I8(n), types::I16) => DataValue::I16(n as i16), |
| 440 | (DataValue::I8(n), types::I32) => DataValue::I32(n as i32), |
| 441 | (DataValue::I8(n), types::I64) => DataValue::I64(n as i64), |
| 442 | (DataValue::I8(n), types::I128) => DataValue::I128(n as i128), |
| 443 | (DataValue::I16(n), types::I32) => DataValue::I32(n as i32), |
| 444 | (DataValue::I16(n), types::I64) => DataValue::I64(n as i64), |
| 445 | (DataValue::I16(n), types::I128) => DataValue::I128(n as i128), |
| 446 | (DataValue::I32(n), types::I64) => DataValue::I64(n as i64), |
| 447 | (DataValue::I32(n), types::I128) => DataValue::I128(n as i128), |
| 448 | (DataValue::I64(n), types::I128) => DataValue::I128(n as i128), |
| 449 | (dv, _) => unimplemented!("conversion: {} -> {:?}", dv.ty(), kind), |
no test coverage detected