Skip to content
Snippets Groups Projects
Unverified Commit f3fbd98f authored by Dave Airlie's avatar Dave Airlie Committed by GitHub
Browse files

opt/spec_constants: fix bit pattern width checks. (#4588)

* test: add a test to show 8/16-bit

* opt/spec_constants: fix bit pattern width checks.

The input bit patterns are always at least 32-bits, so let the test
pass for 8/16-bit values as well. This shouldn't have any effect on the
64-bit patterns I assume this was introduced for.
parent 0f3bc1d9
No related branches found
No related tags found
No related merge requests found
......@@ -98,11 +98,15 @@ std::vector<uint32_t> ParseDefaultValueBitPattern(
}
return result;
} else if (const auto* IT = type->AsInteger()) {
if (IT->width() == input_bit_pattern.size() * sizeof(uint32_t) * 8) {
auto width = IT->width();
if (width == 8 || width == 16) width = 32;
if (width == input_bit_pattern.size() * sizeof(uint32_t) * 8) {
return std::vector<uint32_t>(input_bit_pattern);
}
} else if (const auto* FT = type->AsFloat()) {
if (FT->width() == input_bit_pattern.size() * sizeof(uint32_t) * 8) {
auto width = FT->width();
if (width == 8 || width == 16) width = 32;
if (width == input_bit_pattern.size() * sizeof(uint32_t) * 8) {
return std::vector<uint32_t>(input_bit_pattern);
}
}
......
......@@ -935,6 +935,50 @@ INSTANTIATE_TEST_SUITE_P(
"%2 = OpSpecConstantTrue %bool\n"
"%3 = OpSpecConstantTrue %bool\n",
},
// 19. 16-bit int type.
{
// code
"OpDecorate %1 SpecId 100\n"
"OpDecorate %2 SpecId 101\n"
"OpDecorate %3 SpecId 102\n"
"%short = OpTypeInt 16 1\n"
"%1 = OpSpecConstant %short 10\n"
"%2 = OpSpecConstant %short 11\n"
"%3 = OpSpecConstant %short 11\n",
// default values
SpecIdToValueBitPatternMap{
{100, {32768}}, {101, {0xffff}}, {102, {0xffffffd6}}},
// expected
"OpDecorate %1 SpecId 100\n"
"OpDecorate %2 SpecId 101\n"
"OpDecorate %3 SpecId 102\n"
"%short = OpTypeInt 16 1\n"
"%1 = OpSpecConstant %short 32768\n"
"%2 = OpSpecConstant %short 65535\n"
"%3 = OpSpecConstant %short -42\n",
},
// 20. 8-bit int type.
{
// code
"OpDecorate %1 SpecId 100\n"
"OpDecorate %2 SpecId 101\n"
"OpDecorate %3 SpecId 102\n"
"%char = OpTypeInt 8 1\n"
"%1 = OpSpecConstant %char 10\n"
"%2 = OpSpecConstant %char 11\n"
"%3 = OpSpecConstant %char 11\n",
// default values
SpecIdToValueBitPatternMap{
{100, {128}}, {101, {129}}, {102, {0xffffffd6}}},
// expected
"OpDecorate %1 SpecId 100\n"
"OpDecorate %2 SpecId 101\n"
"OpDecorate %3 SpecId 102\n"
"%char = OpTypeInt 8 1\n"
"%1 = OpSpecConstant %char 128\n"
"%2 = OpSpecConstant %char 129\n"
"%3 = OpSpecConstant %char -42\n",
},
}));
INSTANTIATE_TEST_SUITE_P(
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment