improve address mode tests
authorMatthias Braun <matze@braunis.de>
Fri, 31 Aug 2007 14:44:35 +0000 (14:44 +0000)
committerMatthias Braun <matze@braunis.de>
Fri, 31 Aug 2007 14:44:35 +0000 (14:44 +0000)
[r15639]

ir/be/test/am_test.c
ir/be/test/am_test2.c
ir/be/test/am_test3.c
ir/be/test/am_test4.c

index 7b454c5..08ac1ce 100644 (file)
@@ -1,18 +1,46 @@
-void am_test_func(int a, int b) {
-       int ar[10];
-       int i;
+/*$ -fno-inline $*/
 
-       for (i = 0; i < 10; i++) {
-               ar[i] = i;
-       }
+int val;
 
-       i = ar[1];
+#define T(name,OP) \
+       int test_##name(void) { return val OP 7; }   \
+       int test2_##name(int v) { return val OP v; }  \
+       int testp_##name(void) { return 7 OP val; }  \
+       int testp2_##name(int v) { return v OP val; }
 
-       ar[1] = a * b + i;
-}
+int test_cmp_testset(int v, int v2) { return (v & 14) > 0; }
+
+T(add,+)
+T(sub,-)
+T(or,|)
+T(and,&)
+T(xor,^)
+T(cmp,<)
+T(shl,<<)
+T(shr,>>)
+
+#undef T
+
+int main(void) {
+       int res1, res2, res3, res4;
+       val = 11;
+
+#define T(name,OP)          \
+       res1 = test_##name();   \
+       res2 = test2_##name(20); \
+       res3 = testp_##name();   \
+       res4 = testp2_##name(20); \
+       printf("Test %s: %d (should be %d)\n", #name, res1, 11 OP 7);   \
+       printf("Test2 %s: %d (should be %d)\n", #name, res2, 11 OP 20); \
+       printf("Testp %s: %d (should be %d)\n", #name, res3, 7 OP 11);   \
+       printf("Testp2 %s: %d (should be %d)\n", #name, res4, 20 OP 11);
 
-int main()
-{
-    am_test_func(0, 0);
-    return 0;
+       T(add,+)
+       T(sub,-)
+       T(or,|)
+       T(and,&)
+       T(xor,^)
+       T(cmp,<)
+       T(shl,<<)
+       T(shr,>>)
 }
index 2e628a7..88b9108 100644 (file)
@@ -3,14 +3,15 @@
 int arr[10] = { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 };
 
 int sum(int from, int to) {
-       int i, res = 0;
+       int i, res = 0, res2 = 666;
        int len = to - from;
 
        for(i = 0; i < len; ++i) {
-               res += arr[from + i];
+               res  += arr[from + i];
+               res2 -= arr[i];
        }
 
-       return res;
+       return res ^ res2;
 }
 
 int main(int argc, char **argv) {
@@ -19,6 +20,6 @@ int main(int argc, char **argv) {
        if(argc > 1)
                to = atoi(argv[1]);
 
-       printf("Sum: %d\n", sum(from, to));
+       printf("Res: %d\n", sum(from, to));
        return 0;
 }
index 6f9993a..52ce510 100644 (file)
@@ -1,16 +1,19 @@
-int arr[10] = { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 };
+/*$ -fno-inline $*/
 
-int sum(int c) {
+char arr[] = { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17,
+               18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30 };
+
+int sum(int c, int offs) {
        int i, res = 0;
 
        for(i = 0; i < c; ++i) {
-               res += i;
+               res += arr[i * 2 + offs + 2];
        }
 
        return res;
 }
 
 int main(void) {
-       printf("Sum: %d\n", sum(10));
+       printf("Sum: %d\n", sum(10, 0));
        return 0;
 }
index e83d9c2..97d4e63 100644 (file)
@@ -16,36 +16,46 @@ char f4(char *p, int k) {
        return p[k];
 }
 
-void dest_am(int *arr, int from, int to) {
-       int i;
-
-       for(i = from + 1; i < to; ++i) {
-               arr[i] += arr[i-1];
-       }
+#define T(name, OP, OP2) \
+void dest_am_##name(int *arr, int from, int to) {  \
+       int i;                                  \
+                                            \
+       for(i = from; i < to; ++i) {            \
+               arr[i] = OP arr[i] OP2;             \
+       }                                       \
 }
 
-void dest_am2(int *arr, int from, int to) {
-       int i;
-
-       for(i = from + 1; i < to; ++i) {
-               arr[i] = -arr[i];
-       }
-}
+T(neg, -,)
+T(not, ~,)
+T(add, 3 +,)
+T(sub, , - 42)
+T(and, 0x12345 &,)
+T(or, 0x12345 |,)
+T(xor, 0x12345 ^,)
+T(inc, 1 + ,)
+T(dec, , - 1)
+T(shl, , << 3)
+T(shr, , >> 3)
 
 int main(void) {
        int arr[] = { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 };
        int i;
 
-       dest_am(arr, 0, 10);
-       for(i = 0; i < 10; ++i) {
-               printf("%d ", arr[i]);
-       }
-       printf("\n");
-       dest_am2(arr, 0, 10);
-       for(i = 0; i < 10; ++i) {
-               printf("%d ", arr[i]);
-       }
+#define C(name)   dest_am_##name(arr, 0, 10); \
+       for(i = 0; i < 10; ++i) {                 \
+               printf("%d ", arr[i]);                \
+       }                                         \
        printf("\n");
 
+       C(neg);
+       C(not);
+       C(add);
+       C(sub);
+       C(and);
+       C(or);
+       C(inc);
+       C(dec);
+       C(xor);
+
        return 0;
 }