MCPcopy Create free account
hub / github.com/KhronosGroup/SPIRV-Tools / NegateIntegerConstant

Function NegateIntegerConstant

source/opt/folding_rules.cpp:268–285  ·  view source on GitHub ↗

Negates the integer constant |c|. Returns the id of the defining instruction.

Source from the content-addressed store, hash-verified

266
267// Negates the integer constant |c|. Returns the id of the defining instruction.
268uint32_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.
288uint32_t NegateVectorConstant(analysis::ConstantManager* const_mgr,

Callers 2

NegateVectorConstantFunction · 0.85
NegateConstantFunction · 0.85

Calls 10

ExtractIntsFunction · 0.85
AsIntegerMethod · 0.80
GetU64Method · 0.80
GetU32Method · 0.80
typeMethod · 0.45
widthMethod · 0.45
push_backMethod · 0.45
GetConstantMethod · 0.45
result_idMethod · 0.45

Tested by

no test coverage detected