xref: /openbmc/linux/arch/s390/include/asm/fpu/internal.h (revision 7effbd18)
1 /* SPDX-License-Identifier: GPL-2.0 */
2 /*
3  * FPU state and register content conversion primitives
4  *
5  * Copyright IBM Corp. 2015
6  * Author(s): Hendrik Brueckner <brueckner@linux.vnet.ibm.com>
7  */
8 
9 #ifndef _ASM_S390_FPU_INTERNAL_H
10 #define _ASM_S390_FPU_INTERNAL_H
11 
12 #include <linux/string.h>
13 #include <asm/ctl_reg.h>
14 #include <asm/fpu/types.h>
15 
16 static inline void save_vx_regs(__vector128 *vxrs)
17 {
18 	asm volatile(
19 		"	la	1,%0\n"
20 		"	.word	0xe70f,0x1000,0x003e\n"	/* vstm 0,15,0(1) */
21 		"	.word	0xe70f,0x1100,0x0c3e\n"	/* vstm 16,31,256(1) */
22 		: "=Q" (*(struct vx_array *) vxrs) : : "1");
23 }
24 
25 static inline void convert_vx_to_fp(freg_t *fprs, __vector128 *vxrs)
26 {
27 	int i;
28 
29 	for (i = 0; i < __NUM_FPRS; i++)
30 		fprs[i].ui = vxrs[i].high;
31 }
32 
33 static inline void convert_fp_to_vx(__vector128 *vxrs, freg_t *fprs)
34 {
35 	int i;
36 
37 	for (i = 0; i < __NUM_FPRS; i++)
38 		vxrs[i].high = fprs[i].ui;
39 }
40 
41 static inline void fpregs_store(_s390_fp_regs *fpregs, struct fpu *fpu)
42 {
43 	fpregs->pad = 0;
44 	fpregs->fpc = fpu->fpc;
45 	if (MACHINE_HAS_VX)
46 		convert_vx_to_fp((freg_t *)&fpregs->fprs, fpu->vxrs);
47 	else
48 		memcpy((freg_t *)&fpregs->fprs, fpu->fprs,
49 		       sizeof(fpregs->fprs));
50 }
51 
52 static inline void fpregs_load(_s390_fp_regs *fpregs, struct fpu *fpu)
53 {
54 	fpu->fpc = fpregs->fpc;
55 	if (MACHINE_HAS_VX)
56 		convert_fp_to_vx(fpu->vxrs, (freg_t *)&fpregs->fprs);
57 	else
58 		memcpy(fpu->fprs, (freg_t *)&fpregs->fprs,
59 		       sizeof(fpregs->fprs));
60 }
61 
62 #endif /* _ASM_S390_FPU_INTERNAL_H */
63