hotspot/test/compiler/5091921/Test6890943.java
author kvn
Wed, 04 May 2011 13:12:42 -0700
changeset 9446 748a37b25d10
child 15753 f599307f4ca5
permissions -rw-r--r--
5091921: Sign flip issues in loop optimizer Summary: Fix integer overflow problem in the code generated by loop optimizer. Reviewed-by: never
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
9446
748a37b25d10 5091921: Sign flip issues in loop optimizer
kvn
parents:
diff changeset
     1
/*
748a37b25d10 5091921: Sign flip issues in loop optimizer
kvn
parents:
diff changeset
     2
 * Copyright (c) 2011, Oracle and/or its affiliates. All rights reserved.
748a37b25d10 5091921: Sign flip issues in loop optimizer
kvn
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
748a37b25d10 5091921: Sign flip issues in loop optimizer
kvn
parents:
diff changeset
     4
 *
748a37b25d10 5091921: Sign flip issues in loop optimizer
kvn
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
748a37b25d10 5091921: Sign flip issues in loop optimizer
kvn
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
748a37b25d10 5091921: Sign flip issues in loop optimizer
kvn
parents:
diff changeset
     7
 * published by the Free Software Foundation.
748a37b25d10 5091921: Sign flip issues in loop optimizer
kvn
parents:
diff changeset
     8
 *
748a37b25d10 5091921: Sign flip issues in loop optimizer
kvn
parents:
diff changeset
     9
 * This code is distributed in the hope that it will be useful, but WITHOUT
748a37b25d10 5091921: Sign flip issues in loop optimizer
kvn
parents:
diff changeset
    10
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
748a37b25d10 5091921: Sign flip issues in loop optimizer
kvn
parents:
diff changeset
    11
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
748a37b25d10 5091921: Sign flip issues in loop optimizer
kvn
parents:
diff changeset
    12
 * version 2 for more details (a copy is included in the LICENSE file that
748a37b25d10 5091921: Sign flip issues in loop optimizer
kvn
parents:
diff changeset
    13
 * accompanied this code).
748a37b25d10 5091921: Sign flip issues in loop optimizer
kvn
parents:
diff changeset
    14
 *
748a37b25d10 5091921: Sign flip issues in loop optimizer
kvn
parents:
diff changeset
    15
 * You should have received a copy of the GNU General Public License version
748a37b25d10 5091921: Sign flip issues in loop optimizer
kvn
parents:
diff changeset
    16
 * 2 along with this work; if not, write to the Free Software Foundation,
748a37b25d10 5091921: Sign flip issues in loop optimizer
kvn
parents:
diff changeset
    17
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
748a37b25d10 5091921: Sign flip issues in loop optimizer
kvn
parents:
diff changeset
    18
 *
748a37b25d10 5091921: Sign flip issues in loop optimizer
kvn
parents:
diff changeset
    19
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
748a37b25d10 5091921: Sign flip issues in loop optimizer
kvn
parents:
diff changeset
    20
 * or visit www.oracle.com if you need additional information or have any
748a37b25d10 5091921: Sign flip issues in loop optimizer
kvn
parents:
diff changeset
    21
 * questions.
748a37b25d10 5091921: Sign flip issues in loop optimizer
kvn
parents:
diff changeset
    22
 *
748a37b25d10 5091921: Sign flip issues in loop optimizer
kvn
parents:
diff changeset
    23
 */
748a37b25d10 5091921: Sign flip issues in loop optimizer
kvn
parents:
diff changeset
    24
748a37b25d10 5091921: Sign flip issues in loop optimizer
kvn
parents:
diff changeset
    25
/**
748a37b25d10 5091921: Sign flip issues in loop optimizer
kvn
parents:
diff changeset
    26
 * @test
748a37b25d10 5091921: Sign flip issues in loop optimizer
kvn
parents:
diff changeset
    27
 * @bug 6890943
748a37b25d10 5091921: Sign flip issues in loop optimizer
kvn
parents:
diff changeset
    28
 * @summary JVM mysteriously gives wrong result on 64-bit 1.6 VMs in hotspot mode.
748a37b25d10 5091921: Sign flip issues in loop optimizer
kvn
parents:
diff changeset
    29
 *
748a37b25d10 5091921: Sign flip issues in loop optimizer
kvn
parents:
diff changeset
    30
 * @run shell Test6890943.sh
748a37b25d10 5091921: Sign flip issues in loop optimizer
kvn
parents:
diff changeset
    31
 */
748a37b25d10 5091921: Sign flip issues in loop optimizer
kvn
parents:
diff changeset
    32
import java.util.*;
748a37b25d10 5091921: Sign flip issues in loop optimizer
kvn
parents:
diff changeset
    33
import java.io.*;
748a37b25d10 5091921: Sign flip issues in loop optimizer
kvn
parents:
diff changeset
    34
import java.util.regex.*;
748a37b25d10 5091921: Sign flip issues in loop optimizer
kvn
parents:
diff changeset
    35
748a37b25d10 5091921: Sign flip issues in loop optimizer
kvn
parents:
diff changeset
    36
public class Test6890943 {
748a37b25d10 5091921: Sign flip issues in loop optimizer
kvn
parents:
diff changeset
    37
  public static final boolean AIR = true, ROCK = false;
748a37b25d10 5091921: Sign flip issues in loop optimizer
kvn
parents:
diff changeset
    38
  public static void main(String[] args) {
748a37b25d10 5091921: Sign flip issues in loop optimizer
kvn
parents:
diff changeset
    39
    new Test6890943().go();
748a37b25d10 5091921: Sign flip issues in loop optimizer
kvn
parents:
diff changeset
    40
  }
748a37b25d10 5091921: Sign flip issues in loop optimizer
kvn
parents:
diff changeset
    41
748a37b25d10 5091921: Sign flip issues in loop optimizer
kvn
parents:
diff changeset
    42
  int r, c, f, t;
748a37b25d10 5091921: Sign flip issues in loop optimizer
kvn
parents:
diff changeset
    43
  boolean[][] grid;
748a37b25d10 5091921: Sign flip issues in loop optimizer
kvn
parents:
diff changeset
    44
748a37b25d10 5091921: Sign flip issues in loop optimizer
kvn
parents:
diff changeset
    45
  public void go() {
748a37b25d10 5091921: Sign flip issues in loop optimizer
kvn
parents:
diff changeset
    46
    Scanner s = new Scanner(System.in);
748a37b25d10 5091921: Sign flip issues in loop optimizer
kvn
parents:
diff changeset
    47
    s.useDelimiter("\\s+");
748a37b25d10 5091921: Sign flip issues in loop optimizer
kvn
parents:
diff changeset
    48
    int T = s.nextInt();
748a37b25d10 5091921: Sign flip issues in loop optimizer
kvn
parents:
diff changeset
    49
    for (t = 0 ; t < T ; t++) {
748a37b25d10 5091921: Sign flip issues in loop optimizer
kvn
parents:
diff changeset
    50
      r = s.nextInt(); c = s.nextInt(); f = s.nextInt();
748a37b25d10 5091921: Sign flip issues in loop optimizer
kvn
parents:
diff changeset
    51
      grid = new boolean[r][c];
748a37b25d10 5091921: Sign flip issues in loop optimizer
kvn
parents:
diff changeset
    52
      for (int x = 0 ; x < r ; x++) {
748a37b25d10 5091921: Sign flip issues in loop optimizer
kvn
parents:
diff changeset
    53
        String line = s.next();
748a37b25d10 5091921: Sign flip issues in loop optimizer
kvn
parents:
diff changeset
    54
        for (int y = 0 ; y < c ; y++) grid[x][y] = line.charAt(y) == '.';
748a37b25d10 5091921: Sign flip issues in loop optimizer
kvn
parents:
diff changeset
    55
      }
748a37b25d10 5091921: Sign flip issues in loop optimizer
kvn
parents:
diff changeset
    56
      int digs = solve();
748a37b25d10 5091921: Sign flip issues in loop optimizer
kvn
parents:
diff changeset
    57
      String res = digs == -1 ? "No" : "Yes " + digs;
748a37b25d10 5091921: Sign flip issues in loop optimizer
kvn
parents:
diff changeset
    58
      System.out.printf("Case #%d: %s\n", t+1, res);
748a37b25d10 5091921: Sign flip issues in loop optimizer
kvn
parents:
diff changeset
    59
    }
748a37b25d10 5091921: Sign flip issues in loop optimizer
kvn
parents:
diff changeset
    60
  }
748a37b25d10 5091921: Sign flip issues in loop optimizer
kvn
parents:
diff changeset
    61
748a37b25d10 5091921: Sign flip issues in loop optimizer
kvn
parents:
diff changeset
    62
  Map<Integer, Integer> M = new HashMap<Integer, Integer>();
748a37b25d10 5091921: Sign flip issues in loop optimizer
kvn
parents:
diff changeset
    63
748a37b25d10 5091921: Sign flip issues in loop optimizer
kvn
parents:
diff changeset
    64
  private int solve() {
748a37b25d10 5091921: Sign flip issues in loop optimizer
kvn
parents:
diff changeset
    65
    M = new HashMap<Integer, Integer>();
748a37b25d10 5091921: Sign flip issues in loop optimizer
kvn
parents:
diff changeset
    66
    M.put(calcWalkingRange(0, 0), 0);
748a37b25d10 5091921: Sign flip issues in loop optimizer
kvn
parents:
diff changeset
    67
    for (int digDown = 0 ; digDown < r ; digDown++) {
748a37b25d10 5091921: Sign flip issues in loop optimizer
kvn
parents:
diff changeset
    68
      Map<Integer, Integer> tries = new HashMap<Integer, Integer>();
748a37b25d10 5091921: Sign flip issues in loop optimizer
kvn
parents:
diff changeset
    69
      for (Map.Entry<Integer, Integer> m : M.entrySet()) {
748a37b25d10 5091921: Sign flip issues in loop optimizer
kvn
parents:
diff changeset
    70
        int q = m.getKey();
748a37b25d10 5091921: Sign flip issues in loop optimizer
kvn
parents:
diff changeset
    71
        if (depth(q) != (digDown)) continue;
748a37b25d10 5091921: Sign flip issues in loop optimizer
kvn
parents:
diff changeset
    72
        if (stuck(q)) continue;
748a37b25d10 5091921: Sign flip issues in loop optimizer
kvn
parents:
diff changeset
    73
        tries.put(q, m.getValue());
748a37b25d10 5091921: Sign flip issues in loop optimizer
kvn
parents:
diff changeset
    74
      }
748a37b25d10 5091921: Sign flip issues in loop optimizer
kvn
parents:
diff changeset
    75
748a37b25d10 5091921: Sign flip issues in loop optimizer
kvn
parents:
diff changeset
    76
      for (Map.Entry<Integer, Integer> m : tries.entrySet()) {
748a37b25d10 5091921: Sign flip issues in loop optimizer
kvn
parents:
diff changeset
    77
        int q = m.getKey();
748a37b25d10 5091921: Sign flip issues in loop optimizer
kvn
parents:
diff changeset
    78
        int fallLeftDelta = 0, fallRightDelta = 0;
748a37b25d10 5091921: Sign flip issues in loop optimizer
kvn
parents:
diff changeset
    79
        //fall left
748a37b25d10 5091921: Sign flip issues in loop optimizer
kvn
parents:
diff changeset
    80
        int fallLeft = fall(digDown, start(q));
748a37b25d10 5091921: Sign flip issues in loop optimizer
kvn
parents:
diff changeset
    81
        if (fallLeft > 0) {
748a37b25d10 5091921: Sign flip issues in loop optimizer
kvn
parents:
diff changeset
    82
          fallLeftDelta = 1;
748a37b25d10 5091921: Sign flip issues in loop optimizer
kvn
parents:
diff changeset
    83
          if (fallLeft <= f) addToM(calcWalkingRange(digDown+fallLeft, start(q)), m.getValue());
748a37b25d10 5091921: Sign flip issues in loop optimizer
kvn
parents:
diff changeset
    84
        }
748a37b25d10 5091921: Sign flip issues in loop optimizer
kvn
parents:
diff changeset
    85
748a37b25d10 5091921: Sign flip issues in loop optimizer
kvn
parents:
diff changeset
    86
        //fall right
748a37b25d10 5091921: Sign flip issues in loop optimizer
kvn
parents:
diff changeset
    87
        int fallRight = fall(digDown, end(q));
748a37b25d10 5091921: Sign flip issues in loop optimizer
kvn
parents:
diff changeset
    88
        if (fallRight > 0) {
748a37b25d10 5091921: Sign flip issues in loop optimizer
kvn
parents:
diff changeset
    89
          fallRightDelta = 1;
748a37b25d10 5091921: Sign flip issues in loop optimizer
kvn
parents:
diff changeset
    90
748a37b25d10 5091921: Sign flip issues in loop optimizer
kvn
parents:
diff changeset
    91
          if (fallRight <= f) addToM(calcWalkingRange(digDown+fallRight, end(q)), m.getValue());
748a37b25d10 5091921: Sign flip issues in loop optimizer
kvn
parents:
diff changeset
    92
        }
748a37b25d10 5091921: Sign flip issues in loop optimizer
kvn
parents:
diff changeset
    93
748a37b25d10 5091921: Sign flip issues in loop optimizer
kvn
parents:
diff changeset
    94
        for (int p = start(q) + fallLeftDelta ; p <= end(q) - fallRightDelta ; p++) {
748a37b25d10 5091921: Sign flip issues in loop optimizer
kvn
parents:
diff changeset
    95
          //goLeft
748a37b25d10 5091921: Sign flip issues in loop optimizer
kvn
parents:
diff changeset
    96
          for (int digSpot = p ; digSpot > start(q) +fallLeftDelta ; digSpot--) {
748a37b25d10 5091921: Sign flip issues in loop optimizer
kvn
parents:
diff changeset
    97
            int fallDown = 1+fall(digDown+1, digSpot);
748a37b25d10 5091921: Sign flip issues in loop optimizer
kvn
parents:
diff changeset
    98
            if (fallDown <= f) {
748a37b25d10 5091921: Sign flip issues in loop optimizer
kvn
parents:
diff changeset
    99
              if (fallDown == 1) {
748a37b25d10 5091921: Sign flip issues in loop optimizer
kvn
parents:
diff changeset
   100
                addToM(calcWalkingRange(digDown + 1, digSpot, digSpot, p), m.getValue() + Math.abs(digSpot-p)+1);
748a37b25d10 5091921: Sign flip issues in loop optimizer
kvn
parents:
diff changeset
   101
              } else {
748a37b25d10 5091921: Sign flip issues in loop optimizer
kvn
parents:
diff changeset
   102
                addToM(calcWalkingRange(digDown + fallDown, digSpot), m.getValue() + Math.abs(digSpot-p)+1);
748a37b25d10 5091921: Sign flip issues in loop optimizer
kvn
parents:
diff changeset
   103
              }
748a37b25d10 5091921: Sign flip issues in loop optimizer
kvn
parents:
diff changeset
   104
            }
748a37b25d10 5091921: Sign flip issues in loop optimizer
kvn
parents:
diff changeset
   105
          }
748a37b25d10 5091921: Sign flip issues in loop optimizer
kvn
parents:
diff changeset
   106
748a37b25d10 5091921: Sign flip issues in loop optimizer
kvn
parents:
diff changeset
   107
          //goRight
748a37b25d10 5091921: Sign flip issues in loop optimizer
kvn
parents:
diff changeset
   108
          for (int digSpot = p ; digSpot < end(q)-fallRightDelta ;digSpot++) {
748a37b25d10 5091921: Sign flip issues in loop optimizer
kvn
parents:
diff changeset
   109
            int fallDown = 1+fall(digDown+1, digSpot);
748a37b25d10 5091921: Sign flip issues in loop optimizer
kvn
parents:
diff changeset
   110
            if (fallDown <= f) {
748a37b25d10 5091921: Sign flip issues in loop optimizer
kvn
parents:
diff changeset
   111
              if (fallDown == 1) {
748a37b25d10 5091921: Sign flip issues in loop optimizer
kvn
parents:
diff changeset
   112
                addToM(calcWalkingRange(digDown + 1, digSpot, p, digSpot), m.getValue() + Math.abs(digSpot-p)+1);
748a37b25d10 5091921: Sign flip issues in loop optimizer
kvn
parents:
diff changeset
   113
              } else {
748a37b25d10 5091921: Sign flip issues in loop optimizer
kvn
parents:
diff changeset
   114
                addToM(calcWalkingRange(digDown + fallDown, digSpot), m.getValue() + Math.abs(digSpot-p)+1);
748a37b25d10 5091921: Sign flip issues in loop optimizer
kvn
parents:
diff changeset
   115
              }
748a37b25d10 5091921: Sign flip issues in loop optimizer
kvn
parents:
diff changeset
   116
            }
748a37b25d10 5091921: Sign flip issues in loop optimizer
kvn
parents:
diff changeset
   117
          }
748a37b25d10 5091921: Sign flip issues in loop optimizer
kvn
parents:
diff changeset
   118
        }
748a37b25d10 5091921: Sign flip issues in loop optimizer
kvn
parents:
diff changeset
   119
      }
748a37b25d10 5091921: Sign flip issues in loop optimizer
kvn
parents:
diff changeset
   120
    }
748a37b25d10 5091921: Sign flip issues in loop optimizer
kvn
parents:
diff changeset
   121
748a37b25d10 5091921: Sign flip issues in loop optimizer
kvn
parents:
diff changeset
   122
    int result = Integer.MAX_VALUE;
748a37b25d10 5091921: Sign flip issues in loop optimizer
kvn
parents:
diff changeset
   123
    for (Map.Entry<Integer, Integer> m : M.entrySet()) {
748a37b25d10 5091921: Sign flip issues in loop optimizer
kvn
parents:
diff changeset
   124
      if (depth(m.getKey()) == r-1) result = Math.min(m.getValue(), result);
748a37b25d10 5091921: Sign flip issues in loop optimizer
kvn
parents:
diff changeset
   125
    }
748a37b25d10 5091921: Sign flip issues in loop optimizer
kvn
parents:
diff changeset
   126
748a37b25d10 5091921: Sign flip issues in loop optimizer
kvn
parents:
diff changeset
   127
    if (result == Integer.MAX_VALUE) return -1;
748a37b25d10 5091921: Sign flip issues in loop optimizer
kvn
parents:
diff changeset
   128
    return result;
748a37b25d10 5091921: Sign flip issues in loop optimizer
kvn
parents:
diff changeset
   129
  }
748a37b25d10 5091921: Sign flip issues in loop optimizer
kvn
parents:
diff changeset
   130
748a37b25d10 5091921: Sign flip issues in loop optimizer
kvn
parents:
diff changeset
   131
  private void addToM(int q, int i) {
748a37b25d10 5091921: Sign flip issues in loop optimizer
kvn
parents:
diff changeset
   132
    Integer original = M.get(q);
748a37b25d10 5091921: Sign flip issues in loop optimizer
kvn
parents:
diff changeset
   133
    if ( original == null ) M.put(q, i);
748a37b25d10 5091921: Sign flip issues in loop optimizer
kvn
parents:
diff changeset
   134
    else M.put(q, Math.min(original, i));
748a37b25d10 5091921: Sign flip issues in loop optimizer
kvn
parents:
diff changeset
   135
  }
748a37b25d10 5091921: Sign flip issues in loop optimizer
kvn
parents:
diff changeset
   136
748a37b25d10 5091921: Sign flip issues in loop optimizer
kvn
parents:
diff changeset
   137
  private int fall(int row, int column) {
748a37b25d10 5091921: Sign flip issues in loop optimizer
kvn
parents:
diff changeset
   138
    int res = 0;
748a37b25d10 5091921: Sign flip issues in loop optimizer
kvn
parents:
diff changeset
   139
    for ( int p = row+1 ; p < r ; p++) {
748a37b25d10 5091921: Sign flip issues in loop optimizer
kvn
parents:
diff changeset
   140
      if (grid[p][column] == AIR) res++;
748a37b25d10 5091921: Sign flip issues in loop optimizer
kvn
parents:
diff changeset
   141
      else break;
748a37b25d10 5091921: Sign flip issues in loop optimizer
kvn
parents:
diff changeset
   142
    }
748a37b25d10 5091921: Sign flip issues in loop optimizer
kvn
parents:
diff changeset
   143
    return res;
748a37b25d10 5091921: Sign flip issues in loop optimizer
kvn
parents:
diff changeset
   144
  }
748a37b25d10 5091921: Sign flip issues in loop optimizer
kvn
parents:
diff changeset
   145
748a37b25d10 5091921: Sign flip issues in loop optimizer
kvn
parents:
diff changeset
   146
  private boolean stuck(int q) {
748a37b25d10 5091921: Sign flip issues in loop optimizer
kvn
parents:
diff changeset
   147
    return start(q) == end(q);
748a37b25d10 5091921: Sign flip issues in loop optimizer
kvn
parents:
diff changeset
   148
  }
748a37b25d10 5091921: Sign flip issues in loop optimizer
kvn
parents:
diff changeset
   149
748a37b25d10 5091921: Sign flip issues in loop optimizer
kvn
parents:
diff changeset
   150
  private int depth(int q) {
748a37b25d10 5091921: Sign flip issues in loop optimizer
kvn
parents:
diff changeset
   151
    return q % 50;
748a37b25d10 5091921: Sign flip issues in loop optimizer
kvn
parents:
diff changeset
   152
  }
748a37b25d10 5091921: Sign flip issues in loop optimizer
kvn
parents:
diff changeset
   153
748a37b25d10 5091921: Sign flip issues in loop optimizer
kvn
parents:
diff changeset
   154
  private int start(int q) {
748a37b25d10 5091921: Sign flip issues in loop optimizer
kvn
parents:
diff changeset
   155
    return q / (50*50);
748a37b25d10 5091921: Sign flip issues in loop optimizer
kvn
parents:
diff changeset
   156
  }
748a37b25d10 5091921: Sign flip issues in loop optimizer
kvn
parents:
diff changeset
   157
748a37b25d10 5091921: Sign flip issues in loop optimizer
kvn
parents:
diff changeset
   158
  private int end(int q) {
748a37b25d10 5091921: Sign flip issues in loop optimizer
kvn
parents:
diff changeset
   159
    return (q / 50) % 50;
748a37b25d10 5091921: Sign flip issues in loop optimizer
kvn
parents:
diff changeset
   160
  }
748a37b25d10 5091921: Sign flip issues in loop optimizer
kvn
parents:
diff changeset
   161
748a37b25d10 5091921: Sign flip issues in loop optimizer
kvn
parents:
diff changeset
   162
  private int calcWalkingRange(int depth, int pos) {
748a37b25d10 5091921: Sign flip issues in loop optimizer
kvn
parents:
diff changeset
   163
    return calcWalkingRange(depth, pos, Integer.MAX_VALUE, Integer.MIN_VALUE);
748a37b25d10 5091921: Sign flip issues in loop optimizer
kvn
parents:
diff changeset
   164
  }
748a37b25d10 5091921: Sign flip issues in loop optimizer
kvn
parents:
diff changeset
   165
748a37b25d10 5091921: Sign flip issues in loop optimizer
kvn
parents:
diff changeset
   166
  private int calcWalkingRange(int depth, int pos, int airOverrideStart, int airOverrideEnd) {
748a37b25d10 5091921: Sign flip issues in loop optimizer
kvn
parents:
diff changeset
   167
    int left = pos, right = pos;
748a37b25d10 5091921: Sign flip issues in loop optimizer
kvn
parents:
diff changeset
   168
    if (depth >= r) return (c-1)*50 + depth;
748a37b25d10 5091921: Sign flip issues in loop optimizer
kvn
parents:
diff changeset
   169
748a37b25d10 5091921: Sign flip issues in loop optimizer
kvn
parents:
diff changeset
   170
    while (left > 0) {
748a37b25d10 5091921: Sign flip issues in loop optimizer
kvn
parents:
diff changeset
   171
      if (grid[depth][left-1] == ROCK && (left-1 < airOverrideStart || left-1 > airOverrideEnd)) break;
748a37b25d10 5091921: Sign flip issues in loop optimizer
kvn
parents:
diff changeset
   172
      if (depth < r-1 && grid[depth+1][left-1] == AIR) {
748a37b25d10 5091921: Sign flip issues in loop optimizer
kvn
parents:
diff changeset
   173
        left--;
748a37b25d10 5091921: Sign flip issues in loop optimizer
kvn
parents:
diff changeset
   174
        break;
748a37b25d10 5091921: Sign flip issues in loop optimizer
kvn
parents:
diff changeset
   175
      }
748a37b25d10 5091921: Sign flip issues in loop optimizer
kvn
parents:
diff changeset
   176
      left--;
748a37b25d10 5091921: Sign flip issues in loop optimizer
kvn
parents:
diff changeset
   177
    }
748a37b25d10 5091921: Sign flip issues in loop optimizer
kvn
parents:
diff changeset
   178
    while (right < c-1) {
748a37b25d10 5091921: Sign flip issues in loop optimizer
kvn
parents:
diff changeset
   179
      if (grid[depth][right+1] == ROCK && (right+1 < airOverrideStart || right+1 > airOverrideEnd)) break;
748a37b25d10 5091921: Sign flip issues in loop optimizer
kvn
parents:
diff changeset
   180
      if (depth < r-1 && grid[depth+1][right+1] == AIR) {
748a37b25d10 5091921: Sign flip issues in loop optimizer
kvn
parents:
diff changeset
   181
        right++;
748a37b25d10 5091921: Sign flip issues in loop optimizer
kvn
parents:
diff changeset
   182
        break;
748a37b25d10 5091921: Sign flip issues in loop optimizer
kvn
parents:
diff changeset
   183
      }
748a37b25d10 5091921: Sign flip issues in loop optimizer
kvn
parents:
diff changeset
   184
      right++;
748a37b25d10 5091921: Sign flip issues in loop optimizer
kvn
parents:
diff changeset
   185
    }
748a37b25d10 5091921: Sign flip issues in loop optimizer
kvn
parents:
diff changeset
   186
748a37b25d10 5091921: Sign flip issues in loop optimizer
kvn
parents:
diff changeset
   187
    return left *50*50 + right*50 + depth;
748a37b25d10 5091921: Sign flip issues in loop optimizer
kvn
parents:
diff changeset
   188
  }
748a37b25d10 5091921: Sign flip issues in loop optimizer
kvn
parents:
diff changeset
   189
}