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

Function FoldFToIOp

source/opt/const_folding_rules.cpp:867–893  ·  view source on GitHub ↗

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

Source from the content-addressed store, hash-verified

865// integer conversion.
866// TODO(greg-lunarg): Support for 64-bit integer types.
867UnaryScalarFoldingRule FoldFToIOp() {
868 return [](const analysis::Type* result_type, const analysis::Constant* a,
869 analysis::ConstantManager* const_mgr) -> const analysis::Constant* {
870 assert(result_type != nullptr && a != nullptr);
871 const analysis::Integer* integer_type = result_type->AsInteger();
872 const analysis::Float* float_type = a->type()->AsFloat();
873 assert(float_type != nullptr);
874 assert(integer_type != nullptr);
875 if (integer_type->width() != 32) return nullptr;
876 if (float_type->width() == 32) {
877 float fa = a->GetFloat();
878 uint32_t result = integer_type->IsSigned()
879 ? static_cast<uint32_t>(static_cast<int32_t>(fa))
880 : static_cast<uint32_t>(fa);
881 std::vector<uint32_t> words = {result};
882 return const_mgr->GetConstant(result_type, words);
883 } else if (float_type->width() == 64) {
884 double fa = a->GetDouble();
885 uint32_t result = integer_type->IsSigned()
886 ? static_cast<uint32_t>(static_cast<int32_t>(fa))
887 : static_cast<uint32_t>(fa);
888 std::vector<uint32_t> words = {result};
889 return const_mgr->GetConstant(result_type, words);
890 }
891 return nullptr;
892 };
893}
894
895// This function defines a |UnaryScalarFoldingRule| that performs integer to
896// float conversion.

Callers 1

FoldFToIFunction · 0.85

Calls 8

AsIntegerMethod · 0.80
AsFloatMethod · 0.80
GetFloatMethod · 0.80
IsSignedMethod · 0.80
GetDoubleMethod · 0.80
typeMethod · 0.45
widthMethod · 0.45
GetConstantMethod · 0.45

Tested by

no test coverage detected