-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,>>)
}
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) {
if(argc > 1)
to = atoi(argv[1]);
- printf("Sum: %d\n", sum(from, to));
+ printf("Res: %d\n", sum(from, to));
return 0;
}
-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;
}
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;
}