projects
/
libfirm
/ blobdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
|
commitdiff
|
tree
raw
|
inline
| side by side
Use symbolic names instead of magic values for the position parameter of get_irn_n().
[libfirm]
/
ir
/
be
/
test
/
queens-handoptimized.c
diff --git
a/ir/be/test/queens-handoptimized.c
b/ir/be/test/queens-handoptimized.c
index
14b83a1
..
0f71a4a
100644
(file)
--- a/
ir/be/test/queens-handoptimized.c
+++ b/
ir/be/test/queens-handoptimized.c
@@
-26,7
+26,7
@@
typedef int boolean;
//static int *row;
// queen in column c is at row[c]
//static int *row;
// queen in column c is at row[c]
-static in
line in
t myabs(int i) {
+static int myabs(int i) {
if(0 > i)
i = -i;
return(i);
if(0 > i)
i = -i;
return(i);
@@
-38,6
+38,22
@@
static inline boolean place_ok (int i, const int *r, int ri) {
int j = 0;
boolean res;
int j = 0;
boolean res;
+#if 0
+ if(0 >= i)
+ return true;
+
+ do {
+ int rj = r[j];
+ if ((rj == ri) || ((myabs(ri-rj)) == (i-j))) {
+ res = false;
+ return(res);
+ }
+ j = j+1;
+ } while(j < i);
+
+ res = true;
+ return(res);
+#else
while (j < i) {
int rj = r[j];
if ((rj == ri) || ((myabs(ri-rj)) == (i-j))) {
while (j < i) {
int rj = r[j];
if ((rj == ri) || ((myabs(ri-rj)) == (i-j))) {
@@
-49,25
+65,26
@@
static inline boolean place_ok (int i, const int *r, int ri) {
res = true;
return(res);
res = true;
return(res);
+#endif
}
int solve (int n) {
// return the number of solutions to the n-queens problem
int c = 0;
int res = 0;
}
int solve (int n) {
// return the number of solutions to the n-queens problem
int c = 0;
int res = 0;
-
int *row;
+ int *row;
row = malloc(sizeof(*row) * n);
row[0] = -1;
while (c >= 0) {
row = malloc(sizeof(*row) * n);
row[0] = -1;
while (c >= 0) {
-
int rc = row[c];
+ int rc = row[c];
do {
do {
-
rc++;
+ rc++;
} while ((rc < n) && (!place_ok(c, row, rc)));
if (rc < n) { // successfully placed at (c,row[c])
} while ((rc < n) && (!place_ok(c, row, rc)));
if (rc < n) { // successfully placed at (c,row[c])
-
row[c] = rc;
+ row[c] = rc;
if (c == n-1)
res = res+1;
if (c == n-1)
res = res+1;
@@
-75,11
+92,11
@@
int solve (int n) {
c = c+1;
row[c] = -1;
}
c = c+1;
row[c] = -1;
}
-
continue;
+ continue;
}
}
-
row[c] = rc;
-
c = c-1;
+ row[c] = rc;
+ c = c-1;
}
free(row);
}
free(row);