diff options
Diffstat (limited to 'gfx/angle/src/tests/compiler_tests/ConstantFolding_test.cpp')
-rwxr-xr-x | gfx/angle/src/tests/compiler_tests/ConstantFolding_test.cpp | 272 |
1 files changed, 1 insertions, 271 deletions
diff --git a/gfx/angle/src/tests/compiler_tests/ConstantFolding_test.cpp b/gfx/angle/src/tests/compiler_tests/ConstantFolding_test.cpp index 4c5baffe7..1185613de 100755 --- a/gfx/angle/src/tests/compiler_tests/ConstantFolding_test.cpp +++ b/gfx/angle/src/tests/compiler_tests/ConstantFolding_test.cpp @@ -15,8 +15,6 @@ #include "compiler/translator/PoolAlloc.h" #include "compiler/translator/TranslatorESSL.h" -using namespace sh; - template <typename T> class ConstantFinder : public TIntermTraverser { @@ -109,7 +107,7 @@ class ConstantFoldingTest : public testing::Test allocator.push(); SetGlobalPoolAllocator(&allocator); ShBuiltInResources resources; - InitBuiltInResources(&resources); + ShInitBuiltInResources(&resources); mTranslatorESSL = new TranslatorESSL(GL_FRAGMENT_SHADER, SH_GLES3_SPEC); ASSERT_TRUE(mTranslatorESSL->Init(resources)); @@ -794,271 +792,3 @@ TEST_F(ConstantFoldingTest, FoldNonSquareOuterProduct) std::vector<float> result(outputElements, outputElements + 6); ASSERT_TRUE(constantColumnMajorMatrixFoundInAST(result)); } - -// Test that folding bit shift left with non-matching signedness works. -TEST_F(ConstantFoldingTest, FoldBitShiftLeftDifferentSignedness) -{ - const std::string &shaderString = - "#version 300 es\n" - "precision mediump float;\n" - "out vec4 my_FragColor;\n" - "void main()\n" - "{\n" - " uint u = 0xffffffffu << 31;\n" - " my_FragColor = vec4(u);\n" - "}\n"; - compile(shaderString); - ASSERT_TRUE(constantFoundInAST(0x80000000u)); -} - -// Test that folding bit shift right with non-matching signedness works. -TEST_F(ConstantFoldingTest, FoldBitShiftRightDifferentSignedness) -{ - const std::string &shaderString = - "#version 300 es\n" - "precision mediump float;\n" - "out vec4 my_FragColor;\n" - "void main()\n" - "{\n" - " uint u = 0xffffffffu >> 30;\n" - " my_FragColor = vec4(u);\n" - "}\n"; - compile(shaderString); - ASSERT_TRUE(constantFoundInAST(0x3u)); -} - -// Test that folding signed bit shift right extends the sign bit. -// ESSL 3.00.6 section 5.9 Expressions. -TEST_F(ConstantFoldingTest, FoldBitShiftRightExtendSignBit) -{ - const std::string &shaderString = - "#version 300 es\n" - "precision mediump float;\n" - "out vec4 my_FragColor;\n" - "void main()\n" - "{\n" - " const int i = 0x8fffe000 >> 6;\n" - " uint u = uint(i);" - " my_FragColor = vec4(u);\n" - "}\n"; - compile(shaderString); - // The bits of the operand are 0x8fffe000 = 1000 1111 1111 1111 1110 0000 0000 0000 - // After shifting, they become 1111 1110 0011 1111 1111 1111 1000 0000 = 0xfe3fff80 - ASSERT_TRUE(constantFoundInAST(0xfe3fff80u)); -} - -// Signed bit shift left should interpret its operand as a bit pattern. As a consequence a number -// may turn from positive to negative when shifted left. -// ESSL 3.00.6 section 5.9 Expressions. -TEST_F(ConstantFoldingTest, FoldBitShiftLeftInterpretedAsBitPattern) -{ - const std::string &shaderString = - "#version 300 es\n" - "precision mediump float;\n" - "out vec4 my_FragColor;\n" - "void main()\n" - "{\n" - " const int i = 0x1fffffff << 3;\n" - " uint u = uint(i);" - " my_FragColor = vec4(u);\n" - "}\n"; - compile(shaderString); - ASSERT_TRUE(constantFoundInAST(0xfffffff8u)); -} - -// Test that dividing the minimum signed integer by -1 works. -// ESSL 3.00.6 section 4.1.3 Integers: -// "However, for the case where the minimum representable value is divided by -1, it is allowed to -// return either the minimum representable value or the maximum representable value." -TEST_F(ConstantFoldingTest, FoldDivideMinimumIntegerByMinusOne) -{ - const std::string &shaderString = - "#version 300 es\n" - "precision mediump float;\n" - "out vec4 my_FragColor;\n" - "void main()\n" - "{\n" - " int i = 0x80000000 / (-1);\n" - " my_FragColor = vec4(i);\n" - "}\n"; - compile(shaderString); - ASSERT_TRUE(constantFoundInAST(0x7fffffff) || constantFoundInAST(-0x7fffffff - 1)); -} - -// Test that folding an unsigned integer addition that overflows works. -// ESSL 3.00.6 section 4.1.3 Integers: -// "For all precisions, operations resulting in overflow or underflow will not cause any exception, -// nor will they saturate, rather they will 'wrap' to yield the low-order n bits of the result where -// n is the size in bits of the integer." -TEST_F(ConstantFoldingTest, FoldUnsignedIntegerAddOverflow) -{ - const std::string &shaderString = - "#version 300 es\n" - "precision mediump float;\n" - "out vec4 my_FragColor;\n" - "void main()\n" - "{\n" - " uint u = 0xffffffffu + 43u;\n" - " my_FragColor = vec4(u);\n" - "}\n"; - compile(shaderString); - ASSERT_TRUE(constantFoundInAST(42u)); -} - -// Test that folding a signed integer addition that overflows works. -// ESSL 3.00.6 section 4.1.3 Integers: -// "For all precisions, operations resulting in overflow or underflow will not cause any exception, -// nor will they saturate, rather they will 'wrap' to yield the low-order n bits of the result where -// n is the size in bits of the integer." -TEST_F(ConstantFoldingTest, FoldSignedIntegerAddOverflow) -{ - const std::string &shaderString = - "#version 300 es\n" - "precision mediump float;\n" - "out vec4 my_FragColor;\n" - "void main()\n" - "{\n" - " int i = 0x7fffffff + 4;\n" - " my_FragColor = vec4(i);\n" - "}\n"; - compile(shaderString); - ASSERT_TRUE(constantFoundInAST(-0x7ffffffd)); -} - -// Test that folding an unsigned integer subtraction that overflows works. -// ESSL 3.00.6 section 4.1.3 Integers: -// "For all precisions, operations resulting in overflow or underflow will not cause any exception, -// nor will they saturate, rather they will 'wrap' to yield the low-order n bits of the result where -// n is the size in bits of the integer." -TEST_F(ConstantFoldingTest, FoldUnsignedIntegerDiffOverflow) -{ - const std::string &shaderString = - "#version 300 es\n" - "precision mediump float;\n" - "out vec4 my_FragColor;\n" - "void main()\n" - "{\n" - " uint u = 0u - 5u;\n" - " my_FragColor = vec4(u);\n" - "}\n"; - compile(shaderString); - ASSERT_TRUE(constantFoundInAST(0xfffffffbu)); -} - -// Test that folding a signed integer subtraction that overflows works. -// ESSL 3.00.6 section 4.1.3 Integers: -// "For all precisions, operations resulting in overflow or underflow will not cause any exception, -// nor will they saturate, rather they will 'wrap' to yield the low-order n bits of the result where -// n is the size in bits of the integer." -TEST_F(ConstantFoldingTest, FoldSignedIntegerDiffOverflow) -{ - const std::string &shaderString = - "#version 300 es\n" - "precision mediump float;\n" - "out vec4 my_FragColor;\n" - "void main()\n" - "{\n" - " int i = -0x7fffffff - 7;\n" - " my_FragColor = vec4(i);\n" - "}\n"; - compile(shaderString); - ASSERT_TRUE(constantFoundInAST(0x7ffffffa)); -} - -// Test that folding an unsigned integer multiplication that overflows works. -// ESSL 3.00.6 section 4.1.3 Integers: -// "For all precisions, operations resulting in overflow or underflow will not cause any exception, -// nor will they saturate, rather they will 'wrap' to yield the low-order n bits of the result where -// n is the size in bits of the integer." -TEST_F(ConstantFoldingTest, FoldUnsignedIntegerMultiplyOverflow) -{ - const std::string &shaderString = - "#version 300 es\n" - "precision mediump float;\n" - "out vec4 my_FragColor;\n" - "void main()\n" - "{\n" - " uint u = 0xffffffffu * 10u;\n" - " my_FragColor = vec4(u);\n" - "}\n"; - compile(shaderString); - ASSERT_TRUE(constantFoundInAST(0xfffffff6u)); -} - -// Test that folding a signed integer multiplication that overflows works. -// ESSL 3.00.6 section 4.1.3 Integers: -// "For all precisions, operations resulting in overflow or underflow will not cause any exception, -// nor will they saturate, rather they will 'wrap' to yield the low-order n bits of the result where -// n is the size in bits of the integer." -TEST_F(ConstantFoldingTest, FoldSignedIntegerMultiplyOverflow) -{ - const std::string &shaderString = - "#version 300 es\n" - "precision mediump float;\n" - "out vec4 my_FragColor;\n" - "void main()\n" - "{\n" - " int i = 0x7fffffff * 42;\n" - " my_FragColor = vec4(i);\n" - "}\n"; - compile(shaderString); - ASSERT_TRUE(constantFoundInAST(-42)); -} - -// Test that folding of negating the minimum representable integer works. Note that in the test -// "0x80000000" is a negative literal, and the minus sign before it is the negation operator. -// ESSL 3.00.6 section 4.1.3 Integers: -// "For all precisions, operations resulting in overflow or underflow will not cause any exception, -// nor will they saturate, rather they will 'wrap' to yield the low-order n bits of the result where -// n is the size in bits of the integer." -TEST_F(ConstantFoldingTest, FoldMinimumSignedIntegerNegation) -{ - const std::string &shaderString = - "#version 300 es\n" - "precision mediump float;\n" - "out vec4 my_FragColor;\n" - "void main()\n" - "{\n" - " int i = -0x80000000;\n" - " my_FragColor = vec4(i);\n" - "}\n"; - compile(shaderString); - // Negating the minimum signed integer overflows the positive range, so it wraps back to itself. - ASSERT_TRUE(constantFoundInAST(-0x7fffffff - 1)); -} - -// Test that folding of shifting the minimum representable integer works. -TEST_F(ConstantFoldingTest, FoldMinimumSignedIntegerRightShift) -{ - const std::string &shaderString = - "#version 300 es\n" - "precision mediump float;\n" - "out vec4 my_FragColor;\n" - "void main()\n" - "{\n" - " int i = (0x80000000 >> 1);\n" - " int j = (0x80000000 >> 7);\n" - " my_FragColor = vec4(i, j, i, j);\n" - "}\n"; - compile(shaderString); - ASSERT_TRUE(constantFoundInAST(-0x40000000)); - ASSERT_TRUE(constantFoundInAST(-0x01000000)); -} - -// Test that folding of shifting by 0 works. -TEST_F(ConstantFoldingTest, FoldShiftByZero) -{ - const std::string &shaderString = - "#version 300 es\n" - "precision mediump float;\n" - "out vec4 my_FragColor;\n" - "void main()\n" - "{\n" - " int i = (3 >> 0);\n" - " int j = (73 << 0);\n" - " my_FragColor = vec4(i, j, i, j);\n" - "}\n"; - compile(shaderString); - ASSERT_TRUE(constantFoundInAST(3)); - ASSERT_TRUE(constantFoundInAST(73)); -} |