Merge branch 'master' into msp430
[llvm/msp430.git] / test / CodeGen / CellSPU / useful-harnesses / vecoperations.c
blobc4c86e37635d4b79cc5d7543bf8600f6b122cadf
1 #include <stdio.h>
3 typedef unsigned char v16i8 __attribute__((ext_vector_type(16)));
4 typedef short v8i16 __attribute__((ext_vector_type(16)));
5 typedef int v4i32 __attribute__((ext_vector_type(4)));
6 typedef float v4f32 __attribute__((ext_vector_type(4)));
7 typedef long long v2i64 __attribute__((ext_vector_type(2)));
8 typedef double v2f64 __attribute__((ext_vector_type(2)));
10 void print_v16i8(const char *str, const v16i8 v) {
11 union {
12 unsigned char elts[16];
13 v16i8 vec;
14 } tv;
15 tv.vec = v;
16 printf("%s = { %hhu, %hhu, %hhu, %hhu, %hhu, %hhu, %hhu, "
17 "%hhu, %hhu, %hhu, %hhu, %hhu, %hhu, %hhu, "
18 "%hhu, %hhu }\n",
19 str, tv.elts[0], tv.elts[1], tv.elts[2], tv.elts[3], tv.elts[4], tv.elts[5],
20 tv.elts[6], tv.elts[7], tv.elts[8], tv.elts[9], tv.elts[10], tv.elts[11],
21 tv.elts[12], tv.elts[13], tv.elts[14], tv.elts[15]);
24 void print_v16i8_hex(const char *str, const v16i8 v) {
25 union {
26 unsigned char elts[16];
27 v16i8 vec;
28 } tv;
29 tv.vec = v;
30 printf("%s = { 0x%02hhx, 0x%02hhx, 0x%02hhx, 0x%02hhx, 0x%02hhx, 0x%02hhx, 0x%02hhx, "
31 "0x%02hhx, 0x%02hhx, 0x%02hhx, 0x%02hhx, 0x%02hhx, 0x%02hhx, 0x%02hhx, "
32 "0x%02hhx, 0x%02hhx }\n",
33 str, tv.elts[0], tv.elts[1], tv.elts[2], tv.elts[3], tv.elts[4], tv.elts[5],
34 tv.elts[6], tv.elts[7], tv.elts[8], tv.elts[9], tv.elts[10], tv.elts[11],
35 tv.elts[12], tv.elts[13], tv.elts[14], tv.elts[15]);
38 void print_v8i16_hex(const char *str, v8i16 v) {
39 union {
40 short elts[8];
41 v8i16 vec;
42 } tv;
43 tv.vec = v;
44 printf("%s = { 0x%04hx, 0x%04hx, 0x%04hx, 0x%04hx, 0x%04hx, "
45 "0x%04hx, 0x%04hx, 0x%04hx }\n",
46 str, tv.elts[0], tv.elts[1], tv.elts[2], tv.elts[3], tv.elts[4],
47 tv.elts[5], tv.elts[6], tv.elts[7]);
50 void print_v4i32(const char *str, v4i32 v) {
51 printf("%s = { %d, %d, %d, %d }\n", str, v.x, v.y, v.z, v.w);
54 void print_v4f32(const char *str, v4f32 v) {
55 printf("%s = { %f, %f, %f, %f }\n", str, v.x, v.y, v.z, v.w);
58 void print_v2i64(const char *str, v2i64 v) {
59 printf("%s = { %lld, %lld }\n", str, v.x, v.y);
62 void print_v2f64(const char *str, v2f64 v) {
63 printf("%s = { %g, %g }\n", str, v.x, v.y);
66 /*----------------------------------------------------------------------*/
68 v16i8 v16i8_mpy(v16i8 v1, v16i8 v2) {
69 return v1 * v2;
72 v16i8 v16i8_add(v16i8 v1, v16i8 v2) {
73 return v1 + v2;
76 v4i32 v4i32_shuffle_1(v4i32 a) {
77 v4i32 c2 = a.yzwx;
78 return c2;
81 v4i32 v4i32_shuffle_2(v4i32 a) {
82 v4i32 c2 = a.zwxy;
83 return c2;
86 v4i32 v4i32_shuffle_3(v4i32 a) {
87 v4i32 c2 = a.wxyz;
88 return c2;
91 v4i32 v4i32_shuffle_4(v4i32 a) {
92 v4i32 c2 = a.xyzw;
93 return c2;
96 v4i32 v4i32_shuffle_5(v4i32 a) {
97 v4i32 c2 = a.xwzy;
98 return c2;
101 v4f32 v4f32_shuffle_1(v4f32 a) {
102 v4f32 c2 = a.yzwx;
103 return c2;
106 v4f32 v4f32_shuffle_2(v4f32 a) {
107 v4f32 c2 = a.zwxy;
108 return c2;
111 v4f32 v4f32_shuffle_3(v4f32 a) {
112 v4f32 c2 = a.wxyz;
113 return c2;
116 v4f32 v4f32_shuffle_4(v4f32 a) {
117 v4f32 c2 = a.xyzw;
118 return c2;
121 v4f32 v4f32_shuffle_5(v4f32 a) {
122 v4f32 c2 = a.xwzy;
123 return c2;
126 v2i64 v2i64_shuffle(v2i64 a) {
127 v2i64 c2 = a.yx;
128 return c2;
131 v2f64 v2f64_shuffle(v2f64 a) {
132 v2f64 c2 = a.yx;
133 return c2;
136 int main(void) {
137 v16i8 v00 = { 0xf4, 0xad, 0x01, 0xe9, 0x51, 0x78, 0xc1, 0x8a,
138 0x94, 0x7c, 0x49, 0x6c, 0x21, 0x32, 0xb2, 0x04 };
139 v16i8 va0 = { 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08,
140 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f, 0x10 };
141 v16i8 va1 = { 0x11, 0x83, 0x4b, 0x63, 0xff, 0x90, 0x32, 0xe5,
142 0x5a, 0xaa, 0x20, 0x01, 0x0d, 0x15, 0x77, 0x05 };
143 v8i16 v01 = { 0x1a87, 0x0a14, 0x5014, 0xfff0,
144 0xe194, 0x0184, 0x801e, 0x5940 };
145 v4i32 v1 = { 1, 2, 3, 4 };
146 v4f32 v2 = { 1.0, 2.0, 3.0, 4.0 };
147 v2i64 v3 = { 691043ll, 910301513ll };
148 v2f64 v4 = { 5.8e56, 9.103e-62 };
150 puts("---- vector tests start ----");
152 print_v16i8_hex("v00 ", v00);
153 print_v16i8_hex("va0 ", va0);
154 print_v16i8_hex("va1 ", va1);
155 print_v16i8_hex("va0 x va1 ", v16i8_mpy(va0, va1));
156 print_v16i8_hex("va0 + va1 ", v16i8_add(va0, va1));
157 print_v8i16_hex("v01 ", v01);
159 print_v4i32("v4i32_shuffle_1(1, 2, 3, 4)", v4i32_shuffle_1(v1));
160 print_v4i32("v4i32_shuffle_2(1, 2, 3, 4)", v4i32_shuffle_2(v1));
161 print_v4i32("v4i32_shuffle_3(1, 2, 3, 4)", v4i32_shuffle_3(v1));
162 print_v4i32("v4i32_shuffle_4(1, 2, 3, 4)", v4i32_shuffle_4(v1));
163 print_v4i32("v4i32_shuffle_5(1, 2, 3, 4)", v4i32_shuffle_5(v1));
165 print_v4f32("v4f32_shuffle_1(1, 2, 3, 4)", v4f32_shuffle_1(v2));
166 print_v4f32("v4f32_shuffle_2(1, 2, 3, 4)", v4f32_shuffle_2(v2));
167 print_v4f32("v4f32_shuffle_3(1, 2, 3, 4)", v4f32_shuffle_3(v2));
168 print_v4f32("v4f32_shuffle_4(1, 2, 3, 4)", v4f32_shuffle_4(v2));
169 print_v4f32("v4f32_shuffle_5(1, 2, 3, 4)", v4f32_shuffle_5(v2));
171 print_v2i64("v3 ", v3);
172 print_v2i64("v2i64_shuffle ", v2i64_shuffle(v3));
173 print_v2f64("v4 ", v4);
174 print_v2f64("v2f64_shuffle ", v2f64_shuffle(v4));
176 puts("---- vector tests end ----");
178 return 0;