PR rtl-optimization/88018
[official-gcc.git] / gcc / testsuite / c-c++-common / torture / vector-compare-1.c
blob4cdfcf718c128c8955065ea30837add085fe25db
1 /* { dg-do run } */
2 #define vector(elcount, type) \
3 __attribute__((vector_size((elcount)*sizeof(type)))) type
5 #define check_compare(count, res, i0, i1, op, fmt) \
6 do { \
7 int __i; \
8 for (__i = 0; __i < count; __i ++) { \
9 if ((res)[__i] != ((i0)[__i] op (i1)[__i] ? -1 : 0)) \
10 { \
11 __builtin_printf ("%i != ((" fmt " " #op " " fmt " ? -1 : 0) ", \
12 (res)[__i], (i0)[__i], (i1)[__i]); \
13 __builtin_abort (); \
14 } \
15 } \
16 } while (0)
18 #define test(count, v0, v1, res, fmt); \
19 do { \
20 res = (v0 > v1); \
21 check_compare (count, res, v0, v1, >, fmt); \
22 res = (v0 < v1); \
23 check_compare (count, res, v0, v1, <, fmt); \
24 res = (v0 >= v1); \
25 check_compare (count, res, v0, v1, >=, fmt); \
26 res = (v0 <= v1); \
27 check_compare (count, res, v0, v1, <=, fmt); \
28 res = (v0 == v1); \
29 check_compare (count, res, v0, v1, ==, fmt); \
30 res = (v0 != v1); \
31 check_compare (count, res, v0, v1, !=, fmt); \
32 } while (0)
35 int main (int argc, char *argv[]) {
36 #define INT int
37 vector (4, INT) i0;
38 vector (4, INT) i1;
39 vector (4, int) ires;
40 int i;
42 i0 = (vector (4, INT)){(INT)argc, 1, 2, 10};
43 i1 = (vector (4, INT)){0, 3, 2, (INT)-23};
44 test (4, i0, i1, ires, "%i");
45 #undef INT
47 #define INT unsigned int
48 vector (4, int) ures;
49 vector (4, INT) u0;
50 vector (4, INT) u1;
52 u0 = (vector (4, INT)){(INT)argc, 1, 2, 10};
53 u1 = (vector (4, INT)){0, 3, 2, (INT)-23};
54 test (4, u0, u1, ures, "%u");
55 #undef INT
58 #define SHORT short
59 vector (8, SHORT) s0;
60 vector (8, SHORT) s1;
61 vector (8, short) sres;
63 s0 = (vector (8, SHORT)){(SHORT)argc, 1, 2, 10, 6, 87, (SHORT)-5, 2};
64 s1 = (vector (8, SHORT)){0, 3, 2, (SHORT)-23, 12, 10, (SHORT)-2, 0};
65 test (8, s0, s1, sres, "%i");
66 #undef SHORT
68 #define SHORT unsigned short
69 vector (8, SHORT) us0;
70 vector (8, SHORT) us1;
71 vector (8, short) usres;
73 us0 = (vector (8, SHORT)){(SHORT)argc, 1, 2, 10, 6, 87, (SHORT)-5, 2};
74 us1 = (vector (8, SHORT)){0, 3, 2, (SHORT)-23, 12, 10, (SHORT)-2, 0};
75 test (8, us0, us1, usres, "%u");
76 #undef SHORT
78 #define CHAR signed char
79 vector (16, CHAR) c0;
80 vector (16, CHAR) c1;
81 vector (16, signed char) cres;
83 c0 = (vector (16, CHAR)){(CHAR)argc, 1, 2, 10, 6, 87, (CHAR)-5, 2, \
84 (CHAR)argc, 1, 2, 10, 6, 87, (CHAR)-5, 2 };
86 c1 = (vector (16, CHAR)){0, 3, 2, (CHAR)-23, 12, 10, (CHAR)-2, 0, \
87 0, 3, 2, (CHAR)-23, 12, 10, (CHAR)-2, 0};
88 test (16, c0, c1, cres, "%i");
89 #undef CHAR
91 #define CHAR unsigned char
92 vector (16, CHAR) uc0;
93 vector (16, CHAR) uc1;
94 vector (16, signed char) ucres;
96 uc0 = (vector (16, CHAR)){(CHAR)argc, 1, 2, 10, 6, 87, (CHAR)-5, 2, \
97 (CHAR)argc, 1, 2, 10, 6, 87, (CHAR)-5, 2 };
99 uc1 = (vector (16, CHAR)){0, 3, 2, (CHAR)-23, 12, 10, (CHAR)-2, 0, \
100 0, 3, 2, (CHAR)-23, 12, 10, (CHAR)-2, 0};
101 test (16, uc0, uc1, ucres, "%u");
102 #undef CHAR
103 /* Float comparison. */
104 vector (4, float) f0;
105 vector (4, float) f1;
106 __typeof (f0 == f1) ifres;
108 f0 = (vector (4, float)){(float)argc, 1., 2., 10.};
109 f1 = (vector (4, float)){0., 3., 2., (float)-23};
110 test (4, f0, f1, ifres, "%f");
112 /* Double comparison. */
113 vector (2, double) d0;
114 vector (2, double) d1;
115 __typeof (d0 == d1) idres;
117 d0 = (vector (2, double)){(double)argc, 10.};
118 d1 = (vector (2, double)){0., (double)-23};
119 test (2, d0, d1, idres, "%f");
122 return 0;