* M_FLD, M_DLD: Bugfix, we can't use `a' as temp register since it's a
[cacao.git] / src / vm / jit / alpha / codegen.h
1 /* vm/jit/alpha/codegen.h - code generation macros and definitions for Alpha
2
3    Copyright (C) 1996-2005 R. Grafl, A. Krall, C. Kruegel, C. Oates,
4    R. Obermaisser, M. Platter, M. Probst, S. Ring, E. Steiner,
5    C. Thalinger, D. Thuernbeck, P. Tomsich, C. Ullrich, J. Wenninger,
6    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., 59 Temple Place - Suite 330, Boston, MA
23    02111-1307, USA.
24
25    Contact: cacao@complang.tuwien.ac.at
26
27    Authors: Andreas Krall
28             Reinhard Grafl
29
30    Changes: Christian Thalinger
31
32    $Id: codegen.h 3120 2005-07-27 22:20:13Z twisti $
33
34 */
35
36
37 #ifndef _CODEGEN_H
38 #define _CODEGEN_H
39
40 #include "config.h"
41
42 #include <ucontext.h>
43
44
45 /* additional functions and macros to generate code ***************************/
46
47 #ifdef STATISTICS
48 #define COUNT_SPILLS count_spills++
49 #else
50 #define COUNT_SPILLS
51 #endif
52
53
54 /* gen_nullptr_check(objreg) */
55
56 #define gen_nullptr_check(objreg) \
57     if (checknull) { \
58         M_BEQZ((objreg), 0); \
59         codegen_addxnullrefs(cd, mcodeptr); \
60     }
61
62 #define gen_bound_check \
63     if (checkbounds) { \
64         M_ILD(REG_ITMP3, s1, OFFSET(java_arrayheader, size));\
65         M_CMPULT(s2, REG_ITMP3, REG_ITMP3);\
66         M_BEQZ(REG_ITMP3, 0);\
67         codegen_addxboundrefs(cd, mcodeptr, s2); \
68     }
69
70
71 /* MCODECHECK(icnt) */
72
73 #define MCODECHECK(icnt) \
74         if ((mcodeptr + (icnt)) > cd->mcodeend) \
75         mcodeptr = codegen_increase(cd, (u1 *) mcodeptr)
76
77
78 #define ALIGNCODENOP \
79     if ((s4) ((ptrint) mcodeptr & 7)) { \
80         M_NOP; \
81     }
82
83
84 /* M_INTMOVE:
85      generates an integer-move from register a to b.
86      if a and b are the same int-register, no code will be generated.
87 */ 
88
89 #define M_INTMOVE(a,b) if (a != b) { M_MOV(a, b); }
90
91
92 /* M_FLTMOVE:
93     generates a floating-point-move from register a to b.
94     if a and b are the same float-register, no code will be generated
95 */ 
96
97 #define M_FLTMOVE(a,b) if (a != b) { M_FMOV(a, b); }
98
99
100 /* var_to_reg_xxx **************************************************************
101
102    This function generates code to fetch data from a pseudo-register
103    into a real register. If the pseudo-register has actually been
104    assigned to a real register, no code will be emitted, since
105    following operations can use this register directly.
106     
107    v: pseudoregister to be fetched from
108    tempregnum: temporary register to be used if v is actually spilled to ram
109
110    return: the register number, where the operand can be found after 
111            fetching (this wil be either tempregnum or the register
112            number allready given to v)
113
114 *******************************************************************************/
115
116 #define var_to_reg_int(regnr,v,tempnr) \
117     do { \
118         if ((v)->flags & INMEMORY) { \
119             COUNT_SPILLS; \
120             M_LLD(tempnr, REG_SP, (v)->regoff * 8); \
121             regnr = tempnr; \
122         } else { \
123             regnr = (v)->regoff; \
124         } \
125     } while (0)
126
127
128 #define var_to_reg_flt(regnr,v,tempnr) \
129     do { \
130         if ((v)->flags & INMEMORY) { \
131             COUNT_SPILLS; \
132             M_DLD(tempnr, REG_SP, (v)->regoff * 8); \
133             regnr = tempnr; \
134         } else { \
135             regnr = (v)->regoff; \
136         } \
137     } while (0)
138
139
140 /* store_reg_to_var_xxx ********************************************************
141
142    This function generates the code to store the result of an
143    operation back into a spilled pseudo-variable. If the
144    pseudo-variable has not been spilled in the first place, this
145    function will generate nothing.
146     
147    v ............ Pseudovariable
148    tempregnum ... Number of the temporary registers as returned by
149                   reg_of_var.
150
151 *******************************************************************************/
152
153 #define store_reg_to_var_int(sptr, tempregnum) \
154     do { \
155         if ((sptr)->flags & INMEMORY) { \
156             COUNT_SPILLS; \
157             M_LST(tempregnum, REG_SP, (sptr)->regoff * 8); \
158         } \
159     } while (0)
160
161 #define store_reg_to_var_flt(sptr, tempregnum) \
162     do { \
163         if ((sptr)->flags & INMEMORY) { \
164             COUNT_SPILLS; \
165             M_DST(tempregnum, REG_SP, (sptr)->regoff * 8); \
166         } \
167     } while (0)
168
169
170 #define M_COPY(from,to) \
171         d = reg_of_var(rd, to, REG_IFTMP); \
172         if ((from->regoff != to->regoff) || \
173             ((from->flags ^ to->flags) & INMEMORY)) { \
174                 if (IS_FLT_DBL_TYPE(from->type)) { \
175                         var_to_reg_flt(s1, from, d); \
176                         M_FLTMOVE(s1,d); \
177                         store_reg_to_var_flt(to, d); \
178                 } else { \
179                         var_to_reg_int(s1, from, d); \
180                         M_INTMOVE(s1,d); \
181                         store_reg_to_var_int(to, d); \
182                 } \
183         }
184
185 #define ICONST(r,c) \
186     if ((c) >= -32768 && (c) <= 32767) { \
187         M_LDA_INTERN((r), REG_ZERO, c); \
188     } else { \
189         disp = dseg_adds4(cd, (c)); \
190         M_ILD((r), REG_PV, disp); \
191     }
192
193 #define LCONST(r,c) \
194     if ((c) >= -32768 && (c) <= 32767) { \
195         M_LDA_INTERN((r), REG_ZERO, (c)); \
196     } else { \
197         disp = dseg_adds8(cd, (c)); \
198         M_LLD((r), REG_PV, disp); \
199     }
200
201
202 /* macros to create code ******************************************************/
203
204 #define REG   0
205 #define CONST 1
206
207 /* 3-address-operations: M_OP3
208       op ..... opcode
209       fu ..... function-number
210       a  ..... register number source 1
211       b  ..... register number or constant integer source 2
212       c  ..... register number destination
213       const .. switch to use b as constant integer 
214                  (REG means: use b as register number)
215                  (CONST means: use b as constant 8-bit-integer)
216 */      
217
218 #define M_OP3(op,fu,a,b,c,const) \
219         *(mcodeptr++) = ((((s4) (op)) << 26) | ((a) << 21) | ((b) << (16 - 3 * (const))) | ((const) << 12) | ((fu) << 5) | ((c)))
220
221
222 /* 3-address-floating-point-operation: M_FOP3 
223      op .... opcode
224      fu .... function-number
225      a,b ... source floating-point registers
226      c ..... destination register
227 */ 
228
229 #define M_FOP3(op,fu,a,b,c) \
230         *(mcodeptr++) = ((((s4) (op)) << 26) | ((a) << 21) | ((b) << 16) | ((fu) << 5) | (c))
231
232
233 /* branch instructions: M_BRA 
234       op ..... opcode
235       a ...... register to be tested
236       disp ... relative address to be jumped to (divided by 4)
237 */
238
239 #define M_BRA(op,a,disp) \
240         *(mcodeptr++) = ((((s4) (op)) << 26) | ((a) << 21) | ((disp) & 0x1fffff))
241
242
243 /* memory operations: M_MEM
244       op ..... opcode
245       a ...... source/target register for memory access
246       b ...... base register
247       disp ... displacement (16 bit signed) to be added to b
248 */ 
249
250 #define M_MEM(op,a,b,disp) \
251         *(mcodeptr++) = ((((s4) (op)) << 26) | ((a) << 21) | ((b) << 16) | ((disp) & 0xffff))
252
253
254 /* macros for all used commands (see an Alpha-manual for description) *********/
255
256 #define M_LDA_INTERN(a,b,disp)  M_MEM(0x08,a,b,disp)            /* low const  */
257
258 #define M_LDA(a,b,disp) \
259     do { \
260         s4 lo = (short) (disp); \
261         s4 hi = (short) (((disp) - lo) >> 16); \
262         if (hi == 0) { \
263             M_LDA_INTERN(a,b,lo); \
264         } else { \
265             M_LDAH(a,b,hi); \
266             M_LDA_INTERN(a,a,lo); \
267         } \
268     } while (0)
269
270 #define M_LDAH(a,b,disp)        M_MEM (0x09,a,b,disp)           /* high const */
271
272 #define M_BLDU(a,b,disp)        M_MEM (0x0a,a,b,disp)           /*  8 load    */
273 #define M_SLDU(a,b,disp)        M_MEM (0x0c,a,b,disp)           /* 16 load    */
274
275 #define M_ILD_INTERN(a,b,disp)  M_MEM(0x28,a,b,disp)            /* 32 load    */
276 #define M_LLD_INTERN(a,b,disp)  M_MEM(0x29,a,b,disp)            /* 64 load    */
277
278 #define M_ILD(a,b,disp) \
279     do { \
280         s4 lo = (short) (disp); \
281         s4 hi = (short) (((disp) - lo) >> 16); \
282         if (hi == 0) { \
283             M_ILD_INTERN(a,b,lo); \
284         } else { \
285             M_LDAH(a,b,hi); \
286             M_ILD_INTERN(a,a,lo); \
287         } \
288     } while (0)
289
290 #define M_LLD(a,b,disp) \
291     do { \
292         s4 lo = (short) (disp); \
293         s4 hi = (short) (((disp) - lo) >> 16); \
294         if (hi == 0) { \
295             M_LLD_INTERN(a,b,lo); \
296         } else { \
297             M_LDAH(a,b,hi); \
298             M_LLD_INTERN(a,a,lo); \
299         } \
300     } while (0)
301
302 #define M_ALD(a,b,disp)         M_LLD(a,b,disp)                 /* addr load  */
303
304 #define M_BST(a,b,disp)         M_MEM(0x0e,a,b,disp)            /*  8 store   */
305 #define M_SST(a,b,disp)         M_MEM(0x0d,a,b,disp)            /* 16 store   */
306
307 #define M_IST_INTERN(a,b,disp)  M_MEM(0x2c,a,b,disp)            /* 32 store   */
308 #define M_LST_INTERN(a,b,disp)  M_MEM(0x2d,a,b,disp)            /* 64 store   */
309
310 /* Stores with displacement overflow should only happen with PUTFIELD or on   */
311 /* the stack. The PUTFIELD instruction does not use REG_ITMP3 and a           */
312 /* reg_of_var call should not use REG_ITMP3!!!                                */
313
314 #define M_IST(a,b,disp) \
315     do { \
316         s4 lo = (short) (disp); \
317         s4 hi = (short) (((disp) - lo) >> 16); \
318         if (hi == 0) { \
319             M_IST_INTERN(a,b,lo); \
320         } else { \
321             M_LDAH(REG_ITMP3,b,hi); \
322             M_IST_INTERN(a,REG_ITMP3,lo); \
323         } \
324     } while (0)
325
326 #define M_LST(a,b,disp) \
327     do { \
328         s4 lo = (short) (disp); \
329         s4 hi = (short) (((disp) - lo) >> 16); \
330         if (hi == 0) { \
331             M_LST_INTERN(a,b,lo); \
332         } else { \
333             M_LDAH(REG_ITMP3,b,hi); \
334             M_LST_INTERN(a,REG_ITMP3,lo); \
335         } \
336     } while (0)
337
338 #define M_AST(a,b,disp)         M_LST(a,b,disp)                 /* addr store */
339
340 #define M_BSEXT(b,c)            M_OP3 (0x1c,0x0,REG_ZERO,b,c,0) /*  8 signext */
341 #define M_SSEXT(b,c)            M_OP3 (0x1c,0x1,REG_ZERO,b,c,0) /* 16 signext */
342
343 #define M_BR(disp)              M_BRA (0x30,REG_ZERO,disp)      /* branch     */
344 #define M_BSR(ra,disp)          M_BRA (0x34,ra,disp)            /* branch sbr */
345 #define M_BEQZ(a,disp)          M_BRA (0x39,a,disp)             /* br a == 0  */
346 #define M_BLTZ(a,disp)          M_BRA (0x3a,a,disp)             /* br a <  0  */
347 #define M_BLEZ(a,disp)          M_BRA (0x3b,a,disp)             /* br a <= 0  */
348 #define M_BNEZ(a,disp)          M_BRA (0x3d,a,disp)             /* br a != 0  */
349 #define M_BGEZ(a,disp)          M_BRA (0x3e,a,disp)             /* br a >= 0  */
350 #define M_BGTZ(a,disp)          M_BRA (0x3f,a,disp)             /* br a >  0  */
351
352 #define M_JMP(a,b)              M_MEM (0x1a,a,b,0x0000)         /* jump       */
353 #define M_JSR(a,b)              M_MEM (0x1a,a,b,0x4000)         /* call sbr   */
354 #define M_RET(a,b)              M_MEM (0x1a,a,b,0x8000)         /* return     */
355
356 #define M_IADD(a,b,c)           M_OP3 (0x10,0x0,  a,b,c,0)      /* 32 add     */
357 #define M_LADD(a,b,c)           M_OP3 (0x10,0x20, a,b,c,0)      /* 64 add     */
358 #define M_ISUB(a,b,c)           M_OP3 (0x10,0x09, a,b,c,0)      /* 32 sub     */
359 #define M_LSUB(a,b,c)           M_OP3 (0x10,0x29, a,b,c,0)      /* 64 sub     */
360 #define M_IMUL(a,b,c)           M_OP3 (0x13,0x00, a,b,c,0)      /* 32 mul     */
361 #define M_LMUL(a,b,c)           M_OP3 (0x13,0x20, a,b,c,0)      /* 64 mul     */
362
363 #define M_IADD_IMM(a,b,c)       M_OP3 (0x10,0x0,  a,b,c,1)      /* 32 add     */
364 #define M_LADD_IMM(a,b,c)       M_OP3 (0x10,0x20, a,b,c,1)      /* 64 add     */
365 #define M_ISUB_IMM(a,b,c)       M_OP3 (0x10,0x09, a,b,c,1)      /* 32 sub     */
366 #define M_LSUB_IMM(a,b,c)       M_OP3 (0x10,0x29, a,b,c,1)      /* 64 sub     */
367 #define M_IMUL_IMM(a,b,c)       M_OP3 (0x13,0x00, a,b,c,1)      /* 32 mul     */
368 #define M_LMUL_IMM(a,b,c)       M_OP3 (0x13,0x20, a,b,c,1)      /* 64 mul     */
369
370 #define M_AADD_IMM(a,b,c)       M_LADD_IMM(a,b,c)
371
372 #define M_CMPEQ(a,b,c)          M_OP3 (0x10,0x2d, a,b,c,0)      /* c = a == b */
373 #define M_CMPLT(a,b,c)          M_OP3 (0x10,0x4d, a,b,c,0)      /* c = a <  b */
374 #define M_CMPLE(a,b,c)          M_OP3 (0x10,0x6d, a,b,c,0)      /* c = a <= b */
375
376 #define M_CMPULE(a,b,c)         M_OP3 (0x10,0x3d, a,b,c,0)      /* c = a <= b */
377 #define M_CMPULT(a,b,c)         M_OP3 (0x10,0x1d, a,b,c,0)      /* c = a <= b */
378
379 #define M_CMPEQ_IMM(a,b,c)      M_OP3 (0x10,0x2d, a,b,c,1)      /* c = a == b */
380 #define M_CMPLT_IMM(a,b,c)      M_OP3 (0x10,0x4d, a,b,c,1)      /* c = a <  b */
381 #define M_CMPLE_IMM(a,b,c)      M_OP3 (0x10,0x6d, a,b,c,1)      /* c = a <= b */
382
383 #define M_CMPULE_IMM(a,b,c)     M_OP3 (0x10,0x3d, a,b,c,1)      /* c = a <= b */
384 #define M_CMPULT_IMM(a,b,c)     M_OP3 (0x10,0x1d, a,b,c,1)      /* c = a <= b */
385
386 #define M_AND(a,b,c)            M_OP3 (0x11,0x00, a,b,c,0)      /* c = a &  b */
387 #define M_OR( a,b,c)            M_OP3 (0x11,0x20, a,b,c,0)      /* c = a |  b */
388 #define M_XOR(a,b,c)            M_OP3 (0x11,0x40, a,b,c,0)      /* c = a ^  b */
389
390 #define M_AND_IMM(a,b,c)        M_OP3 (0x11,0x00, a,b,c,1)      /* c = a &  b */
391 #define M_OR_IMM( a,b,c)        M_OP3 (0x11,0x20, a,b,c,1)      /* c = a |  b */
392 #define M_XOR_IMM(a,b,c)        M_OP3 (0x11,0x40, a,b,c,1)      /* c = a ^  b */
393
394 #define M_MOV(a,c)              M_OR (a,a,c)                    /* c = a      */
395 #define M_CLR(c)                M_OR (31,31,c)                  /* c = 0      */
396 #define M_NOP                   M_OR (31,31,31)                 /* ;          */
397
398 #define M_SLL(a,b,c)            M_OP3 (0x12,0x39, a,b,c,0)      /* c = a << b */
399 #define M_SRA(a,b,c)            M_OP3 (0x12,0x3c, a,b,c,0)      /* c = a >> b */
400 #define M_SRL(a,b,c)            M_OP3 (0x12,0x34, a,b,c,0)      /* c = a >>>b */
401
402 #define M_SLL_IMM(a,b,c)        M_OP3 (0x12,0x39, a,b,c,1)      /* c = a << b */
403 #define M_SRA_IMM(a,b,c)        M_OP3 (0x12,0x3c, a,b,c,1)      /* c = a >> b */
404 #define M_SRL_IMM(a,b,c)        M_OP3 (0x12,0x34, a,b,c,1)      /* c = a >>>b */
405
406 #define M_FLD_INTERN(a,b,disp)  M_MEM(0x22,a,b,disp)            /* load flt   */
407 #define M_DLD_INTERN(a,b,disp)  M_MEM(0x23,a,b,disp)            /* load dbl   */
408
409 #define M_FLD(a,b,disp) \
410     do { \
411         s4 lo = (short) (disp); \
412         s4 hi = (short) (((disp) - lo) >> 16); \
413         if (hi == 0) { \
414             M_FLD_INTERN(a,b,lo); \
415         } else { \
416             M_LDAH(REG_ITMP3,b,hi); \
417             M_FLD_INTERN(a,REG_ITMP3,lo); \
418         } \
419     } while (0)
420
421 #define M_DLD(a,b,disp) \
422     do { \
423         s4 lo = (short) (disp); \
424         s4 hi = (short) (((disp) - lo) >> 16); \
425         if (hi == 0) { \
426             M_DLD_INTERN(a,b,lo); \
427         } else { \
428             M_LDAH(REG_ITMP3,b,hi); \
429             M_DLD_INTERN(a,REG_ITMP3,lo); \
430         } \
431     } while (0)
432
433 #define M_FST_INTERN(a,b,disp)  M_MEM(0x26,a,b,disp)            /* store flt  */
434 #define M_DST_INTERN(a,b,disp)  M_MEM(0x27,a,b,disp)            /* store dbl  */
435
436 /* Stores with displacement overflow should only happen with PUTFIELD or on   */
437 /* the stack. The PUTFIELD instruction does not use REG_ITMP3 and a           */
438 /* reg_of_var call should not use REG_ITMP3!!!                                */
439
440 #define M_FST(a,b,disp) \
441     do { \
442         s4 lo = (short) (disp); \
443         s4 hi = (short) (((disp) - lo) >> 16); \
444         if (hi == 0) { \
445             M_FST_INTERN(a,b,lo); \
446         } else { \
447             M_LDAH(REG_ITMP3,b,hi); \
448             M_FST_INTERN(a,REG_ITMP3,lo); \
449         } \
450     } while (0)
451
452 #define M_DST(a,b,disp) \
453     do { \
454         s4 lo = (short) (disp); \
455         s4 hi = (short) (((disp) - lo) >> 16); \
456         if (hi == 0) { \
457             M_DST_INTERN(a,b,lo); \
458         } else { \
459             M_LDAH(REG_ITMP3,b,hi); \
460             M_DST_INTERN(a,REG_ITMP3,lo); \
461         } \
462     } while (0)
463
464
465 #define M_FADD(a,b,c)           M_FOP3 (0x16, 0x080, a,b,c)     /* flt add    */
466 #define M_DADD(a,b,c)           M_FOP3 (0x16, 0x0a0, a,b,c)     /* dbl add    */
467 #define M_FSUB(a,b,c)           M_FOP3 (0x16, 0x081, a,b,c)     /* flt sub    */
468 #define M_DSUB(a,b,c)           M_FOP3 (0x16, 0x0a1, a,b,c)     /* dbl sub    */
469 #define M_FMUL(a,b,c)           M_FOP3 (0x16, 0x082, a,b,c)     /* flt mul    */
470 #define M_DMUL(a,b,c)           M_FOP3 (0x16, 0x0a2, a,b,c)     /* dbl mul    */
471 #define M_FDIV(a,b,c)           M_FOP3 (0x16, 0x083, a,b,c)     /* flt div    */
472 #define M_DDIV(a,b,c)           M_FOP3 (0x16, 0x0a3, a,b,c)     /* dbl div    */
473
474 #define M_FADDS(a,b,c)          M_FOP3 (0x16, 0x580, a,b,c)     /* flt add    */
475 #define M_DADDS(a,b,c)          M_FOP3 (0x16, 0x5a0, a,b,c)     /* dbl add    */
476 #define M_FSUBS(a,b,c)          M_FOP3 (0x16, 0x581, a,b,c)     /* flt sub    */
477 #define M_DSUBS(a,b,c)          M_FOP3 (0x16, 0x5a1, a,b,c)     /* dbl sub    */
478 #define M_FMULS(a,b,c)          M_FOP3 (0x16, 0x582, a,b,c)     /* flt mul    */
479 #define M_DMULS(a,b,c)          M_FOP3 (0x16, 0x5a2, a,b,c)     /* dbl mul    */
480 #define M_FDIVS(a,b,c)          M_FOP3 (0x16, 0x583, a,b,c)     /* flt div    */
481 #define M_DDIVS(a,b,c)          M_FOP3 (0x16, 0x5a3, a,b,c)     /* dbl div    */
482
483 #define M_CVTDF(b,c)            M_FOP3 (0x16, 0x0ac, 31,b,c)    /* dbl2flt    */
484 #define M_CVTLF(b,c)            M_FOP3 (0x16, 0x0bc, 31,b,c)    /* long2flt   */
485 #define M_CVTLD(b,c)            M_FOP3 (0x16, 0x0be, 31,b,c)    /* long2dbl   */
486 #define M_CVTDL(b,c)            M_FOP3 (0x16, 0x1af, 31,b,c)    /* dbl2long   */
487 #define M_CVTDL_C(b,c)          M_FOP3 (0x16, 0x12f, 31,b,c)    /* dbl2long   */
488 #define M_CVTLI(b,c)            M_FOP3 (0x17, 0x130, 31,b,c)    /* long2int   */
489
490 #define M_CVTDFS(b,c)           M_FOP3 (0x16, 0x5ac, 31,b,c)    /* dbl2flt    */
491 #define M_CVTFDS(b,c)           M_FOP3 (0x16, 0x6ac, 31,b,c)    /* flt2dbl    */
492 #define M_CVTDLS(b,c)           M_FOP3 (0x16, 0x5af, 31,b,c)    /* dbl2long   */
493 #define M_CVTDL_CS(b,c)         M_FOP3 (0x16, 0x52f, 31,b,c)    /* dbl2long   */
494 #define M_CVTLIS(b,c)           M_FOP3 (0x17, 0x530, 31,b,c)    /* long2int   */
495
496 #define M_FCMPEQ(a,b,c)         M_FOP3 (0x16, 0x0a5, a,b,c)     /* c = a==b   */
497 #define M_FCMPLT(a,b,c)         M_FOP3 (0x16, 0x0a6, a,b,c)     /* c = a<b    */
498
499 #define M_FCMPEQS(a,b,c)        M_FOP3 (0x16, 0x5a5, a,b,c)     /* c = a==b   */
500 #define M_FCMPLTS(a,b,c)        M_FOP3 (0x16, 0x5a6, a,b,c)     /* c = a<b    */
501
502 #define M_FMOV(fa,fb)           M_FOP3 (0x17, 0x020, fa,fa,fb)  /* b = a      */
503 #define M_FMOVN(fa,fb)          M_FOP3 (0x17, 0x021, fa,fa,fb)  /* b = -a     */
504
505 #define M_FNOP                  M_FMOV (31,31)
506
507 #define M_FBEQZ(fa,disp)        M_BRA (0x31,fa,disp)            /* br a == 0.0*/
508
509 /* macros for special commands (see an Alpha-manual for description) **********/ 
510
511 #define M_TRAPB                 M_MEM (0x18,0,0,0x0000)        /* trap barrier*/
512
513 #define M_S4ADDL(a,b,c)         M_OP3 (0x10,0x02, a,b,c,0)     /* c = a*4 + b */
514 #define M_S4ADDQ(a,b,c)         M_OP3 (0x10,0x22, a,b,c,0)     /* c = a*4 + b */
515 #define M_S4SUBL(a,b,c)         M_OP3 (0x10,0x0b, a,b,c,0)     /* c = a*4 - b */
516 #define M_S4SUBQ(a,b,c)         M_OP3 (0x10,0x2b, a,b,c,0)     /* c = a*4 - b */
517 #define M_S8ADDL(a,b,c)         M_OP3 (0x10,0x12, a,b,c,0)     /* c = a*8 + b */
518 #define M_S8ADDQ(a,b,c)         M_OP3 (0x10,0x32, a,b,c,0)     /* c = a*8 + b */
519 #define M_S8SUBL(a,b,c)         M_OP3 (0x10,0x1b, a,b,c,0)     /* c = a*8 - b */
520 #define M_S8SUBQ(a,b,c)         M_OP3 (0x10,0x3b, a,b,c,0)     /* c = a*8 - b */
521 #define M_SAADDQ(a,b,c)         M_S8ADDQ(a,b,c)                /* c = a*8 + b */
522
523 #define M_S4ADDL_IMM(a,b,c)     M_OP3 (0x10,0x02, a,b,c,1)     /* c = a*4 + b */
524 #define M_S4ADDQ_IMM(a,b,c)     M_OP3 (0x10,0x22, a,b,c,1)     /* c = a*4 + b */
525 #define M_S4SUBL_IMM(a,b,c)     M_OP3 (0x10,0x0b, a,b,c,1)     /* c = a*4 - b */
526 #define M_S4SUBQ_IMM(a,b,c)     M_OP3 (0x10,0x2b, a,b,c,1)     /* c = a*4 - b */
527 #define M_S8ADDL_IMM(a,b,c)     M_OP3 (0x10,0x12, a,b,c,1)     /* c = a*8 + b */
528 #define M_S8ADDQ_IMM(a,b,c)     M_OP3 (0x10,0x32, a,b,c,1)     /* c = a*8 + b */
529 #define M_S8SUBL_IMM(a,b,c)     M_OP3 (0x10,0x1b, a,b,c,1)     /* c = a*8 - b */
530 #define M_S8SUBQ_IMM(a,b,c)     M_OP3 (0x10,0x3b, a,b,c,1)     /* c = a*8 - b */
531
532 #define M_LLD_U(a,b,disp)       M_MEM (0x0b,a,b,disp)          /* unalign ld  */
533 #define M_LST_U(a,b,disp)       M_MEM (0x0f,a,b,disp)          /* unalign st  */
534
535 #define M_ZAP(a,b,c)            M_OP3 (0x12,0x30, a,b,c,0)
536 #define M_ZAPNOT(a,b,c)         M_OP3 (0x12,0x31, a,b,c,0)
537
538 #define M_ZAP_IMM(a,b,c)        M_OP3 (0x12,0x30, a,b,c,1)
539 #define M_ZAPNOT_IMM(a,b,c)     M_OP3 (0x12,0x31, a,b,c,1)
540
541 #define M_BZEXT(a,b)            M_ZAPNOT_IMM(a, 0x01, b)       /*  8 zeroext  */
542 #define M_CZEXT(a,b)            M_ZAPNOT_IMM(a, 0x03, b)       /* 16 zeroext  */
543 #define M_IZEXT(a,b)            M_ZAPNOT_IMM(a, 0x0f, b)       /* 32 zeroext  */
544
545 #define M_EXTBL(a,b,c)          M_OP3 (0x12,0x06, a,b,c,0)
546 #define M_EXTWL(a,b,c)          M_OP3 (0x12,0x16, a,b,c,0)
547 #define M_EXTLL(a,b,c)          M_OP3 (0x12,0x26, a,b,c,0)
548 #define M_EXTQL(a,b,c)          M_OP3 (0x12,0x36, a,b,c,0)
549 #define M_EXTWH(a,b,c)          M_OP3 (0x12,0x5a, a,b,c,0)
550 #define M_EXTLH(a,b,c)          M_OP3 (0x12,0x6a, a,b,c,0)
551 #define M_EXTQH(a,b,c)          M_OP3 (0x12,0x7a, a,b,c,0)
552 #define M_INSBL(a,b,c)          M_OP3 (0x12,0x0b, a,b,c,0)
553 #define M_INSWL(a,b,c)          M_OP3 (0x12,0x1b, a,b,c,0)
554 #define M_INSLL(a,b,c)          M_OP3 (0x12,0x2b, a,b,c,0)
555 #define M_INSQL(a,b,c)          M_OP3 (0x12,0x3b, a,b,c,0)
556 #define M_INSWH(a,b,c)          M_OP3 (0x12,0x57, a,b,c,0)
557 #define M_INSLH(a,b,c)          M_OP3 (0x12,0x67, a,b,c,0)
558 #define M_INSQH(a,b,c)          M_OP3 (0x12,0x77, a,b,c,0)
559 #define M_MSKBL(a,b,c)          M_OP3 (0x12,0x02, a,b,c,0)
560 #define M_MSKWL(a,b,c)          M_OP3 (0x12,0x12, a,b,c,0)
561 #define M_MSKLL(a,b,c)          M_OP3 (0x12,0x22, a,b,c,0)
562 #define M_MSKQL(a,b,c)          M_OP3 (0x12,0x32, a,b,c,0)
563 #define M_MSKWH(a,b,c)          M_OP3 (0x12,0x52, a,b,c,0)
564 #define M_MSKLH(a,b,c)          M_OP3 (0x12,0x62, a,b,c,0)
565 #define M_MSKQH(a,b,c)          M_OP3 (0x12,0x72, a,b,c,0)
566
567 #define M_EXTBL_IMM(a,b,c)      M_OP3 (0x12,0x06, a,b,c,1)
568 #define M_EXTWL_IMM(a,b,c)      M_OP3 (0x12,0x16, a,b,c,1)
569 #define M_EXTLL_IMM(a,b,c)      M_OP3 (0x12,0x26, a,b,c,1)
570 #define M_EXTQL_IMM(a,b,c)      M_OP3 (0x12,0x36, a,b,c,1)
571 #define M_EXTWH_IMM(a,b,c)      M_OP3 (0x12,0x5a, a,b,c,1)
572 #define M_EXTLH_IMM(a,b,c)      M_OP3 (0x12,0x6a, a,b,c,1)
573 #define M_EXTQH_IMM(a,b,c)      M_OP3 (0x12,0x7a, a,b,c,1)
574 #define M_INSBL_IMM(a,b,c)      M_OP3 (0x12,0x0b, a,b,c,1)
575 #define M_INSWL_IMM(a,b,c)      M_OP3 (0x12,0x1b, a,b,c,1)
576 #define M_INSLL_IMM(a,b,c)      M_OP3 (0x12,0x2b, a,b,c,1)
577 #define M_INSQL_IMM(a,b,c)      M_OP3 (0x12,0x3b, a,b,c,1)
578 #define M_INSWH_IMM(a,b,c)      M_OP3 (0x12,0x57, a,b,c,1)
579 #define M_INSLH_IMM(a,b,c)      M_OP3 (0x12,0x67, a,b,c,1)
580 #define M_INSQH_IMM(a,b,c)      M_OP3 (0x12,0x77, a,b,c,1)
581 #define M_MSKBL_IMM(a,b,c)      M_OP3 (0x12,0x02, a,b,c,1)
582 #define M_MSKWL_IMM(a,b,c)      M_OP3 (0x12,0x12, a,b,c,1)
583 #define M_MSKLL_IMM(a,b,c)      M_OP3 (0x12,0x22, a,b,c,1)
584 #define M_MSKQL_IMM(a,b,c)      M_OP3 (0x12,0x32, a,b,c,1)
585 #define M_MSKWH_IMM(a,b,c)      M_OP3 (0x12,0x52, a,b,c,1)
586 #define M_MSKLH_IMM(a,b,c)      M_OP3 (0x12,0x62, a,b,c,1)
587 #define M_MSKQH_IMM(a,b,c)      M_OP3 (0x12,0x72, a,b,c,1)
588
589 #define M_UMULH(a,b,c)          M_OP3 (0x13,0x30, a,b,c,0)     /* 64 umulh    */
590
591 #define M_UMULH_IMM(a,b,c)      M_OP3 (0x13,0x30, a,b,c,1)     /* 64 umulh    */
592
593 #define M_CMOVEQ(a,b,c)         M_OP3 (0x11,0x24, a,b,c,0)     /* a==0 ? c=b  */
594 #define M_CMOVNE(a,b,c)         M_OP3 (0x11,0x26, a,b,c,0)     /* a!=0 ? c=b  */
595 #define M_CMOVLT(a,b,c)         M_OP3 (0x11,0x44, a,b,c,0)     /* a< 0 ? c=b  */
596 #define M_CMOVGE(a,b,c)         M_OP3 (0x11,0x46, a,b,c,0)     /* a>=0 ? c=b  */
597 #define M_CMOVLE(a,b,c)         M_OP3 (0x11,0x64, a,b,c,0)     /* a<=0 ? c=b  */
598 #define M_CMOVGT(a,b,c)         M_OP3 (0x11,0x66, a,b,c,0)     /* a> 0 ? c=b  */
599
600 #define M_CMOVEQ_IMM(a,b,c)     M_OP3 (0x11,0x24, a,b,c,1)     /* a==0 ? c=b  */
601 #define M_CMOVNE_IMM(a,b,c)     M_OP3 (0x11,0x26, a,b,c,1)     /* a!=0 ? c=b  */
602 #define M_CMOVLT_IMM(a,b,c)     M_OP3 (0x11,0x44, a,b,c,1)     /* a< 0 ? c=b  */
603 #define M_CMOVGE_IMM(a,b,c)     M_OP3 (0x11,0x46, a,b,c,1)     /* a>=0 ? c=b  */
604 #define M_CMOVLE_IMM(a,b,c)     M_OP3 (0x11,0x64, a,b,c,1)     /* a<=0 ? c=b  */
605 #define M_CMOVGT_IMM(a,b,c)     M_OP3 (0x11,0x66, a,b,c,1)     /* a> 0 ? c=b  */
606
607 /* macros for unused commands (see an Alpha-manual for description) ***********/ 
608
609 #define M_ANDNOT(a,b,c,const)   M_OP3 (0x11,0x08, a,b,c,const) /* c = a &~ b  */
610 #define M_ORNOT(a,b,c,const)    M_OP3 (0x11,0x28, a,b,c,const) /* c = a |~ b  */
611 #define M_XORNOT(a,b,c,const)   M_OP3 (0x11,0x48, a,b,c,const) /* c = a ^~ b  */
612
613 #define M_CMPBGE(a,b,c,const)   M_OP3 (0x10,0x0f, a,b,c,const)
614
615 #define M_FCMPUN(a,b,c)         M_FOP3 (0x16, 0x0a4, a,b,c)    /* unordered   */
616 #define M_FCMPLE(a,b,c)         M_FOP3 (0x16, 0x0a7, a,b,c)    /* c = a<=b    */
617
618 #define M_FCMPUNS(a,b,c)        M_FOP3 (0x16, 0x5a4, a,b,c)    /* unordered   */
619 #define M_FCMPLES(a,b,c)        M_FOP3 (0x16, 0x5a7, a,b,c)    /* c = a<=b    */
620
621 #define M_FBNEZ(fa,disp)        M_BRA (0x35,fa,disp)
622 #define M_FBLEZ(fa,disp)        M_BRA (0x33,fa,disp)
623
624 #define M_JMP_CO(a,b)           M_MEM (0x1a,a,b,0xc000)        /* call cosub  */
625
626
627 /* gen_resolvebranch ***********************************************************
628
629    backpatches a branch instruction; Alpha branch instructions are very
630    regular, so it is only necessary to overwrite some fixed bits in the
631    instruction.
632
633    parameters: ip ... pointer to instruction after branch (void*)
634                so ... offset of instruction after branch  (s4)
635                to ... offset of branch target             (s4)
636
637 *******************************************************************************/
638
639 #define gen_resolvebranch(ip,so,to) \
640     ((s4 *) (ip))[-1] |= ((s4) (to) - (so)) >> 2 & 0x1fffff
641
642
643 /* function prototypes ********************************************************/
644
645 void thread_restartcriticalsection(ucontext_t*);
646
647 #endif /* _CODEGEN_H */
648
649
650 /*
651  * These are local overrides for various environment variables in Emacs.
652  * Please do not remove this and leave it at the end of the file, where
653  * Emacs will automagically detect them.
654  * ---------------------------------------------------------------------
655  * Local variables:
656  * mode: c
657  * indent-tabs-mode: t
658  * c-basic-offset: 4
659  * tab-width: 4
660  * End:
661  */