Use conditional internal functions in if-conversion
[official-gcc.git] / gcc / testsuite / gcc.target / powerpc / builtins-7-p9-runnable.c
blobf2773444f5280b92150dfd32ea23fe129c0f8a3a
1 /* { dg-do run { target { powerpc*-*-* && p9vector_hw } } } */
2 /* { dg-skip-if "do not override -mcpu" { powerpc*-*-* } { "-mcpu=*" } { "-mcpu=power9" } } */
3 /* { dg-require-effective-target powerpc_p9vector_ok } */
4 /* { dg-options "-mcpu=power9 -O2" } */
6 #include <altivec.h>
7 #define TRUE 1
8 #define FALSE 0
10 #ifdef DEBUG
11 #include <stdio.h>
12 #endif
14 #define EXTRACT 0
16 void abort (void);
18 int result_wrong_ull (vector unsigned long long vec_expected,
19 vector unsigned long long vec_actual)
21 int i;
23 for (i = 0; i < 2; i++)
24 if (vec_expected[i] != vec_actual[i])
25 return TRUE;
27 return FALSE;
30 int result_wrong_uc (vector unsigned char vec_expected,
31 vector unsigned char vec_actual)
33 int i;
35 for (i = 0; i < 16; i++)
36 if (vec_expected[i] != vec_actual[i])
37 return TRUE;
39 return FALSE;
42 #ifdef DEBUG
43 void print_ull (vector unsigned long long vec_expected,
44 vector unsigned long long vec_actual)
46 int i;
48 printf("expected unsigned long long data\n");
49 for (i = 0; i < 2; i++)
50 printf(" %lld,", vec_expected[i]);
52 printf("\nactual signed char data\n");
53 for (i = 0; i < 2; i++)
54 printf(" %lld,", vec_actual[i]);
55 printf("\n");
58 void print_uc (vector unsigned char vec_expected,
59 vector unsigned char vec_actual)
61 int i;
63 printf("expected unsigned char data\n");
64 for (i = 0; i < 16; i++)
65 printf(" %d,", vec_expected[i]);
67 printf("\nactual unsigned char data\n");
68 for (i = 0; i < 16; i++)
69 printf(" %d,", vec_actual[i]);
70 printf("\n");
72 #endif
74 #if EXTRACT
75 vector unsigned long long
76 vext (vector unsigned char *vc)
78 return vextract_si_vchar (*vc, 5);
80 #endif
82 int main()
84 vector signed int vsi_arg;
85 vector unsigned int vui_arg;
86 vector unsigned char vec_uc_arg, vec_uc_result, vec_uc_expected;
87 vector unsigned long long vec_ull_result, vec_ull_expected;
88 unsigned long long ull_result, ull_expected;
90 vec_uc_arg = (vector unsigned char){1, 2, 3, 4,
91 5, 6, 7, 8,
92 9, 10, 11, 12,
93 13, 14, 15, 16};
95 vsi_arg = (vector signed int){0xA, 0xB, 0xC, 0xD};
97 vec_uc_expected = (vector unsigned char){0xC, 0, 0, 0,
98 5, 6, 7, 8,
99 9, 10, 11, 12,
100 13, 14, 15, 16};
101 /* Test vec_insert4b() */
102 /* Insert into char 0 location */
103 vec_uc_result = vec_insert4b (vsi_arg, vec_uc_arg, 0);
105 if (result_wrong_uc(vec_uc_expected, vec_uc_result))
107 #ifdef DEBUG
108 printf("Error: vec_insert4b pos 0, result does not match expected result\n");
109 print_uc (vec_uc_expected, vec_uc_result);
110 #else
111 abort();
112 #endif
115 /* insert into char 4 location */
116 vec_uc_expected = (vector unsigned char){1, 2, 3, 4,
117 2, 0, 0, 0,
118 9, 10, 11, 12,
119 13, 14, 15, 16};
120 vui_arg = (vector unsigned int){0x4, 0x3, 0x2, 0x1};
122 vec_uc_result = vec_insert4b (vui_arg, vec_uc_arg, 4);
124 if (result_wrong_uc(vec_uc_expected, vec_uc_result))
126 #ifdef DEBUG
127 printf("Error: vec_insert4b pos 4, result does not match expected result\n");
128 print_uc (vec_uc_expected, vec_uc_result);
129 #else
130 abort();
131 #endif
134 /* Test vec_extract4b() */
135 /* Extract 4b, from char 0 location */
136 vec_uc_arg = (vector unsigned char){10, 0, 0, 0,
137 20, 0, 0, 0,
138 30, 0, 0, 0,
139 40, 0, 0, 0};
141 vec_ull_expected = (vector unsigned long long){0, 10};
142 vec_ull_result = vec_extract4b(vec_uc_arg, 0);
144 if (result_wrong_ull(vec_ull_expected, vec_ull_result))
146 #ifdef DEBUG
147 printf("Error: vec_extract4b pos 0, result does not match expected result\n");
148 print_ull (vec_ull_expected, vec_ull_result);
149 #else
150 abort();
151 #endif
154 /* Extract 4b, from char 12 location */
155 vec_uc_arg = (vector unsigned char){10, 0, 0, 0,
156 20, 0, 0, 0,
157 30, 0, 0, 0,
158 40, 0, 0, 0};
160 vec_ull_expected = (vector unsigned long long){0, 40};
161 vec_ull_result = vec_extract4b(vec_uc_arg, 12);
163 if (result_wrong_ull(vec_ull_expected, vec_ull_result))
165 #ifdef DEBUG
166 printf("Error: vec_extract4b pos 12, result does not match expected result\n");
167 print_ull (vec_ull_expected, vec_ull_result);
168 #else
169 abort();
170 #endif