1 /* Tests to check the utilization of the addc and subc instructions.
2 If everything works as expected we won't see any movt instructions in
3 these cases. */
4 /* { dg-do compile } */
5 /* { dg-options "-O2" } */
6 /* { dg-skip-if "" { "sh*-*-*" } { "-m5*"} { "" } } */
7 /* { dg-final { scan-assembler-times "addc" 4 } } */
8 /* { dg-final { scan-assembler-times "subc" 5 } } */
9 /* { dg-final { scan-assembler-times "movt" 1 } } */
10 /* { dg-final { scan-assembler-times "sub\t" 1 } } */
11 /* { dg-final { scan-assembler-times "neg\t" 2 } } */
12
13 int
test_000(int * x,unsigned int c)14 test_000 (int* x, unsigned int c)
15 {
16 /* 1x addc */
17 int s = 0;
18 unsigned int i;
19 for (i = 0; i < c; ++i)
20 s += ! (x[i] & 0x3000);
21 return s;
22 }
23
24 int
test_001(int * x,unsigned int c)25 test_001 (int* x, unsigned int c)
26 {
27 /* 1x subc */
28 int s = 0;
29 unsigned int i;
30 for (i = 0; i < c; ++i)
31 s -= ! (x[i] & 0x3000);
32 return s;
33 }
34
35 int
test_002(int a,int b,int c)36 test_002 (int a, int b, int c)
37 {
38 /* 1x tst, 1x subc */
39 return ((a & b) != 0) - c;
40 }
41
42 int
test_003(int a,int b,int c)43 test_003 (int a, int b, int c)
44 {
45 /* 1x tst, 1x movt, 1x sub */
46 return ((a & b) == 0) - c;
47 }
48
49 int
test_004(int a,int b,int c)50 test_004 (int a, int b, int c)
51 {
52 /* 1x tst, 1x addc */
53 return c - ((a & b) != 0);
54 }
55
56 int
test_005(int a,int b,int c)57 test_005 (int a, int b, int c)
58 {
59 /* 1x shll, 1x subc */
60 int x = a < 0;
61 return c - (b + x);
62 }
63
64 int
test_006(int a,int b,int c)65 test_006 (int a, int b, int c)
66 {
67 /* 1x neg, 1x cmp/pl, 1x addc */
68 int x = a > 0;
69 int y = b + x;
70 return y - c;
71 }
72
73 int
test_007(int a,int b,int c)74 test_007 (int a, int b, int c)
75 {
76 /* 1x add #-1, 1x cmp/eq, 1x addc */
77 int x = a != 1;
78 int y = b - x;
79 return c + y;
80 }
81
82 int
test_008(int a,int b,int c)83 test_008 (int a, int b, int c)
84 {
85 /* 1x neg, 1x cmp/gt, 1x subc */
86 int x = a > 1;
87 int y = b - x;
88 return c + y;
89 }
90
91 int
test_009(int a,int b,int c,int d)92 test_009 (int a, int b, int c, int d)
93 {
94 /* 1x div0s, 1x subc */
95 return c - d - (a < 0 != b < 0);
96 }
97