1 /* { dg-do run } */
2 /* { dg-options "-O2 --save-temps -fno-inline" } */
3
4 extern void abort (void);
5
6 int
ands_si_test1(int a,int b,int c)7 ands_si_test1 (int a, int b, int c)
8 {
9 int d = a & b;
10
11 /* { dg-final { scan-assembler-times "ands\tw\[0-9\]+, w\[0-9\]+, w\[0-9\]+" 2 } } */
12 if (d == 0)
13 return a + c;
14 else
15 return d;
16 }
17
18 int
ands_si_test2(int a,int b,int c)19 ands_si_test2 (int a, int b, int c)
20 {
21 int d = a & 0xff;
22
23 /* { dg-final { scan-assembler "ands\tw\[0-9\]+, w\[0-9\]+, 255" } } */
24 if (d == 0)
25 return a + c;
26 else
27 return d;
28 }
29
30 int
ands_si_test3(int a,int b,int c)31 ands_si_test3 (int a, int b, int c)
32 {
33 int d = a & (b << 3);
34
35 /* { dg-final { scan-assembler "ands\tw\[0-9\]+, w\[0-9\]+, w\[0-9\]+, lsl 3" } } */
36 if (d == 0)
37 return a + c;
38 else
39 return d;
40 }
41
42 typedef long long s64;
43
44 s64
ands_di_test1(s64 a,s64 b,s64 c)45 ands_di_test1 (s64 a, s64 b, s64 c)
46 {
47 s64 d = a & b;
48
49 /* { dg-final { scan-assembler-times "ands\tx\[0-9\]+, x\[0-9\]+, x\[0-9\]+" 2 } } */
50 if (d == 0)
51 return a + c;
52 else
53 return d;
54 }
55
56 s64
ands_di_test2(s64 a,s64 b,s64 c)57 ands_di_test2 (s64 a, s64 b, s64 c)
58 {
59 s64 d = a & 0xff;
60
61 /* { dg-final { scan-assembler "ands\tx\[0-9\]+, x\[0-9\]+, 255" } } */
62 if (d == 0)
63 return a + c;
64 else
65 return d;
66 }
67
68 s64
ands_di_test3(s64 a,s64 b,s64 c)69 ands_di_test3 (s64 a, s64 b, s64 c)
70 {
71 s64 d = a & (b << 3);
72
73 /* { dg-final { scan-assembler "ands\tx\[0-9\]+, x\[0-9\]+, x\[0-9\]+, lsl 3" } } */
74 if (d == 0)
75 return a + c;
76 else
77 return d;
78 }
79
80 int
main()81 main ()
82 {
83 int x;
84 s64 y;
85
86 x = ands_si_test1 (29, 4, 5);
87 if (x != (29 & 4))
88 abort ();
89
90 x = ands_si_test1 (5, 2, 20);
91 if (x != 25)
92 abort ();
93
94 x = ands_si_test2 (29, 4, 5);
95 if (x != (29 & 0xff))
96 abort ();
97
98 x = ands_si_test2 (1024, 2, 20);
99 if (x != 1044)
100 abort ();
101
102 x = ands_si_test3 (35, 4, 5);
103 if (x != (35 & (4 << 3)))
104 abort ();
105
106 x = ands_si_test3 (5, 2, 20);
107 if (x != 25)
108 abort ();
109
110 y = ands_di_test1 (0x130000029ll,
111 0x320000004ll,
112 0x505050505ll);
113
114 if (y != ((0x130000029ll & 0x320000004ll)))
115 abort ();
116
117 y = ands_di_test1 (0x5000500050005ll,
118 0x2111211121112ll,
119 0x0000000002020ll);
120 if (y != 0x5000500052025ll)
121 abort ();
122
123 y = ands_di_test2 (0x130000029ll,
124 0x320000004ll,
125 0x505050505ll);
126 if (y != ((0x130000029ll & 0xff)))
127 abort ();
128
129 y = ands_di_test2 (0x130002900ll,
130 0x320000004ll,
131 0x505050505ll);
132 if (y != (0x130002900ll + 0x505050505ll))
133 abort ();
134
135 y = ands_di_test3 (0x130000029ll,
136 0x064000008ll,
137 0x505050505ll);
138 if (y != ((0x130000029ll & (0x064000008ll << 3))))
139 abort ();
140
141 y = ands_di_test3 (0x130002900ll,
142 0x088000008ll,
143 0x505050505ll);
144 if (y != (0x130002900ll + 0x505050505ll))
145 abort ();
146
147 return 0;
148 }
149
150