MCPcopy Create free account
hub / github.com/bytecodealliance/wasmtime / icmp

Function icmp

cranelift/interpreter/src/step.rs:1397–1445  ·  view source on GitHub ↗

Compare two values using the given integer condition `code`.

(
    ctrl_ty: types::Type,
    code: IntCC,
    left: &DataValue,
    right: &DataValue,
)

Source from the content-addressed store, hash-verified

1395
1396/// Compare two values using the given integer condition `code`.
1397fn icmp(
1398 ctrl_ty: types::Type,
1399 code: IntCC,
1400 left: &DataValue,
1401 right: &DataValue,
1402) -> ValueResult<DataValue> {
1403 let cmp = |bool_ty: types::Type,
1404 code: IntCC,
1405 left: &DataValue,
1406 right: &DataValue|
1407 -> ValueResult<DataValue> {
1408 Ok(DataValueExt::bool(
1409 match code {
1410 IntCC::Equal => left == right,
1411 IntCC::NotEqual => left != right,
1412 IntCC::SignedGreaterThan => left > right,
1413 IntCC::SignedGreaterThanOrEqual => left >= right,
1414 IntCC::SignedLessThan => left < right,
1415 IntCC::SignedLessThanOrEqual => left <= right,
1416 IntCC::UnsignedGreaterThan => {
1417 left.clone().into_int_unsigned()? > right.clone().into_int_unsigned()?
1418 }
1419 IntCC::UnsignedGreaterThanOrEqual => {
1420 left.clone().into_int_unsigned()? >= right.clone().into_int_unsigned()?
1421 }
1422 IntCC::UnsignedLessThan => {
1423 left.clone().into_int_unsigned()? < right.clone().into_int_unsigned()?
1424 }
1425 IntCC::UnsignedLessThanOrEqual => {
1426 left.clone().into_int_unsigned()? <= right.clone().into_int_unsigned()?
1427 }
1428 },
1429 ctrl_ty.is_vector(),
1430 bool_ty,
1431 )?)
1432 };
1433
1434 let dst_ty = ctrl_ty.as_truthy();
1435 let left = extractlanes(left, ctrl_ty)?;
1436 let right = extractlanes(right, ctrl_ty)?;
1437
1438 let res = left
1439 .into_iter()
1440 .zip(right)
1441 .map(|(l, r)| cmp(dst_ty.lane_type(), code, &l, &r))
1442 .collect::<ValueResult<SimdVec<DataValue>>>()?;
1443
1444 Ok(vectorizelanes(&res, dst_ty)?)
1445}
1446
1447/// Compare two values using the given floating point condition `code`.
1448fn fcmp(code: FloatCC, left: &DataValue, right: &DataValue) -> ValueResult<bool> {

Callers 1

stepFunction · 0.85

Calls 10

OkFunction · 0.85
extractlanesFunction · 0.85
vectorizelanesFunction · 0.85
into_int_unsignedMethod · 0.80
cloneMethod · 0.45
is_vectorMethod · 0.45
as_truthyMethod · 0.45
mapMethod · 0.45
into_iterMethod · 0.45
lane_typeMethod · 0.45

Tested by

no test coverage detected