* jit/codegen-common.h: Enabled dseg_adddata for s390.
[cacao.git] / src / vm / jit / s390 / codegen.h
1 /* src/vm/jit/x86_64/codegen.h - code generation macros for x86_64
2
3    Copyright (C) 1996-2005, 2006 R. Grafl, A. Krall, C. Kruegel,
4    C. Oates, R. Obermaisser, M. Platter, M. Probst, S. Ring,
5    E. Steiner, C. Thalinger, D. Thuernbeck, P. Tomsich, C. Ullrich,
6    J. Wenninger, Institut f. Computersprachen - TU Wien
7
8    This file is part of CACAO.
9
10    This program is free software; you can redistribute it and/or
11    modify it under the terms of the GNU General Public License as
12    published by the Free Software Foundation; either version 2, or (at
13    your option) any later version.
14
15    This program is distributed in the hope that it will be useful, but
16    WITHOUT ANY WARRANTY; without even the implied warranty of
17    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
18    General Public License for more details.
19
20    You should have received a copy of the GNU General Public License
21    along with this program; if not, write to the Free Software
22    Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
23    02110-1301, USA.
24
25    Contact: cacao@cacaojvm.org
26
27    Authors: Andreas Krall
28             Christian Thalinger
29
30    $Id: codegen.h 7283 2007-02-04 19:41:14Z pm $
31
32 */
33
34
35 #ifndef _CODEGEN_H
36 #define _CODEGEN_H
37
38 #include "config.h"
39
40 #include <ucontext.h>
41
42 #include "vm/types.h"
43
44 #include "vm/jit/jit.h"
45
46
47 /* additional functions and macros to generate code ***************************/
48
49 #define CALCOFFSETBYTES(var, reg, val) \
50     if ((s4) (val) < -128 || (s4) (val) > 127) (var) += 4; \
51     else if ((s4) (val) != 0) (var) += 1; \
52     else if ((reg) == RBP || (reg) == RSP || (reg) == R12 || (reg) == R13) (var) += 1;
53
54
55 #define CALCIMMEDIATEBYTES(var, val) \
56     if ((s4) (val) < -128 || (s4) (val) > 127) (var) += 4; \
57     else (var) += 1;
58
59
60 /* gen_nullptr_check(objreg) */
61
62 #define gen_nullptr_check(objreg) \
63         if (checknull) { \
64         M_TEST(objreg); \
65         M_BEQ(0); \
66             codegen_add_nullpointerexception_ref(cd); \
67         }
68
69
70 #define gen_bound_check \
71     if (checkbounds) { \
72         M_ILD(REG_ITMP3, s1, OFFSET(java_arrayheader, size));\
73         M_ICMP(REG_ITMP3, s2); \
74         M_BAE(0); \
75         codegen_add_arrayindexoutofboundsexception_ref(cd, s2); \
76     }
77
78
79 /* MCODECHECK(icnt) */
80
81 #define MCODECHECK(icnt) \
82     do { \
83         if ((cd->mcodeptr + (icnt)) > cd->mcodeend) \
84             codegen_increase(cd); \
85     } while (0)
86
87
88 #define ALIGNCODENOP \
89     if ((s4) (((ptrint) cd->mcodeptr) & 7)) { \
90         M_NOP; \
91     }
92
93
94
95 #define ICONST(r,c) \
96     do { \
97         if ((c) == 0) \
98             M_CLR((d)); \
99         else \
100             M_IMOV_IMM((c), (d)); \
101     } while (0)
102 /*     do { \ */
103 /*        M_IMOV_IMM((c), (d)); \ */
104 /*     } while (0) */
105
106
107 #define LCONST(r,c) \
108     do { \
109         if ((c) == 0) \
110             M_CLR((d)); \
111         else \
112             M_MOV_IMM((c), (d)); \
113     } while (0)
114
115 /* branch defines *************************************************************/
116
117 #define BRANCH_NOPS \
118     do { \
119         M_NOP; \
120         M_NOP; \
121         M_NOP; \
122         M_NOP; \
123         M_NOP; \
124     } while (0)
125
126
127 /* some patcher defines *******************************************************/
128
129 #define PATCHER_CALL_SIZE    5          /* size in bytes of a patcher call    */
130
131 #define PATCHER_NOPS \
132     do { \
133         M_NOP; \
134         M_NOP; \
135         M_NOP; \
136         M_NOP; \
137         M_NOP; \
138     } while (0)
139
140
141 /* macros to create code ******************************************************/
142
143 /* Conventions:
144  * N_foo:   defines the instrucition foo as in `ESA/390 Principles of operations'
145  * SZ_foo:  defines the size of the instruction N_foo
146  * DD_foo:  defines a condition code as used by s390 GCC
147  * M_foo:   defines the alpha like instruction used in cacao
148  *          the instruction is defined by an equivalent N_ instruction
149  * CC_foo:  defines a condition code as used
150  *          the instruction is defined as an equivalent DD_ condition code
151  */
152
153 /* S390 specific code */
154
155 /* Argument checks for debug mode */
156
157 /* Some instructions with register arguments treat %r0 as "value not given".
158  * To prevent bugs, in debug mode we use a special value RN (reg none) with 
159  * the meaning "value not given".
160  * In debug mode, the instructions assert that %r0 was not given as argument.
161  */
162
163 #if 1
164 #       include <stdlib.h>
165         /* register none */
166 #       define RN 16
167         /* Optional register.
168          * Check that value given is %r1 - %r15 or RN
169          */
170 #       define _WITH_LINE(f, ...) f(__FILE__, __LINE__, __VA_ARGS__)
171         static inline int _OR_IMPL(const char *file, int line, int r) {
172                 if(!(
173                         ((0 < r) && (r < 16)) ||
174                         (r == RN)
175                 )) {
176                         fprintf(stdout, "%d is not a valid register at %s:%d.\n", r, file, line);
177                         abort();
178                 }
179                 return ((r == RN) ? 0 : r);
180         }
181 #       define _OR(r) _WITH_LINE(_OR_IMPL, r)
182
183 #       define _SMIN(b) (-(1 << (bits - 1)))
184 #       define _SMAX(b) ((1 << (b - 1)) - 1)
185 #       define _UMIN(b) 0
186 #       define _UMAX(b) ((1 << b) - 1)
187
188         static inline int _UBITS_IMPL(const char *file, int line, int i, int bits) {
189                 if (!((_UMIN(bits) <= i) && (i <= _UMAX(bits)))) {
190                         fprintf(stdout, "%d (0x%X) is not an unsigned %d bit integer at %s:%d.\n", i, i, bits, file, line);
191                         abort();
192                 }
193                 return i;
194         }
195 #       define _UBITS(i, bits) _WITH_LINE(_UBITS_IMPL, i, bits)
196         static inline int _SBITS_IMPL(const char *file, int line, int i, int bits) {
197                 if(!((_SMIN(bits) <= i) && (i <= _SMAX(bits)))) {
198                         fprintf(stdout, "%d (0x%X) is not an signed %d bit integer at %s:%d.\n", i, i, bits, file, line);
199                         abort();
200                 }
201                 return i;
202         }
203 #       define _SBITS(i, bits) _WITH_LINE(_SBITS_IMPL, i, bits)
204         static inline int _BITS_IMPL(const char *file, int line, int i, int bits) {
205                 if (!(
206                         ((_UMIN(bits) <= i) && (i <= _UMAX(bits))) ||
207                         ((_SMIN(bits) <= i) && (i <= _SMAX(bits)))
208                 )) {
209                         fprintf(stdout, "%d (0x%X) is not an %d bit integer at %s:%d.\n", i, i, bits, file, line);
210                         abort();
211                 }
212                 return i;
213         }
214 #       define _BITS(i, bits) _WITH_LINE(_BITS_IMPL, i, bits)
215 #else
216 #       define RN 0
217 #       define _OR(x) (x)
218 #       define _BITS(x, b) (x)
219 #       define _UBITS(x, b) (x)
220 #       define _SBITS(x, b) (x)
221 #endif
222
223 /* Register */
224 #define _R(x) _UBITS((x), 4)
225 /* Displacement */
226 #define _D(x) _UBITS((x), 12)
227 /* 4 bit Immediate */
228 #define _I4(x) _BITS((x), 4)
229 #define _UI4(x) _UBITS((x), 4)
230 #define _SI4(x) _SBITS((x), 4)
231 /* 8 bit Immediate */
232 #define _I8(x) _BITS((x), 8)
233 #define _UI8(x) _UBITS((x), 8)
234 #define _SI8(x) _SBITS((x), 8)
235 /* 12 bit Immediate */
236 #define _I12(x) _BITS((x), 12)
237 #define _UI12(x) _UBITS((x), 12)
238 #define _SI12(x) _SBITS((x), 12)
239 /* 16 bit Immediate */
240 #define _I16(x) _BITS((x), 16)
241 #define _UI16(x) _UBITS((x), 16)
242 #define _SI16(x) _SBITS((x), 16)
243 /* Opcode */
244 #define _OP(x) _UBITS((x), 8)
245 /* Second part of opcode */
246 #define _OP4(x) _UBITS((x), 4)
247 /* Extended opcode */
248 #define _OP16(x) _UBITS((x), 16)
249
250 /* Instruction formats */
251
252 #define _CODE(t, code) \
253         do { \
254                 *((t *) cd->mcodeptr) = (code); \
255                 cd->mcodeptr += sizeof(t); \
256         } while (0)
257
258 #define _CODE2(code) _CODE(u2, code)
259 #define _CODE4(code) _CODE(u4, code)
260
261 #define _IFNEG(val, neg, pos) \
262         do { if ((val) < 0) { neg ; } else { pos ; } } while (0)
263
264 #define N_RR(op, r1, r2) \
265         _CODE2( (_OP(op) << 8) | (_R(r1) << 4) | _R(r2) )
266
267 #define SZ_RR 2
268
269 #define N_RR2(op, i) \
270         _CODE2( (_OP(op) << 8) | _I8(i) )
271
272 #define N_RX(op, r1, d2, x2, b2) \
273         _CODE4( (_OP(op) << 24) | (_R(r1) << 20) | (_OR(x2) << 16) | (_OR(b2) << 12) | (_D(d2) << 0) )
274
275 #define SZ_RX 4
276
277 #define N_RI(op1, op2, r1, i2) \
278         _CODE4( (_OP(op1) << 24) | (_R(r1) << 20) | (_OP4(op2) << 16) | (u2)_I16(i2) )
279
280 #define SZ_RI 4
281
282 #define N_SI(op, d1, b1, i2) \
283         _CODE4( (_OP(op) << 24) | (_OR(i2) << 16) | (_OR(b1) << 12) | _D(d1) )
284
285 #define SZ_SI 4
286
287 #define N_SS(op, d1, l, b1, d2, b2) \
288         do { \
289                 _CODE4( (_OP(op) << 24) | (_I8(l) << 16) | (_OR(b1) << 12) | _D(d1) ); \
290                 _CODE2( (_OR(b2) << 12) | _D(d2) ); \
291         } while (0)
292
293 #define SZ_SS 6
294
295 #define N_SS2(op, d1, l1, b1, d2, l2, b2) \
296         N_SS(op, d1, (_I4(l1) << 4) | _I4(l2), b1, d2, l2)
297
298 #define N_RS(op, r1, r3, d2, b2) \
299         _CODE4( (_OP(op) << 24) | (_R(r1) << 20) | (_R(r3) << 16) | (_OR(b2) << 12) | _D(d2) )
300
301 #define SZ_RS 4
302
303 #define N_RSI(op, r1, r2, i2) \
304         _CODE4( ((op) << 24) | (_R(r1) << 20) | (_R(r3) << 16) | (u2)_16(i2) )
305
306 #define SZ_RSI 4
307
308 #define N_RRE(op, r1, r2) \
309         _CODE4( (_OP16(op) << 16) | (_R(r1) << 4) | _R(r2) )
310
311 #define SZ_RRE 4
312
313 #define N_S2(d2, b2) \
314         _CODE4( (_OP16(op) << 16) | (_OR(b2) << 12) | _D(d2)  )
315
316 #define SZ_S2 4
317
318 #define N_E(op) \
319         _CODE2( _OP16(op) )
320
321 #define SZ_E 2
322
323 /* Condition codes */
324
325 #define DD_O 1
326 #define DD_H 2
327 #define DD_NLE 3
328 #define DD_L 4
329 #define DD_NHE 5
330 #define DD_LH 6
331 #define DD_NE 7
332 #define DD_E 8
333 #define DD_NLH 9
334 #define DD_HE 10
335 #define DD_NL 11
336 #define DD_LE 12
337 #define DD_NH 13
338 #define DD_NO 14
339 #define DD_ANY 15
340
341 /* Misc */
342
343 #define N_LONG_0() _CODE4(0)
344
345 /* Chapter 7. General instructions */
346
347 #define N_AR(r1, r2) N_RR(0x1A, r1, r2)
348 #define N_A(r1, d2, x2, b2) N_RX(0x5A, r1, d2, x2, b2)
349 #define N_AH(r1, d2, x2, b2) N_RX(0x4A, r1, d2, x2, b2)
350 #define N_AHI(r1, i2) N_RI(0xA7, 0xA, r1, i2)
351 #       define SZ_AHI SZ_RI
352 #define N_ALR(r1, r2) N_RR(0x1E, r1, r2)
353 #define N_AL(r1, d2, x2, b2) N_RX(0x5E, r1, d2, x2, b2)
354 #define N_NR(r1, r2) N_RR(r1, r2)
355 #define N_N(r1, d2, x2, b2) N_RX(0x54, r1, d2, x2, b2)
356 #define N_NI(d1, b1, i2) N_SI(0x94, d1, b1, i2)
357 #define N_NC(d1, l, b1, d2, b2) N_NC(0xD4, l, b1, d1, b2, d2)
358 #define N_BALR(r1, r2) N_RR(0x05, r1, _OR(r2))
359 #define N_BAL(r1, d2, x2, b2) N_RX(0x45, r1, d2, x2, b2)
360 #define N_BASR(r1, r2) N_RR(0x0D, r1, _OR(r2))
361 #define N_BAS(r1, d2, x2, b2) N_RX(0x4D, r1, d2, x2, b2)
362 #define N_BASSM(r1, r2) N_RR(0x0C, r1, _OR(r2))
363 #define N_BSM(r1, r2) N_RR(0x0B, r1, _OR(r2))
364 #define N_BCR(m1, r2) N_RR(0x07, m1, _OR(r2))
365 #       define SZ_BCR SZ_RR
366 #       define N_BR(r2) N_BCR(DD_ANY, r2)
367 #       define SZ_BR SZ_BCR
368 #define N_BC(m1, d2, x2, b2) N_RS(0x47, m1, d2, x2, b2)
369 #       define SZ_BC SZ_RS
370 #define N_BCTR(r1, r2) N_RR(0x06, r1, _OR(r2))
371 #define N_BCT(r1, d2, x2, b2) N_RX(0x46, r1, d2, x2, b2)
372 #define N_BHX(r1, r2, d2, b2) N_RS(0xB6, r1, r3, d2, b2)
373 #define N_BXLE(r1, r3, d2, b2) N_RS(0xB7, r1, r3, d2, b2)
374 #define N_BRAS(r1, i2) N_RI(0xA7, 0x5, r1, (i2) / 2)
375 #       define SZ_BRAS SZ_RI
376 #define N_BRC(m1, i2) N_RI(0xA7, 0x4, m1, (i2) / 2)
377 #       define N_J(i2) N_BRC(DD_ANY, i2)
378 #       define SZ_BRC SZ_RI
379 #       define SZ_J SZ_RI
380 #define N_BRCT(r1, i2) N_RI(0xA7, 0x6, r1, (i2) / 2)
381 #define N_BRXH(r1, r3, i2) N_RSI(0x84, r1, r3, (i2) / 2)
382 #define N_BRXLE(r1, r3, i2) N_RSI(0x85, r1, r2, (i2) / 2)
383 #define N_CKSM(r1, r2) N_RRE(0xB241, r1, r2)
384 #define N_CR(r1, r2) N_RR(0x19, r1, r2)
385 #       define SZ_CR SZ_RR
386 #define N_C(r1, d2, x2, b2) N_RX(0x59, r1, d2, x2, b2)
387 #define N_CFC(d2, b2) N_S2(0xB21A, d2, b2)
388 #define N_CS(r1, r3, d2, b2) N_RS(0xBA, r1, r3, d2, b2)
389 #define N_CDS(r1, r3, d2, b2) N_RS(0xBB, r1, r3, d2, b2)
390 #define N_CH(r1, d2, x2, b2) N_CH(0x49, r1, d2, x2, b2)
391 #define N_CHI(r1, i2) N_RI(0xA7, 0xE, r1, i2)
392 #define N_CLR(r1, r2) N_RR(0x15, r1, r2)
393 #define N_CL(r1, d2, x2, b2) N_RX(0x55, r1, d2, x2, b2)
394 #define N_CLI(d1, b1, i2) N_SI(0x95, d1, b1, i2)
395 #define N_CLC(d1, l, b1, d2, b2) N_SS(0xD5, d1, l, b1, d2, b2)
396 #define N_CLM(r1, m3, d2, b2) N_RS(0xBD, r1, m3, d2, b2)
397 #define N_CLCL(r1, r2) N_RR(0x0F, r1, r2)
398 #define N_CLCLE(r1, r3, d2, b2) N_RS(0xA9, r1, r3, d2, b2)
399 #define N_CLST(r1, r2) N_RRE(0xB25D, r1, r2)
400 #define N_CUSE(r1, r2) N_RRE(0xB257, r1, r2)
401 #define N_CVB(r1, d2, x2, b2) N_RX(0x4F, r1, r2, x2, b2)
402 #define N_CVD(r1, d2, x2, b2) N_RX(0x4E, r1, d2, x2, b2)
403 #define N_CUUTF(r1, r2) N_RRE(0xB2A6, r1, r2)
404 #define N_CUTFU(r1, r2) N_RRE(0xB2A7, r1, r2)
405 #define N_CPYA(r1, r2) N_RRE(0xB240, r1, r2)
406 #define N_DR(r1, r2) N_RR(0x1D, r1, r2)
407 #define N_D(r1, d2, x2, b2) N_RX(0x5D, r1, d2, x2, b2)
408 #define N_XR(r1, r2) N_RR(0x17, r1, r2)
409 #define N_X(r1, d2, x2, b2) N_RX(0x57, r1, d2, x2, b2)
410 #define N_XI(d1, b1, i2) N_SI(0x97, d1, b1, i2)
411 #define N_XC(d1, l, b1, d2, b2) N_SS(0xD7, d1, l, b1, d2, b2)
412 #define N_EX(r1, d2, x2, b2) N_RX(0x44, r1, d2, x2, b2)
413 #define N_EAR(r1, r2) N_RRE(0xB24F, r1, r2)
414 #define N_IC(r1, d2, x2, b2) N_RX(0x43, r1, d2, x2, b2)
415 #define N_ICM(r1, m3, d2, b2) N_RS(0xBF, r1, m3, d2, b2)
416 #define N_IPM(r1) N_RRE(0xB222, r1, 0)
417 #define N_LR(r1, r2) N_RR(0x18, r1, r2)
418 #define N_L(r1, d2, x2, b2) N_RX(0x58, r1, d2, x2, b2)
419 #       define SZ_L SZ_RX
420 #define N_LAM(r1, r3, d2, b2) N_RS(0x9A, r1, r3, d2, b2)
421 #define N_LA(r1, d2, x2, b2) N_RX(0x41, r1, d2, x2, b2)
422 #define N_LAE(r1, d2, x2, b2) N_RX(0x51, r1, d2, x2, b2)
423 #define N_LTR(r1, r2) N_RR(0x12, r1, r2)
424 #define N_LCR(r1, r2) N_RR(0x13, r1, r2)
425 #define N_LH(r1, d2, x2, b2) N_RX(0x48, r1, d2, x2, b2)
426 #define N_LHI(r1, i2) N_RI(0xA7, 0x8, r1, i2)
427 #define N_LM(r1, r3, d2, b2) N_RS(0x98, r1, r3, d2, b2)
428 #define N_LNR(r1, r2) N_RR(0x11, r1, r2)
429 #define N_LPR(r1, r2) N_RR(0x10, r1, r2)
430 #define N_MC(d1, b1, i2) N_SI(0xAF, d1, b1, i2)
431 #define N_MVI(d1, b1, i2) N_SI(0x92, d1, b1, i2)
432 #define N_MVC(d1, l, b1, d2, b2) N_SS(0xD2, d1, l, b1, d2, b2)
433 #define N_MVCIN(d1, l, b1, d2, b2) N_SS(0xEB, d1, l, b1, d2, b2)
434 #define N_MVCL(r1, r2) N_RR(0x0E, r1, r2)
435 #define N_MVCLE(r1, r3, d2, b2)  N_RS(0xAB, r1, r3, d2, b2)
436 #define N_MVN(d1, l, b1, d2, b2) N_SS(0xD1, d1, l, b1, d2, b2)
437 #define N_MVPG(r1, r2) N_RRE(0xB254, r1, r2)
438 #define N_MVST(r1, r2) N_RRE(0xB255, r1, r2)
439 #define N_MVO(d1, l1, b1, d2, l2, b2) N_SS2(0xF1, d1, l1, b1, d2, l2, b2)
440 #define N_MVZ(d1, l, b1, d2, b2) N_SS(0xD3, d1, l, b1, d2, b2)
441 #define N_MR(r1, r2) N_RR(0x1C, r1, r2)
442 #define N_M(r1, d2, x2, b2) N_RX(0x5C, r1, d2, x2, b2)
443 #define N_MH(r1, d2, x2, b2) N_RX(0x4C, r1, d2, x2, b2)
444 #define N_MHI(r1, i2) N_RI(0xA7, 0xC, r1, i2)
445 #define N_MSR(r1, r2) N_RRE(0xB252, r1, r2)
446 #define N_MS(r1, d2, x2, b2) N_RX(0x71, r1, d2, x2, b2)
447 #define N_OR(r1, r2) N_RR(0x16, r1, r2)
448 #define N_O(r1, d2, x2, b2) N_RX(0x56, r1, d2, x2, b2)
449 #define N_OI(d1, b1, i2) N_SI(0x96, d1, b1, i2)
450 #define N_OC(d1, l, b1, d2, b2) N_SS(0xD6, d1, l, b1, d2, b2)
451 #define N_PACK(d1, l1, b1, d2, l2, b2) N_SS2(0xF2, d1, l1, b1, d2, l2, b2)
452 #define N_PLO(r1, d2, b2, r3, d4, b4) N_SS2(0xEE, d2, r1, b2, d4, r3, b4)
453 #define N_SRST(r1, r2) N_RRE(0xB25E, r1, r2)
454 #define N_SAR(r1, r2) N_RRE(0xB24E, r1, r2)
455 #define N_SPM(r1) N_RR(0x04, r1, 0x00)
456 #define N_SLDA(r1, d2, b2) N_RS(0x8F, r1, 0x00, d2, b2)
457 #define N_SLDL(r1, d2, b2) N_RS(0x8D, r1, 0x00, d2, b2)
458 #define N_SLA(r1, d2, b2) N_RS(0x8B, r1, 0x00, d2, b2)
459 #define N_SLL(r1, d2, b2) N_RS(0x89, r1, 0x00, d2, b2)
460 #define N_SRDA(r1, d2, b2) N_RS(0x8E, r1, 0x00, d2, b2)
461 #define N_SRDL(r1, d2, b2) N_RS(0x8C, r1, 0x00, d2, b2)
462 #define N_SRA(r1, d2, b2) N_RS(0x8A, r1, 0x00, d2, b2)
463 #define N_SRL(r1, d2, b2) N_RS(0x88, r1, 0x00, d2, b2)
464 #define N_ST(r1, d2, x2, b2) N_RX(0x50, r1, d2, x2, b2)
465 #define N_STAM(r1, r3, d2, b2) N_RS(0x9B, r1, r3, d2, b2)
466 #define N_STC(r1, d2, x2, b2) N_RX(0x42, r1, d2, x2, b2)
467 #define N_STCM(r1, m3, d2, b2) N_RS(0xBE, r1, m3, d2, b2)
468 #define N_STCK(d2, b2) N_S2(0xB205, d2, b2)
469 #define N_STCKE(d2, b2) N_S2(0xB278, d2, b2)
470 #define N_STH(r1, d2, x2, b2) N_RX(0x40, r1, d2, x2, b2)
471 #define N_STM(r1, r3, d2, b2) N_RS(0x90, r1, r3, d2, b2)
472 #define N_SR(r1, r2) N_RR(0x1B, r1, r2)
473 #define N_S(r1, d2, x2, b2) N_RX(0x5B, r1, d2, x2, b2)
474 #define N_SH(r1, d2, x2, b2) N_RX(0x4B, r1, d2, x2, b2)
475 #define N_SLR(r1, r2) N_RR(0x1F, r1, r2)
476 #define N_SL(r1, d2, x2, b2) N_RX(0x5F, r1, d2, x2, b2)
477 #define N_SVC(i) N_RR2(0x0A, i)
478 #define N_TS(d2, b2) N_S2(0x93, d2, b2)
479 #define N_TM(d1, b1, i2) N_SI(0x91, d1, b1, i2)
480 #define N_TMH(r1, i2) N_RI(0xA7, 0x00, r1, i2)
481 #define N_TML(r1, i2) N_RI(0xA7, 0x01, r1, i2)
482 #define N_TR(d1, l, b1, d2, b2) N_SS(0xDC, d1, l, b1, d2, b2)
483 #define N_TRT(d1, l, b1, d2, b2) N_SS(0xDD, d1, l, b1, d2, b2)
484 #define N_TRE(r1, r2) N_RRE(0xB2A5, r1, r2)
485 #define N_UNPK(d1, l1, b1, d2, l2, b2) N_SS2(0xF3, d1, l1, b1, d2, l2, b2)
486 #define N_UPT() N_E(0x0102)
487
488 /* Chapter 9. Floating point instructions */
489
490 #define N_LER(r1, r2) N_RR(0x38, r1, r2)
491 #define N_LDR(r1, r2) N_RR(0x28, r1, r2)
492 #define N_LXR(r1, r2) N_RRE(0xB365, r1, r2)
493 #define N_LE(r1, d2, x2, b2) N_RX(0x78, r1, d2, x2, b2)
494 #define N_LD(r1, d2, x2, b2) N_RX(0x68, r1, d2, x2, b2)
495 #define N_LZER(r1) N_RRE(0xB374, r1, 0x0)
496 #define N_LZDR(r1) N_RRE(0xB375, r1, 0x0)
497 #define N_LZXR(r1) N_RRE(0xB376, r1, 0x0)
498 #define N_STE(r1, d2, x2, b2) N_RX(0x70, r1, d2, x2, b2)
499 #define N_STD(r1, d2, x2, b2) N_RX(0x60, r1, d2, x2, b2)
500
501 /* chapter 19. Binary floating point instructions */
502
503 /* Alpha like instructions */
504
505 #define M_CALL(r2) N_BASR(R14, r2)
506
507 #define M_ILD(r, b, d) _IFNEG( \
508         d, \
509         N_LHI(r, d); N_L(r, 0, r, b), \
510         N_L(r, d, RN, b) \
511 )
512
513 #define M_ALD(r, b, d) M_ILD(r, b, d)
514
515 #define M_LDA(r, b, d) _IFNEG( \
516         d, \
517         N_LHI(r, d); N_LA(r, 0, r, b), \
518         N_LA(r, d, RN, b) \
519 )
520
521 #define M_FLD(r, b, d) _IFNEG(d, assert(0), N_LE(r, d, RN, b))
522 #define M_DLD(r, b, d) _IFNEG(d, assert(0), N_LD(r, d, RN, b))
523
524 #define M_LLD(r, b, d) _IFNEG( \
525         d, \
526         N_LHI(GET_LOW_REG(r), d); \
527                 N_L(GET_HIGH_REG(r), 0, GET_LOW_REG(r), b); \
528                 N_L(GET_LOW_REG(r), 4, GET_LOW_REG(r), b), \
529         N_L(GET_HIGH_REG(r), 0, RN, b); N_L(GET_LOW_REG(r), 4, RN, b) \
530 )
531
532 #define M_MOV(a, b) N_LR(a, b)
533 #define M_FMOV(a, b) N_LDR(a, b)
534 #define M_DST(r, b, d) _IFNEG(d, assert(0), N_STD(r, d, RN, b))
535 #define M_FST(r, b, d) _IFNEG(d, assert(0), N_STE(r, d, RN, b))
536 #define M_IST(r, b, d) _IFNEG( \
537         d, \
538         N_LHI(r, d); N_S(r, 0, r, b), \
539         N_S(r, d, RN, b) \
540 )
541 #define M_AST(r, b, d) M_IST(r, b, d)
542 #define M_LST(r, b, d) _IFNEG( \
543         d, \
544         N_LHI(GET_LOW_REG(r), d); \
545                 N_S(GET_HIGH_REG(r), 0, GET_LOW_REG(r), b); \
546                 N_S(GET_LOW_REG(r), 4, GET_LOW_REG(r), b), \
547         N_S(GET_HIGH_REG(r), 0, RN, b); N_S(GET_LOW_REG(r), 4, RN, b) \
548 )
549 #define M_TEST(r) N_LTR(r, r)
550 #define M_BEQ(off) N_BRC(DD_E, off)
551 #define M_BNE(off) N_BRC(DD_NE, off)
552 #define M_BLE(off) N_BRC(DD_LE, off)
553 #define M_BGT(off) N_BRC(DD_H, off)
554 #define M_BLT(off) N_BRC(DD_L, off)
555
556 #define M_CMP(r1, r2) N_CR(r1, r2)
557 #define M_CLR(r) N_LHI(r, 0)
558 #define M_AADD_IMM(val, reg) N_LA(reg, val, RN, reg)
559 #define M_IADD_IMM(val, reg) N_AHI(reg, val)
560 #define M_ASUB_IMM(val, reg) N_AHI(reg, -(val))
561 #define M_RET N_BCR(DD_ANY, R14)
562
563 /* M_INTMOVE:
564     generates an integer-move from register a to b.
565     if a and b are the same int-register, no code will be generated.
566 */ 
567
568 #define M_INTMOVE(reg,dreg) \
569     do { \
570         if ((reg) != (dreg)) { \
571             M_MOV(reg, dreg); \
572         } \
573     } while (0)
574
575 #define M_LNGMOVE(a, b) \
576     do { \
577         if (GET_HIGH_REG(a) == GET_LOW_REG(b)) { \
578             assert((GET_LOW_REG(a) != GET_HIGH_REG(b))); \
579             M_INTMOVE(GET_HIGH_REG(a), GET_HIGH_REG(b)); \
580             M_INTMOVE(GET_LOW_REG(a), GET_LOW_REG(b)); \
581         } else { \
582             M_INTMOVE(GET_LOW_REG(a), GET_LOW_REG(b)); \
583             M_INTMOVE(GET_HIGH_REG(a), GET_HIGH_REG(b)); \
584         } \
585     } while (0)
586
587 /* M_FLTMOVE:
588     generates a floating-point-move from register a to b.
589     if a and b are the same float-register, no code will be generated
590 */ 
591
592 #define M_FLTMOVE(reg,dreg) \
593     do { \
594         if ((reg) != (dreg)) { \
595             M_FMOV(reg, dreg); \
596         } \
597     } while (0)
598
599
600
601 /* ----------------------------------------------- */
602
603 #define _DEPR(x) \
604         do { \
605                 fprintf(stdout, \
606                         "Using old x86_64 instruction %s at %s (%s:%d), fix this.\n", \
607                         #x, __FUNCTION__, __FILE__, __LINE__); \
608         } while (0)
609
610 #define M_MOV_IMM(a,b) _DEPR( M_MOV_IMM(a,b) )
611
612 #define M_IMOV(a,b) _DEPR( M_IMOV(a,b) )
613 #define M_IMOV_IMM(a,b) _DEPR( M_IMOV_IMM(a,b) )
614
615
616 #define M_ILD32(a,b,disp) _DEPR( M_ILD32(a,b,disp) )
617 #define M_LLD32(a,b,disp) _DEPR( M_LLD32(a,b,disp) )
618
619
620 #define M_IST_IMM(a,b,disp) _DEPR( M_IST_IMM(a,b,disp) )
621 #define M_LST_IMM32(a,b,disp) _DEPR( M_LST_IMM32(a,b,disp) )
622
623 #define M_IST32(a,b,disp) _DEPR( M_IST32(a,b,disp) )
624 #define M_LST32(a,b,disp) _DEPR( M_LST32(a,b,disp) )
625
626 #define M_IST32_IMM(a,b,disp) _DEPR( M_IST32_IMM(a,b,disp) )
627 #define M_LST32_IMM32(a,b,disp) _DEPR( M_LST32_IMM32(a,b,disp) )
628
629 #define M_IADD(a,b) _DEPR( M_IADD(a,b) )
630 #define M_ISUB(a,b) _DEPR( M_ISUB(a,b) )
631 #define M_IMUL(a,b) _DEPR( M_IMUL(a,b) )
632
633 #define M_ISUB_IMM(a,b) _DEPR( M_ISUB_IMM(a,b) )
634 #define M_IMUL_IMM(a,b,c) _DEPR( M_IMUL_IMM(a,b,c) )
635
636 #define M_LADD(a,b) _DEPR( M_LADD(a,b) )
637 #define M_LSUB(a,b) _DEPR( M_LSUB(a,b) )
638 #define M_LMUL(a,b) _DEPR( M_LMUL(a,b) )
639
640 #define M_LADD_IMM(a,b) _DEPR( M_LADD_IMM(a,b) )
641 #define M_LSUB_IMM(a,b) _DEPR( M_LSUB_IMM(a,b) )
642 #define M_LMUL_IMM(a,b,c) _DEPR( M_LMUL_IMM(a,b,c) )
643
644 #define M_IINC(a) _DEPR( M_IINC(a) )
645 #define M_IDEC(a) _DEPR( M_IDEC(a) )
646
647 #define M_ALD32(a,b,disp) _DEPR( M_ALD32(a,b,disp) )
648
649 #define M_AST_IMM32(a,b,c) _DEPR( M_AST_IMM32(a,b,c) )
650
651 #define M_AADD(a,b) _DEPR( M_AADD(a,b) )
652
653 #define M_LADD_IMM32(a,b) _DEPR( M_LADD_IMM32(a,b) )
654 #define M_AADD_IMM32(a,b) _DEPR( M_AADD_IMM32(a,b) )
655 #define M_LSUB_IMM32(a,b) _DEPR( M_LSUB_IMM32(a,b) )
656
657 #define M_ILEA(a,b,c) _DEPR( M_ILEA(a,b,c) )
658 #define M_LLEA(a,b,c) _DEPR( M_LLEA(a,b,c) )
659 #define M_ALEA(a,b,c) _DEPR( M_ALEA(a,b,c) )
660
661 #define M_INEG(a) _DEPR( M_INEG(a) )
662 #define M_LNEG(a) _DEPR( M_LNEG(a) )
663
664 #define M_IAND(a,b) _DEPR( M_IAND(a,b) )
665 #define M_IOR(a,b) _DEPR( M_IOR(a,b) )
666 #define M_IXOR(a,b) _DEPR( M_IXOR(a,b) )
667
668 #define M_IAND_IMM(a,b) _DEPR( M_IAND_IMM(a,b) )
669 #define M_IOR_IMM(a,b) _DEPR( M_IOR_IMM(a,b) )
670 #define M_IXOR_IMM(a,b) _DEPR( M_IXOR_IMM(a,b) )
671
672 #define M_LAND(a,b) _DEPR( M_LAND(a,b) )
673 #define M_LOR(a,b) _DEPR( M_LOR(a,b) )
674 #define M_LXOR(a,b) _DEPR( M_LXOR(a,b) )
675
676 #define M_LAND_IMM(a,b) _DEPR( M_LAND_IMM(a,b) )
677 #define M_LOR_IMM(a,b) _DEPR( M_LOR_IMM(a,b) )
678 #define M_LXOR_IMM(a,b) _DEPR( M_LXOR_IMM(a,b) )
679
680 #define M_SSEXT(a,b) _DEPR( M_SSEXT(a,b) )
681 #define M_ISEXT(a,b) _DEPR( M_ISEXT(a,b) )
682
683 #define M_CZEXT(a,b) _DEPR( M_CZEXT(a,b) )
684
685 #define M_ISLL_IMM(a,b) _DEPR( M_ISLL_IMM(a,b) )
686 #define M_ISRA_IMM(a,b) _DEPR( M_ISRA_IMM(a,b) )
687 #define M_ISRL_IMM(a,b) _DEPR( M_ISRL_IMM(a,b) )
688
689 #define M_LSLL_IMM(a,b) _DEPR( M_LSLL_IMM(a,b) )
690 #define M_LSRA_IMM(a,b) _DEPR( M_LSRA_IMM(a,b) )
691 #define M_LSRL_IMM(a,b) _DEPR( M_LSRL_IMM(a,b) )
692
693 #define M_LCMP(a,b) _DEPR( M_LCMP(a,b) )
694 #define M_LCMP_IMM(a,b) _DEPR( M_LCMP_IMM(a,b) )
695 #define M_LCMP_IMM_MEMBASE(a,b,c) _DEPR( M_LCMP_IMM_MEMBASE(a,b,c) )
696 #define M_LCMP_MEMBASE(a,b,c) _DEPR( M_LCMP_MEMBASE(a,b,c) )
697
698 #define M_ICMP(a,b) _DEPR( M_ICMP(a,b) )
699 #define M_ICMP_IMM(a,b) _DEPR( M_ICMP_IMM(a,b) )
700 #define M_ICMP_IMM_MEMBASE(a,b,c) _DEPR( M_ICMP_IMM_MEMBASE(a,b,c) )
701 #define M_ICMP_MEMBASE(a,b,c) _DEPR( M_ICMP_MEMBASE(a,b,c) )
702
703 #define M_BGE(disp) _DEPR( M_BGE(disp) )
704 #define M_BAE(disp) _DEPR( M_BAE(disp) )
705 #define M_BA(disp) _DEPR( M_BA(disp) )
706
707 #define M_CMOVEQ(a,b) _DEPR( M_CMOVEQ(a,b) )
708 #define M_CMOVNE(a,b) _DEPR( M_CMOVNE(a,b) )
709 #define M_CMOVLT(a,b) _DEPR( M_CMOVLT(a,b) )
710 #define M_CMOVLE(a,b) _DEPR( M_CMOVLE(a,b) )
711 #define M_CMOVGE(a,b) _DEPR( M_CMOVGE(a,b) )
712 #define M_CMOVGT(a,b) _DEPR( M_CMOVGT(a,b) )
713
714 #define M_CMOVEQ_MEMBASE(a,b,c) _DEPR( M_CMOVEQ_MEMBASE(a,b,c) )
715 #define M_CMOVNE_MEMBASE(a,b,c) _DEPR( M_CMOVNE_MEMBASE(a,b,c) )
716 #define M_CMOVLT_MEMBASE(a,b,c) _DEPR( M_CMOVLT_MEMBASE(a,b,c) )
717 #define M_CMOVLE_MEMBASE(a,b,c) _DEPR( M_CMOVLE_MEMBASE(a,b,c) )
718 #define M_CMOVGE_MEMBASE(a,b,c) _DEPR( M_CMOVGE_MEMBASE(a,b,c) )
719 #define M_CMOVGT_MEMBASE(a,b,c) _DEPR( M_CMOVGT_MEMBASE(a,b,c) )
720
721 #define M_CMOVB(a,b) _DEPR( M_CMOVB(a,b) )
722 #define M_CMOVA(a,b) _DEPR( M_CMOVA(a,b) )
723 #define M_CMOVP(a,b) _DEPR( M_CMOVP(a,b) )
724
725 #define M_PUSH(a) _DEPR( M_PUSH(a) )
726 #define M_PUSH_IMM(a) _DEPR( M_PUSH_IMM(a) )
727 #define M_POP(a) _DEPR( M_POP(a) )
728
729 #define M_JMP(a) _DEPR( M_JMP(a) )
730 #define M_JMP_IMM(a) _DEPR( M_JMP_IMM(a) )
731 #define M_CALL_IMM(a) _DEPR( M_CALL_IMM(a) )
732
733 #define M_NOP _DEPR( M_NOP )
734
735
736
737
738 #define M_FLD32(a,b,disp) _DEPR( M_FLD32(a,b,disp) )
739 #define M_DLD32(a,b,disp) _DEPR( M_DLD32(a,b,disp) )
740
741
742 #define M_FST32(a,b,disp) _DEPR( M_FST32(a,b,disp) )
743 #define M_DST32(a,b,disp) _DEPR( M_DST32(a,b,disp) )
744
745 #define M_FADD(a,b) _DEPR( M_FADD(a,b) )
746 #define M_DADD(a,b) _DEPR( M_DADD(a,b) )
747 #define M_FSUB(a,b) _DEPR( M_FSUB(a,b) )
748 #define M_DSUB(a,b) _DEPR( M_DSUB(a,b) )
749 #define M_FMUL(a,b) _DEPR( M_FMUL(a,b) )
750 #define M_DMUL(a,b) _DEPR( M_DMUL(a,b) )
751 #define M_FDIV(a,b) _DEPR( M_FDIV(a,b) )
752 #define M_DDIV(a,b) _DEPR( M_DDIV(a,b) )
753
754 #define M_CVTIF(a,b) _DEPR( M_CVTIF(a,b) )
755 #define M_CVTID(a,b) _DEPR( M_CVTID(a,b) )
756 #define M_CVTLF(a,b) _DEPR( M_CVTLF(a,b) )
757 #define M_CVTLD(a,b) _DEPR( M_CVTLD(a,b) )
758 #define M_CVTFI(a,b) _DEPR( M_CVTFI(a,b) )
759 #define M_CVTDI(a,b) _DEPR( M_CVTDI(a,b) )
760 #define M_CVTFL(a,b) _DEPR( M_CVTFL(a,b) )
761 #define M_CVTDL(a,b) _DEPR( M_CVTDL(a,b) )
762
763 #define M_CVTFD(a,b) _DEPR( M_CVTFD(a,b) )
764 #define M_CVTDF(a,b) _DEPR( M_CVTDF(a,b) )
765
766
767 /* system instructions ********************************************************/
768
769 #define M_RDTSC _DEPR( M_RDTSC )
770
771 #define M_IINC_MEMBASE(a,b) _DEPR( M_IINC_MEMBASE(a,b) )
772
773 #define M_IADD_MEMBASE(a,b,c) _DEPR( M_IADD_MEMBASE(a,b,c) )
774 #define M_IADC_MEMBASE(a,b,c) _DEPR( M_IADC_MEMBASE(a,b,c) )
775 #define M_ISUB_MEMBASE(a,b,c) _DEPR( M_ISUB_MEMBASE(a,b,c) )
776 #define M_ISBB_MEMBASE(a,b,c) _DEPR( M_ISBB_MEMBASE(a,b,c) )
777
778 #define PROFILE_CYCLE_START _DEPR( PROFILE_CYCLE_START )
779 #define __PROFILE_CYCLE_START _DEPR( __PROFILE_CYCLE_START )
780
781 #define PROFILE_CYCLE_STOP _DEPR( PROFILE_CYCLE_STOP )
782 #define __PROFILE_CYCLE_STOP _DEPR( __PROFILE_CYCLE_STOP )
783
784
785 /* function gen_resolvebranch **************************************************
786
787     backpatches a branch instruction
788
789     parameters: ip ... pointer to instruction after branch (void*)
790                 so ... offset of instruction after branch  (s8)
791                 to ... offset of branch target             (s8)
792
793 *******************************************************************************/
794
795 #define gen_resolvebranch(ip,so,to) \
796     *((s4*) ((ip) - 4)) = (s4) ((to) - (so));
797
798 #endif /* _CODEGEN_H */
799
800
801 /*
802  * These are local overrides for various environment variables in Emacs.
803  * Please do not remove this and leave it at the end of the file, where
804  * Emacs will automagically detect them.
805  * ---------------------------------------------------------------------
806  * Local variables:
807  * mode: c
808  * indent-tabs-mode: t
809  * c-basic-offset: 4
810  * tab-width: 4
811  * End:
812  */