This is the mail archive of the
gcc-patches@gcc.gnu.org
mailing list for the GCC project.
altivec testcase
- From: Aldy Hernandez <aldyh at redhat dot com>
- To: gcc patches <gcc-patches at gcc dot gnu dot org>
- Date: 16 Nov 2001 21:02:27 -0500
- Subject: altivec testcase
hi guys.
i've gotten several emails asking how to use what we currently have for
altivec. i think it's time to add a testcase.
this test should obviously only be run for -maltivec. i'd like to add
altivec.x and altivec.c. is this the right way to do it?
eventually i'd like to replace this test with a more in depth one using
the upcoming overloaded vec_blah() functions. it will for sure make it
more readable (not that builtins are supposed to be readable :)).
i've tested this case on actual hardware and it works :)
is this ok?
2001-11-16 Aldy Hernandez <aldyh@redhat.com>
* gcc.c-torture/execute/altivec.c: New.
* gcc.c-torture/execute/altivec.x: New.
Index: altivec.x
===================================================================
RCS file: altivec.x
diff -N altivec.x
*** /dev/null Tue May 5 13:32:27 1998
--- altivec.x Fri Nov 16 17:49:25 2001
***************
*** 0 ****
--- 1,4 ----
+ # This test is only needed for rs6000 with -maltivec
+
+ if { ! [string match "*maltivec*" $CFLAGS] } { return 1 }
+ return 0
Index: altivec.c
===================================================================
RCS file: altivec.c
diff -N altivec.c
*** /dev/null Tue May 5 13:32:27 1998
--- altivec.c Fri Nov 16 17:49:25 2001
***************
*** 0 ****
--- 1,79 ----
+ /* Program to test PowerPC AltiVec instructions. */
+
+ /* These macros are not analogous to the overloaded functions
+ described in Motorola's AltiVec Programming Interface Manual.
+ These are just here for readability. Eventually we'll get the
+ overloaded functions implemented in an <altivec.h>. */
+
+ #define vec_load(src) \
+ __builtin_altivec_ld_internal ((int *) src)
+
+ #define vec_store(dst, src) \
+ __builtin_altivec_st_internal ((int *) dst, (int4) src)
+
+ #define vec_add_int4(x, y) \
+ __builtin_altivec_vaddsws (x, y)
+
+ #define vec_add_float4(x, y) \
+ __builtin_altivec_vaddfp (x, y)
+
+ #define vec_average_int4(x, y) \
+ __builtin_altivec_vavgsw (x, y)
+
+ typedef int int4 __attribute__ ((mode(V4SI)));
+ typedef float float4 __attribute__ ((mode(V4SF)));
+
+ int a1[4] __attribute__((aligned(16))) = { 100, 200, 300, 400 };
+ int a2[4] __attribute__((aligned(16))) = { 500, 600, 700, 800 };
+ int a3[4] __attribute__((aligned(16)));
+ int addi[4] = { 600, 800, 1000, 1200 };
+ int avgi[4] = { 300, 400, 500, 600 };
+
+ float f1[4] __attribute__((aligned(16))) = { 1.0, 2.0, 3.0, 4.0 };
+ float f2[4] __attribute__((aligned(16))) = { 5.0, 6.0, 7.0, 8.0 };
+ float f3[4] __attribute__((aligned(16)));
+ float addf[4] = { 6.0, 8.0, 10.0, 12.0 };
+
+ int4 i, j, k;
+ float4 f, g, h;
+
+ void
+ compare_int4 (int *a, int *b)
+ {
+ int i;
+
+ for (i = 0; i < 4; ++i)
+ if (a[i] != b[i])
+ exit (1);
+ }
+
+ void
+ compare_float4 (float *a, float *b)
+ {
+ int i;
+
+ for (i = 0; i < 4; ++i)
+ if (a[i] != b[i])
+ exit (1);
+ }
+
+ main ()
+ {
+ i = vec_load (a1);
+ j = vec_load (a2);
+ k = vec_add_int4 (i, j);
+ vec_store (a3, k);
+ compare_int4 (a3, addi);
+
+ k = vec_average_int4 (i, j);
+ vec_store (a3, k);
+ compare_int4 (a3, avgi);
+
+ f = (float4) vec_load (f1);
+ g = (float4) vec_load (f2);
+ h = vec_add_float4 (f, g);
+ vec_store (f3, h);
+ compare_float4 (f3, addf);
+
+ exit (0);
+ }