Skip to content

Commit 9b26895

Browse files
committed
Generalise SIMD casting to unequal bitwidths.
1 parent 4fe138c commit 9b26895

File tree

1 file changed

+87
-10
lines changed

1 file changed

+87
-10
lines changed

src/librustc_trans/trans/intrinsic.rs

Lines changed: 87 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1457,13 +1457,73 @@ fn generic_simd_intrinsic<'blk, 'tcx>(bcx: Block<'blk, 'tcx>,
14571457
if in_ == out { return llargs[0]; }
14581458

14591459
match (&in_.sty, &out.sty) {
1460+
(&ty::TyInt(lhs), &ty::TyInt(rhs)) => {
1461+
match (lhs, rhs) {
1462+
(ast::TyI8, ast::TyI8) |
1463+
(ast::TyI16, ast::TyI16) |
1464+
(ast::TyI32, ast::TyI32) |
1465+
(ast::TyI64, ast::TyI64) => return llargs[0],
1466+
1467+
(ast::TyI8, ast::TyI16) |
1468+
(ast::TyI8, ast::TyI32) |
1469+
(ast::TyI8, ast::TyI64) |
1470+
(ast::TyI16, ast::TyI32) |
1471+
(ast::TyI16, ast::TyI64) |
1472+
(ast::TyI32, ast::TyI64) => return SExt(bcx, llargs[0], llret_ty),
1473+
1474+
(ast::TyI16, ast::TyI8) |
1475+
(ast::TyI32, ast::TyI8) |
1476+
(ast::TyI32, ast::TyI16) |
1477+
(ast::TyI64, ast::TyI8) |
1478+
(ast::TyI64, ast::TyI16) |
1479+
(ast::TyI64, ast::TyI32) => return Trunc(bcx, llargs[0], llret_ty),
1480+
_ => {}
1481+
}
1482+
}
1483+
(&ty::TyUint(lhs), &ty::TyUint(rhs)) => {
1484+
match (lhs, rhs) {
1485+
(ast::TyU8, ast::TyU8) |
1486+
(ast::TyU16, ast::TyU16) |
1487+
(ast::TyU32, ast::TyU32) |
1488+
(ast::TyU64, ast::TyU64) => return llargs[0],
1489+
1490+
(ast::TyU8, ast::TyU16) |
1491+
(ast::TyU8, ast::TyU32) |
1492+
(ast::TyU8, ast::TyU64) |
1493+
(ast::TyU16, ast::TyU32) |
1494+
(ast::TyU16, ast::TyU64) |
1495+
(ast::TyU32, ast::TyU64) => return ZExt(bcx, llargs[0], llret_ty),
1496+
1497+
(ast::TyU16, ast::TyU8) |
1498+
(ast::TyU32, ast::TyU8) |
1499+
(ast::TyU32, ast::TyU16) |
1500+
(ast::TyU64, ast::TyU8) |
1501+
(ast::TyU64, ast::TyU16) |
1502+
(ast::TyU64, ast::TyU32) => return Trunc(bcx, llargs[0], llret_ty),
1503+
_ => {}
1504+
}
1505+
}
14601506
(&ty::TyInt(lhs), &ty::TyUint(rhs)) => {
14611507
match (lhs, rhs) {
14621508
(ast::TyI8, ast::TyU8) |
14631509
(ast::TyI16, ast::TyU16) |
14641510
(ast::TyI32, ast::TyU32) |
14651511
(ast::TyI64, ast::TyU64) => return llargs[0],
1466-
_ => {},
1512+
1513+
(ast::TyI8, ast::TyU16) |
1514+
(ast::TyI8, ast::TyU32) |
1515+
(ast::TyI8, ast::TyU64) |
1516+
(ast::TyI16, ast::TyU32) |
1517+
(ast::TyI16, ast::TyU64) |
1518+
(ast::TyI32, ast::TyU64) => return SExt(bcx, llargs[0], llret_ty),
1519+
1520+
(ast::TyI16, ast::TyU8) |
1521+
(ast::TyI32, ast::TyU8) |
1522+
(ast::TyI32, ast::TyU16) |
1523+
(ast::TyI64, ast::TyU8) |
1524+
(ast::TyI64, ast::TyU16) |
1525+
(ast::TyI64, ast::TyU32) => return Trunc(bcx, llargs[0], llret_ty),
1526+
_ => {}
14671527
}
14681528
}
14691529
(&ty::TyUint(lhs), &ty::TyInt(rhs)) => {
@@ -1472,26 +1532,43 @@ fn generic_simd_intrinsic<'blk, 'tcx>(bcx: Block<'blk, 'tcx>,
14721532
(ast::TyU16, ast::TyI16) |
14731533
(ast::TyU32, ast::TyI32) |
14741534
(ast::TyU64, ast::TyI64) => return llargs[0],
1475-
_ => {},
1535+
1536+
(ast::TyU8, ast::TyI16) |
1537+
(ast::TyU8, ast::TyI32) |
1538+
(ast::TyU8, ast::TyI64) |
1539+
(ast::TyU16, ast::TyI32) |
1540+
(ast::TyU16, ast::TyI64) |
1541+
(ast::TyU32, ast::TyI64) => return ZExt(bcx, llargs[0], llret_ty),
1542+
1543+
(ast::TyU16, ast::TyI8) |
1544+
(ast::TyU32, ast::TyI8) |
1545+
(ast::TyU32, ast::TyI16) |
1546+
(ast::TyU64, ast::TyI8) |
1547+
(ast::TyU64, ast::TyI16) |
1548+
(ast::TyU64, ast::TyI32) => return Trunc(bcx, llargs[0], llret_ty),
1549+
_ => {}
14761550
}
14771551
}
1478-
(&ty::TyInt(ast::TyI32), &ty::TyFloat(ast::TyF32)) |
1479-
(&ty::TyInt(ast::TyI64), &ty::TyFloat(ast::TyF64)) => {
1552+
1553+
(&ty::TyInt(_), &ty::TyFloat(_)) => {
14801554
return SIToFP(bcx, llargs[0], llret_ty)
14811555
}
1482-
(&ty::TyUint(ast::TyU32), &ty::TyFloat(ast::TyF32)) |
1483-
(&ty::TyUint(ast::TyU64), &ty::TyFloat(ast::TyF64)) => {
1556+
(&ty::TyUint(_), &ty::TyFloat(_)) => {
14841557
return UIToFP(bcx, llargs[0], llret_ty)
14851558
}
14861559

1487-
(&ty::TyFloat(ast::TyF32), &ty::TyInt(ast::TyI32)) |
1488-
(&ty::TyFloat(ast::TyF64), &ty::TyInt(ast::TyI64)) => {
1560+
(&ty::TyFloat(_), &ty::TyInt(_)) => {
14891561
return FPToSI(bcx, llargs[0], llret_ty)
14901562
}
1491-
(&ty::TyFloat(ast::TyF32), &ty::TyUint(ast::TyU32)) |
1492-
(&ty::TyFloat(ast::TyF64), &ty::TyUint(ast::TyU64)) => {
1563+
(&ty::TyFloat(_), &ty::TyUint(_)) => {
14931564
return FPToUI(bcx, llargs[0], llret_ty)
14941565
}
1566+
(&ty::TyFloat(ast::TyF32), &ty::TyFloat(ast::TyF64)) => {
1567+
return FPExt(bcx, llargs[0], llret_ty)
1568+
}
1569+
(&ty::TyFloat(ast::TyF64), &ty::TyFloat(ast::TyF32)) => {
1570+
return FPTrunc(bcx, llargs[0], llret_ty)
1571+
}
14951572
_ => {}
14961573
}
14971574
require!(false, "SIMD cast intrinsic monomorphised with incompatible cast");

0 commit comments

Comments
 (0)