isl_hash_dim: make result independent of endianness
authorSven Verdoolaege <skimo@kotnet.org>
Fri, 7 Dec 2012 16:51:13 +0000 (17:51 +0100)
committerSven Verdoolaege <skimo@kotnet.org>
Fri, 7 Dec 2012 18:59:31 +0000 (19:59 +0100)
The result computed by isl_hash_dim may affect the order of maps
in a union map, which may in turn affect the result of AST generation.
In particular, we would generate slightly different output depending
on endianness, causing the tests to fail on big endian machines since
the generated output is compared to output generated on a little endian
machine.

Instead of hashing in the dimensions of the space as integers,
we now only hash in the least significant byte.
This has some effect on the results of AST generation, but the output
should now be the same on little endian and big endian.

Reported-by: Richard Biener <rguenther@suse.de>
Signed-off-by: Sven Verdoolaege <skimo@kotnet.org>
22 files changed:
isl_space.c
test_inputs/codegen/atomic.c
test_inputs/codegen/cloog/byu98-1-2-3.c
test_inputs/codegen/cloog/cholesky2.c
test_inputs/codegen/cloog/christian.c
test_inputs/codegen/cloog/classen.c
test_inputs/codegen/cloog/dealII.c
test_inputs/codegen/cloog/dot2.c
test_inputs/codegen/cloog/gauss.c
test_inputs/codegen/cloog/reservoir-lim-lam1.c
test_inputs/codegen/cloog/vivien.c
test_inputs/codegen/cloog/vivien2.c
test_inputs/codegen/cloog/yosr2.c
test_inputs/codegen/omega/iter9-0.c
test_inputs/codegen/omega/m12-1.c
test_inputs/codegen/omega/ts1d-mp-i_ts-m_b-0.c
test_inputs/codegen/omega/wak1-0.c
test_inputs/codegen/omega/wak1-1.c
test_inputs/codegen/omega/x-0.c
test_inputs/codegen/omega/x-1.c
test_inputs/codegen/pldi2012/figure8_b.c
test_inputs/codegen/separate.c

index b0aca35..e6f957c 100644 (file)
@@ -1549,9 +1549,9 @@ static uint32_t isl_hash_dim(uint32_t hash, __isl_keep isl_space *dim)
        if (!dim)
                return hash;
 
-       hash = isl_hash_builtin(hash, dim->nparam);
-       hash = isl_hash_builtin(hash, dim->n_in);
-       hash = isl_hash_builtin(hash, dim->n_out);
+       isl_hash_byte(hash, dim->nparam % 256);
+       isl_hash_byte(hash, dim->n_in % 256);
+       isl_hash_byte(hash, dim->n_out % 256);
 
        for (i = 0; i < dim->nparam; ++i) {
                id = get_id(dim, isl_dim_param, i);
index 0b70279..73731c0 100644 (file)
@@ -1,6 +1,6 @@
 for (int c0 = 0; c0 <= 10; c0 += 1) {
-  if (c0 <= 9)
-    a(c0);
   if (c0 >= 1)
     b(c0 - 1);
+  if (c0 <= 9)
+    a(c0);
 }
index 8c4a081..8e87cba 100644 (file)
@@ -3,12 +3,12 @@
     for (int c1 = -c0 + 6; c1 <= 6; c1 += 1)
       S1(c0, c1);
   for (int c0 = 4; c0 <= 8; c0 += 1) {
-    if (c0 == 4) {
-      for (int c1 = 3; c1 <= 4; c1 += 1)
-        S1(4, c1);
-    } else if (c0 >= 6)
+    if (c0 >= 6) {
       S2(c0, -c0 + 9);
-    if (c0 <= 5) {
+    } else {
+      if (c0 == 4)
+        for (int c1 = 3; c1 <= 4; c1 += 1)
+          S1(4, c1);
       S1(c0, -c0 + 9);
       S2(c0, -c0 + 9);
     }
index 7834ff4..c746460 100644 (file)
@@ -6,11 +6,14 @@
   }
   for (int c0 = 1; c0 < 3 * M - 1; c0 += 3) {
     S3((c0 + 2) / 3);
-    for (int c1 = (c0 + 5) / 3; c1 <= M; c1 += 1) {
-      S6((c0 + 2) / 3, c1);
-      for (int c4 = (c0 + 5) / 3; c4 < c1; c4 += 1)
-        S5(c4, c1, (c0 + 2) / 3);
-    }
+    if (3 * M >= c0 + 8) {
+      for (int c1 = (c0 + 5) / 3; c1 <= M; c1 += 1) {
+        S6((c0 + 2) / 3, c1);
+        for (int c4 = (c0 + 5) / 3; c4 < c1; c4 += 1)
+          S5(c4, c1, (c0 + 2) / 3);
+      }
+    } else if (c0 + 5 == 3 * M)
+      S6(M - 1, M);
     for (int c1 = (c0 + 5) / 3; c1 <= M; c1 += 1)
       S2(c1, (c0 + 2) / 3);
   }
index 9c69a4b..4b4d5a3 100644 (file)
@@ -1,6 +1,6 @@
 for (int c0 = -N + 1; c0 <= N; c0 += 1) {
-  for (int c1 = max(0, c0); c1 < min(N, N + c0); c1 += 1)
-    S1(c1, -c0 + c1);
   for (int c1 = max(c0 - 1, 0); c1 < min(N + c0 - 1, N); c1 += 1)
     S2(c1, -c0 + c1 + 1);
+  for (int c1 = max(0, c0); c1 < min(N, N + c0); c1 += 1)
+    S1(c1, -c0 + c1);
 }
index ec3a1f4..fb12b9d 100644 (file)
@@ -4,8 +4,8 @@
     S8(0, 1);
   } else if (m >= 2) {
     S1(0, 1, 1, 1);
-    S4(0, 1, 2, 2, 1, 1, 2, 2);
     S3(0, 1, 1, 2, 1, 1, 1, 2);
+    S4(0, 1, 2, 2, 1, 1, 2, 2);
     S2(0, 1, 1, 1, 1, 1, 2, 1);
     S8(0, 1);
   }
       S5(m - 2, 1, m - 1, 1, m - 1, 1, m, 1);
       S1(m - 1, 1, m, 1);
       S3(m - 1, 1, m, 2, m, 1, m, 2);
-    } else if (m >= c0 + 2) {
-      S5(c0 - 1, 1, c0, 1, c0, 1, c0 + 1, 1);
-      S1(c0, 1, c0 + 1, 1);
-      S4(c0, 1, c0 + 2, 2, c0 + 1, 1, c0 + 2, 2);
-      S3(c0, 1, c0 + 1, 2, c0 + 1, 1, c0 + 1, 2);
-      S2(c0, 1, c0 + 1, 1, c0 + 1, 1, c0 + 2, 1);
-    } else {
+    } else if (c0 >= m) {
       S5(c0 - 1, -m + c0 + 2, c0, -m + c0 + 2, m - 1, -m + c0 + 2, m, -m + c0 + 2);
       S6(c0 - 1, -m + c0 + 1, c0, -m + c0 + 2, m, -m + c0 + 1, m, -m + c0 + 2);
       S1(c0, -m + c0 + 2, m, -m + c0 + 2);
       S3(c0, -m + c0 + 2, c0 + 1, -m + c0 + 3, m, -m + c0 + 2, m, -m + c0 + 3);
+    } else {
+      S5(c0 - 1, 1, c0, 1, c0, 1, c0 + 1, 1);
+      S1(c0, 1, c0 + 1, 1);
+      S3(c0, 1, c0 + 1, 2, c0 + 1, 1, c0 + 1, 2);
+      S4(c0, 1, c0 + 2, 2, c0 + 1, 1, c0 + 2, 2);
+      S2(c0, 1, c0 + 1, 1, c0 + 1, 1, c0 + 2, 1);
     }
     for (int c2 = max(-m + c0 + 3, 2); c2 <= min(c0, m - 1); c2 += 1) {
       S5(c0 - 1, c2, c0, c2, c0 - c2 + 1, c2, c0 - c2 + 2, c2);
       S6(c0 - 1, c2 - 1, c0, c2, c0 - c2 + 2, c2 - 1, c0 - c2 + 2, c2);
       S1(c0, c2, c0 - c2 + 2, c2);
       S3(c0, c2, c0 + 1, c2 + 1, c0 - c2 + 2, c2, c0 - c2 + 2, c2 + 1);
-      S2(c0, c2, c0 + 1, c2, c0 - c2 + 2, c2, c0 - c2 + 3, c2);
       S4(c0, c2, c0 + 2, c2 + 1, c0 - c2 + 2, c2, c0 - c2 + 3, c2 + 1);
+      S2(c0, c2, c0 + 1, c2, c0 - c2 + 2, c2, c0 - c2 + 3, c2);
     }
     if (c0 + 1 == m) {
-      S6(m - 2, m - 1, m - 1, m, 1, m - 1, 1, m);
       S7(m - 2, m - 1, m, m, 1, m - 1, 2, m);
+      S6(m - 2, m - 1, m - 1, m, 1, m - 1, 1, m);
       S1(m - 1, m, 1, m);
       S2(m - 1, m, m, m, 1, m, 2, m);
     } else if (c0 >= m) {
       S5(c0 - 1, m, c0, m, -m + c0 + 1, m, -m + c0 + 2, m);
-      S6(c0 - 1, m - 1, c0, m, -m + c0 + 2, m - 1, -m + c0 + 2, m);
       S7(c0 - 1, m - 1, c0 + 1, m, -m + c0 + 2, m - 1, -m + c0 + 3, m);
+      S6(c0 - 1, m - 1, c0, m, -m + c0 + 2, m - 1, -m + c0 + 2, m);
       S1(c0, m, -m + c0 + 2, m);
       S2(c0, m, c0 + 1, m, -m + c0 + 2, m, -m + c0 + 3, m);
     } else {
@@ -51,8 +51,8 @@
       S6(c0 - 1, c0, c0, c0 + 1, 1, c0, 1, c0 + 1);
       S1(c0, c0 + 1, 1, c0 + 1);
       S3(c0, c0 + 1, c0 + 1, c0 + 2, 1, c0 + 1, 1, c0 + 2);
-      S2(c0, c0 + 1, c0 + 1, c0 + 1, 1, c0 + 1, 2, c0 + 1);
       S4(c0, c0 + 1, c0 + 2, c0 + 2, 1, c0 + 1, 2, c0 + 2);
+      S2(c0, c0 + 1, c0 + 1, c0 + 1, 1, c0 + 1, 2, c0 + 1);
     }
     for (int c8 = max(-m + c0 + 2, 1); c8 <= min(c0 + 1, m); c8 += 1)
       S8(c0, c8);
       S1(2 * m - 3, m - 1, m, m - 1);
       S3(2 * m - 3, m - 1, 2 * m - 2, m, m, m - 1, m, m);
       S5(2 * m - 4, m, 2 * m - 3, m, m - 2, m, m - 1, m);
-      S6(2 * m - 4, m - 1, 2 * m - 3, m, m - 1, m - 1, m - 1, m);
       S7(2 * m - 4, m - 1, 2 * m - 2, m, m - 1, m - 1, m, m);
+      S6(2 * m - 4, m - 1, 2 * m - 3, m, m - 1, m - 1, m - 1, m);
       S1(2 * m - 3, m, m - 1, m);
     } else {
       S5(0, 1, 1, 1, 1, 1, 2, 1);
       S1(1, 1, 2, 1);
       S3(1, 1, 2, 2, 2, 1, 2, 2);
-      S6(0, 1, 1, 2, 1, 1, 1, 2);
       S7(0, 1, 2, 2, 1, 1, 2, 2);
+      S6(0, 1, 1, 2, 1, 1, 1, 2);
       S1(1, 2, 1, 2);
     }
     S2(2 * m - 3, m, 2 * m - 2, m, m - 1, m, m, m);
index 92fd640..0ae7bfa 100644 (file)
@@ -3,10 +3,10 @@
     S1(c0);
     S2(c0);
   }
+  for (int c0 = T_2; c0 <= min(T_66, T_67 - 1); c0 += 1)
+    S2(c0);
   for (int c0 = max(T_66 + 1, 0); c0 < T_2; c0 += 1)
     S1(c0);
   if (T_67 == 0 && T_2 == 0)
     S1(0);
-  for (int c0 = T_2; c0 <= min(T_66, T_67 - 1); c0 += 1)
-    S2(c0);
 }
index f36aae2..4ab3145 100644 (file)
@@ -4,9 +4,9 @@
     for (int c1 = 1; c1 <= M; c1 += 1)
       S2(c0, c1);
   }
+  for (int c0 = N + 1; c0 <= M; c0 += 1)
+    S1(c0);
   for (int c0 = M + 1; c0 <= N; c0 += 1)
     for (int c1 = 1; c1 <= M; c1 += 1)
       S2(c0, c1);
-  for (int c0 = N + 1; c0 <= M; c0 += 1)
-    S1(c0);
 }
index 4bbe42c..13a8e13 100644 (file)
@@ -1,7 +1,7 @@
 for (int c0 = 1; c0 < M; c0 += 1)
   for (int c1 = c0 + 1; c1 <= M; c1 += 1) {
-    for (int c3 = 1; c3 < c0; c3 += 1)
-      S1(c0, c3, c1);
     for (int c3 = c0 + 1; c3 <= M; c3 += 1)
       S2(c0, c3, c1);
+    for (int c3 = 1; c3 < c0; c3 += 1)
+      S1(c0, c3, c1);
   }
index 8f93f15..ae9848b 100644 (file)
@@ -1,10 +1,10 @@
 for (int c1 = -99; c1 <= 100; c1 += 1) {
-  if (c1 >= 1)
-    S2(c1, 1);
-  for (int c3 = max(1, -c1 + 1); c3 <= min(-c1 + 100, 99); c3 += 1) {
-    S1(c1 + c3, c3);
-    S2(c1 + c3, c3 + 1);
-  }
   if (c1 <= 0)
-    S1(c1 + 100, 100);
+    S1(1, -c1 + 1);
+  for (int c3 = max(-2 * c1 + 3, 1); c3 <= min(199, -2 * c1 + 199); c3 += 2) {
+    S2((2 * c1 + c3 - 1) / 2, (c3 + 1) / 2);
+    S1((2 * c1 + c3 + 1) / 2, (c3 + 1) / 2);
+  }
+  if (c1 >= 1)
+    S2(100, -c1 + 101);
 }
index 29470ed..55c1d79 100644 (file)
@@ -13,8 +13,8 @@
         S5(c0 - c0 / 2 - 1, c0 / 2 + 1, c2);
     }
     for (int c1 = -c0 + c0 / 2 + 3; c1 <= min(n - c0, -1); c1 += 1) {
-      S6(-c1 + 2, c0 + c1 - 2);
       S4(-c1, c0 + c1);
+      S6(-c1 + 2, c0 + c1 - 2);
       for (int c2 = 1; c2 <= -c1; c2 += 1)
         S5(-c1 + 1, c0 + c1 - 1, c2);
     }
       for (int c2 = 1; c2 < -n + c0; c2 += 1)
         S5(-n + c0, n, c2);
     }
-    if (2 * n >= c0 + 1 && c0 >= n + 3)
+    if (2 * n >= c0 + 1 && c0 >= n + 3) {
       S6(-n + c0, n);
-    if (c0 >= n + 3) {
-      S1(c0 - 1);
-    } else if (c0 == n + 2 && n >= 3) {
-      S6(2, n);
-      S1(n + 1);
     } else {
-      if (c0 >= 5 && n + 1 >= c0) {
+      if (n + 1 >= c0 && c0 >= 5) {
         S6(2, c0 - 2);
         S1(c0 - 1);
-      } else if (n + 1 >= c0 && c0 >= 3)
+      } else if (c0 >= 3 && c0 <= 4 && n + 1 >= c0)
         S1(c0 - 1);
-      if (c0 >= 3 && n + 1 >= c0)
+      if (n + 1 >= c0 && c0 >= 3)
         S6(1, c0 - 1);
     }
+    if (c0 >= n + 3) {
+      S1(c0 - 1);
+    } else if (c0 == n + 2 && n >= 3) {
+      S6(2, n);
+      S1(n + 1);
+    }
     if (c0 == 2) {
       S1(1);
     } else if (c0 == 4 && n == 2)
@@ -48,8 +49,6 @@
     for (int c1 = max(-n + c0, 1); c1 < (c0 + 1) / 2; c1 += 1)
       S2(c0 - c1, c1);
   }
-  for (int c0 = max(-27 * n + 2, 2 * n + 1); c0 <= n + 29; c0 += 1)
-    S1(c0 - 1);
   for (int c0 = n + 30; c0 <= 2 * n; c0 += 1) {
     if (2 * n >= c0 + 1) {
       S4(c0 - c0 / 2 - 1, c0 / 2 + 1);
@@ -62,8 +61,8 @@
           S5(c0 - c0 / 2 - 1, c0 / 2 + 1, c2);
       }
       for (int c1 = -c0 + c0 / 2 + 3; c1 <= n - c0; c1 += 1) {
-        S6(-c1 + 2, c0 + c1 - 2);
         S4(-c1, c0 + c1);
+        S6(-c1 + 2, c0 + c1 - 2);
         for (int c2 = 1; c2 <= -c1; c2 += 1)
           S5(-c1 + 1, c0 + c1 - 1, c2);
       }
@@ -79,4 +78,6 @@
     for (int c1 = -n + c0; c1 < (c0 + 1) / 2; c1 += 1)
       S2(c0 - c1, c1);
   }
+  for (int c0 = max(-27 * n + 2, 2 * n + 1); c0 <= n + 29; c0 += 1)
+    S1(c0 - 1);
 }
index 3a679b6..b39b943 100644 (file)
@@ -14,8 +14,8 @@
       }
     }
     for (int c1 = -c0 + c0 / 2 + 3; c1 <= min(n - c0, -1); c1 += 1) {
-      S6(-c1 + 2, c0 + c1 - 2);
       S4(-c1, c0 + c1);
+      S6(-c1 + 2, c0 + c1 - 2);
       for (int c2 = 1; c2 <= -c1; c2 += 1)
         S5(-c1 + 1, c0 + c1 - 1, c2);
     }
     if (c0 >= n + 3) {
       S6(-n + c0, n);
       S1(c0 - 1);
-    } else if (c0 == n + 2) {
-      S6(2, n);
-      S1(n + 1);
     } else {
-      if (c0 >= 5) {
+      if (c0 >= 5 && n + 1 >= c0) {
         S6(2, c0 - 2);
         S1(c0 - 1);
-      } else if (c0 >= 3)
+      } else if (c0 >= 3 && c0 <= 4)
         S1(c0 - 1);
-      if (c0 >= 3)
+      if (c0 >= 3 && n + 1 >= c0)
         S6(1, c0 - 1);
+      if (c0 == n + 2) {
+        S6(2, n);
+        S1(n + 1);
+      }
     }
     if (c0 == 2)
       S1(1);
@@ -58,8 +59,8 @@
           S5(c0 - c0 / 2 - 1, c0 / 2 + 1, c2);
       }
       for (int c1 = -c0 + c0 / 2 + 3; c1 <= n - c0; c1 += 1) {
-        S6(-c1 + 2, c0 + c1 - 2);
         S4(-c1, c0 + c1);
+        S6(-c1 + 2, c0 + c1 - 2);
         for (int c2 = 1; c2 <= -c1; c2 += 1)
           S5(-c1 + 1, c0 + c1 - 1, c2);
       }
index a4c0cd2..a52909c 100644 (file)
@@ -2,12 +2,12 @@
   for (int c1 = 1; c1 <= M; c1 += 1)
     S2(c1);
   for (int c0 = 2; c0 <= M; c0 += 1) {
-    for (int c2 = 1; c2 < c0; c2 += 1)
-      S1(c0, c2);
     for (int c2 = c0 + 1; c2 <= M; c2 += 1)
       for (int c3 = 1; c3 < c0; c3 += 1)
         S3(c0, c2, c3);
     for (int c1 = 1; c1 < c0; c1 += 1)
       S4(c1, c0);
+    for (int c2 = 1; c2 < c0; c2 += 1)
+      S1(c0, c2);
   }
 }
index bf6b887..2336f81 100644 (file)
@@ -1,11 +1,11 @@
-for (int c0 = 1; c0 <= 15; c0 += 1)
-  if (8 * floord(7 * exprVar1 + 7, 8) + 8 >= 7 * exprVar1 + c0 || (exprVar1 + 8 * floord(-exprVar1 + c0 - 1, 8) + 1 == c0 && c0 >= exprVar1 + 1)) {
-    s5(c0);
-    if (8 * floord(7 * exprVar1 + 7, 8) + 8 >= 7 * exprVar1 + c0) {
-      s0(c0);
-      s4(c0);
-      s1(c0);
-      s3(c0);
-      s2(c0);
-    }
+for (int c0 = 1; c0 <= 15; c0 += 1) {
+  if (8 * floord(7 * exprVar1 + 7, 8) + 8 >= 7 * exprVar1 + c0) {
+    s4(c0);
+    s0(c0);
+    s3(c0);
+    s2(c0);
+    s1(c0);
   }
+  if (8 * floord(7 * exprVar1 + 7, 8) + 8 >= 7 * exprVar1 + c0 || (exprVar1 + 8 * floord(-exprVar1 + c0 - 1, 8) + 1 == c0 && c0 >= exprVar1 + 1))
+    s5(c0);
+}
index 555fbfb..eba7c8a 100644 (file)
@@ -1,12 +1,12 @@
 {
   for (int c1 = 1; c1 <= n; c1 += 1)
     for (int c2 = 1; c2 <= m; c2 += 1) {
-      s1(1, c1, c2, 0);
       s0(1, c1, c2, 0);
+      s1(1, c1, c2, 0);
     }
   for (int c1 = 1; c1 <= n; c1 += 1) {
-    s2(2, c1, 0, 0);
     s3(2, c1, 0, 0);
+    s2(2, c1, 0, 0);
   }
   for (int c1 = 1; c1 <= m; c1 += 1) {
     for (int c3 = 1; c3 <= n; c3 += 1) {
       s4(3, c1, 1, c3);
     }
     for (int c3 = 1; c3 <= n; c3 += 1) {
-      s6(3, c1, 2, c3);
       s7(3, c1, 2, c3);
+      s6(3, c1, 2, c3);
     }
   }
   for (int c1 = 1; c1 <= m; c1 += 1) {
-    s9(4, c1, 0, 0);
     s8(4, c1, 0, 0);
+    s9(4, c1, 0, 0);
   }
 }
index 819493d..0cfc22a 100644 (file)
@@ -9,7 +9,7 @@
         s0(1, -1, c2, 0, 0);
   for (int c1 = 0; c1 <= floord(T - 1, 500); c1 += 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 c4 = max(1000 * c1 + 4000 * c3 - 3999, 500 * c1 + 1); c4 <= min(min(1000 * c1 + 4000 * c3 - 3000, 2 * N - 4000 * c3 + 3995), N + T - 3); 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 + 9) / 8) + 2, -((T + 4000) / 4000) + 2); c3 <= floord(N - 500 * c1 - 3, 4000) + 1; c3 += 1)
index 1ce4818..086c561 100644 (file)
@@ -1,27 +1,27 @@
 {
-  for (int c0 = a3; c0 <= min(min(a2 - 1, a1 - 1), b3); c0 += 1)
+  for (int c0 = a2; c0 <= min(min(a3 - 1, a1 - 1), b2); c0 += 1)
+    s1(c0);
+  for (int c0 = a3; c0 <= min(a1 - 1, b3); c0 += 1) {
+    if (c0 >= a2 && b2 >= c0)
+      s1(c0);
     s2(c0);
-  for (int c0 = a1; c0 <= min(a2 - 1, b1); c0 += 1) {
-    s0(c0);
-    if (c0 >= a3 && b3 >= c0)
-      s2(c0);
   }
-  for (int c0 = max(max(b1 + 1, a1), a3); c0 <= min(a2 - 1, b3); c0 += 1)
-    s2(c0);
-  for (int c0 = a2; c0 <= b2; c0 += 1) {
-    if (c0 >= a1 && b1 >= c0)
-      s0(c0);
+  for (int c0 = max(max(b3 + 1, a3), a2); c0 <= min(a1 - 1, b2); c0 += 1)
     s1(c0);
-    if (c0 >= a3 && b3 >= c0)
-      s2(c0);
-  }
-  for (int c0 = max(max(b2 + 1, a3), a2); c0 <= min(a1 - 1, b3); c0 += 1)
-    s2(c0);
-  for (int c0 = max(max(b2 + 1, a1), a2); c0 <= b1; c0 += 1) {
+  for (int c0 = a1; c0 <= b1; c0 += 1) {
     s0(c0);
+    if (b2 >= c0 && c0 >= a2)
+      s1(c0);
     if (b3 >= c0 && c0 >= a3)
       s2(c0);
   }
-  for (int c0 = max(max(max(max(b1 + 1, b2 + 1), a1), a3), a2); c0 <= b3; c0 += 1)
+  for (int c0 = max(max(b1 + 1, a1), a2); c0 <= min(a3 - 1, b2); c0 += 1)
+    s1(c0);
+  for (int c0 = max(max(b1 + 1, a1), a3); c0 <= b3; c0 += 1) {
+    if (c0 >= a2 && b2 >= c0)
+      s1(c0);
     s2(c0);
+  }
+  for (int c0 = max(max(max(max(b1 + 1, b3 + 1), a1), a3), a2); c0 <= b2; c0 += 1)
+    s1(c0);
 }
index 48a6f88..6314c44 100644 (file)
@@ -1,55 +1,55 @@
 {
-  for (int c0 = a2; c0 <= min(min(a3 - 1, a1 - 1), b2); c0 += 1)
-    s1(c0);
-  for (int c0 = a1; c0 <= min(min(a2 - 1, a3 - 1), b1); c0 += 1)
-    s0(c0);
-  for (int c0 = max(a1, a2); c0 <= min(min(a3 - 1, b2), b1); c0 += 1) {
-    s0(c0);
-    s1(c0);
-  }
-  for (int c0 = max(max(b1 + 1, a1), a2); c0 <= min(a3 - 1, b2); c0 += 1)
-    s1(c0);
   for (int c0 = a3; c0 <= min(min(a2 - 1, a1 - 1), b3); c0 += 1)
     s2(c0);
+  for (int c0 = a2; c0 <= min(min(a3 - 1, a1 - 1), b2); c0 += 1)
+    s1(c0);
   for (int c0 = max(a3, a2); c0 <= min(min(a1 - 1, b2), b3); c0 += 1) {
     s1(c0);
     s2(c0);
   }
-  for (int c0 = max(max(b3 + 1, a3), a2); c0 <= min(a1 - 1, b2); c0 += 1)
-    s1(c0);
+  for (int c0 = max(max(b2 + 1, a3), a2); c0 <= min(a1 - 1, b3); c0 += 1)
+    s2(c0);
+  for (int c0 = a1; c0 <= min(min(a2 - 1, a3 - 1), b1); c0 += 1)
+    s0(c0);
   for (int c0 = max(a1, a3); c0 <= min(min(a2 - 1, b3), b1); c0 += 1) {
     s0(c0);
     s2(c0);
   }
-  for (int c0 = max(max(b3 + 1, a1), a3); c0 <= min(a2 - 1, b1); c0 += 1)
-    s0(c0);
-  for (int c0 = max(max(a1, a3), a2); c0 <= min(min(b2, b3), b1); c0 += 1) {
+  for (int c0 = max(max(b1 + 1, a1), a3); c0 <= min(a2 - 1, b3); c0 += 1)
+    s2(c0);
+  for (int c0 = max(a1, a2); c0 <= min(min(a3 - 1, b2), b1); c0 += 1) {
     s0(c0);
     s1(c0);
-    s2(c0);
   }
-  for (int c0 = max(max(max(b3 + 1, a1), a3), a2); c0 <= min(b2, b1); c0 += 1) {
+  for (int c0 = max(max(b1 + 1, a1), a2); c0 <= min(a3 - 1, b2); c0 += 1)
+    s1(c0);
+  for (int c0 = max(max(a1, a3), a2); c0 <= min(min(b2, b3), b1); c0 += 1) {
     s0(c0);
     s1(c0);
-  }
-  for (int c0 = max(max(b1 + 1, a1), a3); c0 <= min(a2 - 1, b3); c0 += 1)
     s2(c0);
+  }
   for (int c0 = max(max(max(b1 + 1, a1), a3), a2); c0 <= min(b2, b3); c0 += 1) {
     s1(c0);
     s2(c0);
   }
-  for (int c0 = max(max(max(max(b1 + 1, b3 + 1), a1), a3), a2); c0 <= b2; c0 += 1)
-    s1(c0);
   for (int c0 = max(max(b2 + 1, a1), a2); c0 <= min(a3 - 1, b1); c0 += 1)
     s0(c0);
-  for (int c0 = max(max(b2 + 1, a3), a2); c0 <= min(a1 - 1, b3); c0 += 1)
-    s2(c0);
   for (int c0 = max(max(max(b2 + 1, a1), a3), a2); c0 <= min(b3, b1); c0 += 1) {
     s0(c0);
     s2(c0);
   }
-  for (int c0 = max(max(max(max(b3 + 1, b2 + 1), a1), a3), a2); c0 <= b1; c0 += 1)
-    s0(c0);
   for (int c0 = max(max(max(max(b1 + 1, b2 + 1), a1), a3), a2); c0 <= b3; c0 += 1)
     s2(c0);
+  for (int c0 = max(max(b3 + 1, a3), a2); c0 <= min(a1 - 1, b2); c0 += 1)
+    s1(c0);
+  for (int c0 = max(max(b3 + 1, a1), a3); c0 <= min(a2 - 1, b1); c0 += 1)
+    s0(c0);
+  for (int c0 = max(max(max(b3 + 1, a1), a3), a2); c0 <= min(b2, b1); c0 += 1) {
+    s0(c0);
+    s1(c0);
+  }
+  for (int c0 = max(max(max(max(b1 + 1, b3 + 1), a1), a3), a2); c0 <= b2; c0 += 1)
+    s1(c0);
+  for (int c0 = max(max(max(max(b3 + 1, b2 + 1), a1), a3), a2); c0 <= b1; c0 += 1)
+    s0(c0);
 }
index 16e6ed0..e009577 100644 (file)
@@ -7,8 +7,8 @@ for (int c0 = 1; c0 <= 11; c0 += 1) {
     s0(c1, c0 + c1 - 8);
     s1(c1, c0 - c1 + 1);
   }
-  for (int c1 = max(-c0 + 9, c0 + 1); c1 <= min(-c0 + 12, 8); c1 += 1)
-    s0(c1, c0 + c1 - 8);
   for (int c1 = max(-c0 + 13, c0 - 3); c1 <= min(c0, 8); c1 += 1)
     s1(c1, c0 - c1 + 1);
+  for (int c1 = max(-c0 + 9, c0 + 1); c1 <= min(-c0 + 12, 8); c1 += 1)
+    s0(c1, c0 + c1 - 8);
 }
index 16e6ed0..e009577 100644 (file)
@@ -7,8 +7,8 @@ for (int c0 = 1; c0 <= 11; c0 += 1) {
     s0(c1, c0 + c1 - 8);
     s1(c1, c0 - c1 + 1);
   }
-  for (int c1 = max(-c0 + 9, c0 + 1); c1 <= min(-c0 + 12, 8); c1 += 1)
-    s0(c1, c0 + c1 - 8);
   for (int c1 = max(-c0 + 13, c0 - 3); c1 <= min(c0, 8); c1 += 1)
     s1(c1, c0 - c1 + 1);
+  for (int c1 = max(-c0 + 9, c0 + 1); c1 <= min(-c0 + 12, 8); c1 += 1)
+    s0(c1, c0 + c1 - 8);
 }
index 21b90f2..a112d19 100644 (file)
@@ -1,5 +1,8 @@
-for (int c0 = 2; c0 <= n; c0 += 4) {
-  s1(c0);
-  if (n >= c0 + 2)
+{
+  for (int c0 = 2; c0 < n - 1; c0 += 4) {
+    s1(c0);
     s0(c0 + 2);
+  }
+  if (n >= 4 * floord(n, 4) + 2 && n >= 0)
+    s1(-(n % 4) + n + 2);
 }
index 14d91be..042e3e7 100644 (file)
@@ -1,8 +1,8 @@
 {
   a(0);
   for (int c0 = 1; c0 <= 9; c0 += 1) {
-    a(c0);
     b(c0 - 1);
+    a(c0);
   }
   b(9);
 }