Debian Codegraph @

gcc/testsuite/gcc.target/riscv/rvv/autovec/reduc/reduc-1.c

raw
1 /* { dg-do compile } */
2 /* { dg-additional-options "-march=rv32gcv_zvfh -mabi=ilp32d -mrvv-vector-bits=scalable -ffast-math -fno-vect-cost-model" } */
3
4 #include <stdint-gcc.h>
5
6 #define DEF_REDUC_PLUS(TYPE) \
7 TYPE __attribute__ ((noinline, noclone)) \
8 reduc_plus_##TYPE (TYPE *a, int n) \
9 { \
10 TYPE r = 0; \
11 for (int i = 0; i < n; ++i) \
12 r += a[i]; \
13 return r; \
14 }
15
16 #define TEST_PLUS(T) \
17 T (int8_t) \
18 T (int16_t) \
19 T (int32_t) \
20 T (int64_t) \
21 T (uint8_t) \
22 T (uint16_t) \
23 T (uint32_t) \
24 T (uint64_t) \
25 T (_Float16) \
26 T (float) \
27 T (double)
28
29 TEST_PLUS (DEF_REDUC_PLUS)
30
31 #define DEF_REDUC_MAXMIN(TYPE, NAME, CMP_OP) \
32 TYPE __attribute__ ((noinline, noclone)) \
33 reduc_##NAME##_##TYPE (TYPE *a, int n) \
34 { \
35 TYPE r = 13; \
36 for (int i = 0; i < n; ++i) \
37 r = a[i] CMP_OP r ? a[i] : r; \
38 return r; \
39 }
40
41 #define TEST_MAXMIN(T) \
42 T (int8_t, max, >) \
43 T (int16_t, max, >) \
44 T (int32_t, max, >) \
45 T (int64_t, max, >) \
46 T (uint8_t, max, >) \
47 T (uint16_t, max, >) \
48 T (uint32_t, max, >) \
49 T (uint64_t, max, >) \
50 T (_Float16, max, >) \
51 T (float, max, >) \
52 T (double, max, >) \
53 \
54 T (int8_t, min, <) \
55 T (int16_t, min, <) \
56 T (int32_t, min, <) \
57 T (int64_t, min, <) \
58 T (uint8_t, min, <) \
59 T (uint16_t, min, <) \
60 T (uint32_t, min, <) \
61 T (uint64_t, min, <) \
62 T (_Float16, min, <) \
63 T (float, min, <) \
64 T (double, min, <)
65
66 TEST_MAXMIN (DEF_REDUC_MAXMIN)
67
68 #define DEF_REDUC_BITWISE(TYPE, NAME, BIT_OP) \
69 TYPE __attribute__ ((noinline, noclone)) \
70 reduc_##NAME##_##TYPE (TYPE *a, int n) \
71 { \
72 TYPE r = 13; \
73 for (int i = 0; i < n; ++i) \
74 r BIT_OP a[i]; \
75 return r; \
76 }
77
78 #define TEST_BITWISE(T) \
79 T (int8_t, and, &=) \
80 T (int16_t, and, &=) \
81 T (int32_t, and, &=) \
82 T (int64_t, and, &=) \
83 T (uint8_t, and, &=) \
84 T (uint16_t, and, &=) \
85 T (uint32_t, and, &=) \
86 T (uint64_t, and, &=) \
87 \
88 T (int8_t, ior, |=) \
89 T (int16_t, ior, |=) \
90 T (int32_t, ior, |=) \
91 T (int64_t, ior, |=) \
92 T (uint8_t, ior, |=) \
93 T (uint16_t, ior, |=) \
94 T (uint32_t, ior, |=) \
95 T (uint64_t, ior, |=) \
96 \
97 T (int8_t, xor, ^=) \
98 T (int16_t, xor, ^=) \
99 T (int32_t, xor, ^=) \
100 T (int64_t, xor, ^=) \
101 T (uint8_t, xor, ^=) \
102 T (uint16_t, xor, ^=) \
103 T (uint32_t, xor, ^=) \
104 T (uint64_t, xor, ^=)
105
106 TEST_BITWISE (DEF_REDUC_BITWISE)
107
108 /* { dg-final { scan-assembler-times {vredsum\.vs\s+v[0-9]+,\s*v[0-9]+,\s*v[0-9]+} 8 } } */
109 /* { dg-final { scan-assembler-times {vredmax\.vs\s+v[0-9]+,\s*v[0-9]+,\s*v[0-9]+} 4 } } */
110 /* { dg-final { scan-assembler-times {vredmaxu\.vs\s+v[0-9]+,\s*v[0-9]+,\s*v[0-9]+} 4 } } */
111 /* { dg-final { scan-assembler-times {vredmin\.vs\s+v[0-9]+,\s*v[0-9]+,\s*v[0-9]+} 4 } } */
112 /* { dg-final { scan-assembler-times {vredminu\.vs\s+v[0-9]+,\s*v[0-9]+,\s*v[0-9]+} 4 } } */
113 /* { dg-final { scan-assembler-times {vredand\.vs\s+v[0-9]+,\s*v[0-9]+,\s*v[0-9]+} 8 } } */
114 /* { dg-final { scan-assembler-times {vredor\.vs\s+v[0-9]+,\s*v[0-9]+,\s*v[0-9]+} 8 } } */
115 /* { dg-final { scan-assembler-times {vredxor\.vs\s+v[0-9]+,\s*v[0-9]+,\s*v[0-9]+} 8 } } */
116 /* { dg-final { scan-assembler-times {vfredusum\.vs\s+v[0-9]+,\s*v[0-9]+,\s*v[0-9]+} 3 } } */
117 /* { dg-final { scan-assembler-times {vfredmax\.vs\s+v[0-9]+,\s*v[0-9]+,\s*v[0-9]+} 3 } } */
118 /* { dg-final { scan-assembler-times {vfredmin\.vs\s+v[0-9]+,\s*v[0-9]+,\s*v[0-9]+} 3 } } */