This function defines a |UnaryScalarFoldingRule| that performs integer to float conversion. TODO(greg-lunarg): Support for 64-bit integer types.
| 896 | // float conversion. |
| 897 | // TODO(greg-lunarg): Support for 64-bit integer types. |
| 898 | UnaryScalarFoldingRule 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|. |
| 928 | UnaryScalarFoldingRule FoldQuantizeToF16Scalar() { |