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

Function NegateVectorConstant

source/opt/folding_rules.cpp:288–312  ·  view source on GitHub ↗

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

Source from the content-addressed store, hash-verified

286
287// Negates the vector constant |c|. Returns the id of the defining instruction.
288uint32_t NegateVectorConstant(analysis::ConstantManager* const_mgr,
289 const analysis::Constant* c) {
290 assert(const_mgr && c);
291 assert(c->type()->AsVector());
292 if (c->AsNullConstant()) {
293 // 0.0 vs -0.0 shouldn't matter.
294 return const_mgr->GetDefiningInstruction(c)->result_id();
295 } else {
296 const analysis::Type* component_type =
297 c->AsVectorConstant()->component_type();
298 std::vector<uint32_t> words;
299 for (auto& comp : c->AsVectorConstant()->GetComponents()) {
300 if (component_type->AsFloat()) {
301 words.push_back(NegateFloatingPointConstant(const_mgr, comp));
302 } else {
303 assert(component_type->AsInteger());
304 words.push_back(NegateIntegerConstant(const_mgr, comp));
305 }
306 }
307
308 const analysis::Constant* negated_const =
309 const_mgr->GetConstant(c->type(), std::move(words));
310 return const_mgr->GetDefiningInstruction(negated_const)->result_id();
311 }
312}
313
314// Negates |c|. Returns the id of the defining instruction.
315uint32_t NegateConstant(analysis::ConstantManager* const_mgr,

Callers 1

NegateConstantFunction · 0.85

Calls 13

NegateIntegerConstantFunction · 0.85
AsVectorMethod · 0.80
AsFloatMethod · 0.80
AsIntegerMethod · 0.80
typeMethod · 0.45
AsNullConstantMethod · 0.45
result_idMethod · 0.45
component_typeMethod · 0.45
AsVectorConstantMethod · 0.45
push_backMethod · 0.45

Tested by

no test coverage detected