Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/KhronosGroup/SPIRV-Tools.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
Diffstat (limited to 'source/opt/folding_rules.cpp')
-rw-r--r--source/opt/folding_rules.cpp13
1 files changed, 8 insertions, 5 deletions
diff --git a/source/opt/folding_rules.cpp b/source/opt/folding_rules.cpp
index 3f10bd009..3d803addc 100644
--- a/source/opt/folding_rules.cpp
+++ b/source/opt/folding_rules.cpp
@@ -136,25 +136,28 @@ std::vector<uint32_t> GetWordsFromScalarIntConstant(
const analysis::IntConstant* c) {
assert(c != nullptr);
uint32_t width = c->type()->AsInteger()->width();
- assert(width == 32 || width == 64);
+ assert(width == 8 || width == 16 || width == 32 || width == 64);
if (width == 64) {
uint64_t uval = static_cast<uint64_t>(c->GetU64());
return ExtractInts(uval);
}
- return {c->GetU32()};
+ // Section 2.2.1 of the SPIR-V spec guarantees that all integer types
+ // smaller than 32-bits are automatically zero or sign extended to 32-bits.
+ return {c->GetU32BitValue()};
}
std::vector<uint32_t> GetWordsFromScalarFloatConstant(
const analysis::FloatConstant* c) {
assert(c != nullptr);
uint32_t width = c->type()->AsFloat()->width();
- assert(width == 32 || width == 64);
+ assert(width == 16 || width == 32 || width == 64);
if (width == 64) {
utils::FloatProxy<double> result(c->GetDouble());
return result.GetWords();
}
- utils::FloatProxy<float> result(c->GetFloat());
- return result.GetWords();
+ // Section 2.2.1 of the SPIR-V spec guarantees that all floating-point types
+ // smaller than 32-bits are automatically zero extended to 32-bits.
+ return {c->GetU32BitValue()};
}
std::vector<uint32_t> GetWordsFromNumericScalarOrVectorConstant(