1 /* SPDX-License-Identifier: GPL-2.0-or-later */
2 /*
3  * Copyright (C) 2015 Anshuman Khandual, IBM Corporation.
4  */
5 #define VEC_MAX 128
6 #define VSX_MAX 32
7 #define VMX_MAX 32
8 
9 /*
10  * unsigned long vsx[32]
11  * unsigned long load[128]
12  */
validate_vsx(unsigned long * vsx,unsigned long * load)13 int validate_vsx(unsigned long *vsx, unsigned long *load)
14 {
15 	int i;
16 
17 	for (i = 0; i < VSX_MAX; i++) {
18 		if (vsx[i] != load[2 * i + 1]) {
19 			printf("vsx[%d]: %lx load[%d] %lx\n",
20 					i, vsx[i], 2 * i + 1, load[2 * i + 1]);
21 			return TEST_FAIL;
22 		}
23 	}
24 	return TEST_PASS;
25 }
26 
27 /*
28  * unsigned long vmx[32][2]
29  * unsigned long load[128]
30  */
validate_vmx(unsigned long vmx[][2],unsigned long * load)31 int validate_vmx(unsigned long vmx[][2], unsigned long *load)
32 {
33 	int i;
34 
35 	for (i = 0; i < VMX_MAX; i++) {
36 		#if __BYTE_ORDER__ == __ORDER_BIG_ENDIAN__
37 		if ((vmx[i][0] != load[64 + 2 * i]) ||
38 				(vmx[i][1] != load[65 + 2 * i])) {
39 			printf("vmx[%d][0]: %lx load[%d] %lx\n",
40 					i, vmx[i][0], 64 + 2 * i,
41 					load[64 + 2 * i]);
42 			printf("vmx[%d][1]: %lx load[%d] %lx\n",
43 					i, vmx[i][1], 65 + 2 * i,
44 					load[65 + 2 * i]);
45 			return TEST_FAIL;
46 		}
47 		#else  /*
48 			* In LE each value pair is stored in an
49 			* alternate manner.
50 			*/
51 		if ((vmx[i][0] != load[65 + 2 * i]) ||
52 				(vmx[i][1] != load[64 + 2 * i])) {
53 			printf("vmx[%d][0]: %lx load[%d] %lx\n",
54 					i, vmx[i][0], 65 + 2 * i,
55 					load[65 + 2 * i]);
56 			printf("vmx[%d][1]: %lx load[%d] %lx\n",
57 					i, vmx[i][1], 64 + 2 * i,
58 					load[64 + 2 * i]);
59 			return TEST_FAIL;
60 		}
61 		#endif
62 	}
63 	return TEST_PASS;
64 }
65 
66 /*
67  * unsigned long store[128]
68  * unsigned long load[128]
69  */
compare_vsx_vmx(unsigned long * store,unsigned long * load)70 int compare_vsx_vmx(unsigned long *store, unsigned long *load)
71 {
72 	int i;
73 
74 	for (i = 0; i < VSX_MAX; i++) {
75 		if (store[1 + 2 * i] != load[1 + 2 * i]) {
76 			printf("store[%d]: %lx load[%d] %lx\n",
77 					1 + 2 * i, store[i],
78 					1 + 2 * i, load[i]);
79 			return TEST_FAIL;
80 		}
81 	}
82 
83 	#if __BYTE_ORDER__ == __ORDER_BIG_ENDIAN__
84 	for (i = 64; i < VEC_MAX; i++) {
85 		if (store[i] != load[i]) {
86 			printf("store[%d]: %lx load[%d] %lx\n",
87 					i, store[i], i, load[i]);
88 			return TEST_FAIL;
89 		}
90 	}
91 	#else	/* In LE each value pair is stored in an alternate manner */
92 	for (i = 64; i < VEC_MAX; i++) {
93 		if (!(i % 2) && (store[i] != load[i+1])) {
94 			printf("store[%d]: %lx load[%d] %lx\n",
95 					i, store[i], i+1, load[i+1]);
96 			return TEST_FAIL;
97 		}
98 		if ((i % 2) && (store[i] != load[i-1])) {
99 			printf("here store[%d]: %lx load[%d] %lx\n",
100 					i, store[i], i-1, load[i-1]);
101 			return TEST_FAIL;
102 		}
103 	}
104 	#endif
105 	return TEST_PASS;
106 }
107 
load_vsx_vmx(unsigned long * load,unsigned long * vsx,unsigned long vmx[][2])108 void load_vsx_vmx(unsigned long *load, unsigned long *vsx,
109 		unsigned long vmx[][2])
110 {
111 	int i;
112 
113 	for (i = 0; i < VSX_MAX; i++)
114 		vsx[i] = load[1 + 2 * i];
115 
116 	for (i = 0; i < VMX_MAX; i++) {
117 		vmx[i][0] = load[64 + 2 * i];
118 		vmx[i][1] = load[65 + 2 * i];
119 	}
120 }
121 
122 void loadvsx(void *p, int tmp);
123 void storevsx(void *p, int tmp);
124