isl_aff_ceil: compute ceil(e/m) as floor((e + m - 1)/m)
authorSven Verdoolaege <skimo@kotnet.org>
Sat, 8 Sep 2012 12:56:40 +0000 (14:56 +0200)
committerSven Verdoolaege <skimo@kotnet.org>
Tue, 13 Nov 2012 23:33:52 +0000 (00:33 +0100)
The original implementation would compute ceil(e/m) as -floor(-e/m).
Although both are correct, floor((e + m - 1)/m) is probably less
surprising.

Signed-off-by: Sven Verdoolaege <skimo@kotnet.org>
30 files changed:
isl_aff.c
test_inputs/codegen/cloog/classen2.c
test_inputs/codegen/cloog/jacobi-shared.c
test_inputs/codegen/cloog/levenshtein-1-2-3.c
test_inputs/codegen/cloog/nul_complex1.c
test_inputs/codegen/cloog/otl.c
test_inputs/codegen/cloog/pouchet.c
test_inputs/codegen/cloog/reservoir-bastoul3.c
test_inputs/codegen/cloog/reservoir-cholesky2.c
test_inputs/codegen/cloog/reservoir-lim-lam3.c
test_inputs/codegen/cloog/reservoir-liu-zhuge1.c
test_inputs/codegen/cloog/reservoir-pingali5.c
test_inputs/codegen/cloog/vivien.c
test_inputs/codegen/cloog/vivien2.c
test_inputs/codegen/omega/floor_bound-0.c
test_inputs/codegen/omega/floor_bound-1.c
test_inputs/codegen/omega/hpf-0.c
test_inputs/codegen/omega/iter8-0.c
test_inputs/codegen/omega/lefur00-0.c
test_inputs/codegen/omega/lefur01-0.c
test_inputs/codegen/omega/lefur01-1.c
test_inputs/codegen/omega/lefur03-0.c
test_inputs/codegen/omega/lefur04-0.c
test_inputs/codegen/omega/m11-0.c
test_inputs/codegen/omega/p.delft-0.c
test_inputs/codegen/omega/stride6-0.c
test_inputs/codegen/omega/substitution-1.c
test_inputs/codegen/omega/ts1d-check0-0.c
test_inputs/codegen/omega/ts1d-mp-i_ts-m_b-0.c
test_inputs/codegen/stride5.c

index 79fd8d5..c2e3f53 100644 (file)
--- a/isl_aff.c
+++ b/isl_aff.c
@@ -994,7 +994,13 @@ __isl_give isl_pw_aff *isl_pw_aff_mod(__isl_take isl_pw_aff *pwaff, isl_int m)
 
 /* Given f, return ceil(f).
  * If f is an integer expression, then just return f.
- * Otherwise, create a new div d = [-f] and return the expression -d.
+ * Otherwise, let f be the expression
+ *
+ *     e/m
+ *
+ * then return
+ *
+ *     floor((e + m - 1)/m)
  */
 __isl_give isl_aff *isl_aff_ceil(__isl_take isl_aff *aff)
 {
@@ -1004,9 +1010,16 @@ __isl_give isl_aff *isl_aff_ceil(__isl_take isl_aff *aff)
        if (isl_int_is_one(aff->v->el[0]))
                return aff;
 
-       aff = isl_aff_neg(aff);
+       aff = isl_aff_cow(aff);
+       if (!aff)
+               return NULL;
+       aff->v = isl_vec_cow(aff->v);
+       if (!aff->v)
+               return isl_aff_free(aff);
+
+       isl_int_add(aff->v->el[1], aff->v->el[1], aff->v->el[0]);
+       isl_int_sub_ui(aff->v->el[1], aff->v->el[1], 1);
        aff = isl_aff_floor(aff);
-       aff = isl_aff_neg(aff);
 
        return aff;
 }
index 314eb1c..0b9ca0e 100644 (file)
@@ -1,4 +1,4 @@
 for (int c0 = max(max(max(max(max(max(4, 10 * outerProcTileScatter1 - 2 * N + 2), 10 * outerProcTileScatter2 - N + 1), 5 * outerProcTileScatter2 + 1), 5 * outerTimeTileScatter), 5 * outerProcTileScatter1 + 5 * outerProcTileScatter2 - N), 5 * outerProcTileScatter1); c0 <= min(min(min(min(min(min(2 * M + 2 * N - 6, 5 * outerProcTileScatter2 + M + N), 5 * outerProcTileScatter1 + M + 2), 10 * outerProcTileScatter2 + N + 3), 10 * outerProcTileScatter1 + 4), 5 * outerTimeTileScatter + 4), 5 * outerProcTileScatter1 + 5 * outerProcTileScatter2 + 5); c0 += 1)
-  for (int c1 = max(max(max(max(-5 * outerProcTileScatter2 + c0 - 1, 5 * outerProcTileScatter1), 5 * outerProcTileScatter2 + 1), -M + c0 + 2), c0 - c0 / 2 + 2); c1 <= min(min(min(min(5 * outerProcTileScatter1 + 4, 5 * outerProcTileScatter2 + N + 2), c0), -5 * outerProcTileScatter2 + N + c0), N + c0 / 2 - 1); c1 += 1)
+  for (int c1 = max(max(max(max(-5 * outerProcTileScatter2 + c0 - 1, 5 * outerProcTileScatter1), 5 * outerProcTileScatter2 + 1), -M + c0 + 2), (c0 + 1) / 2 + 2); c1 <= min(min(min(min(5 * outerProcTileScatter1 + 4, 5 * outerProcTileScatter2 + N + 2), c0), -5 * outerProcTileScatter2 + N + c0), N + c0 / 2 - 1); c1 += 1)
     for (int c2 = max(max(5 * outerProcTileScatter2, -N + c1 + 2), c0 - c1 + 3); c2 <= min(min(5 * outerProcTileScatter2 + 4, N + c0 - c1), c1 - 1); c2 += 1)
       S1(c0 - c1 + 1, -c0 + c1 + c2 - 2, c1 - c2, c0, c1, c2);
index 6314bc3..c671cf9 100644 (file)
@@ -1,3 +1,3 @@
 if (2 * floord(h0 - 1, 2) + 1 == h0 && g2 + 29 >= (g2 - t1 + 32) % 32 && ((g2 - t1 + 32) % 32) + N >= g2 + 33)
-  for (int c0 = max(-((-t0 + 16) % 16) + 16, t0 - 16 * floord(g1 + t0 - 3, 16)); c0 <= min(32, N - g1 - 1); c0 += 16)
+  for (int c0 = max(((t0 + 15) % 16) + 1, ((g1 + t0 + 13) % 16) - g1 + 3); c0 <= min(32, N - g1 - 1); c0 += 16)
     S1(g1 + c0 - 1, ((t1 + 31) % 32) + g2);
index 6929d18..10fa2a3 100644 (file)
@@ -17,7 +17,7 @@
       S5(c0, (-N + c0) / 2);
       S8(c0, (-N + c0) / 2);
     }
-    for (int c1 = c0 - (N + c0 + 1) / 2 + 1; c1 < (N + c0 + 1) / 2; c1 += 1) {
+    for (int c1 = -N + (N + c0) / 2 + 1; c1 < (N + c0 + 1) / 2; c1 += 1) {
       S6(c0, c1);
       S8(c0, c1);
     }
index 750e331..6395f8a 100644 (file)
@@ -1,3 +1,3 @@
 for (int c0 = 0; c0 <= 5 * n; c0 += 1)
-  for (int c1 = max(((n + c0) % 2) - n + c0, ((c0 + c0 / 3) % 2) + c0 - c0 / 3); c1 <= min(n + c0 - (n + c0 + 2) / 3, c0); c1 += 2)
+  for (int c1 = max(-((n + c0 + 1) % 2) - n + c0 + 1, 2 * floord(c0 - (c0 + 3) / 3, 2) + 2); c1 <= min(n + c0 - (n + c0 + 2) / 3, c0); c1 += 2)
     S1((-2 * c0 + 3 * c1) / 2, c0 - c1);
index d0848ca..b84006b 100644 (file)
@@ -1,7 +1,7 @@
 if (M >= 3 && N >= 4)
   for (int c0 = 1; c0 < (2 * M + 2 * N - 2) / 5; c0 += 1)
-    for (int c1 = max(c0 - c0 / 2, c0 - (M + 2) / 5); c1 <= min(min((2 * N + 5 * c0 + 1) / 10, c0), (M + 2 * N) / 5 - 1); c1 += 1)
-      for (int c2 = max(max(max(max(c0 - (N + 5 * c0 + 2) / 10, c1 - (N + 1) / 5), c0 - c1 - 1), 0), c0 - (M + N - 1) / 5); c2 <= min(min(min(c0 - c1 + (N - 1) / 5 + 1, (N + 5 * c0 + 3) / 10), c1), (M + N - 2) / 5); c2 += 1)
-        for (int c3 = max(max(max(c1 + c2 - (N - 2) / 5 - 1, 2 * c2 - (N + 2) / 5), 2 * c1 - 2 * N / 5), c0); c3 <= min(min(min(min(min(c0 + 1, c1 + c2 + 1), c2 + (M + N) / 5), (2 * M + 2 * N - 1) / 5 - 1), c1 + (M - 2) / 5 + 1), 2 * c2 + (N - 2) / 5 + 1); c3 += 1)
-          for (int c4 = max(max(max(max(c1, c0 - c2), c3 - (M + 2) / 5), c0 - (M + 1) / 5), c3 - c3 / 2); c4 <= min(min(min(min(min(min(min(c0 - c2 + N / 5 + 1, -c2 + c3 + (N - 1) / 5 + 1), (2 * N + 5 * c0 + 3) / 10), (M + 2 * N + 1) / 5 - 1), (2 * N + 5 * c3 + 2) / 10), c2 + (N + 2) / 5), c1 + 1), c0); c4 += 1)
+    for (int c1 = max((c0 + 1) / 2, c0 - (M + 2) / 5); c1 <= min(min((2 * N + 5 * c0 + 1) / 10, c0), (M + 2 * N) / 5 - 1); c1 += 1)
+      for (int c2 = max(max(max(max(floord(-N + 5 * c0 - 3, 10) + 1, c1 - (N + 6) / 5 + 1), c0 - c1 - 1), 0), c0 - (M + N + 4) / 5 + 1); c2 <= min(min(min(c0 - c1 + (N - 1) / 5 + 1, (N + 5 * c0 + 3) / 10), c1), (M + N - 2) / 5); c2 += 1)
+        for (int c3 = max(max(max(c1 + c2 - (N + 3) / 5, 2 * c2 - (N + 2) / 5), 2 * c1 - (2 * N + 5) / 5 + 1), c0); c3 <= min(min(min(min(min(c0 + 1, c1 + c2 + 1), c2 + (M + N) / 5), (2 * M + 2 * N - 1) / 5 - 1), c1 + (M - 2) / 5 + 1), 2 * c2 + (N - 2) / 5 + 1); c3 += 1)
+          for (int c4 = max(max(max(max(c1, c0 - c2), c3 - (M + 2) / 5), c0 - (M + 6) / 5 + 1), (c3 + 1) / 2); c4 <= min(min(min(min(min(min(min(c0 - c2 + N / 5 + 1, -c2 + c3 + (N - 1) / 5 + 1), (2 * N + 5 * c0 + 3) / 10), (M + 2 * N + 1) / 5 - 1), (2 * N + 5 * c3 + 2) / 10), c2 + (N + 2) / 5), c1 + 1), c0); c4 += 1)
             S1(c0, c1, c2, c3, c4, c2);
index 42c03a0..c602e1f 100644 (file)
@@ -1,5 +1,5 @@
 for (int c0 = 1; c0 <= floord(Ny, 2) + 2; c0 += 1)
-  for (int c1 = max(c0 - (c0 + 1) / 2 + 1, c0 - 1); c1 <= min((Ny + 2 * c0) / 4, c0); c1 += 1)
+  for (int c1 = max(c0 / 2 + 1, c0 - 1); c1 <= min((Ny + 2 * c0) / 4, c0); c1 += 1)
     if (Ny + 2 * c0 >= 4 * c1 + 1) {
       for (int c2 = 1; c2 <= 2; c2 += 1) {
         S1(c0 - c1, c1, 2 * c0 - 2 * c1, -2 * c0 + 4 * c1, c2);
index 05e95d2..b59b93d 100644 (file)
@@ -1,3 +1,3 @@
 for (int c0 = 3; c0 <= 9; c0 += 1)
-  for (int c1 = max(((c0 + 1) % 2) + 1, c0 - 6); c1 <= min(c0 - 2, 3); c1 += 2)
+  for (int c1 = max(-(c0 % 2) + 2, c0 - 6); c1 <= min(c0 - 2, 3); c1 += 2)
     S1(c0, c1, (c0 - c1) / 2);
index 5d90323..1e60bb6 100644 (file)
@@ -2,9 +2,9 @@ for (int c1 = 2; c1 < 3 * M; c1 += 1) {
   if ((c1 - 2) % 3 == 0)
     S1((c1 + 1) / 3);
   for (int c3 = (c1 + 1) / 3 + 1; c3 <= min(c1 - 2, M); c3 += 1)
-    for (int c5 = c1 - (c1 + c3) / 2 + 1; c5 <= min(c1 - c3, c3); c5 += 1)
+    for (int c5 = -c3 + (c1 + c3 + 1) / 2 + 1; c5 <= min(c1 - c3, c3); c5 += 1)
       S3(c1 - c3 - c5 + 1, c3, c5);
-  if (c1 + 1 >= 3 * ((c1 - (c1 + 3) / 3 + 1) / 2) && 3 * ((c1 - (c1 + 3) / 3 + 1) / 2) + 1 >= c1)
-    for (int c3 = ((c1 - (c1 + 3) / 3 + 1) % 2) + (c1 + 3) / 3 + 1; c3 <= min(c1, M); c3 += 2)
+  if (2 * c1 + 1 >= 3 * ((c1 + c1 / 3 + 1) / 2) && 3 * ((c1 + c1 / 3 + 1) / 2) + 1 >= 2 * c1)
+    for (int c3 = -((c1 + c1 / 3 + 1) % 2) + c1 / 3 + 3; c3 <= min(c1, M); c3 += 2)
       S2((c1 - c3 + 2) / 2, c3);
 }
index bd64f09..d011975 100644 (file)
@@ -1,11 +1,11 @@
 for (int c1 = 5; c1 <= 5 * M; c1 += 1) {
-  for (int c3 = max(2, -floord(M - c1 - 1, 4) - 1); c3 < min((c1 + 1) / 3 - 2, M); c3 += 1)
-    for (int c5 = max(c1 - c3 - (M + c1 + 1) / 2 - 2, 1); c5 < min(c3, -2 * c3 + (c1 + c3) / 2 - 2); c5 += 1)
+  for (int c3 = max(2, floord(-M + c1, 4)); c3 < min((c1 + 1) / 3 - 2, M); c3 += 1)
+    for (int c5 = max(-M - c3 + (M + c1) / 2 - 2, 1); c5 < min(c3, -2 * c3 + (c1 + c3) / 2 - 2); c5 += 1)
       S1(c1 - 2 * c3 - 2 * c5 - 5, c3, c5);
-  for (int c3 = max(1, -floord(M - c1 - 1, 4) - 1); c3 < (c1 + 1) / 5; c3 += 1)
+  for (int c3 = max(1, floord(-M + c1, 4)); c3 < (c1 + 1) / 5; c3 += 1)
     S2(c1 - 4 * c3 - 3, c3);
   if (c1 % 5 == 0)
     S4(c1 / 5);
-  for (int c3 = max(-((c1 + 2) % 3) + 3, 2 * c1 - 3 * ((M + c1 + 1) / 2) + 1); c3 < (c1 + 1) / 5; c3 += 3)
+  for (int c3 = max(-((c1 - 1) % 3) + 3, -3 * M - c1 + 3 * ((M + c1) / 2) + 1); c3 < (c1 + 1) / 5; c3 += 3)
     S3((c1 - 2 * c3 - 1) / 3, c3);
 }
index 78712ca..987c280 100644 (file)
@@ -4,7 +4,7 @@ if (N >= 0 && M >= 0)
       S2(M, -3 * M + c1);
     } else if (3 * floord(c1 - 2, 3) + 2 == c1 && c1 + 1 >= 0 && 3 * M >= c1 + 4)
       S1((c1 + 4) / 3, 0);
-    for (int c3 = max(c1 - 3 * floord(c1, 3), -3 * M + c1 + 3); c3 <= min(c1, N - 1); c3 += 3) {
+    for (int c3 = max(c1 + 3 * floord(-c1 - 1, 3) + 3, -3 * M + c1 + 3); c3 <= min(c1, N - 1); c3 += 3) {
       S2((c1 - c3) / 3, c3);
       S1((c1 - c3 + 3) / 3, c3 + 1);
     }
@@ -12,6 +12,6 @@ if (N >= 0 && M >= 0)
       S2((-N + c1) / 3, N);
     } else if (N >= c1 + 4)
       S1(0, c1 + 4);
-    for (int c3 = max(-3 * M + c1, c1 - 3 * floord(c1, 3)); c3 <= min(N, c1); c3 += 3)
+    for (int c3 = max(-3 * M + c1, c1 + 3 * floord(-c1 - 1, 3) + 3); c3 <= min(N, c1); c3 += 3)
       S3((c1 - c3) / 3, c3);
   }
index fe2d283..51f2f0c 100644 (file)
@@ -1,10 +1,10 @@
 for (int c1 = 3; c1 < 2 * M; c1 += 1) {
-  for (int c3 = c1 - (c1 + 1) / 2 + 2; c3 <= M; c3 += 1)
-    for (int c7 = c1 - (c1 + 1) / 2 + 1; c7 < min(c1, c3); c7 += 1)
+  for (int c3 = c1 / 2 + 2; c3 <= M; c3 += 1)
+    for (int c7 = c1 / 2 + 1; c7 < min(c1, c3); c7 += 1)
       S1(c7, c1 - c7, c3);
   for (int c3 = max(1, -M + c1); c3 < (c1 + 1) / 2; c3 += 1)
     S2(c1 - c3, c3);
-  for (int c3 = c1 - (c1 + 1) / 2 + 2; c3 <= M; c3 += 1)
-    for (int c7 = c1 - (c1 + 1) / 2 + 1; c7 < min(c1, c3); c7 += 1)
+  for (int c3 = c1 / 2 + 2; c3 <= M; c3 += 1)
+    for (int c7 = c1 / 2 + 1; c7 < min(c1, c3); c7 += 1)
       S3(c7, c1 - c7, c3);
 }
index 70e2fb7..29470ed 100644 (file)
@@ -12,7 +12,7 @@
       for (int c2 = 1; c2 < (c0 + 1) / 2 - 1; c2 += 1)
         S5(c0 - c0 / 2 - 1, c0 / 2 + 1, c2);
     }
-    for (int c1 = -((c0 + 1) / 2) + 3; c1 <= min(n - c0, -1); c1 += 1) {
+    for (int c1 = -c0 + c0 / 2 + 3; c1 <= min(n - c0, -1); c1 += 1) {
       S6(-c1 + 2, c0 + c1 - 2);
       S4(-c1, c0 + c1);
       for (int c2 = 1; c2 <= -c1; c2 += 1)
@@ -61,7 +61,7 @@
         for (int c2 = 1; c2 < (c0 + 1) / 2 - 1; c2 += 1)
           S5(c0 - c0 / 2 - 1, c0 / 2 + 1, c2);
       }
-      for (int c1 = -((c0 + 1) / 2) + 3; c1 <= n - c0; c1 += 1) {
+      for (int c1 = -c0 + c0 / 2 + 3; c1 <= n - c0; c1 += 1) {
         S6(-c1 + 2, c0 + c1 - 2);
         S4(-c1, c0 + c1);
         for (int c2 = 1; c2 <= -c1; c2 += 1)
index 4cb1864..3a679b6 100644 (file)
@@ -13,7 +13,7 @@
           S5(c0 - c0 / 2 - 1, c0 / 2 + 1, c2);
       }
     }
-    for (int c1 = -((c0 + 1) / 2) + 3; c1 <= min(n - c0, -1); c1 += 1) {
+    for (int c1 = -c0 + c0 / 2 + 3; c1 <= min(n - c0, -1); c1 += 1) {
       S6(-c1 + 2, c0 + c1 - 2);
       S4(-c1, c0 + c1);
       for (int c2 = 1; c2 <= -c1; c2 += 1)
@@ -57,7 +57,7 @@
         for (int c2 = 1; c2 < (c0 + 1) / 2 - 1; c2 += 1)
           S5(c0 - c0 / 2 - 1, c0 / 2 + 1, c2);
       }
-      for (int c1 = -((c0 + 1) / 2) + 3; c1 <= n - c0; c1 += 1) {
+      for (int c1 = -c0 + c0 / 2 + 3; c1 <= n - c0; c1 += 1) {
         S6(-c1 + 2, c0 + c1 - 2);
         S4(-c1, c0 + c1);
         for (int c2 = 1; c2 <= -c1; c2 += 1)
index 534b50e..959f268 100644 (file)
@@ -1,2 +1,2 @@
-for (int c0 = -4 * floord(floord(-m, 3), 4); c0 <= floord(n, 3); c0 += 4)
+for (int c0 = 4 * floord(floord(m - 1, 3), 4) + 4; c0 <= floord(n, 3); c0 += 4)
   s0(c0);
index b1420ce..bc87982 100644 (file)
@@ -1,2 +1,2 @@
-for (int c0 = -floord(-m - 1, 4) - 1; c0 <= n; c0 += 1)
+for (int c0 = floord(m, 4); c0 <= n; c0 += 1)
   s0(c0);
index 8b52b22..c8fecaa 100644 (file)
@@ -1,4 +1,4 @@
 if (P1 == P2 && P2 <= 3 && P2 >= 0)
   for (int c0 = 0; c0 <= min(2, -P2 + 4); c0 += 1)
-    for (int c2 = -((P2 + c0 + 2) % 3) + 2; c2 <= 3; c2 += 3)
+    for (int c2 = -P2 - c0 + 3 * floord(P2 + c0 - 1, 3) + 3; c2 <= 3; c2 += 3)
       s0(c0, c0, c2, c2);
index 280b706..505dd79 100644 (file)
@@ -1,2 +1,2 @@
-for (int c0 = max(exprVar2 - 8 * floord(exprVar2 - exprVar1, 8) + 1, exprVar2 + 1); c0 <= 16; c0 += 8)
+for (int c0 = max(exprVar2 + 8 * floord(-exprVar2 + exprVar1 - 1, 8) + 9, exprVar2 + 1); c0 <= 16; c0 += 8)
   s0(c0);
index b3873c0..1cd7fc3 100644 (file)
@@ -1,5 +1,5 @@
 for (int c0 = 0; c0 <= 15; c0 += 1)
-  for (int c1 = max(c0 - (c0 + 1) / 2, 2 * c0 - 15); c1 <= min(c0 + 1, 15); c1 += 1)
-    for (int c2 = max(max(max(67 * c0 - (c0 + 1) / 3, 133 * c0 - 67 * c1 + (c0 + c1 + 1) / 3 - 66), 67 * c1 - floord(c1 - 1, 3) - 1), 1); c2 <= min(min(133 * c0 - 67 * c1 + floord(c0 + c1 - 1, 3) + 133, 100 * c0 + 99), 1000); c2 += 1)
-      for (int c3 = max(max(200 * c0 - c2, 100 * c1 + c2 - c2 / 2), c2); c3 <= min(min(100 * c1 + (c2 + 1) / 2 + 99, 2 * c2 + 1), 200 * c0 - c2 + 199); c3 += 1)
+  for (int c1 = max(c0 / 2, 2 * c0 - 15); c1 <= min(c0 + 1, 15); c1 += 1)
+    for (int c2 = max(max(max(67 * c0 - (c0 + 1) / 3, 133 * c0 - 67 * c1 + (c0 + c1 + 1) / 3 - 66), 67 * c1 - (c1 + 2) / 3), 1); c2 <= min(min(133 * c0 - 67 * c1 + floord(c0 + c1 - 1, 3) + 133, 100 * c0 + 99), 1000); c2 += 1)
+      for (int c3 = max(max(200 * c0 - c2, 100 * c1 + (c2 + 1) / 2), c2); c3 <= min(min(100 * c1 + (c2 + 1) / 2 + 99, 2 * c2 + 1), 200 * c0 - c2 + 199); c3 += 1)
         s0(c0, c1, c2, c3);
index b3873c0..1cd7fc3 100644 (file)
@@ -1,5 +1,5 @@
 for (int c0 = 0; c0 <= 15; c0 += 1)
-  for (int c1 = max(c0 - (c0 + 1) / 2, 2 * c0 - 15); c1 <= min(c0 + 1, 15); c1 += 1)
-    for (int c2 = max(max(max(67 * c0 - (c0 + 1) / 3, 133 * c0 - 67 * c1 + (c0 + c1 + 1) / 3 - 66), 67 * c1 - floord(c1 - 1, 3) - 1), 1); c2 <= min(min(133 * c0 - 67 * c1 + floord(c0 + c1 - 1, 3) + 133, 100 * c0 + 99), 1000); c2 += 1)
-      for (int c3 = max(max(200 * c0 - c2, 100 * c1 + c2 - c2 / 2), c2); c3 <= min(min(100 * c1 + (c2 + 1) / 2 + 99, 2 * c2 + 1), 200 * c0 - c2 + 199); c3 += 1)
+  for (int c1 = max(c0 / 2, 2 * c0 - 15); c1 <= min(c0 + 1, 15); c1 += 1)
+    for (int c2 = max(max(max(67 * c0 - (c0 + 1) / 3, 133 * c0 - 67 * c1 + (c0 + c1 + 1) / 3 - 66), 67 * c1 - (c1 + 2) / 3), 1); c2 <= min(min(133 * c0 - 67 * c1 + floord(c0 + c1 - 1, 3) + 133, 100 * c0 + 99), 1000); c2 += 1)
+      for (int c3 = max(max(200 * c0 - c2, 100 * c1 + (c2 + 1) / 2), c2); c3 <= min(min(100 * c1 + (c2 + 1) / 2 + 99, 2 * c2 + 1), 200 * c0 - c2 + 199); c3 += 1)
         s0(c0, c1, c2, c3);
index 804a9ef..c10688a 100644 (file)
@@ -1,5 +1,5 @@
 for (int c0 = 0; c0 <= 15; c0 += 1)
-  for (int c1 = max(c0 - (c0 + 1) / 2, 2 * c0 - 15); c1 <= min(c0 + 1, 15); c1 += 1)
-    for (int c2 = max(max(max(133 * c0 - 67 * c1 + (c0 + c1 + 1) / 3 - 66, 67 * c1 - floord(c1 - 1, 3) - 1), 67 * c0 - (c0 + 1) / 3), 1); c2 <= min(min(133 * c0 - 67 * c1 + floord(c0 + c1 - 1, 3) + 133, 100 * c0 + 99), 1000); c2 += 1)
-      for (int c3 = max(max(200 * c0 - c2, 100 * c1 + c2 - c2 / 2), c2); c3 <= min(min(100 * c1 + (c2 + 1) / 2 + 99, 2 * c2 + 1), 200 * c0 - c2 + 199); c3 += 1)
+  for (int c1 = max(c0 / 2, 2 * c0 - 15); c1 <= min(c0 + 1, 15); c1 += 1)
+    for (int c2 = max(max(max(133 * c0 - 67 * c1 + (c0 + c1 + 1) / 3 - 66, 67 * c1 - (c1 + 2) / 3), 67 * c0 - (c0 + 1) / 3), 1); c2 <= min(min(133 * c0 - 67 * c1 + floord(c0 + c1 - 1, 3) + 133, 100 * c0 + 99), 1000); c2 += 1)
+      for (int c3 = max(max(200 * c0 - c2, 100 * c1 + (c2 + 1) / 2), c2); c3 <= min(min(100 * c1 + (c2 + 1) / 2 + 99, 2 * c2 + 1), 200 * c0 - c2 + 199); c3 += 1)
         s0(c0, c1, c2, c3);
index 3e58184..2b6d7b2 100644 (file)
@@ -1,7 +1,7 @@
 for (int c0 = 0; c0 <= 3; c0 += 1)
   for (int c1 = max(0, 2 * c0 - 3); c1 <= min(c0 + c0 / 2 + 1, 3); c1 += 1)
     for (int c2 = c0; c2 <= min(min(3, 3 * c1 + 2), 2 * c0 - c1 + 1); c2 += 1)
-      for (int c3 = max(max(max(c1 + (c1 + 2) / 3 - 1, 0), c1 + c2 - (3 * c1 + c2) / 6 - 1), 2 * c0 - (c0 + c1 + 1) / 3 - 1); c3 <= min(c0 + 1, 3); c3 += 1)
-        for (int c4 = max(max(max(max(-200 * c1 + 400 * c3 - 199, 333 * c1 + (c1 + 3) / 3 - 1), 333 * c2 + (c2 + 1) / 3), 667 * c0 - 333 * c1 - (c0 + c1) / 3 - 333), 250 * c3 + 1); c4 <= min(min(min(min(500 * c0 + 499, -200 * c1 + 400 * c3 + 400), 333 * c3 - (-c3 + 3) / 3 + 334), 1000), 333 * c2 - (-c2 + 3) / 3 + 333); c4 += 1)
-          for (int c5 = max(max(max(1000 * c3 - 2 * c4 + 2, 1000 * c0 - c4), 500 * c1 + c4 - c4 / 2), c4); c5 <= min(min(min(1000 * c3 - 2 * c4 + 1001, 1000 * c0 - c4 + 999), 500 * c1 + (c4 + 1) / 2 + 499), 2 * c4 + 1); c5 += 1)
+      for (int c3 = max(max(max(c1 - (-c1 + 3) / 3, 0), c2 + floord(3 * c1 - c2 - 1, 6)), 2 * c0 - (c0 + c1 + 1) / 3 - 1); c3 <= min(c0 + 1, 3); c3 += 1)
+        for (int c4 = max(max(max(max(-200 * c1 + 400 * c3 - 199, 333 * c1 + c1 / 3), 333 * c2 + (c2 + 1) / 3), 667 * c0 - 333 * c1 - (c0 + c1 + 3) / 3 - 332), 250 * c3 + 1); c4 <= min(min(min(min(500 * c0 + 499, -200 * c1 + 400 * c3 + 400), 333 * c3 - (-c3 + 3) / 3 + 334), 1000), 333 * c2 - (-c2 + 3) / 3 + 333); c4 += 1)
+          for (int c5 = max(max(max(1000 * c3 - 2 * c4 + 2, 1000 * c0 - c4), 500 * c1 + (c4 + 1) / 2), c4); c5 <= min(min(min(1000 * c3 - 2 * c4 + 1001, 1000 * c0 - c4 + 999), 500 * c1 + (c4 + 1) / 2 + 499), 2 * c4 + 1); c5 += 1)
             s0(c0, c1, c2, c3, c4, c5);
index b531bf6..079505e 100644 (file)
@@ -1,8 +1,8 @@
 for (int c0 = 0; c0 <= 3; c0 += 1)
   for (int c1 = max(0, 2 * c0 - 3); c1 <= min(c0 + 1, 3); c1 += 1)
     for (int c2 = c0; c2 <= min(min(3, 3 * c1 + 2), 2 * c0 - c1 + 1); c2 += 1)
-      for (int c3 = max(max(max(c2 + (-c2 + 3) / 3 - 1, c1 + c2 - (3 * c1 + c2) / 6 - 1), c1 + (c1 + 2) / 3 - 1), c0 + (c2 + 2) / 3 - 1); c3 <= min(c0 + c0 / 2 + 1, 3); c3 += 1)
-        for (int c5 = max(max(max(max(c1 + (c1 + 2) / 3 - 1, 0), 2 * c3 - 4), c3 - c3 / 3 - 1), c2 - c2 / 3 - 1); c5 <= min(min(-c2 + 2 * c3 - (c2 + 3) / 3 + 2, c1 + 1), c3); c5 += 1)
-          for (int c6 = max(max(max(max(max(250 * c3 + 1, 667 * c0 - 333 * c1 - (c0 + c1) / 3 - 333), -200 * c1 + 400 * c3 - 199), 333 * c1 + (c1 + 3) / 3 - 1), 1000 * c0 - 500 * c5 - 501), 333 * c2 + (c2 + 1) / 3); c6 <= min(min(min(min(min(min(333 * c3 - (-c3 + 3) / 3 + 334, 1000), 333 * c2 - (-c2 + 3) / 3 + 333), 1000 * c0 - 500 * c5 + 997), 500 * c5 + 501), 500 * c0 + 499), -200 * c1 + 400 * c3 + 400); c6 += 1)
-            for (int c7 = max(max(max(max(c6, 500 * c1 + c6 - c6 / 2), 1000 * c0 - c6), 500 * c5 + 2), 1000 * c3 - 2 * c6 + 2); c7 <= min(min(min(min(500 * c5 + 501, 2 * c6 + 1), 1000 * c3 - 2 * c6 + 1001), 1000 * c0 - c6 + 999), 500 * c1 + (c6 + 1) / 2 + 499); c7 += 1)
+      for (int c3 = max(max(max(c2 - (c2 + 2) / 3, c2 + floord(3 * c1 - c2 - 1, 6)), c1 - (-c1 + 3) / 3), c0 - (-c2 + 3) / 3); c3 <= min(c0 + c0 / 2 + 1, 3); c3 += 1)
+        for (int c5 = max(max(max(max(c1 - (-c1 + 3) / 3, 0), 2 * c3 - 4), c3 - (c3 + 3) / 3), c2 - (c2 + 3) / 3); c5 <= min(min(-c2 + 2 * c3 - (c2 + 3) / 3 + 2, c1 + 1), c3); c5 += 1)
+          for (int c6 = max(max(max(max(max(250 * c3 + 1, 667 * c0 - 333 * c1 - (c0 + c1 + 3) / 3 - 332), -200 * c1 + 400 * c3 - 199), 333 * c1 + c1 / 3), 1000 * c0 - 500 * c5 - 501), 333 * c2 + (c2 + 1) / 3); c6 <= min(min(min(min(min(min(333 * c3 - (-c3 + 3) / 3 + 334, 1000), 333 * c2 - (-c2 + 3) / 3 + 333), 1000 * c0 - 500 * c5 + 997), 500 * c5 + 501), 500 * c0 + 499), -200 * c1 + 400 * c3 + 400); c6 += 1)
+            for (int c7 = max(max(max(max(c6, 500 * c1 + (c6 + 1) / 2), 1000 * c0 - c6), 500 * c5 + 2), 1000 * c3 - 2 * c6 + 2); c7 <= min(min(min(min(500 * c5 + 501, 2 * c6 + 1), 1000 * c3 - 2 * c6 + 1001), 1000 * c0 - c6 + 999), 500 * c1 + (c6 + 1) / 2 + 499); c7 += 1)
               s0(c0, c1, c2, c3, c2 / 3, c5, c6, c7);
index e0abe48..e1c320c 100644 (file)
@@ -1,6 +1,6 @@
 for (int c0 = 1; c0 <= min(4, floord(2 * m - 1, 17) + 1); c0 += 1)
   for (int c1 = 1; c1 <= 2; c1 += 1)
     for (int c2 = 0; c2 <= min(-c1 + c1 / 2 + 3, -c0 - c1 + (2 * m + 3 * c0 + 10 * c1 + 6) / 20 + 1); c2 += 1)
-      for (int c3 = 9 * c0 - c0 / 2 - 8; c3 <= min(min(m - 5 * c1 - 10 * c2 + 5, 8 * c0 + c0 / 2), 30); c3 += 1)
+      for (int c3 = 8 * c0 + (c0 + 1) / 2 - 8; c3 <= min(min(m - 5 * c1 - 10 * c2 + 5, 8 * c0 + c0 / 2), 30); c3 += 1)
         for (int c4 = 5 * c1 + 10 * c2 - 4; c4 <= min(m - c3 + 1, 5 * c1 + 10 * c2); c4 += 1)
           s0(c0, c1, c2, c3, c4, -9 * c0 + c3 + c0 / 2 + 9, -5 * c1 - 5 * c2 + c4 + 5);
index 8b52b22..c8fecaa 100644 (file)
@@ -1,4 +1,4 @@
 if (P1 == P2 && P2 <= 3 && P2 >= 0)
   for (int c0 = 0; c0 <= min(2, -P2 + 4); c0 += 1)
-    for (int c2 = -((P2 + c0 + 2) % 3) + 2; c2 <= 3; c2 += 3)
+    for (int c2 = -P2 - c0 + 3 * floord(P2 + c0 - 1, 3) + 3; c2 <= 3; c2 += 3)
       s0(c0, c0, c2, c2);
index d6bd4d4..5f619bf 100644 (file)
@@ -1,3 +1,3 @@
 for (int c0 = 1; c0 <= 101; c0 += 1)
-  for (int c1 = (c0 % 2) + c0; c1 <= 400; c1 += 2)
+  for (int c1 = -((c0 + 1) % 2) + c0 + 1; c1 <= 400; c1 += 2)
     s0(c0, c1);
index b394e5c..51ab952 100644 (file)
@@ -1,3 +1,3 @@
 for (int c0 = 0; c0 <= 14; c0 += 1)
-  for (int c1 = max(2 * c0 - 12, 2 * c0 - 3 * (c0 / 2)); c1 <= min(2 * c0, c0 / 2 + 9); c1 += 3)
+  for (int c1 = max(2 * c0 - 12, -c0 + 3 * ((c0 + 1) / 2)); c1 <= min(2 * c0, c0 / 2 + 9); c1 += 3)
     s0((2 * c0 - c1) / 3, (-c0 + 2 * c1) / 3);
index e00eb91..d252bdf 100644 (file)
@@ -3,7 +3,7 @@
     s0(1, c1, 1, 0, 0);
   for (int c1 = 0; c1 <= floord(T - 1, 500); c1 += 1)
     for (int c2 = 1000 * c1; c2 <= min(N + 1000 * c1 + 997, N + 2 * T - 3); c2 += 1) {
-      for (int c3 = max(0, ((N + c2 + 1) % 2) - N - 1000 * c1 + c2 + 1); c3 <= min(min(2 * T - 1000 * c1 - 2, 998), -1000 * c1 + c2 - 2); c3 += 2) {
+      for (int c3 = max(0, -((N + c2) % 2) - N - 1000 * c1 + c2 + 2); c3 <= min(min(2 * T - 1000 * c1 - 2, 998), -1000 * c1 + c2 - 2); c3 += 2) {
         s1(2, 1000 * c1 + c3, 0, -1000 * c1 + c2 - c3, 1);
         s2(2, 1000 * c1 + c3 + 1, 0, -1000 * c1 + c2 - c3 - 1, 1);
       }
index 1ab5459..c8526f0 100644 (file)
@@ -8,27 +8,27 @@
       } else if (c1 + 1 == 0 && c2 >= 0 && N >= c2 + 1)
         s0(1, -1, c2, 0, 0);
   for (int c1 = 0; c1 <= floord(T - 1, 500); c1 += 1) {
-    for (int c3 = -((c1 + 1) / 8) + 1; c3 <= floord(N - 500 * c1 - 3, 4000) + 1; c3 += 1)
+    for (int c3 = -((c1 + 9) / 8) + 2; c3 <= floord(N - 500 * c1 - 3, 4000) + 1; c3 += 1)
       for (int c4 = max(1000 * c1 + 4000 * c3 - 3999, 500 * c1 + 1); c4 <= min(min(2 * N - 4000 * c3 + 3995, N + T - 3), 1000 * c1 + 4000 * c3 - 3000); c4 += 1)
         for (int c5 = max(-N - 500 * c1 + c4 + 2, 0); c5 <= min(min(T - 500 * c1 - 1, -500 * c1 + c4 - 1), -500 * c1 - 2000 * c3 + (c4 + 1) / 2 + 1999); c5 += 1)
           s1(2, 500 * c1 + c5, 1, -500 * c1 + c4 - c5, 1);
-    for (int c3 = max(-((c1 + 1) / 8) + 1, -(T / 4000) + 1); c3 <= floord(N - 500 * c1 - 3, 4000) + 1; c3 += 1)
+    for (int c3 = max(-((c1 + 9) / 8) + 2, -((T + 4000) / 4000) + 2); c3 <= floord(N - 500 * c1 - 3, 4000) + 1; c3 += 1)
       for (int c4 = max(-4000 * c3 + 4000, 1000 * c1 + 4000 * c3 - 3999); c4 <= min(min(2 * N - 4000 * c3 + 3995, 1000 * c1 + 4000 * c3 - 3000), 2 * T + 4000 * c3 - 4000); c4 += 1)
         s2(2, -2000 * c3 + (c4 + 1) / 2 + 1999, 1, 2000 * c3 + c4 - (c4 + 1) / 2 - 1999, 1);
-    for (int c3 = -floord(c1 - 1, 8); c3 <= min(floord(N - 500 * c1 - 504, 4000) + 1, floord(N + T - 1000 * c1 - 1004, 4000) + 1); c3 += 1)
+    for (int c3 = -((c1 + 7) / 8) + 1; c3 <= min(floord(N - 500 * c1 - 504, 4000) + 1, floord(N + T - 1000 * c1 - 1004, 4000) + 1); c3 += 1)
       for (int c4 = max(1000 * c1 + 4000 * c3 - 2999, 500 * c1 + 1); c4 <= min(min(N + T - 3, N + 500 * c1 + 497), 1000 * c1 + 4000 * c3); c4 += 1)
         for (int c5 = max(0, -N - 500 * c1 + c4 + 2); c5 <= min(min(T - 500 * c1 - 1, -500 * c1 + c4 - 1), 499); c5 += 1)
           s3(2, 500 * c1 + c5, 1, -500 * c1 + c4 - c5, 1);
-    for (int c3 = max(-((c1 + 1) / 8), -(T / 4000)); c3 <= floord(N - 500 * c1 - 3, 4000); c3 += 1)
+    for (int c3 = max(-((c1 + 9) / 8) + 1, -((T + 4000) / 4000) + 1); c3 <= floord(N - 500 * c1 - 3, 4000); c3 += 1)
       for (int c4 = max(-4000 * c3, 1000 * c1 + 4000 * c3 + 1); c4 <= min(min(2 * N - 4000 * c3 - 5, 1000 * c1 + 4000 * c3 + 1000), 2 * T + 4000 * c3); c4 += 1)
         s4(2, -2000 * c3 + (c4 + 1) / 2 - 1, 1, 2000 * c3 + c4 - (c4 + 1) / 2 + 1, 1);
-    for (int c3 = -(c1 / 8); c3 <= min(floord(N - 500 * c1 + 496, 4000), floord(N + T - 1000 * c1 - 4, 4000)); c3 += 1)
+    for (int c3 = -((c1 + 8) / 8) + 1; c3 <= min(floord(N - 500 * c1 + 496, 4000), floord(N + T - 1000 * c1 - 4, 4000)); c3 += 1)
       for (int c4 = max(1000 * c1 + 4000 * c3 + 1, -4000 * c3 + 2); c4 <= min(min(min(1000 * c1 + 4000 * c3 + 998, N + 500 * c1 + 497), 2 * T + 4000 * c3 - 2), N + T - 3); c4 += 1)
-        for (int c5 = max(-N - 500 * c1 + c4 + 2, -500 * c1 - 2000 * c3 + c4 - c4 / 2); c5 <= min(min(T - 500 * c1 - 1, -500 * c1 + c4 - 1), 499); c5 += 1)
+        for (int c5 = max(-N - 500 * c1 + c4 + 2, -500 * c1 - 2000 * c3 + (c4 + 1) / 2); c5 <= min(min(T - 500 * c1 - 1, -500 * c1 + c4 - 1), 499); c5 += 1)
           s5(2, 500 * c1 + c5, 1, -500 * c1 + c4 - c5, 1);
   }
   if (T >= 1)
-    for (int c3 = -floord(T - 2, 4000); c3 <= floord(N - T - 2, 4000) + 1; c3 += 1)
+    for (int c3 = -((T + 3998) / 4000) + 1; c3 <= floord(N - T - 2, 4000) + 1; c3 += 1)
       for (int c4 = max(2 * T + 4000 * c3 - 4001, T); c4 < min(2 * T + 4000 * c3 - 1, N + T - 2); c4 += 1)
         s6(2, T - 1, 1, -T + c4 + 1, 1);
 }
index 1e69f06..080bea0 100644 (file)
@@ -1,3 +1,3 @@
 if (2 * floord(n, 2) == n)
-  for (int c0 = (n - 4 * floord(n, 4)) / 2; c0 <= 100; c0 += 2)
+  for (int c0 = (n + 4 * floord(-n - 1, 4) + 4) / 2; c0 <= 100; c0 += 2)
     S(c0);