OSDN Git Service

Fix determining the loop iteration count.
authorNicolas Capens <capn@google.com>
Fri, 6 Jan 2017 22:22:13 +0000 (17:22 -0500)
committerNicolas Capens <capn@google.com>
Mon, 9 Jan 2017 15:03:49 +0000 (15:03 +0000)
Bug b/34128224

Change-Id: I4aebcda840baa8ceef2ae99c98a80a83e32b89b3
Reviewed-on: https://swiftshader-review.googlesource.com/8376
Tested-by: Nicolas Capens <capn@google.com>
Reviewed-by: Alexis Hétu <sugoi@google.com>
Reviewed-by: Nicolas Capens <capn@google.com>
src/OpenGL/compiler/OutputASM.cpp

index acd8fbf..49f62b1 100644 (file)
@@ -24,6 +24,8 @@
 #include <GLES2/gl2ext.h>
 #include <GLES3/gl3.h>
 
+#include <stdlib.h>
+
 namespace glsl
 {
        // Integer to TString conversion
@@ -3599,11 +3601,16 @@ namespace glsl
 
                        if(comparator == EOpLessThan)
                        {
-                               int iterations = (limit - initial) / increment;
+                               if(!(initial < limit))   // Never loops
+                               {
+                                       return 0;
+                               }
+
+                               int iterations = (limit - initial + abs(increment) - 1) / increment;   // Ceiling division
 
-                               if(iterations <= 0)
+                               if(iterations < 0)
                                {
-                                       iterations = 0;
+                                       return ~0u;
                                }
 
                                return iterations;