18c2ecf20Sopenharmony_ci/* SPDX-License-Identifier: GPL-2.0-or-later */
28c2ecf20Sopenharmony_ci/*
38c2ecf20Sopenharmony_ci * Copyright (C) 2015 Anshuman Khandual, IBM Corporation.
48c2ecf20Sopenharmony_ci */
58c2ecf20Sopenharmony_ci#define VEC_MAX 128
68c2ecf20Sopenharmony_ci#define VSX_MAX 32
78c2ecf20Sopenharmony_ci#define VMX_MAX 32
88c2ecf20Sopenharmony_ci
98c2ecf20Sopenharmony_ci/*
108c2ecf20Sopenharmony_ci * unsigned long vsx[32]
118c2ecf20Sopenharmony_ci * unsigned long load[128]
128c2ecf20Sopenharmony_ci */
138c2ecf20Sopenharmony_ciint validate_vsx(unsigned long *vsx, unsigned long *load)
148c2ecf20Sopenharmony_ci{
158c2ecf20Sopenharmony_ci	int i;
168c2ecf20Sopenharmony_ci
178c2ecf20Sopenharmony_ci	for (i = 0; i < VSX_MAX; i++) {
188c2ecf20Sopenharmony_ci		if (vsx[i] != load[2 * i + 1]) {
198c2ecf20Sopenharmony_ci			printf("vsx[%d]: %lx load[%d] %lx\n",
208c2ecf20Sopenharmony_ci					i, vsx[i], 2 * i + 1, load[2 * i + 1]);
218c2ecf20Sopenharmony_ci			return TEST_FAIL;
228c2ecf20Sopenharmony_ci		}
238c2ecf20Sopenharmony_ci	}
248c2ecf20Sopenharmony_ci	return TEST_PASS;
258c2ecf20Sopenharmony_ci}
268c2ecf20Sopenharmony_ci
278c2ecf20Sopenharmony_ci/*
288c2ecf20Sopenharmony_ci * unsigned long vmx[32][2]
298c2ecf20Sopenharmony_ci * unsigned long load[128]
308c2ecf20Sopenharmony_ci */
318c2ecf20Sopenharmony_ciint validate_vmx(unsigned long vmx[][2], unsigned long *load)
328c2ecf20Sopenharmony_ci{
338c2ecf20Sopenharmony_ci	int i;
348c2ecf20Sopenharmony_ci
358c2ecf20Sopenharmony_ci	for (i = 0; i < VMX_MAX; i++) {
368c2ecf20Sopenharmony_ci		#if __BYTE_ORDER__ == __ORDER_BIG_ENDIAN__
378c2ecf20Sopenharmony_ci		if ((vmx[i][0] != load[64 + 2 * i]) ||
388c2ecf20Sopenharmony_ci				(vmx[i][1] != load[65 + 2 * i])) {
398c2ecf20Sopenharmony_ci			printf("vmx[%d][0]: %lx load[%d] %lx\n",
408c2ecf20Sopenharmony_ci					i, vmx[i][0], 64 + 2 * i,
418c2ecf20Sopenharmony_ci					load[64 + 2 * i]);
428c2ecf20Sopenharmony_ci			printf("vmx[%d][1]: %lx load[%d] %lx\n",
438c2ecf20Sopenharmony_ci					i, vmx[i][1], 65 + 2 * i,
448c2ecf20Sopenharmony_ci					load[65 + 2 * i]);
458c2ecf20Sopenharmony_ci			return TEST_FAIL;
468c2ecf20Sopenharmony_ci		}
478c2ecf20Sopenharmony_ci		#else  /*
488c2ecf20Sopenharmony_ci			* In LE each value pair is stored in an
498c2ecf20Sopenharmony_ci			* alternate manner.
508c2ecf20Sopenharmony_ci			*/
518c2ecf20Sopenharmony_ci		if ((vmx[i][0] != load[65 + 2 * i]) ||
528c2ecf20Sopenharmony_ci				(vmx[i][1] != load[64 + 2 * i])) {
538c2ecf20Sopenharmony_ci			printf("vmx[%d][0]: %lx load[%d] %lx\n",
548c2ecf20Sopenharmony_ci					i, vmx[i][0], 65 + 2 * i,
558c2ecf20Sopenharmony_ci					load[65 + 2 * i]);
568c2ecf20Sopenharmony_ci			printf("vmx[%d][1]: %lx load[%d] %lx\n",
578c2ecf20Sopenharmony_ci					i, vmx[i][1], 64 + 2 * i,
588c2ecf20Sopenharmony_ci					load[64 + 2 * i]);
598c2ecf20Sopenharmony_ci			return TEST_FAIL;
608c2ecf20Sopenharmony_ci		}
618c2ecf20Sopenharmony_ci		#endif
628c2ecf20Sopenharmony_ci	}
638c2ecf20Sopenharmony_ci	return TEST_PASS;
648c2ecf20Sopenharmony_ci}
658c2ecf20Sopenharmony_ci
668c2ecf20Sopenharmony_ci/*
678c2ecf20Sopenharmony_ci * unsigned long store[128]
688c2ecf20Sopenharmony_ci * unsigned long load[128]
698c2ecf20Sopenharmony_ci */
708c2ecf20Sopenharmony_ciint compare_vsx_vmx(unsigned long *store, unsigned long *load)
718c2ecf20Sopenharmony_ci{
728c2ecf20Sopenharmony_ci	int i;
738c2ecf20Sopenharmony_ci
748c2ecf20Sopenharmony_ci	for (i = 0; i < VSX_MAX; i++) {
758c2ecf20Sopenharmony_ci		if (store[1 + 2 * i] != load[1 + 2 * i]) {
768c2ecf20Sopenharmony_ci			printf("store[%d]: %lx load[%d] %lx\n",
778c2ecf20Sopenharmony_ci					1 + 2 * i, store[i],
788c2ecf20Sopenharmony_ci					1 + 2 * i, load[i]);
798c2ecf20Sopenharmony_ci			return TEST_FAIL;
808c2ecf20Sopenharmony_ci		}
818c2ecf20Sopenharmony_ci	}
828c2ecf20Sopenharmony_ci
838c2ecf20Sopenharmony_ci	#if __BYTE_ORDER__ == __ORDER_BIG_ENDIAN__
848c2ecf20Sopenharmony_ci	for (i = 64; i < VEC_MAX; i++) {
858c2ecf20Sopenharmony_ci		if (store[i] != load[i]) {
868c2ecf20Sopenharmony_ci			printf("store[%d]: %lx load[%d] %lx\n",
878c2ecf20Sopenharmony_ci					i, store[i], i, load[i]);
888c2ecf20Sopenharmony_ci			return TEST_FAIL;
898c2ecf20Sopenharmony_ci		}
908c2ecf20Sopenharmony_ci	}
918c2ecf20Sopenharmony_ci	#else	/* In LE each value pair is stored in an alternate manner */
928c2ecf20Sopenharmony_ci	for (i = 64; i < VEC_MAX; i++) {
938c2ecf20Sopenharmony_ci		if (!(i % 2) && (store[i] != load[i+1])) {
948c2ecf20Sopenharmony_ci			printf("store[%d]: %lx load[%d] %lx\n",
958c2ecf20Sopenharmony_ci					i, store[i], i+1, load[i+1]);
968c2ecf20Sopenharmony_ci			return TEST_FAIL;
978c2ecf20Sopenharmony_ci		}
988c2ecf20Sopenharmony_ci		if ((i % 2) && (store[i] != load[i-1])) {
998c2ecf20Sopenharmony_ci			printf("here store[%d]: %lx load[%d] %lx\n",
1008c2ecf20Sopenharmony_ci					i, store[i], i-1, load[i-1]);
1018c2ecf20Sopenharmony_ci			return TEST_FAIL;
1028c2ecf20Sopenharmony_ci		}
1038c2ecf20Sopenharmony_ci	}
1048c2ecf20Sopenharmony_ci	#endif
1058c2ecf20Sopenharmony_ci	return TEST_PASS;
1068c2ecf20Sopenharmony_ci}
1078c2ecf20Sopenharmony_ci
1088c2ecf20Sopenharmony_civoid load_vsx_vmx(unsigned long *load, unsigned long *vsx,
1098c2ecf20Sopenharmony_ci		unsigned long vmx[][2])
1108c2ecf20Sopenharmony_ci{
1118c2ecf20Sopenharmony_ci	int i;
1128c2ecf20Sopenharmony_ci
1138c2ecf20Sopenharmony_ci	for (i = 0; i < VSX_MAX; i++)
1148c2ecf20Sopenharmony_ci		vsx[i] = load[1 + 2 * i];
1158c2ecf20Sopenharmony_ci
1168c2ecf20Sopenharmony_ci	for (i = 0; i < VMX_MAX; i++) {
1178c2ecf20Sopenharmony_ci		vmx[i][0] = load[64 + 2 * i];
1188c2ecf20Sopenharmony_ci		vmx[i][1] = load[65 + 2 * i];
1198c2ecf20Sopenharmony_ci	}
1208c2ecf20Sopenharmony_ci}
1218c2ecf20Sopenharmony_ci
1228c2ecf20Sopenharmony_civoid loadvsx(void *p, int tmp);
1238c2ecf20Sopenharmony_civoid storevsx(void *p, int tmp);
124