File: vector-compare-1.c

package info (click to toggle)
gcc-arm-none-eabi 15%3A12.2.rel1-1
  • links: PTS, VCS
  • area: main
  • in suites: bookworm
  • size: 959,712 kB
  • sloc: cpp: 3,275,382; ansic: 2,061,766; ada: 840,956; f90: 208,513; makefile: 76,132; asm: 73,433; xml: 50,448; exp: 34,146; sh: 32,436; objc: 15,637; fortran: 14,012; python: 11,991; pascal: 6,787; awk: 4,779; perl: 3,054; yacc: 338; ml: 285; lex: 201; haskell: 122
file content (124 lines) | stat: -rw-r--r-- 3,584 bytes parent folder | download | duplicates (10)
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
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
/* { dg-do run } */
#define vector(elcount, type)  \
__attribute__((vector_size((elcount)*sizeof(type)))) type

#define check_compare(count, res, i0, i1, op, fmt) \
do { \
    int __i; \
    for (__i = 0; __i < count; __i ++) { \
      if ((res)[__i] != ((i0)[__i] op (i1)[__i] ? -1 : 0)) \
	{ \
            __builtin_printf ("%i != ((" fmt " " #op " " fmt " ? -1 : 0) ", \
			      (res)[__i], (i0)[__i], (i1)[__i]); \
            __builtin_abort (); \
        } \
    } \
} while (0)

#define test(count, v0, v1, res, fmt); \
do { \
    res = (v0 > v1); \
    check_compare (count, res, v0, v1, >, fmt); \
    res = (v0 < v1); \
    check_compare (count, res, v0, v1, <, fmt); \
    res = (v0 >= v1); \
    check_compare (count, res, v0, v1, >=, fmt); \
    res = (v0 <= v1); \
    check_compare (count, res, v0, v1, <=, fmt); \
    res = (v0 == v1); \
    check_compare (count, res, v0, v1, ==, fmt); \
    res = (v0 != v1); \
    check_compare (count, res, v0, v1, !=, fmt); \
} while (0)


int main (int argc, char *argv[]) {
#define INT  int
    vector (4, INT) i0;
    vector (4, INT) i1;
    vector (4, int) ires;
    int i;

    i0 = (vector (4, INT)){(INT)argc, 1,  2,  10};
    i1 = (vector (4, INT)){0, 3, 2, (INT)-23};
    test (4, i0, i1, ires, "%i");
#undef INT

#define INT unsigned int
    vector (4, int) ures;
    vector (4, INT) u0;
    vector (4, INT) u1;

    u0 = (vector (4, INT)){(INT)argc, 1,  2,  10};
    u1 = (vector (4, INT)){0, 3, 2, (INT)-23};
    test (4, u0, u1, ures, "%u");
#undef INT


#define SHORT short
    vector (8, SHORT) s0;
    vector (8, SHORT) s1;
    vector (8, short) sres;

    s0 = (vector (8, SHORT)){(SHORT)argc, 1,  2,  10,  6, 87, (SHORT)-5, 2};
    s1 = (vector (8, SHORT)){0, 3, 2, (SHORT)-23, 12, 10, (SHORT)-2, 0};
    test (8, s0, s1, sres, "%i");
#undef SHORT

#define SHORT unsigned short
    vector (8, SHORT) us0;
    vector (8, SHORT) us1;
    vector (8, short) usres;

    us0 = (vector (8, SHORT)){(SHORT)argc, 1,  2,  10,  6, 87, (SHORT)-5, 2};
    us1 = (vector (8, SHORT)){0, 3, 2, (SHORT)-23, 12, 10, (SHORT)-2, 0};
    test (8, us0, us1, usres, "%u");
#undef SHORT

#define CHAR signed char
    vector (16, CHAR) c0;
    vector (16, CHAR) c1;
    vector (16, signed char) cres;

    c0 = (vector (16, CHAR)){(CHAR)argc, 1,  2,  10,  6, 87, (CHAR)-5, 2, \
                             (CHAR)argc, 1,  2,  10,  6, 87, (CHAR)-5, 2 };

    c1 = (vector (16, CHAR)){0, 3, 2, (CHAR)-23, 12, 10, (CHAR)-2, 0, \
                             0, 3, 2, (CHAR)-23, 12, 10, (CHAR)-2, 0};
    test (16, c0, c1, cres, "%i");
#undef CHAR

#define CHAR unsigned char
    vector (16, CHAR) uc0;
    vector (16, CHAR) uc1;
    vector (16, signed char) ucres;

    uc0 = (vector (16, CHAR)){(CHAR)argc, 1,  2,  10,  6, 87, (CHAR)-5, 2, \
                              (CHAR)argc, 1,  2,  10,  6, 87, (CHAR)-5, 2 };

    uc1 = (vector (16, CHAR)){0, 3, 2, (CHAR)-23, 12, 10, (CHAR)-2, 0, \
                             0, 3, 2, (CHAR)-23, 12, 10, (CHAR)-2, 0};
    test (16, uc0, uc1, ucres, "%u");
#undef CHAR
/* Float comparison.  */
    vector (4, float) f0;
    vector (4, float) f1;
    __typeof (f0 == f1) ifres;

    f0 = (vector (4, float)){(float)argc, 1.,  2.,  10.};
    f1 = (vector (4, float)){0., 3., 2., (float)-23};
    test (4, f0, f1, ifres, "%f");

/* Double comparison.  */
    vector (2, double) d0;
    vector (2, double) d1;
    __typeof (d0 == d1) idres;

    d0 = (vector (2, double)){(double)argc,  10.};
    d1 = (vector (2, double)){0., (double)-23};
    test (2, d0, d1, idres, "%f");


    return 0;
}