summaryrefslogtreecommitdiffstats
path: root/src/arch/arm/arm-vfp-codegen.h
blob: 8b56b00dbbee462d56c19c9089a64aae9687403a (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
//
// Copyright 2011 Xamarin Inc
//

#ifndef __MONO_ARM_VFP_CODEGEN_H__
#define __MONO_ARM_VFP_CODEGEN_H__

#include "arm-codegen.h"

enum {
	/* VFP registers */
	ARM_VFP_F0,
	ARM_VFP_F1,
	ARM_VFP_F2,
	ARM_VFP_F3,
	ARM_VFP_F4,
	ARM_VFP_F5,
	ARM_VFP_F6,
	ARM_VFP_F7,
	ARM_VFP_F8,
	ARM_VFP_F9,
	ARM_VFP_F10,
	ARM_VFP_F11,
	ARM_VFP_F12,
	ARM_VFP_F13,
	ARM_VFP_F14,
	ARM_VFP_F15,
	ARM_VFP_F16,
	ARM_VFP_F17,
	ARM_VFP_F18,
	ARM_VFP_F19,
	ARM_VFP_F20,
	ARM_VFP_F21,
	ARM_VFP_F22,
	ARM_VFP_F23,
	ARM_VFP_F24,
	ARM_VFP_F25,
	ARM_VFP_F26,
	ARM_VFP_F27,
	ARM_VFP_F28,
	ARM_VFP_F29,
	ARM_VFP_F30,
	ARM_VFP_F31,

	ARM_VFP_D0 = ARM_VFP_F0,
	ARM_VFP_D1 = ARM_VFP_F2,
	ARM_VFP_D2 = ARM_VFP_F4,
	ARM_VFP_D3 = ARM_VFP_F6,
	ARM_VFP_D4 = ARM_VFP_F8,
	ARM_VFP_D5 = ARM_VFP_F10,
	ARM_VFP_D6 = ARM_VFP_F12,
	ARM_VFP_D7 = ARM_VFP_F14,
	ARM_VFP_D8 = ARM_VFP_F16,
	ARM_VFP_D9 = ARM_VFP_F18,
	ARM_VFP_D10 = ARM_VFP_F20,
	ARM_VFP_D11 = ARM_VFP_F22,
	ARM_VFP_D12 = ARM_VFP_F24,
	ARM_VFP_D13 = ARM_VFP_F26,
	ARM_VFP_D14 = ARM_VFP_F28,
	ARM_VFP_D15 = ARM_VFP_F30,

	ARM_VFP_COPROC_SINGLE = 10,
	ARM_VFP_COPROC_DOUBLE = 11,

#define ARM_VFP_OP(p,q,r,s) (((p) << 23) | ((q) << 21) | ((r) << 20) | ((s) << 6))
#define ARM_VFP_OP2(Fn,N) (ARM_VFP_OP (1,1,1,1) | ((Fn) << 16) | ((N) << 7))

	ARM_VFP_MUL = ARM_VFP_OP (0,1,0,0),
	ARM_VFP_NMUL = ARM_VFP_OP (0,1,0,1),
	ARM_VFP_ADD = ARM_VFP_OP (0,1,1,0),
	ARM_VFP_SUB = ARM_VFP_OP (0,1,1,1),
	ARM_VFP_DIV = ARM_VFP_OP (1,0,0,0),

	ARM_VFP_CPY = ARM_VFP_OP2 (0,0),
	ARM_VFP_ABS = ARM_VFP_OP2 (0,1),
	ARM_VFP_NEG = ARM_VFP_OP2 (1,0),
	ARM_VFP_SQRT = ARM_VFP_OP2 (1,1),
	ARM_VFP_CMP = ARM_VFP_OP2 (4,0),
	ARM_VFP_CMPE = ARM_VFP_OP2 (4,1),
	ARM_VFP_CMPZ = ARM_VFP_OP2 (5,0),
	ARM_VFP_CMPEZ = ARM_VFP_OP2 (5,1),
	ARM_VFP_CVT = ARM_VFP_OP2 (7,1),
	ARM_VFP_UITO = ARM_VFP_OP2 (8,0),
	ARM_VFP_SITO = ARM_VFP_OP2 (8,1),
	ARM_VFP_TOUI = ARM_VFP_OP2 (12,0),
	ARM_VFP_TOSI = ARM_VFP_OP2 (13,0),
	ARM_VFP_TOUIZ = ARM_VFP_OP2 (12,1),
	ARM_VFP_TOSIZ = ARM_VFP_OP2 (13,1),

	ARM_VFP_SID = 0,
	ARM_VFP_SCR = 1 << 1,
	ARM_VFP_EXC = 8 << 1
};

#define ARM_DEF_VFP_DYADIC(cond,cp,op,Fd,Fn,Fm)	\
	(14 << 24)				|	\
	((cp) << 8)				|	\
	(op)					|	\
	(((Fd) >> 1) << 12)			|	\
	(((Fd) & 1) << 22)			|	\
	(((Fn) >> 1) << 16)			|	\
	(((Fn) & 1) << 7)			|	\
	(((Fm) >> 1) << 0)			|	\
	(((Fm) & 1) << 5)			|	\
	ARM_DEF_COND(cond)

#define ARM_DEF_VFP_MONADIC(cond,cp,op,Fd,Fm)	\
	(14 << 24)				|	\
	((cp) << 8)				|	\
	(op)					|	\
	(((Fd) >> 1) << 12)			|	\
	(((Fd) & 1) << 22)			|	\
	(((Fm) >> 1) << 0)			|	\
	(((Fm) & 1) << 5)			|	\
	ARM_DEF_COND(cond)

#define ARM_DEF_VFP_LSF(cond,cp,post,ls,wback,basereg,Fd,offset)	\
	((offset) >= 0? (offset)>>2: -(offset)>>2)	|	\
	(6 << 25)					|	\
	((cp) << 8)					|	\
	(((Fd) >> 1) << 12)				|	\
	(((Fd) & 1) << 22)				|	\
	((basereg) << 16)				|	\
	((ls) << 20)					|	\
	((wback) << 21)					|	\
	(((offset) >= 0) << 23)				|	\
	((wback) << 21)					|	\
	((post) << 24)					|	\
	ARM_DEF_COND(cond)

#define ARM_DEF_VFP_CPT(cond,cp,op,L,Fn,Rd)	\
	(14 << 24)				|	\
	(1 << 4)				|	\
	((cp) << 8)				|	\
	((op) << 21)				|	\
	((L) << 20)				|	\
	((Rd) << 12)				|	\
	(((Fn) >> 1) << 16)			|	\
	(((Fn) & 1) << 7)			|	\
	ARM_DEF_COND(cond)

/* FP load and stores */
#define ARM_FLDS_COND(p,freg,base,offset,cond)	\
	ARM_EMIT((p), ARM_DEF_VFP_LSF((cond),ARM_VFP_COPROC_SINGLE,1,ARMOP_LDR,0,(base),(freg),(offset)))
#define ARM_FLDS(p,freg,base,offset)	\
	ARM_FLDS_COND(p,freg,base,offset,ARMCOND_AL)

#define ARM_FLDD_COND(p,freg,base,offset,cond)	\
	ARM_EMIT((p), ARM_DEF_VFP_LSF((cond),ARM_VFP_COPROC_DOUBLE,1,ARMOP_LDR,0,(base),(freg),(offset)))
#define ARM_FLDD(p,freg,base,offset)	\
	ARM_FLDD_COND(p,freg,base,offset,ARMCOND_AL)

#define ARM_FSTS_COND(p,freg,base,offset,cond)	\
	ARM_EMIT((p), ARM_DEF_VFP_LSF((cond),ARM_VFP_COPROC_SINGLE,1,ARMOP_STR,0,(base),(freg),(offset)))
#define ARM_FSTS(p,freg,base,offset)	\
	ARM_FSTS_COND(p,freg,base,offset,ARMCOND_AL)

#define ARM_FSTD_COND(p,freg,base,offset,cond)	\
	ARM_EMIT((p), ARM_DEF_VFP_LSF((cond),ARM_VFP_COPROC_DOUBLE,1,ARMOP_STR,0,(base),(freg),(offset)))
#define ARM_FSTD(p,freg,base,offset)	\
	ARM_FSTD_COND(p,freg,base,offset,ARMCOND_AL)

#define ARM_FLDMD_COND(p,first_reg,nregs,base,cond)							\
	ARM_EMIT((p), ARM_DEF_VFP_LSF((cond),ARM_VFP_COPROC_DOUBLE,0,ARMOP_LDR,0,(base),(first_reg),((nregs) * 2) << 2))

#define ARM_FLDMD(p,first_reg,nregs,base)		\
	ARM_FLDMD_COND(p,first_reg,nregs,base,ARMCOND_AL)

#define ARM_FSTMD_COND(p,first_reg,nregs,base,cond)							\
	ARM_EMIT((p), ARM_DEF_VFP_LSF((cond),ARM_VFP_COPROC_DOUBLE,0,ARMOP_STR,0,(base),(first_reg),((nregs) * 2) << 2))

#define ARM_FSTMD(p,first_reg,nregs,base)		\
	ARM_FSTMD_COND(p,first_reg,nregs,base,ARMCOND_AL)

#include <mono/arch/arm/arm_vfpmacros.h>

/* coprocessor register transfer */
#define ARM_FMSR(p,freg,reg)	\
	ARM_EMIT((p), ARM_DEF_VFP_CPT(ARMCOND_AL,ARM_VFP_COPROC_SINGLE,0,0,(freg),(reg)))
#define ARM_FMRS(p,reg,freg)	\
	ARM_EMIT((p), ARM_DEF_VFP_CPT(ARMCOND_AL,ARM_VFP_COPROC_SINGLE,0,1,(freg),(reg)))

#define ARM_FMDLR(p,freg,reg)	\
	ARM_EMIT((p), ARM_DEF_VFP_CPT(ARMCOND_AL,ARM_VFP_COPROC_DOUBLE,0,0,(freg),(reg)))
#define ARM_FMRDL(p,reg,freg)	\
	ARM_EMIT((p), ARM_DEF_VFP_CPT(ARMCOND_AL,ARM_VFP_COPROC_DOUBLE,0,1,(freg),(reg)))
#define ARM_FMDHR(p,freg,reg)	\
	ARM_EMIT((p), ARM_DEF_VFP_CPT(ARMCOND_AL,ARM_VFP_COPROC_DOUBLE,1,0,(freg),(reg)))
#define ARM_FMRDH(p,reg,freg)	\
	ARM_EMIT((p), ARM_DEF_VFP_CPT(ARMCOND_AL,ARM_VFP_COPROC_DOUBLE,1,1,(freg),(reg)))

#define ARM_FMXR(p,freg,reg)	\
	ARM_EMIT((p), ARM_DEF_VFP_CPT(ARMCOND_AL,ARM_VFP_COPROC_SINGLE,7,0,(freg),(reg)))
#define ARM_FMRX(p,reg,fcreg)	\
	ARM_EMIT((p), ARM_DEF_VFP_CPT(ARMCOND_AL,ARM_VFP_COPROC_SINGLE,7,1,(fcreg),(reg)))

#define ARM_FMSTAT(p)   \
	ARM_FMRX((p),ARMREG_R15,ARM_VFP_SCR)

#define ARM_DEF_MCRR(cond,cp,rn,rd,Fm,M) \
	((Fm) << 0) |					   \
	(1 << 4)   |					   \
	((M) << 5) |					   \
	((cp) << 8) |					   \
	((rd) << 12) |					   \
	((rn) << 16) |					   \
	((2) << 21) |					   \
	(12 << 24) |					   \
	ARM_DEF_COND(cond)

#define ARM_FMDRR(p,rd,rn,dm)   \
	ARM_EMIT((p), ARM_DEF_MCRR(ARMCOND_AL,ARM_VFP_COPROC_DOUBLE,(rn),(rd),(dm) >> 1, (dm) & 1))

#define ARM_DEF_FMRRD(cond,cp,rn,rd,Dm,D)		\
	((Dm) << 0) |					   \
	(1 << 4)   |					   \
	((cp) << 8) |					   \
	((rd) << 12) |					   \
	((rn) << 16) |					   \
	((0xc5) << 20) |					   \
	ARM_DEF_COND(cond)

#define ARM_FMRRD(p,rd,rn,dm)   \
	ARM_EMIT((p), ARM_DEF_FMRRD(ARMCOND_AL,ARM_VFP_COPROC_DOUBLE,(rn),(rd),(dm) >> 1, (dm) & 1))

#define ARM_DEF_FUITOS(cond,Dd,D,Fm,M) ((cond) << 28) | ((0x1d) << 23) | ((D) << 22) | ((0x3) << 20) | ((8) << 16) | ((Dd) << 12) | ((0xa) << 8) | ((1) << 6) | ((M) << 5) | ((Fm) << 0)

#define ARM_FUITOS(p,dreg,sreg) \
	ARM_EMIT((p), ARM_DEF_FUITOS (ARMCOND_AL, (dreg) >> 1, (dreg) & 1, (sreg) >> 1, (sreg) & 1))

#define ARM_DEF_FUITOD(cond,Dd,D,Fm,M) ((cond) << 28) | ((0x1d) << 23) | ((D) << 22) | ((0x3) << 20) | ((8) << 16) | ((Dd) << 12) | ((0xb) << 8) | ((1) << 6) | ((M) << 5) | ((Fm) << 0)

#define ARM_FUITOD(p,dreg,sreg) \
	ARM_EMIT((p), ARM_DEF_FUITOD (ARMCOND_AL, (dreg) >> 1, (dreg) & 1, (sreg) >> 1, (sreg) & 1))

#define ARM_DEF_FSITOS(cond,Dd,D,Fm,M) ((cond) << 28) | ((0x1d) << 23) | ((D) << 22) | ((0x3) << 20) | ((8) << 16) | ((Dd) << 12) | ((0xa) << 8) | ((1) << 7) | ((1) << 6) | ((M) << 5) | ((Fm) << 0)

#define ARM_FSITOS(p,dreg,sreg) \
	ARM_EMIT((p), ARM_DEF_FSITOS (ARMCOND_AL, (dreg) >> 1, (dreg) & 1, (sreg) >> 1, (sreg) & 1))

#define ARM_DEF_FSITOD(cond,Dd,D,Fm,M) ((cond) << 28) | ((0x1d) << 23) | ((D) << 22) | ((0x3) << 20) | ((8) << 16) | ((Dd) << 12) | ((0xb) << 8) | ((1) << 7) | ((1) << 6) | ((M) << 5) | ((Fm) << 0)

#define ARM_FSITOD(p,dreg,sreg) \
	ARM_EMIT((p), ARM_DEF_FSITOD (ARMCOND_AL, (dreg) >> 1, (dreg) & 1, (sreg) >> 1, (sreg) & 1))

#endif /* __MONO_ARM_VFP_CODEGEN_H__ */

OpenPOWER on IntegriCloud