OSDN Git Service

35cc9477b8c394d35d25c8f032e348bcbcd853f7
[pf3gnuchains/gcc-fork.git] / gcc / config / s390 / s390.h
1 /* Definitions of target machine for GNU compiler, for IBM S/390
2    Copyright (C) 1999, 2000, 2001, 2002, 2003, 2004, 2005, 2006,
3    2007 Free Software Foundation, Inc.
4    Contributed by Hartmut Penner (hpenner@de.ibm.com) and
5                   Ulrich Weigand (uweigand@de.ibm.com).
6
7 This file is part of GCC.
8
9 GCC is free software; you can redistribute it and/or modify it under
10 the terms of the GNU General Public License as published by the Free
11 Software Foundation; either version 3, or (at your option) any later
12 version.
13
14 GCC is distributed in the hope that it will be useful, but WITHOUT ANY
15 WARRANTY; without even the implied warranty of MERCHANTABILITY or
16 FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
17 for more details.
18
19 You should have received a copy of the GNU General Public License
20 along with GCC; see the file COPYING3.  If not see
21 <http://www.gnu.org/licenses/>.  */
22
23 #ifndef _S390_H
24 #define _S390_H
25
26 /* Override the __fixdfdi etc. routines when building libgcc2.
27    ??? This should be done in a cleaner way ...  */
28 #if defined (IN_LIBGCC2) && !defined (__s390x__)
29 #include <config/s390/fixdfdi.h>
30 #endif
31
32 /* Which processor to generate code or schedule for. The cpu attribute
33    defines a list that mirrors this list, so changes to s390.md must be
34    made at the same time.  */
35
36 enum processor_type
37 {
38   PROCESSOR_9672_G5,
39   PROCESSOR_9672_G6,
40   PROCESSOR_2064_Z900,
41   PROCESSOR_2084_Z990,
42   PROCESSOR_2094_Z9_109,
43   PROCESSOR_max
44 };
45
46 /* Optional architectural facilities supported by the processor.  */
47
48 enum processor_flags
49 {
50   PF_IEEE_FLOAT = 1,
51   PF_ZARCH = 2,
52   PF_LONG_DISPLACEMENT = 4,
53   PF_EXTIMM = 8,
54   PF_DFP = 16
55 };
56
57 extern enum processor_type s390_tune;
58 extern enum processor_flags s390_tune_flags;
59
60 extern enum processor_type s390_arch;
61 extern enum processor_flags s390_arch_flags;
62
63 #define TARGET_CPU_IEEE_FLOAT \
64         (s390_arch_flags & PF_IEEE_FLOAT)
65 #define TARGET_CPU_ZARCH \
66         (s390_arch_flags & PF_ZARCH)
67 #define TARGET_CPU_LONG_DISPLACEMENT \
68         (s390_arch_flags & PF_LONG_DISPLACEMENT)
69 #define TARGET_CPU_EXTIMM \
70         (s390_arch_flags & PF_EXTIMM)
71 #define TARGET_CPU_DFP \
72         (s390_arch_flags & PF_DFP)
73
74 #define TARGET_LONG_DISPLACEMENT \
75        (TARGET_ZARCH && TARGET_CPU_LONG_DISPLACEMENT)
76 #define TARGET_EXTIMM \
77        (TARGET_ZARCH && TARGET_CPU_EXTIMM)
78 #define TARGET_DFP \
79        (TARGET_ZARCH && TARGET_CPU_DFP)
80
81 /* Run-time target specification.  */
82
83 /* Defaults for option flags defined only on some subtargets.  */
84 #ifndef TARGET_TPF_PROFILING
85 #define TARGET_TPF_PROFILING 0
86 #endif
87
88 /* This will be overridden by OS headers.  */
89 #define TARGET_TPF 0
90
91 /* Target CPU builtins.  */
92 #define TARGET_CPU_CPP_BUILTINS()                       \
93   do                                                    \
94     {                                                   \
95       builtin_assert ("cpu=s390");                      \
96       builtin_assert ("machine=s390");                  \
97       builtin_define ("__s390__");                      \
98       if (TARGET_64BIT)                                 \
99         builtin_define ("__s390x__");                   \
100       if (TARGET_LONG_DOUBLE_128)                       \
101         builtin_define ("__LONG_DOUBLE_128__");         \
102     }                                                   \
103   while (0)
104
105 #ifdef DEFAULT_TARGET_64BIT
106 #define TARGET_DEFAULT             (MASK_64BIT | MASK_ZARCH | MASK_HARD_DFP)
107 #else
108 #define TARGET_DEFAULT             0
109 #endif
110
111 /* Support for configure-time defaults.  */
112 #define OPTION_DEFAULT_SPECS                                    \
113   { "mode", "%{!mesa:%{!mzarch:-m%(VALUE)}}" },                 \
114   { "arch", "%{!march=*:-march=%(VALUE)}" },                    \
115   { "tune", "%{!mtune=*:-mtune=%(VALUE)}" }
116
117 /* Defaulting rules.  */
118 #ifdef DEFAULT_TARGET_64BIT
119 #define DRIVER_SELF_SPECS                                       \
120   "%{!m31:%{!m64:-m64}}",                                       \
121   "%{!mesa:%{!mzarch:%{m31:-mesa}%{m64:-mzarch}}}",             \
122   "%{!march=*:%{mesa:-march=g5}%{mzarch:-march=z900}}"
123 #else
124 #define DRIVER_SELF_SPECS                                       \
125   "%{!m31:%{!m64:-m31}}",                                       \
126   "%{!mesa:%{!mzarch:%{m31:-mesa}%{m64:-mzarch}}}",             \
127   "%{!march=*:%{mesa:-march=g5}%{mzarch:-march=z900}}"
128 #endif
129
130 /* Target version string.  Overridden by the OS header.  */
131 #ifdef DEFAULT_TARGET_64BIT
132 #define TARGET_VERSION fprintf (stderr, " (zSeries)");
133 #else
134 #define TARGET_VERSION fprintf (stderr, " (S/390)");
135 #endif
136
137 /* Hooks to override options.  */
138 #define OPTIMIZATION_OPTIONS(LEVEL, SIZE) optimization_options(LEVEL, SIZE)
139 #define OVERRIDE_OPTIONS override_options ()
140
141 /* Frame pointer is not used for debugging.  */
142 #define CAN_DEBUG_WITHOUT_FP
143
144 /* Constants needed to control the TEST DATA CLASS (TDC) instruction.  */
145 #define S390_TDC_POSITIVE_ZERO                (1 << 11)
146 #define S390_TDC_NEGATIVE_ZERO                (1 << 10)
147 #define S390_TDC_POSITIVE_NORMALIZED_NUMBER   (1 << 9)
148 #define S390_TDC_NEGATIVE_NORMALIZED_NUMBER   (1 << 8)
149 #define S390_TDC_POSITIVE_DENORMALIZED_NUMBER (1 << 7)
150 #define S390_TDC_NEGATIVE_DENORMALIZED_NUMBER (1 << 6)
151 #define S390_TDC_POSITIVE_INFINITY            (1 << 5)
152 #define S390_TDC_NEGATIVE_INFINITY            (1 << 4)
153 #define S390_TDC_POSITIVE_QUIET_NAN           (1 << 3)
154 #define S390_TDC_NEGATIVE_QUIET_NAN           (1 << 2)
155 #define S390_TDC_POSITIVE_SIGNALING_NAN       (1 << 1)
156 #define S390_TDC_NEGATIVE_SIGNALING_NAN       (1 << 0)
157
158 #define S390_TDC_SIGNBIT_SET (S390_TDC_NEGATIVE_ZERO \
159                           | S390_TDC_NEGATIVE_NORMALIZED_NUMBER \
160                           | S390_TDC_NEGATIVE_DENORMALIZED_NUMBER\
161                           | S390_TDC_NEGATIVE_INFINITY \
162                           | S390_TDC_NEGATIVE_QUIET_NAN \
163                           | S390_TDC_NEGATIVE_SIGNALING_NAN )
164
165 #define S390_TDC_INFINITY (S390_TDC_POSITIVE_INFINITY \
166                           | S390_TDC_NEGATIVE_INFINITY )
167
168 /* In libgcc2, determine target settings as compile-time constants.  */
169 #ifdef IN_LIBGCC2
170 #undef TARGET_64BIT
171 #ifdef __s390x__
172 #define TARGET_64BIT 1
173 #else
174 #define TARGET_64BIT 0
175 #endif
176 #endif
177
178
179 /* Target machine storage layout.  */
180
181 /* Everything is big-endian.  */
182 #define BITS_BIG_ENDIAN 1
183 #define BYTES_BIG_ENDIAN 1
184 #define WORDS_BIG_ENDIAN 1
185
186 /* Width of a word, in units (bytes).  */
187 #define UNITS_PER_WORD (TARGET_64BIT ? 8 : 4)
188 #ifndef IN_LIBGCC2
189 #define MIN_UNITS_PER_WORD 4
190 #endif
191 #define MAX_BITS_PER_WORD 64
192
193 /* Function arguments and return values are promoted to word size.  */
194 #define PROMOTE_FUNCTION_MODE(MODE, UNSIGNEDP, TYPE)            \
195 if (INTEGRAL_MODE_P (MODE) &&                           \
196     GET_MODE_SIZE (MODE) < UNITS_PER_WORD) {            \
197   (MODE) = Pmode;                                       \
198           }
199
200 /* Allocation boundary (in *bits*) for storing arguments in argument list.  */
201 #define PARM_BOUNDARY (TARGET_64BIT ? 64 : 32)
202
203 /* Boundary (in *bits*) on which stack pointer should be aligned.  */
204 #define STACK_BOUNDARY 64
205
206 /* Allocation boundary (in *bits*) for the code of a function.  */
207 #define FUNCTION_BOUNDARY 32
208
209 /* There is no point aligning anything to a rounder boundary than this.  */
210 #define BIGGEST_ALIGNMENT 64
211
212 /* Alignment of field after `int : 0' in a structure.  */
213 #define EMPTY_FIELD_BOUNDARY 32
214
215 /* Alignment on even addresses for LARL instruction.  */
216 #define CONSTANT_ALIGNMENT(EXP, ALIGN) (ALIGN) < 16 ? 16 : (ALIGN)
217 #define DATA_ALIGNMENT(TYPE, ALIGN) (ALIGN) < 16 ? 16 : (ALIGN)
218
219 /* Alignment is not required by the hardware.  */
220 #define STRICT_ALIGNMENT 0
221
222 /* Mode of stack savearea.
223    FUNCTION is VOIDmode because calling convention maintains SP.
224    BLOCK needs Pmode for SP.
225    NONLOCAL needs twice Pmode to maintain both backchain and SP.  */
226 #define STACK_SAVEAREA_MODE(LEVEL)      \
227   (LEVEL == SAVE_FUNCTION ? VOIDmode    \
228   : LEVEL == SAVE_NONLOCAL ? (TARGET_64BIT ? OImode : TImode) : Pmode)
229
230
231 /* Type layout.  */
232
233 /* Sizes in bits of the source language data types.  */
234 #define SHORT_TYPE_SIZE 16
235 #define INT_TYPE_SIZE 32
236 #define LONG_TYPE_SIZE (TARGET_64BIT ? 64 : 32)
237 #define LONG_LONG_TYPE_SIZE 64
238 #define FLOAT_TYPE_SIZE 32
239 #define DOUBLE_TYPE_SIZE 64
240 #define LONG_DOUBLE_TYPE_SIZE (TARGET_LONG_DOUBLE_128 ? 128 : 64)
241
242 /* Define this to set long double type size to use in libgcc2.c, which can
243    not depend on target_flags.  */
244 #ifdef __LONG_DOUBLE_128__
245 #define LIBGCC2_LONG_DOUBLE_TYPE_SIZE 128
246 #else
247 #define LIBGCC2_LONG_DOUBLE_TYPE_SIZE 64
248 #endif
249
250 /* Work around target_flags dependency in ada/targtyps.c.  */
251 #define WIDEST_HARDWARE_FP_SIZE 64
252
253 /* We use "unsigned char" as default.  */
254 #define DEFAULT_SIGNED_CHAR 0
255
256
257 /* Register usage.  */
258
259 /* We have 16 general purpose registers (registers 0-15),
260    and 16 floating point registers (registers 16-31).
261    (On non-IEEE machines, we have only 4 fp registers.)
262
263    Amongst the general purpose registers, some are used
264    for specific purposes:
265    GPR 11: Hard frame pointer (if needed)
266    GPR 12: Global offset table pointer (if needed)
267    GPR 13: Literal pool base register
268    GPR 14: Return address register
269    GPR 15: Stack pointer
270
271    Registers 32-35 are 'fake' hard registers that do not
272    correspond to actual hardware:
273    Reg 32: Argument pointer
274    Reg 33: Condition code
275    Reg 34: Frame pointer  
276    Reg 35: Return address pointer
277
278    Registers 36 and 37 are mapped to access registers 
279    0 and 1, used to implement thread-local storage.  */
280
281 #define FIRST_PSEUDO_REGISTER 38
282
283 /* Standard register usage.  */
284 #define GENERAL_REGNO_P(N)      ((int)(N) >= 0 && (N) < 16)
285 #define ADDR_REGNO_P(N)         ((N) >= 1 && (N) < 16)
286 #define FP_REGNO_P(N)           ((N) >= 16 && (N) < 32)
287 #define CC_REGNO_P(N)           ((N) == 33)
288 #define FRAME_REGNO_P(N)        ((N) == 32 || (N) == 34 || (N) == 35)
289 #define ACCESS_REGNO_P(N)       ((N) == 36 || (N) == 37)
290
291 #define GENERAL_REG_P(X)        (REG_P (X) && GENERAL_REGNO_P (REGNO (X)))
292 #define ADDR_REG_P(X)           (REG_P (X) && ADDR_REGNO_P (REGNO (X)))
293 #define FP_REG_P(X)             (REG_P (X) && FP_REGNO_P (REGNO (X)))
294 #define CC_REG_P(X)             (REG_P (X) && CC_REGNO_P (REGNO (X)))
295 #define FRAME_REG_P(X)          (REG_P (X) && FRAME_REGNO_P (REGNO (X)))
296 #define ACCESS_REG_P(X)         (REG_P (X) && ACCESS_REGNO_P (REGNO (X)))
297
298 /* Set up fixed registers and calling convention:
299
300    GPRs 0-5 are always call-clobbered,
301    GPRs 6-15 are always call-saved.
302    GPR 12 is fixed if used as GOT pointer.
303    GPR 13 is always fixed (as literal pool pointer).
304    GPR 14 is always fixed on S/390 machines (as return address).
305    GPR 15 is always fixed (as stack pointer).
306    The 'fake' hard registers are call-clobbered and fixed.
307    The access registers are call-saved and fixed.
308
309    On 31-bit, FPRs 18-19 are call-clobbered;
310    on 64-bit, FPRs 24-31 are call-clobbered.
311    The remaining FPRs are call-saved.  */
312
313 #define FIXED_REGISTERS                         \
314 { 0, 0, 0, 0,                                   \
315   0, 0, 0, 0,                                   \
316   0, 0, 0, 0,                                   \
317   0, 1, 1, 1,                                   \
318   0, 0, 0, 0,                                   \
319   0, 0, 0, 0,                                   \
320   0, 0, 0, 0,                                   \
321   0, 0, 0, 0,                                   \
322   1, 1, 1, 1,                                   \
323   1, 1 }
324
325 #define CALL_USED_REGISTERS                     \
326 { 1, 1, 1, 1,                                   \
327   1, 1, 0, 0,                                   \
328   0, 0, 0, 0,                                   \
329   0, 1, 1, 1,                                   \
330   1, 1, 1, 1,                                   \
331   1, 1, 1, 1,                                   \
332   1, 1, 1, 1,                                   \
333   1, 1, 1, 1,                                   \
334   1, 1, 1, 1,                                   \
335   1, 1 }
336
337 #define CALL_REALLY_USED_REGISTERS              \
338 { 1, 1, 1, 1,                                   \
339   1, 1, 0, 0,                                   \
340   0, 0, 0, 0,                                   \
341   0, 0, 0, 0,                                   \
342   1, 1, 1, 1,                                   \
343   1, 1, 1, 1,                                   \
344   1, 1, 1, 1,                                   \
345   1, 1, 1, 1,                                   \
346   1, 1, 1, 1,                                   \
347   0, 0 }
348
349 #define CONDITIONAL_REGISTER_USAGE s390_conditional_register_usage ()
350
351 /* Preferred register allocation order.  */
352 #define REG_ALLOC_ORDER                                         \
353 {  1, 2, 3, 4, 5, 0, 12, 11, 10, 9, 8, 7, 6, 14, 13,            \
354    16, 17, 18, 19, 20, 21, 22, 23,                              \
355    24, 25, 26, 27, 28, 29, 30, 31,                              \
356    15, 32, 33, 34, 35, 36, 37 }
357
358
359 /* Fitting values into registers.  */
360
361 /* Integer modes <= word size fit into any GPR.
362    Integer modes > word size fit into successive GPRs, starting with
363    an even-numbered register.
364    SImode and DImode fit into FPRs as well.
365
366    Floating point modes <= word size fit into any FPR or GPR.
367    Floating point modes > word size (i.e. DFmode on 32-bit) fit
368    into any FPR, or an even-odd GPR pair.
369    TFmode fits only into an even-odd FPR pair.
370
371    Complex floating point modes fit either into two FPRs, or into
372    successive GPRs (again starting with an even number).
373    TCmode fits only into two successive even-odd FPR pairs.
374
375    Condition code modes fit only into the CC register.  */
376
377 /* Because all registers in a class have the same size HARD_REGNO_NREGS
378    is equivalent to CLASS_MAX_NREGS.  */
379 #define HARD_REGNO_NREGS(REGNO, MODE)                           \
380   s390_class_max_nregs (REGNO_REG_CLASS (REGNO), (MODE))
381
382 #define HARD_REGNO_MODE_OK(REGNO, MODE)         \
383   s390_hard_regno_mode_ok ((REGNO), (MODE))
384
385 #define HARD_REGNO_RENAME_OK(FROM, TO)          \
386   s390_hard_regno_rename_ok (FROM, TO)
387
388 #define MODES_TIEABLE_P(MODE1, MODE2)           \
389    (((MODE1) == SFmode || (MODE1) == DFmode)    \
390    == ((MODE2) == SFmode || (MODE2) == DFmode))
391
392 /* Maximum number of registers to represent a value of mode MODE
393    in a register of class CLASS.  */
394 #define CLASS_MAX_NREGS(CLASS, MODE)                                    \
395   s390_class_max_nregs ((CLASS), (MODE))
396
397 /* If a 4-byte value is loaded into a FPR, it is placed into the
398    *upper* half of the register, not the lower.  Therefore, we
399    cannot use SUBREGs to switch between modes in FP registers.
400    Likewise for access registers, since they have only half the
401    word size on 64-bit.  */
402 #define CANNOT_CHANGE_MODE_CLASS(FROM, TO, CLASS)                       \
403   (GET_MODE_SIZE (FROM) != GET_MODE_SIZE (TO)                           \
404    ? ((reg_classes_intersect_p (FP_REGS, CLASS)                         \
405        && (GET_MODE_SIZE (FROM) < 8 || GET_MODE_SIZE (TO) < 8))         \
406       || reg_classes_intersect_p (ACCESS_REGS, CLASS)) : 0)
407
408 /* Register classes.  */
409
410 /* We use the following register classes:
411    GENERAL_REGS     All general purpose registers
412    ADDR_REGS        All general purpose registers except %r0
413                     (These registers can be used in address generation)
414    FP_REGS          All floating point registers
415    CC_REGS          The condition code register
416    ACCESS_REGS      The access registers
417
418    GENERAL_FP_REGS  Union of GENERAL_REGS and FP_REGS
419    ADDR_FP_REGS     Union of ADDR_REGS and FP_REGS
420    GENERAL_CC_REGS  Union of GENERAL_REGS and CC_REGS
421    ADDR_CC_REGS     Union of ADDR_REGS and CC_REGS
422
423    NO_REGS          No registers
424    ALL_REGS         All registers
425
426    Note that the 'fake' frame pointer and argument pointer registers
427    are included amongst the address registers here.  */
428
429 enum reg_class
430 {
431   NO_REGS, CC_REGS, ADDR_REGS, GENERAL_REGS, ACCESS_REGS,
432   ADDR_CC_REGS, GENERAL_CC_REGS, 
433   FP_REGS, ADDR_FP_REGS, GENERAL_FP_REGS,
434   ALL_REGS, LIM_REG_CLASSES
435 };
436 #define N_REG_CLASSES (int) LIM_REG_CLASSES
437
438 #define REG_CLASS_NAMES                                                 \
439 { "NO_REGS", "CC_REGS", "ADDR_REGS", "GENERAL_REGS", "ACCESS_REGS",     \
440   "ADDR_CC_REGS", "GENERAL_CC_REGS",                                    \
441   "FP_REGS", "ADDR_FP_REGS", "GENERAL_FP_REGS", "ALL_REGS" }
442
443 /* Class -> register mapping.  */
444 #define REG_CLASS_CONTENTS \
445 {                                                       \
446   { 0x00000000, 0x00000000 },   /* NO_REGS */           \
447   { 0x00000000, 0x00000002 },   /* CC_REGS */           \
448   { 0x0000fffe, 0x0000000d },   /* ADDR_REGS */         \
449   { 0x0000ffff, 0x0000000d },   /* GENERAL_REGS */      \
450   { 0x00000000, 0x00000030 },   /* ACCESS_REGS */       \
451   { 0x0000fffe, 0x0000000f },   /* ADDR_CC_REGS */      \
452   { 0x0000ffff, 0x0000000f },   /* GENERAL_CC_REGS */   \
453   { 0xffff0000, 0x00000000 },   /* FP_REGS */           \
454   { 0xfffffffe, 0x0000000d },   /* ADDR_FP_REGS */      \
455   { 0xffffffff, 0x0000000d },   /* GENERAL_FP_REGS */   \
456   { 0xffffffff, 0x0000003f },   /* ALL_REGS */          \
457 }
458
459 /* Register -> class mapping.  */
460 extern const enum reg_class regclass_map[FIRST_PSEUDO_REGISTER];
461 #define REGNO_REG_CLASS(REGNO) (regclass_map[REGNO])
462
463 /* ADDR_REGS can be used as base or index register.  */
464 #define INDEX_REG_CLASS ADDR_REGS
465 #define BASE_REG_CLASS ADDR_REGS
466
467 /* Check whether REGNO is a hard register of the suitable class
468    or a pseudo register currently allocated to one such.  */
469 #define REGNO_OK_FOR_INDEX_P(REGNO)                                     \
470     (((REGNO) < FIRST_PSEUDO_REGISTER                                   \
471       && REGNO_REG_CLASS ((REGNO)) == ADDR_REGS)                        \
472      || ADDR_REGNO_P (reg_renumber[REGNO]))
473 #define REGNO_OK_FOR_BASE_P(REGNO) REGNO_OK_FOR_INDEX_P (REGNO)
474
475
476 /* Given an rtx X being reloaded into a reg required to be in class CLASS,
477    return the class of reg to actually use.  */
478 #define PREFERRED_RELOAD_CLASS(X, CLASS)        \
479   s390_preferred_reload_class ((X), (CLASS))
480
481 /* We need secondary memory to move data between GPRs and FPRs.  */
482 #define SECONDARY_MEMORY_NEEDED(CLASS1, CLASS2, MODE) \
483  ((CLASS1) != (CLASS2)                                \
484   && ((CLASS1) == FP_REGS || (CLASS2) == FP_REGS)     \
485   && (!TARGET_DFP || GET_MODE_SIZE (MODE) != 8))
486
487 /* Get_secondary_mem widens its argument to BITS_PER_WORD which loses on 64bit
488    because the movsi and movsf patterns don't handle r/f moves.  */
489 #define SECONDARY_MEMORY_NEEDED_MODE(MODE)              \
490  (GET_MODE_BITSIZE (MODE) < 32                          \
491   ? mode_for_size (32, GET_MODE_CLASS (MODE), 0)        \
492   : MODE)
493
494
495 /* Stack layout and calling conventions.  */
496
497 /* Our stack grows from higher to lower addresses.  However, local variables
498    are accessed by positive offsets, and function arguments are stored at
499    increasing addresses.  */
500 #define STACK_GROWS_DOWNWARD
501 #define FRAME_GROWS_DOWNWARD 1
502 /* #undef ARGS_GROW_DOWNWARD */
503
504 /* The basic stack layout looks like this: the stack pointer points
505    to the register save area for called functions.  Above that area
506    is the location to place outgoing arguments.  Above those follow
507    dynamic allocations (alloca), and finally the local variables.  */
508
509 /* Offset from stack-pointer to first location of outgoing args.  */
510 #define STACK_POINTER_OFFSET (TARGET_64BIT ? 160 : 96)
511
512 /* Offset within stack frame to start allocating local variables at.  */
513 #define STARTING_FRAME_OFFSET 0
514
515 /* Offset from the stack pointer register to an item dynamically
516    allocated on the stack, e.g., by `alloca'.  */
517 extern int current_function_outgoing_args_size;
518 #define STACK_DYNAMIC_OFFSET(FUNDECL) \
519   (STACK_POINTER_OFFSET + current_function_outgoing_args_size)
520
521 /* Offset of first parameter from the argument pointer register value.
522    We have a fake argument pointer register that points directly to
523    the argument area.  */
524 #define FIRST_PARM_OFFSET(FNDECL) 0
525
526 /* Defining this macro makes __builtin_frame_address(0) and 
527    __builtin_return_address(0) work with -fomit-frame-pointer.  */
528 #define INITIAL_FRAME_ADDRESS_RTX                                             \
529   (TARGET_PACKED_STACK ?                                                      \
530    plus_constant (arg_pointer_rtx, -UNITS_PER_WORD) :                         \
531    plus_constant (arg_pointer_rtx, -STACK_POINTER_OFFSET))
532
533 /* The return address of the current frame is retrieved
534    from the initial value of register RETURN_REGNUM.
535    For frames farther back, we use the stack slot where
536    the corresponding RETURN_REGNUM register was saved.  */
537 #define DYNAMIC_CHAIN_ADDRESS(FRAME)                                          \
538   (TARGET_PACKED_STACK ?                                                      \
539    plus_constant ((FRAME), STACK_POINTER_OFFSET - UNITS_PER_WORD) : (FRAME))
540
541 #define RETURN_ADDR_RTX(COUNT, FRAME)                                         \
542   s390_return_addr_rtx ((COUNT), DYNAMIC_CHAIN_ADDRESS ((FRAME)))
543
544 /* In 31-bit mode, we need to mask off the high bit of return addresses.  */
545 #define MASK_RETURN_ADDR (TARGET_64BIT ? constm1_rtx : GEN_INT (0x7fffffff))
546
547
548 /* Exception handling.  */
549
550 /* Describe calling conventions for DWARF-2 exception handling.  */
551 #define INCOMING_RETURN_ADDR_RTX  gen_rtx_REG (Pmode, RETURN_REGNUM)
552 #define INCOMING_FRAME_SP_OFFSET STACK_POINTER_OFFSET
553 #define DWARF_FRAME_RETURN_COLUMN  14
554
555 /* Describe how we implement __builtin_eh_return.  */
556 #define EH_RETURN_DATA_REGNO(N) ((N) < 4 ? (N) + 6 : INVALID_REGNUM)
557 #define EH_RETURN_HANDLER_RTX gen_rtx_MEM (Pmode, return_address_pointer_rtx)
558        
559 /* Select a format to encode pointers in exception handling data.  */
560 #define ASM_PREFERRED_EH_DATA_FORMAT(CODE, GLOBAL)                          \
561   (flag_pic                                                                 \
562     ? ((GLOBAL) ? DW_EH_PE_indirect : 0) | DW_EH_PE_pcrel | DW_EH_PE_sdata4 \
563    : DW_EH_PE_absptr)
564
565
566 /* Frame registers.  */
567
568 #define STACK_POINTER_REGNUM 15
569 #define FRAME_POINTER_REGNUM 34
570 #define HARD_FRAME_POINTER_REGNUM 11
571 #define ARG_POINTER_REGNUM 32
572 #define RETURN_ADDRESS_POINTER_REGNUM 35
573
574 /* The static chain must be call-clobbered, but not used for
575    function argument passing.  As register 1 is clobbered by
576    the trampoline code, we only have one option.  */
577 #define STATIC_CHAIN_REGNUM 0
578
579 /* Number of hardware registers that go into the DWARF-2 unwind info.
580    To avoid ABI incompatibility, this number must not change even as
581    'fake' hard registers are added or removed.  */
582 #define DWARF_FRAME_REGISTERS 34
583
584
585 /* Frame pointer and argument pointer elimination.  */
586
587 #define FRAME_POINTER_REQUIRED 0
588
589 #define ELIMINABLE_REGS                                         \
590 {{ FRAME_POINTER_REGNUM, STACK_POINTER_REGNUM },                \
591  { FRAME_POINTER_REGNUM, HARD_FRAME_POINTER_REGNUM },           \
592  { ARG_POINTER_REGNUM, STACK_POINTER_REGNUM },                  \
593  { ARG_POINTER_REGNUM, HARD_FRAME_POINTER_REGNUM },             \
594  { RETURN_ADDRESS_POINTER_REGNUM, STACK_POINTER_REGNUM },       \
595  { RETURN_ADDRESS_POINTER_REGNUM, HARD_FRAME_POINTER_REGNUM },  \
596  { BASE_REGNUM, BASE_REGNUM }}
597
598 #define CAN_ELIMINATE(FROM, TO) \
599   s390_can_eliminate ((FROM), (TO))
600
601 #define INITIAL_ELIMINATION_OFFSET(FROM, TO, OFFSET) \
602   (OFFSET) = s390_initial_elimination_offset ((FROM), (TO))
603
604
605 /* Stack arguments.  */
606
607 /* We need current_function_outgoing_args to be valid.  */
608 #define ACCUMULATE_OUTGOING_ARGS 1
609
610 /* Return doesn't modify the stack.  */
611 #define RETURN_POPS_ARGS(FUNDECL, FUNTYPE, SIZE) 0
612
613
614 /* Register arguments.  */
615
616 typedef struct s390_arg_structure
617 {
618   int gprs;                     /* gpr so far */
619   int fprs;                     /* fpr so far */
620 }
621 CUMULATIVE_ARGS;
622
623 #define INIT_CUMULATIVE_ARGS(CUM, FNTYPE, LIBNAME, NN, N_NAMED_ARGS) \
624   ((CUM).gprs=0, (CUM).fprs=0)
625
626 #define FUNCTION_ARG_ADVANCE(CUM, MODE, TYPE, NAMED)                    \
627   s390_function_arg_advance (&CUM, MODE, TYPE, NAMED)
628
629 #define FUNCTION_ARG(CUM, MODE, TYPE, NAMED)   \
630   s390_function_arg (&CUM, MODE, TYPE, NAMED)
631
632 /* Arguments can be placed in general registers 2 to 6,
633    or in floating point registers 0 and 2.  */
634 #define FUNCTION_ARG_REGNO_P(N) (((N) >=2 && (N) <7) || \
635                                  (N) == 16 || (N) == 17)
636
637
638 /* Scalar return values.  */
639
640 #define FUNCTION_VALUE(VALTYPE, FUNC) \
641   s390_function_value ((VALTYPE), VOIDmode)
642
643 #define LIBCALL_VALUE(MODE) \
644   s390_function_value (NULL, (MODE))
645
646 /* Only gpr 2 and fpr 0 are ever used as return registers.  */
647 #define FUNCTION_VALUE_REGNO_P(N) ((N) == 2 || (N) == 16)
648
649
650 /* Function entry and exit.  */
651
652 /* When returning from a function, the stack pointer does not matter.  */
653 #define EXIT_IGNORE_STACK       1
654
655
656 /* Profiling.  */
657
658 #define FUNCTION_PROFILER(FILE, LABELNO)                        \
659   s390_function_profiler ((FILE), ((LABELNO)))
660
661 #define PROFILE_BEFORE_PROLOGUE 1
662
663
664 /* Trampolines for nested functions.  */
665
666 #define TRAMPOLINE_SIZE (TARGET_64BIT ? 32 : 16)
667
668 #define INITIALIZE_TRAMPOLINE(ADDR, FNADDR, CXT)                       \
669    s390_initialize_trampoline ((ADDR), (FNADDR), (CXT))
670
671 #define TRAMPOLINE_TEMPLATE(FILE)                                       \
672    s390_trampoline_template (FILE)
673
674
675 /* Addressing modes, and classification of registers for them.  */
676
677 /* Recognize any constant value that is a valid address.  */
678 #define CONSTANT_ADDRESS_P(X) 0
679
680 /* Maximum number of registers that can appear in a valid memory address.  */
681 #define MAX_REGS_PER_ADDRESS 2
682
683 /* S/390 has no mode dependent addresses.  */
684 #define GO_IF_MODE_DEPENDENT_ADDRESS(ADDR, LABEL)
685
686 /* GO_IF_LEGITIMATE_ADDRESS recognizes an RTL expression that is a
687    valid memory address for an instruction.
688    The MODE argument is the machine mode for the MEM expression
689    that wants to use this address.  */
690 #ifdef REG_OK_STRICT
691 #define GO_IF_LEGITIMATE_ADDRESS(MODE, X, ADDR)                         \
692 {                                                                       \
693   if (legitimate_address_p (MODE, X, 1))                                \
694     goto ADDR;                                                          \
695 }
696 #else
697 #define GO_IF_LEGITIMATE_ADDRESS(MODE, X, ADDR)                         \
698 {                                                                       \
699   if (legitimate_address_p (MODE, X, 0))                                \
700     goto ADDR;                                                          \
701 }
702 #endif
703
704 /* Try machine-dependent ways of modifying an illegitimate address
705    to be legitimate.  If we find one, return the new, valid address.
706    This macro is used in only one place: `memory_address' in explow.c.  */
707 #define LEGITIMIZE_ADDRESS(X, OLDX, MODE, WIN)                          \
708 {                                                                       \
709   (X) = legitimize_address (X, OLDX, MODE);                             \
710   if (memory_address_p (MODE, X))                                       \
711     goto WIN;                                                           \
712 }
713
714 /* Try a machine-dependent way of reloading an illegitimate address
715    operand.  If we find one, push the reload and jump to WIN.  This
716    macro is used in only one place: `find_reloads_address' in reload.c.  */
717 #define LEGITIMIZE_RELOAD_ADDRESS(AD, MODE, OPNUM, TYPE, IND, WIN)      \
718 do {                                                                    \
719   rtx new = legitimize_reload_address (AD, MODE, OPNUM, (int)(TYPE));   \
720   if (new)                                                              \
721     {                                                                   \
722       (AD) = new;                                                       \
723       goto WIN;                                                         \
724     }                                                                   \
725 } while (0)
726
727 /* Nonzero if the constant value X is a legitimate general operand.
728    It is given that X satisfies CONSTANT_P or is a CONST_DOUBLE.  */
729 #define LEGITIMATE_CONSTANT_P(X) \
730      legitimate_constant_p (X)
731
732 /* Helper macro for s390.c and s390.md to check for symbolic constants.  */
733 #define SYMBOLIC_CONST(X)       \
734 (GET_CODE (X) == SYMBOL_REF                                             \
735  || GET_CODE (X) == LABEL_REF                                           \
736  || (GET_CODE (X) == CONST && symbolic_reference_mentioned_p (X)))
737
738 #define TLS_SYMBOLIC_CONST(X)   \
739 ((GET_CODE (X) == SYMBOL_REF && tls_symbolic_operand (X))       \
740  || (GET_CODE (X) == CONST && tls_symbolic_reference_mentioned_p (X)))
741
742
743 /* Condition codes.  */
744
745 /* Given a comparison code (EQ, NE, etc.) and the first operand of a COMPARE,
746    return the mode to be used for the comparison.  */
747 #define SELECT_CC_MODE(OP, X, Y) s390_select_ccmode ((OP), (X), (Y))
748
749 /* Canonicalize a comparison from one we don't have to one we do have.  */
750 #define CANONICALIZE_COMPARISON(CODE, OP0, OP1) \
751   s390_canonicalize_comparison (&(CODE), &(OP0), &(OP1))
752
753 /* Define the information needed to generate branch and scc insns.  This is
754    stored from the compare operation.  Note that we can't use "rtx" here
755    since it hasn't been defined!  */
756 extern struct rtx_def *s390_compare_op0, *s390_compare_op1, *s390_compare_emitted;
757
758
759 /* Relative costs of operations.  */
760
761 /* On s390, copy between fprs and gprs is expensive.  */
762 #define REGISTER_MOVE_COST(MODE, CLASS1, CLASS2)                        \
763   ((   (   reg_classes_intersect_p ((CLASS1), GENERAL_REGS)             \
764         && reg_classes_intersect_p ((CLASS2), FP_REGS))                 \
765     || (   reg_classes_intersect_p ((CLASS1), FP_REGS)                  \
766         && reg_classes_intersect_p ((CLASS2), GENERAL_REGS))) ? 10 : 1)
767
768 /* A C expression for the cost of moving data of mode M between a
769    register and memory.  A value of 2 is the default; this cost is
770    relative to those in `REGISTER_MOVE_COST'.  */
771 #define MEMORY_MOVE_COST(M, C, I) 1
772
773 /* A C expression for the cost of a branch instruction.  A value of 1
774    is the default; other values are interpreted relative to that.  */
775 #define BRANCH_COST 1
776
777 /* Nonzero if access to memory by bytes is slow and undesirable.  */
778 #define SLOW_BYTE_ACCESS 1
779
780 /* An integer expression for the size in bits of the largest integer machine
781    mode that should actually be used.  We allow pairs of registers.  */ 
782 #define MAX_FIXED_MODE_SIZE GET_MODE_BITSIZE (TARGET_64BIT ? TImode : DImode)
783
784 /* The maximum number of bytes that a single instruction can move quickly
785    between memory and registers or between two memory locations.  */
786 #define MOVE_MAX (TARGET_64BIT ? 16 : 8)
787 #define MOVE_MAX_PIECES (TARGET_64BIT ? 8 : 4)
788 #define MAX_MOVE_MAX 16
789
790 /* Determine whether to use move_by_pieces or block move insn.  */
791 #define MOVE_BY_PIECES_P(SIZE, ALIGN)           \
792   ( (SIZE) == 1 || (SIZE) == 2 || (SIZE) == 4   \
793     || (TARGET_64BIT && (SIZE) == 8) )
794
795 /* Determine whether to use clear_by_pieces or block clear insn.  */
796 #define CLEAR_BY_PIECES_P(SIZE, ALIGN)          \
797   ( (SIZE) == 1 || (SIZE) == 2 || (SIZE) == 4   \
798     || (TARGET_64BIT && (SIZE) == 8) )
799
800 /* This macro is used to determine whether store_by_pieces should be
801    called to "memcpy" storage when the source is a constant string.  */
802 #define STORE_BY_PIECES_P(SIZE, ALIGN) MOVE_BY_PIECES_P (SIZE, ALIGN)
803
804 /* Likewise to decide whether to "memset" storage with byte values
805    other than zero.  */
806 #define SET_BY_PIECES_P(SIZE, ALIGN) STORE_BY_PIECES_P (SIZE, ALIGN)
807
808 /* Don't perform CSE on function addresses.  */
809 #define NO_FUNCTION_CSE
810
811
812 /* Sections.  */
813
814 /* Output before read-only data.  */
815 #define TEXT_SECTION_ASM_OP ".text"
816
817 /* Output before writable (initialized) data.  */
818 #define DATA_SECTION_ASM_OP ".data"
819
820 /* Output before writable (uninitialized) data.  */
821 #define BSS_SECTION_ASM_OP ".bss"
822
823 /* S/390 constant pool breaks the devices in crtstuff.c to control section
824    in where code resides.  We have to write it as asm code.  */
825 #ifndef __s390x__
826 #define CRT_CALL_STATIC_FUNCTION(SECTION_OP, FUNC) \
827     asm (SECTION_OP "\n\
828         bras\t%r2,1f\n\
829 0:      .long\t" USER_LABEL_PREFIX #FUNC " - 0b\n\
830 1:      l\t%r3,0(%r2)\n\
831         bas\t%r14,0(%r3,%r2)\n\
832         .previous");
833 #endif
834
835
836 /* Position independent code.  */
837
838 extern int flag_pic;
839
840 #define PIC_OFFSET_TABLE_REGNUM (flag_pic ? 12 : INVALID_REGNUM)
841
842 #define LEGITIMATE_PIC_OPERAND_P(X)  legitimate_pic_operand_p (X)
843
844
845 /* Assembler file format.  */
846
847 /* Character to start a comment.  */
848 #define ASM_COMMENT_START "#"
849
850 /* Declare an uninitialized external linkage data object.  */
851 #define ASM_OUTPUT_ALIGNED_BSS(FILE, DECL, NAME, SIZE, ALIGN) \
852   asm_output_aligned_bss (FILE, DECL, NAME, SIZE, ALIGN)
853
854 /* Globalizing directive for a label.  */
855 #define GLOBAL_ASM_OP ".globl "
856
857 /* Advance the location counter to a multiple of 2**LOG bytes.  */
858 #define ASM_OUTPUT_ALIGN(FILE, LOG) \
859   if ((LOG)) fprintf ((FILE), "\t.align\t%d\n", 1 << (LOG))
860
861 /* Advance the location counter by SIZE bytes.  */
862 #define ASM_OUTPUT_SKIP(FILE, SIZE) \
863   fprintf ((FILE), "\t.set\t.,.+"HOST_WIDE_INT_PRINT_UNSIGNED"\n", (SIZE))
864
865 /* The LOCAL_LABEL_PREFIX variable is used by dbxelf.h.  */
866 #define LOCAL_LABEL_PREFIX "."
867
868 /* How to refer to registers in assembler output.  This sequence is
869    indexed by compiler's hard-register-number (see above).  */
870 #define REGISTER_NAMES                                                  \
871 { "%r0",  "%r1",  "%r2",  "%r3",  "%r4",  "%r5",  "%r6",  "%r7",        \
872   "%r8",  "%r9",  "%r10", "%r11", "%r12", "%r13", "%r14", "%r15",       \
873   "%f0",  "%f2",  "%f4",  "%f6",  "%f1",  "%f3",  "%f5",  "%f7",        \
874   "%f8",  "%f10", "%f12", "%f14", "%f9",  "%f11", "%f13", "%f15",       \
875   "%ap",  "%cc",  "%fp",  "%rp",  "%a0",  "%a1"                         \
876 }
877
878 /* Print operand X (an rtx) in assembler syntax to file FILE.  */
879 #define PRINT_OPERAND(FILE, X, CODE) print_operand (FILE, X, CODE)
880 #define PRINT_OPERAND_ADDRESS(FILE, ADDR) print_operand_address (FILE, ADDR)
881
882 /* Output machine-dependent UNSPECs in address constants.  */
883 #define OUTPUT_ADDR_CONST_EXTRA(FILE, X, FAIL)          \
884 do {                                                    \
885   if (!s390_output_addr_const_extra (FILE, (X)))        \
886     goto FAIL;                                          \
887 } while (0);
888
889 /* Output an element of a case-vector that is absolute.  */
890 #define ASM_OUTPUT_ADDR_VEC_ELT(FILE, VALUE)                            \
891 do {                                                                    \
892   char buf[32];                                                         \
893   fputs (integer_asm_op (UNITS_PER_WORD, TRUE), (FILE));                \
894   ASM_GENERATE_INTERNAL_LABEL (buf, "L", (VALUE));                      \
895   assemble_name ((FILE), buf);                                          \
896   fputc ('\n', (FILE));                                                 \
897 } while (0)
898
899 /* Output an element of a case-vector that is relative.  */
900 #define ASM_OUTPUT_ADDR_DIFF_ELT(FILE, BODY, VALUE, REL)                \
901 do {                                                                    \
902   char buf[32];                                                         \
903   fputs (integer_asm_op (UNITS_PER_WORD, TRUE), (FILE));                \
904   ASM_GENERATE_INTERNAL_LABEL (buf, "L", (VALUE));                      \
905   assemble_name ((FILE), buf);                                          \
906   fputc ('-', (FILE));                                                  \
907   ASM_GENERATE_INTERNAL_LABEL (buf, "L", (REL));                        \
908   assemble_name ((FILE), buf);                                          \
909   fputc ('\n', (FILE));                                                 \
910 } while (0)
911
912
913 /* Miscellaneous parameters.  */
914
915 /* Specify the machine mode that this machine uses for the index in the
916    tablejump instruction.  */
917 #define CASE_VECTOR_MODE (TARGET_64BIT ? DImode : SImode)
918
919 /* Value is 1 if truncating an integer of INPREC bits to OUTPREC bits
920    is done just by pretending it is already truncated.  */
921 #define TRULY_NOOP_TRUNCATION(OUTPREC, INPREC)  1
922
923 /* Specify the machine mode that pointers have.
924    After generation of rtl, the compiler makes no further distinction
925    between pointers and any other objects of this machine mode.  */
926 #define Pmode ((enum machine_mode) (TARGET_64BIT ? DImode : SImode))
927
928 /* This is -1 for "pointer mode" extend.  See ptr_extend in s390.md.  */
929 #define POINTERS_EXTEND_UNSIGNED -1
930
931 /* A function address in a call instruction is a byte address (for
932    indexing purposes) so give the MEM rtx a byte's mode.  */
933 #define FUNCTION_MODE QImode
934
935 /* Specify the value which is used when clz operand is zero.  */
936 #define CLZ_DEFINED_VALUE_AT_ZERO(MODE, VALUE) ((VALUE) = 64, 1)
937
938 /* Machine-specific symbol_ref flags.  */
939 #define SYMBOL_FLAG_ALIGN1      (SYMBOL_FLAG_MACH_DEP << 0)
940
941 /* Check whether integer displacement is in range.  */
942 #define DISP_IN_RANGE(d) \
943   (TARGET_LONG_DISPLACEMENT? ((d) >= -524288 && (d) <= 524287) \
944                            : ((d) >= 0 && (d) <= 4095))
945
946 #endif