1139749Simp#include <altivec.h> 2138755Simp 3138755Simpvector short vshort = {111, 222, 333, 444, 555, 666, 777, 888}; 4138755Simpvector unsigned short vushort = {100, 200, 300, 400, 500, 600, 700, 800}; 5138755Simpvector int vint = {-10, -20, -30, -40}; 6138755Simpvector unsigned int vuint = {1111, 2222, 3333, 4444}; 7138755Simpvector char vchar = {'a','b','c','d','e','f','g','h','i','l','m','n','o','p','q','r'}; 8138755Simpvector unsigned char vuchar = {'A','B','C','D','E','F','G','H','I','L','M','N','O','P','Q','R'}; 9140040Simpvector float vfloat = {1.25, 3.75, 5.5, 1.25}; 10138755Simp 11140040Simpvector short vshort_d = {0,0,0,0,0,0,0,0}; 12140040Simpvector unsigned short vushort_d = {0,0,0,0,0,0,0,0}; 13138755Simpvector int vint_d = {0,0,0,0}; 14138755Simpvector unsigned int vuint_d = {0,0,0,0}; 15138755Simpvector char vchar_d = {'z','z','z','z','z','z','z','z','z','z','z','z','z','z','z','z'}; 16138755Simpvector unsigned char vuchar_d = {'Z','Z','Z','Z','Z','Z','Z','Z','Z','Z','Z','Z','Z','Z','Z','Z'}; 17140040Simpvector float vfloat_d = {1.0, 1.0, 1.0, 1.0}; 18140040Simp 19138755Simpstruct test_vec_struct 20138755Simp{ 21138755Simp vector signed short vshort1; 22138755Simp vector signed short vshort2; 23138755Simp vector signed short vshort3; 24138755Simp vector signed short vshort4; 25138755Simp}; 26138755Simp 27138755Simpstatic vector signed short test4[4] = 28138755Simp{ 29140040Simp (vector signed short) {1, 2, 3, 4, 5, 6, 7, 8}, 30138755Simp (vector signed short) {11, 12, 13, 14, 15, 16, 17, 18}, 31138755Simp (vector signed short) {21, 22, 23, 24, 25, 26, 27, 28}, 32138755Simp (vector signed short) {31, 32, 33, 34, 35, 36, 37, 38} 33138755Simp}; 34138755Simp 35138755Simpvoid 36138755Simpstruct_of_vector_func (struct test_vec_struct vector_struct) 37138755Simp{ 38138755Simp vector_struct.vshort1 = vec_add (vector_struct.vshort1, vector_struct.vshort2); 39138755Simp vector_struct.vshort3 = vec_add (vector_struct.vshort3, vector_struct.vshort4); 40138755Simp} 41138755Simp 42138755Simpvoid 43138755Simparray_of_vector_func (vector signed short *matrix) 44138755Simp{ 45138755Simp matrix[0] = vec_add (matrix[0], matrix[1]); 46138755Simp matrix[2] = vec_add (matrix[2], matrix[3]); 47138755Simp} 48138755Simp 49138755Simpvector int 50138755Simpvec_func (vector short vshort_f, /* goes in v2 */ 51138755Simp vector unsigned short vushort_f, /* goes in v3 */ 52138755Simp vector int vint_f, /* goes in v4 */ 53138755Simp vector unsigned int vuint_f, /* goes in v5 */ 54138755Simp vector char vchar_f, /* goes in v6 */ 55138755Simp vector unsigned char vuchar_f, /* goes in v7 */ 56138755Simp vector float vfloat_f, /* goes in v8 */ 57138755Simp vector short x_f, /* goes in v9 */ 58138755Simp vector int y_f, /* goes in v10 */ 59138755Simp vector char a_f, /* goes in v11 */ 60138755Simp vector float b_f, /* goes in v12 */ 61138755Simp vector float c_f, /* goes in v13 */ 62138755Simp vector int intv_on_stack_f) 63138755Simp{ 64138755Simp 65138755Simp vector int vint_res; 66138755Simp vector unsigned int vuint_res; 67138755Simp vector short vshort_res; 68138755Simp vector unsigned short vushort_res; 69138755Simp vector char vchar_res; 70138755Simp vector float vfloat_res; 71138755Simp vector unsigned char vuchar_res; 72138755Simp 73138755Simp vint_res = vec_add (vint_f, intv_on_stack_f); 74138755Simp vint_res = vec_add (vint_f, y_f); 75138755Simp vuint_res = vec_add (vuint_f, ((vector unsigned int) {5,6,7,8})); 76138755Simp vshort_res = vec_add (vshort_f, x_f); 77138755Simp vushort_res = vec_add (vushort_f, 78138755Simp ((vector unsigned short) {1,2,3,4,5,6,7,8})); 79138755Simp vchar_res = vec_add (vchar_f, a_f); 80138755Simp vfloat_res = vec_add (vfloat_f, b_f); 81138755Simp vfloat_res = vec_add (c_f, ((vector float) {1.1,1.1,1.1,1.1})); 82138755Simp vuchar_res = vec_add (vuchar_f, 83138755Simp ((vector unsigned char) {'a','a','a','a','a','a','a','a','a','a','a','a','a','a','a','a'})); 84138755Simp 85138755Simp return vint_res; 86138755Simp} 87144280Simp 88144280Simpvoid marker(void) {}; 89138755Simp 90144280Simpint 91144280Simpmain (void) 92138755Simp{ 93138755Simp vector int result = {-1,-1,-1,-1}; 94144280Simp vector short x = {1,2,3,4,5,6,7,8}; 95138755Simp vector int y = {12, 22, 32, 42}; 96138755Simp vector int intv_on_stack = {12, 34, 56, 78}; 97138755Simp vector char a = {'v','e','c','t','o','r',' ','o','f',' ','c','h','a','r','s','.' }; 98138755Simp vector float b = {5.5, 4.5, 3.75, 2.25}; 99138755Simp vector float c = {1.25, 3.5, 5.5, 7.75}; 100138755Simp 101138755Simp vector short x_d = {0,0,0,0,0,0,0,0}; 102138755Simp vector int y_d = {0,0,0,0}; 103138755Simp vector int intv_on_stack_d = {0,0,0,0}; 104138755Simp vector char a_d = {'q','q','q','q','q','q','q','q','q','q','q','q','q','q','q','q'}; 105138755Simp vector float b_d = {5.0, 5.0, 5.0, 5.0}; 106138755Simp vector float c_d = {3.0, 3.0, 3.0, 3.0}; 107138755Simp 108138755Simp int var_int = 44; 109138755Simp short var_short = 3; 110138755Simp struct test_vec_struct vect_struct; 111138755Simp 112138755Simp vect_struct.vshort1 = (vector signed short){1, 2, 3, 4, 5, 6, 7, 8}; 113138755Simp vect_struct.vshort2 = (vector signed short){11, 12, 13, 14, 15, 16, 17, 18}; 114138755Simp vect_struct.vshort3 = (vector signed short){21, 22, 23, 24, 25, 26, 27, 28}; 115138755Simp vect_struct.vshort4 = (vector signed short){31, 32, 33, 34, 35, 36, 37, 38}; 116138755Simp 117138755Simp marker (); 118138755Simp#if 0 119138755Simp /* This line is useful for cutting and pasting from the gdb command line. */ 120138755Simpvec_func(vshort,vushort,vint,vuint,vchar,vuchar,vfloat,x,y,a,b,c,intv_on_stack) 121138755Simp#endif 122138755Simp result = vec_func (vshort, /* goes in v2 */ 123138755Simp vushort, /* goes in v3 */ 124138755Simp vint, /* goes in v4 */ 125138755Simp vuint, /* goes in v5 */ 126 vchar, /* goes in v6 */ 127 vuchar, /* goes in v7 */ 128 vfloat, /* goes in v8 */ 129 x, /* goes in v9 */ 130 y, /* goes in v10 */ 131 a, /* goes in v11 */ 132 b, /* goes in v12 */ 133 c, /* goes in v13 */ 134 intv_on_stack); 135 136 struct_of_vector_func (vect_struct); 137 array_of_vector_func (test4); 138 139 return 0; 140} 141 142