2 #define vector(elcount, type) \
3 __attribute__((vector_size((elcount)*sizeof(type)))) type
5 #define check_compare(count, res, i0, i1, op, fmt) \
8 for (__i = 0; __i < count; __i ++) { \
9 if ((res)[__i] != ((i0)[__i] op (i1)[__i] ? -1 : 0)) \
11 __builtin_printf ("%i != ((" fmt " " #op " " fmt " ? -1 : 0) ", \
12 (res)[__i], (i0)[__i], (i1)[__i]); \
18 #define test(count, v0, v1, res, fmt); \
21 check_compare (count, res, v0, v1, >, fmt); \
23 check_compare (count, res, v0, v1, <, fmt); \
25 check_compare (count, res, v0, v1, >=, fmt); \
27 check_compare (count, res, v0, v1, <=, fmt); \
29 check_compare (count, res, v0, v1, ==, fmt); \
31 check_compare (count, res, v0, v1, !=, fmt); \
35 int main (int argc
, char *argv
[]) {
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");
47 #define INT unsigned int
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");
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");
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");
78 #define CHAR signed char
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");
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");
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");