Debian Codegraph @

gcc/testsuite/gcc.target/riscv/rvv/base/abi-call-args-4-run.c

raw
1 /* { dg-do run { target { riscv_v } } } */
2 /* { dg-options "-O1" } */
3 /* { dg-additional-sources abi-call-args-4.c } */
4
5 #include <stdbool.h>
6 #include <stdlib.h>
7 #include <string.h>
8 #include <stdio.h>
9 #include <stdint-gcc.h>
10 #include "riscv_vector.h"
11
12 vint64m8_t
13 foo1 (vint8m1_t a1, vint8m1_t a2, vint16m2_t b1, vint32m4_t c1, vint64m8_t d1,
14 size_t vl);
15 vint64m8_t
16 foo2 (vint8m1_t a1, vint16m2_t b1, vint8m1_t a2, vint32m4_t c1, vint64m8_t d1,
17 size_t vl);
18 vint64m8_t
19 foo3 (vint8m1_t a1, vint16m2_t b1, vint32m4_t c1, vint8m1_t a2, vint64m8_t d1,
20 size_t vl);
21 vint64m8_t
22 foo4 (vint8m1_t a1, vint16m2_t b1, vint32m4_t c1, vint64m8_t d1, vint8m1_t a2,
23 size_t vl);
24
25 vint8m1x8_t
26 foo5 (vint8m8_t a1, vint8m1x8_t a2);
27
28 int
29 main ()
30 {
31 size_t vlmax_e8m1 = __riscv_vsetvlmax_e8m1 ();
32 int8_t a1[vlmax_e8m1], a2[vlmax_e8m1];
33 int16_t b1[vlmax_e8m1], b2[vlmax_e8m1];
34 int32_t c1[vlmax_e8m1], c2[vlmax_e8m1];
35 int64_t d1[vlmax_e8m1], d2[vlmax_e8m1];
36 memset (a1, 0, vlmax_e8m1 * sizeof (int8_t));
37 memset (a2, 0, vlmax_e8m1 * sizeof (int8_t));
38 memset (b1, 0, vlmax_e8m1 * sizeof (int16_t));
39 memset (b2, 0, vlmax_e8m1 * sizeof (int16_t));
40 memset (c1, 0, vlmax_e8m1 * sizeof (int32_t));
41 memset (c2, 0, vlmax_e8m1 * sizeof (int32_t));
42 memset (d1, 0, vlmax_e8m1 * sizeof (int64_t));
43 memset (d2, 0, vlmax_e8m1 * sizeof (int64_t));
44
45 for (size_t i = 0; i < vlmax_e8m1; i++)
46 {
47 a1[i] = 67 * i;
48 a2[i] = 83 * i;
49 b1[i] = 132 * i;
50 c1[i] = 1928 * i;
51 d1[i] = 23495 * i;
52 }
53
54 for (size_t i = 0; i < vlmax_e8m1; i++)
55 {
56 b2[i] = a1[i] + a2[i];
57 }
58 for (size_t i = 0; i < vlmax_e8m1; i++)
59 {
60 c2[i] = b1[i] - b2[i];
61 }
62
63 for (size_t i = 0; i < vlmax_e8m1; i++)
64 {
65 d2[i] = c1[i] * c2[i];
66 d2[i] = d2[i] & d1[i];
67 }
68 int64_t golden = 0;
69 for (size_t i = 0; i < vlmax_e8m1; i++)
70 {
71 golden += d2[i];
72 }
73
74 int64_t test;
75
76 vint64m8_t res1
77 = foo1 (*(vint8m1_t *) a1, *(vint8m1_t *) a2, *(vint16m2_t *) b1,
78 *(vint32m4_t *) c1, *(vint64m8_t *) d1, vlmax_e8m1);
79 test = __riscv_vmv_x_s_i64m1_i64 (
80 __riscv_vredsum_vs_i64m8_i64m1 (res1, __riscv_vmv_v_x_i64m1 (0, vlmax_e8m1),
81 vlmax_e8m1));
82
83 if (test != golden)
84 {
85 printf ("foo1: %ld, %ld\n", test, golden);
86 abort ();
87 }
88
89 vint64m8_t res2
90 = foo2 (*(vint8m1_t *) a1, *(vint16m2_t *) b1, *(vint8m1_t *) a2,
91 *(vint32m4_t *) c1, *(vint64m8_t *) d1, vlmax_e8m1);
92 test = __riscv_vmv_x_s_i64m1_i64 (
93 __riscv_vredsum_vs_i64m8_i64m1 (res2, __riscv_vmv_v_x_i64m1 (0, vlmax_e8m1),
94 vlmax_e8m1));
95
96 if (test != golden)
97 {
98 printf ("foo2: %ld, %ld\n", test, golden);
99 abort ();
100 }
101
102 vint64m8_t res3
103 = foo3 (*(vint8m1_t *) a1, *(vint16m2_t *) b1, *(vint32m4_t *) c1,
104 *(vint8m1_t *) a2, *(vint64m8_t *) d1, vlmax_e8m1);
105 test = __riscv_vmv_x_s_i64m1_i64 (
106 __riscv_vredsum_vs_i64m8_i64m1 (res3, __riscv_vmv_v_x_i64m1 (0, vlmax_e8m1),
107 vlmax_e8m1));
108 if (test != golden)
109 {
110 printf ("foo3: %ld, %ld\n", test, golden);
111 abort ();
112 }
113
114 vint64m8_t res4
115 = foo4 (*(vint8m1_t *) a1, *(vint16m2_t *) b1, *(vint32m4_t *) c1,
116 *(vint64m8_t *) d1, *(vint8m1_t *) a2, vlmax_e8m1);
117 test = __riscv_vmv_x_s_i64m1_i64 (
118 __riscv_vredsum_vs_i64m8_i64m1 (res4, __riscv_vmv_v_x_i64m1 (0, vlmax_e8m1),
119 vlmax_e8m1));
120 if (test != golden)
121 {
122 printf ("foo4: %ld, %ld\n", test, golden);
123 abort ();
124 }
125
126 int8_t t1[vlmax_e8m1 * 8];
127 int8_t t2[vlmax_e8m1 * 8];
128 for (size_t i = 0; i < vlmax_e8m1 * 8; i++)
129 {
130 t1[i] = 67 * i;
131 t2[i] = 83 * i;
132 }
133 vint8m1x8_t res5 = foo5 (*(vint8m8_t *) t1, *(vint8m1x8_t *) t2);
134 int8_t test_arr[vlmax_e8m1 * 8];
135 memset (test_arr, 0, vlmax_e8m1 * 8 * sizeof (int8_t));
136 *(vint8m1x8_t *) test_arr = res5;
137 for (size_t i = 0; i < vlmax_e8m1 * 8; i += 1)
138 if (t2[i] != test_arr[i])
139 {
140 printf ("foo5 %d: %ld, %ld\n", i, test_arr[i], t2[i]);
141 abort ();
142 }
143
144 return 0;
145 }