summaryrefslogtreecommitdiffstats
path: root/arch/powerpc/kvm/fpu.S
blob: cb34bbe1611365c4761ebd1d20c58e8f2997ae12 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
/*
 *  FPU helper code to use FPU operations from inside the kernel
 *
 *    Copyright (C) 2010 Alexander Graf (agraf@suse.de)
 *
 *  This program is free software; you can redistribute it and/or
 *  modify it under the terms of the GNU General Public License
 *  as published by the Free Software Foundation; either version
 *  2 of the License, or (at your option) any later version.
 *
 */

#include <asm/reg.h>
#include <asm/page.h>
#include <asm/mmu.h>
#include <asm/pgtable.h>
#include <asm/cputable.h>
#include <asm/cache.h>
#include <asm/thread_info.h>
#include <asm/ppc_asm.h>
#include <asm/asm-offsets.h>

/* Instructions operating on single parameters */

/*
 * Single operation with one input operand
 *
 * R3 = (double*)&fpscr
 * R4 = (short*)&result
 * R5 = (short*)&param1
 */
#define FPS_ONE_IN(name) 					\
_GLOBAL(fps_ ## name);							\
	lfd	0,0(r3);		/* load up fpscr value */	\
	MTFSF_L(0);							\
	lfs	0,0(r5);						\
									\
	name	0,0;							\
									\
	stfs	0,0(r4);						\
	mffs	0;							\
	stfd	0,0(r3);	/* save new fpscr value */	\
	blr

/*
 * Single operation with two input operands
 *
 * R3 = (double*)&fpscr
 * R4 = (short*)&result
 * R5 = (short*)&param1
 * R6 = (short*)&param2
 */
#define FPS_TWO_IN(name) 					\
_GLOBAL(fps_ ## name);							\
	lfd	0,0(r3);		/* load up fpscr value */	\
	MTFSF_L(0);							\
	lfs	0,0(r5);						\
	lfs	1,0(r6);						\
									\
	name	0,0,1;							\
									\
	stfs	0,0(r4);						\
	mffs	0;							\
	stfd	0,0(r3);		/* save new fpscr value */	\
	blr

/*
 * Single operation with three input operands
 *
 * R3 = (double*)&fpscr
 * R4 = (short*)&result
 * R5 = (short*)&param1
 * R6 = (short*)&param2
 * R7 = (short*)&param3
 */
#define FPS_THREE_IN(name) 					\
_GLOBAL(fps_ ## name);							\
	lfd	0,0(r3);		/* load up fpscr value */	\
	MTFSF_L(0);							\
	lfs	0,0(r5);						\
	lfs	1,0(r6);						\
	lfs	2,0(r7);						\
									\
	name	0,0,1,2;						\
									\
	stfs	0,0(r4);						\
	mffs	0;							\
	stfd	0,0(r3);		/* save new fpscr value */	\
	blr

FPS_ONE_IN(fres)
FPS_ONE_IN(frsqrte)
FPS_ONE_IN(fsqrts)
FPS_TWO_IN(fadds)
FPS_TWO_IN(fdivs)
FPS_TWO_IN(fmuls)
FPS_TWO_IN(fsubs)
FPS_THREE_IN(fmadds)
FPS_THREE_IN(fmsubs)
FPS_THREE_IN(fnmadds)
FPS_THREE_IN(fnmsubs)
FPS_THREE_IN(fsel)


/* Instructions operating on double parameters */

/*
 * Beginning of double instruction processing
 *
 * R3 = (double*)&fpscr
 * R4 = (u32*)&cr
 * R5 = (double*)&result
 * R6 = (double*)&param1
 * R7 = (double*)&param2 [load_two]
 * R8 = (double*)&param3 [load_three]
 * LR = instruction call function
 */
fpd_load_three:
	lfd	2,0(r8)			/* load param3 */
fpd_load_two:
	lfd	1,0(r7)			/* load param2 */
fpd_load_one:
	lfd	0,0(r6)			/* load param1 */
fpd_load_none:
	lfd	3,0(r3)			/* load up fpscr value */
	MTFSF_L(3)
	lwz	r6, 0(r4)		/* load cr */
	mtcr	r6
	blr

/*
 * End of double instruction processing
 *
 * R3 = (double*)&fpscr
 * R4 = (u32*)&cr
 * R5 = (double*)&result
 * LR = caller of instruction call function
 */
fpd_return:
	mfcr	r6
	stfd	0,0(r5)			/* save result */
	mffs	0
	stfd	0,0(r3)			/* save new fpscr value */
	stw	r6,0(r4)		/* save new cr value */
	blr

/*
 * Double operation with no input operand
 *
 * R3 = (double*)&fpscr
 * R4 = (u32*)&cr
 * R5 = (double*)&result
 */
#define FPD_NONE_IN(name) 						\
_GLOBAL(fpd_ ## name);							\
	mflr	r12;							\
	bl	fpd_load_none;						\
	mtlr	r12;							\
									\
	name.	0;			/* call instruction */		\
	b	fpd_return

/*
 * Double operation with one input operand
 *
 * R3 = (double*)&fpscr
 * R4 = (u32*)&cr
 * R5 = (double*)&result
 * R6 = (double*)&param1
 */
#define FPD_ONE_IN(name) 						\
_GLOBAL(fpd_ ## name);							\
	mflr	r12;							\
	bl	fpd_load_one;						\
	mtlr	r12;							\
									\
	name.	0,0;			/* call instruction */		\
	b	fpd_return

/*
 * Double operation with two input operands
 *
 * R3 = (double*)&fpscr
 * R4 = (u32*)&cr
 * R5 = (double*)&result
 * R6 = (double*)&param1
 * R7 = (double*)&param2
 * R8 = (double*)&param3
 */
#define FPD_TWO_IN(name) 						\
_GLOBAL(fpd_ ## name);							\
	mflr	r12;							\
	bl	fpd_load_two;						\
	mtlr	r12;							\
									\
	name.	0,0,1;			/* call instruction */		\
	b	fpd_return

/*
 * CR Double operation with two input operands
 *
 * R3 = (double*)&fpscr
 * R4 = (u32*)&cr
 * R5 = (double*)&param1
 * R6 = (double*)&param2
 * R7 = (double*)&param3
 */
#define FPD_TWO_IN_CR(name)						\
_GLOBAL(fpd_ ## name);							\
	lfd	1,0(r6);		/* load param2 */		\
	lfd	0,0(r5);		/* load param1 */		\
	lfd	3,0(r3);		/* load up fpscr value */	\
	MTFSF_L(3);							\
	lwz	r6, 0(r4);		/* load cr */			\
	mtcr	r6;							\
									\
	name	0,0,1;			/* call instruction */		\
	mfcr	r6;							\
	mffs	0;							\
	stfd	0,0(r3);		/* save new fpscr value */	\
	stw	r6,0(r4);		/* save new cr value */		\
	blr

/*
 * Double operation with three input operands
 *
 * R3 = (double*)&fpscr
 * R4 = (u32*)&cr
 * R5 = (double*)&result
 * R6 = (double*)&param1
 * R7 = (double*)&param2
 * R8 = (double*)&param3
 */
#define FPD_THREE_IN(name) 						\
_GLOBAL(fpd_ ## name);							\
	mflr	r12;							\
	bl	fpd_load_three;						\
	mtlr	r12;							\
									\
	name.	0,0,1,2;		/* call instruction */		\
	b	fpd_return

FPD_ONE_IN(fsqrts)
FPD_ONE_IN(frsqrtes)
FPD_ONE_IN(fres)
FPD_ONE_IN(frsp)
FPD_ONE_IN(fctiw)
FPD_ONE_IN(fctiwz)
FPD_ONE_IN(fsqrt)
FPD_ONE_IN(fre)
FPD_ONE_IN(frsqrte)
FPD_ONE_IN(fneg)
FPD_ONE_IN(fabs)
FPD_TWO_IN(fadds)
FPD_TWO_IN(fsubs)
FPD_TWO_IN(fdivs)
FPD_TWO_IN(fmuls)
FPD_TWO_IN_CR(fcmpu)
FPD_TWO_IN(fcpsgn)
FPD_TWO_IN(fdiv)
FPD_TWO_IN(fadd)
FPD_TWO_IN(fmul)
FPD_TWO_IN_CR(fcmpo)
FPD_TWO_IN(fsub)
FPD_THREE_IN(fmsubs)
FPD_THREE_IN(fmadds)
FPD_THREE_IN(fnmsubs)
FPD_THREE_IN(fnmadds)
FPD_THREE_IN(fsel)
FPD_THREE_IN(fmsub)
FPD_THREE_IN(fmadd)
FPD_THREE_IN(fnmsub)
FPD_THREE_IN(fnmadd)

_GLOBAL(kvm_cvt_fd)
	lfd	0,0(r5)			/* load up fpscr value */
	MTFSF_L(0)
	lfs	0,0(r3)
	stfd	0,0(r4)
	mffs	0
	stfd	0,0(r5)			/* save new fpscr value */
	blr

_GLOBAL(kvm_cvt_df)
	lfd	0,0(r5)			/* load up fpscr value */
	MTFSF_L(0)
	lfd	0,0(r3)
	stfs	0,0(r4)
	mffs	0
	stfd	0,0(r5)			/* save new fpscr value */
	blr
OpenPOWER on IntegriCloud