FSF GCC merge 02/23/03
[official-gcc.git] / gcc / testsuite / gcc.dg / altivec-3.c
blobc82f1e2a214604cc5b194a84085b93d649dd1eba
1 /* { dg-do run { target powerpc-*-*altivec powerpc-*-*-*altivec } } */
2 /* { dg-options "-maltivec" } */
4 typedef int int4 __attribute__ ((mode(V4SI)));
5 typedef float float4 __attribute__ ((mode(V4SF)));
7 int4 a1 = (int4) { 100, 200, 300, 400 };
8 int4 a2 = (int4) { 500, 600, 700, 800 };
10 float4 f1 = (float4) { 1.0, 2.0, 3.0, 4.0 };
11 float4 f2 = (float4) { 5.0, 6.0, 7.0, 8.0 };
13 int i3[4] __attribute__((aligned(16)));
14 int j3[4] __attribute__((aligned(16)));
15 float h3[4] __attribute__((aligned(16)));
16 float g3[4] __attribute__((aligned(16)));
18 #define vec_store(dst, src) \
19 __builtin_altivec_st_internal_4si ((int *) dst, (int4) src)
21 #define vec_add_int4(x, y) \
22 __builtin_altivec_vaddsws (x, y)
24 #define vec_add_float4(x, y) \
25 __builtin_altivec_vaddfp (x, y)
27 #define my_abs(x) (x > 0.0F ? x : -x)
29 void
30 compare_int4 (int *a, int *b)
32 int i;
34 for (i = 0; i < 4; ++i)
35 if (a[i] != b[i])
36 abort ();
39 void
40 compare_float4 (float *a, float *b)
42 int i;
44 for (i = 0; i < 4; ++i)
45 if (my_abs(a[i] - b[i]) >= 1.0e-6)
46 abort ();
49 main ()
51 int loc1 = 600, loc2 = 800;
52 int4 a3 = (int4) { loc1, loc2, 1000, 1200 };
53 int4 itmp;
54 double locf = 12.0;
55 float4 f3 = (float4) { 6.0, 8.0, 10.0, 12.0 };
56 float4 ftmp;
58 vec_store (i3, a3);
59 itmp = vec_add_int4 (a1, a2);
60 vec_store (j3, itmp);
61 compare_int4 (i3, j3);
63 vec_store (g3, f3);
64 ftmp = vec_add_float4 (f1, f2);
65 vec_store (h3, ftmp);
66 compare_float4 (g3, h3);
68 exit (0);