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

Function NegateFloatingPointConstant

source/opt/folding_rules.cpp:247–265  ·  view source on GitHub ↗

Returns the negation of |c|. |c| must be a 32 or 64 bit floating point constant.

Source from the content-addressed store, hash-verified

245// Returns the negation of |c|. |c| must be a 32 or 64 bit floating point
246// constant.
247uint32_t NegateFloatingPointConstant(analysis::ConstantManager* const_mgr,
248 const analysis::Constant* c) {
249 assert(c);
250 assert(c->type()->AsFloat());
251 uint32_t width = c->type()->AsFloat()->width();
252 assert(width == 32 || width == 64);
253 std::vector<uint32_t> words;
254 if (width == 64) {
255 utils::FloatProxy<double> result(c->GetDouble() * -1.0);
256 words = result.GetWords();
257 } else {
258 utils::FloatProxy<float> result(c->GetFloat() * -1.0f);
259 words = result.GetWords();
260 }
261
262 const analysis::Constant* negated_const =
263 const_mgr->GetConstant(c->type(), std::move(words));
264 return const_mgr->GetDefiningInstruction(negated_const)->result_id();
265}
266
267// Negates the integer constant |c|. Returns the id of the defining instruction.
268uint32_t NegateIntegerConstant(analysis::ConstantManager* const_mgr,

Callers 2

NegateVectorConstantFunction · 0.85
NegateConstantFunction · 0.85

Calls 9

AsFloatMethod · 0.80
GetDoubleMethod · 0.80
GetWordsMethod · 0.80
GetFloatMethod · 0.80
typeMethod · 0.45
widthMethod · 0.45
GetConstantMethod · 0.45
result_idMethod · 0.45

Tested by

no test coverage detected