From: Matthias Braun Date: Tue, 26 Sep 2006 13:14:01 +0000 (+0000) Subject: more handoptimisation X-Git-Url: http://nsz.repo.hu/git/?a=commitdiff_plain;h=0b5c6b380615b36799e1d5c1a0126167f1770b6b;p=libfirm more handoptimisation --- diff --git a/ir/be/test/queens-handoptimized.c b/ir/be/test/queens-handoptimized.c index b9bf0c147..14b83a1e8 100644 --- a/ir/be/test/queens-handoptimized.c +++ b/ir/be/test/queens-handoptimized.c @@ -39,7 +39,8 @@ static inline boolean place_ok (int i, const int *r, int ri) { boolean res; while (j < i) { - if ((r[j] == ri) || ((myabs(ri-r[j])) == (i-j))) { + int rj = r[j]; + if ((rj == ri) || ((myabs(ri-rj)) == (i-j))) { res = false; return(res); } @@ -59,27 +60,26 @@ int solve (int n) { row = malloc(sizeof(*row) * n); row[0] = -1; while (c >= 0) { - int ri; -#if 1 + int rc = row[c]; + do { - row[c] = ri = row[c]+1; - } while ((ri < n) && (!place_ok(c, row, ri))); -#else - row[c] = row[c]+1; - while ((row[c] < n) && (!place_ok(c, row))) { - row[c] = row[c]+1; - } -#endif - if (row[c] < n) { // successfully placed at (c,row[c]) + rc++; + } while ((rc < n) && (!place_ok(c, row, rc))); + + if (rc < n) { // successfully placed at (c,row[c]) + row[c] = rc; + if (c == n-1) res = res+1; else { c = c+1; row[c] = -1; } + continue; } - else // dead end, track back - c = c-1; + + row[c] = rc; + c = c-1; } free(row);