| 1477 | } |
| 1478 | |
| 1479 | std::vector<uint32_t> IntToWords(uint64_t value, uint32_t width, |
| 1480 | bool is_signed) { |
| 1481 | assert(width <= 64 && "The bit width should not be more than 64 bits"); |
| 1482 | |
| 1483 | // Sign-extend or zero-extend the last |width| bits of |value|, depending on |
| 1484 | // |is_signed|. |
| 1485 | if (is_signed) { |
| 1486 | // Sign-extend by shifting left and then shifting right, interpreting the |
| 1487 | // integer as signed. |
| 1488 | value = static_cast<int64_t>(value << (64 - width)) >> (64 - width); |
| 1489 | } else { |
| 1490 | // Zero-extend by shifting left and then shifting right, interpreting the |
| 1491 | // integer as unsigned. |
| 1492 | value = (value << (64 - width)) >> (64 - width); |
| 1493 | } |
| 1494 | |
| 1495 | std::vector<uint32_t> result; |
| 1496 | result.push_back(static_cast<uint32_t>(value)); |
| 1497 | if (width > 32) { |
| 1498 | result.push_back(static_cast<uint32_t>(value >> 32)); |
| 1499 | } |
| 1500 | return result; |
| 1501 | } |
| 1502 | |
| 1503 | bool TypesAreEqualUpToSign(opt::IRContext* ir_context, uint32_t type1_id, |
| 1504 | uint32_t type2_id) { |