Negates the integer constant |c|. Returns the id of the defining instruction.
| 266 | |
| 267 | // Negates the integer constant |c|. Returns the id of the defining instruction. |
| 268 | uint32_t NegateIntegerConstant(analysis::ConstantManager* const_mgr, |
| 269 | const analysis::Constant* c) { |
| 270 | assert(c); |
| 271 | assert(c->type()->AsInteger()); |
| 272 | uint32_t width = c->type()->AsInteger()->width(); |
| 273 | assert(width == 32 || width == 64); |
| 274 | std::vector<uint32_t> words; |
| 275 | if (width == 64) { |
| 276 | uint64_t uval = static_cast<uint64_t>(0 - c->GetU64()); |
| 277 | words = ExtractInts(uval); |
| 278 | } else { |
| 279 | words.push_back(static_cast<uint32_t>(0 - c->GetU32())); |
| 280 | } |
| 281 | |
| 282 | const analysis::Constant* negated_const = |
| 283 | const_mgr->GetConstant(c->type(), std::move(words)); |
| 284 | return const_mgr->GetDefiningInstruction(negated_const)->result_id(); |
| 285 | } |
| 286 | |
| 287 | // Negates the vector constant |c|. Returns the id of the defining instruction. |
| 288 | uint32_t NegateVectorConstant(analysis::ConstantManager* const_mgr, |
no test coverage detected