]>
Commit | Line | Data |
---|---|---|
e075ae69 | 1 | /* Subroutines used for code generation on IA-32. |
4592bdcb JL |
2 | Copyright (C) 1988, 1992, 1994, 1995, 1996, 1997, 1998, 1999, 2000 |
3 | Free Software Foundation, Inc. | |
2a2ab3f9 JVA |
4 | |
5 | This file is part of GNU CC. | |
6 | ||
7 | GNU CC is free software; you can redistribute it and/or modify | |
8 | it under the terms of the GNU General Public License as published by | |
9 | the Free Software Foundation; either version 2, or (at your option) | |
10 | any later version. | |
11 | ||
12 | GNU CC is distributed in the hope that it will be useful, | |
13 | but WITHOUT ANY WARRANTY; without even the implied warranty of | |
14 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
15 | GNU General Public License for more details. | |
16 | ||
17 | You should have received a copy of the GNU General Public License | |
18 | along with GNU CC; see the file COPYING. If not, write to | |
97aadbb9 | 19 | the Free Software Foundation, 59 Temple Place - Suite 330, |
32b5b1aa | 20 | Boston, MA 02111-1307, USA. */ |
2a2ab3f9 | 21 | |
0b6b2900 | 22 | #include <setjmp.h> |
2a2ab3f9 | 23 | #include "config.h" |
bb5177ac | 24 | #include "system.h" |
2a2ab3f9 | 25 | #include "rtl.h" |
6baf1cc8 BS |
26 | #include "tree.h" |
27 | #include "tm_p.h" | |
2a2ab3f9 JVA |
28 | #include "regs.h" |
29 | #include "hard-reg-set.h" | |
30 | #include "real.h" | |
31 | #include "insn-config.h" | |
32 | #include "conditions.h" | |
33 | #include "insn-flags.h" | |
34 | #include "output.h" | |
35 | #include "insn-attr.h" | |
2a2ab3f9 | 36 | #include "flags.h" |
a8ffcc81 | 37 | #include "except.h" |
ecbc4695 | 38 | #include "function.h" |
00c79232 | 39 | #include "recog.h" |
ced8dd8c | 40 | #include "expr.h" |
f103890b | 41 | #include "toplev.h" |
e075ae69 | 42 | #include "basic-block.h" |
1526a060 | 43 | #include "ggc.h" |
2a2ab3f9 | 44 | |
997de79c JVA |
45 | #ifdef EXTRA_CONSTRAINT |
46 | /* If EXTRA_CONSTRAINT is defined, then the 'S' | |
47 | constraint in REG_CLASS_FROM_LETTER will no longer work, and various | |
48 | asm statements that need 'S' for class SIREG will break. */ | |
ad5a6adc RS |
49 | error EXTRA_CONSTRAINT conflicts with S constraint letter |
50 | /* The previous line used to be #error, but some compilers barf | |
51 | even if the conditional was untrue. */ | |
997de79c JVA |
52 | #endif |
53 | ||
8dfe5673 RK |
54 | #ifndef CHECK_STACK_LIMIT |
55 | #define CHECK_STACK_LIMIT -1 | |
56 | #endif | |
57 | ||
32b5b1aa SC |
58 | /* Processor costs (relative to an add) */ |
59 | struct processor_costs i386_cost = { /* 386 specific costs */ | |
e9a25f70 | 60 | 1, /* cost of an add instruction */ |
32b5b1aa SC |
61 | 1, /* cost of a lea instruction */ |
62 | 3, /* variable shift costs */ | |
63 | 2, /* constant shift costs */ | |
64 | 6, /* cost of starting a multiply */ | |
65 | 1, /* cost of multiply per each bit set */ | |
e075ae69 | 66 | 23, /* cost of a divide/mod */ |
96e7ae40 | 67 | 15, /* "large" insn */ |
e2e52e1b | 68 | 3, /* MOVE_RATIO */ |
7c6b971d | 69 | 4, /* cost for loading QImode using movzbl */ |
96e7ae40 JH |
70 | {2, 4, 2}, /* cost of loading integer registers |
71 | in QImode, HImode and SImode. | |
72 | Relative to reg-reg move (2). */ | |
73 | {2, 4, 2}, /* cost of storing integer registers */ | |
74 | 2, /* cost of reg,reg fld/fst */ | |
75 | {8, 8, 8}, /* cost of loading fp registers | |
76 | in SFmode, DFmode and XFmode */ | |
77 | {8, 8, 8} /* cost of loading integer registers */ | |
32b5b1aa SC |
78 | }; |
79 | ||
80 | struct processor_costs i486_cost = { /* 486 specific costs */ | |
81 | 1, /* cost of an add instruction */ | |
82 | 1, /* cost of a lea instruction */ | |
83 | 3, /* variable shift costs */ | |
84 | 2, /* constant shift costs */ | |
85 | 12, /* cost of starting a multiply */ | |
86 | 1, /* cost of multiply per each bit set */ | |
e075ae69 | 87 | 40, /* cost of a divide/mod */ |
96e7ae40 | 88 | 15, /* "large" insn */ |
e2e52e1b | 89 | 3, /* MOVE_RATIO */ |
7c6b971d | 90 | 4, /* cost for loading QImode using movzbl */ |
96e7ae40 JH |
91 | {2, 4, 2}, /* cost of loading integer registers |
92 | in QImode, HImode and SImode. | |
93 | Relative to reg-reg move (2). */ | |
94 | {2, 4, 2}, /* cost of storing integer registers */ | |
95 | 2, /* cost of reg,reg fld/fst */ | |
96 | {8, 8, 8}, /* cost of loading fp registers | |
97 | in SFmode, DFmode and XFmode */ | |
98 | {8, 8, 8} /* cost of loading integer registers */ | |
32b5b1aa SC |
99 | }; |
100 | ||
e5cb57e8 | 101 | struct processor_costs pentium_cost = { |
32b5b1aa SC |
102 | 1, /* cost of an add instruction */ |
103 | 1, /* cost of a lea instruction */ | |
856b07a1 | 104 | 4, /* variable shift costs */ |
e5cb57e8 | 105 | 1, /* constant shift costs */ |
856b07a1 SC |
106 | 11, /* cost of starting a multiply */ |
107 | 0, /* cost of multiply per each bit set */ | |
e075ae69 | 108 | 25, /* cost of a divide/mod */ |
96e7ae40 | 109 | 8, /* "large" insn */ |
e2e52e1b | 110 | 6, /* MOVE_RATIO */ |
7c6b971d | 111 | 6, /* cost for loading QImode using movzbl */ |
96e7ae40 JH |
112 | {2, 4, 2}, /* cost of loading integer registers |
113 | in QImode, HImode and SImode. | |
114 | Relative to reg-reg move (2). */ | |
115 | {2, 4, 2}, /* cost of storing integer registers */ | |
116 | 2, /* cost of reg,reg fld/fst */ | |
117 | {2, 2, 6}, /* cost of loading fp registers | |
118 | in SFmode, DFmode and XFmode */ | |
119 | {4, 4, 6} /* cost of loading integer registers */ | |
32b5b1aa SC |
120 | }; |
121 | ||
856b07a1 SC |
122 | struct processor_costs pentiumpro_cost = { |
123 | 1, /* cost of an add instruction */ | |
124 | 1, /* cost of a lea instruction */ | |
e075ae69 | 125 | 1, /* variable shift costs */ |
856b07a1 | 126 | 1, /* constant shift costs */ |
e075ae69 | 127 | 1, /* cost of starting a multiply */ |
856b07a1 | 128 | 0, /* cost of multiply per each bit set */ |
e075ae69 | 129 | 17, /* cost of a divide/mod */ |
96e7ae40 | 130 | 8, /* "large" insn */ |
e2e52e1b | 131 | 6, /* MOVE_RATIO */ |
7c6b971d | 132 | 2, /* cost for loading QImode using movzbl */ |
96e7ae40 JH |
133 | {4, 4, 4}, /* cost of loading integer registers |
134 | in QImode, HImode and SImode. | |
135 | Relative to reg-reg move (2). */ | |
136 | {2, 2, 2}, /* cost of storing integer registers */ | |
137 | 2, /* cost of reg,reg fld/fst */ | |
138 | {2, 2, 6}, /* cost of loading fp registers | |
139 | in SFmode, DFmode and XFmode */ | |
140 | {4, 4, 6} /* cost of loading integer registers */ | |
856b07a1 SC |
141 | }; |
142 | ||
a269a03c JC |
143 | struct processor_costs k6_cost = { |
144 | 1, /* cost of an add instruction */ | |
e075ae69 | 145 | 2, /* cost of a lea instruction */ |
a269a03c JC |
146 | 1, /* variable shift costs */ |
147 | 1, /* constant shift costs */ | |
73fe76e4 | 148 | 3, /* cost of starting a multiply */ |
a269a03c | 149 | 0, /* cost of multiply per each bit set */ |
e075ae69 | 150 | 18, /* cost of a divide/mod */ |
96e7ae40 | 151 | 8, /* "large" insn */ |
e2e52e1b | 152 | 4, /* MOVE_RATIO */ |
7c6b971d | 153 | 3, /* cost for loading QImode using movzbl */ |
96e7ae40 JH |
154 | {4, 5, 4}, /* cost of loading integer registers |
155 | in QImode, HImode and SImode. | |
156 | Relative to reg-reg move (2). */ | |
157 | {2, 3, 2}, /* cost of storing integer registers */ | |
158 | 4, /* cost of reg,reg fld/fst */ | |
159 | {6, 6, 6}, /* cost of loading fp registers | |
160 | in SFmode, DFmode and XFmode */ | |
161 | {4, 4, 4} /* cost of loading integer registers */ | |
a269a03c JC |
162 | }; |
163 | ||
309ada50 JH |
164 | struct processor_costs athlon_cost = { |
165 | 1, /* cost of an add instruction */ | |
166 | 1, /* cost of a lea instruction */ | |
167 | 1, /* variable shift costs */ | |
168 | 1, /* constant shift costs */ | |
169 | 5, /* cost of starting a multiply */ | |
170 | 0, /* cost of multiply per each bit set */ | |
171 | 19, /* cost of a divide/mod */ | |
172 | 8, /* "large" insn */ | |
e2e52e1b | 173 | 9, /* MOVE_RATIO */ |
309ada50 JH |
174 | 4, /* cost for loading QImode using movzbl */ |
175 | {4, 5, 4}, /* cost of loading integer registers | |
176 | in QImode, HImode and SImode. | |
177 | Relative to reg-reg move (2). */ | |
178 | {2, 3, 2}, /* cost of storing integer registers */ | |
179 | 4, /* cost of reg,reg fld/fst */ | |
180 | {6, 6, 6}, /* cost of loading fp registers | |
181 | in SFmode, DFmode and XFmode */ | |
182 | {4, 4, 4} /* cost of loading integer registers */ | |
183 | }; | |
184 | ||
32b5b1aa SC |
185 | struct processor_costs *ix86_cost = &pentium_cost; |
186 | ||
a269a03c JC |
187 | /* Processor feature/optimization bitmasks. */ |
188 | #define m_386 (1<<PROCESSOR_I386) | |
189 | #define m_486 (1<<PROCESSOR_I486) | |
190 | #define m_PENT (1<<PROCESSOR_PENTIUM) | |
191 | #define m_PPRO (1<<PROCESSOR_PENTIUMPRO) | |
192 | #define m_K6 (1<<PROCESSOR_K6) | |
309ada50 | 193 | #define m_ATHLON (1<<PROCESSOR_ATHLON) |
a269a03c | 194 | |
309ada50 JH |
195 | const int x86_use_leave = m_386 | m_K6 | m_ATHLON; |
196 | const int x86_push_memory = m_386 | m_K6 | m_ATHLON; | |
a269a03c | 197 | const int x86_zero_extend_with_and = m_486 | m_PENT; |
309ada50 | 198 | const int x86_movx = m_ATHLON /* m_386 | m_PPRO | m_K6 */; |
e075ae69 | 199 | const int x86_double_with_add = ~m_386; |
a269a03c | 200 | const int x86_use_bit_test = m_386; |
e2e52e1b | 201 | const int x86_unroll_strlen = m_486 | m_PENT | m_PPRO | m_ATHLON | m_K6; |
a269a03c JC |
202 | const int x86_use_q_reg = m_PENT | m_PPRO | m_K6; |
203 | const int x86_use_any_reg = m_486; | |
309ada50 JH |
204 | const int x86_cmove = m_PPRO | m_ATHLON; |
205 | const int x86_deep_branch = m_PPRO | m_K6 | m_ATHLON; | |
206 | const int x86_use_sahf = m_PPRO | m_K6 | m_ATHLON; | |
e075ae69 RH |
207 | const int x86_partial_reg_stall = m_PPRO; |
208 | const int x86_use_loop = m_K6; | |
309ada50 | 209 | const int x86_use_fiop = ~(m_PPRO | m_ATHLON | m_PENT); |
e075ae69 RH |
210 | const int x86_use_mov0 = m_K6; |
211 | const int x86_use_cltd = ~(m_PENT | m_K6); | |
212 | const int x86_read_modify_write = ~m_PENT; | |
213 | const int x86_read_modify = ~(m_PENT | m_PPRO); | |
214 | const int x86_split_long_moves = m_PPRO; | |
e9e80858 | 215 | const int x86_promote_QImode = m_K6 | m_PENT | m_386 | m_486; |
f90800f8 | 216 | const int x86_single_stringop = m_386; |
a269a03c | 217 | |
564d80f4 | 218 | #define AT_BP(mode) (gen_rtx_MEM ((mode), hard_frame_pointer_rtx)) |
2a2ab3f9 | 219 | |
e075ae69 RH |
220 | const char * const hi_reg_name[] = HI_REGISTER_NAMES; |
221 | const char * const qi_reg_name[] = QI_REGISTER_NAMES; | |
222 | const char * const qi_high_reg_name[] = QI_HIGH_REGISTER_NAMES; | |
4c0d89b5 RS |
223 | |
224 | /* Array of the smallest class containing reg number REGNO, indexed by | |
225 | REGNO. Used by REGNO_REG_CLASS in i386.h. */ | |
226 | ||
e075ae69 | 227 | enum reg_class const regclass_map[FIRST_PSEUDO_REGISTER] = |
4c0d89b5 RS |
228 | { |
229 | /* ax, dx, cx, bx */ | |
ab408a86 | 230 | AREG, DREG, CREG, BREG, |
4c0d89b5 | 231 | /* si, di, bp, sp */ |
e075ae69 | 232 | SIREG, DIREG, NON_Q_REGS, NON_Q_REGS, |
4c0d89b5 RS |
233 | /* FP registers */ |
234 | FP_TOP_REG, FP_SECOND_REG, FLOAT_REGS, FLOAT_REGS, | |
79325812 | 235 | FLOAT_REGS, FLOAT_REGS, FLOAT_REGS, FLOAT_REGS, |
4c0d89b5 | 236 | /* arg pointer */ |
83774849 | 237 | NON_Q_REGS, |
564d80f4 JH |
238 | /* flags, fpsr, dirflag, frame */ |
239 | NO_REGS, NO_REGS, NO_REGS, NON_Q_REGS | |
4c0d89b5 | 240 | }; |
c572e5ba | 241 | |
83774849 RH |
242 | /* The "default" register map. */ |
243 | ||
244 | int const dbx_register_map[FIRST_PSEUDO_REGISTER] = | |
245 | { | |
246 | 0, 2, 1, 3, 6, 7, 4, 5, /* general regs */ | |
247 | 12, 13, 14, 15, 16, 17, 18, 19, /* fp regs */ | |
248 | -1, -1, -1, -1, /* arg, flags, fpsr, dir */ | |
249 | }; | |
250 | ||
251 | /* Define the register numbers to be used in Dwarf debugging information. | |
252 | The SVR4 reference port C compiler uses the following register numbers | |
253 | in its Dwarf output code: | |
254 | 0 for %eax (gcc regno = 0) | |
255 | 1 for %ecx (gcc regno = 2) | |
256 | 2 for %edx (gcc regno = 1) | |
257 | 3 for %ebx (gcc regno = 3) | |
258 | 4 for %esp (gcc regno = 7) | |
259 | 5 for %ebp (gcc regno = 6) | |
260 | 6 for %esi (gcc regno = 4) | |
261 | 7 for %edi (gcc regno = 5) | |
262 | The following three DWARF register numbers are never generated by | |
263 | the SVR4 C compiler or by the GNU compilers, but SDB on x86/svr4 | |
264 | believes these numbers have these meanings. | |
265 | 8 for %eip (no gcc equivalent) | |
266 | 9 for %eflags (gcc regno = 17) | |
267 | 10 for %trapno (no gcc equivalent) | |
268 | It is not at all clear how we should number the FP stack registers | |
269 | for the x86 architecture. If the version of SDB on x86/svr4 were | |
270 | a bit less brain dead with respect to floating-point then we would | |
271 | have a precedent to follow with respect to DWARF register numbers | |
272 | for x86 FP registers, but the SDB on x86/svr4 is so completely | |
273 | broken with respect to FP registers that it is hardly worth thinking | |
274 | of it as something to strive for compatibility with. | |
275 | The version of x86/svr4 SDB I have at the moment does (partially) | |
276 | seem to believe that DWARF register number 11 is associated with | |
277 | the x86 register %st(0), but that's about all. Higher DWARF | |
278 | register numbers don't seem to be associated with anything in | |
279 | particular, and even for DWARF regno 11, SDB only seems to under- | |
280 | stand that it should say that a variable lives in %st(0) (when | |
281 | asked via an `=' command) if we said it was in DWARF regno 11, | |
282 | but SDB still prints garbage when asked for the value of the | |
283 | variable in question (via a `/' command). | |
284 | (Also note that the labels SDB prints for various FP stack regs | |
285 | when doing an `x' command are all wrong.) | |
286 | Note that these problems generally don't affect the native SVR4 | |
287 | C compiler because it doesn't allow the use of -O with -g and | |
288 | because when it is *not* optimizing, it allocates a memory | |
289 | location for each floating-point variable, and the memory | |
290 | location is what gets described in the DWARF AT_location | |
291 | attribute for the variable in question. | |
292 | Regardless of the severe mental illness of the x86/svr4 SDB, we | |
293 | do something sensible here and we use the following DWARF | |
294 | register numbers. Note that these are all stack-top-relative | |
295 | numbers. | |
296 | 11 for %st(0) (gcc regno = 8) | |
297 | 12 for %st(1) (gcc regno = 9) | |
298 | 13 for %st(2) (gcc regno = 10) | |
299 | 14 for %st(3) (gcc regno = 11) | |
300 | 15 for %st(4) (gcc regno = 12) | |
301 | 16 for %st(5) (gcc regno = 13) | |
302 | 17 for %st(6) (gcc regno = 14) | |
303 | 18 for %st(7) (gcc regno = 15) | |
304 | */ | |
305 | int const svr4_dbx_register_map[FIRST_PSEUDO_REGISTER] = | |
306 | { | |
307 | 0, 2, 1, 3, 6, 7, 5, 4, /* general regs */ | |
308 | 11, 12, 13, 14, 15, 16, 17, 18, /* fp regs */ | |
309 | -1, 9, -1, -1, /* arg, flags, fpsr, dir */ | |
310 | }; | |
311 | ||
312 | ||
313 | ||
c572e5ba JVA |
314 | /* Test and compare insns in i386.md store the information needed to |
315 | generate branch and scc insns here. */ | |
316 | ||
e075ae69 RH |
317 | struct rtx_def *ix86_compare_op0 = NULL_RTX; |
318 | struct rtx_def *ix86_compare_op1 = NULL_RTX; | |
f5316dfe | 319 | |
36edd3cc BS |
320 | #define MAX_386_STACK_LOCALS 2 |
321 | ||
322 | /* Define the structure for the machine field in struct function. */ | |
323 | struct machine_function | |
324 | { | |
325 | rtx stack_locals[(int) MAX_MACHINE_MODE][MAX_386_STACK_LOCALS]; | |
326 | }; | |
327 | ||
01d939e8 | 328 | #define ix86_stack_locals (cfun->machine->stack_locals) |
36edd3cc | 329 | |
c8c5cb99 | 330 | /* which cpu are we scheduling for */ |
e42ea7f9 | 331 | enum processor_type ix86_cpu; |
c8c5cb99 SC |
332 | |
333 | /* which instruction set architecture to use. */ | |
c942177e | 334 | int ix86_arch; |
c8c5cb99 SC |
335 | |
336 | /* Strings to hold which cpu and instruction set architecture to use. */ | |
9c23aa47 ZW |
337 | const char *ix86_cpu_string; /* for -mcpu=<xxx> */ |
338 | const char *ix86_arch_string; /* for -march=<xxx> */ | |
c8c5cb99 | 339 | |
f5316dfe | 340 | /* Register allocation order */ |
e075ae69 | 341 | const char *ix86_reg_alloc_order; |
f5316dfe MM |
342 | static char regs_allocated[FIRST_PSEUDO_REGISTER]; |
343 | ||
b08de47e | 344 | /* # of registers to use to pass arguments. */ |
e075ae69 | 345 | const char *ix86_regparm_string; |
e9a25f70 | 346 | |
e075ae69 RH |
347 | /* ix86_regparm_string as a number */ |
348 | int ix86_regparm; | |
e9a25f70 JL |
349 | |
350 | /* Alignment to use for loops and jumps: */ | |
351 | ||
352 | /* Power of two alignment for loops. */ | |
e075ae69 | 353 | const char *ix86_align_loops_string; |
e9a25f70 JL |
354 | |
355 | /* Power of two alignment for non-loop jumps. */ | |
e075ae69 | 356 | const char *ix86_align_jumps_string; |
e9a25f70 | 357 | |
3af4bd89 | 358 | /* Power of two alignment for stack boundary in bytes. */ |
e075ae69 | 359 | const char *ix86_preferred_stack_boundary_string; |
3af4bd89 JH |
360 | |
361 | /* Preferred alignment for stack boundary in bits. */ | |
e075ae69 | 362 | int ix86_preferred_stack_boundary; |
3af4bd89 | 363 | |
e9a25f70 | 364 | /* Values 1-5: see jump.c */ |
e075ae69 RH |
365 | int ix86_branch_cost; |
366 | const char *ix86_branch_cost_string; | |
e9a25f70 JL |
367 | |
368 | /* Power of two alignment for functions. */ | |
e075ae69 RH |
369 | int ix86_align_funcs; |
370 | const char *ix86_align_funcs_string; | |
b08de47e | 371 | |
e9a25f70 | 372 | /* Power of two alignment for loops. */ |
e075ae69 | 373 | int ix86_align_loops; |
b08de47e | 374 | |
e9a25f70 | 375 | /* Power of two alignment for non-loop jumps. */ |
e075ae69 RH |
376 | int ix86_align_jumps; |
377 | \f | |
f6da8bc3 KG |
378 | static void output_pic_addr_const PARAMS ((FILE *, rtx, int)); |
379 | static void put_condition_code PARAMS ((enum rtx_code, enum machine_mode, | |
e075ae69 | 380 | int, int, FILE *)); |
f6da8bc3 KG |
381 | static enum rtx_code unsigned_comparison PARAMS ((enum rtx_code code)); |
382 | static rtx ix86_expand_int_compare PARAMS ((enum rtx_code, rtx, rtx)); | |
383 | static rtx ix86_expand_fp_compare PARAMS ((enum rtx_code, rtx, rtx, int)); | |
384 | static rtx ix86_expand_compare PARAMS ((enum rtx_code, int)); | |
385 | static rtx gen_push PARAMS ((rtx)); | |
386 | static int memory_address_length PARAMS ((rtx addr)); | |
387 | static int ix86_flags_dependant PARAMS ((rtx, rtx, enum attr_type)); | |
388 | static int ix86_agi_dependant PARAMS ((rtx, rtx, enum attr_type)); | |
389 | static int ix86_safe_length PARAMS ((rtx)); | |
390 | static enum attr_memory ix86_safe_memory PARAMS ((rtx)); | |
391 | static enum attr_pent_pair ix86_safe_pent_pair PARAMS ((rtx)); | |
392 | static enum attr_ppro_uops ix86_safe_ppro_uops PARAMS ((rtx)); | |
393 | static void ix86_dump_ppro_packet PARAMS ((FILE *)); | |
394 | static void ix86_reorder_insn PARAMS ((rtx *, rtx *)); | |
395 | static rtx * ix86_pent_find_pair PARAMS ((rtx *, rtx *, enum attr_pent_pair, | |
e075ae69 | 396 | rtx)); |
f6da8bc3 KG |
397 | static void ix86_init_machine_status PARAMS ((struct function *)); |
398 | static void ix86_mark_machine_status PARAMS ((struct function *)); | |
399 | static void ix86_split_to_parts PARAMS ((rtx, rtx *, enum machine_mode)); | |
400 | static int ix86_safe_length_prefix PARAMS ((rtx)); | |
564d80f4 JH |
401 | static HOST_WIDE_INT ix86_compute_frame_size PARAMS((HOST_WIDE_INT, |
402 | int *, int *, int *)); | |
0903fcab JH |
403 | static int ix86_nsaved_regs PARAMS((void)); |
404 | static void ix86_emit_save_regs PARAMS((void)); | |
da2d1d3a | 405 | static void ix86_emit_restore_regs_using_mov PARAMS ((rtx, int)); |
0903fcab | 406 | static void ix86_emit_epilogue_esp_adjustment PARAMS((int)); |
c6991660 KG |
407 | static void ix86_sched_reorder_pentium PARAMS((rtx *, rtx *)); |
408 | static void ix86_sched_reorder_ppro PARAMS((rtx *, rtx *)); | |
e075ae69 RH |
409 | |
410 | struct ix86_address | |
411 | { | |
412 | rtx base, index, disp; | |
413 | HOST_WIDE_INT scale; | |
414 | }; | |
b08de47e | 415 | |
e075ae69 RH |
416 | static int ix86_decompose_address PARAMS ((rtx, struct ix86_address *)); |
417 | \f | |
f5316dfe MM |
418 | /* Sometimes certain combinations of command options do not make |
419 | sense on a particular target machine. You can define a macro | |
420 | `OVERRIDE_OPTIONS' to take account of this. This macro, if | |
421 | defined, is executed once just after all the command options have | |
422 | been parsed. | |
423 | ||
424 | Don't use this macro to turn on various extra optimizations for | |
425 | `-O'. That is what `OPTIMIZATION_OPTIONS' is for. */ | |
426 | ||
427 | void | |
428 | override_options () | |
429 | { | |
e075ae69 RH |
430 | /* Comes from final.c -- no real reason to change it. */ |
431 | #define MAX_CODE_ALIGN 16 | |
f5316dfe | 432 | |
c8c5cb99 SC |
433 | static struct ptt |
434 | { | |
e075ae69 RH |
435 | struct processor_costs *cost; /* Processor costs */ |
436 | int target_enable; /* Target flags to enable. */ | |
437 | int target_disable; /* Target flags to disable. */ | |
438 | int align_loop; /* Default alignments. */ | |
439 | int align_jump; | |
440 | int align_func; | |
441 | int branch_cost; | |
442 | } | |
443 | const processor_target_table[PROCESSOR_max] = | |
444 | { | |
445 | {&i386_cost, 0, 0, 2, 2, 2, 1}, | |
446 | {&i486_cost, 0, 0, 4, 4, 4, 1}, | |
447 | {&pentium_cost, 0, 0, -4, -4, -4, 1}, | |
448 | {&pentiumpro_cost, 0, 0, 4, -4, 4, 1}, | |
309ada50 JH |
449 | {&k6_cost, 0, 0, -5, -5, 4, 1}, |
450 | {&athlon_cost, 0, 0, 4, -4, 4, 1} | |
e075ae69 RH |
451 | }; |
452 | ||
453 | static struct pta | |
454 | { | |
69ddee61 | 455 | const char *name; /* processor name or nickname. */ |
e075ae69 RH |
456 | enum processor_type processor; |
457 | } | |
458 | const processor_alias_table[] = | |
459 | { | |
460 | {"i386", PROCESSOR_I386}, | |
461 | {"i486", PROCESSOR_I486}, | |
462 | {"i586", PROCESSOR_PENTIUM}, | |
463 | {"pentium", PROCESSOR_PENTIUM}, | |
464 | {"i686", PROCESSOR_PENTIUMPRO}, | |
465 | {"pentiumpro", PROCESSOR_PENTIUMPRO}, | |
e075ae69 | 466 | {"k6", PROCESSOR_K6}, |
309ada50 | 467 | {"athlon", PROCESSOR_ATHLON}, |
3af4bd89 | 468 | }; |
c8c5cb99 | 469 | |
e075ae69 | 470 | int const pta_size = sizeof(processor_alias_table)/sizeof(struct pta); |
c8c5cb99 | 471 | |
f5316dfe MM |
472 | #ifdef SUBTARGET_OVERRIDE_OPTIONS |
473 | SUBTARGET_OVERRIDE_OPTIONS; | |
474 | #endif | |
475 | ||
5a6ee819 | 476 | ix86_arch = PROCESSOR_I386; |
e075ae69 RH |
477 | ix86_cpu = (enum processor_type) TARGET_CPU_DEFAULT; |
478 | ||
479 | if (ix86_arch_string != 0) | |
480 | { | |
481 | int i; | |
482 | for (i = 0; i < pta_size; i++) | |
483 | if (! strcmp (ix86_arch_string, processor_alias_table[i].name)) | |
484 | { | |
485 | ix86_arch = processor_alias_table[i].processor; | |
486 | /* Default cpu tuning to the architecture. */ | |
487 | ix86_cpu = ix86_arch; | |
488 | break; | |
489 | } | |
490 | if (i == pta_size) | |
491 | error ("bad value (%s) for -march= switch", ix86_arch_string); | |
492 | } | |
493 | ||
494 | if (ix86_cpu_string != 0) | |
495 | { | |
496 | int i; | |
497 | for (i = 0; i < pta_size; i++) | |
498 | if (! strcmp (ix86_cpu_string, processor_alias_table[i].name)) | |
499 | { | |
500 | ix86_cpu = processor_alias_table[i].processor; | |
501 | break; | |
502 | } | |
503 | if (i == pta_size) | |
504 | error ("bad value (%s) for -mcpu= switch", ix86_cpu_string); | |
505 | } | |
506 | ||
507 | ix86_cost = processor_target_table[ix86_cpu].cost; | |
508 | target_flags |= processor_target_table[ix86_cpu].target_enable; | |
509 | target_flags &= ~processor_target_table[ix86_cpu].target_disable; | |
510 | ||
36edd3cc BS |
511 | /* Arrange to set up i386_stack_locals for all functions. */ |
512 | init_machine_status = ix86_init_machine_status; | |
1526a060 | 513 | mark_machine_status = ix86_mark_machine_status; |
36edd3cc | 514 | |
e9a25f70 | 515 | /* Validate registers in register allocation order. */ |
e075ae69 | 516 | if (ix86_reg_alloc_order) |
f5316dfe | 517 | { |
e075ae69 RH |
518 | int i, ch; |
519 | for (i = 0; (ch = ix86_reg_alloc_order[i]) != '\0'; i++) | |
f5316dfe | 520 | { |
00c79232 | 521 | int regno = 0; |
79325812 | 522 | |
f5316dfe MM |
523 | switch (ch) |
524 | { | |
525 | case 'a': regno = 0; break; | |
526 | case 'd': regno = 1; break; | |
527 | case 'c': regno = 2; break; | |
528 | case 'b': regno = 3; break; | |
529 | case 'S': regno = 4; break; | |
530 | case 'D': regno = 5; break; | |
531 | case 'B': regno = 6; break; | |
532 | ||
533 | default: fatal ("Register '%c' is unknown", ch); | |
534 | } | |
535 | ||
536 | if (regs_allocated[regno]) | |
e9a25f70 | 537 | fatal ("Register '%c' already specified in allocation order", ch); |
f5316dfe MM |
538 | |
539 | regs_allocated[regno] = 1; | |
540 | } | |
541 | } | |
b08de47e | 542 | |
e9a25f70 | 543 | /* Validate -mregparm= value. */ |
e075ae69 | 544 | if (ix86_regparm_string) |
b08de47e | 545 | { |
e075ae69 RH |
546 | ix86_regparm = atoi (ix86_regparm_string); |
547 | if (ix86_regparm < 0 || ix86_regparm > REGPARM_MAX) | |
e9a25f70 | 548 | fatal ("-mregparm=%d is not between 0 and %d", |
e075ae69 | 549 | ix86_regparm, REGPARM_MAX); |
b08de47e MM |
550 | } |
551 | ||
e9a25f70 | 552 | /* Validate -malign-loops= value, or provide default. */ |
e075ae69 RH |
553 | ix86_align_loops = processor_target_table[ix86_cpu].align_loop; |
554 | if (ix86_align_loops_string) | |
b08de47e | 555 | { |
e075ae69 RH |
556 | ix86_align_loops = atoi (ix86_align_loops_string); |
557 | if (ix86_align_loops < 0 || ix86_align_loops > MAX_CODE_ALIGN) | |
b08de47e | 558 | fatal ("-malign-loops=%d is not between 0 and %d", |
e075ae69 | 559 | ix86_align_loops, MAX_CODE_ALIGN); |
b08de47e | 560 | } |
3af4bd89 JH |
561 | |
562 | /* Validate -malign-jumps= value, or provide default. */ | |
e075ae69 RH |
563 | ix86_align_jumps = processor_target_table[ix86_cpu].align_jump; |
564 | if (ix86_align_jumps_string) | |
b08de47e | 565 | { |
e075ae69 RH |
566 | ix86_align_jumps = atoi (ix86_align_jumps_string); |
567 | if (ix86_align_jumps < 0 || ix86_align_jumps > MAX_CODE_ALIGN) | |
b08de47e | 568 | fatal ("-malign-jumps=%d is not between 0 and %d", |
e075ae69 | 569 | ix86_align_jumps, MAX_CODE_ALIGN); |
b08de47e | 570 | } |
b08de47e | 571 | |
e9a25f70 | 572 | /* Validate -malign-functions= value, or provide default. */ |
e075ae69 RH |
573 | ix86_align_funcs = processor_target_table[ix86_cpu].align_func; |
574 | if (ix86_align_funcs_string) | |
b08de47e | 575 | { |
e075ae69 RH |
576 | ix86_align_funcs = atoi (ix86_align_funcs_string); |
577 | if (ix86_align_funcs < 0 || ix86_align_funcs > MAX_CODE_ALIGN) | |
b08de47e | 578 | fatal ("-malign-functions=%d is not between 0 and %d", |
e075ae69 | 579 | ix86_align_funcs, MAX_CODE_ALIGN); |
b08de47e | 580 | } |
3af4bd89 | 581 | |
e4c0478d | 582 | /* Validate -mpreferred-stack-boundary= value, or provide default. |
3af4bd89 | 583 | The default of 128 bits is for Pentium III's SSE __m128. */ |
e075ae69 RH |
584 | ix86_preferred_stack_boundary = 128; |
585 | if (ix86_preferred_stack_boundary_string) | |
3af4bd89 | 586 | { |
e075ae69 | 587 | int i = atoi (ix86_preferred_stack_boundary_string); |
3af4bd89 | 588 | if (i < 2 || i > 31) |
e4c0478d | 589 | fatal ("-mpreferred-stack-boundary=%d is not between 2 and 31", i); |
e075ae69 | 590 | ix86_preferred_stack_boundary = (1 << i) * BITS_PER_UNIT; |
3af4bd89 | 591 | } |
77a989d1 | 592 | |
e9a25f70 | 593 | /* Validate -mbranch-cost= value, or provide default. */ |
e075ae69 RH |
594 | ix86_branch_cost = processor_target_table[ix86_cpu].branch_cost; |
595 | if (ix86_branch_cost_string) | |
804a8ee0 | 596 | { |
e075ae69 RH |
597 | ix86_branch_cost = atoi (ix86_branch_cost_string); |
598 | if (ix86_branch_cost < 0 || ix86_branch_cost > 5) | |
599 | fatal ("-mbranch-cost=%d is not between 0 and 5", | |
600 | ix86_branch_cost); | |
804a8ee0 | 601 | } |
804a8ee0 | 602 | |
e9a25f70 JL |
603 | /* Keep nonleaf frame pointers. */ |
604 | if (TARGET_OMIT_LEAF_FRAME_POINTER) | |
77a989d1 | 605 | flag_omit_frame_pointer = 1; |
e075ae69 RH |
606 | |
607 | /* If we're doing fast math, we don't care about comparison order | |
608 | wrt NaNs. This lets us use a shorter comparison sequence. */ | |
609 | if (flag_fast_math) | |
610 | target_flags &= ~MASK_IEEE_FP; | |
611 | ||
612 | /* If we're planning on using `loop', use it. */ | |
613 | if (TARGET_USE_LOOP && optimize) | |
614 | flag_branch_on_count_reg = 1; | |
f5316dfe MM |
615 | } |
616 | \f | |
617 | /* A C statement (sans semicolon) to choose the order in which to | |
618 | allocate hard registers for pseudo-registers local to a basic | |
619 | block. | |
620 | ||
621 | Store the desired register order in the array `reg_alloc_order'. | |
622 | Element 0 should be the register to allocate first; element 1, the | |
623 | next register; and so on. | |
624 | ||
625 | The macro body should not assume anything about the contents of | |
626 | `reg_alloc_order' before execution of the macro. | |
627 | ||
628 | On most machines, it is not necessary to define this macro. */ | |
629 | ||
630 | void | |
631 | order_regs_for_local_alloc () | |
632 | { | |
00c79232 | 633 | int i, ch, order; |
f5316dfe | 634 | |
e9a25f70 JL |
635 | /* User specified the register allocation order. */ |
636 | ||
e075ae69 | 637 | if (ix86_reg_alloc_order) |
f5316dfe | 638 | { |
e075ae69 | 639 | for (i = order = 0; (ch = ix86_reg_alloc_order[i]) != '\0'; i++) |
f5316dfe | 640 | { |
00c79232 | 641 | int regno = 0; |
79325812 | 642 | |
f5316dfe MM |
643 | switch (ch) |
644 | { | |
645 | case 'a': regno = 0; break; | |
646 | case 'd': regno = 1; break; | |
647 | case 'c': regno = 2; break; | |
648 | case 'b': regno = 3; break; | |
649 | case 'S': regno = 4; break; | |
650 | case 'D': regno = 5; break; | |
651 | case 'B': regno = 6; break; | |
652 | } | |
653 | ||
654 | reg_alloc_order[order++] = regno; | |
655 | } | |
656 | ||
657 | for (i = 0; i < FIRST_PSEUDO_REGISTER; i++) | |
658 | { | |
e9a25f70 | 659 | if (! regs_allocated[i]) |
f5316dfe MM |
660 | reg_alloc_order[order++] = i; |
661 | } | |
662 | } | |
663 | ||
e9a25f70 | 664 | /* If user did not specify a register allocation order, use natural order. */ |
f5316dfe MM |
665 | else |
666 | { | |
667 | for (i = 0; i < FIRST_PSEUDO_REGISTER; i++) | |
668 | reg_alloc_order[i] = i; | |
f5316dfe MM |
669 | } |
670 | } | |
32b5b1aa SC |
671 | \f |
672 | void | |
c6aded7c | 673 | optimization_options (level, size) |
32b5b1aa | 674 | int level; |
bb5177ac | 675 | int size ATTRIBUTE_UNUSED; |
32b5b1aa | 676 | { |
e9a25f70 JL |
677 | /* For -O2 and beyond, turn off -fschedule-insns by default. It tends to |
678 | make the problem with not enough registers even worse. */ | |
32b5b1aa SC |
679 | #ifdef INSN_SCHEDULING |
680 | if (level > 1) | |
681 | flag_schedule_insns = 0; | |
682 | #endif | |
683 | } | |
b08de47e MM |
684 | \f |
685 | /* Return nonzero if IDENTIFIER with arguments ARGS is a valid machine specific | |
686 | attribute for DECL. The attributes in ATTRIBUTES have previously been | |
687 | assigned to DECL. */ | |
688 | ||
689 | int | |
e075ae69 | 690 | ix86_valid_decl_attribute_p (decl, attributes, identifier, args) |
bb5177ac RL |
691 | tree decl ATTRIBUTE_UNUSED; |
692 | tree attributes ATTRIBUTE_UNUSED; | |
693 | tree identifier ATTRIBUTE_UNUSED; | |
694 | tree args ATTRIBUTE_UNUSED; | |
b08de47e MM |
695 | { |
696 | return 0; | |
697 | } | |
698 | ||
699 | /* Return nonzero if IDENTIFIER with arguments ARGS is a valid machine specific | |
700 | attribute for TYPE. The attributes in ATTRIBUTES have previously been | |
701 | assigned to TYPE. */ | |
702 | ||
703 | int | |
e075ae69 | 704 | ix86_valid_type_attribute_p (type, attributes, identifier, args) |
b08de47e | 705 | tree type; |
bb5177ac | 706 | tree attributes ATTRIBUTE_UNUSED; |
b08de47e MM |
707 | tree identifier; |
708 | tree args; | |
709 | { | |
710 | if (TREE_CODE (type) != FUNCTION_TYPE | |
ac478ac0 | 711 | && TREE_CODE (type) != METHOD_TYPE |
b08de47e MM |
712 | && TREE_CODE (type) != FIELD_DECL |
713 | && TREE_CODE (type) != TYPE_DECL) | |
714 | return 0; | |
715 | ||
716 | /* Stdcall attribute says callee is responsible for popping arguments | |
717 | if they are not variable. */ | |
718 | if (is_attribute_p ("stdcall", identifier)) | |
719 | return (args == NULL_TREE); | |
720 | ||
e9a25f70 | 721 | /* Cdecl attribute says the callee is a normal C declaration. */ |
b08de47e MM |
722 | if (is_attribute_p ("cdecl", identifier)) |
723 | return (args == NULL_TREE); | |
724 | ||
725 | /* Regparm attribute specifies how many integer arguments are to be | |
e9a25f70 | 726 | passed in registers. */ |
b08de47e MM |
727 | if (is_attribute_p ("regparm", identifier)) |
728 | { | |
729 | tree cst; | |
730 | ||
e9a25f70 | 731 | if (! args || TREE_CODE (args) != TREE_LIST |
b08de47e MM |
732 | || TREE_CHAIN (args) != NULL_TREE |
733 | || TREE_VALUE (args) == NULL_TREE) | |
734 | return 0; | |
735 | ||
736 | cst = TREE_VALUE (args); | |
737 | if (TREE_CODE (cst) != INTEGER_CST) | |
738 | return 0; | |
739 | ||
cce097f1 | 740 | if (compare_tree_int (cst, REGPARM_MAX) > 0) |
b08de47e MM |
741 | return 0; |
742 | ||
743 | return 1; | |
744 | } | |
745 | ||
746 | return 0; | |
747 | } | |
748 | ||
749 | /* Return 0 if the attributes for two types are incompatible, 1 if they | |
750 | are compatible, and 2 if they are nearly compatible (which causes a | |
751 | warning to be generated). */ | |
752 | ||
753 | int | |
e075ae69 | 754 | ix86_comp_type_attributes (type1, type2) |
afcfe58c MM |
755 | tree type1; |
756 | tree type2; | |
b08de47e | 757 | { |
afcfe58c | 758 | /* Check for mismatch of non-default calling convention. */ |
69ddee61 | 759 | const char *rtdstr = TARGET_RTD ? "cdecl" : "stdcall"; |
afcfe58c MM |
760 | |
761 | if (TREE_CODE (type1) != FUNCTION_TYPE) | |
762 | return 1; | |
763 | ||
764 | /* Check for mismatched return types (cdecl vs stdcall). */ | |
6093f019 RH |
765 | if (!lookup_attribute (rtdstr, TYPE_ATTRIBUTES (type1)) |
766 | != !lookup_attribute (rtdstr, TYPE_ATTRIBUTES (type2))) | |
afcfe58c | 767 | return 0; |
b08de47e MM |
768 | return 1; |
769 | } | |
b08de47e MM |
770 | \f |
771 | /* Value is the number of bytes of arguments automatically | |
772 | popped when returning from a subroutine call. | |
773 | FUNDECL is the declaration node of the function (as a tree), | |
774 | FUNTYPE is the data type of the function (as a tree), | |
775 | or for a library call it is an identifier node for the subroutine name. | |
776 | SIZE is the number of bytes of arguments passed on the stack. | |
777 | ||
778 | On the 80386, the RTD insn may be used to pop them if the number | |
779 | of args is fixed, but if the number is variable then the caller | |
780 | must pop them all. RTD can't be used for library calls now | |
781 | because the library is compiled with the Unix compiler. | |
782 | Use of RTD is a selectable option, since it is incompatible with | |
783 | standard Unix calling sequences. If the option is not selected, | |
784 | the caller must always pop the args. | |
785 | ||
786 | The attribute stdcall is equivalent to RTD on a per module basis. */ | |
787 | ||
788 | int | |
e075ae69 | 789 | ix86_return_pops_args (fundecl, funtype, size) |
b08de47e MM |
790 | tree fundecl; |
791 | tree funtype; | |
792 | int size; | |
79325812 | 793 | { |
3345ee7d | 794 | int rtd = TARGET_RTD && (!fundecl || TREE_CODE (fundecl) != IDENTIFIER_NODE); |
b08de47e | 795 | |
e9a25f70 JL |
796 | /* Cdecl functions override -mrtd, and never pop the stack. */ |
797 | if (! lookup_attribute ("cdecl", TYPE_ATTRIBUTES (funtype))) { | |
79325812 | 798 | |
e9a25f70 | 799 | /* Stdcall functions will pop the stack if not variable args. */ |
698cdd84 SC |
800 | if (lookup_attribute ("stdcall", TYPE_ATTRIBUTES (funtype))) |
801 | rtd = 1; | |
79325812 | 802 | |
698cdd84 SC |
803 | if (rtd |
804 | && (TYPE_ARG_TYPES (funtype) == NULL_TREE | |
e9a25f70 JL |
805 | || (TREE_VALUE (tree_last (TYPE_ARG_TYPES (funtype))) |
806 | == void_type_node))) | |
698cdd84 SC |
807 | return size; |
808 | } | |
79325812 | 809 | |
e9a25f70 | 810 | /* Lose any fake structure return argument. */ |
698cdd84 SC |
811 | if (aggregate_value_p (TREE_TYPE (funtype))) |
812 | return GET_MODE_SIZE (Pmode); | |
79325812 | 813 | |
2614aac6 | 814 | return 0; |
b08de47e | 815 | } |
b08de47e MM |
816 | \f |
817 | /* Argument support functions. */ | |
818 | ||
819 | /* Initialize a variable CUM of type CUMULATIVE_ARGS | |
820 | for a call to a function whose data type is FNTYPE. | |
821 | For a library call, FNTYPE is 0. */ | |
822 | ||
823 | void | |
824 | init_cumulative_args (cum, fntype, libname) | |
e9a25f70 | 825 | CUMULATIVE_ARGS *cum; /* Argument info to initialize */ |
b08de47e MM |
826 | tree fntype; /* tree ptr for function decl */ |
827 | rtx libname; /* SYMBOL_REF of library name or 0 */ | |
828 | { | |
829 | static CUMULATIVE_ARGS zero_cum; | |
830 | tree param, next_param; | |
831 | ||
832 | if (TARGET_DEBUG_ARG) | |
833 | { | |
834 | fprintf (stderr, "\ninit_cumulative_args ("); | |
835 | if (fntype) | |
e9a25f70 JL |
836 | fprintf (stderr, "fntype code = %s, ret code = %s", |
837 | tree_code_name[(int) TREE_CODE (fntype)], | |
838 | tree_code_name[(int) TREE_CODE (TREE_TYPE (fntype))]); | |
b08de47e MM |
839 | else |
840 | fprintf (stderr, "no fntype"); | |
841 | ||
842 | if (libname) | |
843 | fprintf (stderr, ", libname = %s", XSTR (libname, 0)); | |
844 | } | |
845 | ||
846 | *cum = zero_cum; | |
847 | ||
848 | /* Set up the number of registers to use for passing arguments. */ | |
e075ae69 | 849 | cum->nregs = ix86_regparm; |
b08de47e MM |
850 | if (fntype) |
851 | { | |
852 | tree attr = lookup_attribute ("regparm", TYPE_ATTRIBUTES (fntype)); | |
e9a25f70 | 853 | |
b08de47e MM |
854 | if (attr) |
855 | cum->nregs = TREE_INT_CST_LOW (TREE_VALUE (TREE_VALUE (attr))); | |
856 | } | |
857 | ||
858 | /* Determine if this function has variable arguments. This is | |
859 | indicated by the last argument being 'void_type_mode' if there | |
860 | are no variable arguments. If there are variable arguments, then | |
861 | we won't pass anything in registers */ | |
862 | ||
863 | if (cum->nregs) | |
864 | { | |
865 | for (param = (fntype) ? TYPE_ARG_TYPES (fntype) : 0; | |
e9a25f70 | 866 | param != 0; param = next_param) |
b08de47e MM |
867 | { |
868 | next_param = TREE_CHAIN (param); | |
e9a25f70 | 869 | if (next_param == 0 && TREE_VALUE (param) != void_type_node) |
b08de47e MM |
870 | cum->nregs = 0; |
871 | } | |
872 | } | |
873 | ||
874 | if (TARGET_DEBUG_ARG) | |
875 | fprintf (stderr, ", nregs=%d )\n", cum->nregs); | |
876 | ||
877 | return; | |
878 | } | |
879 | ||
880 | /* Update the data in CUM to advance over an argument | |
881 | of mode MODE and data type TYPE. | |
882 | (TYPE is null for libcalls where that information may not be available.) */ | |
883 | ||
884 | void | |
885 | function_arg_advance (cum, mode, type, named) | |
886 | CUMULATIVE_ARGS *cum; /* current arg information */ | |
887 | enum machine_mode mode; /* current arg mode */ | |
888 | tree type; /* type of the argument or 0 if lib support */ | |
889 | int named; /* whether or not the argument was named */ | |
890 | { | |
e9a25f70 JL |
891 | int bytes |
892 | = (mode == BLKmode) ? int_size_in_bytes (type) : GET_MODE_SIZE (mode); | |
b08de47e MM |
893 | int words = (bytes + UNITS_PER_WORD - 1) / UNITS_PER_WORD; |
894 | ||
895 | if (TARGET_DEBUG_ARG) | |
896 | fprintf (stderr, | |
e9a25f70 | 897 | "function_adv (sz=%d, wds=%2d, nregs=%d, mode=%s, named=%d)\n\n", |
b08de47e MM |
898 | words, cum->words, cum->nregs, GET_MODE_NAME (mode), named); |
899 | ||
900 | cum->words += words; | |
901 | cum->nregs -= words; | |
902 | cum->regno += words; | |
903 | ||
904 | if (cum->nregs <= 0) | |
905 | { | |
906 | cum->nregs = 0; | |
907 | cum->regno = 0; | |
908 | } | |
909 | ||
910 | return; | |
911 | } | |
912 | ||
913 | /* Define where to put the arguments to a function. | |
914 | Value is zero to push the argument on the stack, | |
915 | or a hard register in which to store the argument. | |
916 | ||
917 | MODE is the argument's machine mode. | |
918 | TYPE is the data type of the argument (as a tree). | |
919 | This is null for libcalls where that information may | |
920 | not be available. | |
921 | CUM is a variable of type CUMULATIVE_ARGS which gives info about | |
922 | the preceding args and about the function being called. | |
923 | NAMED is nonzero if this argument is a named parameter | |
924 | (otherwise it is an extra parameter matching an ellipsis). */ | |
925 | ||
926 | struct rtx_def * | |
927 | function_arg (cum, mode, type, named) | |
928 | CUMULATIVE_ARGS *cum; /* current arg information */ | |
929 | enum machine_mode mode; /* current arg mode */ | |
930 | tree type; /* type of the argument or 0 if lib support */ | |
931 | int named; /* != 0 for normal args, == 0 for ... args */ | |
932 | { | |
933 | rtx ret = NULL_RTX; | |
e9a25f70 JL |
934 | int bytes |
935 | = (mode == BLKmode) ? int_size_in_bytes (type) : GET_MODE_SIZE (mode); | |
b08de47e MM |
936 | int words = (bytes + UNITS_PER_WORD - 1) / UNITS_PER_WORD; |
937 | ||
938 | switch (mode) | |
939 | { | |
e9a25f70 JL |
940 | /* For now, pass fp/complex values on the stack. */ |
941 | default: | |
b08de47e MM |
942 | break; |
943 | ||
944 | case BLKmode: | |
945 | case DImode: | |
946 | case SImode: | |
947 | case HImode: | |
948 | case QImode: | |
949 | if (words <= cum->nregs) | |
f64cecad | 950 | ret = gen_rtx_REG (mode, cum->regno); |
b08de47e MM |
951 | break; |
952 | } | |
953 | ||
954 | if (TARGET_DEBUG_ARG) | |
955 | { | |
956 | fprintf (stderr, | |
e9a25f70 | 957 | "function_arg (size=%d, wds=%2d, nregs=%d, mode=%4s, named=%d", |
b08de47e MM |
958 | words, cum->words, cum->nregs, GET_MODE_NAME (mode), named); |
959 | ||
960 | if (ret) | |
961 | fprintf (stderr, ", reg=%%e%s", reg_names[ REGNO(ret) ]); | |
962 | else | |
963 | fprintf (stderr, ", stack"); | |
964 | ||
965 | fprintf (stderr, " )\n"); | |
966 | } | |
967 | ||
968 | return ret; | |
969 | } | |
e075ae69 RH |
970 | \f |
971 | /* Returns 1 if OP is either a symbol reference or a sum of a symbol | |
972 | reference and a constant. */ | |
b08de47e MM |
973 | |
974 | int | |
e075ae69 RH |
975 | symbolic_operand (op, mode) |
976 | register rtx op; | |
977 | enum machine_mode mode ATTRIBUTE_UNUSED; | |
2a2ab3f9 | 978 | { |
e075ae69 | 979 | switch (GET_CODE (op)) |
2a2ab3f9 | 980 | { |
e075ae69 RH |
981 | case SYMBOL_REF: |
982 | case LABEL_REF: | |
983 | return 1; | |
984 | ||
985 | case CONST: | |
986 | op = XEXP (op, 0); | |
987 | if (GET_CODE (op) == SYMBOL_REF | |
988 | || GET_CODE (op) == LABEL_REF | |
989 | || (GET_CODE (op) == UNSPEC | |
990 | && XINT (op, 1) >= 6 | |
991 | && XINT (op, 1) <= 7)) | |
992 | return 1; | |
993 | if (GET_CODE (op) != PLUS | |
994 | || GET_CODE (XEXP (op, 1)) != CONST_INT) | |
995 | return 0; | |
996 | ||
997 | op = XEXP (op, 0); | |
998 | if (GET_CODE (op) == SYMBOL_REF | |
999 | || GET_CODE (op) == LABEL_REF) | |
1000 | return 1; | |
1001 | /* Only @GOTOFF gets offsets. */ | |
1002 | if (GET_CODE (op) != UNSPEC | |
1003 | || XINT (op, 1) != 7) | |
1004 | return 0; | |
1005 | ||
1006 | op = XVECEXP (op, 0, 0); | |
1007 | if (GET_CODE (op) == SYMBOL_REF | |
1008 | || GET_CODE (op) == LABEL_REF) | |
1009 | return 1; | |
1010 | return 0; | |
1011 | ||
1012 | default: | |
1013 | return 0; | |
2a2ab3f9 JVA |
1014 | } |
1015 | } | |
2a2ab3f9 | 1016 | |
e075ae69 | 1017 | /* Return true if the operand contains a @GOT or @GOTOFF reference. */ |
3b3c6a3f | 1018 | |
e075ae69 RH |
1019 | int |
1020 | pic_symbolic_operand (op, mode) | |
1021 | register rtx op; | |
1022 | enum machine_mode mode ATTRIBUTE_UNUSED; | |
1023 | { | |
1024 | if (GET_CODE (op) == CONST) | |
2a2ab3f9 | 1025 | { |
e075ae69 RH |
1026 | op = XEXP (op, 0); |
1027 | if (GET_CODE (op) == UNSPEC) | |
1028 | return 1; | |
1029 | if (GET_CODE (op) != PLUS | |
1030 | || GET_CODE (XEXP (op, 1)) != CONST_INT) | |
1031 | return 0; | |
1032 | op = XEXP (op, 0); | |
1033 | if (GET_CODE (op) == UNSPEC) | |
1034 | return 1; | |
2a2ab3f9 | 1035 | } |
e075ae69 | 1036 | return 0; |
2a2ab3f9 | 1037 | } |
2a2ab3f9 | 1038 | |
28d52ffb RH |
1039 | /* Test for a valid operand for a call instruction. Don't allow the |
1040 | arg pointer register or virtual regs since they may decay into | |
1041 | reg + const, which the patterns can't handle. */ | |
2a2ab3f9 | 1042 | |
e075ae69 RH |
1043 | int |
1044 | call_insn_operand (op, mode) | |
1045 | rtx op; | |
1046 | enum machine_mode mode ATTRIBUTE_UNUSED; | |
1047 | { | |
1048 | if (GET_CODE (op) != MEM) | |
1049 | return 0; | |
1050 | op = XEXP (op, 0); | |
2a2ab3f9 | 1051 | |
e075ae69 RH |
1052 | /* Disallow indirect through a virtual register. This leads to |
1053 | compiler aborts when trying to eliminate them. */ | |
1054 | if (GET_CODE (op) == REG | |
1055 | && (op == arg_pointer_rtx | |
564d80f4 | 1056 | || op == frame_pointer_rtx |
e075ae69 RH |
1057 | || (REGNO (op) >= FIRST_PSEUDO_REGISTER |
1058 | && REGNO (op) <= LAST_VIRTUAL_REGISTER))) | |
1059 | return 0; | |
2a2ab3f9 | 1060 | |
28d52ffb RH |
1061 | /* Disallow `call 1234'. Due to varying assembler lameness this |
1062 | gets either rejected or translated to `call .+1234'. */ | |
1063 | if (GET_CODE (op) == CONST_INT) | |
1064 | return 0; | |
1065 | ||
e075ae69 RH |
1066 | /* Otherwise we can allow any general_operand in the address. */ |
1067 | return general_operand (op, Pmode); | |
1068 | } | |
2a2ab3f9 | 1069 | |
28d52ffb | 1070 | /* Like call_insn_operand but allow (mem (symbol_ref ...)) even if pic. */ |
5f1ec3e6 | 1071 | |
e075ae69 RH |
1072 | int |
1073 | expander_call_insn_operand (op, mode) | |
1074 | rtx op; | |
28d52ffb | 1075 | enum machine_mode mode; |
e075ae69 | 1076 | { |
28d52ffb RH |
1077 | if (GET_CODE (op) == MEM |
1078 | && GET_CODE (XEXP (op, 0)) == SYMBOL_REF) | |
e075ae69 | 1079 | return 1; |
2a2ab3f9 | 1080 | |
28d52ffb | 1081 | return call_insn_operand (op, mode); |
e075ae69 | 1082 | } |
79325812 | 1083 | |
e075ae69 RH |
1084 | int |
1085 | constant_call_address_operand (op, mode) | |
1086 | rtx op; | |
1087 | enum machine_mode mode ATTRIBUTE_UNUSED; | |
1088 | { | |
dc5f5366 CP |
1089 | return GET_CODE (op) == MEM && |
1090 | CONSTANT_ADDRESS_P (XEXP (op, 0)) && | |
1091 | GET_CODE (XEXP (op, 0)) != CONST_INT; | |
e075ae69 | 1092 | } |
2a2ab3f9 | 1093 | |
e075ae69 | 1094 | /* Match exactly zero and one. */ |
e9a25f70 | 1095 | |
e075ae69 RH |
1096 | int |
1097 | const0_operand (op, mode) | |
1098 | register rtx op; | |
1099 | enum machine_mode mode; | |
1100 | { | |
1101 | return op == CONST0_RTX (mode); | |
1102 | } | |
e9a25f70 | 1103 | |
e075ae69 RH |
1104 | int |
1105 | const1_operand (op, mode) | |
1106 | register rtx op; | |
1107 | enum machine_mode mode ATTRIBUTE_UNUSED; | |
1108 | { | |
1109 | return op == const1_rtx; | |
1110 | } | |
2a2ab3f9 | 1111 | |
e075ae69 | 1112 | /* Match 2, 4, or 8. Used for leal multiplicands. */ |
e9a25f70 | 1113 | |
e075ae69 RH |
1114 | int |
1115 | const248_operand (op, mode) | |
1116 | register rtx op; | |
1117 | enum machine_mode mode ATTRIBUTE_UNUSED; | |
1118 | { | |
1119 | return (GET_CODE (op) == CONST_INT | |
1120 | && (INTVAL (op) == 2 || INTVAL (op) == 4 || INTVAL (op) == 8)); | |
1121 | } | |
e9a25f70 | 1122 | |
e075ae69 | 1123 | /* True if this is a constant appropriate for an increment or decremenmt. */ |
81fd0956 | 1124 | |
e075ae69 RH |
1125 | int |
1126 | incdec_operand (op, mode) | |
1127 | register rtx op; | |
1128 | enum machine_mode mode; | |
1129 | { | |
1130 | if (op == const1_rtx || op == constm1_rtx) | |
1131 | return 1; | |
1132 | if (GET_CODE (op) != CONST_INT) | |
1133 | return 0; | |
1134 | if (mode == SImode && INTVAL (op) == (HOST_WIDE_INT) 0xffffffff) | |
1135 | return 1; | |
1136 | if (mode == HImode && INTVAL (op) == (HOST_WIDE_INT) 0xffff) | |
1137 | return 1; | |
1138 | if (mode == QImode && INTVAL (op) == (HOST_WIDE_INT) 0xff) | |
1139 | return 1; | |
1140 | return 0; | |
1141 | } | |
2a2ab3f9 | 1142 | |
e075ae69 RH |
1143 | /* Return false if this is the stack pointer, or any other fake |
1144 | register eliminable to the stack pointer. Otherwise, this is | |
1145 | a register operand. | |
2a2ab3f9 | 1146 | |
e075ae69 RH |
1147 | This is used to prevent esp from being used as an index reg. |
1148 | Which would only happen in pathological cases. */ | |
5f1ec3e6 | 1149 | |
e075ae69 RH |
1150 | int |
1151 | reg_no_sp_operand (op, mode) | |
1152 | register rtx op; | |
1153 | enum machine_mode mode; | |
1154 | { | |
1155 | rtx t = op; | |
1156 | if (GET_CODE (t) == SUBREG) | |
1157 | t = SUBREG_REG (t); | |
564d80f4 | 1158 | if (t == stack_pointer_rtx || t == arg_pointer_rtx || t == frame_pointer_rtx) |
e075ae69 | 1159 | return 0; |
2a2ab3f9 | 1160 | |
e075ae69 | 1161 | return register_operand (op, mode); |
2a2ab3f9 | 1162 | } |
b840bfb0 | 1163 | |
2c5a510c RH |
1164 | /* Return false if this is any eliminable register. Otherwise |
1165 | general_operand. */ | |
1166 | ||
1167 | int | |
1168 | general_no_elim_operand (op, mode) | |
1169 | register rtx op; | |
1170 | enum machine_mode mode; | |
1171 | { | |
1172 | rtx t = op; | |
1173 | if (GET_CODE (t) == SUBREG) | |
1174 | t = SUBREG_REG (t); | |
1175 | if (t == arg_pointer_rtx || t == frame_pointer_rtx | |
1176 | || t == virtual_incoming_args_rtx || t == virtual_stack_vars_rtx | |
1177 | || t == virtual_stack_dynamic_rtx) | |
1178 | return 0; | |
1179 | ||
1180 | return general_operand (op, mode); | |
1181 | } | |
1182 | ||
1183 | /* Return false if this is any eliminable register. Otherwise | |
1184 | register_operand or const_int. */ | |
1185 | ||
1186 | int | |
1187 | nonmemory_no_elim_operand (op, mode) | |
1188 | register rtx op; | |
1189 | enum machine_mode mode; | |
1190 | { | |
1191 | rtx t = op; | |
1192 | if (GET_CODE (t) == SUBREG) | |
1193 | t = SUBREG_REG (t); | |
1194 | if (t == arg_pointer_rtx || t == frame_pointer_rtx | |
1195 | || t == virtual_incoming_args_rtx || t == virtual_stack_vars_rtx | |
1196 | || t == virtual_stack_dynamic_rtx) | |
1197 | return 0; | |
1198 | ||
1199 | return GET_CODE (op) == CONST_INT || register_operand (op, mode); | |
1200 | } | |
1201 | ||
e075ae69 | 1202 | /* Return true if op is a Q_REGS class register. */ |
b840bfb0 | 1203 | |
e075ae69 RH |
1204 | int |
1205 | q_regs_operand (op, mode) | |
1206 | register rtx op; | |
1207 | enum machine_mode mode; | |
b840bfb0 | 1208 | { |
e075ae69 RH |
1209 | if (mode != VOIDmode && GET_MODE (op) != mode) |
1210 | return 0; | |
1211 | if (GET_CODE (op) == SUBREG) | |
1212 | op = SUBREG_REG (op); | |
1213 | return QI_REG_P (op); | |
1214 | } | |
b840bfb0 | 1215 | |
e075ae69 | 1216 | /* Return true if op is a NON_Q_REGS class register. */ |
b840bfb0 | 1217 | |
e075ae69 RH |
1218 | int |
1219 | non_q_regs_operand (op, mode) | |
1220 | register rtx op; | |
1221 | enum machine_mode mode; | |
1222 | { | |
1223 | if (mode != VOIDmode && GET_MODE (op) != mode) | |
1224 | return 0; | |
1225 | if (GET_CODE (op) == SUBREG) | |
1226 | op = SUBREG_REG (op); | |
1227 | return NON_QI_REG_P (op); | |
1228 | } | |
b840bfb0 | 1229 | |
e075ae69 RH |
1230 | /* Return 1 if OP is a comparison operator that can use the condition code |
1231 | generated by a logical operation, which characteristicly does not set | |
1232 | overflow or carry. To be used with CCNOmode. */ | |
b840bfb0 | 1233 | |
e075ae69 RH |
1234 | int |
1235 | no_comparison_operator (op, mode) | |
1236 | register rtx op; | |
1237 | enum machine_mode mode; | |
1238 | { | |
1239 | return ((mode == VOIDmode || GET_MODE (op) == mode) | |
1240 | && GET_RTX_CLASS (GET_CODE (op)) == '<' | |
1241 | && GET_CODE (op) != LE | |
1242 | && GET_CODE (op) != GT); | |
1243 | } | |
b840bfb0 | 1244 | |
e075ae69 | 1245 | /* Return 1 if OP is a comparison operator that can be issued by fcmov. */ |
b840bfb0 | 1246 | |
e075ae69 RH |
1247 | int |
1248 | fcmov_comparison_operator (op, mode) | |
1249 | register rtx op; | |
1250 | enum machine_mode mode; | |
1251 | { | |
1252 | return ((mode == VOIDmode || GET_MODE (op) == mode) | |
1253 | && GET_RTX_CLASS (GET_CODE (op)) == '<' | |
1254 | && GET_CODE (op) == unsigned_condition (GET_CODE (op))); | |
1255 | } | |
b840bfb0 | 1256 | |
e9e80858 JH |
1257 | /* Return 1 if OP is a binary operator that can be promoted to wider mode. */ |
1258 | ||
1259 | int | |
1260 | promotable_binary_operator (op, mode) | |
1261 | register rtx op; | |
1262 | enum machine_mode mode ATTRIBUTE_UNUSED; | |
1263 | { | |
1264 | switch (GET_CODE (op)) | |
1265 | { | |
1266 | case MULT: | |
1267 | /* Modern CPUs have same latency for HImode and SImode multiply, | |
1268 | but 386 and 486 do HImode multiply faster. */ | |
1269 | return ix86_cpu > PROCESSOR_I486; | |
1270 | case PLUS: | |
1271 | case AND: | |
1272 | case IOR: | |
1273 | case XOR: | |
1274 | case ASHIFT: | |
1275 | return 1; | |
1276 | default: | |
1277 | return 0; | |
1278 | } | |
1279 | } | |
1280 | ||
e075ae69 RH |
1281 | /* Nearly general operand, but accept any const_double, since we wish |
1282 | to be able to drop them into memory rather than have them get pulled | |
1283 | into registers. */ | |
b840bfb0 | 1284 | |
2a2ab3f9 | 1285 | int |
e075ae69 RH |
1286 | cmp_fp_expander_operand (op, mode) |
1287 | register rtx op; | |
1288 | enum machine_mode mode; | |
2a2ab3f9 | 1289 | { |
e075ae69 | 1290 | if (mode != VOIDmode && mode != GET_MODE (op)) |
0b6b2900 | 1291 | return 0; |
e075ae69 | 1292 | if (GET_CODE (op) == CONST_DOUBLE) |
2a2ab3f9 | 1293 | return 1; |
e075ae69 | 1294 | return general_operand (op, mode); |
2a2ab3f9 JVA |
1295 | } |
1296 | ||
e075ae69 | 1297 | /* Match an SI or HImode register for a zero_extract. */ |
2a2ab3f9 JVA |
1298 | |
1299 | int | |
e075ae69 | 1300 | ext_register_operand (op, mode) |
2a2ab3f9 | 1301 | register rtx op; |
bb5177ac | 1302 | enum machine_mode mode ATTRIBUTE_UNUSED; |
2a2ab3f9 | 1303 | { |
e075ae69 RH |
1304 | if (GET_MODE (op) != SImode && GET_MODE (op) != HImode) |
1305 | return 0; | |
1306 | return register_operand (op, VOIDmode); | |
1307 | } | |
1308 | ||
1309 | /* Return 1 if this is a valid binary floating-point operation. | |
1310 | OP is the expression matched, and MODE is its mode. */ | |
1311 | ||
1312 | int | |
1313 | binary_fp_operator (op, mode) | |
1314 | register rtx op; | |
1315 | enum machine_mode mode; | |
1316 | { | |
1317 | if (mode != VOIDmode && mode != GET_MODE (op)) | |
1318 | return 0; | |
1319 | ||
2a2ab3f9 JVA |
1320 | switch (GET_CODE (op)) |
1321 | { | |
e075ae69 RH |
1322 | case PLUS: |
1323 | case MINUS: | |
1324 | case MULT: | |
1325 | case DIV: | |
1326 | return GET_MODE_CLASS (GET_MODE (op)) == MODE_FLOAT; | |
e9a25f70 | 1327 | |
2a2ab3f9 JVA |
1328 | default: |
1329 | return 0; | |
1330 | } | |
1331 | } | |
fee2770d | 1332 | |
e075ae69 RH |
1333 | int |
1334 | mult_operator(op, mode) | |
1335 | register rtx op; | |
1336 | enum machine_mode mode ATTRIBUTE_UNUSED; | |
1337 | { | |
1338 | return GET_CODE (op) == MULT; | |
1339 | } | |
1340 | ||
1341 | int | |
1342 | div_operator(op, mode) | |
1343 | register rtx op; | |
1344 | enum machine_mode mode ATTRIBUTE_UNUSED; | |
1345 | { | |
1346 | return GET_CODE (op) == DIV; | |
1347 | } | |
0a726ef1 JL |
1348 | |
1349 | int | |
e075ae69 RH |
1350 | arith_or_logical_operator (op, mode) |
1351 | rtx op; | |
1352 | enum machine_mode mode; | |
0a726ef1 | 1353 | { |
e075ae69 RH |
1354 | return ((mode == VOIDmode || GET_MODE (op) == mode) |
1355 | && (GET_RTX_CLASS (GET_CODE (op)) == 'c' | |
1356 | || GET_RTX_CLASS (GET_CODE (op)) == '2')); | |
0a726ef1 JL |
1357 | } |
1358 | ||
e075ae69 | 1359 | /* Returns 1 if OP is memory operand with a displacement. */ |
fee2770d RS |
1360 | |
1361 | int | |
e075ae69 RH |
1362 | memory_displacement_operand (op, mode) |
1363 | register rtx op; | |
1364 | enum machine_mode mode; | |
4f2c8ebb | 1365 | { |
e075ae69 | 1366 | struct ix86_address parts; |
e9a25f70 | 1367 | |
e075ae69 RH |
1368 | if (! memory_operand (op, mode)) |
1369 | return 0; | |
1370 | ||
1371 | if (! ix86_decompose_address (XEXP (op, 0), &parts)) | |
1372 | abort (); | |
1373 | ||
1374 | return parts.disp != NULL_RTX; | |
4f2c8ebb RS |
1375 | } |
1376 | ||
e075ae69 RH |
1377 | /* To avoid problems when jump re-emits comparisons like testqi_ext_0, |
1378 | re-recognize the operand to avoid a copy_to_mode_reg that will fail. | |
1379 | ||
1380 | ??? It seems likely that this will only work because cmpsi is an | |
1381 | expander, and no actual insns use this. */ | |
4f2c8ebb RS |
1382 | |
1383 | int | |
e075ae69 RH |
1384 | cmpsi_operand (op, mode) |
1385 | rtx op; | |
1386 | enum machine_mode mode; | |
fee2770d | 1387 | { |
e075ae69 RH |
1388 | if (general_operand (op, mode)) |
1389 | return 1; | |
1390 | ||
1391 | if (GET_CODE (op) == AND | |
1392 | && GET_MODE (op) == SImode | |
1393 | && GET_CODE (XEXP (op, 0)) == ZERO_EXTRACT | |
1394 | && GET_CODE (XEXP (XEXP (op, 0), 1)) == CONST_INT | |
1395 | && GET_CODE (XEXP (XEXP (op, 0), 2)) == CONST_INT | |
1396 | && INTVAL (XEXP (XEXP (op, 0), 1)) == 8 | |
1397 | && INTVAL (XEXP (XEXP (op, 0), 2)) == 8 | |
1398 | && GET_CODE (XEXP (op, 1)) == CONST_INT) | |
fee2770d | 1399 | return 1; |
e9a25f70 | 1400 | |
fee2770d RS |
1401 | return 0; |
1402 | } | |
d784886d | 1403 | |
e075ae69 RH |
1404 | /* Returns 1 if OP is memory operand that can not be represented by the |
1405 | modRM array. */ | |
d784886d RK |
1406 | |
1407 | int | |
e075ae69 | 1408 | long_memory_operand (op, mode) |
d784886d RK |
1409 | register rtx op; |
1410 | enum machine_mode mode; | |
1411 | { | |
e075ae69 | 1412 | if (! memory_operand (op, mode)) |
d784886d RK |
1413 | return 0; |
1414 | ||
e075ae69 | 1415 | return memory_address_length (op) != 0; |
d784886d | 1416 | } |
2247f6ed JH |
1417 | |
1418 | /* Return nonzero if the rtx is known aligned. */ | |
1419 | ||
1420 | int | |
1421 | aligned_operand (op, mode) | |
1422 | rtx op; | |
1423 | enum machine_mode mode; | |
1424 | { | |
1425 | struct ix86_address parts; | |
1426 | ||
1427 | if (!general_operand (op, mode)) | |
1428 | return 0; | |
1429 | ||
1430 | /* Registers and immediate operands are always "aligned". */ | |
1431 | if (GET_CODE (op) != MEM) | |
1432 | return 1; | |
1433 | ||
1434 | /* Don't even try to do any aligned optimizations with volatiles. */ | |
1435 | if (MEM_VOLATILE_P (op)) | |
1436 | return 0; | |
1437 | ||
1438 | op = XEXP (op, 0); | |
1439 | ||
1440 | /* Pushes and pops are only valid on the stack pointer. */ | |
1441 | if (GET_CODE (op) == PRE_DEC | |
1442 | || GET_CODE (op) == POST_INC) | |
1443 | return 1; | |
1444 | ||
1445 | /* Decode the address. */ | |
1446 | if (! ix86_decompose_address (op, &parts)) | |
1447 | abort (); | |
1448 | ||
1449 | /* Look for some component that isn't known to be aligned. */ | |
1450 | if (parts.index) | |
1451 | { | |
1452 | if (parts.scale < 4 | |
1453 | && REGNO_POINTER_ALIGN (REGNO (parts.index)) < 4) | |
1454 | return 0; | |
1455 | } | |
1456 | if (parts.base) | |
1457 | { | |
1458 | if (REGNO_POINTER_ALIGN (REGNO (parts.base)) < 4) | |
1459 | return 0; | |
1460 | } | |
1461 | if (parts.disp) | |
1462 | { | |
1463 | if (GET_CODE (parts.disp) != CONST_INT | |
1464 | || (INTVAL (parts.disp) & 3) != 0) | |
1465 | return 0; | |
1466 | } | |
1467 | ||
1468 | /* Didn't find one -- this must be an aligned address. */ | |
1469 | return 1; | |
1470 | } | |
e075ae69 RH |
1471 | \f |
1472 | /* Return true if the constant is something that can be loaded with | |
1473 | a special instruction. Only handle 0.0 and 1.0; others are less | |
1474 | worthwhile. */ | |
57dbca5e BS |
1475 | |
1476 | int | |
e075ae69 RH |
1477 | standard_80387_constant_p (x) |
1478 | rtx x; | |
57dbca5e | 1479 | { |
e075ae69 RH |
1480 | if (GET_CODE (x) != CONST_DOUBLE) |
1481 | return -1; | |
1482 | ||
1483 | #if ! defined (REAL_IS_NOT_DOUBLE) || defined (REAL_ARITHMETIC) | |
1484 | { | |
1485 | REAL_VALUE_TYPE d; | |
1486 | jmp_buf handler; | |
1487 | int is0, is1; | |
1488 | ||
1489 | if (setjmp (handler)) | |
1490 | return 0; | |
1491 | ||
1492 | set_float_handler (handler); | |
1493 | REAL_VALUE_FROM_CONST_DOUBLE (d, x); | |
1494 | is0 = REAL_VALUES_EQUAL (d, dconst0) && !REAL_VALUE_MINUS_ZERO (d); | |
1495 | is1 = REAL_VALUES_EQUAL (d, dconst1); | |
1496 | set_float_handler (NULL_PTR); | |
1497 | ||
1498 | if (is0) | |
1499 | return 1; | |
1500 | ||
1501 | if (is1) | |
1502 | return 2; | |
1503 | ||
1504 | /* Note that on the 80387, other constants, such as pi, | |
1505 | are much slower to load as standard constants | |
1506 | than to load from doubles in memory! */ | |
1507 | /* ??? Not true on K6: all constants are equal cost. */ | |
1508 | } | |
1509 | #endif | |
1510 | ||
1511 | return 0; | |
57dbca5e BS |
1512 | } |
1513 | ||
2a2ab3f9 JVA |
1514 | /* Returns 1 if OP contains a symbol reference */ |
1515 | ||
1516 | int | |
1517 | symbolic_reference_mentioned_p (op) | |
1518 | rtx op; | |
1519 | { | |
6f7d635c | 1520 | register const char *fmt; |
2a2ab3f9 JVA |
1521 | register int i; |
1522 | ||
1523 | if (GET_CODE (op) == SYMBOL_REF || GET_CODE (op) == LABEL_REF) | |
1524 | return 1; | |
1525 | ||
1526 | fmt = GET_RTX_FORMAT (GET_CODE (op)); | |
1527 | for (i = GET_RTX_LENGTH (GET_CODE (op)) - 1; i >= 0; i--) | |
1528 | { | |
1529 | if (fmt[i] == 'E') | |
1530 | { | |
1531 | register int j; | |
1532 | ||
1533 | for (j = XVECLEN (op, i) - 1; j >= 0; j--) | |
1534 | if (symbolic_reference_mentioned_p (XVECEXP (op, i, j))) | |
1535 | return 1; | |
1536 | } | |
e9a25f70 | 1537 | |
2a2ab3f9 JVA |
1538 | else if (fmt[i] == 'e' && symbolic_reference_mentioned_p (XEXP (op, i))) |
1539 | return 1; | |
1540 | } | |
1541 | ||
1542 | return 0; | |
1543 | } | |
e075ae69 RH |
1544 | |
1545 | /* Return 1 if it is appropriate to emit `ret' instructions in the | |
1546 | body of a function. Do this only if the epilogue is simple, needing a | |
1547 | couple of insns. Prior to reloading, we can't tell how many registers | |
1548 | must be saved, so return 0 then. Return 0 if there is no frame | |
1549 | marker to de-allocate. | |
1550 | ||
1551 | If NON_SAVING_SETJMP is defined and true, then it is not possible | |
1552 | for the epilogue to be simple, so return 0. This is a special case | |
1553 | since NON_SAVING_SETJMP will not cause regs_ever_live to change | |
1554 | until final, but jump_optimize may need to know sooner if a | |
1555 | `return' is OK. */ | |
32b5b1aa SC |
1556 | |
1557 | int | |
e075ae69 | 1558 | ix86_can_use_return_insn_p () |
32b5b1aa | 1559 | { |
9a7372d6 RH |
1560 | HOST_WIDE_INT tsize; |
1561 | int nregs; | |
1562 | ||
e075ae69 RH |
1563 | #ifdef NON_SAVING_SETJMP |
1564 | if (NON_SAVING_SETJMP && current_function_calls_setjmp) | |
1565 | return 0; | |
1566 | #endif | |
9a7372d6 RH |
1567 | #ifdef FUNCTION_BLOCK_PROFILER_EXIT |
1568 | if (profile_block_flag == 2) | |
1569 | return 0; | |
1570 | #endif | |
1571 | ||
1572 | if (! reload_completed || frame_pointer_needed) | |
1573 | return 0; | |
32b5b1aa | 1574 | |
9a7372d6 RH |
1575 | /* Don't allow more than 32 pop, since that's all we can do |
1576 | with one instruction. */ | |
1577 | if (current_function_pops_args | |
1578 | && current_function_args_size >= 32768) | |
e075ae69 | 1579 | return 0; |
32b5b1aa | 1580 | |
9a7372d6 RH |
1581 | tsize = ix86_compute_frame_size (get_frame_size (), &nregs, NULL, NULL); |
1582 | return tsize == 0 && nregs == 0; | |
e075ae69 RH |
1583 | } |
1584 | \f | |
21a427cc | 1585 | static char *pic_label_name; |
e075ae69 | 1586 | static int pic_label_output; |
21a427cc | 1587 | static char *global_offset_table_name; |
e9a25f70 | 1588 | |
e075ae69 RH |
1589 | /* This function generates code for -fpic that loads %ebx with |
1590 | the return address of the caller and then returns. */ | |
1591 | ||
1592 | void | |
1593 | asm_output_function_prefix (file, name) | |
1594 | FILE *file; | |
3cce094d | 1595 | const char *name ATTRIBUTE_UNUSED; |
e075ae69 RH |
1596 | { |
1597 | rtx xops[2]; | |
1598 | int pic_reg_used = flag_pic && (current_function_uses_pic_offset_table | |
1599 | || current_function_uses_const_pool); | |
1600 | xops[0] = pic_offset_table_rtx; | |
1601 | xops[1] = stack_pointer_rtx; | |
32b5b1aa | 1602 | |
e075ae69 RH |
1603 | /* Deep branch prediction favors having a return for every call. */ |
1604 | if (pic_reg_used && TARGET_DEEP_BRANCH_PREDICTION) | |
32b5b1aa | 1605 | { |
e075ae69 RH |
1606 | if (!pic_label_output) |
1607 | { | |
1608 | /* This used to call ASM_DECLARE_FUNCTION_NAME() but since it's an | |
1609 | internal (non-global) label that's being emitted, it didn't make | |
1610 | sense to have .type information for local labels. This caused | |
1611 | the SCO OpenServer 5.0.4 ELF assembler grief (why are you giving | |
1612 | me debug info for a label that you're declaring non-global?) this | |
1613 | was changed to call ASM_OUTPUT_LABEL() instead. */ | |
32b5b1aa | 1614 | |
e075ae69 | 1615 | ASM_OUTPUT_LABEL (file, pic_label_name); |
e9a25f70 | 1616 | |
e075ae69 RH |
1617 | xops[1] = gen_rtx_MEM (SImode, xops[1]); |
1618 | output_asm_insn ("mov{l}\t{%1, %0|%0, %1}", xops); | |
1619 | output_asm_insn ("ret", xops); | |
0afeb08a | 1620 | |
e075ae69 | 1621 | pic_label_output = 1; |
32b5b1aa | 1622 | } |
32b5b1aa | 1623 | } |
32b5b1aa | 1624 | } |
32b5b1aa | 1625 | |
e075ae69 RH |
1626 | void |
1627 | load_pic_register () | |
32b5b1aa | 1628 | { |
e075ae69 | 1629 | rtx gotsym, pclab; |
32b5b1aa | 1630 | |
21a427cc AS |
1631 | if (global_offset_table_name == NULL) |
1632 | { | |
1633 | global_offset_table_name = | |
1634 | ggc_alloc_string ("_GLOBAL_OFFSET_TABLE_", 21); | |
1635 | ggc_add_string_root (&global_offset_table_name, 1); | |
1636 | } | |
1637 | gotsym = gen_rtx_SYMBOL_REF (Pmode, global_offset_table_name); | |
32b5b1aa | 1638 | |
e075ae69 | 1639 | if (TARGET_DEEP_BRANCH_PREDICTION) |
32b5b1aa | 1640 | { |
21a427cc AS |
1641 | if (pic_label_name == NULL) |
1642 | { | |
1643 | pic_label_name = ggc_alloc_string (NULL, 32); | |
1644 | ggc_add_string_root (&pic_label_name, 1); | |
1645 | ASM_GENERATE_INTERNAL_LABEL (pic_label_name, "LPR", 0); | |
1646 | } | |
e075ae69 | 1647 | pclab = gen_rtx_MEM (QImode, gen_rtx_SYMBOL_REF (Pmode, pic_label_name)); |
32b5b1aa | 1648 | } |
e075ae69 | 1649 | else |
e5cb57e8 | 1650 | { |
e075ae69 | 1651 | pclab = gen_rtx_LABEL_REF (VOIDmode, gen_label_rtx ()); |
e5cb57e8 | 1652 | } |
e5cb57e8 | 1653 | |
e075ae69 | 1654 | emit_insn (gen_prologue_get_pc (pic_offset_table_rtx, pclab)); |
2a2ab3f9 | 1655 | |
e075ae69 RH |
1656 | if (! TARGET_DEEP_BRANCH_PREDICTION) |
1657 | emit_insn (gen_popsi1 (pic_offset_table_rtx)); | |
79325812 | 1658 | |
e075ae69 | 1659 | emit_insn (gen_prologue_set_got (pic_offset_table_rtx, gotsym, pclab)); |
e9a25f70 | 1660 | } |
8dfe5673 | 1661 | |
e075ae69 | 1662 | /* Generate an SImode "push" pattern for input ARG. */ |
e9a25f70 | 1663 | |
e075ae69 RH |
1664 | static rtx |
1665 | gen_push (arg) | |
1666 | rtx arg; | |
e9a25f70 | 1667 | { |
c5c76735 JL |
1668 | return gen_rtx_SET (VOIDmode, |
1669 | gen_rtx_MEM (SImode, | |
1670 | gen_rtx_PRE_DEC (SImode, | |
1671 | stack_pointer_rtx)), | |
1672 | arg); | |
e9a25f70 JL |
1673 | } |
1674 | ||
0903fcab JH |
1675 | /* Return number of registers to be saved on the stack. */ |
1676 | ||
1677 | static int | |
1678 | ix86_nsaved_regs () | |
1679 | { | |
1680 | int nregs = 0; | |
1681 | int pic_reg_used = flag_pic && (current_function_uses_pic_offset_table | |
1682 | || current_function_uses_const_pool); | |
1683 | int limit = (frame_pointer_needed | |
1684 | ? HARD_FRAME_POINTER_REGNUM : STACK_POINTER_REGNUM); | |
1685 | int regno; | |
1686 | ||
1687 | for (regno = limit - 1; regno >= 0; regno--) | |
1688 | if ((regs_ever_live[regno] && ! call_used_regs[regno]) | |
1689 | || (regno == PIC_OFFSET_TABLE_REGNUM && pic_reg_used)) | |
1690 | { | |
1691 | nregs ++; | |
1692 | } | |
1693 | return nregs; | |
1694 | } | |
1695 | ||
1696 | /* Return the offset between two registers, one to be eliminated, and the other | |
1697 | its replacement, at the start of a routine. */ | |
1698 | ||
1699 | HOST_WIDE_INT | |
1700 | ix86_initial_elimination_offset (from, to) | |
1701 | int from; | |
1702 | int to; | |
1703 | { | |
564d80f4 JH |
1704 | int padding1; |
1705 | int nregs; | |
1706 | ||
1707 | /* Stack grows downward: | |
1708 | ||
1709 | [arguments] | |
1710 | <- ARG_POINTER | |
1711 | saved pc | |
1712 | ||
1713 | saved frame pointer if frame_pointer_needed | |
1714 | <- HARD_FRAME_POINTER | |
1c71e60e | 1715 | [saved regs] |
564d80f4 JH |
1716 | |
1717 | [padding1] \ | |
1718 | | <- FRAME_POINTER | |
1719 | [frame] > tsize | |
1720 | | | |
1721 | [padding2] / | |
564d80f4 JH |
1722 | */ |
1723 | ||
1724 | if (from == ARG_POINTER_REGNUM && to == HARD_FRAME_POINTER_REGNUM) | |
1725 | /* Skip saved PC and previous frame pointer. | |
1726 | Executed only when frame_pointer_needed. */ | |
1727 | return 8; | |
1728 | else if (from == FRAME_POINTER_REGNUM | |
1729 | && to == HARD_FRAME_POINTER_REGNUM) | |
1730 | { | |
1731 | ix86_compute_frame_size (get_frame_size (), &nregs, &padding1, (int *)0); | |
1c71e60e | 1732 | padding1 += nregs * UNITS_PER_WORD; |
564d80f4 JH |
1733 | return -padding1; |
1734 | } | |
0903fcab JH |
1735 | else |
1736 | { | |
564d80f4 JH |
1737 | /* ARG_POINTER or FRAME_POINTER to STACK_POINTER elimination. */ |
1738 | int frame_size = frame_pointer_needed ? 8 : 4; | |
0903fcab | 1739 | HOST_WIDE_INT tsize = ix86_compute_frame_size (get_frame_size (), |
564d80f4 | 1740 | &nregs, &padding1, (int *)0); |
0903fcab | 1741 | |
0903fcab | 1742 | |
564d80f4 JH |
1743 | if (to != STACK_POINTER_REGNUM) |
1744 | abort (); | |
1745 | else if (from == ARG_POINTER_REGNUM) | |
1746 | return tsize + nregs * UNITS_PER_WORD + frame_size; | |
1747 | else if (from != FRAME_POINTER_REGNUM) | |
1748 | abort (); | |
0903fcab | 1749 | else |
1c71e60e | 1750 | return tsize - padding1; |
0903fcab JH |
1751 | } |
1752 | } | |
1753 | ||
65954bd8 JL |
1754 | /* Compute the size of local storage taking into consideration the |
1755 | desired stack alignment which is to be maintained. Also determine | |
564d80f4 JH |
1756 | the number of registers saved below the local storage. |
1757 | ||
1758 | PADDING1 returns padding before stack frame and PADDING2 returns | |
1759 | padding after stack frame; | |
1760 | */ | |
1761 | ||
1762 | static HOST_WIDE_INT | |
1763 | ix86_compute_frame_size (size, nregs_on_stack, rpadding1, rpadding2) | |
65954bd8 JL |
1764 | HOST_WIDE_INT size; |
1765 | int *nregs_on_stack; | |
564d80f4 JH |
1766 | int *rpadding1; |
1767 | int *rpadding2; | |
65954bd8 | 1768 | { |
65954bd8 | 1769 | int nregs; |
564d80f4 JH |
1770 | int padding1 = 0; |
1771 | int padding2 = 0; | |
65954bd8 | 1772 | HOST_WIDE_INT total_size; |
564d80f4 | 1773 | int stack_alignment_needed = cfun->stack_alignment_needed / BITS_PER_UNIT; |
44affdae JH |
1774 | int offset; |
1775 | int preferred_alignment = cfun->preferred_stack_boundary / BITS_PER_UNIT; | |
65954bd8 | 1776 | |
564d80f4 | 1777 | nregs = ix86_nsaved_regs (); |
564d80f4 | 1778 | total_size = size; |
65954bd8 | 1779 | |
44affdae | 1780 | offset = frame_pointer_needed ? 8 : 4; |
564d80f4 | 1781 | |
44affdae JH |
1782 | /* Do some sanity checking of stack_alignment_needed and preferred_alignment, |
1783 | since i386 port is the only using those features that may break easilly. */ | |
564d80f4 | 1784 | |
44affdae JH |
1785 | if (size && !stack_alignment_needed) |
1786 | abort (); | |
5f677a9e | 1787 | if (!size && stack_alignment_needed != STACK_BOUNDARY / BITS_PER_UNIT) |
44affdae JH |
1788 | abort (); |
1789 | if (preferred_alignment < STACK_BOUNDARY / BITS_PER_UNIT) | |
1790 | abort (); | |
1791 | if (preferred_alignment > PREFERRED_STACK_BOUNDARY / BITS_PER_UNIT) | |
1792 | abort (); | |
1793 | if (stack_alignment_needed > PREFERRED_STACK_BOUNDARY / BITS_PER_UNIT) | |
1794 | abort (); | |
564d80f4 | 1795 | |
44affdae JH |
1796 | if (stack_alignment_needed < 4) |
1797 | stack_alignment_needed = 4; | |
564d80f4 | 1798 | |
44affdae | 1799 | offset += nregs * UNITS_PER_WORD; |
65954bd8 | 1800 | |
44affdae | 1801 | total_size += offset; |
65954bd8 | 1802 | |
44affdae JH |
1803 | /* Align start of frame for local function. */ |
1804 | padding1 = ((offset + stack_alignment_needed - 1) | |
1805 | & -stack_alignment_needed) - offset; | |
1806 | total_size += padding1; | |
54ff41b7 | 1807 | |
44affdae JH |
1808 | /* Align stack boundary. */ |
1809 | padding2 = ((total_size + preferred_alignment - 1) | |
1810 | & -preferred_alignment) - total_size; | |
65954bd8 JL |
1811 | |
1812 | if (nregs_on_stack) | |
1813 | *nregs_on_stack = nregs; | |
564d80f4 JH |
1814 | if (rpadding1) |
1815 | *rpadding1 = padding1; | |
564d80f4 JH |
1816 | if (rpadding2) |
1817 | *rpadding2 = padding2; | |
1818 | ||
1819 | return size + padding1 + padding2; | |
65954bd8 JL |
1820 | } |
1821 | ||
0903fcab JH |
1822 | /* Emit code to save registers in the prologue. */ |
1823 | ||
1824 | static void | |
1825 | ix86_emit_save_regs () | |
1826 | { | |
1827 | register int regno; | |
1828 | int limit; | |
1829 | rtx insn; | |
1830 | int pic_reg_used = flag_pic && (current_function_uses_pic_offset_table | |
1831 | || current_function_uses_const_pool); | |
1832 | limit = (frame_pointer_needed | |
564d80f4 | 1833 | ? HARD_FRAME_POINTER_REGNUM : STACK_POINTER_REGNUM); |
0903fcab JH |
1834 | |
1835 | for (regno = limit - 1; regno >= 0; regno--) | |
1836 | if ((regs_ever_live[regno] && !call_used_regs[regno]) | |
1837 | || (regno == PIC_OFFSET_TABLE_REGNUM && pic_reg_used)) | |
1838 | { | |
1839 | insn = emit_insn (gen_push (gen_rtx_REG (SImode, regno))); | |
1840 | RTX_FRAME_RELATED_P (insn) = 1; | |
1841 | } | |
1842 | } | |
1843 | ||
e075ae69 RH |
1844 | /* Expand the prologue into a bunch of separate insns. */ |
1845 | ||
1846 | void | |
1847 | ix86_expand_prologue () | |
2a2ab3f9 | 1848 | { |
564d80f4 JH |
1849 | HOST_WIDE_INT tsize = ix86_compute_frame_size (get_frame_size (), (int *)0, (int *)0, |
1850 | (int *)0); | |
1851 | rtx insn; | |
aae75261 JVA |
1852 | int pic_reg_used = flag_pic && (current_function_uses_pic_offset_table |
1853 | || current_function_uses_const_pool); | |
79325812 | 1854 | |
e075ae69 RH |
1855 | /* Note: AT&T enter does NOT have reversed args. Enter is probably |
1856 | slower on all targets. Also sdb doesn't like it. */ | |
e9a25f70 | 1857 | |
2a2ab3f9 JVA |
1858 | if (frame_pointer_needed) |
1859 | { | |
564d80f4 | 1860 | insn = emit_insn (gen_push (hard_frame_pointer_rtx)); |
e075ae69 | 1861 | RTX_FRAME_RELATED_P (insn) = 1; |
e9a25f70 | 1862 | |
564d80f4 | 1863 | insn = emit_move_insn (hard_frame_pointer_rtx, stack_pointer_rtx); |
e075ae69 | 1864 | RTX_FRAME_RELATED_P (insn) = 1; |
2a2ab3f9 JVA |
1865 | } |
1866 | ||
1c71e60e | 1867 | ix86_emit_save_regs (); |
564d80f4 | 1868 | |
8dfe5673 RK |
1869 | if (tsize == 0) |
1870 | ; | |
1871 | else if (! TARGET_STACK_PROBE || tsize < CHECK_STACK_LIMIT) | |
469ac993 | 1872 | { |
e075ae69 | 1873 | if (frame_pointer_needed) |
1c71e60e JH |
1874 | insn = emit_insn (gen_pro_epilogue_adjust_stack |
1875 | (stack_pointer_rtx, stack_pointer_rtx, | |
1876 | GEN_INT (-tsize), hard_frame_pointer_rtx)); | |
79325812 | 1877 | else |
e075ae69 RH |
1878 | insn = emit_insn (gen_addsi3 (stack_pointer_rtx, stack_pointer_rtx, |
1879 | GEN_INT (-tsize))); | |
1880 | RTX_FRAME_RELATED_P (insn) = 1; | |
469ac993 | 1881 | } |
79325812 | 1882 | else |
8dfe5673 | 1883 | { |
e075ae69 | 1884 | /* ??? Is this only valid for Win32? */ |
e9a25f70 | 1885 | |
e075ae69 | 1886 | rtx arg0, sym; |
e9a25f70 | 1887 | |
e075ae69 RH |
1888 | arg0 = gen_rtx_REG (SImode, 0); |
1889 | emit_move_insn (arg0, GEN_INT (tsize)); | |
77a989d1 | 1890 | |
e075ae69 RH |
1891 | sym = gen_rtx_MEM (FUNCTION_MODE, |
1892 | gen_rtx_SYMBOL_REF (Pmode, "_alloca")); | |
1893 | insn = emit_call_insn (gen_call (sym, const0_rtx)); | |
1894 | ||
1895 | CALL_INSN_FUNCTION_USAGE (insn) | |
276ab4a4 RH |
1896 | = gen_rtx_EXPR_LIST (VOIDmode, gen_rtx_USE (VOIDmode, arg0), |
1897 | CALL_INSN_FUNCTION_USAGE (insn)); | |
e075ae69 | 1898 | } |
e9a25f70 | 1899 | |
84530511 SC |
1900 | #ifdef SUBTARGET_PROLOGUE |
1901 | SUBTARGET_PROLOGUE; | |
1902 | #endif | |
1903 | ||
e9a25f70 | 1904 | if (pic_reg_used) |
e075ae69 | 1905 | load_pic_register (); |
77a989d1 | 1906 | |
e9a25f70 JL |
1907 | /* If we are profiling, make sure no instructions are scheduled before |
1908 | the call to mcount. However, if -fpic, the above call will have | |
1909 | done that. */ | |
e075ae69 | 1910 | if ((profile_flag || profile_block_flag) && ! pic_reg_used) |
e9a25f70 | 1911 | emit_insn (gen_blockage ()); |
77a989d1 SC |
1912 | } |
1913 | ||
0903fcab JH |
1914 | /* Emit code to add TSIZE to esp value. Use POP instruction when |
1915 | profitable. */ | |
1916 | ||
1917 | static void | |
1918 | ix86_emit_epilogue_esp_adjustment (tsize) | |
1919 | int tsize; | |
1920 | { | |
1921 | /* Intel's docs say that for 4 or 8 bytes of stack frame one should | |
1922 | use `pop' and not `add'. */ | |
1923 | int use_pop = tsize == 4; | |
1924 | rtx edx = 0, ecx; | |
1925 | ||
1926 | /* Use two pops only for the Pentium processors. */ | |
1927 | if (tsize == 8 && !TARGET_386 && !TARGET_486) | |
1928 | { | |
1929 | rtx retval = current_function_return_rtx; | |
1930 | ||
1931 | edx = gen_rtx_REG (SImode, 1); | |
1932 | ||
1933 | /* This case is a bit more complex. Since we cannot pop into | |
1934 | %ecx twice we need a second register. But this is only | |
1935 | available if the return value is not of DImode in which | |
1936 | case the %edx register is not available. */ | |
1937 | use_pop = (retval == NULL | |
1938 | || !reg_overlap_mentioned_p (edx, retval)); | |
1939 | } | |
1940 | ||
1941 | if (use_pop) | |
1942 | { | |
1943 | ecx = gen_rtx_REG (SImode, 2); | |
1944 | ||
1945 | /* We have to prevent the two pops here from being scheduled. | |
1946 | GCC otherwise would try in some situation to put other | |
1947 | instructions in between them which has a bad effect. */ | |
1948 | emit_insn (gen_blockage ()); | |
1949 | emit_insn (gen_popsi1 (ecx)); | |
1950 | if (tsize == 8) | |
1951 | emit_insn (gen_popsi1 (edx)); | |
1952 | } | |
1953 | else | |
1954 | { | |
1c71e60e JH |
1955 | /* If a frame pointer is present, we must be sure to tie the sp |
1956 | to the fp so that we don't mis-schedule. */ | |
1957 | if (frame_pointer_needed) | |
1958 | emit_insn (gen_pro_epilogue_adjust_stack (stack_pointer_rtx, | |
1959 | stack_pointer_rtx, | |
1960 | GEN_INT (tsize), | |
1961 | hard_frame_pointer_rtx)); | |
1962 | else | |
1963 | emit_insn (gen_addsi3 (stack_pointer_rtx, stack_pointer_rtx, | |
1964 | GEN_INT (tsize))); | |
0903fcab JH |
1965 | } |
1966 | } | |
1967 | ||
da2d1d3a JH |
1968 | /* Emit code to restore saved registers using MOV insns. First register |
1969 | is restored from POINTER + OFFSET. */ | |
1970 | static void | |
1971 | ix86_emit_restore_regs_using_mov (pointer, offset) | |
1972 | rtx pointer; | |
1973 | int offset; | |
1974 | { | |
1975 | int regno; | |
1976 | int pic_reg_used = flag_pic && (current_function_uses_pic_offset_table | |
1977 | || current_function_uses_const_pool); | |
1978 | int limit = (frame_pointer_needed | |
1979 | ? HARD_FRAME_POINTER_REGNUM : STACK_POINTER_REGNUM); | |
1980 | ||
1981 | for (regno = 0; regno < limit; regno++) | |
1982 | if ((regs_ever_live[regno] && !call_used_regs[regno]) | |
1983 | || (regno == PIC_OFFSET_TABLE_REGNUM && pic_reg_used)) | |
1984 | { | |
1985 | emit_move_insn (gen_rtx_REG (SImode, regno), | |
1986 | adj_offsettable_operand (gen_rtx_MEM (SImode, | |
1987 | pointer), | |
1988 | offset)); | |
1989 | offset += 4; | |
1990 | } | |
1991 | } | |
1992 | ||
79325812 | 1993 | /* Restore function stack, frame, and registers. */ |
e9a25f70 | 1994 | |
2a2ab3f9 | 1995 | void |
77a989d1 | 1996 | ix86_expand_epilogue () |
2a2ab3f9 | 1997 | { |
65954bd8 | 1998 | int nregs; |
1c71e60e JH |
1999 | int regno; |
2000 | ||
aae75261 JVA |
2001 | int pic_reg_used = flag_pic && (current_function_uses_pic_offset_table |
2002 | || current_function_uses_const_pool); | |
fdb8a883 | 2003 | int sp_valid = !frame_pointer_needed || current_function_sp_is_unchanging; |
65954bd8 | 2004 | HOST_WIDE_INT offset; |
1c71e60e JH |
2005 | HOST_WIDE_INT tsize = ix86_compute_frame_size (get_frame_size (), &nregs, |
2006 | (int *)0, (int *)0); | |
2a2ab3f9 | 2007 | |
2a2ab3f9 | 2008 | |
1c71e60e JH |
2009 | /* Calculate start of saved registers relative to ebp. */ |
2010 | offset = -nregs * UNITS_PER_WORD; | |
2a2ab3f9 | 2011 | |
1c71e60e JH |
2012 | #ifdef FUNCTION_BLOCK_PROFILER_EXIT |
2013 | if (profile_block_flag == 2) | |
564d80f4 | 2014 | { |
1c71e60e | 2015 | FUNCTION_BLOCK_PROFILER_EXIT; |
564d80f4 | 2016 | } |
1c71e60e | 2017 | #endif |
564d80f4 | 2018 | |
fdb8a883 JW |
2019 | /* If we're only restoring one register and sp is not valid then |
2020 | using a move instruction to restore the register since it's | |
da2d1d3a JH |
2021 | less work than reloading sp and popping the register. |
2022 | ||
2023 | The default code result in stack adjustment using add/lea instruction, | |
2024 | while this code results in LEAVE instruction (or discrete equivalent), | |
2025 | so it is profitable in some other cases as well. Especially when there | |
2026 | are no registers to restore. We also use this code when TARGET_USE_LEAVE | |
2027 | and there is exactly one register to pop. This heruistic may need some | |
2028 | tuning in future. */ | |
2029 | if ((!sp_valid && nregs <= 1) | |
2030 | || (frame_pointer_needed && !nregs && tsize) | |
2031 | || (frame_pointer_needed && TARGET_USE_LEAVE && !optimize_size | |
2032 | && nregs == 1)) | |
2a2ab3f9 | 2033 | { |
da2d1d3a JH |
2034 | /* Restore registers. We can use ebp or esp to address the memory |
2035 | locations. If both are available, default to ebp, since offsets | |
2036 | are known to be small. Only exception is esp pointing directly to the | |
2037 | end of block of saved registers, where we may simplify addressing | |
2038 | mode. */ | |
2039 | ||
2040 | if (!frame_pointer_needed || (sp_valid && !tsize)) | |
2041 | ix86_emit_restore_regs_using_mov (stack_pointer_rtx, tsize); | |
2042 | else | |
2043 | ix86_emit_restore_regs_using_mov (hard_frame_pointer_rtx, offset); | |
2a2ab3f9 | 2044 | |
da2d1d3a JH |
2045 | if (!frame_pointer_needed) |
2046 | ix86_emit_epilogue_esp_adjustment (tsize + nregs * UNITS_PER_WORD); | |
c8c5cb99 | 2047 | /* If not an i386, mov & pop is faster than "leave". */ |
da2d1d3a | 2048 | else if (TARGET_USE_LEAVE || optimize_size) |
564d80f4 | 2049 | emit_insn (gen_leave ()); |
c8c5cb99 | 2050 | else |
2a2ab3f9 | 2051 | { |
1c71e60e JH |
2052 | emit_insn (gen_pro_epilogue_adjust_stack (stack_pointer_rtx, |
2053 | hard_frame_pointer_rtx, | |
2054 | const0_rtx, | |
2055 | hard_frame_pointer_rtx)); | |
564d80f4 | 2056 | emit_insn (gen_popsi1 (hard_frame_pointer_rtx)); |
e9a25f70 JL |
2057 | } |
2058 | } | |
1c71e60e | 2059 | else |
68f654ec | 2060 | { |
1c71e60e JH |
2061 | /* First step is to deallocate the stack frame so that we can |
2062 | pop the registers. */ | |
2063 | if (!sp_valid) | |
2064 | { | |
2065 | if (!frame_pointer_needed) | |
2066 | abort (); | |
2067 | emit_insn (gen_pro_epilogue_adjust_stack (stack_pointer_rtx, | |
2068 | hard_frame_pointer_rtx, | |
2069 | GEN_INT (offset), | |
2070 | hard_frame_pointer_rtx)); | |
2071 | } | |
2072 | else if (tsize) | |
2073 | ix86_emit_epilogue_esp_adjustment (tsize); | |
2074 | ||
2075 | for (regno = 0; regno < STACK_POINTER_REGNUM; regno++) | |
2076 | if ((regs_ever_live[regno] && !call_used_regs[regno]) | |
2077 | || (regno == PIC_OFFSET_TABLE_REGNUM && pic_reg_used)) | |
2078 | emit_insn (gen_popsi1 (gen_rtx_REG (SImode, regno))); | |
68f654ec | 2079 | } |
68f654ec | 2080 | |
2a2ab3f9 JVA |
2081 | if (current_function_pops_args && current_function_args_size) |
2082 | { | |
e075ae69 | 2083 | rtx popc = GEN_INT (current_function_pops_args); |
2a2ab3f9 JVA |
2084 | |
2085 | /* i386 can only pop 32K bytes (maybe 64K? Is it signed?). If | |
2086 | asked to pop more, pop return address, do explicit add, and jump | |
2087 | indirectly to the caller. */ | |
2088 | ||
2089 | if (current_function_pops_args >= 32768) | |
2090 | { | |
e075ae69 | 2091 | rtx ecx = gen_rtx_REG (SImode, 2); |
e9a25f70 | 2092 | |
e075ae69 RH |
2093 | emit_insn (gen_popsi1 (ecx)); |
2094 | emit_insn (gen_addsi3 (stack_pointer_rtx, stack_pointer_rtx, popc)); | |
2095 | emit_indirect_jump (ecx); | |
e9a25f70 | 2096 | } |
79325812 | 2097 | else |
e075ae69 RH |
2098 | emit_jump_insn (gen_return_pop_internal (popc)); |
2099 | } | |
2100 | else | |
2101 | emit_jump_insn (gen_return_internal ()); | |
2102 | } | |
2103 | \f | |
2104 | /* Extract the parts of an RTL expression that is a valid memory address | |
2105 | for an instruction. Return false if the structure of the address is | |
2106 | grossly off. */ | |
2107 | ||
2108 | static int | |
2109 | ix86_decompose_address (addr, out) | |
2110 | register rtx addr; | |
2111 | struct ix86_address *out; | |
2112 | { | |
2113 | rtx base = NULL_RTX; | |
2114 | rtx index = NULL_RTX; | |
2115 | rtx disp = NULL_RTX; | |
2116 | HOST_WIDE_INT scale = 1; | |
2117 | rtx scale_rtx = NULL_RTX; | |
2118 | ||
2119 | if (GET_CODE (addr) == REG || GET_CODE (addr) == SUBREG) | |
2120 | base = addr; | |
2121 | else if (GET_CODE (addr) == PLUS) | |
2122 | { | |
2123 | rtx op0 = XEXP (addr, 0); | |
2124 | rtx op1 = XEXP (addr, 1); | |
2125 | enum rtx_code code0 = GET_CODE (op0); | |
2126 | enum rtx_code code1 = GET_CODE (op1); | |
2127 | ||
2128 | if (code0 == REG || code0 == SUBREG) | |
2129 | { | |
2130 | if (code1 == REG || code1 == SUBREG) | |
2131 | index = op0, base = op1; /* index + base */ | |
2132 | else | |
2133 | base = op0, disp = op1; /* base + displacement */ | |
2134 | } | |
2135 | else if (code0 == MULT) | |
e9a25f70 | 2136 | { |
e075ae69 RH |
2137 | index = XEXP (op0, 0); |
2138 | scale_rtx = XEXP (op0, 1); | |
2139 | if (code1 == REG || code1 == SUBREG) | |
2140 | base = op1; /* index*scale + base */ | |
e9a25f70 | 2141 | else |
e075ae69 RH |
2142 | disp = op1; /* index*scale + disp */ |
2143 | } | |
2144 | else if (code0 == PLUS && GET_CODE (XEXP (op0, 0)) == MULT) | |
2145 | { | |
2146 | index = XEXP (XEXP (op0, 0), 0); /* index*scale + base + disp */ | |
2147 | scale_rtx = XEXP (XEXP (op0, 0), 1); | |
2148 | base = XEXP (op0, 1); | |
2149 | disp = op1; | |
2a2ab3f9 | 2150 | } |
e075ae69 RH |
2151 | else if (code0 == PLUS) |
2152 | { | |
2153 | index = XEXP (op0, 0); /* index + base + disp */ | |
2154 | base = XEXP (op0, 1); | |
2155 | disp = op1; | |
2156 | } | |
2157 | else | |
2158 | return FALSE; | |
2159 | } | |
2160 | else if (GET_CODE (addr) == MULT) | |
2161 | { | |
2162 | index = XEXP (addr, 0); /* index*scale */ | |
2163 | scale_rtx = XEXP (addr, 1); | |
2164 | } | |
2165 | else if (GET_CODE (addr) == ASHIFT) | |
2166 | { | |
2167 | rtx tmp; | |
2168 | ||
2169 | /* We're called for lea too, which implements ashift on occasion. */ | |
2170 | index = XEXP (addr, 0); | |
2171 | tmp = XEXP (addr, 1); | |
2172 | if (GET_CODE (tmp) != CONST_INT) | |
2173 | return FALSE; | |
2174 | scale = INTVAL (tmp); | |
2175 | if ((unsigned HOST_WIDE_INT) scale > 3) | |
2176 | return FALSE; | |
2177 | scale = 1 << scale; | |
2a2ab3f9 | 2178 | } |
2a2ab3f9 | 2179 | else |
e075ae69 RH |
2180 | disp = addr; /* displacement */ |
2181 | ||
2182 | /* Extract the integral value of scale. */ | |
2183 | if (scale_rtx) | |
e9a25f70 | 2184 | { |
e075ae69 RH |
2185 | if (GET_CODE (scale_rtx) != CONST_INT) |
2186 | return FALSE; | |
2187 | scale = INTVAL (scale_rtx); | |
e9a25f70 | 2188 | } |
3b3c6a3f | 2189 | |
e075ae69 RH |
2190 | /* Allow arg pointer and stack pointer as index if there is not scaling */ |
2191 | if (base && index && scale == 1 | |
564d80f4 JH |
2192 | && (index == arg_pointer_rtx || index == frame_pointer_rtx |
2193 | || index == stack_pointer_rtx)) | |
e075ae69 RH |
2194 | { |
2195 | rtx tmp = base; | |
2196 | base = index; | |
2197 | index = tmp; | |
2198 | } | |
2199 | ||
2200 | /* Special case: %ebp cannot be encoded as a base without a displacement. */ | |
564d80f4 JH |
2201 | if ((base == hard_frame_pointer_rtx |
2202 | || base == frame_pointer_rtx | |
2203 | || base == arg_pointer_rtx) && !disp) | |
e075ae69 RH |
2204 | disp = const0_rtx; |
2205 | ||
2206 | /* Special case: on K6, [%esi] makes the instruction vector decoded. | |
2207 | Avoid this by transforming to [%esi+0]. */ | |
2208 | if (ix86_cpu == PROCESSOR_K6 && !optimize_size | |
2209 | && base && !index && !disp | |
329e1d01 | 2210 | && REG_P (base) |
e075ae69 RH |
2211 | && REGNO_REG_CLASS (REGNO (base)) == SIREG) |
2212 | disp = const0_rtx; | |
2213 | ||
2214 | /* Special case: encode reg+reg instead of reg*2. */ | |
2215 | if (!base && index && scale && scale == 2) | |
2216 | base = index, scale = 1; | |
2217 | ||
2218 | /* Special case: scaling cannot be encoded without base or displacement. */ | |
2219 | if (!base && !disp && index && scale != 1) | |
2220 | disp = const0_rtx; | |
2221 | ||
2222 | out->base = base; | |
2223 | out->index = index; | |
2224 | out->disp = disp; | |
2225 | out->scale = scale; | |
3b3c6a3f | 2226 | |
e075ae69 RH |
2227 | return TRUE; |
2228 | } | |
3b3c6a3f | 2229 | |
e075ae69 RH |
2230 | /* Determine if a given CONST RTX is a valid memory displacement |
2231 | in PIC mode. */ | |
2232 | ||
59be65f6 | 2233 | int |
91bb873f RH |
2234 | legitimate_pic_address_disp_p (disp) |
2235 | register rtx disp; | |
2236 | { | |
2237 | if (GET_CODE (disp) != CONST) | |
2238 | return 0; | |
2239 | disp = XEXP (disp, 0); | |
2240 | ||
2241 | if (GET_CODE (disp) == PLUS) | |
2242 | { | |
2243 | if (GET_CODE (XEXP (disp, 1)) != CONST_INT) | |
2244 | return 0; | |
2245 | disp = XEXP (disp, 0); | |
2246 | } | |
2247 | ||
2248 | if (GET_CODE (disp) != UNSPEC | |
2249 | || XVECLEN (disp, 0) != 1) | |
2250 | return 0; | |
2251 | ||
2252 | /* Must be @GOT or @GOTOFF. */ | |
2253 | if (XINT (disp, 1) != 6 | |
2254 | && XINT (disp, 1) != 7) | |
2255 | return 0; | |
2256 | ||
2257 | if (GET_CODE (XVECEXP (disp, 0, 0)) != SYMBOL_REF | |
2258 | && GET_CODE (XVECEXP (disp, 0, 0)) != LABEL_REF) | |
2259 | return 0; | |
2260 | ||
2261 | return 1; | |
2262 | } | |
2263 | ||
e075ae69 RH |
2264 | /* GO_IF_LEGITIMATE_ADDRESS recognizes an RTL expression that is a valid |
2265 | memory address for an instruction. The MODE argument is the machine mode | |
2266 | for the MEM expression that wants to use this address. | |
2267 | ||
2268 | It only recognizes address in canonical form. LEGITIMIZE_ADDRESS should | |
2269 | convert common non-canonical forms to canonical form so that they will | |
2270 | be recognized. */ | |
2271 | ||
3b3c6a3f MM |
2272 | int |
2273 | legitimate_address_p (mode, addr, strict) | |
2274 | enum machine_mode mode; | |
2275 | register rtx addr; | |
2276 | int strict; | |
2277 | { | |
e075ae69 RH |
2278 | struct ix86_address parts; |
2279 | rtx base, index, disp; | |
2280 | HOST_WIDE_INT scale; | |
2281 | const char *reason = NULL; | |
2282 | rtx reason_rtx = NULL_RTX; | |
3b3c6a3f MM |
2283 | |
2284 | if (TARGET_DEBUG_ADDR) | |
2285 | { | |
2286 | fprintf (stderr, | |
e9a25f70 | 2287 | "\n======\nGO_IF_LEGITIMATE_ADDRESS, mode = %s, strict = %d\n", |
3b3c6a3f | 2288 | GET_MODE_NAME (mode), strict); |
3b3c6a3f MM |
2289 | debug_rtx (addr); |
2290 | } | |
2291 | ||
e075ae69 | 2292 | if (! ix86_decompose_address (addr, &parts)) |
3b3c6a3f | 2293 | { |
e075ae69 RH |
2294 | reason = "decomposition failed"; |
2295 | goto error; | |
3b3c6a3f MM |
2296 | } |
2297 | ||
e075ae69 RH |
2298 | base = parts.base; |
2299 | index = parts.index; | |
2300 | disp = parts.disp; | |
2301 | scale = parts.scale; | |
91f0226f | 2302 | |
e075ae69 | 2303 | /* Validate base register. |
e9a25f70 JL |
2304 | |
2305 | Don't allow SUBREG's here, it can lead to spill failures when the base | |
3d771dfd MM |
2306 | is one word out of a two word structure, which is represented internally |
2307 | as a DImode int. */ | |
e9a25f70 | 2308 | |
3b3c6a3f MM |
2309 | if (base) |
2310 | { | |
e075ae69 RH |
2311 | reason_rtx = base; |
2312 | ||
3d771dfd | 2313 | if (GET_CODE (base) != REG) |
3b3c6a3f | 2314 | { |
e075ae69 RH |
2315 | reason = "base is not a register"; |
2316 | goto error; | |
3b3c6a3f MM |
2317 | } |
2318 | ||
c954bd01 RH |
2319 | if (GET_MODE (base) != Pmode) |
2320 | { | |
e075ae69 RH |
2321 | reason = "base is not in Pmode"; |
2322 | goto error; | |
c954bd01 RH |
2323 | } |
2324 | ||
e9a25f70 JL |
2325 | if ((strict && ! REG_OK_FOR_BASE_STRICT_P (base)) |
2326 | || (! strict && ! REG_OK_FOR_BASE_NONSTRICT_P (base))) | |
3b3c6a3f | 2327 | { |
e075ae69 RH |
2328 | reason = "base is not valid"; |
2329 | goto error; | |
3b3c6a3f MM |
2330 | } |
2331 | } | |
2332 | ||
e075ae69 | 2333 | /* Validate index register. |
e9a25f70 JL |
2334 | |
2335 | Don't allow SUBREG's here, it can lead to spill failures when the index | |
3d771dfd MM |
2336 | is one word out of a two word structure, which is represented internally |
2337 | as a DImode int. */ | |
e075ae69 RH |
2338 | |
2339 | if (index) | |
3b3c6a3f | 2340 | { |
e075ae69 RH |
2341 | reason_rtx = index; |
2342 | ||
2343 | if (GET_CODE (index) != REG) | |
3b3c6a3f | 2344 | { |
e075ae69 RH |
2345 | reason = "index is not a register"; |
2346 | goto error; | |
3b3c6a3f MM |
2347 | } |
2348 | ||
e075ae69 | 2349 | if (GET_MODE (index) != Pmode) |
c954bd01 | 2350 | { |
e075ae69 RH |
2351 | reason = "index is not in Pmode"; |
2352 | goto error; | |
c954bd01 RH |
2353 | } |
2354 | ||
e075ae69 RH |
2355 | if ((strict && ! REG_OK_FOR_INDEX_STRICT_P (index)) |
2356 | || (! strict && ! REG_OK_FOR_INDEX_NONSTRICT_P (index))) | |
3b3c6a3f | 2357 | { |
e075ae69 RH |
2358 | reason = "index is not valid"; |
2359 | goto error; | |
3b3c6a3f MM |
2360 | } |
2361 | } | |
3b3c6a3f | 2362 | |
e075ae69 RH |
2363 | /* Validate scale factor. */ |
2364 | if (scale != 1) | |
3b3c6a3f | 2365 | { |
e075ae69 RH |
2366 | reason_rtx = GEN_INT (scale); |
2367 | if (!index) | |
3b3c6a3f | 2368 | { |
e075ae69 RH |
2369 | reason = "scale without index"; |
2370 | goto error; | |
3b3c6a3f MM |
2371 | } |
2372 | ||
e075ae69 | 2373 | if (scale != 2 && scale != 4 && scale != 8) |
3b3c6a3f | 2374 | { |
e075ae69 RH |
2375 | reason = "scale is not a valid multiplier"; |
2376 | goto error; | |
3b3c6a3f MM |
2377 | } |
2378 | } | |
2379 | ||
91bb873f | 2380 | /* Validate displacement. */ |
3b3c6a3f MM |
2381 | if (disp) |
2382 | { | |
e075ae69 RH |
2383 | reason_rtx = disp; |
2384 | ||
91bb873f | 2385 | if (!CONSTANT_ADDRESS_P (disp)) |
3b3c6a3f | 2386 | { |
e075ae69 RH |
2387 | reason = "displacement is not constant"; |
2388 | goto error; | |
3b3c6a3f MM |
2389 | } |
2390 | ||
e075ae69 | 2391 | if (GET_CODE (disp) == CONST_DOUBLE) |
3b3c6a3f | 2392 | { |
e075ae69 RH |
2393 | reason = "displacement is a const_double"; |
2394 | goto error; | |
3b3c6a3f MM |
2395 | } |
2396 | ||
91bb873f | 2397 | if (flag_pic && SYMBOLIC_CONST (disp)) |
3b3c6a3f | 2398 | { |
91bb873f RH |
2399 | if (! legitimate_pic_address_disp_p (disp)) |
2400 | { | |
e075ae69 RH |
2401 | reason = "displacement is an invalid pic construct"; |
2402 | goto error; | |
91bb873f RH |
2403 | } |
2404 | ||
e075ae69 RH |
2405 | /* Verify that a symbolic pic displacement includes |
2406 | the pic_offset_table_rtx register. */ | |
91bb873f | 2407 | if (base != pic_offset_table_rtx |
e075ae69 | 2408 | && (index != pic_offset_table_rtx || scale != 1)) |
91bb873f | 2409 | { |
e075ae69 RH |
2410 | reason = "pic displacement against invalid base"; |
2411 | goto error; | |
91bb873f | 2412 | } |
3b3c6a3f | 2413 | } |
91bb873f | 2414 | else if (HALF_PIC_P ()) |
3b3c6a3f | 2415 | { |
91bb873f | 2416 | if (! HALF_PIC_ADDRESS_P (disp) |
e075ae69 | 2417 | || (base != NULL_RTX || index != NULL_RTX)) |
91bb873f | 2418 | { |
e075ae69 RH |
2419 | reason = "displacement is an invalid half-pic reference"; |
2420 | goto error; | |
91bb873f | 2421 | } |
3b3c6a3f MM |
2422 | } |
2423 | } | |
2424 | ||
e075ae69 | 2425 | /* Everything looks valid. */ |
3b3c6a3f | 2426 | if (TARGET_DEBUG_ADDR) |
e075ae69 | 2427 | fprintf (stderr, "Success.\n"); |
3b3c6a3f | 2428 | return TRUE; |
e075ae69 RH |
2429 | |
2430 | error: | |
2431 | if (TARGET_DEBUG_ADDR) | |
2432 | { | |
2433 | fprintf (stderr, "Error: %s\n", reason); | |
2434 | debug_rtx (reason_rtx); | |
2435 | } | |
2436 | return FALSE; | |
3b3c6a3f | 2437 | } |
3b3c6a3f MM |
2438 | \f |
2439 | /* Return a legitimate reference for ORIG (an address) using the | |
2440 | register REG. If REG is 0, a new pseudo is generated. | |
2441 | ||
91bb873f | 2442 | There are two types of references that must be handled: |
3b3c6a3f MM |
2443 | |
2444 | 1. Global data references must load the address from the GOT, via | |
2445 | the PIC reg. An insn is emitted to do this load, and the reg is | |
2446 | returned. | |
2447 | ||
91bb873f RH |
2448 | 2. Static data references, constant pool addresses, and code labels |
2449 | compute the address as an offset from the GOT, whose base is in | |
2450 | the PIC reg. Static data objects have SYMBOL_REF_FLAG set to | |
2451 | differentiate them from global data objects. The returned | |
2452 | address is the PIC reg + an unspec constant. | |
3b3c6a3f MM |
2453 | |
2454 | GO_IF_LEGITIMATE_ADDRESS rejects symbolic references unless the PIC | |
91bb873f | 2455 | reg also appears in the address. */ |
3b3c6a3f MM |
2456 | |
2457 | rtx | |
2458 | legitimize_pic_address (orig, reg) | |
2459 | rtx orig; | |
2460 | rtx reg; | |
2461 | { | |
2462 | rtx addr = orig; | |
2463 | rtx new = orig; | |
91bb873f | 2464 | rtx base; |
3b3c6a3f | 2465 | |
91bb873f RH |
2466 | if (GET_CODE (addr) == LABEL_REF |
2467 | || (GET_CODE (addr) == SYMBOL_REF | |
2468 | && (CONSTANT_POOL_ADDRESS_P (addr) | |
2469 | || SYMBOL_REF_FLAG (addr)))) | |
3b3c6a3f | 2470 | { |
91bb873f RH |
2471 | /* This symbol may be referenced via a displacement from the PIC |
2472 | base address (@GOTOFF). */ | |
3b3c6a3f | 2473 | |
91bb873f RH |
2474 | current_function_uses_pic_offset_table = 1; |
2475 | new = gen_rtx_UNSPEC (VOIDmode, gen_rtvec (1, addr), 7); | |
2476 | new = gen_rtx_CONST (VOIDmode, new); | |
2477 | new = gen_rtx_PLUS (Pmode, pic_offset_table_rtx, new); | |
3b3c6a3f | 2478 | |
91bb873f RH |
2479 | if (reg != 0) |
2480 | { | |
3b3c6a3f | 2481 | emit_move_insn (reg, new); |
91bb873f | 2482 | new = reg; |
3b3c6a3f | 2483 | } |
3b3c6a3f | 2484 | } |
91bb873f | 2485 | else if (GET_CODE (addr) == SYMBOL_REF) |
3b3c6a3f | 2486 | { |
91bb873f RH |
2487 | /* This symbol must be referenced via a load from the |
2488 | Global Offset Table (@GOT). */ | |
3b3c6a3f | 2489 | |
91bb873f RH |
2490 | current_function_uses_pic_offset_table = 1; |
2491 | new = gen_rtx_UNSPEC (VOIDmode, gen_rtvec (1, addr), 6); | |
2492 | new = gen_rtx_CONST (VOIDmode, new); | |
2493 | new = gen_rtx_PLUS (Pmode, pic_offset_table_rtx, new); | |
2494 | new = gen_rtx_MEM (Pmode, new); | |
2495 | RTX_UNCHANGING_P (new) = 1; | |
3b3c6a3f MM |
2496 | |
2497 | if (reg == 0) | |
2498 | reg = gen_reg_rtx (Pmode); | |
91bb873f RH |
2499 | emit_move_insn (reg, new); |
2500 | new = reg; | |
2501 | } | |
2502 | else | |
2503 | { | |
2504 | if (GET_CODE (addr) == CONST) | |
3b3c6a3f | 2505 | { |
91bb873f RH |
2506 | addr = XEXP (addr, 0); |
2507 | if (GET_CODE (addr) == UNSPEC) | |
2508 | { | |
2509 | /* Check that the unspec is one of the ones we generate? */ | |
2510 | } | |
2511 | else if (GET_CODE (addr) != PLUS) | |
564d80f4 | 2512 | abort (); |
3b3c6a3f | 2513 | } |
91bb873f RH |
2514 | if (GET_CODE (addr) == PLUS) |
2515 | { | |
2516 | rtx op0 = XEXP (addr, 0), op1 = XEXP (addr, 1); | |
e9a25f70 | 2517 | |
91bb873f RH |
2518 | /* Check first to see if this is a constant offset from a @GOTOFF |
2519 | symbol reference. */ | |
2520 | if ((GET_CODE (op0) == LABEL_REF | |
2521 | || (GET_CODE (op0) == SYMBOL_REF | |
2522 | && (CONSTANT_POOL_ADDRESS_P (op0) | |
2523 | || SYMBOL_REF_FLAG (op0)))) | |
2524 | && GET_CODE (op1) == CONST_INT) | |
2525 | { | |
2526 | current_function_uses_pic_offset_table = 1; | |
2527 | new = gen_rtx_UNSPEC (VOIDmode, gen_rtvec (1, op0), 7); | |
2528 | new = gen_rtx_PLUS (VOIDmode, new, op1); | |
2529 | new = gen_rtx_CONST (VOIDmode, new); | |
2530 | new = gen_rtx_PLUS (Pmode, pic_offset_table_rtx, new); | |
2531 | ||
2532 | if (reg != 0) | |
2533 | { | |
2534 | emit_move_insn (reg, new); | |
2535 | new = reg; | |
2536 | } | |
2537 | } | |
2538 | else | |
2539 | { | |
2540 | base = legitimize_pic_address (XEXP (addr, 0), reg); | |
2541 | new = legitimize_pic_address (XEXP (addr, 1), | |
2542 | base == reg ? NULL_RTX : reg); | |
2543 | ||
2544 | if (GET_CODE (new) == CONST_INT) | |
2545 | new = plus_constant (base, INTVAL (new)); | |
2546 | else | |
2547 | { | |
2548 | if (GET_CODE (new) == PLUS && CONSTANT_P (XEXP (new, 1))) | |
2549 | { | |
2550 | base = gen_rtx_PLUS (Pmode, base, XEXP (new, 0)); | |
2551 | new = XEXP (new, 1); | |
2552 | } | |
2553 | new = gen_rtx_PLUS (Pmode, base, new); | |
2554 | } | |
2555 | } | |
2556 | } | |
3b3c6a3f MM |
2557 | } |
2558 | return new; | |
2559 | } | |
2560 | \f | |
3b3c6a3f MM |
2561 | /* Try machine-dependent ways of modifying an illegitimate address |
2562 | to be legitimate. If we find one, return the new, valid address. | |
2563 | This macro is used in only one place: `memory_address' in explow.c. | |
2564 | ||
2565 | OLDX is the address as it was before break_out_memory_refs was called. | |
2566 | In some cases it is useful to look at this to decide what needs to be done. | |
2567 | ||
2568 | MODE and WIN are passed so that this macro can use | |
2569 | GO_IF_LEGITIMATE_ADDRESS. | |
2570 | ||
2571 | It is always safe for this macro to do nothing. It exists to recognize | |
2572 | opportunities to optimize the output. | |
2573 | ||
2574 | For the 80386, we handle X+REG by loading X into a register R and | |
2575 | using R+REG. R will go in a general reg and indexing will be used. | |
2576 | However, if REG is a broken-out memory address or multiplication, | |
2577 | nothing needs to be done because REG can certainly go in a general reg. | |
2578 | ||
2579 | When -fpic is used, special handling is needed for symbolic references. | |
2580 | See comments by legitimize_pic_address in i386.c for details. */ | |
2581 | ||
2582 | rtx | |
2583 | legitimize_address (x, oldx, mode) | |
2584 | register rtx x; | |
bb5177ac | 2585 | register rtx oldx ATTRIBUTE_UNUSED; |
3b3c6a3f MM |
2586 | enum machine_mode mode; |
2587 | { | |
2588 | int changed = 0; | |
2589 | unsigned log; | |
2590 | ||
2591 | if (TARGET_DEBUG_ADDR) | |
2592 | { | |
e9a25f70 JL |
2593 | fprintf (stderr, "\n==========\nLEGITIMIZE_ADDRESS, mode = %s\n", |
2594 | GET_MODE_NAME (mode)); | |
3b3c6a3f MM |
2595 | debug_rtx (x); |
2596 | } | |
2597 | ||
2598 | if (flag_pic && SYMBOLIC_CONST (x)) | |
2599 | return legitimize_pic_address (x, 0); | |
2600 | ||
2601 | /* Canonicalize shifts by 0, 1, 2, 3 into multiply */ | |
2602 | if (GET_CODE (x) == ASHIFT | |
2603 | && GET_CODE (XEXP (x, 1)) == CONST_INT | |
2604 | && (log = (unsigned)exact_log2 (INTVAL (XEXP (x, 1)))) < 4) | |
2605 | { | |
2606 | changed = 1; | |
a269a03c JC |
2607 | x = gen_rtx_MULT (Pmode, force_reg (Pmode, XEXP (x, 0)), |
2608 | GEN_INT (1 << log)); | |
3b3c6a3f MM |
2609 | } |
2610 | ||
2611 | if (GET_CODE (x) == PLUS) | |
2612 | { | |
e9a25f70 JL |
2613 | /* Canonicalize shifts by 0, 1, 2, 3 into multiply. */ |
2614 | ||
3b3c6a3f MM |
2615 | if (GET_CODE (XEXP (x, 0)) == ASHIFT |
2616 | && GET_CODE (XEXP (XEXP (x, 0), 1)) == CONST_INT | |
2617 | && (log = (unsigned)exact_log2 (INTVAL (XEXP (XEXP (x, 0), 1)))) < 4) | |
2618 | { | |
2619 | changed = 1; | |
c5c76735 JL |
2620 | XEXP (x, 0) = gen_rtx_MULT (Pmode, |
2621 | force_reg (Pmode, XEXP (XEXP (x, 0), 0)), | |
2622 | GEN_INT (1 << log)); | |
3b3c6a3f MM |
2623 | } |
2624 | ||
2625 | if (GET_CODE (XEXP (x, 1)) == ASHIFT | |
2626 | && GET_CODE (XEXP (XEXP (x, 1), 1)) == CONST_INT | |
2627 | && (log = (unsigned)exact_log2 (INTVAL (XEXP (XEXP (x, 1), 1)))) < 4) | |
2628 | { | |
2629 | changed = 1; | |
c5c76735 JL |
2630 | XEXP (x, 1) = gen_rtx_MULT (Pmode, |
2631 | force_reg (Pmode, XEXP (XEXP (x, 1), 0)), | |
2632 | GEN_INT (1 << log)); | |
3b3c6a3f MM |
2633 | } |
2634 | ||
e9a25f70 | 2635 | /* Put multiply first if it isn't already. */ |
3b3c6a3f MM |
2636 | if (GET_CODE (XEXP (x, 1)) == MULT) |
2637 | { | |
2638 | rtx tmp = XEXP (x, 0); | |
2639 | XEXP (x, 0) = XEXP (x, 1); | |
2640 | XEXP (x, 1) = tmp; | |
2641 | changed = 1; | |
2642 | } | |
2643 | ||
2644 | /* Canonicalize (plus (mult (reg) (const)) (plus (reg) (const))) | |
2645 | into (plus (plus (mult (reg) (const)) (reg)) (const)). This can be | |
2646 | created by virtual register instantiation, register elimination, and | |
2647 | similar optimizations. */ | |
2648 | if (GET_CODE (XEXP (x, 0)) == MULT && GET_CODE (XEXP (x, 1)) == PLUS) | |
2649 | { | |
2650 | changed = 1; | |
c5c76735 JL |
2651 | x = gen_rtx_PLUS (Pmode, |
2652 | gen_rtx_PLUS (Pmode, XEXP (x, 0), | |
2653 | XEXP (XEXP (x, 1), 0)), | |
2654 | XEXP (XEXP (x, 1), 1)); | |
3b3c6a3f MM |
2655 | } |
2656 | ||
e9a25f70 JL |
2657 | /* Canonicalize |
2658 | (plus (plus (mult (reg) (const)) (plus (reg) (const))) const) | |
3b3c6a3f MM |
2659 | into (plus (plus (mult (reg) (const)) (reg)) (const)). */ |
2660 | else if (GET_CODE (x) == PLUS && GET_CODE (XEXP (x, 0)) == PLUS | |
2661 | && GET_CODE (XEXP (XEXP (x, 0), 0)) == MULT | |
2662 | && GET_CODE (XEXP (XEXP (x, 0), 1)) == PLUS | |
2663 | && CONSTANT_P (XEXP (x, 1))) | |
2664 | { | |
00c79232 ML |
2665 | rtx constant; |
2666 | rtx other = NULL_RTX; | |
3b3c6a3f MM |
2667 | |
2668 | if (GET_CODE (XEXP (x, 1)) == CONST_INT) | |
2669 | { | |
2670 | constant = XEXP (x, 1); | |
2671 | other = XEXP (XEXP (XEXP (x, 0), 1), 1); | |
2672 | } | |
2673 | else if (GET_CODE (XEXP (XEXP (XEXP (x, 0), 1), 1)) == CONST_INT) | |
2674 | { | |
2675 | constant = XEXP (XEXP (XEXP (x, 0), 1), 1); | |
2676 | other = XEXP (x, 1); | |
2677 | } | |
2678 | else | |
2679 | constant = 0; | |
2680 | ||
2681 | if (constant) | |
2682 | { | |
2683 | changed = 1; | |
c5c76735 JL |
2684 | x = gen_rtx_PLUS (Pmode, |
2685 | gen_rtx_PLUS (Pmode, XEXP (XEXP (x, 0), 0), | |
2686 | XEXP (XEXP (XEXP (x, 0), 1), 0)), | |
2687 | plus_constant (other, INTVAL (constant))); | |
3b3c6a3f MM |
2688 | } |
2689 | } | |
2690 | ||
2691 | if (changed && legitimate_address_p (mode, x, FALSE)) | |
2692 | return x; | |
2693 | ||
2694 | if (GET_CODE (XEXP (x, 0)) == MULT) | |
2695 | { | |
2696 | changed = 1; | |
2697 | XEXP (x, 0) = force_operand (XEXP (x, 0), 0); | |
2698 | } | |
2699 | ||
2700 | if (GET_CODE (XEXP (x, 1)) == MULT) | |
2701 | { | |
2702 | changed = 1; | |
2703 | XEXP (x, 1) = force_operand (XEXP (x, 1), 0); | |
2704 | } | |
2705 | ||
2706 | if (changed | |
2707 | && GET_CODE (XEXP (x, 1)) == REG | |
2708 | && GET_CODE (XEXP (x, 0)) == REG) | |
2709 | return x; | |
2710 | ||
2711 | if (flag_pic && SYMBOLIC_CONST (XEXP (x, 1))) | |
2712 | { | |
2713 | changed = 1; | |
2714 | x = legitimize_pic_address (x, 0); | |
2715 | } | |
2716 | ||
2717 | if (changed && legitimate_address_p (mode, x, FALSE)) | |
2718 | return x; | |
2719 | ||
2720 | if (GET_CODE (XEXP (x, 0)) == REG) | |
2721 | { | |
2722 | register rtx temp = gen_reg_rtx (Pmode); | |
2723 | register rtx val = force_operand (XEXP (x, 1), temp); | |
2724 | if (val != temp) | |
2725 | emit_move_insn (temp, val); | |
2726 | ||
2727 | XEXP (x, 1) = temp; | |
2728 | return x; | |
2729 | } | |
2730 | ||
2731 | else if (GET_CODE (XEXP (x, 1)) == REG) | |
2732 | { | |
2733 | register rtx temp = gen_reg_rtx (Pmode); | |
2734 | register rtx val = force_operand (XEXP (x, 0), temp); | |
2735 | if (val != temp) | |
2736 | emit_move_insn (temp, val); | |
2737 | ||
2738 | XEXP (x, 0) = temp; | |
2739 | return x; | |
2740 | } | |
2741 | } | |
2742 | ||
2743 | return x; | |
2744 | } | |
2a2ab3f9 JVA |
2745 | \f |
2746 | /* Print an integer constant expression in assembler syntax. Addition | |
2747 | and subtraction are the only arithmetic that may appear in these | |
2748 | expressions. FILE is the stdio stream to write to, X is the rtx, and | |
2749 | CODE is the operand print code from the output string. */ | |
2750 | ||
2751 | static void | |
2752 | output_pic_addr_const (file, x, code) | |
2753 | FILE *file; | |
2754 | rtx x; | |
2755 | int code; | |
2756 | { | |
2757 | char buf[256]; | |
2758 | ||
2759 | switch (GET_CODE (x)) | |
2760 | { | |
2761 | case PC: | |
2762 | if (flag_pic) | |
2763 | putc ('.', file); | |
2764 | else | |
2765 | abort (); | |
2766 | break; | |
2767 | ||
2768 | case SYMBOL_REF: | |
91bb873f RH |
2769 | assemble_name (file, XSTR (x, 0)); |
2770 | if (code == 'P' && ! SYMBOL_REF_FLAG (x)) | |
2771 | fputs ("@PLT", file); | |
2a2ab3f9 JVA |
2772 | break; |
2773 | ||
91bb873f RH |
2774 | case LABEL_REF: |
2775 | x = XEXP (x, 0); | |
2776 | /* FALLTHRU */ | |
2a2ab3f9 JVA |
2777 | case CODE_LABEL: |
2778 | ASM_GENERATE_INTERNAL_LABEL (buf, "L", CODE_LABEL_NUMBER (x)); | |
2779 | assemble_name (asm_out_file, buf); | |
2780 | break; | |
2781 | ||
2782 | case CONST_INT: | |
f64cecad | 2783 | fprintf (file, HOST_WIDE_INT_PRINT_DEC, INTVAL (x)); |
2a2ab3f9 JVA |
2784 | break; |
2785 | ||
2786 | case CONST: | |
2787 | /* This used to output parentheses around the expression, | |
2788 | but that does not work on the 386 (either ATT or BSD assembler). */ | |
2789 | output_pic_addr_const (file, XEXP (x, 0), code); | |
2790 | break; | |
2791 | ||
2792 | case CONST_DOUBLE: | |
2793 | if (GET_MODE (x) == VOIDmode) | |
2794 | { | |
2795 | /* We can use %d if the number is <32 bits and positive. */ | |
2796 | if (CONST_DOUBLE_HIGH (x) || CONST_DOUBLE_LOW (x) < 0) | |
f64cecad JC |
2797 | fprintf (file, "0x%lx%08lx", |
2798 | (unsigned long) CONST_DOUBLE_HIGH (x), | |
2799 | (unsigned long) CONST_DOUBLE_LOW (x)); | |
2a2ab3f9 | 2800 | else |
f64cecad | 2801 | fprintf (file, HOST_WIDE_INT_PRINT_DEC, CONST_DOUBLE_LOW (x)); |
2a2ab3f9 JVA |
2802 | } |
2803 | else | |
2804 | /* We can't handle floating point constants; | |
2805 | PRINT_OPERAND must handle them. */ | |
2806 | output_operand_lossage ("floating constant misused"); | |
2807 | break; | |
2808 | ||
2809 | case PLUS: | |
e9a25f70 | 2810 | /* Some assemblers need integer constants to appear first. */ |
2a2ab3f9 JVA |
2811 | if (GET_CODE (XEXP (x, 0)) == CONST_INT) |
2812 | { | |
2a2ab3f9 | 2813 | output_pic_addr_const (file, XEXP (x, 0), code); |
e075ae69 | 2814 | putc ('+', file); |
e9a25f70 | 2815 | output_pic_addr_const (file, XEXP (x, 1), code); |
2a2ab3f9 | 2816 | } |
91bb873f | 2817 | else if (GET_CODE (XEXP (x, 1)) == CONST_INT) |
2a2ab3f9 | 2818 | { |
2a2ab3f9 | 2819 | output_pic_addr_const (file, XEXP (x, 1), code); |
e075ae69 | 2820 | putc ('+', file); |
e9a25f70 | 2821 | output_pic_addr_const (file, XEXP (x, 0), code); |
2a2ab3f9 | 2822 | } |
91bb873f RH |
2823 | else |
2824 | abort (); | |
2a2ab3f9 JVA |
2825 | break; |
2826 | ||
2827 | case MINUS: | |
e075ae69 | 2828 | putc (ASSEMBLER_DIALECT ? '(' : '[', file); |
2a2ab3f9 | 2829 | output_pic_addr_const (file, XEXP (x, 0), code); |
e075ae69 | 2830 | putc ('-', file); |
2a2ab3f9 | 2831 | output_pic_addr_const (file, XEXP (x, 1), code); |
e075ae69 | 2832 | putc (ASSEMBLER_DIALECT ? ')' : ']', file); |
2a2ab3f9 JVA |
2833 | break; |
2834 | ||
91bb873f RH |
2835 | case UNSPEC: |
2836 | if (XVECLEN (x, 0) != 1) | |
2837 | abort (); | |
2838 | output_pic_addr_const (file, XVECEXP (x, 0, 0), code); | |
2839 | switch (XINT (x, 1)) | |
2840 | { | |
2841 | case 6: | |
2842 | fputs ("@GOT", file); | |
2843 | break; | |
2844 | case 7: | |
2845 | fputs ("@GOTOFF", file); | |
2846 | break; | |
2847 | case 8: | |
2848 | fputs ("@PLT", file); | |
2849 | break; | |
2850 | default: | |
2851 | output_operand_lossage ("invalid UNSPEC as operand"); | |
2852 | break; | |
2853 | } | |
2854 | break; | |
2855 | ||
2a2ab3f9 JVA |
2856 | default: |
2857 | output_operand_lossage ("invalid expression as operand"); | |
2858 | } | |
2859 | } | |
1865dbb5 JM |
2860 | |
2861 | /* This is called from dwarfout.c via ASM_OUTPUT_DWARF_ADDR_CONST. | |
2862 | We need to handle our special PIC relocations. */ | |
2863 | ||
2864 | void | |
2865 | i386_dwarf_output_addr_const (file, x) | |
2866 | FILE *file; | |
2867 | rtx x; | |
2868 | { | |
2869 | fprintf (file, "\t%s\t", INT_ASM_OP); | |
2870 | if (flag_pic) | |
2871 | output_pic_addr_const (file, x, '\0'); | |
2872 | else | |
2873 | output_addr_const (file, x); | |
2874 | fputc ('\n', file); | |
2875 | } | |
2876 | ||
2877 | /* In the name of slightly smaller debug output, and to cater to | |
2878 | general assembler losage, recognize PIC+GOTOFF and turn it back | |
2879 | into a direct symbol reference. */ | |
2880 | ||
2881 | rtx | |
2882 | i386_simplify_dwarf_addr (orig_x) | |
2883 | rtx orig_x; | |
2884 | { | |
2885 | rtx x = orig_x; | |
2886 | ||
2887 | if (GET_CODE (x) != PLUS | |
2888 | || GET_CODE (XEXP (x, 0)) != REG | |
2889 | || GET_CODE (XEXP (x, 1)) != CONST) | |
2890 | return orig_x; | |
2891 | ||
2892 | x = XEXP (XEXP (x, 1), 0); | |
2893 | if (GET_CODE (x) == UNSPEC | |
2894 | && XINT (x, 1) == 7) | |
2895 | return XVECEXP (x, 0, 0); | |
2896 | ||
2897 | if (GET_CODE (x) == PLUS | |
2898 | && GET_CODE (XEXP (x, 0)) == UNSPEC | |
2899 | && GET_CODE (XEXP (x, 1)) == CONST_INT | |
2900 | && XINT (XEXP (x, 0), 1) == 7) | |
2901 | return gen_rtx_PLUS (VOIDmode, XVECEXP (XEXP (x, 0), 0, 0), XEXP (x, 1)); | |
2902 | ||
2903 | return orig_x; | |
2904 | } | |
2a2ab3f9 | 2905 | \f |
a269a03c | 2906 | static void |
e075ae69 | 2907 | put_condition_code (code, mode, reverse, fp, file) |
a269a03c | 2908 | enum rtx_code code; |
e075ae69 RH |
2909 | enum machine_mode mode; |
2910 | int reverse, fp; | |
a269a03c JC |
2911 | FILE *file; |
2912 | { | |
a269a03c JC |
2913 | const char *suffix; |
2914 | ||
a269a03c JC |
2915 | if (reverse) |
2916 | code = reverse_condition (code); | |
e075ae69 | 2917 | |
a269a03c JC |
2918 | switch (code) |
2919 | { | |
2920 | case EQ: | |
2921 | suffix = "e"; | |
2922 | break; | |
a269a03c JC |
2923 | case NE: |
2924 | suffix = "ne"; | |
2925 | break; | |
a269a03c | 2926 | case GT: |
e075ae69 RH |
2927 | if (mode == CCNOmode) |
2928 | abort (); | |
2929 | suffix = "g"; | |
a269a03c | 2930 | break; |
a269a03c | 2931 | case GTU: |
e075ae69 RH |
2932 | /* ??? Use "nbe" instead of "a" for fcmov losage on some assemblers. |
2933 | Those same assemblers have the same but opposite losage on cmov. */ | |
2934 | suffix = fp ? "nbe" : "a"; | |
a269a03c | 2935 | break; |
a269a03c | 2936 | case LT: |
e075ae69 | 2937 | if (mode == CCNOmode) |
a269a03c JC |
2938 | suffix = "s"; |
2939 | else | |
e075ae69 | 2940 | suffix = "l"; |
a269a03c | 2941 | break; |
a269a03c JC |
2942 | case LTU: |
2943 | suffix = "b"; | |
2944 | break; | |
a269a03c | 2945 | case GE: |
e075ae69 | 2946 | if (mode == CCNOmode) |
a269a03c JC |
2947 | suffix = "ns"; |
2948 | else | |
e075ae69 | 2949 | suffix = "ge"; |
a269a03c | 2950 | break; |
a269a03c | 2951 | case GEU: |
e075ae69 RH |
2952 | /* ??? As above. */ |
2953 | suffix = fp ? "nb" : "ae"; | |
a269a03c | 2954 | break; |
a269a03c | 2955 | case LE: |
e075ae69 RH |
2956 | if (mode == CCNOmode) |
2957 | abort (); | |
2958 | suffix = "le"; | |
a269a03c | 2959 | break; |
a269a03c JC |
2960 | case LEU: |
2961 | suffix = "be"; | |
2962 | break; | |
a269a03c JC |
2963 | default: |
2964 | abort (); | |
2965 | } | |
2966 | fputs (suffix, file); | |
2967 | } | |
2968 | ||
e075ae69 RH |
2969 | void |
2970 | print_reg (x, code, file) | |
2971 | rtx x; | |
2972 | int code; | |
2973 | FILE *file; | |
e5cb57e8 | 2974 | { |
e075ae69 | 2975 | if (REGNO (x) == ARG_POINTER_REGNUM |
564d80f4 | 2976 | || REGNO (x) == FRAME_POINTER_REGNUM |
e075ae69 RH |
2977 | || REGNO (x) == FLAGS_REG |
2978 | || REGNO (x) == FPSR_REG) | |
2979 | abort (); | |
e9a25f70 | 2980 | |
e075ae69 RH |
2981 | if (ASSEMBLER_DIALECT == 0 || USER_LABEL_PREFIX[0] == 0) |
2982 | putc ('%', file); | |
2983 | ||
2984 | if (code == 'w') | |
2985 | code = 2; | |
2986 | else if (code == 'b') | |
2987 | code = 1; | |
2988 | else if (code == 'k') | |
2989 | code = 4; | |
2990 | else if (code == 'y') | |
2991 | code = 3; | |
2992 | else if (code == 'h') | |
2993 | code = 0; | |
2994 | else | |
2995 | code = GET_MODE_SIZE (GET_MODE (x)); | |
e9a25f70 | 2996 | |
e075ae69 RH |
2997 | switch (code) |
2998 | { | |
2999 | case 3: | |
3000 | if (STACK_TOP_P (x)) | |
3001 | { | |
3002 | fputs ("st(0)", file); | |
3003 | break; | |
3004 | } | |
3005 | /* FALLTHRU */ | |
3006 | case 4: | |
3007 | case 8: | |
3008 | case 12: | |
3009 | if (! FP_REG_P (x)) | |
3010 | putc ('e', file); | |
3011 | /* FALLTHRU */ | |
3012 | case 2: | |
3013 | fputs (hi_reg_name[REGNO (x)], file); | |
3014 | break; | |
3015 | case 1: | |
3016 | fputs (qi_reg_name[REGNO (x)], file); | |
3017 | break; | |
3018 | case 0: | |
3019 | fputs (qi_high_reg_name[REGNO (x)], file); | |
3020 | break; | |
3021 | default: | |
3022 | abort (); | |
fe25fea3 | 3023 | } |
e5cb57e8 SC |
3024 | } |
3025 | ||
2a2ab3f9 | 3026 | /* Meaning of CODE: |
fe25fea3 | 3027 | L,W,B,Q,S,T -- print the opcode suffix for specified size of operand. |
e5cb57e8 | 3028 | C -- print opcode suffix for set/cmov insn. |
fe25fea3 | 3029 | c -- like C, but print reversed condition |
2a2ab3f9 JVA |
3030 | R -- print the prefix for register names. |
3031 | z -- print the opcode suffix for the size of the current operand. | |
3032 | * -- print a star (in certain assembler syntax) | |
3033 | w -- print the operand as if it's a "word" (HImode) even if it isn't. | |
2d49677f SC |
3034 | s -- print a shift double count, followed by the assemblers argument |
3035 | delimiter. | |
fe25fea3 SC |
3036 | b -- print the QImode name of the register for the indicated operand. |
3037 | %b0 would print %al if operands[0] is reg 0. | |
3038 | w -- likewise, print the HImode name of the register. | |
3039 | k -- likewise, print the SImode name of the register. | |
3040 | h -- print the QImode name for a "high" register, either ah, bh, ch or dh. | |
e075ae69 | 3041 | y -- print "st(0)" instead of "st" as a register. */ |
2a2ab3f9 JVA |
3042 | |
3043 | void | |
3044 | print_operand (file, x, code) | |
3045 | FILE *file; | |
3046 | rtx x; | |
3047 | int code; | |
3048 | { | |
3049 | if (code) | |
3050 | { | |
3051 | switch (code) | |
3052 | { | |
3053 | case '*': | |
e075ae69 | 3054 | if (ASSEMBLER_DIALECT == 0) |
2a2ab3f9 JVA |
3055 | putc ('*', file); |
3056 | return; | |
3057 | ||
2a2ab3f9 | 3058 | case 'L': |
e075ae69 RH |
3059 | if (ASSEMBLER_DIALECT == 0) |
3060 | putc ('l', file); | |
2a2ab3f9 JVA |
3061 | return; |
3062 | ||
3063 | case 'W': | |
e075ae69 RH |
3064 | if (ASSEMBLER_DIALECT == 0) |
3065 | putc ('w', file); | |
2a2ab3f9 JVA |
3066 | return; |
3067 | ||
3068 | case 'B': | |
e075ae69 RH |
3069 | if (ASSEMBLER_DIALECT == 0) |
3070 | putc ('b', file); | |
2a2ab3f9 JVA |
3071 | return; |
3072 | ||
3073 | case 'Q': | |
e075ae69 RH |
3074 | if (ASSEMBLER_DIALECT == 0) |
3075 | putc ('l', file); | |
2a2ab3f9 JVA |
3076 | return; |
3077 | ||
3078 | case 'S': | |
e075ae69 RH |
3079 | if (ASSEMBLER_DIALECT == 0) |
3080 | putc ('s', file); | |
2a2ab3f9 JVA |
3081 | return; |
3082 | ||
5f1ec3e6 | 3083 | case 'T': |
e075ae69 RH |
3084 | if (ASSEMBLER_DIALECT == 0) |
3085 | putc ('t', file); | |
5f1ec3e6 JVA |
3086 | return; |
3087 | ||
2a2ab3f9 JVA |
3088 | case 'z': |
3089 | /* 387 opcodes don't get size suffixes if the operands are | |
3090 | registers. */ | |
3091 | ||
3092 | if (STACK_REG_P (x)) | |
3093 | return; | |
3094 | ||
e075ae69 RH |
3095 | /* Intel syntax has no truck with instruction suffixes. */ |
3096 | if (ASSEMBLER_DIALECT != 0) | |
3097 | return; | |
3098 | ||
2a2ab3f9 JVA |
3099 | /* this is the size of op from size of operand */ |
3100 | switch (GET_MODE_SIZE (GET_MODE (x))) | |
3101 | { | |
e075ae69 RH |
3102 | case 1: |
3103 | putc ('b', file); | |
3104 | return; | |
3105 | ||
2a2ab3f9 | 3106 | case 2: |
e075ae69 | 3107 | putc ('w', file); |
2a2ab3f9 JVA |
3108 | return; |
3109 | ||
3110 | case 4: | |
3111 | if (GET_MODE (x) == SFmode) | |
3112 | { | |
e075ae69 | 3113 | putc ('s', file); |
2a2ab3f9 JVA |
3114 | return; |
3115 | } | |
3116 | else | |
e075ae69 | 3117 | putc ('l', file); |
2a2ab3f9 JVA |
3118 | return; |
3119 | ||
5f1ec3e6 | 3120 | case 12: |
e075ae69 RH |
3121 | putc ('t', file); |
3122 | return; | |
5f1ec3e6 | 3123 | |
2a2ab3f9 JVA |
3124 | case 8: |
3125 | if (GET_MODE_CLASS (GET_MODE (x)) == MODE_INT) | |
56c0e8fa JVA |
3126 | { |
3127 | #ifdef GAS_MNEMONICS | |
e075ae69 | 3128 | putc ('q', file); |
56c0e8fa | 3129 | #else |
e075ae69 RH |
3130 | putc ('l', file); |
3131 | putc ('l', file); | |
56c0e8fa JVA |
3132 | #endif |
3133 | } | |
e075ae69 RH |
3134 | else |
3135 | putc ('l', file); | |
2a2ab3f9 JVA |
3136 | return; |
3137 | } | |
4af3895e JVA |
3138 | |
3139 | case 'b': | |
3140 | case 'w': | |
3141 | case 'k': | |
3142 | case 'h': | |
3143 | case 'y': | |
5cb6195d | 3144 | case 'X': |
e075ae69 | 3145 | case 'P': |
4af3895e JVA |
3146 | break; |
3147 | ||
2d49677f SC |
3148 | case 's': |
3149 | if (GET_CODE (x) == CONST_INT || ! SHIFT_DOUBLE_OMITS_COUNT) | |
3150 | { | |
3151 | PRINT_OPERAND (file, x, 0); | |
e075ae69 | 3152 | putc (',', file); |
2d49677f | 3153 | } |
a269a03c JC |
3154 | return; |
3155 | ||
1853aadd | 3156 | case 'C': |
e075ae69 | 3157 | put_condition_code (GET_CODE (x), GET_MODE (XEXP (x, 0)), 0, 0, file); |
1853aadd | 3158 | return; |
fe25fea3 | 3159 | case 'F': |
e075ae69 | 3160 | put_condition_code (GET_CODE (x), GET_MODE (XEXP (x, 0)), 0, 1, file); |
fe25fea3 SC |
3161 | return; |
3162 | ||
e9a25f70 | 3163 | /* Like above, but reverse condition */ |
e075ae69 RH |
3164 | case 'c': |
3165 | put_condition_code (GET_CODE (x), GET_MODE (XEXP (x, 0)), 1, 0, file); | |
3166 | return; | |
fe25fea3 | 3167 | case 'f': |
e075ae69 | 3168 | put_condition_code (GET_CODE (x), GET_MODE (XEXP (x, 0)), 1, 1, file); |
1853aadd | 3169 | return; |
e5cb57e8 | 3170 | |
4af3895e | 3171 | default: |
68daafd4 JVA |
3172 | { |
3173 | char str[50]; | |
68daafd4 JVA |
3174 | sprintf (str, "invalid operand code `%c'", code); |
3175 | output_operand_lossage (str); | |
3176 | } | |
2a2ab3f9 JVA |
3177 | } |
3178 | } | |
e9a25f70 | 3179 | |
2a2ab3f9 JVA |
3180 | if (GET_CODE (x) == REG) |
3181 | { | |
3182 | PRINT_REG (x, code, file); | |
3183 | } | |
e9a25f70 | 3184 | |
2a2ab3f9 JVA |
3185 | else if (GET_CODE (x) == MEM) |
3186 | { | |
e075ae69 RH |
3187 | /* No `byte ptr' prefix for call instructions. */ |
3188 | if (ASSEMBLER_DIALECT != 0 && code != 'X' && code != 'P') | |
2a2ab3f9 | 3189 | { |
69ddee61 | 3190 | const char * size; |
e075ae69 RH |
3191 | switch (GET_MODE_SIZE (GET_MODE (x))) |
3192 | { | |
3193 | case 1: size = "BYTE"; break; | |
3194 | case 2: size = "WORD"; break; | |
3195 | case 4: size = "DWORD"; break; | |
3196 | case 8: size = "QWORD"; break; | |
3197 | case 12: size = "XWORD"; break; | |
3198 | default: | |
564d80f4 | 3199 | abort (); |
e075ae69 RH |
3200 | } |
3201 | fputs (size, file); | |
3202 | fputs (" PTR ", file); | |
2a2ab3f9 | 3203 | } |
e075ae69 RH |
3204 | |
3205 | x = XEXP (x, 0); | |
3206 | if (flag_pic && CONSTANT_ADDRESS_P (x)) | |
3207 | output_pic_addr_const (file, x, code); | |
2a2ab3f9 | 3208 | else |
e075ae69 | 3209 | output_address (x); |
2a2ab3f9 | 3210 | } |
e9a25f70 | 3211 | |
2a2ab3f9 JVA |
3212 | else if (GET_CODE (x) == CONST_DOUBLE && GET_MODE (x) == SFmode) |
3213 | { | |
e9a25f70 JL |
3214 | REAL_VALUE_TYPE r; |
3215 | long l; | |
3216 | ||
5f1ec3e6 JVA |
3217 | REAL_VALUE_FROM_CONST_DOUBLE (r, x); |
3218 | REAL_VALUE_TO_TARGET_SINGLE (r, l); | |
e075ae69 RH |
3219 | |
3220 | if (ASSEMBLER_DIALECT == 0) | |
3221 | putc ('$', file); | |
52267fcb | 3222 | fprintf (file, "0x%lx", l); |
5f1ec3e6 | 3223 | } |
e9a25f70 | 3224 | |
5f1ec3e6 JVA |
3225 | /* These float cases don't actually occur as immediate operands. */ |
3226 | else if (GET_CODE (x) == CONST_DOUBLE && GET_MODE (x) == DFmode) | |
3227 | { | |
e9a25f70 JL |
3228 | REAL_VALUE_TYPE r; |
3229 | char dstr[30]; | |
3230 | ||
5f1ec3e6 JVA |
3231 | REAL_VALUE_FROM_CONST_DOUBLE (r, x); |
3232 | REAL_VALUE_TO_DECIMAL (r, "%.22e", dstr); | |
3233 | fprintf (file, "%s", dstr); | |
2a2ab3f9 | 3234 | } |
e9a25f70 | 3235 | |
5f1ec3e6 | 3236 | else if (GET_CODE (x) == CONST_DOUBLE && GET_MODE (x) == XFmode) |
2a2ab3f9 | 3237 | { |
e9a25f70 JL |
3238 | REAL_VALUE_TYPE r; |
3239 | char dstr[30]; | |
3240 | ||
5f1ec3e6 JVA |
3241 | REAL_VALUE_FROM_CONST_DOUBLE (r, x); |
3242 | REAL_VALUE_TO_DECIMAL (r, "%.22e", dstr); | |
3243 | fprintf (file, "%s", dstr); | |
2a2ab3f9 | 3244 | } |
79325812 | 3245 | else |
2a2ab3f9 | 3246 | { |
4af3895e | 3247 | if (code != 'P') |
2a2ab3f9 | 3248 | { |
695dac07 | 3249 | if (GET_CODE (x) == CONST_INT || GET_CODE (x) == CONST_DOUBLE) |
e075ae69 RH |
3250 | { |
3251 | if (ASSEMBLER_DIALECT == 0) | |
3252 | putc ('$', file); | |
3253 | } | |
2a2ab3f9 JVA |
3254 | else if (GET_CODE (x) == CONST || GET_CODE (x) == SYMBOL_REF |
3255 | || GET_CODE (x) == LABEL_REF) | |
e075ae69 RH |
3256 | { |
3257 | if (ASSEMBLER_DIALECT == 0) | |
3258 | putc ('$', file); | |
3259 | else | |
3260 | fputs ("OFFSET FLAT:", file); | |
3261 | } | |
2a2ab3f9 | 3262 | } |
e075ae69 RH |
3263 | if (GET_CODE (x) == CONST_INT) |
3264 | fprintf (file, HOST_WIDE_INT_PRINT_DEC, INTVAL (x)); | |
3265 | else if (flag_pic) | |
2a2ab3f9 JVA |
3266 | output_pic_addr_const (file, x, code); |
3267 | else | |
3268 | output_addr_const (file, x); | |
3269 | } | |
3270 | } | |
3271 | \f | |
3272 | /* Print a memory operand whose address is ADDR. */ | |
3273 | ||
3274 | void | |
3275 | print_operand_address (file, addr) | |
3276 | FILE *file; | |
3277 | register rtx addr; | |
3278 | { | |
e075ae69 RH |
3279 | struct ix86_address parts; |
3280 | rtx base, index, disp; | |
3281 | int scale; | |
e9a25f70 | 3282 | |
e075ae69 RH |
3283 | if (! ix86_decompose_address (addr, &parts)) |
3284 | abort (); | |
e9a25f70 | 3285 | |
e075ae69 RH |
3286 | base = parts.base; |
3287 | index = parts.index; | |
3288 | disp = parts.disp; | |
3289 | scale = parts.scale; | |
e9a25f70 | 3290 | |
e075ae69 RH |
3291 | if (!base && !index) |
3292 | { | |
3293 | /* Displacement only requires special attention. */ | |
e9a25f70 | 3294 | |
e075ae69 | 3295 | if (GET_CODE (disp) == CONST_INT) |
2a2ab3f9 | 3296 | { |
e075ae69 RH |
3297 | if (ASSEMBLER_DIALECT != 0) |
3298 | fputs ("ds:", file); | |
3299 | fprintf (file, HOST_WIDE_INT_PRINT_DEC, INTVAL (addr)); | |
2a2ab3f9 | 3300 | } |
e075ae69 RH |
3301 | else if (flag_pic) |
3302 | output_pic_addr_const (file, addr, 0); | |
3303 | else | |
3304 | output_addr_const (file, addr); | |
3305 | } | |
3306 | else | |
3307 | { | |
3308 | if (ASSEMBLER_DIALECT == 0) | |
2a2ab3f9 | 3309 | { |
e075ae69 | 3310 | if (disp) |
2a2ab3f9 | 3311 | { |
c399861d | 3312 | if (flag_pic) |
e075ae69 RH |
3313 | output_pic_addr_const (file, disp, 0); |
3314 | else if (GET_CODE (disp) == LABEL_REF) | |
3315 | output_asm_label (disp); | |
2a2ab3f9 | 3316 | else |
e075ae69 | 3317 | output_addr_const (file, disp); |
2a2ab3f9 JVA |
3318 | } |
3319 | ||
e075ae69 RH |
3320 | putc ('(', file); |
3321 | if (base) | |
3322 | PRINT_REG (base, 0, file); | |
3323 | if (index) | |
2a2ab3f9 | 3324 | { |
e075ae69 RH |
3325 | putc (',', file); |
3326 | PRINT_REG (index, 0, file); | |
3327 | if (scale != 1) | |
3328 | fprintf (file, ",%d", scale); | |
2a2ab3f9 | 3329 | } |
e075ae69 | 3330 | putc (')', file); |
2a2ab3f9 | 3331 | } |
2a2ab3f9 JVA |
3332 | else |
3333 | { | |
e075ae69 | 3334 | rtx offset = NULL_RTX; |
e9a25f70 | 3335 | |
e075ae69 RH |
3336 | if (disp) |
3337 | { | |
3338 | /* Pull out the offset of a symbol; print any symbol itself. */ | |
3339 | if (GET_CODE (disp) == CONST | |
3340 | && GET_CODE (XEXP (disp, 0)) == PLUS | |
3341 | && GET_CODE (XEXP (XEXP (disp, 0), 1)) == CONST_INT) | |
3342 | { | |
3343 | offset = XEXP (XEXP (disp, 0), 1); | |
3344 | disp = gen_rtx_CONST (VOIDmode, | |
3345 | XEXP (XEXP (disp, 0), 0)); | |
3346 | } | |
ce193852 | 3347 | |
e075ae69 RH |
3348 | if (flag_pic) |
3349 | output_pic_addr_const (file, disp, 0); | |
3350 | else if (GET_CODE (disp) == LABEL_REF) | |
3351 | output_asm_label (disp); | |
3352 | else if (GET_CODE (disp) == CONST_INT) | |
3353 | offset = disp; | |
3354 | else | |
3355 | output_addr_const (file, disp); | |
3356 | } | |
e9a25f70 | 3357 | |
e075ae69 RH |
3358 | putc ('[', file); |
3359 | if (base) | |
a8620236 | 3360 | { |
e075ae69 RH |
3361 | PRINT_REG (base, 0, file); |
3362 | if (offset) | |
3363 | { | |
3364 | if (INTVAL (offset) >= 0) | |
3365 | putc ('+', file); | |
3366 | fprintf (file, HOST_WIDE_INT_PRINT_DEC, INTVAL (offset)); | |
3367 | } | |
a8620236 | 3368 | } |
e075ae69 RH |
3369 | else if (offset) |
3370 | fprintf (file, HOST_WIDE_INT_PRINT_DEC, INTVAL (offset)); | |
2247a58c | 3371 | else |
e075ae69 | 3372 | putc ('0', file); |
e9a25f70 | 3373 | |
e075ae69 RH |
3374 | if (index) |
3375 | { | |
3376 | putc ('+', file); | |
3377 | PRINT_REG (index, 0, file); | |
3378 | if (scale != 1) | |
3379 | fprintf (file, "*%d", scale); | |
3380 | } | |
3381 | putc (']', file); | |
3382 | } | |
2a2ab3f9 JVA |
3383 | } |
3384 | } | |
3385 | \f | |
3386 | /* Split one or more DImode RTL references into pairs of SImode | |
3387 | references. The RTL can be REG, offsettable MEM, integer constant, or | |
3388 | CONST_DOUBLE. "operands" is a pointer to an array of DImode RTL to | |
3389 | split and "num" is its length. lo_half and hi_half are output arrays | |
3390 | that parallel "operands". */ | |
3391 | ||
3392 | void | |
3393 | split_di (operands, num, lo_half, hi_half) | |
3394 | rtx operands[]; | |
3395 | int num; | |
3396 | rtx lo_half[], hi_half[]; | |
3397 | { | |
3398 | while (num--) | |
3399 | { | |
57dbca5e | 3400 | rtx op = operands[num]; |
e075ae69 RH |
3401 | if (CONSTANT_P (op)) |
3402 | split_double (op, &lo_half[num], &hi_half[num]); | |
3403 | else if (! reload_completed) | |
a269a03c JC |
3404 | { |
3405 | lo_half[num] = gen_lowpart (SImode, op); | |
3406 | hi_half[num] = gen_highpart (SImode, op); | |
3407 | } | |
3408 | else if (GET_CODE (op) == REG) | |
2a2ab3f9 | 3409 | { |
57dbca5e BS |
3410 | lo_half[num] = gen_rtx_REG (SImode, REGNO (op)); |
3411 | hi_half[num] = gen_rtx_REG (SImode, REGNO (op) + 1); | |
2a2ab3f9 | 3412 | } |
57dbca5e | 3413 | else if (offsettable_memref_p (op)) |
2a2ab3f9 | 3414 | { |
57dbca5e BS |
3415 | rtx lo_addr = XEXP (op, 0); |
3416 | rtx hi_addr = XEXP (adj_offsettable_operand (op, 4), 0); | |
3417 | lo_half[num] = change_address (op, SImode, lo_addr); | |
3418 | hi_half[num] = change_address (op, SImode, hi_addr); | |
2a2ab3f9 JVA |
3419 | } |
3420 | else | |
564d80f4 | 3421 | abort (); |
2a2ab3f9 JVA |
3422 | } |
3423 | } | |
3424 | \f | |
2a2ab3f9 JVA |
3425 | /* Output code to perform a 387 binary operation in INSN, one of PLUS, |
3426 | MINUS, MULT or DIV. OPERANDS are the insn operands, where operands[3] | |
3427 | is the expression of the binary operation. The output may either be | |
3428 | emitted here, or returned to the caller, like all output_* functions. | |
3429 | ||
3430 | There is no guarantee that the operands are the same mode, as they | |
3431 | might be within FLOAT or FLOAT_EXTEND expressions. */ | |
3432 | ||
69ddee61 | 3433 | const char * |
2a2ab3f9 JVA |
3434 | output_387_binary_op (insn, operands) |
3435 | rtx insn; | |
3436 | rtx *operands; | |
3437 | { | |
2a2ab3f9 | 3438 | static char buf[100]; |
e075ae69 | 3439 | rtx temp; |
69ddee61 | 3440 | const char *p; |
2a2ab3f9 JVA |
3441 | |
3442 | switch (GET_CODE (operands[3])) | |
3443 | { | |
3444 | case PLUS: | |
e075ae69 RH |
3445 | if (GET_MODE_CLASS (GET_MODE (operands[1])) == MODE_INT |
3446 | || GET_MODE_CLASS (GET_MODE (operands[2])) == MODE_INT) | |
3447 | p = "fiadd"; | |
3448 | else | |
3449 | p = "fadd"; | |
2a2ab3f9 JVA |
3450 | break; |
3451 | ||
3452 | case MINUS: | |
e075ae69 RH |
3453 | if (GET_MODE_CLASS (GET_MODE (operands[1])) == MODE_INT |
3454 | || GET_MODE_CLASS (GET_MODE (operands[2])) == MODE_INT) | |
3455 | p = "fisub"; | |
3456 | else | |
3457 | p = "fsub"; | |
2a2ab3f9 JVA |
3458 | break; |
3459 | ||
3460 | case MULT: | |
e075ae69 RH |
3461 | if (GET_MODE_CLASS (GET_MODE (operands[1])) == MODE_INT |
3462 | || GET_MODE_CLASS (GET_MODE (operands[2])) == MODE_INT) | |
3463 | p = "fimul"; | |
3464 | else | |
3465 | p = "fmul"; | |
2a2ab3f9 JVA |
3466 | break; |
3467 | ||
3468 | case DIV: | |
e075ae69 RH |
3469 | if (GET_MODE_CLASS (GET_MODE (operands[1])) == MODE_INT |
3470 | || GET_MODE_CLASS (GET_MODE (operands[2])) == MODE_INT) | |
3471 | p = "fidiv"; | |
3472 | else | |
3473 | p = "fdiv"; | |
2a2ab3f9 JVA |
3474 | break; |
3475 | ||
3476 | default: | |
3477 | abort (); | |
3478 | } | |
3479 | ||
e075ae69 | 3480 | strcpy (buf, p); |
2a2ab3f9 JVA |
3481 | |
3482 | switch (GET_CODE (operands[3])) | |
3483 | { | |
3484 | case MULT: | |
3485 | case PLUS: | |
3486 | if (REG_P (operands[2]) && REGNO (operands[0]) == REGNO (operands[2])) | |
3487 | { | |
3488 | temp = operands[2]; | |
3489 | operands[2] = operands[1]; | |
3490 | operands[1] = temp; | |
3491 | } | |
3492 | ||
3493 | if (GET_CODE (operands[2]) == MEM) | |
e075ae69 RH |
3494 | { |
3495 | p = "%z2\t%2"; | |
3496 | break; | |
3497 | } | |
2a2ab3f9 JVA |
3498 | |
3499 | if (find_regno_note (insn, REG_DEAD, REGNO (operands[2]))) | |
6b28fd63 JL |
3500 | { |
3501 | if (STACK_TOP_P (operands[0])) | |
e075ae69 | 3502 | p = "p\t{%0,%2|%2, %0}"; |
6b28fd63 | 3503 | else |
e075ae69 RH |
3504 | p = "p\t{%2,%0|%0, %2}"; |
3505 | break; | |
6b28fd63 | 3506 | } |
2a2ab3f9 JVA |
3507 | |
3508 | if (STACK_TOP_P (operands[0])) | |
e075ae69 | 3509 | p = "\t{%y2,%0|%0, %y2}"; |
2a2ab3f9 | 3510 | else |
e075ae69 RH |
3511 | p = "\t{%2,%0|%0, %2}"; |
3512 | break; | |
2a2ab3f9 JVA |
3513 | |
3514 | case MINUS: | |
3515 | case DIV: | |
3516 | if (GET_CODE (operands[1]) == MEM) | |
e075ae69 RH |
3517 | { |
3518 | p = "r%z1\t%1"; | |
3519 | break; | |
3520 | } | |
2a2ab3f9 JVA |
3521 | |
3522 | if (GET_CODE (operands[2]) == MEM) | |
e075ae69 RH |
3523 | { |
3524 | p = "%z2\t%2"; | |
3525 | break; | |
3526 | } | |
2a2ab3f9 | 3527 | |
2a2ab3f9 JVA |
3528 | if (! STACK_REG_P (operands[1]) || ! STACK_REG_P (operands[2])) |
3529 | abort (); | |
3530 | ||
e075ae69 RH |
3531 | /* Note that the Unixware assembler, and the AT&T assembler before |
3532 | that, are confusingly not reversed from Intel syntax in this | |
3533 | area. */ | |
2a2ab3f9 | 3534 | if (find_regno_note (insn, REG_DEAD, REGNO (operands[2]))) |
6b28fd63 JL |
3535 | { |
3536 | if (STACK_TOP_P (operands[0])) | |
e075ae69 | 3537 | p = "p\t%0,%2"; |
6b28fd63 | 3538 | else |
e075ae69 RH |
3539 | p = "rp\t%2,%0"; |
3540 | break; | |
6b28fd63 | 3541 | } |
2a2ab3f9 JVA |
3542 | |
3543 | if (find_regno_note (insn, REG_DEAD, REGNO (operands[1]))) | |
6b28fd63 JL |
3544 | { |
3545 | if (STACK_TOP_P (operands[0])) | |
e075ae69 | 3546 | p = "rp\t%0,%1"; |
6b28fd63 | 3547 | else |
e075ae69 RH |
3548 | p = "p\t%1,%0"; |
3549 | break; | |
6b28fd63 | 3550 | } |
2a2ab3f9 JVA |
3551 | |
3552 | if (STACK_TOP_P (operands[0])) | |
3553 | { | |
3554 | if (STACK_TOP_P (operands[1])) | |
e075ae69 | 3555 | p = "\t%y2,%0"; |
2a2ab3f9 | 3556 | else |
e075ae69 RH |
3557 | p = "r\t%y1,%0"; |
3558 | break; | |
2a2ab3f9 JVA |
3559 | } |
3560 | else if (STACK_TOP_P (operands[1])) | |
e075ae69 | 3561 | p = "\t%1,%0"; |
2a2ab3f9 | 3562 | else |
e075ae69 RH |
3563 | p = "r\t%2,%0"; |
3564 | break; | |
2a2ab3f9 JVA |
3565 | |
3566 | default: | |
3567 | abort (); | |
3568 | } | |
e075ae69 RH |
3569 | |
3570 | strcat (buf, p); | |
3571 | return buf; | |
2a2ab3f9 | 3572 | } |
e075ae69 | 3573 | |
2a2ab3f9 | 3574 | /* Output code for INSN to convert a float to a signed int. OPERANDS |
e075ae69 RH |
3575 | are the insn operands. The output may be [SD]Imode and the input |
3576 | operand may be [SDX]Fmode. */ | |
2a2ab3f9 | 3577 | |
69ddee61 | 3578 | const char * |
2a2ab3f9 JVA |
3579 | output_fix_trunc (insn, operands) |
3580 | rtx insn; | |
3581 | rtx *operands; | |
3582 | { | |
3583 | int stack_top_dies = find_regno_note (insn, REG_DEAD, FIRST_STACK_REG) != 0; | |
e075ae69 RH |
3584 | int dimode_p = GET_MODE (operands[0]) == DImode; |
3585 | rtx xops[4]; | |
2a2ab3f9 | 3586 | |
e075ae69 RH |
3587 | /* Jump through a hoop or two for DImode, since the hardware has no |
3588 | non-popping instruction. We used to do this a different way, but | |
3589 | that was somewhat fragile and broke with post-reload splitters. */ | |
a05924f9 JH |
3590 | if (dimode_p && !stack_top_dies) |
3591 | output_asm_insn ("fld\t%y1", operands); | |
e075ae69 RH |
3592 | |
3593 | if (! STACK_TOP_P (operands[1])) | |
10195bd8 JW |
3594 | abort (); |
3595 | ||
e075ae69 RH |
3596 | xops[0] = GEN_INT (12); |
3597 | xops[1] = adj_offsettable_operand (operands[2], 1); | |
3598 | xops[1] = change_address (xops[1], QImode, NULL_RTX); | |
305f097e | 3599 | |
e075ae69 RH |
3600 | xops[2] = operands[0]; |
3601 | if (GET_CODE (operands[0]) != MEM) | |
3602 | xops[2] = operands[3]; | |
2a2ab3f9 | 3603 | |
e075ae69 RH |
3604 | output_asm_insn ("fnstcw\t%2", operands); |
3605 | output_asm_insn ("mov{l}\t{%2, %4|%4, %2}", operands); | |
3606 | output_asm_insn ("mov{b}\t{%0, %1|%1, %0}", xops); | |
3607 | output_asm_insn ("fldcw\t%2", operands); | |
3608 | output_asm_insn ("mov{l}\t{%4, %2|%2, %4}", operands); | |
e9a25f70 | 3609 | |
e075ae69 RH |
3610 | if (stack_top_dies || dimode_p) |
3611 | output_asm_insn ("fistp%z2\t%2", xops); | |
10195bd8 | 3612 | else |
e075ae69 RH |
3613 | output_asm_insn ("fist%z2\t%2", xops); |
3614 | ||
3615 | output_asm_insn ("fldcw\t%2", operands); | |
10195bd8 | 3616 | |
e075ae69 | 3617 | if (GET_CODE (operands[0]) != MEM) |
2a2ab3f9 | 3618 | { |
e075ae69 | 3619 | if (dimode_p) |
2e14a41b | 3620 | { |
e075ae69 RH |
3621 | split_di (operands+0, 1, xops+0, xops+1); |
3622 | split_di (operands+3, 1, xops+2, xops+3); | |
3623 | output_asm_insn ("mov{l}\t{%2, %0|%0, %2}", xops); | |
3624 | output_asm_insn ("mov{l}\t{%3, %1|%1, %3}", xops); | |
2e14a41b | 3625 | } |
e075ae69 RH |
3626 | else |
3627 | output_asm_insn ("mov{l}\t{%3,%0|%0, %3}", operands); | |
2a2ab3f9 | 3628 | } |
2a2ab3f9 | 3629 | |
e075ae69 | 3630 | return ""; |
2a2ab3f9 | 3631 | } |
cda749b1 | 3632 | |
e075ae69 RH |
3633 | /* Output code for INSN to compare OPERANDS. EFLAGS_P is 1 when fcomi |
3634 | should be used and 2 when fnstsw should be used. UNORDERED_P is true | |
3635 | when fucom should be used. */ | |
3636 | ||
69ddee61 | 3637 | const char * |
e075ae69 | 3638 | output_fp_compare (insn, operands, eflags_p, unordered_p) |
cda749b1 JW |
3639 | rtx insn; |
3640 | rtx *operands; | |
e075ae69 | 3641 | int eflags_p, unordered_p; |
cda749b1 | 3642 | { |
e075ae69 RH |
3643 | int stack_top_dies; |
3644 | rtx cmp_op0 = operands[0]; | |
3645 | rtx cmp_op1 = operands[1]; | |
3646 | ||
3647 | if (eflags_p == 2) | |
3648 | { | |
3649 | cmp_op0 = cmp_op1; | |
3650 | cmp_op1 = operands[2]; | |
3651 | } | |
cda749b1 | 3652 | |
e075ae69 | 3653 | if (! STACK_TOP_P (cmp_op0)) |
cda749b1 JW |
3654 | abort (); |
3655 | ||
e075ae69 | 3656 | stack_top_dies = find_regno_note (insn, REG_DEAD, FIRST_STACK_REG) != 0; |
cda749b1 | 3657 | |
e075ae69 RH |
3658 | if (STACK_REG_P (cmp_op1) |
3659 | && stack_top_dies | |
3660 | && find_regno_note (insn, REG_DEAD, REGNO (cmp_op1)) | |
3661 | && REGNO (cmp_op1) != FIRST_STACK_REG) | |
cda749b1 | 3662 | { |
e075ae69 RH |
3663 | /* If both the top of the 387 stack dies, and the other operand |
3664 | is also a stack register that dies, then this must be a | |
3665 | `fcompp' float compare */ | |
3666 | ||
3667 | if (eflags_p == 1) | |
3668 | { | |
3669 | /* There is no double popping fcomi variant. Fortunately, | |
3670 | eflags is immune from the fstp's cc clobbering. */ | |
3671 | if (unordered_p) | |
3672 | output_asm_insn ("fucomip\t{%y1, %0|%0, %y1}", operands); | |
3673 | else | |
3674 | output_asm_insn ("fcomip\t{%y1, %0|%0, %y1}", operands); | |
3675 | return "fstp\t%y0"; | |
3676 | } | |
3677 | else | |
cda749b1 | 3678 | { |
e075ae69 RH |
3679 | if (eflags_p == 2) |
3680 | { | |
3681 | if (unordered_p) | |
3682 | return "fucompp\n\tfnstsw\t%0"; | |
3683 | else | |
3684 | return "fcompp\n\tfnstsw\t%0"; | |
3685 | } | |
cda749b1 JW |
3686 | else |
3687 | { | |
e075ae69 RH |
3688 | if (unordered_p) |
3689 | return "fucompp"; | |
3690 | else | |
3691 | return "fcompp"; | |
cda749b1 JW |
3692 | } |
3693 | } | |
cda749b1 JW |
3694 | } |
3695 | else | |
3696 | { | |
e075ae69 | 3697 | /* Encoded here as eflags_p | intmode | unordered_p | stack_top_dies. */ |
cda749b1 | 3698 | |
69ddee61 | 3699 | static const char * const alt[24] = |
e075ae69 RH |
3700 | { |
3701 | "fcom%z1\t%y1", | |
3702 | "fcomp%z1\t%y1", | |
3703 | "fucom%z1\t%y1", | |
3704 | "fucomp%z1\t%y1", | |
3705 | ||
3706 | "ficom%z1\t%y1", | |
3707 | "ficomp%z1\t%y1", | |
3708 | NULL, | |
3709 | NULL, | |
3710 | ||
3711 | "fcomi\t{%y1, %0|%0, %y1}", | |
3712 | "fcomip\t{%y1, %0|%0, %y1}", | |
3713 | "fucomi\t{%y1, %0|%0, %y1}", | |
3714 | "fucomip\t{%y1, %0|%0, %y1}", | |
3715 | ||
3716 | NULL, | |
3717 | NULL, | |
3718 | NULL, | |
3719 | NULL, | |
3720 | ||
3721 | "fcom%z2\t%y2\n\tfnstsw\t%0", | |
3722 | "fcomp%z2\t%y2\n\tfnstsw\t%0", | |
3723 | "fucom%z2\t%y2\n\tfnstsw\t%0", | |
3724 | "fucomp%z2\t%y2\n\tfnstsw\t%0", | |
3725 | ||
3726 | "ficom%z2\t%y2\n\tfnstsw\t%0", | |
3727 | "ficomp%z2\t%y2\n\tfnstsw\t%0", | |
3728 | NULL, | |
3729 | NULL | |
3730 | }; | |
3731 | ||
3732 | int mask; | |
69ddee61 | 3733 | const char *ret; |
e075ae69 RH |
3734 | |
3735 | mask = eflags_p << 3; | |
3736 | mask |= (GET_MODE_CLASS (GET_MODE (operands[1])) == MODE_INT) << 2; | |
3737 | mask |= unordered_p << 1; | |
3738 | mask |= stack_top_dies; | |
3739 | ||
3740 | if (mask >= 24) | |
3741 | abort (); | |
3742 | ret = alt[mask]; | |
3743 | if (ret == NULL) | |
3744 | abort (); | |
cda749b1 | 3745 | |
e075ae69 | 3746 | return ret; |
cda749b1 JW |
3747 | } |
3748 | } | |
2a2ab3f9 | 3749 | |
e075ae69 | 3750 | /* Output assembler code to FILE to initialize basic-block profiling. |
2a2ab3f9 | 3751 | |
e075ae69 | 3752 | If profile_block_flag == 2 |
2a2ab3f9 | 3753 | |
e075ae69 RH |
3754 | Output code to call the subroutine `__bb_init_trace_func' |
3755 | and pass two parameters to it. The first parameter is | |
3756 | the address of a block allocated in the object module. | |
3757 | The second parameter is the number of the first basic block | |
3758 | of the function. | |
2a2ab3f9 | 3759 | |
e075ae69 RH |
3760 | The name of the block is a local symbol made with this statement: |
3761 | ||
3762 | ASM_GENERATE_INTERNAL_LABEL (BUFFER, "LPBX", 0); | |
2a2ab3f9 | 3763 | |
e075ae69 RH |
3764 | Of course, since you are writing the definition of |
3765 | `ASM_GENERATE_INTERNAL_LABEL' as well as that of this macro, you | |
3766 | can take a short cut in the definition of this macro and use the | |
3767 | name that you know will result. | |
2a2ab3f9 | 3768 | |
e075ae69 RH |
3769 | The number of the first basic block of the function is |
3770 | passed to the macro in BLOCK_OR_LABEL. | |
2a2ab3f9 | 3771 | |
e075ae69 RH |
3772 | If described in a virtual assembler language the code to be |
3773 | output looks like: | |
2a2ab3f9 | 3774 | |
e075ae69 RH |
3775 | parameter1 <- LPBX0 |
3776 | parameter2 <- BLOCK_OR_LABEL | |
3777 | call __bb_init_trace_func | |
2a2ab3f9 | 3778 | |
e075ae69 | 3779 | else if profile_block_flag != 0 |
e74389ff | 3780 | |
e075ae69 RH |
3781 | Output code to call the subroutine `__bb_init_func' |
3782 | and pass one single parameter to it, which is the same | |
3783 | as the first parameter to `__bb_init_trace_func'. | |
e74389ff | 3784 | |
e075ae69 RH |
3785 | The first word of this parameter is a flag which will be nonzero if |
3786 | the object module has already been initialized. So test this word | |
3787 | first, and do not call `__bb_init_func' if the flag is nonzero. | |
3788 | Note: When profile_block_flag == 2 the test need not be done | |
3789 | but `__bb_init_trace_func' *must* be called. | |
e74389ff | 3790 | |
e075ae69 RH |
3791 | BLOCK_OR_LABEL may be used to generate a label number as a |
3792 | branch destination in case `__bb_init_func' will not be called. | |
e74389ff | 3793 | |
e075ae69 RH |
3794 | If described in a virtual assembler language the code to be |
3795 | output looks like: | |
2a2ab3f9 | 3796 | |
e075ae69 RH |
3797 | cmp (LPBX0),0 |
3798 | jne local_label | |
3799 | parameter1 <- LPBX0 | |
3800 | call __bb_init_func | |
3801 | local_label: | |
3802 | */ | |
c572e5ba | 3803 | |
e075ae69 RH |
3804 | void |
3805 | ix86_output_function_block_profiler (file, block_or_label) | |
3806 | FILE *file; | |
3807 | int block_or_label; | |
c572e5ba | 3808 | { |
e075ae69 RH |
3809 | static int num_func = 0; |
3810 | rtx xops[8]; | |
3811 | char block_table[80], false_label[80]; | |
c572e5ba | 3812 | |
e075ae69 | 3813 | ASM_GENERATE_INTERNAL_LABEL (block_table, "LPBX", 0); |
e9a25f70 | 3814 | |
e075ae69 RH |
3815 | xops[1] = gen_rtx_SYMBOL_REF (VOIDmode, block_table); |
3816 | xops[5] = stack_pointer_rtx; | |
3817 | xops[7] = gen_rtx_REG (Pmode, 0); /* eax */ | |
2a2ab3f9 | 3818 | |
e075ae69 | 3819 | CONSTANT_POOL_ADDRESS_P (xops[1]) = TRUE; |
c572e5ba | 3820 | |
e075ae69 | 3821 | switch (profile_block_flag) |
c572e5ba | 3822 | { |
e075ae69 RH |
3823 | case 2: |
3824 | xops[2] = GEN_INT (block_or_label); | |
3825 | xops[3] = gen_rtx_MEM (Pmode, | |
3826 | gen_rtx_SYMBOL_REF (VOIDmode, "__bb_init_trace_func")); | |
3827 | xops[6] = GEN_INT (8); | |
e9a25f70 | 3828 | |
e075ae69 RH |
3829 | output_asm_insn ("push{l}\t%2", xops); |
3830 | if (!flag_pic) | |
3831 | output_asm_insn ("push{l}\t%1", xops); | |
e9a25f70 | 3832 | else |
870a0c2c | 3833 | { |
e075ae69 RH |
3834 | output_asm_insn ("lea{l}\t{%a1, %7|%7, %a1}", xops); |
3835 | output_asm_insn ("push{l}\t%7", xops); | |
870a0c2c | 3836 | } |
e075ae69 RH |
3837 | output_asm_insn ("call\t%P3", xops); |
3838 | output_asm_insn ("add{l}\t{%6, %5|%5, %6}", xops); | |
3839 | break; | |
c572e5ba | 3840 | |
e075ae69 RH |
3841 | default: |
3842 | ASM_GENERATE_INTERNAL_LABEL (false_label, "LPBZ", num_func); | |
c572e5ba | 3843 | |
e075ae69 RH |
3844 | xops[0] = const0_rtx; |
3845 | xops[2] = gen_rtx_MEM (Pmode, | |
3846 | gen_rtx_SYMBOL_REF (VOIDmode, false_label)); | |
3847 | xops[3] = gen_rtx_MEM (Pmode, | |
3848 | gen_rtx_SYMBOL_REF (VOIDmode, "__bb_init_func")); | |
3849 | xops[4] = gen_rtx_MEM (Pmode, xops[1]); | |
3850 | xops[6] = GEN_INT (4); | |
a14003ee | 3851 | |
e075ae69 | 3852 | CONSTANT_POOL_ADDRESS_P (xops[2]) = TRUE; |
446ba526 | 3853 | |
e075ae69 RH |
3854 | output_asm_insn ("cmp{l}\t{%0, %4|%4, %0}", xops); |
3855 | output_asm_insn ("jne\t%2", xops); | |
870a0c2c | 3856 | |
e075ae69 RH |
3857 | if (!flag_pic) |
3858 | output_asm_insn ("push{l}\t%1", xops); | |
3859 | else | |
3860 | { | |
3861 | output_asm_insn ("lea{l}\t{%a1, %7|%7, %a2}", xops); | |
3862 | output_asm_insn ("push{l}\t%7", xops); | |
870a0c2c | 3863 | } |
e075ae69 RH |
3864 | output_asm_insn ("call\t%P3", xops); |
3865 | output_asm_insn ("add{l}\t{%6, %5|%5, %6}", xops); | |
3866 | ASM_OUTPUT_INTERNAL_LABEL (file, "LPBZ", num_func); | |
3867 | num_func++; | |
3868 | break; | |
c572e5ba | 3869 | } |
2a2ab3f9 | 3870 | } |
305f097e | 3871 | |
e075ae69 RH |
3872 | /* Output assembler code to FILE to increment a counter associated |
3873 | with basic block number BLOCKNO. | |
305f097e | 3874 | |
e075ae69 | 3875 | If profile_block_flag == 2 |
ecbc4695 | 3876 | |
e075ae69 RH |
3877 | Output code to initialize the global structure `__bb' and |
3878 | call the function `__bb_trace_func' which will increment the | |
3879 | counter. | |
ecbc4695 | 3880 | |
e075ae69 RH |
3881 | `__bb' consists of two words. In the first word the number |
3882 | of the basic block has to be stored. In the second word | |
3883 | the address of a block allocated in the object module | |
3884 | has to be stored. | |
ecbc4695 | 3885 | |
e075ae69 | 3886 | The basic block number is given by BLOCKNO. |
ecbc4695 | 3887 | |
e075ae69 | 3888 | The address of the block is given by the label created with |
305f097e | 3889 | |
e075ae69 | 3890 | ASM_GENERATE_INTERNAL_LABEL (BUFFER, "LPBX", 0); |
305f097e | 3891 | |
e075ae69 | 3892 | by FUNCTION_BLOCK_PROFILER. |
ecbc4695 | 3893 | |
e075ae69 RH |
3894 | Of course, since you are writing the definition of |
3895 | `ASM_GENERATE_INTERNAL_LABEL' as well as that of this macro, you | |
3896 | can take a short cut in the definition of this macro and use the | |
3897 | name that you know will result. | |
305f097e | 3898 | |
e075ae69 RH |
3899 | If described in a virtual assembler language the code to be |
3900 | output looks like: | |
305f097e | 3901 | |
e075ae69 RH |
3902 | move BLOCKNO -> (__bb) |
3903 | move LPBX0 -> (__bb+4) | |
3904 | call __bb_trace_func | |
305f097e | 3905 | |
e075ae69 RH |
3906 | Note that function `__bb_trace_func' must not change the |
3907 | machine state, especially the flag register. To grant | |
3908 | this, you must output code to save and restore registers | |
3909 | either in this macro or in the macros MACHINE_STATE_SAVE | |
3910 | and MACHINE_STATE_RESTORE. The last two macros will be | |
3911 | used in the function `__bb_trace_func', so you must make | |
3912 | sure that the function prologue does not change any | |
3913 | register prior to saving it with MACHINE_STATE_SAVE. | |
305f097e | 3914 | |
e075ae69 | 3915 | else if profile_block_flag != 0 |
305f097e | 3916 | |
e075ae69 RH |
3917 | Output code to increment the counter directly. |
3918 | Basic blocks are numbered separately from zero within each | |
3919 | compiled object module. The count associated with block number | |
3920 | BLOCKNO is at index BLOCKNO in an array of words; the name of | |
3921 | this array is a local symbol made with this statement: | |
32b5b1aa | 3922 | |
e075ae69 | 3923 | ASM_GENERATE_INTERNAL_LABEL (BUFFER, "LPBX", 2); |
32b5b1aa | 3924 | |
e075ae69 RH |
3925 | Of course, since you are writing the definition of |
3926 | `ASM_GENERATE_INTERNAL_LABEL' as well as that of this macro, you | |
3927 | can take a short cut in the definition of this macro and use the | |
3928 | name that you know will result. | |
32b5b1aa | 3929 | |
e075ae69 RH |
3930 | If described in a virtual assembler language the code to be |
3931 | output looks like: | |
32b5b1aa | 3932 | |
e075ae69 RH |
3933 | inc (LPBX2+4*BLOCKNO) |
3934 | */ | |
32b5b1aa | 3935 | |
e075ae69 RH |
3936 | void |
3937 | ix86_output_block_profiler (file, blockno) | |
3938 | FILE *file ATTRIBUTE_UNUSED; | |
3939 | int blockno; | |
3940 | { | |
3941 | rtx xops[8], cnt_rtx; | |
3942 | char counts[80]; | |
3943 | char *block_table = counts; | |
3944 | ||
3945 | switch (profile_block_flag) | |
3946 | { | |
3947 | case 2: | |
3948 | ASM_GENERATE_INTERNAL_LABEL (block_table, "LPBX", 0); | |
32b5b1aa | 3949 | |
e075ae69 RH |
3950 | xops[1] = gen_rtx_SYMBOL_REF (VOIDmode, block_table); |
3951 | xops[2] = GEN_INT (blockno); | |
3952 | xops[3] = gen_rtx_MEM (Pmode, | |
3953 | gen_rtx_SYMBOL_REF (VOIDmode, "__bb_trace_func")); | |
3954 | xops[4] = gen_rtx_SYMBOL_REF (VOIDmode, "__bb"); | |
3955 | xops[5] = plus_constant (xops[4], 4); | |
3956 | xops[0] = gen_rtx_MEM (SImode, xops[4]); | |
3957 | xops[6] = gen_rtx_MEM (SImode, xops[5]); | |
79325812 | 3958 | |
e075ae69 | 3959 | CONSTANT_POOL_ADDRESS_P (xops[1]) = TRUE; |
32b5b1aa | 3960 | |
e075ae69 RH |
3961 | output_asm_insn ("pushf", xops); |
3962 | output_asm_insn ("mov{l}\t{%2, %0|%0, %2}", xops); | |
3963 | if (flag_pic) | |
32b5b1aa | 3964 | { |
e075ae69 RH |
3965 | xops[7] = gen_rtx_REG (Pmode, 0); /* eax */ |
3966 | output_asm_insn ("push{l}\t%7", xops); | |
3967 | output_asm_insn ("lea{l}\t{%a1, %7|%7, %a1}", xops); | |
3968 | output_asm_insn ("mov{l}\t{%7, %6|%6, %7}", xops); | |
3969 | output_asm_insn ("pop{l}\t%7", xops); | |
3970 | } | |
3971 | else | |
3972 | output_asm_insn ("mov{l}\t{%1, %6|%6, %1}", xops); | |
3973 | output_asm_insn ("call\t%P3", xops); | |
3974 | output_asm_insn ("popf", xops); | |
32b5b1aa | 3975 | |
e075ae69 | 3976 | break; |
32b5b1aa | 3977 | |
e075ae69 RH |
3978 | default: |
3979 | ASM_GENERATE_INTERNAL_LABEL (counts, "LPBX", 2); | |
3980 | cnt_rtx = gen_rtx_SYMBOL_REF (VOIDmode, counts); | |
3981 | SYMBOL_REF_FLAG (cnt_rtx) = TRUE; | |
32b5b1aa | 3982 | |
e075ae69 RH |
3983 | if (blockno) |
3984 | cnt_rtx = plus_constant (cnt_rtx, blockno*4); | |
32b5b1aa | 3985 | |
e075ae69 RH |
3986 | if (flag_pic) |
3987 | cnt_rtx = gen_rtx_PLUS (Pmode, pic_offset_table_rtx, cnt_rtx); | |
32b5b1aa | 3988 | |
e075ae69 RH |
3989 | xops[0] = gen_rtx_MEM (SImode, cnt_rtx); |
3990 | output_asm_insn ("inc{l}\t%0", xops); | |
32b5b1aa | 3991 | |
e075ae69 | 3992 | break; |
32b5b1aa | 3993 | } |
32b5b1aa | 3994 | } |
32b5b1aa | 3995 | \f |
79325812 | 3996 | void |
e075ae69 RH |
3997 | ix86_expand_move (mode, operands) |
3998 | enum machine_mode mode; | |
3999 | rtx operands[]; | |
32b5b1aa | 4000 | { |
e075ae69 | 4001 | int strict = (reload_in_progress || reload_completed); |
e075ae69 | 4002 | rtx insn; |
e9a25f70 | 4003 | |
e075ae69 | 4004 | if (flag_pic && mode == Pmode && symbolic_operand (operands[1], Pmode)) |
32b5b1aa | 4005 | { |
e075ae69 | 4006 | /* Emit insns to move operands[1] into operands[0]. */ |
e9a25f70 | 4007 | |
e075ae69 RH |
4008 | if (GET_CODE (operands[0]) == MEM) |
4009 | operands[1] = force_reg (Pmode, operands[1]); | |
4010 | else | |
32b5b1aa | 4011 | { |
e075ae69 RH |
4012 | rtx temp = operands[0]; |
4013 | if (GET_CODE (temp) != REG) | |
4014 | temp = gen_reg_rtx (Pmode); | |
4015 | temp = legitimize_pic_address (operands[1], temp); | |
4016 | if (temp == operands[0]) | |
4017 | return; | |
4018 | operands[1] = temp; | |
32b5b1aa | 4019 | } |
e075ae69 RH |
4020 | } |
4021 | else | |
4022 | { | |
d7a29404 JH |
4023 | if (GET_CODE (operands[0]) == MEM |
4024 | && (GET_MODE (operands[0]) == QImode | |
4025 | || !push_operand (operands[0], mode)) | |
4026 | && GET_CODE (operands[1]) == MEM) | |
e075ae69 | 4027 | operands[1] = force_reg (mode, operands[1]); |
e9a25f70 | 4028 | |
2c5a510c RH |
4029 | if (push_operand (operands[0], mode) |
4030 | && ! general_no_elim_operand (operands[1], mode)) | |
4031 | operands[1] = copy_to_mode_reg (mode, operands[1]); | |
4032 | ||
e075ae69 | 4033 | if (FLOAT_MODE_P (mode)) |
32b5b1aa | 4034 | { |
d7a29404 JH |
4035 | /* If we are loading a floating point constant to a register, |
4036 | force the value to memory now, since we'll get better code | |
4037 | out the back end. */ | |
e075ae69 RH |
4038 | |
4039 | if (strict) | |
4040 | ; | |
e075ae69 | 4041 | else if (GET_CODE (operands[1]) == CONST_DOUBLE |
d7a29404 | 4042 | && register_operand (operands[0], mode)) |
e075ae69 | 4043 | operands[1] = validize_mem (force_const_mem (mode, operands[1])); |
32b5b1aa | 4044 | } |
32b5b1aa | 4045 | } |
e9a25f70 | 4046 | |
e075ae69 | 4047 | insn = gen_rtx_SET (VOIDmode, operands[0], operands[1]); |
e9a25f70 | 4048 | |
e075ae69 RH |
4049 | emit_insn (insn); |
4050 | } | |
e9a25f70 | 4051 | |
e075ae69 RH |
4052 | /* Attempt to expand a binary operator. Make the expansion closer to the |
4053 | actual machine, then just general_operand, which will allow 3 separate | |
9d81fc27 | 4054 | memory references (one output, two input) in a single insn. */ |
e9a25f70 | 4055 | |
e075ae69 RH |
4056 | void |
4057 | ix86_expand_binary_operator (code, mode, operands) | |
4058 | enum rtx_code code; | |
4059 | enum machine_mode mode; | |
4060 | rtx operands[]; | |
4061 | { | |
4062 | int matching_memory; | |
4063 | rtx src1, src2, dst, op, clob; | |
4064 | ||
4065 | dst = operands[0]; | |
4066 | src1 = operands[1]; | |
4067 | src2 = operands[2]; | |
4068 | ||
4069 | /* Recognize <var1> = <value> <op> <var1> for commutative operators */ | |
4070 | if (GET_RTX_CLASS (code) == 'c' | |
4071 | && (rtx_equal_p (dst, src2) | |
4072 | || immediate_operand (src1, mode))) | |
4073 | { | |
4074 | rtx temp = src1; | |
4075 | src1 = src2; | |
4076 | src2 = temp; | |
32b5b1aa | 4077 | } |
e9a25f70 | 4078 | |
e075ae69 RH |
4079 | /* If the destination is memory, and we do not have matching source |
4080 | operands, do things in registers. */ | |
4081 | matching_memory = 0; | |
4082 | if (GET_CODE (dst) == MEM) | |
32b5b1aa | 4083 | { |
e075ae69 RH |
4084 | if (rtx_equal_p (dst, src1)) |
4085 | matching_memory = 1; | |
4086 | else if (GET_RTX_CLASS (code) == 'c' | |
4087 | && rtx_equal_p (dst, src2)) | |
4088 | matching_memory = 2; | |
4089 | else | |
4090 | dst = gen_reg_rtx (mode); | |
4091 | } | |
4092 | ||
4093 | /* Both source operands cannot be in memory. */ | |
4094 | if (GET_CODE (src1) == MEM && GET_CODE (src2) == MEM) | |
4095 | { | |
4096 | if (matching_memory != 2) | |
4097 | src2 = force_reg (mode, src2); | |
4098 | else | |
4099 | src1 = force_reg (mode, src1); | |
32b5b1aa | 4100 | } |
e9a25f70 | 4101 | |
06a964de JH |
4102 | /* If the operation is not commutable, source 1 cannot be a constant |
4103 | or non-matching memory. */ | |
4104 | if ((CONSTANT_P (src1) | |
4105 | || (!matching_memory && GET_CODE (src1) == MEM)) | |
4106 | && GET_RTX_CLASS (code) != 'c') | |
e075ae69 RH |
4107 | src1 = force_reg (mode, src1); |
4108 | ||
4109 | /* If optimizing, copy to regs to improve CSE */ | |
4110 | if (optimize && !reload_in_progress && !reload_completed) | |
32b5b1aa | 4111 | { |
e075ae69 RH |
4112 | if (GET_CODE (dst) == MEM) |
4113 | dst = gen_reg_rtx (mode); | |
4114 | if (GET_CODE (src1) == MEM) | |
4115 | src1 = force_reg (mode, src1); | |
4116 | if (GET_CODE (src2) == MEM) | |
4117 | src2 = force_reg (mode, src2); | |
32b5b1aa | 4118 | } |
e9a25f70 | 4119 | |
e075ae69 RH |
4120 | /* Emit the instruction. */ |
4121 | ||
4122 | op = gen_rtx_SET (VOIDmode, dst, gen_rtx_fmt_ee (code, mode, src1, src2)); | |
4123 | if (reload_in_progress) | |
4124 | { | |
4125 | /* Reload doesn't know about the flags register, and doesn't know that | |
4126 | it doesn't want to clobber it. We can only do this with PLUS. */ | |
4127 | if (code != PLUS) | |
4128 | abort (); | |
4129 | emit_insn (op); | |
4130 | } | |
4131 | else | |
32b5b1aa | 4132 | { |
e075ae69 RH |
4133 | clob = gen_rtx_CLOBBER (VOIDmode, gen_rtx_REG (CCmode, FLAGS_REG)); |
4134 | emit_insn (gen_rtx_PARALLEL (VOIDmode, gen_rtvec (2, op, clob))); | |
32b5b1aa | 4135 | } |
e9a25f70 | 4136 | |
e075ae69 RH |
4137 | /* Fix up the destination if needed. */ |
4138 | if (dst != operands[0]) | |
4139 | emit_move_insn (operands[0], dst); | |
4140 | } | |
4141 | ||
4142 | /* Return TRUE or FALSE depending on whether the binary operator meets the | |
4143 | appropriate constraints. */ | |
4144 | ||
4145 | int | |
4146 | ix86_binary_operator_ok (code, mode, operands) | |
4147 | enum rtx_code code; | |
4148 | enum machine_mode mode ATTRIBUTE_UNUSED; | |
4149 | rtx operands[3]; | |
4150 | { | |
4151 | /* Both source operands cannot be in memory. */ | |
4152 | if (GET_CODE (operands[1]) == MEM && GET_CODE (operands[2]) == MEM) | |
4153 | return 0; | |
4154 | /* If the operation is not commutable, source 1 cannot be a constant. */ | |
4155 | if (CONSTANT_P (operands[1]) && GET_RTX_CLASS (code) != 'c') | |
4156 | return 0; | |
4157 | /* If the destination is memory, we must have a matching source operand. */ | |
4158 | if (GET_CODE (operands[0]) == MEM | |
4159 | && ! (rtx_equal_p (operands[0], operands[1]) | |
4160 | || (GET_RTX_CLASS (code) == 'c' | |
4161 | && rtx_equal_p (operands[0], operands[2])))) | |
4162 | return 0; | |
06a964de JH |
4163 | /* If the operation is not commutable and the source 1 is memory, we must |
4164 | have a matching destionation. */ | |
4165 | if (GET_CODE (operands[1]) == MEM | |
4166 | && GET_RTX_CLASS (code) != 'c' | |
4167 | && ! rtx_equal_p (operands[0], operands[1])) | |
4168 | return 0; | |
e075ae69 RH |
4169 | return 1; |
4170 | } | |
4171 | ||
4172 | /* Attempt to expand a unary operator. Make the expansion closer to the | |
4173 | actual machine, then just general_operand, which will allow 2 separate | |
9d81fc27 | 4174 | memory references (one output, one input) in a single insn. */ |
e075ae69 | 4175 | |
9d81fc27 | 4176 | void |
e075ae69 RH |
4177 | ix86_expand_unary_operator (code, mode, operands) |
4178 | enum rtx_code code; | |
4179 | enum machine_mode mode; | |
4180 | rtx operands[]; | |
4181 | { | |
06a964de JH |
4182 | int matching_memory; |
4183 | rtx src, dst, op, clob; | |
4184 | ||
4185 | dst = operands[0]; | |
4186 | src = operands[1]; | |
e075ae69 | 4187 | |
06a964de JH |
4188 | /* If the destination is memory, and we do not have matching source |
4189 | operands, do things in registers. */ | |
4190 | matching_memory = 0; | |
4191 | if (GET_CODE (dst) == MEM) | |
32b5b1aa | 4192 | { |
06a964de JH |
4193 | if (rtx_equal_p (dst, src)) |
4194 | matching_memory = 1; | |
e075ae69 | 4195 | else |
06a964de | 4196 | dst = gen_reg_rtx (mode); |
32b5b1aa | 4197 | } |
e9a25f70 | 4198 | |
06a964de JH |
4199 | /* When source operand is memory, destination must match. */ |
4200 | if (!matching_memory && GET_CODE (src) == MEM) | |
4201 | src = force_reg (mode, src); | |
4202 | ||
4203 | /* If optimizing, copy to regs to improve CSE */ | |
4204 | if (optimize && !reload_in_progress && !reload_completed) | |
4205 | { | |
4206 | if (GET_CODE (dst) == MEM) | |
4207 | dst = gen_reg_rtx (mode); | |
4208 | if (GET_CODE (src) == MEM) | |
4209 | src = force_reg (mode, src); | |
4210 | } | |
4211 | ||
4212 | /* Emit the instruction. */ | |
4213 | ||
4214 | op = gen_rtx_SET (VOIDmode, dst, gen_rtx_fmt_e (code, mode, src)); | |
4215 | if (reload_in_progress || code == NOT) | |
4216 | { | |
4217 | /* Reload doesn't know about the flags register, and doesn't know that | |
4218 | it doesn't want to clobber it. */ | |
4219 | if (code != NOT) | |
4220 | abort (); | |
4221 | emit_insn (op); | |
4222 | } | |
4223 | else | |
4224 | { | |
4225 | clob = gen_rtx_CLOBBER (VOIDmode, gen_rtx_REG (CCmode, FLAGS_REG)); | |
4226 | emit_insn (gen_rtx_PARALLEL (VOIDmode, gen_rtvec (2, op, clob))); | |
4227 | } | |
4228 | ||
4229 | /* Fix up the destination if needed. */ | |
4230 | if (dst != operands[0]) | |
4231 | emit_move_insn (operands[0], dst); | |
e075ae69 RH |
4232 | } |
4233 | ||
4234 | /* Return TRUE or FALSE depending on whether the unary operator meets the | |
4235 | appropriate constraints. */ | |
4236 | ||
4237 | int | |
4238 | ix86_unary_operator_ok (code, mode, operands) | |
4239 | enum rtx_code code ATTRIBUTE_UNUSED; | |
4240 | enum machine_mode mode ATTRIBUTE_UNUSED; | |
4241 | rtx operands[2] ATTRIBUTE_UNUSED; | |
4242 | { | |
06a964de JH |
4243 | /* If one of operands is memory, source and destination must match. */ |
4244 | if ((GET_CODE (operands[0]) == MEM | |
4245 | || GET_CODE (operands[1]) == MEM) | |
4246 | && ! rtx_equal_p (operands[0], operands[1])) | |
4247 | return FALSE; | |
e075ae69 RH |
4248 | return TRUE; |
4249 | } | |
4250 | ||
4251 | /* Produce an unsigned comparison for a given signed comparison. */ | |
4252 | ||
4253 | static enum rtx_code | |
4254 | unsigned_comparison (code) | |
4255 | enum rtx_code code; | |
4256 | { | |
4257 | switch (code) | |
32b5b1aa | 4258 | { |
e075ae69 RH |
4259 | case GT: |
4260 | code = GTU; | |
4261 | break; | |
4262 | case LT: | |
4263 | code = LTU; | |
4264 | break; | |
4265 | case GE: | |
4266 | code = GEU; | |
4267 | break; | |
4268 | case LE: | |
4269 | code = LEU; | |
4270 | break; | |
4271 | case EQ: | |
4272 | case NE: | |
4273 | case LEU: | |
4274 | case LTU: | |
4275 | case GEU: | |
4276 | case GTU: | |
4277 | break; | |
4278 | default: | |
4279 | abort (); | |
4280 | } | |
4281 | return code; | |
4282 | } | |
4283 | ||
4284 | /* Generate insn patterns to do an integer compare of OPERANDS. */ | |
4285 | ||
4286 | static rtx | |
4287 | ix86_expand_int_compare (code, op0, op1) | |
4288 | enum rtx_code code; | |
4289 | rtx op0, op1; | |
4290 | { | |
4291 | enum machine_mode cmpmode; | |
4292 | rtx tmp, flags; | |
4293 | ||
4294 | cmpmode = SELECT_CC_MODE (code, op0, op1); | |
4295 | flags = gen_rtx_REG (cmpmode, FLAGS_REG); | |
4296 | ||
4297 | /* This is very simple, but making the interface the same as in the | |
4298 | FP case makes the rest of the code easier. */ | |
4299 | tmp = gen_rtx_COMPARE (cmpmode, op0, op1); | |
4300 | emit_insn (gen_rtx_SET (VOIDmode, flags, tmp)); | |
4301 | ||
4302 | /* Return the test that should be put into the flags user, i.e. | |
4303 | the bcc, scc, or cmov instruction. */ | |
4304 | return gen_rtx_fmt_ee (code, VOIDmode, flags, const0_rtx); | |
4305 | } | |
4306 | ||
4307 | /* Generate insn patterns to do a floating point compare of OPERANDS. | |
4308 | If UNORDERED, allow for unordered compares. */ | |
4309 | ||
4310 | static rtx | |
4311 | ix86_expand_fp_compare (code, op0, op1, unordered) | |
4312 | enum rtx_code code; | |
4313 | rtx op0, op1; | |
4314 | int unordered; | |
4315 | { | |
4316 | enum machine_mode fpcmp_mode; | |
4317 | enum machine_mode intcmp_mode; | |
4318 | rtx tmp; | |
4319 | ||
4320 | /* When not doing IEEE compliant compares, disable unordered. */ | |
4321 | if (! TARGET_IEEE_FP) | |
4322 | unordered = 0; | |
4323 | fpcmp_mode = unordered ? CCFPUmode : CCFPmode; | |
4324 | ||
4325 | /* ??? If we knew whether invalid-operand exceptions were masked, | |
4326 | we could rely on fcom to raise an exception and take care of | |
4327 | NaNs. But we don't. We could know this from c9x math bits. */ | |
4328 | if (TARGET_IEEE_FP) | |
4329 | unordered = 1; | |
4330 | ||
4331 | /* All of the unordered compare instructions only work on registers. | |
4332 | The same is true of the XFmode compare instructions. */ | |
4333 | if (unordered || GET_MODE (op0) == XFmode) | |
4334 | { | |
4335 | op0 = force_reg (GET_MODE (op0), op0); | |
4336 | op1 = force_reg (GET_MODE (op1), op1); | |
4337 | } | |
4338 | else | |
4339 | { | |
4340 | /* %%% We only allow op1 in memory; op0 must be st(0). So swap | |
4341 | things around if they appear profitable, otherwise force op0 | |
4342 | into a register. */ | |
4343 | ||
4344 | if (standard_80387_constant_p (op0) == 0 | |
4345 | || (GET_CODE (op0) == MEM | |
4346 | && ! (standard_80387_constant_p (op1) == 0 | |
4347 | || GET_CODE (op1) == MEM))) | |
32b5b1aa | 4348 | { |
e075ae69 RH |
4349 | rtx tmp; |
4350 | tmp = op0, op0 = op1, op1 = tmp; | |
4351 | code = swap_condition (code); | |
4352 | } | |
4353 | ||
4354 | if (GET_CODE (op0) != REG) | |
4355 | op0 = force_reg (GET_MODE (op0), op0); | |
4356 | ||
4357 | if (CONSTANT_P (op1)) | |
4358 | { | |
4359 | if (standard_80387_constant_p (op1)) | |
4360 | op1 = force_reg (GET_MODE (op1), op1); | |
4361 | else | |
4362 | op1 = validize_mem (force_const_mem (GET_MODE (op1), op1)); | |
32b5b1aa SC |
4363 | } |
4364 | } | |
e9a25f70 | 4365 | |
e075ae69 RH |
4366 | /* %%% fcomi is probably always faster, even when dealing with memory, |
4367 | since compare-and-branch would be three insns instead of four. */ | |
4368 | if (TARGET_CMOVE && !unordered) | |
32b5b1aa | 4369 | { |
e075ae69 RH |
4370 | if (GET_CODE (op0) != REG) |
4371 | op0 = force_reg (GET_MODE (op0), op0); | |
4372 | if (GET_CODE (op1) != REG) | |
4373 | op1 = force_reg (GET_MODE (op1), op1); | |
4374 | ||
4375 | tmp = gen_rtx_COMPARE (fpcmp_mode, op0, op1); | |
4376 | tmp = gen_rtx_SET (VOIDmode, gen_rtx_REG (fpcmp_mode, FLAGS_REG), tmp); | |
4377 | emit_insn (tmp); | |
4378 | ||
4379 | /* The FP codes work out to act like unsigned. */ | |
4380 | code = unsigned_comparison (code); | |
4381 | intcmp_mode = fpcmp_mode; | |
4382 | } | |
4383 | else | |
4384 | { | |
4385 | /* Sadness wrt reg-stack pops killing fpsr -- gotta get fnstsw first. */ | |
e9a25f70 | 4386 | |
e075ae69 RH |
4387 | rtx tmp2; |
4388 | tmp = gen_rtx_COMPARE (fpcmp_mode, op0, op1); | |
4389 | tmp2 = gen_rtx_UNSPEC (HImode, gen_rtvec (1, tmp), 9); | |
4390 | tmp = gen_reg_rtx (HImode); | |
4391 | emit_insn (gen_rtx_SET (VOIDmode, tmp, tmp2)); | |
4392 | ||
4393 | if (! unordered) | |
32b5b1aa | 4394 | { |
e075ae69 RH |
4395 | /* We have two options here -- use sahf, or testing bits of ah |
4396 | directly. On PPRO, they are equivalent, sahf being one byte | |
4397 | smaller. On Pentium, sahf is non-pairable while test is UV | |
4398 | pairable. */ | |
4399 | ||
4400 | if (TARGET_USE_SAHF || optimize_size) | |
32b5b1aa | 4401 | { |
e075ae69 | 4402 | do_sahf: |
e9a25f70 | 4403 | |
e075ae69 RH |
4404 | /* The FP codes work out to act like unsigned. */ |
4405 | code = unsigned_comparison (code); | |
4406 | emit_insn (gen_x86_sahf_1 (tmp)); | |
4407 | intcmp_mode = CCmode; | |
32b5b1aa SC |
4408 | } |
4409 | else | |
4410 | { | |
e075ae69 RH |
4411 | /* |
4412 | * The numbers below correspond to the bits of the FPSW in AH. | |
d22ce03d | 4413 | * C3, C2, and C0 are in bits 0x40, 0x4, and 0x01 respectively. |
e075ae69 RH |
4414 | * |
4415 | * cmp C3 C2 C0 | |
4416 | * > 0 0 0 | |
4417 | * < 0 0 1 | |
4418 | * = 1 0 0 | |
4419 | * un 1 1 1 | |
4420 | */ | |
4421 | ||
4422 | int mask; | |
4423 | ||
4424 | switch (code) | |
32b5b1aa | 4425 | { |
e075ae69 | 4426 | case GT: |
d22ce03d | 4427 | mask = 0x41; |
e075ae69 RH |
4428 | code = EQ; |
4429 | break; | |
4430 | case LT: | |
4431 | mask = 0x01; | |
4432 | code = NE; | |
4433 | break; | |
4434 | case GE: | |
4435 | /* We'd have to use `xorb 1,ah; andb 0x41,ah', so it's | |
4436 | faster in all cases to just fall back on sahf. */ | |
4437 | goto do_sahf; | |
4438 | case LE: | |
4439 | mask = 0x41; | |
4440 | code = NE; | |
4441 | break; | |
4442 | case EQ: | |
4443 | mask = 0x40; | |
4444 | code = NE; | |
4445 | break; | |
4446 | case NE: | |
4447 | mask = 0x40; | |
4448 | code = EQ; | |
4449 | break; | |
4450 | default: | |
4451 | abort (); | |
32b5b1aa | 4452 | } |
e075ae69 RH |
4453 | |
4454 | emit_insn (gen_testqi_ext_0 (tmp, GEN_INT (mask))); | |
4455 | intcmp_mode = CCNOmode; | |
32b5b1aa SC |
4456 | } |
4457 | } | |
4458 | else | |
4459 | { | |
e075ae69 RH |
4460 | /* In the unordered case, we have to check C2 for NaN's, which |
4461 | doesn't happen to work out to anything nice combination-wise. | |
4462 | So do some bit twiddling on the value we've got in AH to come | |
4463 | up with an appropriate set of condition codes. */ | |
4464 | ||
4465 | intcmp_mode = CCNOmode; | |
4466 | switch (code) | |
32b5b1aa | 4467 | { |
e075ae69 RH |
4468 | case GT: |
4469 | emit_insn (gen_testqi_ext_0 (tmp, GEN_INT (0x45))); | |
4470 | code = EQ; | |
4471 | break; | |
4472 | case LT: | |
4473 | emit_insn (gen_andqi_ext_0 (tmp, tmp, GEN_INT (0x45))); | |
4474 | emit_insn (gen_cmpqi_ext_3 (tmp, GEN_INT (0x01))); | |
4475 | intcmp_mode = CCmode; | |
4476 | code = EQ; | |
4477 | break; | |
4478 | case GE: | |
4479 | emit_insn (gen_testqi_ext_0 (tmp, GEN_INT (0x05))); | |
4480 | code = EQ; | |
4481 | break; | |
4482 | case LE: | |
4483 | emit_insn (gen_andqi_ext_0 (tmp, tmp, GEN_INT (0x45))); | |
4484 | emit_insn (gen_addqi_ext_1 (tmp, tmp, constm1_rtx)); | |
4485 | emit_insn (gen_cmpqi_ext_3 (tmp, GEN_INT (0x40))); | |
4486 | intcmp_mode = CCmode; | |
4487 | code = LTU; | |
4488 | break; | |
4489 | case EQ: | |
4490 | emit_insn (gen_andqi_ext_0 (tmp, tmp, GEN_INT (0x45))); | |
4491 | emit_insn (gen_cmpqi_ext_3 (tmp, GEN_INT (0x40))); | |
4492 | intcmp_mode = CCmode; | |
4493 | code = EQ; | |
4494 | break; | |
4495 | case NE: | |
4496 | emit_insn (gen_andqi_ext_0 (tmp, tmp, GEN_INT (0x45))); | |
7abd4e00 | 4497 | emit_insn (gen_xorqi_cc_ext_1 (tmp, tmp, GEN_INT (0x40))); |
e075ae69 RH |
4498 | code = NE; |
4499 | break; | |
4500 | default: | |
4501 | abort (); | |
32b5b1aa SC |
4502 | } |
4503 | } | |
32b5b1aa | 4504 | } |
e075ae69 RH |
4505 | |
4506 | /* Return the test that should be put into the flags user, i.e. | |
4507 | the bcc, scc, or cmov instruction. */ | |
4508 | return gen_rtx_fmt_ee (code, VOIDmode, | |
4509 | gen_rtx_REG (intcmp_mode, FLAGS_REG), | |
4510 | const0_rtx); | |
4511 | } | |
4512 | ||
4513 | static rtx | |
4514 | ix86_expand_compare (code, unordered) | |
4515 | enum rtx_code code; | |
4516 | int unordered; | |
4517 | { | |
4518 | rtx op0, op1, ret; | |
4519 | op0 = ix86_compare_op0; | |
4520 | op1 = ix86_compare_op1; | |
4521 | ||
4522 | if (GET_MODE_CLASS (GET_MODE (op0)) == MODE_FLOAT) | |
4523 | ret = ix86_expand_fp_compare (code, op0, op1, unordered); | |
32b5b1aa | 4524 | else |
e075ae69 RH |
4525 | ret = ix86_expand_int_compare (code, op0, op1); |
4526 | ||
4527 | return ret; | |
4528 | } | |
4529 | ||
4530 | void | |
4531 | ix86_expand_branch (code, unordered, label) | |
4532 | enum rtx_code code; | |
4533 | int unordered; | |
4534 | rtx label; | |
4535 | { | |
4536 | rtx tmp, lo[2], hi[2], label2; | |
4537 | enum rtx_code code1, code2, code3; | |
4538 | ||
4539 | if (GET_MODE (ix86_compare_op0) != DImode) | |
32b5b1aa | 4540 | { |
e075ae69 RH |
4541 | tmp = ix86_expand_compare (code, unordered); |
4542 | tmp = gen_rtx_IF_THEN_ELSE (VOIDmode, tmp, | |
4543 | gen_rtx_LABEL_REF (VOIDmode, label), | |
4544 | pc_rtx); | |
4545 | emit_jump_insn (gen_rtx_SET (VOIDmode, pc_rtx, tmp)); | |
32b5b1aa SC |
4546 | return; |
4547 | } | |
32b5b1aa | 4548 | |
e075ae69 RH |
4549 | /* Expand DImode branch into multiple compare+branch. */ |
4550 | ||
4551 | if (CONSTANT_P (ix86_compare_op0) && ! CONSTANT_P (ix86_compare_op1)) | |
32b5b1aa | 4552 | { |
e075ae69 RH |
4553 | tmp = ix86_compare_op0; |
4554 | ix86_compare_op0 = ix86_compare_op1; | |
4555 | ix86_compare_op1 = tmp; | |
4556 | code = swap_condition (code); | |
4557 | } | |
4558 | split_di (&ix86_compare_op0, 1, lo+0, hi+0); | |
4559 | split_di (&ix86_compare_op1, 1, lo+1, hi+1); | |
32b5b1aa | 4560 | |
e075ae69 RH |
4561 | /* When comparing for equality, we can use (hi0^hi1)|(lo0^lo1) to avoid |
4562 | two branches. This costs one extra insn, so disable when optimizing | |
4563 | for size. */ | |
32b5b1aa | 4564 | |
e075ae69 RH |
4565 | if ((code == EQ || code == NE) |
4566 | && (!optimize_size | |
4567 | || hi[1] == const0_rtx || lo[1] == const0_rtx)) | |
4568 | { | |
4569 | rtx xor0, xor1; | |
32b5b1aa | 4570 | |
e075ae69 RH |
4571 | xor1 = hi[0]; |
4572 | if (hi[1] != const0_rtx) | |
4573 | { | |
4574 | xor1 = expand_binop (SImode, xor_optab, xor1, hi[1], | |
4575 | NULL_RTX, 0, OPTAB_WIDEN); | |
4576 | } | |
32b5b1aa | 4577 | |
e075ae69 RH |
4578 | xor0 = lo[0]; |
4579 | if (lo[1] != const0_rtx) | |
4580 | { | |
4581 | xor0 = expand_binop (SImode, xor_optab, xor0, lo[1], | |
4582 | NULL_RTX, 0, OPTAB_WIDEN); | |
32b5b1aa SC |
4583 | } |
4584 | ||
e075ae69 RH |
4585 | tmp = expand_binop (SImode, ior_optab, xor1, xor0, |
4586 | NULL_RTX, 0, OPTAB_WIDEN); | |
32b5b1aa | 4587 | |
e075ae69 RH |
4588 | ix86_compare_op0 = tmp; |
4589 | ix86_compare_op1 = const0_rtx; | |
4590 | ix86_expand_branch (code, unordered, label); | |
4591 | return; | |
32b5b1aa SC |
4592 | } |
4593 | ||
e075ae69 RH |
4594 | /* Otherwise, if we are doing less-than, op1 is a constant and the |
4595 | low word is zero, then we can just examine the high word. */ | |
4596 | ||
4597 | if (GET_CODE (hi[1]) == CONST_INT && lo[1] == const0_rtx | |
4598 | && (code == LT || code == LTU)) | |
32b5b1aa | 4599 | { |
e075ae69 RH |
4600 | ix86_compare_op0 = hi[0]; |
4601 | ix86_compare_op1 = hi[1]; | |
4602 | ix86_expand_branch (code, unordered, label); | |
4603 | return; | |
4604 | } | |
32b5b1aa | 4605 | |
e075ae69 RH |
4606 | /* Otherwise, we need two or three jumps. */ |
4607 | ||
4608 | label2 = gen_label_rtx (); | |
32b5b1aa | 4609 | |
e075ae69 RH |
4610 | code1 = code; |
4611 | code2 = swap_condition (code); | |
4612 | code3 = unsigned_condition (code); | |
4613 | ||
4614 | switch (code) | |
4615 | { | |
4616 | case LT: case GT: case LTU: case GTU: | |
4617 | break; | |
4618 | ||
4619 | case LE: code1 = LT; code2 = GT; break; | |
4620 | case GE: code1 = GT; code2 = LT; break; | |
4621 | case LEU: code1 = LTU; code2 = GTU; break; | |
4622 | case GEU: code1 = GTU; code2 = LTU; break; | |
4623 | ||
4624 | case EQ: code1 = NIL; code2 = NE; break; | |
4625 | case NE: code2 = NIL; break; | |
4626 | ||
4627 | default: | |
4628 | abort (); | |
32b5b1aa | 4629 | } |
e075ae69 RH |
4630 | |
4631 | /* | |
4632 | * a < b => | |
4633 | * if (hi(a) < hi(b)) goto true; | |
4634 | * if (hi(a) > hi(b)) goto false; | |
4635 | * if (lo(a) < lo(b)) goto true; | |
4636 | * false: | |
4637 | */ | |
4638 | ||
4639 | ix86_compare_op0 = hi[0]; | |
4640 | ix86_compare_op1 = hi[1]; | |
4641 | ||
4642 | if (code1 != NIL) | |
4643 | ix86_expand_branch (code1, unordered, label); | |
4644 | if (code2 != NIL) | |
4645 | ix86_expand_branch (code2, unordered, label2); | |
4646 | ||
4647 | ix86_compare_op0 = lo[0]; | |
4648 | ix86_compare_op1 = lo[1]; | |
4649 | ix86_expand_branch (code3, unordered, label); | |
4650 | ||
4651 | if (code2 != NIL) | |
4652 | emit_label (label2); | |
32b5b1aa | 4653 | } |
e075ae69 | 4654 | |
32b5b1aa | 4655 | int |
e075ae69 RH |
4656 | ix86_expand_setcc (code, unordered, dest) |
4657 | enum rtx_code code; | |
4658 | int unordered; | |
4659 | rtx dest; | |
32b5b1aa | 4660 | { |
e075ae69 RH |
4661 | rtx ret, tmp; |
4662 | int type; | |
4663 | ||
4664 | if (GET_MODE (ix86_compare_op0) == DImode) | |
4665 | return 0; /* FAIL */ | |
4666 | ||
4667 | /* Three modes of generation: | |
4668 | 0 -- destination does not overlap compare sources: | |
4669 | clear dest first, emit strict_low_part setcc. | |
4670 | 1 -- destination does overlap compare sources: | |
4671 | emit subreg setcc, zero extend. | |
4672 | 2 -- destination is in QImode: | |
4673 | emit setcc only. | |
4674 | */ | |
4675 | ||
4676 | type = 0; | |
e075ae69 RH |
4677 | |
4678 | if (GET_MODE (dest) == QImode) | |
4679 | type = 2; | |
4680 | else if (reg_overlap_mentioned_p (dest, ix86_compare_op0) | |
a500c31b | 4681 | || reg_overlap_mentioned_p (dest, ix86_compare_op1)) |
e075ae69 RH |
4682 | type = 1; |
4683 | ||
4684 | if (type == 0) | |
4685 | emit_move_insn (dest, const0_rtx); | |
4686 | ||
4687 | ret = ix86_expand_compare (code, unordered); | |
4688 | PUT_MODE (ret, QImode); | |
4689 | ||
4690 | tmp = dest; | |
4691 | if (type == 0) | |
32b5b1aa | 4692 | { |
e075ae69 RH |
4693 | tmp = gen_lowpart (QImode, dest); |
4694 | tmp = gen_rtx_STRICT_LOW_PART (VOIDmode, tmp); | |
4695 | } | |
4696 | else if (type == 1) | |
4697 | { | |
4698 | if (!cse_not_expected) | |
4699 | tmp = gen_reg_rtx (QImode); | |
4700 | else | |
4701 | tmp = gen_lowpart (QImode, dest); | |
4702 | } | |
32b5b1aa | 4703 | |
e075ae69 RH |
4704 | emit_insn (gen_rtx_SET (VOIDmode, tmp, ret)); |
4705 | ||
4706 | if (type == 1) | |
4707 | { | |
4708 | rtx clob; | |
4709 | ||
4710 | tmp = gen_rtx_ZERO_EXTEND (GET_MODE (dest), tmp); | |
4711 | tmp = gen_rtx_SET (VOIDmode, dest, tmp); | |
4712 | clob = gen_rtx_CLOBBER (VOIDmode, gen_rtx_REG (CCmode, FLAGS_REG)); | |
4713 | tmp = gen_rtx_PARALLEL (VOIDmode, gen_rtvec (2, tmp, clob)); | |
4714 | emit_insn (tmp); | |
32b5b1aa | 4715 | } |
e075ae69 RH |
4716 | |
4717 | return 1; /* DONE */ | |
32b5b1aa | 4718 | } |
e075ae69 | 4719 | |
32b5b1aa | 4720 | int |
e075ae69 RH |
4721 | ix86_expand_int_movcc (operands) |
4722 | rtx operands[]; | |
32b5b1aa | 4723 | { |
e075ae69 RH |
4724 | enum rtx_code code = GET_CODE (operands[1]), compare_code; |
4725 | rtx compare_seq, compare_op; | |
32b5b1aa | 4726 | |
36583fea JH |
4727 | /* When the compare code is not LTU or GEU, we can not use sbbl case. |
4728 | In case comparsion is done with immediate, we can convert it to LTU or | |
4729 | GEU by altering the integer. */ | |
4730 | ||
4731 | if ((code == LEU || code == GTU) | |
4732 | && GET_CODE (ix86_compare_op1) == CONST_INT | |
4733 | && GET_MODE (operands[0]) != HImode | |
4734 | && (unsigned int)INTVAL (ix86_compare_op1) != 0xffffffff | |
4735 | && GET_CODE (operands[2]) == CONST_INT | |
4736 | && GET_CODE (operands[3]) == CONST_INT) | |
4737 | { | |
4738 | if (code == LEU) | |
4739 | code = LTU; | |
4740 | else | |
4741 | code = GEU; | |
4742 | ix86_compare_op1 = GEN_INT (INTVAL (ix86_compare_op1) + 1); | |
4743 | } | |
e075ae69 RH |
4744 | start_sequence (); |
4745 | compare_op = ix86_expand_compare (code, code == EQ || code == NE); | |
4746 | compare_seq = gen_sequence (); | |
4747 | end_sequence (); | |
4748 | ||
4749 | compare_code = GET_CODE (compare_op); | |
4750 | ||
4751 | /* Don't attempt mode expansion here -- if we had to expand 5 or 6 | |
4752 | HImode insns, we'd be swallowed in word prefix ops. */ | |
4753 | ||
4754 | if (GET_MODE (operands[0]) != HImode | |
4755 | && GET_CODE (operands[2]) == CONST_INT | |
4756 | && GET_CODE (operands[3]) == CONST_INT) | |
4757 | { | |
4758 | rtx out = operands[0]; | |
4759 | HOST_WIDE_INT ct = INTVAL (operands[2]); | |
4760 | HOST_WIDE_INT cf = INTVAL (operands[3]); | |
4761 | HOST_WIDE_INT diff; | |
4762 | ||
36583fea | 4763 | if (compare_code == LTU || compare_code == GEU) |
e075ae69 | 4764 | { |
e075ae69 RH |
4765 | |
4766 | /* Detect overlap between destination and compare sources. */ | |
4767 | rtx tmp = out; | |
4768 | ||
36583fea JH |
4769 | /* To simplify rest of code, restrict to the GEU case. */ |
4770 | if (compare_code == LTU) | |
4771 | { | |
4772 | int tmp = ct; | |
4773 | ct = cf; | |
4774 | cf = tmp; | |
4775 | compare_code = reverse_condition (compare_code); | |
4776 | code = reverse_condition (code); | |
4777 | } | |
4778 | diff = ct - cf; | |
4779 | ||
e075ae69 | 4780 | if (reg_overlap_mentioned_p (out, ix86_compare_op0) |
a500c31b | 4781 | || reg_overlap_mentioned_p (out, ix86_compare_op1)) |
e075ae69 RH |
4782 | tmp = gen_reg_rtx (SImode); |
4783 | ||
4784 | emit_insn (compare_seq); | |
4785 | emit_insn (gen_x86_movsicc_0_m1 (tmp)); | |
4786 | ||
36583fea JH |
4787 | if (diff == 1) |
4788 | { | |
4789 | /* | |
4790 | * cmpl op0,op1 | |
4791 | * sbbl dest,dest | |
4792 | * [addl dest, ct] | |
4793 | * | |
4794 | * Size 5 - 8. | |
4795 | */ | |
4796 | if (ct) | |
4797 | emit_insn (gen_addsi3 (out, out, GEN_INT (ct))); | |
4798 | } | |
4799 | else if (cf == -1) | |
4800 | { | |
4801 | /* | |
4802 | * cmpl op0,op1 | |
4803 | * sbbl dest,dest | |
4804 | * orl $ct, dest | |
4805 | * | |
4806 | * Size 8. | |
4807 | */ | |
4808 | emit_insn (gen_iorsi3 (out, out, GEN_INT (ct))); | |
4809 | } | |
4810 | else if (diff == -1 && ct) | |
4811 | { | |
4812 | /* | |
4813 | * cmpl op0,op1 | |
4814 | * sbbl dest,dest | |
4815 | * xorl $-1, dest | |
4816 | * [addl dest, cf] | |
4817 | * | |
4818 | * Size 8 - 11. | |
4819 | */ | |
4820 | emit_insn (gen_one_cmplsi2 (tmp, tmp)); | |
4821 | if (cf) | |
4822 | emit_insn (gen_addsi3 (out, out, GEN_INT (cf))); | |
4823 | } | |
4824 | else | |
4825 | { | |
4826 | /* | |
4827 | * cmpl op0,op1 | |
4828 | * sbbl dest,dest | |
4829 | * andl cf - ct, dest | |
4830 | * [addl dest, ct] | |
4831 | * | |
4832 | * Size 8 - 11. | |
4833 | */ | |
4834 | emit_insn (gen_andsi3 (out, out, GEN_INT (cf - ct))); | |
4835 | if (ct) | |
4836 | emit_insn (gen_addsi3 (out, out, GEN_INT (ct))); | |
4837 | } | |
e075ae69 RH |
4838 | |
4839 | if (tmp != out) | |
4840 | emit_move_insn (out, tmp); | |
4841 | ||
4842 | return 1; /* DONE */ | |
4843 | } | |
4844 | ||
4845 | diff = ct - cf; | |
4846 | if (diff < 0) | |
4847 | { | |
4848 | HOST_WIDE_INT tmp; | |
4849 | tmp = ct, ct = cf, cf = tmp; | |
4850 | diff = -diff; | |
4851 | compare_code = reverse_condition (compare_code); | |
4852 | code = reverse_condition (code); | |
4853 | } | |
4854 | if (diff == 1 || diff == 2 || diff == 4 || diff == 8 | |
4855 | || diff == 3 || diff == 5 || diff == 9) | |
4856 | { | |
4857 | /* | |
4858 | * xorl dest,dest | |
4859 | * cmpl op1,op2 | |
4860 | * setcc dest | |
4861 | * lea cf(dest*(ct-cf)),dest | |
4862 | * | |
4863 | * Size 14. | |
4864 | * | |
4865 | * This also catches the degenerate setcc-only case. | |
4866 | */ | |
4867 | ||
4868 | rtx tmp; | |
4869 | int nops; | |
4870 | ||
4871 | out = emit_store_flag (out, code, ix86_compare_op0, | |
4872 | ix86_compare_op1, VOIDmode, 0, 1); | |
4873 | ||
4874 | nops = 0; | |
4875 | if (diff == 1) | |
4876 | tmp = out; | |
4877 | else | |
4878 | { | |
4879 | tmp = gen_rtx_MULT (SImode, out, GEN_INT (diff & ~1)); | |
4880 | nops++; | |
4881 | if (diff & 1) | |
4882 | { | |
4883 | tmp = gen_rtx_PLUS (SImode, tmp, out); | |
4884 | nops++; | |
4885 | } | |
4886 | } | |
4887 | if (cf != 0) | |
4888 | { | |
4889 | tmp = gen_rtx_PLUS (SImode, tmp, GEN_INT (cf)); | |
4890 | nops++; | |
4891 | } | |
4892 | if (tmp != out) | |
4893 | { | |
4894 | if (nops == 0) | |
4895 | emit_move_insn (out, tmp); | |
4896 | else if (nops == 1) | |
4897 | { | |
4898 | rtx clob; | |
4899 | ||
4900 | clob = gen_rtx_REG (CCmode, FLAGS_REG); | |
4901 | clob = gen_rtx_CLOBBER (VOIDmode, clob); | |
4902 | ||
4903 | tmp = gen_rtx_SET (VOIDmode, out, tmp); | |
4904 | tmp = gen_rtx_PARALLEL (VOIDmode, gen_rtvec (2, tmp, clob)); | |
4905 | emit_insn (tmp); | |
4906 | } | |
4907 | else | |
4908 | emit_insn (gen_rtx_SET (VOIDmode, out, tmp)); | |
4909 | } | |
4910 | if (out != operands[0]) | |
4911 | emit_move_insn (operands[0], out); | |
4912 | ||
4913 | return 1; /* DONE */ | |
4914 | } | |
4915 | ||
4916 | /* | |
4917 | * General case: Jumpful: | |
4918 | * xorl dest,dest cmpl op1, op2 | |
4919 | * cmpl op1, op2 movl ct, dest | |
4920 | * setcc dest jcc 1f | |
4921 | * decl dest movl cf, dest | |
4922 | * andl (cf-ct),dest 1: | |
4923 | * addl ct,dest | |
4924 | * | |
4925 | * Size 20. Size 14. | |
4926 | * | |
4927 | * This is reasonably steep, but branch mispredict costs are | |
4928 | * high on modern cpus, so consider failing only if optimizing | |
4929 | * for space. | |
4930 | * | |
4931 | * %%% Parameterize branch_cost on the tuning architecture, then | |
4932 | * use that. The 80386 couldn't care less about mispredicts. | |
4933 | */ | |
4934 | ||
4935 | if (!optimize_size && !TARGET_CMOVE) | |
4936 | { | |
4937 | if (ct == 0) | |
4938 | { | |
4939 | ct = cf; | |
4940 | cf = 0; | |
4941 | compare_code = reverse_condition (compare_code); | |
4942 | code = reverse_condition (code); | |
4943 | } | |
4944 | ||
4945 | out = emit_store_flag (out, code, ix86_compare_op0, | |
4946 | ix86_compare_op1, VOIDmode, 0, 1); | |
4947 | ||
4948 | emit_insn (gen_addsi3 (out, out, constm1_rtx)); | |
4949 | emit_insn (gen_andsi3 (out, out, GEN_INT (cf-ct))); | |
4950 | if (ct != 0) | |
4951 | emit_insn (gen_addsi3 (out, out, GEN_INT (ct))); | |
4952 | if (out != operands[0]) | |
4953 | emit_move_insn (operands[0], out); | |
4954 | ||
4955 | return 1; /* DONE */ | |
4956 | } | |
4957 | } | |
4958 | ||
4959 | if (!TARGET_CMOVE) | |
4960 | { | |
4961 | /* Try a few things more with specific constants and a variable. */ | |
4962 | ||
78a0d70c | 4963 | optab op; |
e075ae69 RH |
4964 | rtx var, orig_out, out, tmp; |
4965 | ||
4966 | if (optimize_size) | |
4967 | return 0; /* FAIL */ | |
4968 | ||
4969 | /* If one of the two operands is an interesting constant, load a | |
4970 | constant with the above and mask it in with a logical operation. */ | |
4971 | ||
4972 | if (GET_CODE (operands[2]) == CONST_INT) | |
4973 | { | |
4974 | var = operands[3]; | |
4975 | if (INTVAL (operands[2]) == 0) | |
4976 | operands[3] = constm1_rtx, op = and_optab; | |
4977 | else if (INTVAL (operands[2]) == -1) | |
4978 | operands[3] = const0_rtx, op = ior_optab; | |
78a0d70c ZW |
4979 | else |
4980 | return 0; /* FAIL */ | |
e075ae69 RH |
4981 | } |
4982 | else if (GET_CODE (operands[3]) == CONST_INT) | |
4983 | { | |
4984 | var = operands[2]; | |
4985 | if (INTVAL (operands[3]) == 0) | |
4986 | operands[2] = constm1_rtx, op = and_optab; | |
4987 | else if (INTVAL (operands[3]) == -1) | |
4988 | operands[2] = const0_rtx, op = ior_optab; | |
78a0d70c ZW |
4989 | else |
4990 | return 0; /* FAIL */ | |
e075ae69 | 4991 | } |
78a0d70c | 4992 | else |
e075ae69 RH |
4993 | return 0; /* FAIL */ |
4994 | ||
4995 | orig_out = operands[0]; | |
4996 | tmp = gen_reg_rtx (GET_MODE (orig_out)); | |
4997 | operands[0] = tmp; | |
4998 | ||
4999 | /* Recurse to get the constant loaded. */ | |
5000 | if (ix86_expand_int_movcc (operands) == 0) | |
5001 | return 0; /* FAIL */ | |
5002 | ||
5003 | /* Mask in the interesting variable. */ | |
5004 | out = expand_binop (GET_MODE (orig_out), op, var, tmp, orig_out, 0, | |
5005 | OPTAB_WIDEN); | |
5006 | if (out != orig_out) | |
5007 | emit_move_insn (orig_out, out); | |
5008 | ||
5009 | return 1; /* DONE */ | |
5010 | } | |
5011 | ||
5012 | /* | |
5013 | * For comparison with above, | |
5014 | * | |
5015 | * movl cf,dest | |
5016 | * movl ct,tmp | |
5017 | * cmpl op1,op2 | |
5018 | * cmovcc tmp,dest | |
5019 | * | |
5020 | * Size 15. | |
5021 | */ | |
5022 | ||
5023 | if (! nonimmediate_operand (operands[2], GET_MODE (operands[0]))) | |
5024 | operands[2] = force_reg (GET_MODE (operands[0]), operands[2]); | |
5025 | if (! nonimmediate_operand (operands[3], GET_MODE (operands[0]))) | |
5026 | operands[3] = force_reg (GET_MODE (operands[0]), operands[3]); | |
5027 | ||
5028 | emit_insn (compare_seq); | |
5029 | emit_insn (gen_rtx_SET (VOIDmode, operands[0], | |
5030 | gen_rtx_IF_THEN_ELSE (GET_MODE (operands[0]), | |
5031 | compare_op, operands[2], | |
5032 | operands[3]))); | |
5033 | ||
5034 | return 1; /* DONE */ | |
e9a25f70 | 5035 | } |
e075ae69 | 5036 | |
32b5b1aa | 5037 | int |
e075ae69 RH |
5038 | ix86_expand_fp_movcc (operands) |
5039 | rtx operands[]; | |
32b5b1aa | 5040 | { |
e075ae69 RH |
5041 | enum rtx_code code; |
5042 | enum machine_mode mode; | |
5043 | rtx tmp; | |
32b5b1aa | 5044 | |
e075ae69 RH |
5045 | /* The floating point conditional move instructions don't directly |
5046 | support conditions resulting from a signed integer comparison. */ | |
32b5b1aa | 5047 | |
e075ae69 RH |
5048 | code = GET_CODE (operands[1]); |
5049 | switch (code) | |
5050 | { | |
5051 | case LT: | |
5052 | case LE: | |
5053 | case GE: | |
5054 | case GT: | |
5055 | tmp = gen_reg_rtx (QImode); | |
5056 | ix86_expand_setcc (code, 0, tmp); | |
5057 | code = NE; | |
5058 | ix86_compare_op0 = tmp; | |
5059 | ix86_compare_op1 = const0_rtx; | |
5060 | break; | |
5061 | ||
5062 | default: | |
5063 | break; | |
5064 | } | |
e9a25f70 | 5065 | |
e075ae69 RH |
5066 | mode = SELECT_CC_MODE (code, ix86_compare_op0, ix86_compare_op1); |
5067 | emit_insn (gen_rtx_SET (VOIDmode, gen_rtx_REG (mode, FLAGS_REG), | |
5068 | gen_rtx_COMPARE (mode, | |
5069 | ix86_compare_op0, | |
5070 | ix86_compare_op1))); | |
5071 | emit_insn (gen_rtx_SET (VOIDmode, operands[0], | |
5072 | gen_rtx_IF_THEN_ELSE (GET_MODE (operands[0]), | |
5073 | gen_rtx_fmt_ee (code, VOIDmode, | |
5074 | gen_rtx_REG (mode, FLAGS_REG), | |
5075 | const0_rtx), | |
5076 | operands[2], | |
5077 | operands[3]))); | |
32b5b1aa | 5078 | |
e075ae69 | 5079 | return 1; |
32b5b1aa SC |
5080 | } |
5081 | ||
2450a057 JH |
5082 | /* Split operands 0 and 1 into SImode parts. Similar to split_di, but |
5083 | works for floating pointer parameters and nonoffsetable memories. | |
5084 | For pushes, it returns just stack offsets; the values will be saved | |
5085 | in the right order. Maximally three parts are generated. */ | |
5086 | ||
5087 | static void | |
5088 | ix86_split_to_parts (operand, parts, mode) | |
5089 | rtx operand; | |
5090 | rtx *parts; | |
5091 | enum machine_mode mode; | |
32b5b1aa | 5092 | { |
2450a057 JH |
5093 | int size = GET_MODE_SIZE (mode) / 4; |
5094 | ||
5095 | if (size < 2 || size > 3) | |
5096 | abort (); | |
5097 | ||
d7a29404 JH |
5098 | /* Optimize constant pool reference to immediates. This is used by fp moves, |
5099 | that force all constants to memory to allow combining. */ | |
5100 | ||
5101 | if (GET_CODE (operand) == MEM | |
5102 | && GET_CODE (XEXP (operand, 0)) == SYMBOL_REF | |
5103 | && CONSTANT_POOL_ADDRESS_P (XEXP (operand, 0))) | |
5104 | operand = get_pool_constant (XEXP (operand, 0)); | |
5105 | ||
2450a057 | 5106 | if (GET_CODE (operand) == MEM && !offsettable_memref_p (operand)) |
e075ae69 | 5107 | { |
2450a057 JH |
5108 | /* The only non-offsetable memories we handle are pushes. */ |
5109 | if (! push_operand (operand, VOIDmode)) | |
5110 | abort (); | |
5111 | ||
5112 | PUT_MODE (operand, SImode); | |
5113 | parts[0] = parts[1] = parts[2] = operand; | |
5114 | } | |
5115 | else | |
5116 | { | |
5117 | if (mode == DImode) | |
5118 | split_di (&operand, 1, &parts[0], &parts[1]); | |
5119 | else | |
e075ae69 | 5120 | { |
2450a057 JH |
5121 | if (REG_P (operand)) |
5122 | { | |
5123 | if (!reload_completed) | |
5124 | abort (); | |
5125 | parts[0] = gen_rtx_REG (SImode, REGNO (operand) + 0); | |
5126 | parts[1] = gen_rtx_REG (SImode, REGNO (operand) + 1); | |
5127 | if (size == 3) | |
5128 | parts[2] = gen_rtx_REG (SImode, REGNO (operand) + 2); | |
5129 | } | |
5130 | else if (offsettable_memref_p (operand)) | |
5131 | { | |
5132 | PUT_MODE (operand, SImode); | |
5133 | parts[0] = operand; | |
5134 | parts[1] = adj_offsettable_operand (operand, 4); | |
5135 | if (size == 3) | |
5136 | parts[2] = adj_offsettable_operand (operand, 8); | |
5137 | } | |
5138 | else if (GET_CODE (operand) == CONST_DOUBLE) | |
5139 | { | |
5140 | REAL_VALUE_TYPE r; | |
5141 | long l[3]; | |
5142 | ||
5143 | REAL_VALUE_FROM_CONST_DOUBLE (r, operand); | |
5144 | switch (mode) | |
5145 | { | |
5146 | case XFmode: | |
5147 | REAL_VALUE_TO_TARGET_LONG_DOUBLE (r, l); | |
5148 | parts[2] = GEN_INT (l[2]); | |
5149 | break; | |
5150 | case DFmode: | |
5151 | REAL_VALUE_TO_TARGET_DOUBLE (r, l); | |
5152 | break; | |
5153 | default: | |
5154 | abort (); | |
5155 | } | |
5156 | parts[1] = GEN_INT (l[1]); | |
5157 | parts[0] = GEN_INT (l[0]); | |
5158 | } | |
5159 | else | |
5160 | abort (); | |
e075ae69 | 5161 | } |
2450a057 JH |
5162 | } |
5163 | ||
5164 | return; | |
5165 | } | |
5166 | ||
5167 | /* Emit insns to perform a move or push of DI, DF, and XF values. | |
5168 | Return false when normal moves are needed; true when all required | |
5169 | insns have been emitted. Operands 2-4 contain the input values | |
5170 | int the correct order; operands 5-7 contain the output values. */ | |
5171 | ||
5172 | int | |
5173 | ix86_split_long_move (operands1) | |
5174 | rtx operands1[]; | |
5175 | { | |
5176 | rtx part[2][3]; | |
5177 | rtx operands[2]; | |
5178 | int size = GET_MODE_SIZE (GET_MODE (operands1[0])) / 4; | |
5179 | int push = 0; | |
5180 | int collisions = 0; | |
5181 | ||
5182 | /* Make our own copy to avoid clobbering the operands. */ | |
5183 | operands[0] = copy_rtx (operands1[0]); | |
5184 | operands[1] = copy_rtx (operands1[1]); | |
5185 | ||
5186 | if (size < 2 || size > 3) | |
5187 | abort (); | |
5188 | ||
5189 | /* The only non-offsettable memory we handle is push. */ | |
5190 | if (push_operand (operands[0], VOIDmode)) | |
5191 | push = 1; | |
5192 | else if (GET_CODE (operands[0]) == MEM | |
5193 | && ! offsettable_memref_p (operands[0])) | |
5194 | abort (); | |
5195 | ||
5196 | ix86_split_to_parts (operands[0], part[0], GET_MODE (operands1[0])); | |
5197 | ix86_split_to_parts (operands[1], part[1], GET_MODE (operands1[0])); | |
5198 | ||
5199 | /* When emitting push, take care for source operands on the stack. */ | |
5200 | if (push && GET_CODE (operands[1]) == MEM | |
5201 | && reg_overlap_mentioned_p (stack_pointer_rtx, operands[1])) | |
5202 | { | |
5203 | if (size == 3) | |
5204 | part[1][1] = part[1][2]; | |
5205 | part[1][0] = part[1][1]; | |
5206 | } | |
5207 | ||
5208 | /* We need to do copy in the right order in case an address register | |
5209 | of the source overlaps the destination. */ | |
5210 | if (REG_P (part[0][0]) && GET_CODE (part[1][0]) == MEM) | |
5211 | { | |
5212 | if (reg_overlap_mentioned_p (part[0][0], XEXP (part[1][0], 0))) | |
5213 | collisions++; | |
5214 | if (reg_overlap_mentioned_p (part[0][1], XEXP (part[1][0], 0))) | |
5215 | collisions++; | |
5216 | if (size == 3 | |
5217 | && reg_overlap_mentioned_p (part[0][2], XEXP (part[1][0], 0))) | |
5218 | collisions++; | |
5219 | ||
5220 | /* Collision in the middle part can be handled by reordering. */ | |
5221 | if (collisions == 1 && size == 3 | |
5222 | && reg_overlap_mentioned_p (part[0][1], XEXP (part[1][0], 0))) | |
e075ae69 | 5223 | { |
2450a057 JH |
5224 | rtx tmp; |
5225 | tmp = part[0][1]; part[0][1] = part[0][2]; part[0][2] = tmp; | |
5226 | tmp = part[1][1]; part[1][1] = part[1][2]; part[1][2] = tmp; | |
5227 | } | |
e075ae69 | 5228 | |
2450a057 JH |
5229 | /* If there are more collisions, we can't handle it by reordering. |
5230 | Do an lea to the last part and use only one colliding move. */ | |
5231 | else if (collisions > 1) | |
5232 | { | |
5233 | collisions = 1; | |
5234 | emit_insn (gen_rtx_SET (VOIDmode, part[0][size - 1], | |
5235 | XEXP (part[1][0], 0))); | |
5236 | part[1][0] = change_address (part[1][0], SImode, part[0][size - 1]); | |
5237 | part[1][1] = adj_offsettable_operand (part[1][0], 4); | |
5238 | if (size == 3) | |
5239 | part[1][2] = adj_offsettable_operand (part[1][0], 8); | |
5240 | } | |
5241 | } | |
5242 | ||
5243 | if (push) | |
5244 | { | |
5245 | if (size == 3) | |
5246 | emit_insn (gen_push (part[1][2])); | |
5247 | emit_insn (gen_push (part[1][1])); | |
5248 | emit_insn (gen_push (part[1][0])); | |
5249 | return 1; | |
5250 | } | |
5251 | ||
5252 | /* Choose correct order to not overwrite the source before it is copied. */ | |
5253 | if ((REG_P (part[0][0]) | |
5254 | && REG_P (part[1][1]) | |
5255 | && (REGNO (part[0][0]) == REGNO (part[1][1]) | |
5256 | || (size == 3 | |
5257 | && REGNO (part[0][0]) == REGNO (part[1][2])))) | |
5258 | || (collisions > 0 | |
5259 | && reg_overlap_mentioned_p (part[0][0], XEXP (part[1][0], 0)))) | |
5260 | { | |
5261 | if (size == 3) | |
5262 | { | |
5263 | operands1[2] = part[0][2]; | |
5264 | operands1[3] = part[0][1]; | |
5265 | operands1[4] = part[0][0]; | |
5266 | operands1[5] = part[1][2]; | |
5267 | operands1[6] = part[1][1]; | |
5268 | operands1[7] = part[1][0]; | |
5269 | } | |
5270 | else | |
5271 | { | |
5272 | operands1[2] = part[0][1]; | |
5273 | operands1[3] = part[0][0]; | |
5274 | operands1[5] = part[1][1]; | |
5275 | operands1[6] = part[1][0]; | |
5276 | } | |
5277 | } | |
5278 | else | |
5279 | { | |
5280 | if (size == 3) | |
5281 | { | |
5282 | operands1[2] = part[0][0]; | |
5283 | operands1[3] = part[0][1]; | |
5284 | operands1[4] = part[0][2]; | |
5285 | operands1[5] = part[1][0]; | |
5286 | operands1[6] = part[1][1]; | |
5287 | operands1[7] = part[1][2]; | |
5288 | } | |
5289 | else | |
5290 | { | |
5291 | operands1[2] = part[0][0]; | |
5292 | operands1[3] = part[0][1]; | |
5293 | operands1[5] = part[1][0]; | |
5294 | operands1[6] = part[1][1]; | |
e075ae69 RH |
5295 | } |
5296 | } | |
32b5b1aa | 5297 | |
e9a25f70 | 5298 | return 0; |
32b5b1aa | 5299 | } |
32b5b1aa | 5300 | |
e075ae69 RH |
5301 | void |
5302 | ix86_split_ashldi (operands, scratch) | |
5303 | rtx *operands, scratch; | |
32b5b1aa | 5304 | { |
e075ae69 RH |
5305 | rtx low[2], high[2]; |
5306 | int count; | |
b985a30f | 5307 | |
e075ae69 RH |
5308 | if (GET_CODE (operands[2]) == CONST_INT) |
5309 | { | |
5310 | split_di (operands, 2, low, high); | |
5311 | count = INTVAL (operands[2]) & 63; | |
32b5b1aa | 5312 | |
e075ae69 RH |
5313 | if (count >= 32) |
5314 | { | |
5315 | emit_move_insn (high[0], low[1]); | |
5316 | emit_move_insn (low[0], const0_rtx); | |
b985a30f | 5317 | |
e075ae69 RH |
5318 | if (count > 32) |
5319 | emit_insn (gen_ashlsi3 (high[0], high[0], GEN_INT (count - 32))); | |
5320 | } | |
5321 | else | |
5322 | { | |
5323 | if (!rtx_equal_p (operands[0], operands[1])) | |
5324 | emit_move_insn (operands[0], operands[1]); | |
5325 | emit_insn (gen_x86_shld_1 (high[0], low[0], GEN_INT (count))); | |
5326 | emit_insn (gen_ashlsi3 (low[0], low[0], GEN_INT (count))); | |
5327 | } | |
5328 | } | |
5329 | else | |
5330 | { | |
5331 | if (!rtx_equal_p (operands[0], operands[1])) | |
5332 | emit_move_insn (operands[0], operands[1]); | |
b985a30f | 5333 | |
e075ae69 | 5334 | split_di (operands, 1, low, high); |
b985a30f | 5335 | |
e075ae69 RH |
5336 | emit_insn (gen_x86_shld_1 (high[0], low[0], operands[2])); |
5337 | emit_insn (gen_ashlsi3 (low[0], low[0], operands[2])); | |
32b5b1aa | 5338 | |
e075ae69 RH |
5339 | if (TARGET_CMOVE && (! reload_completed || scratch)) |
5340 | { | |
5341 | if (! reload_completed) | |
5342 | scratch = force_reg (SImode, const0_rtx); | |
5343 | else | |
5344 | emit_move_insn (scratch, const0_rtx); | |
5345 | ||
5346 | emit_insn (gen_x86_shift_adj_1 (high[0], low[0], operands[2], | |
5347 | scratch)); | |
5348 | } | |
5349 | else | |
5350 | emit_insn (gen_x86_shift_adj_2 (high[0], low[0], operands[2])); | |
5351 | } | |
e9a25f70 | 5352 | } |
32b5b1aa | 5353 | |
e075ae69 RH |
5354 | void |
5355 | ix86_split_ashrdi (operands, scratch) | |
5356 | rtx *operands, scratch; | |
32b5b1aa | 5357 | { |
e075ae69 RH |
5358 | rtx low[2], high[2]; |
5359 | int count; | |
32b5b1aa | 5360 | |
e075ae69 RH |
5361 | if (GET_CODE (operands[2]) == CONST_INT) |
5362 | { | |
5363 | split_di (operands, 2, low, high); | |
5364 | count = INTVAL (operands[2]) & 63; | |
32b5b1aa | 5365 | |
e075ae69 RH |
5366 | if (count >= 32) |
5367 | { | |
5368 | emit_move_insn (low[0], high[1]); | |
32b5b1aa | 5369 | |
e075ae69 RH |
5370 | if (! reload_completed) |
5371 | emit_insn (gen_ashrsi3 (high[0], low[0], GEN_INT (31))); | |
5372 | else | |
5373 | { | |
5374 | emit_move_insn (high[0], low[0]); | |
5375 | emit_insn (gen_ashrsi3 (high[0], high[0], GEN_INT (31))); | |
5376 | } | |
5377 | ||
5378 | if (count > 32) | |
5379 | emit_insn (gen_ashrsi3 (low[0], low[0], GEN_INT (count - 32))); | |
5380 | } | |
5381 | else | |
5382 | { | |
5383 | if (!rtx_equal_p (operands[0], operands[1])) | |
5384 | emit_move_insn (operands[0], operands[1]); | |
5385 | emit_insn (gen_x86_shrd_1 (low[0], high[0], GEN_INT (count))); | |
5386 | emit_insn (gen_ashrsi3 (high[0], high[0], GEN_INT (count))); | |
5387 | } | |
5388 | } | |
5389 | else | |
32b5b1aa | 5390 | { |
e075ae69 RH |
5391 | if (!rtx_equal_p (operands[0], operands[1])) |
5392 | emit_move_insn (operands[0], operands[1]); | |
5393 | ||
5394 | split_di (operands, 1, low, high); | |
5395 | ||
5396 | emit_insn (gen_x86_shrd_1 (low[0], high[0], operands[2])); | |
5397 | emit_insn (gen_ashrsi3 (high[0], high[0], operands[2])); | |
5398 | ||
5399 | if (TARGET_CMOVE && (!reload_completed || scratch)) | |
5400 | { | |
5401 | if (! reload_completed) | |
5402 | scratch = gen_reg_rtx (SImode); | |
5403 | emit_move_insn (scratch, high[0]); | |
5404 | emit_insn (gen_ashrsi3 (scratch, scratch, GEN_INT (31))); | |
5405 | emit_insn (gen_x86_shift_adj_1 (low[0], high[0], operands[2], | |
5406 | scratch)); | |
5407 | } | |
5408 | else | |
5409 | emit_insn (gen_x86_shift_adj_3 (low[0], high[0], operands[2])); | |
32b5b1aa | 5410 | } |
e075ae69 | 5411 | } |
32b5b1aa | 5412 | |
e075ae69 RH |
5413 | void |
5414 | ix86_split_lshrdi (operands, scratch) | |
5415 | rtx *operands, scratch; | |
5416 | { | |
5417 | rtx low[2], high[2]; | |
5418 | int count; | |
32b5b1aa | 5419 | |
e075ae69 | 5420 | if (GET_CODE (operands[2]) == CONST_INT) |
32b5b1aa | 5421 | { |
e075ae69 RH |
5422 | split_di (operands, 2, low, high); |
5423 | count = INTVAL (operands[2]) & 63; | |
5424 | ||
5425 | if (count >= 32) | |
c7271385 | 5426 | { |
e075ae69 RH |
5427 | emit_move_insn (low[0], high[1]); |
5428 | emit_move_insn (high[0], const0_rtx); | |
32b5b1aa | 5429 | |
e075ae69 RH |
5430 | if (count > 32) |
5431 | emit_insn (gen_lshrsi3 (low[0], low[0], GEN_INT (count - 32))); | |
5432 | } | |
5433 | else | |
5434 | { | |
5435 | if (!rtx_equal_p (operands[0], operands[1])) | |
5436 | emit_move_insn (operands[0], operands[1]); | |
5437 | emit_insn (gen_x86_shrd_1 (low[0], high[0], GEN_INT (count))); | |
5438 | emit_insn (gen_lshrsi3 (high[0], high[0], GEN_INT (count))); | |
5439 | } | |
32b5b1aa | 5440 | } |
e075ae69 RH |
5441 | else |
5442 | { | |
5443 | if (!rtx_equal_p (operands[0], operands[1])) | |
5444 | emit_move_insn (operands[0], operands[1]); | |
32b5b1aa | 5445 | |
e075ae69 RH |
5446 | split_di (operands, 1, low, high); |
5447 | ||
5448 | emit_insn (gen_x86_shrd_1 (low[0], high[0], operands[2])); | |
5449 | emit_insn (gen_lshrsi3 (high[0], high[0], operands[2])); | |
5450 | ||
5451 | /* Heh. By reversing the arguments, we can reuse this pattern. */ | |
5452 | if (TARGET_CMOVE && (! reload_completed || scratch)) | |
5453 | { | |
5454 | if (! reload_completed) | |
5455 | scratch = force_reg (SImode, const0_rtx); | |
5456 | else | |
5457 | emit_move_insn (scratch, const0_rtx); | |
5458 | ||
5459 | emit_insn (gen_x86_shift_adj_1 (low[0], high[0], operands[2], | |
5460 | scratch)); | |
5461 | } | |
5462 | else | |
5463 | emit_insn (gen_x86_shift_adj_2 (low[0], high[0], operands[2])); | |
5464 | } | |
32b5b1aa | 5465 | } |
3f803cd9 | 5466 | |
e075ae69 RH |
5467 | /* Expand the appropriate insns for doing strlen if not just doing |
5468 | repnz; scasb | |
5469 | ||
5470 | out = result, initialized with the start address | |
5471 | align_rtx = alignment of the address. | |
5472 | scratch = scratch register, initialized with the startaddress when | |
5473 | not aligned, otherwise undefined | |
3f803cd9 SC |
5474 | |
5475 | This is just the body. It needs the initialisations mentioned above and | |
5476 | some address computing at the end. These things are done in i386.md. */ | |
5477 | ||
e075ae69 RH |
5478 | void |
5479 | ix86_expand_strlensi_unroll_1 (out, align_rtx, scratch) | |
5480 | rtx out, align_rtx, scratch; | |
3f803cd9 | 5481 | { |
e075ae69 RH |
5482 | int align; |
5483 | rtx tmp; | |
5484 | rtx align_2_label = NULL_RTX; | |
5485 | rtx align_3_label = NULL_RTX; | |
5486 | rtx align_4_label = gen_label_rtx (); | |
5487 | rtx end_0_label = gen_label_rtx (); | |
e075ae69 RH |
5488 | rtx mem; |
5489 | rtx flags = gen_rtx_REG (CCNOmode, FLAGS_REG); | |
e2e52e1b | 5490 | rtx tmpreg = gen_reg_rtx (SImode); |
e075ae69 RH |
5491 | |
5492 | align = 0; | |
5493 | if (GET_CODE (align_rtx) == CONST_INT) | |
5494 | align = INTVAL (align_rtx); | |
3f803cd9 | 5495 | |
e9a25f70 | 5496 | /* Loop to check 1..3 bytes for null to get an aligned pointer. */ |
3f803cd9 | 5497 | |
e9a25f70 | 5498 | /* Is there a known alignment and is it less than 4? */ |
e075ae69 | 5499 | if (align < 4) |
3f803cd9 | 5500 | { |
e9a25f70 | 5501 | /* Is there a known alignment and is it not 2? */ |
e075ae69 | 5502 | if (align != 2) |
3f803cd9 | 5503 | { |
e075ae69 RH |
5504 | align_3_label = gen_label_rtx (); /* Label when aligned to 3-byte */ |
5505 | align_2_label = gen_label_rtx (); /* Label when aligned to 2-byte */ | |
5506 | ||
5507 | /* Leave just the 3 lower bits. */ | |
5508 | align_rtx = expand_binop (SImode, and_optab, scratch, GEN_INT (3), | |
5509 | NULL_RTX, 0, OPTAB_WIDEN); | |
5510 | ||
5511 | emit_insn (gen_cmpsi_0 (align_rtx, const0_rtx)); | |
5512 | ||
5513 | tmp = gen_rtx_EQ (VOIDmode, flags, const0_rtx); | |
5514 | tmp = gen_rtx_IF_THEN_ELSE (VOIDmode, tmp, | |
5515 | gen_rtx_LABEL_REF (VOIDmode, | |
5516 | align_4_label), | |
5517 | pc_rtx); | |
5518 | emit_jump_insn (gen_rtx_SET (VOIDmode, pc_rtx, tmp)); | |
5519 | ||
5520 | emit_insn (gen_cmpsi_1 (align_rtx, GEN_INT (2))); | |
5521 | ||
5522 | tmp = gen_rtx_EQ (VOIDmode, flags, const0_rtx); | |
5523 | tmp = gen_rtx_IF_THEN_ELSE (VOIDmode, tmp, | |
5524 | gen_rtx_LABEL_REF (VOIDmode, | |
5525 | align_2_label), | |
5526 | pc_rtx); | |
5527 | emit_jump_insn (gen_rtx_SET (VOIDmode, pc_rtx, tmp)); | |
5528 | ||
5529 | tmp = gen_rtx_GTU (VOIDmode, flags, const0_rtx); | |
5530 | tmp = gen_rtx_IF_THEN_ELSE (VOIDmode, tmp, | |
5531 | gen_rtx_LABEL_REF (VOIDmode, | |
5532 | align_3_label), | |
5533 | pc_rtx); | |
5534 | emit_jump_insn (gen_rtx_SET (VOIDmode, pc_rtx, tmp)); | |
3f803cd9 SC |
5535 | } |
5536 | else | |
5537 | { | |
e9a25f70 JL |
5538 | /* Since the alignment is 2, we have to check 2 or 0 bytes; |
5539 | check if is aligned to 4 - byte. */ | |
e9a25f70 | 5540 | |
e075ae69 RH |
5541 | align_rtx = expand_binop (SImode, and_optab, scratch, GEN_INT (2), |
5542 | NULL_RTX, 0, OPTAB_WIDEN); | |
5543 | ||
5544 | emit_insn (gen_cmpsi_0 (align_rtx, const0_rtx)); | |
5545 | ||
5546 | tmp = gen_rtx_EQ (VOIDmode, flags, const0_rtx); | |
5547 | tmp = gen_rtx_IF_THEN_ELSE (VOIDmode, tmp, | |
5548 | gen_rtx_LABEL_REF (VOIDmode, | |
5549 | align_4_label), | |
5550 | pc_rtx); | |
5551 | emit_jump_insn (gen_rtx_SET (VOIDmode, pc_rtx, tmp)); | |
3f803cd9 SC |
5552 | } |
5553 | ||
e075ae69 | 5554 | mem = gen_rtx_MEM (QImode, out); |
e9a25f70 | 5555 | |
e075ae69 | 5556 | /* Now compare the bytes. */ |
e9a25f70 | 5557 | |
e075ae69 RH |
5558 | /* Compare the first n unaligned byte on a byte per byte basis. */ |
5559 | emit_insn (gen_cmpqi_0 (mem, const0_rtx)); | |
e9a25f70 | 5560 | |
e075ae69 RH |
5561 | tmp = gen_rtx_EQ (VOIDmode, flags, const0_rtx); |
5562 | tmp = gen_rtx_IF_THEN_ELSE (VOIDmode, tmp, | |
5563 | gen_rtx_LABEL_REF (VOIDmode, end_0_label), | |
5564 | pc_rtx); | |
5565 | emit_jump_insn (gen_rtx_SET (VOIDmode, pc_rtx, tmp)); | |
3f803cd9 | 5566 | |
e075ae69 RH |
5567 | /* Increment the address. */ |
5568 | emit_insn (gen_addsi3 (out, out, const1_rtx)); | |
e9a25f70 | 5569 | |
e075ae69 RH |
5570 | /* Not needed with an alignment of 2 */ |
5571 | if (align != 2) | |
5572 | { | |
5573 | emit_label (align_2_label); | |
3f803cd9 | 5574 | |
e075ae69 | 5575 | emit_insn (gen_cmpqi_0 (mem, const0_rtx)); |
3f803cd9 | 5576 | |
e075ae69 RH |
5577 | tmp = gen_rtx_EQ (VOIDmode, flags, const0_rtx); |
5578 | tmp = gen_rtx_IF_THEN_ELSE (VOIDmode, tmp, | |
5579 | gen_rtx_LABEL_REF (VOIDmode, | |
5580 | end_0_label), | |
5581 | pc_rtx); | |
5582 | emit_jump_insn (gen_rtx_SET (VOIDmode, pc_rtx, tmp)); | |
5583 | ||
5584 | emit_insn (gen_addsi3 (out, out, const1_rtx)); | |
5585 | ||
5586 | emit_label (align_3_label); | |
5587 | } | |
5588 | ||
5589 | emit_insn (gen_cmpqi_0 (mem, const0_rtx)); | |
e9a25f70 | 5590 | |
e075ae69 RH |
5591 | tmp = gen_rtx_EQ (VOIDmode, flags, const0_rtx); |
5592 | tmp = gen_rtx_IF_THEN_ELSE (VOIDmode, tmp, | |
5593 | gen_rtx_LABEL_REF (VOIDmode, end_0_label), | |
5594 | pc_rtx); | |
5595 | emit_jump_insn (gen_rtx_SET (VOIDmode, pc_rtx, tmp)); | |
5596 | ||
5597 | emit_insn (gen_addsi3 (out, out, const1_rtx)); | |
3f803cd9 SC |
5598 | } |
5599 | ||
e075ae69 RH |
5600 | /* Generate loop to check 4 bytes at a time. It is not a good idea to |
5601 | align this loop. It gives only huge programs, but does not help to | |
5602 | speed up. */ | |
5603 | emit_label (align_4_label); | |
3f803cd9 | 5604 | |
e075ae69 RH |
5605 | mem = gen_rtx_MEM (SImode, out); |
5606 | emit_move_insn (scratch, mem); | |
e075ae69 | 5607 | emit_insn (gen_addsi3 (out, out, GEN_INT (4))); |
e075ae69 | 5608 | |
e2e52e1b JH |
5609 | /* This formula yields a nonzero result iff one of the bytes is zero. |
5610 | This saves three branches inside loop and many cycles. */ | |
5611 | ||
5612 | emit_insn (gen_addsi3 (tmpreg, scratch, GEN_INT (-0x01010101))); | |
5613 | emit_insn (gen_one_cmplsi2 (scratch, scratch)); | |
5614 | emit_insn (gen_andsi3 (tmpreg, tmpreg, scratch)); | |
5615 | emit_insn (gen_andsi3 (tmpreg, tmpreg, GEN_INT (0x80808080))); | |
5616 | emit_cmp_and_jump_insns (tmpreg, const0_rtx, EQ, 0, SImode, 1, 0, align_4_label); | |
5617 | ||
5618 | if (TARGET_CMOVE) | |
5619 | { | |
5620 | rtx reg = gen_reg_rtx (SImode); | |
5621 | emit_move_insn (reg, tmpreg); | |
5622 | emit_insn (gen_lshrsi3 (reg, reg, GEN_INT (16))); | |
5623 | ||
5624 | /* If zero is not in the first two bytes, move two bytes forward. */ | |
5625 | emit_insn (gen_testsi_1 (tmpreg, GEN_INT (0x8080))); | |
5626 | tmp = gen_rtx_REG (CCNOmode, FLAGS_REG); | |
5627 | tmp = gen_rtx_EQ (VOIDmode, tmp, const0_rtx); | |
5628 | emit_insn (gen_rtx_SET (VOIDmode, tmpreg, | |
5629 | gen_rtx_IF_THEN_ELSE (SImode, tmp, | |
5630 | reg, | |
5631 | tmpreg))); | |
5632 | /* Emit lea manually to avoid clobbering of flags. */ | |
5633 | emit_insn (gen_rtx_SET (SImode, reg, | |
5634 | gen_rtx_PLUS (SImode, out, GEN_INT (2)))); | |
5635 | ||
5636 | tmp = gen_rtx_REG (CCNOmode, FLAGS_REG); | |
5637 | tmp = gen_rtx_EQ (VOIDmode, tmp, const0_rtx); | |
5638 | emit_insn (gen_rtx_SET (VOIDmode, out, | |
5639 | gen_rtx_IF_THEN_ELSE (SImode, tmp, | |
5640 | reg, | |
5641 | out))); | |
5642 | ||
5643 | } | |
5644 | else | |
5645 | { | |
5646 | rtx end_2_label = gen_label_rtx (); | |
5647 | /* Is zero in the first two bytes? */ | |
5648 | ||
5649 | emit_insn (gen_testsi_1 (tmpreg, GEN_INT (0x8080))); | |
5650 | tmp = gen_rtx_REG (CCNOmode, FLAGS_REG); | |
5651 | tmp = gen_rtx_NE (VOIDmode, tmp, const0_rtx); | |
5652 | tmp = gen_rtx_IF_THEN_ELSE (VOIDmode, tmp, | |
5653 | gen_rtx_LABEL_REF (VOIDmode, end_2_label), | |
5654 | pc_rtx); | |
5655 | tmp = emit_jump_insn (gen_rtx_SET (VOIDmode, pc_rtx, tmp)); | |
5656 | JUMP_LABEL (tmp) = end_2_label; | |
5657 | ||
5658 | /* Not in the first two. Move two bytes forward. */ | |
5659 | emit_insn (gen_lshrsi3 (tmpreg, tmpreg, GEN_INT (16))); | |
5660 | emit_insn (gen_addsi3 (out, out, GEN_INT (2))); | |
5661 | ||
5662 | emit_label (end_2_label); | |
5663 | ||
5664 | } | |
5665 | ||
5666 | /* Avoid branch in fixing the byte. */ | |
5667 | tmpreg = gen_lowpart (QImode, tmpreg); | |
5668 | emit_insn (gen_addqi3_cc (tmpreg, tmpreg, tmpreg)); | |
5669 | emit_insn (gen_subsi3_carry (out, out, GEN_INT (3))); | |
e075ae69 RH |
5670 | |
5671 | emit_label (end_0_label); | |
5672 | } | |
5673 | \f | |
e075ae69 RH |
5674 | /* Clear stack slot assignments remembered from previous functions. |
5675 | This is called from INIT_EXPANDERS once before RTL is emitted for each | |
5676 | function. */ | |
5677 | ||
36edd3cc BS |
5678 | static void |
5679 | ix86_init_machine_status (p) | |
1526a060 | 5680 | struct function *p; |
e075ae69 RH |
5681 | { |
5682 | enum machine_mode mode; | |
5683 | int n; | |
36edd3cc BS |
5684 | p->machine |
5685 | = (struct machine_function *) xmalloc (sizeof (struct machine_function)); | |
e075ae69 RH |
5686 | |
5687 | for (mode = VOIDmode; (int) mode < (int) MAX_MACHINE_MODE; | |
5688 | mode = (enum machine_mode) ((int) mode + 1)) | |
5689 | for (n = 0; n < MAX_386_STACK_LOCALS; n++) | |
5690 | ix86_stack_locals[(int) mode][n] = NULL_RTX; | |
e075ae69 RH |
5691 | } |
5692 | ||
1526a060 BS |
5693 | /* Mark machine specific bits of P for GC. */ |
5694 | static void | |
5695 | ix86_mark_machine_status (p) | |
5696 | struct function *p; | |
5697 | { | |
5698 | enum machine_mode mode; | |
5699 | int n; | |
5700 | ||
5701 | for (mode = VOIDmode; (int) mode < (int) MAX_MACHINE_MODE; | |
5702 | mode = (enum machine_mode) ((int) mode + 1)) | |
5703 | for (n = 0; n < MAX_386_STACK_LOCALS; n++) | |
5704 | ggc_mark_rtx (p->machine->stack_locals[(int) mode][n]); | |
5705 | } | |
5706 | ||
e075ae69 RH |
5707 | /* Return a MEM corresponding to a stack slot with mode MODE. |
5708 | Allocate a new slot if necessary. | |
5709 | ||
5710 | The RTL for a function can have several slots available: N is | |
5711 | which slot to use. */ | |
5712 | ||
5713 | rtx | |
5714 | assign_386_stack_local (mode, n) | |
5715 | enum machine_mode mode; | |
5716 | int n; | |
5717 | { | |
5718 | if (n < 0 || n >= MAX_386_STACK_LOCALS) | |
5719 | abort (); | |
5720 | ||
5721 | if (ix86_stack_locals[(int) mode][n] == NULL_RTX) | |
5722 | ix86_stack_locals[(int) mode][n] | |
5723 | = assign_stack_local (mode, GET_MODE_SIZE (mode), 0); | |
5724 | ||
5725 | return ix86_stack_locals[(int) mode][n]; | |
5726 | } | |
5727 | \f | |
5728 | /* Calculate the length of the memory address in the instruction | |
5729 | encoding. Does not include the one-byte modrm, opcode, or prefix. */ | |
5730 | ||
5731 | static int | |
5732 | memory_address_length (addr) | |
5733 | rtx addr; | |
5734 | { | |
5735 | struct ix86_address parts; | |
5736 | rtx base, index, disp; | |
5737 | int len; | |
5738 | ||
5739 | if (GET_CODE (addr) == PRE_DEC | |
5740 | || GET_CODE (addr) == POST_INC) | |
5741 | return 0; | |
3f803cd9 | 5742 | |
e075ae69 RH |
5743 | if (! ix86_decompose_address (addr, &parts)) |
5744 | abort (); | |
3f803cd9 | 5745 | |
e075ae69 RH |
5746 | base = parts.base; |
5747 | index = parts.index; | |
5748 | disp = parts.disp; | |
5749 | len = 0; | |
3f803cd9 | 5750 | |
e075ae69 RH |
5751 | /* Register Indirect. */ |
5752 | if (base && !index && !disp) | |
5753 | { | |
5754 | /* Special cases: ebp and esp need the two-byte modrm form. */ | |
5755 | if (addr == stack_pointer_rtx | |
5756 | || addr == arg_pointer_rtx | |
564d80f4 JH |
5757 | || addr == frame_pointer_rtx |
5758 | || addr == hard_frame_pointer_rtx) | |
e075ae69 | 5759 | len = 1; |
3f803cd9 | 5760 | } |
e9a25f70 | 5761 | |
e075ae69 RH |
5762 | /* Direct Addressing. */ |
5763 | else if (disp && !base && !index) | |
5764 | len = 4; | |
5765 | ||
3f803cd9 SC |
5766 | else |
5767 | { | |
e075ae69 RH |
5768 | /* Find the length of the displacement constant. */ |
5769 | if (disp) | |
5770 | { | |
5771 | if (GET_CODE (disp) == CONST_INT | |
5772 | && CONST_OK_FOR_LETTER_P (INTVAL (disp), 'K')) | |
5773 | len = 1; | |
5774 | else | |
5775 | len = 4; | |
5776 | } | |
3f803cd9 | 5777 | |
e075ae69 RH |
5778 | /* An index requires the two-byte modrm form. */ |
5779 | if (index) | |
5780 | len += 1; | |
3f803cd9 SC |
5781 | } |
5782 | ||
e075ae69 RH |
5783 | return len; |
5784 | } | |
79325812 | 5785 | |
e075ae69 RH |
5786 | int |
5787 | ix86_attr_length_default (insn) | |
5788 | rtx insn; | |
5789 | { | |
5790 | enum attr_type type; | |
5791 | int len = 0, i; | |
5792 | ||
5793 | type = get_attr_type (insn); | |
5794 | extract_insn (insn); | |
5795 | switch (type) | |
5796 | { | |
5797 | case TYPE_INCDEC: | |
5798 | case TYPE_SETCC: | |
5799 | case TYPE_ICMOV: | |
5800 | case TYPE_FMOV: | |
5801 | case TYPE_FOP: | |
5802 | case TYPE_FCMP: | |
5803 | case TYPE_FOP1: | |
5804 | case TYPE_FMUL: | |
5805 | case TYPE_FDIV: | |
5806 | case TYPE_FSGN: | |
5807 | case TYPE_FPSPC: | |
5808 | case TYPE_FCMOV: | |
5809 | case TYPE_IBR: | |
5810 | break; | |
7c7ef435 JH |
5811 | case TYPE_STR: |
5812 | case TYPE_CLD: | |
5813 | len = 0; | |
3f803cd9 | 5814 | |
e075ae69 RH |
5815 | case TYPE_ALU1: |
5816 | case TYPE_NEGNOT: | |
5817 | case TYPE_ALU: | |
5818 | case TYPE_ICMP: | |
5819 | case TYPE_IMOVX: | |
5820 | case TYPE_ISHIFT: | |
5821 | case TYPE_IMUL: | |
5822 | case TYPE_IDIV: | |
5823 | case TYPE_PUSH: | |
5824 | case TYPE_POP: | |
1ccbefce RH |
5825 | for (i = recog_data.n_operands - 1; i >= 0; --i) |
5826 | if (CONSTANT_P (recog_data.operand[i])) | |
e075ae69 | 5827 | { |
1ccbefce RH |
5828 | if (GET_CODE (recog_data.operand[i]) == CONST_INT |
5829 | && CONST_OK_FOR_LETTER_P (INTVAL (recog_data.operand[i]), 'K')) | |
e075ae69 RH |
5830 | len += 1; |
5831 | else | |
1ccbefce | 5832 | len += GET_MODE_SIZE (GET_MODE (recog_data.operand[0])); |
e075ae69 RH |
5833 | } |
5834 | break; | |
5835 | ||
5836 | case TYPE_IMOV: | |
1ccbefce RH |
5837 | if (CONSTANT_P (recog_data.operand[1])) |
5838 | len += GET_MODE_SIZE (GET_MODE (recog_data.operand[0])); | |
e075ae69 RH |
5839 | break; |
5840 | ||
5841 | case TYPE_CALL: | |
6baf1cc8 BS |
5842 | if (constant_call_address_operand (recog_data.operand[0], |
5843 | GET_MODE (recog_data.operand[0]))) | |
e075ae69 RH |
5844 | return 5; |
5845 | break; | |
3f803cd9 | 5846 | |
e075ae69 | 5847 | case TYPE_CALLV: |
6baf1cc8 BS |
5848 | if (constant_call_address_operand (recog_data.operand[1], |
5849 | GET_MODE (recog_data.operand[1]))) | |
e075ae69 RH |
5850 | return 5; |
5851 | break; | |
3f803cd9 | 5852 | |
e075ae69 | 5853 | case TYPE_LEA: |
3071fab5 RH |
5854 | { |
5855 | /* Irritatingly, single_set doesn't work with REG_UNUSED present, | |
5856 | as we'll get from running life_analysis during reg-stack when | |
1c71e60e JH |
5857 | not optimizing. Not that it matters anyway, now that |
5858 | pro_epilogue_adjust_stack uses lea, and is by design not | |
5859 | single_set. */ | |
3071fab5 RH |
5860 | rtx set = PATTERN (insn); |
5861 | if (GET_CODE (set) == SET) | |
5862 | ; | |
5863 | else if (GET_CODE (set) == PARALLEL | |
1c71e60e | 5864 | && GET_CODE (XVECEXP (set, 0, 0)) == SET) |
3071fab5 RH |
5865 | set = XVECEXP (set, 0, 0); |
5866 | else | |
5867 | abort (); | |
5868 | ||
5869 | len += memory_address_length (SET_SRC (set)); | |
5870 | goto just_opcode; | |
5871 | } | |
3f803cd9 | 5872 | |
e075ae69 RH |
5873 | case TYPE_OTHER: |
5874 | case TYPE_MULTI: | |
5875 | return 15; | |
3f803cd9 | 5876 | |
5d3c4797 | 5877 | case TYPE_FXCH: |
1ccbefce RH |
5878 | if (STACK_TOP_P (recog_data.operand[0])) |
5879 | return 2 + (REGNO (recog_data.operand[1]) != FIRST_STACK_REG + 1); | |
5d3c4797 | 5880 | else |
1ccbefce | 5881 | return 2 + (REGNO (recog_data.operand[0]) != FIRST_STACK_REG + 1); |
5d3c4797 | 5882 | |
e075ae69 RH |
5883 | default: |
5884 | abort (); | |
5885 | } | |
5886 | ||
1ccbefce RH |
5887 | for (i = recog_data.n_operands - 1; i >= 0; --i) |
5888 | if (GET_CODE (recog_data.operand[i]) == MEM) | |
e075ae69 | 5889 | { |
1ccbefce | 5890 | len += memory_address_length (XEXP (recog_data.operand[i], 0)); |
e075ae69 RH |
5891 | break; |
5892 | } | |
5893 | ||
5894 | just_opcode: | |
5895 | len += get_attr_length_opcode (insn); | |
5896 | len += get_attr_length_prefix (insn); | |
5897 | ||
5898 | return len; | |
3f803cd9 | 5899 | } |
e075ae69 RH |
5900 | \f |
5901 | /* Return the maximum number of instructions a cpu can issue. */ | |
b657fc39 | 5902 | |
e075ae69 RH |
5903 | int |
5904 | ix86_issue_rate () | |
b657fc39 | 5905 | { |
e075ae69 | 5906 | switch (ix86_cpu) |
b657fc39 | 5907 | { |
e075ae69 RH |
5908 | case PROCESSOR_PENTIUM: |
5909 | case PROCESSOR_K6: | |
5910 | return 2; | |
79325812 | 5911 | |
e075ae69 RH |
5912 | case PROCESSOR_PENTIUMPRO: |
5913 | return 3; | |
b657fc39 | 5914 | |
b657fc39 | 5915 | default: |
e075ae69 | 5916 | return 1; |
b657fc39 | 5917 | } |
b657fc39 L |
5918 | } |
5919 | ||
e075ae69 RH |
5920 | /* A subroutine of ix86_adjust_cost -- return true iff INSN reads flags set |
5921 | by DEP_INSN and nothing set by DEP_INSN. */ | |
b657fc39 | 5922 | |
e075ae69 RH |
5923 | static int |
5924 | ix86_flags_dependant (insn, dep_insn, insn_type) | |
5925 | rtx insn, dep_insn; | |
5926 | enum attr_type insn_type; | |
5927 | { | |
5928 | rtx set, set2; | |
b657fc39 | 5929 | |
e075ae69 RH |
5930 | /* Simplify the test for uninteresting insns. */ |
5931 | if (insn_type != TYPE_SETCC | |
5932 | && insn_type != TYPE_ICMOV | |
5933 | && insn_type != TYPE_FCMOV | |
5934 | && insn_type != TYPE_IBR) | |
5935 | return 0; | |
b657fc39 | 5936 | |
e075ae69 RH |
5937 | if ((set = single_set (dep_insn)) != 0) |
5938 | { | |
5939 | set = SET_DEST (set); | |
5940 | set2 = NULL_RTX; | |
5941 | } | |
5942 | else if (GET_CODE (PATTERN (dep_insn)) == PARALLEL | |
5943 | && XVECLEN (PATTERN (dep_insn), 0) == 2 | |
5944 | && GET_CODE (XVECEXP (PATTERN (dep_insn), 0, 0)) == SET | |
5945 | && GET_CODE (XVECEXP (PATTERN (dep_insn), 0, 1)) == SET) | |
5946 | { | |
5947 | set = SET_DEST (XVECEXP (PATTERN (dep_insn), 0, 0)); | |
5948 | set2 = SET_DEST (XVECEXP (PATTERN (dep_insn), 0, 0)); | |
5949 | } | |
78a0d70c ZW |
5950 | else |
5951 | return 0; | |
b657fc39 | 5952 | |
78a0d70c ZW |
5953 | if (GET_CODE (set) != REG || REGNO (set) != FLAGS_REG) |
5954 | return 0; | |
b657fc39 | 5955 | |
78a0d70c ZW |
5956 | /* This test is true if the dependant insn reads the flags but |
5957 | not any other potentially set register. */ | |
5958 | if (!reg_overlap_mentioned_p (set, PATTERN (insn))) | |
5959 | return 0; | |
5960 | ||
5961 | if (set2 && reg_overlap_mentioned_p (set2, PATTERN (insn))) | |
5962 | return 0; | |
5963 | ||
5964 | return 1; | |
e075ae69 | 5965 | } |
b657fc39 | 5966 | |
e075ae69 RH |
5967 | /* A subroutine of ix86_adjust_cost -- return true iff INSN has a memory |
5968 | address with operands set by DEP_INSN. */ | |
5969 | ||
5970 | static int | |
5971 | ix86_agi_dependant (insn, dep_insn, insn_type) | |
5972 | rtx insn, dep_insn; | |
5973 | enum attr_type insn_type; | |
5974 | { | |
5975 | rtx addr; | |
5976 | ||
5977 | if (insn_type == TYPE_LEA) | |
5fbdde42 RH |
5978 | { |
5979 | addr = PATTERN (insn); | |
5980 | if (GET_CODE (addr) == SET) | |
5981 | ; | |
5982 | else if (GET_CODE (addr) == PARALLEL | |
5983 | && GET_CODE (XVECEXP (addr, 0, 0)) == SET) | |
5984 | addr = XVECEXP (addr, 0, 0); | |
5985 | else | |
5986 | abort (); | |
5987 | addr = SET_SRC (addr); | |
5988 | } | |
e075ae69 RH |
5989 | else |
5990 | { | |
5991 | int i; | |
5992 | extract_insn (insn); | |
1ccbefce RH |
5993 | for (i = recog_data.n_operands - 1; i >= 0; --i) |
5994 | if (GET_CODE (recog_data.operand[i]) == MEM) | |
e075ae69 | 5995 | { |
1ccbefce | 5996 | addr = XEXP (recog_data.operand[i], 0); |
e075ae69 RH |
5997 | goto found; |
5998 | } | |
5999 | return 0; | |
6000 | found:; | |
b657fc39 L |
6001 | } |
6002 | ||
e075ae69 | 6003 | return modified_in_p (addr, dep_insn); |
b657fc39 | 6004 | } |
a269a03c JC |
6005 | |
6006 | int | |
e075ae69 | 6007 | ix86_adjust_cost (insn, link, dep_insn, cost) |
a269a03c JC |
6008 | rtx insn, link, dep_insn; |
6009 | int cost; | |
6010 | { | |
e075ae69 RH |
6011 | enum attr_type insn_type, dep_insn_type; |
6012 | rtx set, set2; | |
9b00189f | 6013 | int dep_insn_code_number; |
a269a03c | 6014 | |
309ada50 | 6015 | /* Anti and output depenancies have zero cost on all CPUs. */ |
e075ae69 | 6016 | if (REG_NOTE_KIND (link) != 0) |
309ada50 | 6017 | return 0; |
a269a03c | 6018 | |
9b00189f JH |
6019 | dep_insn_code_number = recog_memoized (dep_insn); |
6020 | ||
e075ae69 | 6021 | /* If we can't recognize the insns, we can't really do anything. */ |
9b00189f | 6022 | if (dep_insn_code_number < 0 || recog_memoized (insn) < 0) |
e075ae69 | 6023 | return cost; |
a269a03c | 6024 | |
1c71e60e JH |
6025 | insn_type = get_attr_type (insn); |
6026 | dep_insn_type = get_attr_type (dep_insn); | |
9b00189f | 6027 | |
1c71e60e JH |
6028 | /* Prologue and epilogue allocators can have a false dependency on ebp. |
6029 | This results in one cycle extra stall on Pentium prologue scheduling, | |
6030 | so handle this important case manually. */ | |
6031 | if (dep_insn_code_number == CODE_FOR_pro_epilogue_adjust_stack | |
6032 | && dep_insn_type == TYPE_ALU | |
9b00189f JH |
6033 | && !reg_mentioned_p (stack_pointer_rtx, insn)) |
6034 | return 0; | |
6035 | ||
a269a03c JC |
6036 | switch (ix86_cpu) |
6037 | { | |
6038 | case PROCESSOR_PENTIUM: | |
e075ae69 RH |
6039 | /* Address Generation Interlock adds a cycle of latency. */ |
6040 | if (ix86_agi_dependant (insn, dep_insn, insn_type)) | |
6041 | cost += 1; | |
6042 | ||
6043 | /* ??? Compares pair with jump/setcc. */ | |
6044 | if (ix86_flags_dependant (insn, dep_insn, insn_type)) | |
6045 | cost = 0; | |
6046 | ||
6047 | /* Floating point stores require value to be ready one cycle ealier. */ | |
6048 | if (insn_type == TYPE_FMOV | |
6049 | && get_attr_memory (insn) == MEMORY_STORE | |
6050 | && !ix86_agi_dependant (insn, dep_insn, insn_type)) | |
6051 | cost += 1; | |
6052 | break; | |
a269a03c | 6053 | |
e075ae69 RH |
6054 | case PROCESSOR_PENTIUMPRO: |
6055 | /* Since we can't represent delayed latencies of load+operation, | |
6056 | increase the cost here for non-imov insns. */ | |
6057 | if (dep_insn_type != TYPE_IMOV | |
6058 | && dep_insn_type != TYPE_FMOV | |
6059 | && get_attr_memory (dep_insn) == MEMORY_LOAD) | |
6060 | cost += 1; | |
6061 | ||
6062 | /* INT->FP conversion is expensive. */ | |
6063 | if (get_attr_fp_int_src (dep_insn)) | |
6064 | cost += 5; | |
6065 | ||
6066 | /* There is one cycle extra latency between an FP op and a store. */ | |
6067 | if (insn_type == TYPE_FMOV | |
6068 | && (set = single_set (dep_insn)) != NULL_RTX | |
6069 | && (set2 = single_set (insn)) != NULL_RTX | |
6070 | && rtx_equal_p (SET_DEST (set), SET_SRC (set2)) | |
6071 | && GET_CODE (SET_DEST (set2)) == MEM) | |
6072 | cost += 1; | |
6073 | break; | |
a269a03c | 6074 | |
e075ae69 RH |
6075 | case PROCESSOR_K6: |
6076 | /* The esp dependency is resolved before the instruction is really | |
6077 | finished. */ | |
6078 | if ((insn_type == TYPE_PUSH || insn_type == TYPE_POP) | |
6079 | && (dep_insn_type == TYPE_PUSH || dep_insn_type == TYPE_POP)) | |
6080 | return 1; | |
a269a03c | 6081 | |
e075ae69 RH |
6082 | /* Since we can't represent delayed latencies of load+operation, |
6083 | increase the cost here for non-imov insns. */ | |
6084 | if (get_attr_memory (dep_insn) == MEMORY_LOAD) | |
6085 | cost += (dep_insn_type != TYPE_IMOV) ? 2 : 1; | |
6086 | ||
6087 | /* INT->FP conversion is expensive. */ | |
6088 | if (get_attr_fp_int_src (dep_insn)) | |
6089 | cost += 5; | |
a14003ee | 6090 | break; |
e075ae69 | 6091 | |
309ada50 JH |
6092 | case PROCESSOR_ATHLON: |
6093 | /* Address Generation Interlock cause problems on the Athlon CPU because | |
6094 | the loads and stores are done in order so once one load or store has | |
6095 | to wait, others must too, so penalize the AGIs slightly by one cycle. | |
6096 | We might experiment with this value later. */ | |
6097 | if (ix86_agi_dependant (insn, dep_insn, insn_type)) | |
6098 | cost += 1; | |
6099 | ||
6100 | /* Since we can't represent delayed latencies of load+operation, | |
6101 | increase the cost here for non-imov insns. */ | |
6102 | if (dep_insn_type != TYPE_IMOV | |
6103 | && dep_insn_type != TYPE_FMOV | |
6104 | && get_attr_memory (dep_insn) == MEMORY_LOAD) | |
6105 | cost += 2; | |
a269a03c | 6106 | default: |
a269a03c JC |
6107 | break; |
6108 | } | |
6109 | ||
6110 | return cost; | |
6111 | } | |
0a726ef1 | 6112 | |
e075ae69 RH |
6113 | static union |
6114 | { | |
6115 | struct ppro_sched_data | |
6116 | { | |
6117 | rtx decode[3]; | |
6118 | int issued_this_cycle; | |
6119 | } ppro; | |
6120 | } ix86_sched_data; | |
0a726ef1 | 6121 | |
e075ae69 RH |
6122 | static int |
6123 | ix86_safe_length (insn) | |
6124 | rtx insn; | |
6125 | { | |
6126 | if (recog_memoized (insn) >= 0) | |
6127 | return get_attr_length(insn); | |
6128 | else | |
6129 | return 128; | |
6130 | } | |
0a726ef1 | 6131 | |
e075ae69 RH |
6132 | static int |
6133 | ix86_safe_length_prefix (insn) | |
6134 | rtx insn; | |
6135 | { | |
6136 | if (recog_memoized (insn) >= 0) | |
6137 | return get_attr_length(insn); | |
6138 | else | |
6139 | return 0; | |
6140 | } | |
6141 | ||
6142 | static enum attr_memory | |
6143 | ix86_safe_memory (insn) | |
6144 | rtx insn; | |
6145 | { | |
6146 | if (recog_memoized (insn) >= 0) | |
6147 | return get_attr_memory(insn); | |
6148 | else | |
6149 | return MEMORY_UNKNOWN; | |
6150 | } | |
0a726ef1 | 6151 | |
e075ae69 RH |
6152 | static enum attr_pent_pair |
6153 | ix86_safe_pent_pair (insn) | |
6154 | rtx insn; | |
6155 | { | |
6156 | if (recog_memoized (insn) >= 0) | |
6157 | return get_attr_pent_pair(insn); | |
6158 | else | |
6159 | return PENT_PAIR_NP; | |
6160 | } | |
0a726ef1 | 6161 | |
e075ae69 RH |
6162 | static enum attr_ppro_uops |
6163 | ix86_safe_ppro_uops (insn) | |
6164 | rtx insn; | |
6165 | { | |
6166 | if (recog_memoized (insn) >= 0) | |
6167 | return get_attr_ppro_uops (insn); | |
6168 | else | |
6169 | return PPRO_UOPS_MANY; | |
6170 | } | |
0a726ef1 | 6171 | |
e075ae69 RH |
6172 | static void |
6173 | ix86_dump_ppro_packet (dump) | |
6174 | FILE *dump; | |
0a726ef1 | 6175 | { |
e075ae69 | 6176 | if (ix86_sched_data.ppro.decode[0]) |
0a726ef1 | 6177 | { |
e075ae69 RH |
6178 | fprintf (dump, "PPRO packet: %d", |
6179 | INSN_UID (ix86_sched_data.ppro.decode[0])); | |
6180 | if (ix86_sched_data.ppro.decode[1]) | |
6181 | fprintf (dump, " %d", INSN_UID (ix86_sched_data.ppro.decode[1])); | |
6182 | if (ix86_sched_data.ppro.decode[2]) | |
6183 | fprintf (dump, " %d", INSN_UID (ix86_sched_data.ppro.decode[2])); | |
6184 | fputc ('\n', dump); | |
6185 | } | |
6186 | } | |
0a726ef1 | 6187 | |
e075ae69 | 6188 | /* We're beginning a new block. Initialize data structures as necessary. */ |
0a726ef1 | 6189 | |
e075ae69 RH |
6190 | void |
6191 | ix86_sched_init (dump, sched_verbose) | |
6192 | FILE *dump ATTRIBUTE_UNUSED; | |
6193 | int sched_verbose ATTRIBUTE_UNUSED; | |
6194 | { | |
6195 | memset (&ix86_sched_data, 0, sizeof (ix86_sched_data)); | |
6196 | } | |
6197 | ||
6198 | /* Shift INSN to SLOT, and shift everything else down. */ | |
6199 | ||
6200 | static void | |
6201 | ix86_reorder_insn (insnp, slot) | |
6202 | rtx *insnp, *slot; | |
6203 | { | |
6204 | if (insnp != slot) | |
6205 | { | |
6206 | rtx insn = *insnp; | |
6207 | do | |
6208 | insnp[0] = insnp[1]; | |
6209 | while (++insnp != slot); | |
6210 | *insnp = insn; | |
0a726ef1 | 6211 | } |
e075ae69 RH |
6212 | } |
6213 | ||
6214 | /* Find an instruction with given pairability and minimal amount of cycles | |
6215 | lost by the fact that the CPU waits for both pipelines to finish before | |
6216 | reading next instructions. Also take care that both instructions together | |
6217 | can not exceed 7 bytes. */ | |
6218 | ||
6219 | static rtx * | |
6220 | ix86_pent_find_pair (e_ready, ready, type, first) | |
6221 | rtx *e_ready; | |
6222 | rtx *ready; | |
6223 | enum attr_pent_pair type; | |
6224 | rtx first; | |
6225 | { | |
6226 | int mincycles, cycles; | |
6227 | enum attr_pent_pair tmp; | |
6228 | enum attr_memory memory; | |
6229 | rtx *insnp, *bestinsnp = NULL; | |
0a726ef1 | 6230 | |
e075ae69 RH |
6231 | if (ix86_safe_length (first) > 7 + ix86_safe_length_prefix (first)) |
6232 | return NULL; | |
0a726ef1 | 6233 | |
e075ae69 RH |
6234 | memory = ix86_safe_memory (first); |
6235 | cycles = result_ready_cost (first); | |
6236 | mincycles = INT_MAX; | |
6237 | ||
6238 | for (insnp = e_ready; insnp >= ready && mincycles; --insnp) | |
6239 | if ((tmp = ix86_safe_pent_pair (*insnp)) == type | |
6240 | && ix86_safe_length (*insnp) <= 7 + ix86_safe_length_prefix (*insnp)) | |
6ec6d558 | 6241 | { |
e075ae69 RH |
6242 | enum attr_memory second_memory; |
6243 | int secondcycles, currentcycles; | |
6244 | ||
6245 | second_memory = ix86_safe_memory (*insnp); | |
6246 | secondcycles = result_ready_cost (*insnp); | |
6247 | currentcycles = abs (cycles - secondcycles); | |
6248 | ||
6249 | if (secondcycles >= 1 && cycles >= 1) | |
6ec6d558 | 6250 | { |
e075ae69 RH |
6251 | /* Two read/modify/write instructions together takes two |
6252 | cycles longer. */ | |
6253 | if (memory == MEMORY_BOTH && second_memory == MEMORY_BOTH) | |
6254 | currentcycles += 2; | |
6255 | ||
6256 | /* Read modify/write instruction followed by read/modify | |
6257 | takes one cycle longer. */ | |
6258 | if (memory == MEMORY_BOTH && second_memory == MEMORY_LOAD | |
6259 | && tmp != PENT_PAIR_UV | |
6260 | && ix86_safe_pent_pair (first) != PENT_PAIR_UV) | |
6261 | currentcycles += 1; | |
6ec6d558 | 6262 | } |
e075ae69 RH |
6263 | if (currentcycles < mincycles) |
6264 | bestinsnp = insnp, mincycles = currentcycles; | |
6ec6d558 | 6265 | } |
0a726ef1 | 6266 | |
e075ae69 RH |
6267 | return bestinsnp; |
6268 | } | |
6269 | ||
78a0d70c | 6270 | /* Subroutines of ix86_sched_reorder. */ |
e075ae69 | 6271 | |
c6991660 | 6272 | static void |
78a0d70c | 6273 | ix86_sched_reorder_pentium (ready, e_ready) |
e075ae69 | 6274 | rtx *ready; |
78a0d70c | 6275 | rtx *e_ready; |
e075ae69 | 6276 | { |
78a0d70c | 6277 | enum attr_pent_pair pair1, pair2; |
e075ae69 | 6278 | rtx *insnp; |
e075ae69 | 6279 | |
78a0d70c ZW |
6280 | /* This wouldn't be necessary if Haifa knew that static insn ordering |
6281 | is important to which pipe an insn is issued to. So we have to make | |
6282 | some minor rearrangements. */ | |
e075ae69 | 6283 | |
78a0d70c ZW |
6284 | pair1 = ix86_safe_pent_pair (*e_ready); |
6285 | ||
6286 | /* If the first insn is non-pairable, let it be. */ | |
6287 | if (pair1 == PENT_PAIR_NP) | |
6288 | return; | |
6289 | ||
6290 | pair2 = PENT_PAIR_NP; | |
6291 | insnp = 0; | |
6292 | ||
6293 | /* If the first insn is UV or PV pairable, search for a PU | |
6294 | insn to go with. */ | |
6295 | if (pair1 == PENT_PAIR_UV || pair1 == PENT_PAIR_PV) | |
e075ae69 | 6296 | { |
78a0d70c ZW |
6297 | insnp = ix86_pent_find_pair (e_ready-1, ready, |
6298 | PENT_PAIR_PU, *e_ready); | |
6299 | if (insnp) | |
6300 | pair2 = PENT_PAIR_PU; | |
6301 | } | |
e075ae69 | 6302 | |
78a0d70c ZW |
6303 | /* If the first insn is PU or UV pairable, search for a PV |
6304 | insn to go with. */ | |
6305 | if (pair2 == PENT_PAIR_NP | |
6306 | && (pair1 == PENT_PAIR_PU || pair1 == PENT_PAIR_UV)) | |
6307 | { | |
6308 | insnp = ix86_pent_find_pair (e_ready-1, ready, | |
6309 | PENT_PAIR_PV, *e_ready); | |
6310 | if (insnp) | |
6311 | pair2 = PENT_PAIR_PV; | |
6312 | } | |
e075ae69 | 6313 | |
78a0d70c ZW |
6314 | /* If the first insn is pairable, search for a UV |
6315 | insn to go with. */ | |
6316 | if (pair2 == PENT_PAIR_NP) | |
6317 | { | |
6318 | insnp = ix86_pent_find_pair (e_ready-1, ready, | |
6319 | PENT_PAIR_UV, *e_ready); | |
6320 | if (insnp) | |
6321 | pair2 = PENT_PAIR_UV; | |
6322 | } | |
e075ae69 | 6323 | |
78a0d70c ZW |
6324 | if (pair2 == PENT_PAIR_NP) |
6325 | return; | |
e075ae69 | 6326 | |
78a0d70c ZW |
6327 | /* Found something! Decide if we need to swap the order. */ |
6328 | if (pair1 == PENT_PAIR_PV || pair2 == PENT_PAIR_PU | |
6329 | || (pair1 == PENT_PAIR_UV && pair2 == PENT_PAIR_UV | |
6330 | && ix86_safe_memory (*e_ready) == MEMORY_BOTH | |
6331 | && ix86_safe_memory (*insnp) == MEMORY_LOAD)) | |
6332 | ix86_reorder_insn (insnp, e_ready); | |
6333 | else | |
6334 | ix86_reorder_insn (insnp, e_ready - 1); | |
6335 | } | |
e075ae69 | 6336 | |
c6991660 | 6337 | static void |
78a0d70c ZW |
6338 | ix86_sched_reorder_ppro (ready, e_ready) |
6339 | rtx *ready; | |
6340 | rtx *e_ready; | |
6341 | { | |
6342 | rtx decode[3]; | |
6343 | enum attr_ppro_uops cur_uops; | |
6344 | int issued_this_cycle; | |
6345 | rtx *insnp; | |
6346 | int i; | |
e075ae69 | 6347 | |
78a0d70c ZW |
6348 | /* At this point .ppro.decode contains the state of the three |
6349 | decoders from last "cycle". That is, those insns that were | |
6350 | actually independent. But here we're scheduling for the | |
6351 | decoder, and we may find things that are decodable in the | |
6352 | same cycle. */ | |
e075ae69 | 6353 | |
78a0d70c ZW |
6354 | memcpy (decode, ix86_sched_data.ppro.decode, sizeof(decode)); |
6355 | issued_this_cycle = 0; | |
e075ae69 | 6356 | |
78a0d70c ZW |
6357 | insnp = e_ready; |
6358 | cur_uops = ix86_safe_ppro_uops (*insnp); | |
0a726ef1 | 6359 | |
78a0d70c ZW |
6360 | /* If the decoders are empty, and we've a complex insn at the |
6361 | head of the priority queue, let it issue without complaint. */ | |
6362 | if (decode[0] == NULL) | |
6363 | { | |
6364 | if (cur_uops == PPRO_UOPS_MANY) | |
6365 | { | |
6366 | decode[0] = *insnp; | |
6367 | goto ppro_done; | |
6368 | } | |
6369 | ||
6370 | /* Otherwise, search for a 2-4 uop unsn to issue. */ | |
6371 | while (cur_uops != PPRO_UOPS_FEW) | |
6372 | { | |
6373 | if (insnp == ready) | |
6374 | break; | |
6375 | cur_uops = ix86_safe_ppro_uops (*--insnp); | |
6376 | } | |
6377 | ||
6378 | /* If so, move it to the head of the line. */ | |
6379 | if (cur_uops == PPRO_UOPS_FEW) | |
6380 | ix86_reorder_insn (insnp, e_ready); | |
0a726ef1 | 6381 | |
78a0d70c ZW |
6382 | /* Issue the head of the queue. */ |
6383 | issued_this_cycle = 1; | |
6384 | decode[0] = *e_ready--; | |
6385 | } | |
fb693d44 | 6386 | |
78a0d70c ZW |
6387 | /* Look for simple insns to fill in the other two slots. */ |
6388 | for (i = 1; i < 3; ++i) | |
6389 | if (decode[i] == NULL) | |
6390 | { | |
6391 | if (ready >= e_ready) | |
6392 | goto ppro_done; | |
fb693d44 | 6393 | |
e075ae69 RH |
6394 | insnp = e_ready; |
6395 | cur_uops = ix86_safe_ppro_uops (*insnp); | |
78a0d70c ZW |
6396 | while (cur_uops != PPRO_UOPS_ONE) |
6397 | { | |
6398 | if (insnp == ready) | |
6399 | break; | |
6400 | cur_uops = ix86_safe_ppro_uops (*--insnp); | |
6401 | } | |
fb693d44 | 6402 | |
78a0d70c ZW |
6403 | /* Found one. Move it to the head of the queue and issue it. */ |
6404 | if (cur_uops == PPRO_UOPS_ONE) | |
e075ae69 | 6405 | { |
78a0d70c ZW |
6406 | ix86_reorder_insn (insnp, e_ready); |
6407 | decode[i] = *e_ready--; | |
6408 | issued_this_cycle++; | |
6409 | continue; | |
6410 | } | |
fb693d44 | 6411 | |
78a0d70c ZW |
6412 | /* ??? Didn't find one. Ideally, here we would do a lazy split |
6413 | of 2-uop insns, issue one and queue the other. */ | |
6414 | } | |
fb693d44 | 6415 | |
78a0d70c ZW |
6416 | ppro_done: |
6417 | if (issued_this_cycle == 0) | |
6418 | issued_this_cycle = 1; | |
6419 | ix86_sched_data.ppro.issued_this_cycle = issued_this_cycle; | |
6420 | } | |
fb693d44 | 6421 | |
78a0d70c ZW |
6422 | |
6423 | /* We are about to being issuing insns for this clock cycle. | |
6424 | Override the default sort algorithm to better slot instructions. */ | |
6425 | int | |
6426 | ix86_sched_reorder (dump, sched_verbose, ready, n_ready, clock_var) | |
6427 | FILE *dump ATTRIBUTE_UNUSED; | |
6428 | int sched_verbose ATTRIBUTE_UNUSED; | |
6429 | rtx *ready; | |
6430 | int n_ready; | |
6431 | int clock_var ATTRIBUTE_UNUSED; | |
6432 | { | |
6433 | rtx *e_ready = ready + n_ready - 1; | |
fb693d44 | 6434 | |
78a0d70c ZW |
6435 | if (n_ready < 2) |
6436 | goto out; | |
e075ae69 | 6437 | |
78a0d70c ZW |
6438 | switch (ix86_cpu) |
6439 | { | |
6440 | default: | |
6441 | break; | |
e075ae69 | 6442 | |
78a0d70c ZW |
6443 | case PROCESSOR_PENTIUM: |
6444 | ix86_sched_reorder_pentium (ready, e_ready); | |
6445 | break; | |
e075ae69 | 6446 | |
78a0d70c ZW |
6447 | case PROCESSOR_PENTIUMPRO: |
6448 | ix86_sched_reorder_ppro (ready, e_ready); | |
e075ae69 | 6449 | break; |
fb693d44 RH |
6450 | } |
6451 | ||
e075ae69 RH |
6452 | out: |
6453 | return ix86_issue_rate (); | |
6454 | } | |
fb693d44 | 6455 | |
e075ae69 RH |
6456 | /* We are about to issue INSN. Return the number of insns left on the |
6457 | ready queue that can be issued this cycle. */ | |
b222082e | 6458 | |
e075ae69 RH |
6459 | int |
6460 | ix86_variable_issue (dump, sched_verbose, insn, can_issue_more) | |
6461 | FILE *dump; | |
6462 | int sched_verbose; | |
6463 | rtx insn; | |
6464 | int can_issue_more; | |
6465 | { | |
6466 | int i; | |
6467 | switch (ix86_cpu) | |
fb693d44 | 6468 | { |
e075ae69 RH |
6469 | default: |
6470 | return can_issue_more - 1; | |
fb693d44 | 6471 | |
e075ae69 RH |
6472 | case PROCESSOR_PENTIUMPRO: |
6473 | { | |
6474 | enum attr_ppro_uops uops = ix86_safe_ppro_uops (insn); | |
fb693d44 | 6475 | |
e075ae69 RH |
6476 | if (uops == PPRO_UOPS_MANY) |
6477 | { | |
6478 | if (sched_verbose) | |
6479 | ix86_dump_ppro_packet (dump); | |
6480 | ix86_sched_data.ppro.decode[0] = insn; | |
6481 | ix86_sched_data.ppro.decode[1] = NULL; | |
6482 | ix86_sched_data.ppro.decode[2] = NULL; | |
6483 | if (sched_verbose) | |
6484 | ix86_dump_ppro_packet (dump); | |
6485 | ix86_sched_data.ppro.decode[0] = NULL; | |
6486 | } | |
6487 | else if (uops == PPRO_UOPS_FEW) | |
6488 | { | |
6489 | if (sched_verbose) | |
6490 | ix86_dump_ppro_packet (dump); | |
6491 | ix86_sched_data.ppro.decode[0] = insn; | |
6492 | ix86_sched_data.ppro.decode[1] = NULL; | |
6493 | ix86_sched_data.ppro.decode[2] = NULL; | |
6494 | } | |
6495 | else | |
6496 | { | |
6497 | for (i = 0; i < 3; ++i) | |
6498 | if (ix86_sched_data.ppro.decode[i] == NULL) | |
6499 | { | |
6500 | ix86_sched_data.ppro.decode[i] = insn; | |
6501 | break; | |
6502 | } | |
6503 | if (i == 3) | |
6504 | abort (); | |
6505 | if (i == 2) | |
6506 | { | |
6507 | if (sched_verbose) | |
6508 | ix86_dump_ppro_packet (dump); | |
6509 | ix86_sched_data.ppro.decode[0] = NULL; | |
6510 | ix86_sched_data.ppro.decode[1] = NULL; | |
6511 | ix86_sched_data.ppro.decode[2] = NULL; | |
6512 | } | |
6513 | } | |
6514 | } | |
6515 | return --ix86_sched_data.ppro.issued_this_cycle; | |
6516 | } | |
fb693d44 | 6517 | } |