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

Function FoldIToFOp

source/opt/const_folding_rules.cpp:898–925  ·  view source on GitHub ↗

This function defines a |UnaryScalarFoldingRule| that performs integer to float conversion. TODO(greg-lunarg): Support for 64-bit integer types.

Source from the content-addressed store, hash-verified

896// float conversion.
897// TODO(greg-lunarg): Support for 64-bit integer types.
898UnaryScalarFoldingRule FoldIToFOp() {
899 return [](const analysis::Type* result_type, const analysis::Constant* a,
900 analysis::ConstantManager* const_mgr) -> const analysis::Constant* {
901 assert(result_type != nullptr && a != nullptr);
902 const analysis::Integer* integer_type = a->type()->AsInteger();
903 const analysis::Float* float_type = result_type->AsFloat();
904 assert(float_type != nullptr);
905 assert(integer_type != nullptr);
906 if (integer_type->width() != 32) return nullptr;
907 uint32_t ua = a->GetU32();
908 if (float_type->width() == 32) {
909 float result_val = integer_type->IsSigned()
910 ? static_cast<float>(static_cast<int32_t>(ua))
911 : static_cast<float>(ua);
912 utils::FloatProxy<float> result(result_val);
913 std::vector<uint32_t> words = {result.data()};
914 return const_mgr->GetConstant(result_type, words);
915 } else if (float_type->width() == 64) {
916 double result_val = integer_type->IsSigned()
917 ? static_cast<double>(static_cast<int32_t>(ua))
918 : static_cast<double>(ua);
919 utils::FloatProxy<double> result(result_val);
920 std::vector<uint32_t> words = result.GetWords();
921 return const_mgr->GetConstant(result_type, words);
922 }
923 return nullptr;
924 };
925}
926
927// This defines a |UnaryScalarFoldingRule| that performs |OpQuantizeToF16|.
928UnaryScalarFoldingRule FoldQuantizeToF16Scalar() {

Callers 1

FoldIToFFunction · 0.85

Calls 9

AsIntegerMethod · 0.80
AsFloatMethod · 0.80
GetU32Method · 0.80
IsSignedMethod · 0.80
GetWordsMethod · 0.80
typeMethod · 0.45
widthMethod · 0.45
dataMethod · 0.45
GetConstantMethod · 0.45

Tested by

no test coverage detected