OpenCores
URL https://opencores.org/ocsvn/openrisc_me/openrisc_me/trunk

Subversion Repositories openrisc_me

[/] [openrisc/] [trunk/] [gnu-src/] [gcc-4.2.2/] [gcc/] [config/] [m32r/] [m32r.md] - Blame information for rev 307

Go to most recent revision | Details | Compare with Previous | View Log

Line No. Rev Author Line
1 38 julius
;; Machine description of the Renesas M32R cpu for GNU C compiler
2
;; Copyright (C) 1996, 1997, 1998, 1999, 2001, 2003, 2004, 2005, 2007
3
;; Free Software Foundation, Inc.
4
 
5
;; This file is part of GCC.
6
 
7
;; GCC is free software; you can redistribute it and/or modify it
8
;; under the terms of the GNU General Public License as published
9
;; by the Free Software Foundation; either version 3, or (at your
10
;; option) any later version.
11
 
12
;; GCC is distributed in the hope that it will be useful, but WITHOUT
13
;; ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
14
;; or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public
15
;; License for more details.
16
 
17
;; You should have received a copy of the GNU General Public License
18
;; along with GCC; see the file COPYING3.  If not see
19
;; .
20
 
21
;; See file "rtl.def" for documentation on define_insn, match_*, et. al.
22
 
23
;; UNSPEC_VOLATILE usage
24
(define_constants
25
  [(UNSPECV_BLOCKAGE            0)
26
   (UNSPECV_FLUSH_ICACHE        1)])
27
 
28
;; UNSPEC usage
29
(define_constants
30
  [(UNSPEC_LOAD_SDA_BASE        2)
31
   (UNSPEC_SET_CBIT             3)
32
   (UNSPEC_PIC_LOAD_ADDR        4)
33
   (UNSPEC_GET_PC               5)
34
   (UNSPEC_GOTOFF               6)
35
   ])
36
 
37
;; Insn type.  Used to default other attribute values.
38
(define_attr "type"
39
  "int2,int4,load2,load4,load8,store2,store4,store8,shift2,shift4,mul2,div4,uncond_branch,branch,call,multi,misc"
40
  (const_string "misc"))
41
 
42
;; Length in bytes.
43
(define_attr "length" ""
44
  (cond [(eq_attr "type" "int2,load2,store2,shift2,mul2")
45
         (const_int 2)
46
 
47
         (eq_attr "type" "int4,load4,store4,shift4,div4")
48
         (const_int 4)
49
 
50
         (eq_attr "type" "multi")
51
         (const_int 8)
52
 
53
         (eq_attr "type" "uncond_branch,branch,call")
54
         (const_int 4)]
55
 
56
         (const_int 4)))
57
 
58
;; The length here is the length of a single asm.  Unfortunately it might be
59
;; 2 or 4 so we must allow for 4.  That's ok though.
60
(define_asm_attributes
61
  [(set_attr "length" "4")
62
   (set_attr "type" "multi")])
63
 
64
;; Whether an instruction is short (16-bit) or long (32-bit).
65
(define_attr "insn_size" "short,long"
66
  (if_then_else (eq_attr "type" "int2,load2,store2,shift2,mul2")
67
                (const_string "short")
68
                (const_string "long")))
69
 
70
;; The target CPU we're compiling for.
71
(define_attr "cpu" "m32r,m32r2,m32rx"
72
  (cond [(ne (symbol_ref "TARGET_M32RX") (const_int 0))
73
             (const_string "m32rx")
74
         (ne (symbol_ref "TARGET_M32R2") (const_int 0))
75
             (const_string "m32r2")]
76
    (const_string "m32r")))
77
 
78
;; Defines the pipeline where an instruction can be executed on.
79
;; For the M32R, a short instruction can execute one of the two pipes.
80
;; For the M32Rx, the restrictions are modelled in the second
81
;;  condition of this attribute definition.
82
(define_attr "m32r_pipeline" "either,s,o,long"
83
  (cond [(and (eq_attr "cpu" "m32r")
84
              (eq_attr "insn_size" "short"))
85
             (const_string "either")
86
         (eq_attr "insn_size" "!short")
87
             (const_string "long")]
88
         (cond [(eq_attr "type" "int2")
89
                   (const_string "either")
90
                (eq_attr "type" "load2,store2,shift2,uncond_branch,branch,call")
91
                   (const_string "o")
92
                (eq_attr "type" "mul2")
93
                   (const_string "s")]
94
         (const_string "long"))))
95
 
96
;; ::::::::::::::::::::
97
;; ::
98
;; :: Pipeline description
99
;; ::
100
;; ::::::::::::::::::::
101
 
102
;; This model is based on Chapter 2, Appendix 3 and Appendix 4 of the
103
;; "M32R-FPU Software Manual", Revision 1.01, plus additional information
104
;; obtained by our best friend and mine, Google.
105
;;
106
;; The pipeline is modelled as a fetch unit, and a core with a memory unit,
107
;; two execution units, where "fetch" models IF and D, "memory" for MEM1
108
;; and MEM2, and "EXEC" for E, E1, E2, EM, and EA.  Writeback and
109
;; bypasses are not modelled.
110
(define_automaton "m32r")
111
 
112
;; We pretend there are two short (16 bits) instruction fetchers.  The
113
;; "s" short fetcher cannot be reserved until the "o" short fetcher is
114
;; reserved.  Some instructions reserve both the left and right fetchers.
115
;; These fetch units are a hack to get GCC to better pack the instructions
116
;; for the M32Rx processor, which has two execution pipes.
117
;;
118
;; In reality there is only one decoder, which can decode either two 16 bits
119
;; instructions, or a single 32 bits instruction.
120
;;
121
;; Note, "fetch" models both the IF and the D pipeline stages.
122
;;
123
;; The m32rx core has two execution pipes.  We name them o_E and s_E.
124
;; In addition, there's a memory unit.
125
 
126
(define_cpu_unit "o_IF,s_IF,o_E,s_E,memory" "m32r")
127
 
128
;; Prevent the s pipe from being reserved before the o pipe.
129
(absence_set "s_IF" "o_IF")
130
(absence_set "s_E"  "o_E")
131
 
132
;; On the M32Rx, long instructions execute on both pipes, so reserve
133
;; both fetch slots and both pipes.
134
(define_reservation "long_IF" "o_IF+s_IF")
135
(define_reservation "long_E" "o_E+s_E")
136
 
137
;; ::::::::::::::::::::
138
 
139
;; Simple instructions do 4 stages: IF D E WB.  WB is not modelled.
140
;; Hence, ready latency is 1.
141
(define_insn_reservation "short_left" 1
142
  (and (eq_attr "m32r_pipeline" "o")
143
       (and (eq_attr "insn_size" "short")
144
            (eq_attr "type" "!load2")))
145
  "o_IF,o_E")
146
 
147
(define_insn_reservation "short_right" 1
148
  (and (eq_attr "m32r_pipeline" "s")
149
       (and (eq_attr "insn_size" "short")
150
            (eq_attr "type" "!load2")))
151
  "s_IF,s_E")
152
 
153
(define_insn_reservation "short_either" 1
154
  (and (eq_attr "m32r_pipeline" "either")
155
       (and (eq_attr "insn_size" "short")
156
            (eq_attr "type" "!load2")))
157
  "o_IF|s_IF,o_E|s_E")
158
 
159
(define_insn_reservation "long_m32r" 1
160
  (and (eq_attr "cpu" "m32r")
161
       (and (eq_attr "insn_size" "long")
162
            (eq_attr "type" "!load4,load8")))
163
  "long_IF,long_E")
164
 
165
(define_insn_reservation "long_m32rx" 2
166
  (and (eq_attr "m32r_pipeline" "long")
167
       (and (eq_attr "insn_size" "long")
168
            (eq_attr "type" "!load4,load8")))
169
  "long_IF,long_E")
170
 
171
;; Load/store instructions do 6 stages: IF D E MEM1 MEM2 WB.
172
;; MEM1 may require more than one cycle depending on locality.  We
173
;; optimistically assume all memory is nearby, i.e. MEM1 takes only
174
;; one cycle.  Hence, ready latency is 3.
175
 
176
;; The M32Rx can do short load/store only on the left pipe.
177
(define_insn_reservation "short_load_left" 3
178
  (and (eq_attr "m32r_pipeline" "o")
179
       (and (eq_attr "insn_size" "short")
180
            (eq_attr "type" "load2")))
181
  "o_IF,o_E,memory*2")
182
 
183
(define_insn_reservation "short_load" 3
184
  (and (eq_attr "m32r_pipeline" "either")
185
       (and (eq_attr "insn_size" "short")
186
            (eq_attr "type" "load2")))
187
  "s_IF|o_IF,s_E|o_E,memory*2")
188
 
189
(define_insn_reservation "long_load" 3
190
  (and (eq_attr "cpu" "m32r")
191
       (and (eq_attr "insn_size" "long")
192
            (eq_attr "type" "load4,load8")))
193
  "long_IF,long_E,memory*2")
194
 
195
(define_insn_reservation "long_load_m32rx" 3
196
  (and (eq_attr "m32r_pipeline" "long")
197
       (eq_attr "type" "load4,load8"))
198
  "long_IF,long_E,memory*2")
199
 
200
 
201
(include "predicates.md")
202
 
203
;; Expand prologue as RTL
204
(define_expand "prologue"
205
  [(const_int 1)]
206
  ""
207
  "
208
{
209
  m32r_expand_prologue ();
210
  DONE;
211
}")
212
 
213
 
214
;; Move instructions.
215
;;
216
;; For QI and HI moves, the register must contain the full properly
217
;; sign-extended value.  nonzero_bits assumes this [otherwise
218
;; SHORT_IMMEDIATES_SIGN_EXTEND must be used, but the comment for it
219
;; says it's a kludge and the .md files should be fixed instead].
220
 
221
(define_expand "movqi"
222
  [(set (match_operand:QI 0 "general_operand" "")
223
        (match_operand:QI 1 "general_operand" ""))]
224
  ""
225
  "
226
{
227
  /* Fixup PIC cases.  */
228
  if (flag_pic)
229
    {
230
      if (symbolic_operand (operands[1], QImode))
231
        {
232
          if (reload_in_progress || reload_completed)
233
            operands[1] = m32r_legitimize_pic_address (operands[1], operands[0]);
234
          else
235
            operands[1] = m32r_legitimize_pic_address (operands[1], NULL_RTX);
236
        }
237
    }
238
 
239
  /* Everything except mem = const or mem = mem can be done easily.
240
     Objects in the small data area are handled too.  */
241
 
242
  if (GET_CODE (operands[0]) == MEM)
243
    operands[1] = force_reg (QImode, operands[1]);
244
}")
245
 
246
(define_insn "*movqi_insn"
247
  [(set (match_operand:QI 0 "move_dest_operand" "=r,r,r,r,r,T,m")
248
        (match_operand:QI 1 "move_src_operand" "r,I,JQR,T,m,r,r"))]
249
  "register_operand (operands[0], QImode) || register_operand (operands[1], QImode)"
250
  "@
251
   mv %0,%1
252
   ldi %0,%#%1
253
   ldi %0,%#%1
254
   ldub %0,%1
255
   ldub %0,%1
256
   stb %1,%0
257
   stb %1,%0"
258
  [(set_attr "type" "int2,int2,int4,load2,load4,store2,store4")
259
   (set_attr "length" "2,2,4,2,4,2,4")])
260
 
261
(define_expand "movhi"
262
  [(set (match_operand:HI 0 "general_operand" "")
263
        (match_operand:HI 1 "general_operand" ""))]
264
  ""
265
  "
266
{
267
  /* Fixup PIC cases.  */
268
  if (flag_pic)
269
    {
270
      if (symbolic_operand (operands[1], HImode))
271
        {
272
          if (reload_in_progress || reload_completed)
273
            operands[1] = m32r_legitimize_pic_address (operands[1], operands[0]);
274
          else
275
            operands[1] = m32r_legitimize_pic_address (operands[1], NULL_RTX);
276
        }
277
    }
278
 
279
  /* Everything except mem = const or mem = mem can be done easily.  */
280
 
281
  if (GET_CODE (operands[0]) == MEM)
282
    operands[1] = force_reg (HImode, operands[1]);
283
}")
284
 
285
(define_insn "*movhi_insn"
286
  [(set (match_operand:HI 0 "move_dest_operand" "=r,r,r,r,r,r,T,m")
287
        (match_operand:HI 1 "move_src_operand" "r,I,JQR,K,T,m,r,r"))]
288
  "register_operand (operands[0], HImode) || register_operand (operands[1], HImode)"
289
  "@
290
   mv %0,%1
291
   ldi %0,%#%1
292
   ldi %0,%#%1
293
   ld24 %0,%#%1
294
   lduh %0,%1
295
   lduh %0,%1
296
   sth %1,%0
297
   sth %1,%0"
298
  [(set_attr "type" "int2,int2,int4,int4,load2,load4,store2,store4")
299
   (set_attr "length" "2,2,4,4,2,4,2,4")])
300
 
301
(define_expand "movsi_push"
302
  [(set (mem:SI (pre_dec:SI (match_operand:SI 0 "register_operand" "")))
303
        (match_operand:SI 1 "register_operand" ""))]
304
  ""
305
  "")
306
 
307
(define_expand "movsi_pop"
308
  [(set (match_operand:SI 0 "register_operand" "")
309
        (mem:SI (post_inc:SI (match_operand:SI 1 "register_operand" ""))))]
310
  ""
311
  "")
312
 
313
(define_expand "movsi"
314
  [(set (match_operand:SI 0 "general_operand" "")
315
        (match_operand:SI 1 "general_operand" ""))]
316
  ""
317
  "
318
{
319
  /* Fixup PIC cases.  */
320
  if (flag_pic)
321
    {
322
      if (symbolic_operand (operands[1], SImode))
323
        {
324
          if (reload_in_progress || reload_completed)
325
            operands[1] = m32r_legitimize_pic_address (operands[1], operands[0]);
326
          else
327
            operands[1] = m32r_legitimize_pic_address (operands[1], NULL_RTX);
328
        }
329
    }
330
 
331
  /* Everything except mem = const or mem = mem can be done easily.  */
332
 
333
  if (GET_CODE (operands[0]) == MEM)
334
    operands[1] = force_reg (SImode, operands[1]);
335
 
336
  /* Small Data Area reference?  */
337
  if (small_data_operand (operands[1], SImode))
338
    {
339
      emit_insn (gen_movsi_sda (operands[0], operands[1]));
340
      DONE;
341
    }
342
 
343
  /* If medium or large code model, symbols have to be loaded with
344
     seth/add3.  */
345
  if (addr32_operand (operands[1], SImode))
346
    {
347
      emit_insn (gen_movsi_addr32 (operands[0], operands[1]));
348
      DONE;
349
    }
350
}")
351
 
352
;; ??? Do we need a const_double constraint here for large unsigned values?
353
(define_insn "*movsi_insn"
354
  [(set (match_operand:SI 0 "move_dest_operand" "=r,r,r,r,r,r,r,r,r,T,S,m")
355
        (match_operand:SI 1 "move_src_operand" "r,I,J,MQ,L,n,T,U,m,r,r,r"))]
356
  "register_operand (operands[0], SImode) || register_operand (operands[1], SImode)"
357
  "*
358
{
359
  if (GET_CODE (operands[0]) == REG || GET_CODE (operands[1]) == SUBREG)
360
    {
361
      switch (GET_CODE (operands[1]))
362
        {
363
          HOST_WIDE_INT value;
364
 
365
          default:
366
            break;
367
 
368
          case REG:
369
          case SUBREG:
370
            return \"mv %0,%1\";
371
 
372
          case MEM:
373
            if (GET_CODE (XEXP (operands[1], 0)) == POST_INC
374
                && XEXP (XEXP (operands[1], 0), 0) == stack_pointer_rtx)
375
              return \"pop %0\";
376
 
377
            return \"ld %0,%1\";
378
 
379
          case CONST_INT:
380
            value = INTVAL (operands[1]);
381
            if (INT16_P (value))
382
              return \"ldi %0,%#%1\\t; %X1\";
383
 
384
            if (UINT24_P (value))
385
              return \"ld24 %0,%#%1\\t; %X1\";
386
 
387
            if (UPPER16_P (value))
388
              return \"seth %0,%#%T1\\t; %X1\";
389
 
390
            return \"#\";
391
 
392
          case CONST:
393
          case SYMBOL_REF:
394
          case LABEL_REF:
395
            if (TARGET_ADDR24)
396
              return \"ld24 %0,%#%1\";
397
 
398
            return \"#\";
399
        }
400
    }
401
 
402
  else if (GET_CODE (operands[0]) == MEM
403
           && (GET_CODE (operands[1]) == REG || GET_CODE (operands[1]) == SUBREG))
404
    {
405
      if (GET_CODE (XEXP (operands[0], 0)) == PRE_DEC
406
          && XEXP (XEXP (operands[0], 0), 0) == stack_pointer_rtx)
407
        return \"push %1\";
408
 
409
      return \"st %1,%0\";
410
    }
411
 
412
  gcc_unreachable ();
413
}"
414
  [(set_attr "type" "int2,int2,int4,int4,int4,multi,load2,load2,load4,store2,store2,store4")
415
   (set_attr "length" "2,2,4,4,4,8,2,2,4,2,2,4")])
416
 
417
; Try to use a four byte / two byte pair for constants not loadable with
418
; ldi, ld24, seth.
419
 
420
(define_split
421
 [(set (match_operand:SI 0 "register_operand" "")
422
       (match_operand:SI 1 "two_insn_const_operand" ""))]
423
  ""
424
  [(set (match_dup 0) (match_dup 2))
425
   (set (match_dup 0) (ior:SI (match_dup 0) (match_dup 3)))]
426
  "
427
{
428
  unsigned HOST_WIDE_INT val = INTVAL (operands[1]);
429
  unsigned HOST_WIDE_INT tmp;
430
  int shift;
431
 
432
  /* In all cases we will emit two instructions.  However we try to
433
     use 2 byte instructions wherever possible.  We can assume the
434
     constant isn't loadable with any of ldi, ld24, or seth.  */
435
 
436
  /* See if we can load a 24 bit unsigned value and invert it.  */
437
  if (UINT24_P (~ val))
438
    {
439
      emit_insn (gen_movsi (operands[0], GEN_INT (~ val)));
440
      emit_insn (gen_one_cmplsi2 (operands[0], operands[0]));
441
      DONE;
442
    }
443
 
444
  /* See if we can load a 24 bit unsigned value and shift it into place.
445
     0x01fffffe is just beyond ld24's range.  */
446
  for (shift = 1, tmp = 0x01fffffe;
447
       shift < 8;
448
       ++shift, tmp <<= 1)
449
    {
450
      if ((val & ~tmp) == 0)
451
        {
452
          emit_insn (gen_movsi (operands[0], GEN_INT (val >> shift)));
453
          emit_insn (gen_ashlsi3 (operands[0], operands[0], GEN_INT (shift)));
454
          DONE;
455
        }
456
    }
457
 
458
  /* Can't use any two byte insn, fall back to seth/or3.  Use ~0xffff instead
459
     of 0xffff0000, since the later fails on a 64-bit host.  */
460
  operands[2] = GEN_INT ((val) & ~0xffff);
461
  operands[3] = GEN_INT ((val) & 0xffff);
462
}")
463
 
464
(define_split
465
  [(set (match_operand:SI 0 "register_operand" "")
466
        (match_operand:SI 1 "seth_add3_operand" ""))]
467
  "TARGET_ADDR32"
468
  [(set (match_dup 0)
469
        (high:SI (match_dup 1)))
470
   (set (match_dup 0)
471
        (lo_sum:SI (match_dup 0)
472
                   (match_dup 1)))]
473
  "")
474
 
475
;; Small data area support.
476
;; The address of _SDA_BASE_ is loaded into a register and all objects in
477
;; the small data area are indexed off that.  This is done for each reference
478
;; but cse will clean things up for us.  We let the compiler choose the
479
;; register to use so we needn't allocate (and maybe even fix) a special
480
;; register to use.  Since the load and store insns have a 16 bit offset the
481
;; total size of the data area can be 64K.  However, if the data area lives
482
;; above 16M (24 bits), _SDA_BASE_ will have to be loaded with seth/add3 which
483
;; would then yield 3 instructions to reference an object [though there would
484
;; be no net loss if two or more objects were referenced].  The 3 insns can be
485
;; reduced back to 2 if the size of the small data area were reduced to 32K
486
;; [then seth + ld/st would work for any object in the area].  Doing this
487
;; would require special handling of _SDA_BASE_ (its value would be
488
;; (.sdata + 32K) & 0xffff0000) and reloc computations would be different
489
;; [I think].  What to do about this is deferred until later and for now we
490
;; require .sdata to be in the first 16M.
491
 
492
(define_expand "movsi_sda"
493
  [(set (match_dup 2)
494
        (unspec:SI [(const_int 0)] UNSPEC_LOAD_SDA_BASE))
495
   (set (match_operand:SI 0 "register_operand" "")
496
        (lo_sum:SI (match_dup 2)
497
                   (match_operand:SI 1 "small_data_operand" "")))]
498
  ""
499
  "
500
{
501
  if (reload_in_progress || reload_completed)
502
    operands[2] = operands[0];
503
  else
504
    operands[2] = gen_reg_rtx (SImode);
505
}")
506
 
507
(define_insn "*load_sda_base_32"
508
  [(set (match_operand:SI 0 "register_operand" "=r")
509
        (unspec:SI [(const_int 0)] UNSPEC_LOAD_SDA_BASE))]
510
  "TARGET_ADDR32"
511
  "seth %0,%#shigh(_SDA_BASE_)\;add3 %0,%0,%#low(_SDA_BASE_)"
512
  [(set_attr "type" "multi")
513
   (set_attr "length" "8")])
514
 
515
(define_insn "*load_sda_base"
516
  [(set (match_operand:SI 0 "register_operand" "=r")
517
        (unspec:SI [(const_int 0)] UNSPEC_LOAD_SDA_BASE))]
518
  ""
519
  "ld24 %0,#_SDA_BASE_"
520
  [(set_attr "type" "int4")
521
   (set_attr "length" "4")])
522
 
523
;; 32 bit address support.
524
 
525
(define_expand "movsi_addr32"
526
  [(set (match_dup 2)
527
        ; addr32_operand isn't used because it's too restrictive,
528
        ; seth_add3_operand is more general and thus safer.
529
        (high:SI (match_operand:SI 1 "seth_add3_operand" "")))
530
   (set (match_operand:SI 0 "register_operand" "")
531
        (lo_sum:SI (match_dup 2) (match_dup 1)))]
532
  ""
533
  "
534
{
535
  if (reload_in_progress || reload_completed)
536
    operands[2] = operands[0];
537
  else
538
    operands[2] = gen_reg_rtx (SImode);
539
}")
540
 
541
(define_insn "set_hi_si"
542
  [(set (match_operand:SI 0 "register_operand" "=r")
543
        (high:SI (match_operand 1 "symbolic_operand" "")))]
544
  ""
545
  "seth %0,%#shigh(%1)"
546
  [(set_attr "type" "int4")
547
   (set_attr "length" "4")])
548
 
549
(define_insn "lo_sum_si"
550
  [(set (match_operand:SI 0 "register_operand" "=r")
551
        (lo_sum:SI (match_operand:SI 1 "register_operand" "r")
552
                   (match_operand:SI 2 "immediate_operand" "in")))]
553
  ""
554
  "add3 %0,%1,%#%B2"
555
  [(set_attr "type" "int4")
556
   (set_attr "length" "4")])
557
 
558
(define_expand "movdi"
559
  [(set (match_operand:DI 0 "general_operand" "")
560
        (match_operand:DI 1 "general_operand" ""))]
561
  ""
562
  "
563
{
564
  /* Fixup PIC cases.  */
565
  if (flag_pic)
566
    {
567
      if (symbolic_operand (operands[1], DImode))
568
        {
569
          if (reload_in_progress || reload_completed)
570
            operands[1] = m32r_legitimize_pic_address (operands[1], operands[0]);
571
          else
572
            operands[1] = m32r_legitimize_pic_address (operands[1], NULL_RTX);
573
        }
574
    }
575
 
576
  /* Everything except mem = const or mem = mem can be done easily.  */
577
 
578
  if (GET_CODE (operands[0]) == MEM)
579
    operands[1] = force_reg (DImode, operands[1]);
580
}")
581
 
582
(define_insn "*movdi_insn"
583
  [(set (match_operand:DI 0 "move_dest_operand" "=r,r,r,r,m")
584
        (match_operand:DI 1 "move_double_src_operand" "r,nG,F,m,r"))]
585
  "register_operand (operands[0], DImode) || register_operand (operands[1], DImode)"
586
  "#"
587
  [(set_attr "type" "multi,multi,multi,load8,store8")
588
   (set_attr "length" "4,4,16,6,6")])
589
 
590
(define_split
591
  [(set (match_operand:DI 0 "move_dest_operand" "")
592
        (match_operand:DI 1 "move_double_src_operand" ""))]
593
  "reload_completed"
594
  [(match_dup 2)]
595
  "operands[2] = gen_split_move_double (operands);")
596
 
597
;; Floating point move insns.
598
 
599
(define_expand "movsf"
600
  [(set (match_operand:SF 0 "general_operand" "")
601
        (match_operand:SF 1 "general_operand" ""))]
602
  ""
603
  "
604
{
605
  /* Fixup PIC cases.  */
606
  if (flag_pic)
607
    {
608
      if (symbolic_operand (operands[1], SFmode))
609
        {
610
          if (reload_in_progress || reload_completed)
611
            operands[1] = m32r_legitimize_pic_address (operands[1], operands[0]);
612
          else
613
            operands[1] = m32r_legitimize_pic_address (operands[1], NULL_RTX);
614
        }
615
    }
616
 
617
  /* Everything except mem = const or mem = mem can be done easily.  */
618
 
619
  if (GET_CODE (operands[0]) == MEM)
620
    operands[1] = force_reg (SFmode, operands[1]);
621
}")
622
 
623
(define_insn "*movsf_insn"
624
  [(set (match_operand:SF 0 "move_dest_operand" "=r,r,r,r,r,T,S,m")
625
        (match_operand:SF 1 "move_src_operand" "r,F,U,S,m,r,r,r"))]
626
  "register_operand (operands[0], SFmode) || register_operand (operands[1], SFmode)"
627
  "@
628
   mv %0,%1
629
   #
630
   ld %0,%1
631
   ld %0,%1
632
   ld %0,%1
633
   st %1,%0
634
   st %1,%0
635
   st %1,%0"
636
  ;; ??? Length of alternative 1 is either 2, 4 or 8.
637
  [(set_attr "type" "int2,multi,load2,load2,load4,store2,store2,store4")
638
   (set_attr "length" "2,8,2,2,4,2,2,4")])
639
 
640
(define_split
641
  [(set (match_operand:SF 0 "register_operand" "")
642
        (match_operand:SF 1 "const_double_operand" ""))]
643
  "reload_completed"
644
  [(set (match_dup 2) (match_dup 3))]
645
  "
646
{
647
  operands[2] = operand_subword (operands[0], 0, 0, SFmode);
648
  operands[3] = operand_subword (operands[1], 0, 0, SFmode);
649
}")
650
 
651
(define_expand "movdf"
652
  [(set (match_operand:DF 0 "general_operand" "")
653
        (match_operand:DF 1 "general_operand" ""))]
654
  ""
655
  "
656
{
657
  /* Fixup PIC cases.  */
658
  if (flag_pic)
659
    {
660
      if (symbolic_operand (operands[1], DFmode))
661
        {
662
          if (reload_in_progress || reload_completed)
663
            operands[1] = m32r_legitimize_pic_address (operands[1], operands[0]);
664
          else
665
            operands[1] = m32r_legitimize_pic_address (operands[1], NULL_RTX);
666
        }
667
    }
668
 
669
  /* Everything except mem = const or mem = mem can be done easily.  */
670
 
671
  if (GET_CODE (operands[0]) == MEM)
672
    operands[1] = force_reg (DFmode, operands[1]);
673
}")
674
 
675
(define_insn "*movdf_insn"
676
  [(set (match_operand:DF 0 "move_dest_operand" "=r,r,r,m")
677
        (match_operand:DF 1 "move_double_src_operand" "r,F,m,r"))]
678
  "register_operand (operands[0], DFmode) || register_operand (operands[1], DFmode)"
679
  "#"
680
  [(set_attr "type" "multi,multi,load8,store8")
681
   (set_attr "length" "4,16,6,6")])
682
 
683
(define_split
684
  [(set (match_operand:DF 0 "move_dest_operand" "")
685
        (match_operand:DF 1 "move_double_src_operand" ""))]
686
  "reload_completed"
687
  [(match_dup 2)]
688
  "operands[2] = gen_split_move_double (operands);")
689
 
690
;; Zero extension instructions.
691
 
692
(define_insn "zero_extendqihi2"
693
  [(set (match_operand:HI 0 "register_operand" "=r,r,r")
694
        (zero_extend:HI (match_operand:QI 1 "extend_operand" "r,T,m")))]
695
  ""
696
  "@
697
   and3 %0,%1,%#255
698
   ldub %0,%1
699
   ldub %0,%1"
700
  [(set_attr "type" "int4,load2,load4")
701
   (set_attr "length" "4,2,4")])
702
 
703
(define_insn "zero_extendqisi2"
704
  [(set (match_operand:SI 0 "register_operand" "=r,r,r")
705
        (zero_extend:SI (match_operand:QI 1 "extend_operand" "r,T,m")))]
706
  ""
707
  "@
708
   and3 %0,%1,%#255
709
   ldub %0,%1
710
   ldub %0,%1"
711
  [(set_attr "type" "int4,load2,load4")
712
   (set_attr "length" "4,2,4")])
713
 
714
(define_insn "zero_extendhisi2"
715
  [(set (match_operand:SI 0 "register_operand" "=r,r,r")
716
        (zero_extend:SI (match_operand:HI 1 "extend_operand" "r,T,m")))]
717
  ""
718
  "@
719
   and3 %0,%1,%#65535
720
   lduh %0,%1
721
   lduh %0,%1"
722
  [(set_attr "type" "int4,load2,load4")
723
   (set_attr "length" "4,2,4")])
724
 
725
;; Signed conversions from a smaller integer to a larger integer
726
(define_insn "extendqihi2"
727
  [(set (match_operand:HI 0 "register_operand" "=r,r,r")
728
        (sign_extend:HI (match_operand:QI 1 "extend_operand" "0,T,m")))]
729
  ""
730
  "@
731
    #
732
    ldb %0,%1
733
    ldb %0,%1"
734
  [(set_attr "type" "multi,load2,load4")
735
   (set_attr "length" "2,2,4")])
736
 
737
(define_split
738
  [(set (match_operand:HI 0 "register_operand" "")
739
        (sign_extend:HI (match_operand:QI 1 "register_operand" "")))]
740
  "reload_completed"
741
  [(match_dup 2)
742
   (match_dup 3)]
743
  "
744
{
745
  rtx op0   = gen_lowpart (SImode, operands[0]);
746
  rtx shift = GEN_INT (24);
747
 
748
  operands[2] = gen_ashlsi3 (op0, op0, shift);
749
  operands[3] = gen_ashrsi3 (op0, op0, shift);
750
}")
751
 
752
(define_insn "extendqisi2"
753
  [(set (match_operand:SI 0 "register_operand" "=r,r,r")
754
        (sign_extend:SI (match_operand:QI 1 "extend_operand" "0,T,m")))]
755
  ""
756
  "@
757
    #
758
    ldb %0,%1
759
    ldb %0,%1"
760
  [(set_attr "type" "multi,load2,load4")
761
   (set_attr "length" "4,2,4")])
762
 
763
(define_split
764
  [(set (match_operand:SI 0 "register_operand" "")
765
        (sign_extend:SI (match_operand:QI 1 "register_operand" "")))]
766
  "reload_completed"
767
  [(match_dup 2)
768
   (match_dup 3)]
769
  "
770
{
771
  rtx shift = GEN_INT (24);
772
 
773
  operands[2] = gen_ashlsi3 (operands[0], operands[0], shift);
774
  operands[3] = gen_ashrsi3 (operands[0], operands[0], shift);
775
}")
776
 
777
(define_insn "extendhisi2"
778
  [(set (match_operand:SI 0 "register_operand" "=r,r,r")
779
        (sign_extend:SI (match_operand:HI 1 "extend_operand" "0,T,m")))]
780
  ""
781
  "@
782
    #
783
    ldh %0,%1
784
    ldh %0,%1"
785
  [(set_attr "type" "multi,load2,load4")
786
   (set_attr "length" "4,2,4")])
787
 
788
(define_split
789
  [(set (match_operand:SI 0 "register_operand" "")
790
        (sign_extend:SI (match_operand:HI 1 "register_operand" "")))]
791
  "reload_completed"
792
  [(match_dup 2)
793
   (match_dup 3)]
794
  "
795
{
796
  rtx shift = GEN_INT (16);
797
 
798
  operands[2] = gen_ashlsi3 (operands[0], operands[0], shift);
799
  operands[3] = gen_ashrsi3 (operands[0], operands[0], shift);
800
}")
801
 
802
;; Arithmetic instructions.
803
 
804
; ??? Adding an alternative to split add3 of small constants into two
805
; insns yields better instruction packing but slower code.  Adds of small
806
; values is done a lot.
807
 
808
(define_insn "addsi3"
809
  [(set (match_operand:SI 0 "register_operand" "=r,r,r")
810
        (plus:SI (match_operand:SI 1 "register_operand" "%0,0,r")
811
                 (match_operand:SI 2 "nonmemory_operand" "r,I,J")))]
812
  ""
813
  "@
814
   add %0,%2
815
   addi %0,%#%2
816
   add3 %0,%1,%#%2"
817
  [(set_attr "type" "int2,int2,int4")
818
   (set_attr "length" "2,2,4")])
819
 
820
;(define_split
821
;  [(set (match_operand:SI 0 "register_operand" "")
822
;       (plus:SI (match_operand:SI 1 "register_operand" "")
823
;                (match_operand:SI 2 "int8_operand" "")))]
824
;  "reload_completed
825
;   && REGNO (operands[0]) != REGNO (operands[1])
826
;   && INT8_P (INTVAL (operands[2]))
827
;   && INTVAL (operands[2]) != 0"
828
;  [(set (match_dup 0) (match_dup 1))
829
;   (set (match_dup 0) (plus:SI (match_dup 0) (match_dup 2)))]
830
;  "")
831
 
832
(define_insn "adddi3"
833
  [(set (match_operand:DI 0 "register_operand" "=r")
834
        (plus:DI (match_operand:DI 1 "register_operand" "%0")
835
                 (match_operand:DI 2 "register_operand" "r")))
836
   (clobber (reg:CC 17))]
837
  ""
838
  "#"
839
  [(set_attr "type" "multi")
840
   (set_attr "length" "6")])
841
 
842
;; ??? The cmp clears the condition bit.  Can we speed up somehow?
843
(define_split
844
  [(set (match_operand:DI 0 "register_operand" "")
845
        (plus:DI (match_operand:DI 1 "register_operand" "")
846
                 (match_operand:DI 2 "register_operand" "")))
847
   (clobber (reg:CC 17))]
848
  "reload_completed"
849
  [(parallel [(set (reg:CC 17)
850
                   (const_int 0))
851
              (use (match_dup 4))])
852
   (parallel [(set (match_dup 4)
853
                   (plus:SI (match_dup 4)
854
                            (plus:SI (match_dup 5)
855
                                     (ne:SI (reg:CC 17) (const_int 0)))))
856
              (set (reg:CC 17)
857
                   (unspec:CC [(const_int 0)] UNSPEC_SET_CBIT))])
858
   (parallel [(set (match_dup 6)
859
                   (plus:SI (match_dup 6)
860
                            (plus:SI (match_dup 7)
861
                                     (ne:SI (reg:CC 17) (const_int 0)))))
862
              (set (reg:CC 17)
863
                   (unspec:CC [(const_int 0)] UNSPEC_SET_CBIT))])]
864
  "
865
{
866
  operands[4] = operand_subword (operands[0], (WORDS_BIG_ENDIAN != 0), 0, DImode);
867
  operands[5] = operand_subword (operands[2], (WORDS_BIG_ENDIAN != 0), 0, DImode);
868
  operands[6] = operand_subword (operands[0], (WORDS_BIG_ENDIAN == 0), 0, DImode);
869
  operands[7] = operand_subword (operands[2], (WORDS_BIG_ENDIAN == 0), 0, DImode);
870
}")
871
 
872
(define_insn "*clear_c"
873
  [(set (reg:CC 17)
874
        (const_int 0))
875
   (use (match_operand:SI 0 "register_operand" "r"))]
876
  ""
877
  "cmp %0,%0"
878
  [(set_attr "type" "int2")
879
   (set_attr "length" "2")])
880
 
881
(define_insn "*add_carry"
882
  [(set (match_operand:SI 0 "register_operand" "=r")
883
        (plus:SI (match_operand:SI 1 "register_operand" "%0")
884
                 (plus:SI (match_operand:SI 2 "register_operand" "r")
885
                          (ne:SI (reg:CC 17) (const_int 0)))))
886
   (set (reg:CC 17)
887
        (unspec:CC [(const_int 0)] UNSPEC_SET_CBIT))]
888
  ""
889
  "addx %0,%2"
890
  [(set_attr "type" "int2")
891
   (set_attr "length" "2")])
892
 
893
(define_insn "subsi3"
894
  [(set (match_operand:SI 0 "register_operand" "=r")
895
        (minus:SI (match_operand:SI 1 "register_operand" "0")
896
                  (match_operand:SI 2 "register_operand" "r")))]
897
  ""
898
  "sub %0,%2"
899
  [(set_attr "type" "int2")
900
   (set_attr "length" "2")])
901
 
902
(define_insn "subdi3"
903
  [(set (match_operand:DI 0 "register_operand" "=r")
904
        (minus:DI (match_operand:DI 1 "register_operand" "0")
905
                  (match_operand:DI 2 "register_operand" "r")))
906
   (clobber (reg:CC 17))]
907
  ""
908
  "#"
909
  [(set_attr "type" "multi")
910
   (set_attr "length" "6")])
911
 
912
;; ??? The cmp clears the condition bit.  Can we speed up somehow?
913
(define_split
914
  [(set (match_operand:DI 0 "register_operand" "")
915
        (minus:DI (match_operand:DI 1 "register_operand" "")
916
                  (match_operand:DI 2 "register_operand" "")))
917
   (clobber (reg:CC 17))]
918
  "reload_completed"
919
  [(parallel [(set (reg:CC 17)
920
                   (const_int 0))
921
              (use (match_dup 4))])
922
   (parallel [(set (match_dup 4)
923
                   (minus:SI (match_dup 4)
924
                             (minus:SI (match_dup 5)
925
                                       (ne:SI (reg:CC 17) (const_int 0)))))
926
              (set (reg:CC 17)
927
                   (unspec:CC [(const_int 0)] UNSPEC_SET_CBIT))])
928
   (parallel [(set (match_dup 6)
929
                   (minus:SI (match_dup 6)
930
                             (minus:SI (match_dup 7)
931
                                       (ne:SI (reg:CC 17) (const_int 0)))))
932
              (set (reg:CC 17)
933
                   (unspec:CC [(const_int 0)] UNSPEC_SET_CBIT))])]
934
  "
935
{
936
  operands[4] = operand_subword (operands[0], (WORDS_BIG_ENDIAN != 0), 0, DImode);
937
  operands[5] = operand_subword (operands[2], (WORDS_BIG_ENDIAN != 0), 0, DImode);
938
  operands[6] = operand_subword (operands[0], (WORDS_BIG_ENDIAN == 0), 0, DImode);
939
  operands[7] = operand_subword (operands[2], (WORDS_BIG_ENDIAN == 0), 0, DImode);
940
}")
941
 
942
(define_insn "*sub_carry"
943
  [(set (match_operand:SI 0 "register_operand" "=r")
944
        (minus:SI (match_operand:SI 1 "register_operand" "%0")
945
                  (minus:SI (match_operand:SI 2 "register_operand" "r")
946
                            (ne:SI (reg:CC 17) (const_int 0)))))
947
   (set (reg:CC 17)
948
        (unspec:CC [(const_int 0)] UNSPEC_SET_CBIT))]
949
  ""
950
  "subx %0,%2"
951
  [(set_attr "type" "int2")
952
   (set_attr "length" "2")])
953
 
954
; Multiply/Divide instructions.
955
 
956
(define_insn "mulhisi3"
957
  [(set (match_operand:SI 0 "register_operand" "=r")
958
        (mult:SI (sign_extend:SI (match_operand:HI 1 "register_operand" "r"))
959
                 (sign_extend:SI (match_operand:HI 2 "register_operand" "r"))))]
960
  ""
961
  "mullo %1,%2\;mvfacmi %0"
962
  [(set_attr "type" "multi")
963
   (set_attr "length" "4")])
964
 
965
(define_insn "mulsi3"
966
  [(set (match_operand:SI 0 "register_operand" "=r")
967
        (mult:SI (match_operand:SI 1 "register_operand" "%0")
968
                 (match_operand:SI 2 "register_operand" "r")))]
969
  ""
970
  "mul %0,%2"
971
  [(set_attr "type" "mul2")
972
   (set_attr "length" "2")])
973
 
974
(define_insn "divsi3"
975
  [(set (match_operand:SI 0 "register_operand" "=r")
976
        (div:SI (match_operand:SI 1 "register_operand" "0")
977
                (match_operand:SI 2 "register_operand" "r")))]
978
  ""
979
  "div %0,%2"
980
  [(set_attr "type" "div4")
981
   (set_attr "length" "4")])
982
 
983
(define_insn "udivsi3"
984
  [(set (match_operand:SI 0 "register_operand" "=r")
985
        (udiv:SI (match_operand:SI 1 "register_operand" "0")
986
                 (match_operand:SI 2 "register_operand" "r")))]
987
  ""
988
  "divu %0,%2"
989
  [(set_attr "type" "div4")
990
   (set_attr "length" "4")])
991
 
992
(define_insn "modsi3"
993
  [(set (match_operand:SI 0 "register_operand" "=r")
994
        (mod:SI (match_operand:SI 1 "register_operand" "0")
995
                (match_operand:SI 2 "register_operand" "r")))]
996
  ""
997
  "rem %0,%2"
998
  [(set_attr "type" "div4")
999
   (set_attr "length" "4")])
1000
 
1001
(define_insn "umodsi3"
1002
  [(set (match_operand:SI 0 "register_operand" "=r")
1003
        (umod:SI (match_operand:SI 1 "register_operand" "0")
1004
                 (match_operand:SI 2 "register_operand" "r")))]
1005
  ""
1006
  "remu %0,%2"
1007
  [(set_attr "type" "div4")
1008
   (set_attr "length" "4")])
1009
 
1010
;; Boolean instructions.
1011
;;
1012
;; We don't define the DImode versions as expand_binop does a good enough job.
1013
;; And if it doesn't it should be fixed.
1014
 
1015
(define_insn "andsi3"
1016
  [(set (match_operand:SI 0 "register_operand" "=r,r")
1017
        (and:SI (match_operand:SI 1 "register_operand" "%0,r")
1018
                (match_operand:SI 2 "reg_or_uint16_operand" "r,K")))]
1019
  ""
1020
  "*
1021
{
1022
  /* If we are worried about space, see if we can break this up into two
1023
     short instructions, which might eliminate a NOP being inserted.  */
1024
  if (optimize_size
1025
      && m32r_not_same_reg (operands[0], operands[1])
1026
      && GET_CODE (operands[2]) == CONST_INT
1027
      && INT8_P (INTVAL (operands[2])))
1028
    return \"#\";
1029
 
1030
  else if (GET_CODE (operands[2]) == CONST_INT)
1031
    return \"and3 %0,%1,%#%X2\";
1032
 
1033
  return \"and %0,%2\";
1034
}"
1035
  [(set_attr "type" "int2,int4")
1036
   (set_attr "length" "2,4")])
1037
 
1038
(define_split
1039
  [(set (match_operand:SI 0 "register_operand" "")
1040
        (and:SI (match_operand:SI 1 "register_operand" "")
1041
                (match_operand:SI 2 "int8_operand" "")))]
1042
  "optimize_size && m32r_not_same_reg (operands[0], operands[1])"
1043
  [(set (match_dup 0) (match_dup 2))
1044
   (set (match_dup 0) (and:SI (match_dup 0) (match_dup 1)))]
1045
  "")
1046
 
1047
(define_insn "iorsi3"
1048
  [(set (match_operand:SI 0 "register_operand" "=r,r")
1049
        (ior:SI (match_operand:SI 1 "register_operand" "%0,r")
1050
                (match_operand:SI 2 "reg_or_uint16_operand" "r,K")))]
1051
  ""
1052
  "*
1053
{
1054
  /* If we are worried about space, see if we can break this up into two
1055
     short instructions, which might eliminate a NOP being inserted.  */
1056
  if (optimize_size
1057
      && m32r_not_same_reg (operands[0], operands[1])
1058
      && GET_CODE (operands[2]) == CONST_INT
1059
      && INT8_P (INTVAL (operands[2])))
1060
    return \"#\";
1061
 
1062
  else if (GET_CODE (operands[2]) == CONST_INT)
1063
    return \"or3 %0,%1,%#%X2\";
1064
 
1065
  return \"or %0,%2\";
1066
}"
1067
  [(set_attr "type" "int2,int4")
1068
   (set_attr "length" "2,4")])
1069
 
1070
(define_split
1071
  [(set (match_operand:SI 0 "register_operand" "")
1072
        (ior:SI (match_operand:SI 1 "register_operand" "")
1073
                (match_operand:SI 2 "int8_operand" "")))]
1074
  "optimize_size && m32r_not_same_reg (operands[0], operands[1])"
1075
  [(set (match_dup 0) (match_dup 2))
1076
   (set (match_dup 0) (ior:SI (match_dup 0) (match_dup 1)))]
1077
  "")
1078
 
1079
(define_insn "xorsi3"
1080
  [(set (match_operand:SI 0 "register_operand" "=r,r")
1081
        (xor:SI (match_operand:SI 1 "register_operand" "%0,r")
1082
                (match_operand:SI 2 "reg_or_uint16_operand" "r,K")))]
1083
  ""
1084
  "*
1085
{
1086
  /* If we are worried about space, see if we can break this up into two
1087
     short instructions, which might eliminate a NOP being inserted.  */
1088
  if (optimize_size
1089
      && m32r_not_same_reg (operands[0], operands[1])
1090
      && GET_CODE (operands[2]) == CONST_INT
1091
      && INT8_P (INTVAL (operands[2])))
1092
    return \"#\";
1093
 
1094
  else if (GET_CODE (operands[2]) == CONST_INT)
1095
    return \"xor3 %0,%1,%#%X2\";
1096
 
1097
  return \"xor %0,%2\";
1098
}"
1099
  [(set_attr "type" "int2,int4")
1100
   (set_attr "length" "2,4")])
1101
 
1102
(define_split
1103
  [(set (match_operand:SI 0 "register_operand" "")
1104
        (xor:SI (match_operand:SI 1 "register_operand" "")
1105
                (match_operand:SI 2 "int8_operand" "")))]
1106
  "optimize_size && m32r_not_same_reg (operands[0], operands[1])"
1107
  [(set (match_dup 0) (match_dup 2))
1108
   (set (match_dup 0) (xor:SI (match_dup 0) (match_dup 1)))]
1109
  "")
1110
 
1111
(define_insn "negsi2"
1112
  [(set (match_operand:SI 0 "register_operand" "=r")
1113
        (neg:SI (match_operand:SI 1 "register_operand" "r")))]
1114
  ""
1115
  "neg %0,%1"
1116
  [(set_attr "type" "int2")
1117
   (set_attr "length" "2")])
1118
 
1119
(define_insn "one_cmplsi2"
1120
  [(set (match_operand:SI 0 "register_operand" "=r")
1121
        (not:SI (match_operand:SI 1 "register_operand" "r")))]
1122
  ""
1123
  "not %0,%1"
1124
  [(set_attr "type" "int2")
1125
   (set_attr "length" "2")])
1126
 
1127
;; Shift instructions.
1128
 
1129
(define_insn "ashlsi3"
1130
  [(set (match_operand:SI 0 "register_operand" "=r,r,r")
1131
        (ashift:SI (match_operand:SI 1 "register_operand" "0,0,r")
1132
                   (match_operand:SI 2 "reg_or_uint16_operand" "r,O,K")))]
1133
  ""
1134
  "@
1135
   sll %0,%2
1136
   slli %0,%#%2
1137
   sll3 %0,%1,%#%2"
1138
  [(set_attr "type" "shift2,shift2,shift4")
1139
   (set_attr "length" "2,2,4")])
1140
 
1141
(define_insn "ashrsi3"
1142
  [(set (match_operand:SI 0 "register_operand" "=r,r,r")
1143
        (ashiftrt:SI (match_operand:SI 1 "register_operand" "0,0,r")
1144
                     (match_operand:SI 2 "reg_or_uint16_operand" "r,O,K")))]
1145
  ""
1146
  "@
1147
   sra %0,%2
1148
   srai %0,%#%2
1149
   sra3 %0,%1,%#%2"
1150
  [(set_attr "type" "shift2,shift2,shift4")
1151
   (set_attr "length" "2,2,4")])
1152
 
1153
(define_insn "lshrsi3"
1154
  [(set (match_operand:SI 0 "register_operand" "=r,r,r")
1155
        (lshiftrt:SI (match_operand:SI 1 "register_operand" "0,0,r")
1156
                     (match_operand:SI 2 "reg_or_uint16_operand" "r,O,K")))]
1157
  ""
1158
  "@
1159
   srl %0,%2
1160
   srli %0,%#%2
1161
   srl3 %0,%1,%#%2"
1162
  [(set_attr "type" "shift2,shift2,shift4")
1163
   (set_attr "length" "2,2,4")])
1164
 
1165
;; Compare instructions.
1166
;; This controls RTL generation and register allocation.
1167
 
1168
;; We generate RTL for comparisons and branches by having the cmpxx
1169
;; patterns store away the operands.  Then the bcc patterns
1170
;; emit RTL for both the compare and the branch.
1171
;;
1172
;; On the m32r it is more efficient to use the bxxz instructions and
1173
;; thus merge the compare and branch into one instruction, so they are
1174
;; preferred.
1175
 
1176
(define_expand "cmpsi"
1177
  [(set (reg:CC 17)
1178
        (compare:CC (match_operand:SI 0 "register_operand" "")
1179
                    (match_operand:SI 1 "reg_or_cmp_int16_operand" "")))]
1180
  ""
1181
  "
1182
{
1183
  m32r_compare_op0 = operands[0];
1184
  m32r_compare_op1 = operands[1];
1185
  DONE;
1186
}")
1187
 
1188
(define_insn "cmp_eqsi_zero_insn"
1189
  [(set (reg:CC 17)
1190
        (eq:CC (match_operand:SI 0 "register_operand" "r,r")
1191
               (match_operand:SI 1 "reg_or_zero_operand" "r,P")))]
1192
  "TARGET_M32RX || TARGET_M32R2"
1193
  "@
1194
   cmpeq %0, %1
1195
   cmpz  %0"
1196
  [(set_attr "type" "int4")
1197
   (set_attr "length" "4")])
1198
 
1199
;; The cmp_xxx_insn patterns set the condition bit to the result of the
1200
;; comparison.  There isn't a "compare equal" instruction so cmp_eqsi_insn
1201
;; is quite inefficient.  However, it is rarely used.
1202
 
1203
(define_insn "cmp_eqsi_insn"
1204
  [(set (reg:CC 17)
1205
        (eq:CC (match_operand:SI 0 "register_operand" "r,r")
1206
               (match_operand:SI 1 "reg_or_cmp_int16_operand" "r,P")))
1207
   (clobber (match_scratch:SI 2 "=&r,&r"))]
1208
  ""
1209
  "*
1210
{
1211
  if (which_alternative == 0)
1212
    {
1213
         return \"mv %2,%0\;sub %2,%1\;cmpui %2,#1\";
1214
    }
1215
  else
1216
    {
1217
        if (INTVAL (operands [1]) == 0)
1218
          return \"cmpui %0, #1\";
1219
        else if (REGNO (operands [2]) == REGNO (operands [0]))
1220
          return \"addi %0,%#%N1\;cmpui %2,#1\";
1221
        else
1222
          return \"add3 %2,%0,%#%N1\;cmpui %2,#1\";
1223
    }
1224
}"
1225
  [(set_attr "type" "multi,multi")
1226
   (set_attr "length" "8,8")])
1227
 
1228
(define_insn "cmp_ltsi_insn"
1229
  [(set (reg:CC 17)
1230
        (lt:CC (match_operand:SI 0 "register_operand" "r,r")
1231
               (match_operand:SI 1 "reg_or_int16_operand" "r,J")))]
1232
  ""
1233
  "@
1234
   cmp %0,%1
1235
   cmpi %0,%#%1"
1236
  [(set_attr "type" "int2,int4")
1237
   (set_attr "length" "2,4")])
1238
 
1239
(define_insn "cmp_ltusi_insn"
1240
  [(set (reg:CC 17)
1241
        (ltu:CC (match_operand:SI 0 "register_operand" "r,r")
1242
                (match_operand:SI 1 "reg_or_int16_operand" "r,J")))]
1243
  ""
1244
  "@
1245
   cmpu %0,%1
1246
   cmpui %0,%#%1"
1247
  [(set_attr "type" "int2,int4")
1248
   (set_attr "length" "2,4")])
1249
 
1250
;; These control RTL generation for conditional jump insns.
1251
 
1252
(define_expand "beq"
1253
  [(set (pc)
1254
        (if_then_else (match_dup 1)
1255
                      (label_ref (match_operand 0 "" ""))
1256
                      (pc)))]
1257
  ""
1258
  "
1259
{
1260
  operands[1] = gen_compare (EQ, m32r_compare_op0, m32r_compare_op1, FALSE);
1261
}")
1262
 
1263
(define_expand "bne"
1264
  [(set (pc)
1265
        (if_then_else (match_dup 1)
1266
                      (label_ref (match_operand 0 "" ""))
1267
                      (pc)))]
1268
  ""
1269
  "
1270
{
1271
  operands[1] = gen_compare (NE, m32r_compare_op0, m32r_compare_op1, FALSE);
1272
}")
1273
 
1274
(define_expand "bgt"
1275
  [(set (pc)
1276
        (if_then_else (match_dup 1)
1277
                      (label_ref (match_operand 0 "" ""))
1278
                      (pc)))]
1279
  ""
1280
  "
1281
{
1282
  operands[1] = gen_compare (GT, m32r_compare_op0, m32r_compare_op1, FALSE);
1283
}")
1284
 
1285
(define_expand "ble"
1286
  [(set (pc)
1287
        (if_then_else (match_dup 1)
1288
                      (label_ref (match_operand 0 "" ""))
1289
                      (pc)))]
1290
  ""
1291
  "
1292
{
1293
  operands[1] = gen_compare (LE, m32r_compare_op0, m32r_compare_op1, FALSE);
1294
}")
1295
 
1296
(define_expand "bge"
1297
  [(set (pc)
1298
        (if_then_else (match_dup 1)
1299
                      (label_ref (match_operand 0 "" ""))
1300
                      (pc)))]
1301
  ""
1302
  "
1303
{
1304
  operands[1] = gen_compare (GE, m32r_compare_op0, m32r_compare_op1, FALSE);
1305
}")
1306
 
1307
(define_expand "blt"
1308
  [(set (pc)
1309
        (if_then_else (match_dup 1)
1310
                      (label_ref (match_operand 0 "" ""))
1311
                      (pc)))]
1312
  ""
1313
  "
1314
{
1315
  operands[1] = gen_compare (LT, m32r_compare_op0, m32r_compare_op1, FALSE);
1316
}")
1317
 
1318
(define_expand "bgtu"
1319
  [(set (pc)
1320
        (if_then_else (match_dup 1)
1321
                      (label_ref (match_operand 0 "" ""))
1322
                      (pc)))]
1323
  ""
1324
  "
1325
{
1326
  operands[1] = gen_compare (GTU, m32r_compare_op0, m32r_compare_op1, FALSE);
1327
}")
1328
 
1329
(define_expand "bleu"
1330
  [(set (pc)
1331
        (if_then_else (match_dup 1)
1332
                      (label_ref (match_operand 0 "" ""))
1333
                      (pc)))]
1334
  ""
1335
  "
1336
{
1337
  operands[1] = gen_compare (LEU, m32r_compare_op0, m32r_compare_op1, FALSE);
1338
}")
1339
 
1340
(define_expand "bgeu"
1341
  [(set (pc)
1342
        (if_then_else (match_dup 1)
1343
                      (label_ref (match_operand 0 "" ""))
1344
                      (pc)))]
1345
  ""
1346
  "
1347
{
1348
  operands[1] = gen_compare (GEU, m32r_compare_op0, m32r_compare_op1, FALSE);
1349
}")
1350
 
1351
(define_expand "bltu"
1352
  [(set (pc)
1353
        (if_then_else (match_dup 1)
1354
                      (label_ref (match_operand 0 "" ""))
1355
                      (pc)))]
1356
  ""
1357
  "
1358
{
1359
  operands[1] = gen_compare (LTU, m32r_compare_op0, m32r_compare_op1, FALSE);
1360
}")
1361
 
1362
;; Now match both normal and inverted jump.
1363
 
1364
(define_insn "*branch_insn"
1365
  [(set (pc)
1366
        (if_then_else (match_operator 1 "eqne_comparison_operator"
1367
                                      [(reg 17) (const_int 0)])
1368
                      (label_ref (match_operand 0 "" ""))
1369
                      (pc)))]
1370
  ""
1371
  "*
1372
{
1373
  static char instruction[40];
1374
  sprintf (instruction, \"%s%s %%l0\",
1375
           (GET_CODE (operands[1]) == NE) ? \"bc\" : \"bnc\",
1376
           (get_attr_length (insn) == 2) ? \".s\" : \"\");
1377
  return instruction;
1378
}"
1379
  [(set_attr "type" "branch")
1380
   ; cf PR gcc/28508
1381
   ; We use 300/600 instead of 512,1024 to account for inaccurate insn
1382
   ; lengths and insn alignments that are complex to track.
1383
   ; It's not important that we be hyper-precise here.  It may be more
1384
   ; important blah blah blah when the chip supports parallel execution
1385
   ; blah blah blah but until then blah blah blah this is simple and
1386
   ; suffices.
1387
   (set (attr "length") (if_then_else (ltu (plus (minus (match_dup 0) (pc))
1388
                                                 (const_int 300))
1389
                                           (const_int 600))
1390
                                      (const_int 2)
1391
                                      (const_int 4)))])
1392
 
1393
(define_insn "*rev_branch_insn"
1394
  [(set (pc)
1395
        (if_then_else (match_operator 1 "eqne_comparison_operator"
1396
                                      [(reg 17) (const_int 0)])
1397
                      (pc)
1398
                      (label_ref (match_operand 0 "" ""))))]
1399
  ;"REVERSIBLE_CC_MODE (GET_MODE (XEXP (operands[1], 0)))"
1400
  ""
1401
  "*
1402
{
1403
  static char instruction[40];
1404
  sprintf (instruction, \"%s%s %%l0\",
1405
           (GET_CODE (operands[1]) == EQ) ? \"bc\" : \"bnc\",
1406
           (get_attr_length (insn) == 2) ? \".s\" : \"\");
1407
  return instruction;
1408
}"
1409
  [(set_attr "type" "branch")
1410
   ; cf PR gcc/28508
1411
   ; We use 300/600 instead of 512,1024 to account for inaccurate insn
1412
   ; lengths and insn alignments that are complex to track.
1413
   ; It's not important that we be hyper-precise here.  It may be more
1414
   ; important blah blah blah when the chip supports parallel execution
1415
   ; blah blah blah but until then blah blah blah this is simple and
1416
   ; suffices.
1417
   (set (attr "length") (if_then_else (ltu (plus (minus (match_dup 0) (pc))
1418
                                                 (const_int 300))
1419
                                           (const_int 600))
1420
                                      (const_int 2)
1421
                                      (const_int 4)))])
1422
 
1423
; reg/reg compare and branch insns
1424
 
1425
(define_insn "*reg_branch_insn"
1426
  [(set (pc)
1427
        (if_then_else (match_operator 1 "eqne_comparison_operator"
1428
                                      [(match_operand:SI 2 "register_operand" "r")
1429
                                       (match_operand:SI 3 "register_operand" "r")])
1430
                      (label_ref (match_operand 0 "" ""))
1431
                      (pc)))]
1432
  ""
1433
  "*
1434
{
1435
  /* Is branch target reachable with beq/bne?  */
1436
  if (get_attr_length (insn) == 4)
1437
    {
1438
      if (GET_CODE (operands[1]) == EQ)
1439
        return \"beq %2,%3,%l0\";
1440
      else
1441
        return \"bne %2,%3,%l0\";
1442
    }
1443
  else
1444
    {
1445
      if (GET_CODE (operands[1]) == EQ)
1446
        return \"bne %2,%3,1f\;bra %l0\;1:\";
1447
      else
1448
        return \"beq %2,%3,1f\;bra %l0\;1:\";
1449
    }
1450
}"
1451
  [(set_attr "type" "branch")
1452
  ; We use 25000/50000 instead of 32768/65536 to account for slot filling
1453
  ; which is complex to track and inaccurate length specs.
1454
   (set (attr "length") (if_then_else (ltu (plus (minus (match_dup 0) (pc))
1455
                                                 (const_int 25000))
1456
                                           (const_int 50000))
1457
                                      (const_int 4)
1458
                                      (const_int 8)))])
1459
 
1460
(define_insn "*rev_reg_branch_insn"
1461
  [(set (pc)
1462
        (if_then_else (match_operator 1 "eqne_comparison_operator"
1463
                                      [(match_operand:SI 2 "register_operand" "r")
1464
                                       (match_operand:SI 3 "register_operand" "r")])
1465
                      (pc)
1466
                      (label_ref (match_operand 0 "" ""))))]
1467
  ""
1468
  "*
1469
{
1470
  /* Is branch target reachable with beq/bne?  */
1471
  if (get_attr_length (insn) == 4)
1472
    {
1473
      if (GET_CODE (operands[1]) == NE)
1474
        return \"beq %2,%3,%l0\";
1475
      else
1476
        return \"bne %2,%3,%l0\";
1477
    }
1478
  else
1479
    {
1480
      if (GET_CODE (operands[1]) == NE)
1481
        return \"bne %2,%3,1f\;bra %l0\;1:\";
1482
      else
1483
        return \"beq %2,%3,1f\;bra %l0\;1:\";
1484
    }
1485
}"
1486
  [(set_attr "type" "branch")
1487
  ; We use 25000/50000 instead of 32768/65536 to account for slot filling
1488
  ; which is complex to track and inaccurate length specs.
1489
   (set (attr "length") (if_then_else (ltu (plus (minus (match_dup 0) (pc))
1490
                                                 (const_int 25000))
1491
                                           (const_int 50000))
1492
                                      (const_int 4)
1493
                                      (const_int 8)))])
1494
 
1495
; reg/zero compare and branch insns
1496
 
1497
(define_insn "*zero_branch_insn"
1498
  [(set (pc)
1499
        (if_then_else (match_operator 1 "signed_comparison_operator"
1500
                                      [(match_operand:SI 2 "register_operand" "r")
1501
                                       (const_int 0)])
1502
                      (label_ref (match_operand 0 "" ""))
1503
                      (pc)))]
1504
  ""
1505
  "*
1506
{
1507
  const char *br,*invbr;
1508
  char asmtext[40];
1509
 
1510
  switch (GET_CODE (operands[1]))
1511
    {
1512
      case EQ : br = \"eq\"; invbr = \"ne\"; break;
1513
      case NE : br = \"ne\"; invbr = \"eq\"; break;
1514
      case LE : br = \"le\"; invbr = \"gt\"; break;
1515
      case GT : br = \"gt\"; invbr = \"le\"; break;
1516
      case LT : br = \"lt\"; invbr = \"ge\"; break;
1517
      case GE : br = \"ge\"; invbr = \"lt\"; break;
1518
 
1519
      default: gcc_unreachable ();
1520
    }
1521
 
1522
  /* Is branch target reachable with bxxz?  */
1523
  if (get_attr_length (insn) == 4)
1524
    {
1525
      sprintf (asmtext, \"b%sz %%2,%%l0\", br);
1526
      output_asm_insn (asmtext, operands);
1527
    }
1528
  else
1529
    {
1530
      sprintf (asmtext, \"b%sz %%2,1f\;bra %%l0\;1:\", invbr);
1531
      output_asm_insn (asmtext, operands);
1532
    }
1533
  return \"\";
1534
}"
1535
  [(set_attr "type" "branch")
1536
  ; We use 25000/50000 instead of 32768/65536 to account for slot filling
1537
  ; which is complex to track and inaccurate length specs.
1538
   (set (attr "length") (if_then_else (ltu (plus (minus (match_dup 0) (pc))
1539
                                                 (const_int 25000))
1540
                                           (const_int 50000))
1541
                                      (const_int 4)
1542
                                      (const_int 8)))])
1543
 
1544
(define_insn "*rev_zero_branch_insn"
1545
  [(set (pc)
1546
        (if_then_else (match_operator 1 "eqne_comparison_operator"
1547
                                      [(match_operand:SI 2 "register_operand" "r")
1548
                                       (const_int 0)])
1549
                      (pc)
1550
                      (label_ref (match_operand 0 "" ""))))]
1551
  ""
1552
  "*
1553
{
1554
  const char *br,*invbr;
1555
  char asmtext[40];
1556
 
1557
  switch (GET_CODE (operands[1]))
1558
    {
1559
      case EQ : br = \"eq\"; invbr = \"ne\"; break;
1560
      case NE : br = \"ne\"; invbr = \"eq\"; break;
1561
      case LE : br = \"le\"; invbr = \"gt\"; break;
1562
      case GT : br = \"gt\"; invbr = \"le\"; break;
1563
      case LT : br = \"lt\"; invbr = \"ge\"; break;
1564
      case GE : br = \"ge\"; invbr = \"lt\"; break;
1565
 
1566
      default: gcc_unreachable ();
1567
    }
1568
 
1569
  /* Is branch target reachable with bxxz?  */
1570
  if (get_attr_length (insn) == 4)
1571
    {
1572
      sprintf (asmtext, \"b%sz %%2,%%l0\", invbr);
1573
      output_asm_insn (asmtext, operands);
1574
    }
1575
  else
1576
    {
1577
      sprintf (asmtext, \"b%sz %%2,1f\;bra %%l0\;1:\", br);
1578
      output_asm_insn (asmtext, operands);
1579
    }
1580
  return \"\";
1581
}"
1582
  [(set_attr "type" "branch")
1583
  ; We use 25000/50000 instead of 32768/65536 to account for slot filling
1584
  ; which is complex to track and inaccurate length specs.
1585
   (set (attr "length") (if_then_else (ltu (plus (minus (match_dup 0) (pc))
1586
                                                 (const_int 25000))
1587
                                           (const_int 50000))
1588
                                      (const_int 4)
1589
                                      (const_int 8)))])
1590
 
1591
;; S operations to set a register to 1/0 based on a comparison
1592
 
1593
(define_expand "seq"
1594
  [(match_operand:SI 0 "register_operand" "")]
1595
  ""
1596
  "
1597
{
1598
  rtx op0 = operands[0];
1599
  rtx op1 = m32r_compare_op0;
1600
  rtx op2 = m32r_compare_op1;
1601
  enum machine_mode mode = GET_MODE (op0);
1602
 
1603
  if (mode != SImode)
1604
    FAIL;
1605
 
1606
  if (! register_operand (op1, mode))
1607
    op1 = force_reg (mode, op1);
1608
 
1609
  if (TARGET_M32RX || TARGET_M32R2)
1610
    {
1611
      if (! reg_or_zero_operand (op2, mode))
1612
        op2 = force_reg (mode, op2);
1613
 
1614
      emit_insn (gen_seq_insn_m32rx (op0, op1, op2));
1615
      DONE;
1616
    }
1617
  if (GET_CODE (op2) == CONST_INT && INTVAL (op2) == 0)
1618
    {
1619
      emit_insn (gen_seq_zero_insn (op0, op1));
1620
      DONE;
1621
    }
1622
 
1623
  if (! reg_or_eq_int16_operand (op2, mode))
1624
    op2 = force_reg (mode, op2);
1625
 
1626
  emit_insn (gen_seq_insn (op0, op1, op2));
1627
  DONE;
1628
}")
1629
 
1630
(define_insn "seq_insn_m32rx"
1631
  [(set (match_operand:SI 0 "register_operand" "=r")
1632
        (eq:SI (match_operand:SI 1 "register_operand" "%r")
1633
               (match_operand:SI 2 "reg_or_zero_operand" "rP")))
1634
   (clobber (reg:CC 17))]
1635
  "TARGET_M32RX || TARGET_M32R2"
1636
  "#"
1637
  [(set_attr "type" "multi")
1638
   (set_attr "length" "6")])
1639
 
1640
(define_split
1641
  [(set (match_operand:SI 0 "register_operand" "")
1642
        (eq:SI (match_operand:SI 1 "register_operand" "")
1643
               (match_operand:SI 2 "reg_or_zero_operand" "")))
1644
   (clobber (reg:CC 17))]
1645
  "TARGET_M32RX || TARGET_M32R2"
1646
  [(set (reg:CC 17)
1647
        (eq:CC (match_dup 1)
1648
               (match_dup 2)))
1649
   (set (match_dup 0)
1650
        (ne:SI (reg:CC 17) (const_int 0)))]
1651
  "")
1652
 
1653
(define_insn "seq_zero_insn"
1654
  [(set (match_operand:SI 0 "register_operand" "=r")
1655
        (eq:SI (match_operand:SI 1 "register_operand" "r")
1656
               (const_int 0)))
1657
   (clobber (reg:CC 17))]
1658
  "TARGET_M32R"
1659
  "#"
1660
  [(set_attr "type" "multi")
1661
   (set_attr "length" "6")])
1662
 
1663
(define_split
1664
  [(set (match_operand:SI 0 "register_operand" "")
1665
        (eq:SI (match_operand:SI 1 "register_operand" "")
1666
               (const_int 0)))
1667
   (clobber (reg:CC 17))]
1668
  "TARGET_M32R"
1669
  [(match_dup 3)]
1670
  "
1671
{
1672
  rtx op0 = operands[0];
1673
  rtx op1 = operands[1];
1674
 
1675
  start_sequence ();
1676
  emit_insn (gen_cmp_ltusi_insn (op1, const1_rtx));
1677
  emit_insn (gen_movcc_insn (op0));
1678
  operands[3] = get_insns ();
1679
  end_sequence ();
1680
}")
1681
 
1682
(define_insn "seq_insn"
1683
  [(set (match_operand:SI 0 "register_operand" "=r,r,??r,r")
1684
        (eq:SI (match_operand:SI 1 "register_operand" "r,r,r,r")
1685
               (match_operand:SI 2 "reg_or_eq_int16_operand" "r,r,r,PK")))
1686
   (clobber (reg:CC 17))
1687
   (clobber (match_scratch:SI 3 "=1,2,&r,r"))]
1688
  "TARGET_M32R"
1689
  "#"
1690
  [(set_attr "type" "multi")
1691
   (set_attr "length" "8,8,10,10")])
1692
 
1693
(define_split
1694
  [(set (match_operand:SI 0 "register_operand" "")
1695
        (eq:SI (match_operand:SI 1 "register_operand" "")
1696
               (match_operand:SI 2 "reg_or_eq_int16_operand" "")))
1697
   (clobber (reg:CC 17))
1698
   (clobber (match_scratch:SI 3 ""))]
1699
  "TARGET_M32R && reload_completed"
1700
  [(match_dup 4)]
1701
  "
1702
{
1703
  rtx op0 = operands[0];
1704
  rtx op1 = operands[1];
1705
  rtx op2 = operands[2];
1706
  rtx op3 = operands[3];
1707
  HOST_WIDE_INT value;
1708
 
1709
  if (GET_CODE (op2) == REG && GET_CODE (op3) == REG
1710
      && REGNO (op2) == REGNO (op3))
1711
    {
1712
      op1 = operands[2];
1713
      op2 = operands[1];
1714
    }
1715
 
1716
  start_sequence ();
1717
  if (GET_CODE (op1) == REG && GET_CODE (op3) == REG
1718
      && REGNO (op1) != REGNO (op3))
1719
    {
1720
      emit_move_insn (op3, op1);
1721
      op1 = op3;
1722
    }
1723
 
1724
  if (GET_CODE (op2) == CONST_INT && (value = INTVAL (op2)) != 0
1725
      && CMP_INT16_P (value))
1726
    emit_insn (gen_addsi3 (op3, op1, GEN_INT (-value)));
1727
  else
1728
    emit_insn (gen_xorsi3 (op3, op1, op2));
1729
 
1730
  emit_insn (gen_cmp_ltusi_insn (op3, const1_rtx));
1731
  emit_insn (gen_movcc_insn (op0));
1732
  operands[4] = get_insns ();
1733
  end_sequence ();
1734
}")
1735
 
1736
(define_expand "sne"
1737
  [(match_operand:SI 0 "register_operand" "")]
1738
  ""
1739
  "
1740
{
1741
  rtx op0 = operands[0];
1742
  rtx op1 = m32r_compare_op0;
1743
  rtx op2 = m32r_compare_op1;
1744
  enum machine_mode mode = GET_MODE (op0);
1745
 
1746
  if (mode != SImode)
1747
    FAIL;
1748
 
1749
  if (GET_CODE (op2) != CONST_INT
1750
      || (INTVAL (op2) != 0 && UINT16_P (INTVAL (op2))))
1751
    {
1752
      rtx reg;
1753
 
1754
      if (reload_completed || reload_in_progress)
1755
        FAIL;
1756
 
1757
      reg = gen_reg_rtx (SImode);
1758
      emit_insn (gen_xorsi3 (reg, op1, op2));
1759
      op1 = reg;
1760
 
1761
      if (! register_operand (op1, mode))
1762
        op1 = force_reg (mode, op1);
1763
 
1764
      emit_insn (gen_sne_zero_insn (op0, op1));
1765
      DONE;
1766
    }
1767
  else
1768
    FAIL;
1769
}")
1770
 
1771
(define_insn "sne_zero_insn"
1772
  [(set (match_operand:SI 0 "register_operand" "=r")
1773
        (ne:SI (match_operand:SI 1 "register_operand" "r")
1774
               (const_int 0)))
1775
   (clobber (reg:CC 17))
1776
   (clobber (match_scratch:SI 2 "=&r"))]
1777
  ""
1778
  "#"
1779
  [(set_attr "type" "multi")
1780
   (set_attr "length" "6")])
1781
 
1782
(define_split
1783
  [(set (match_operand:SI 0 "register_operand" "")
1784
        (ne:SI (match_operand:SI 1 "register_operand" "")
1785
               (const_int 0)))
1786
   (clobber (reg:CC 17))
1787
   (clobber (match_scratch:SI 2 ""))]
1788
  "reload_completed"
1789
  [(set (match_dup 2)
1790
        (const_int 0))
1791
   (set (reg:CC 17)
1792
        (ltu:CC (match_dup 2)
1793
                (match_dup 1)))
1794
   (set (match_dup 0)
1795
        (ne:SI (reg:CC 17) (const_int 0)))]
1796
  "")
1797
 
1798
(define_expand "slt"
1799
  [(match_operand:SI 0 "register_operand" "")]
1800
  ""
1801
  "
1802
{
1803
  rtx op0 = operands[0];
1804
  rtx op1 = m32r_compare_op0;
1805
  rtx op2 = m32r_compare_op1;
1806
  enum machine_mode mode = GET_MODE (op0);
1807
 
1808
  if (mode != SImode)
1809
    FAIL;
1810
 
1811
  if (! register_operand (op1, mode))
1812
    op1 = force_reg (mode, op1);
1813
 
1814
  if (! reg_or_int16_operand (op2, mode))
1815
    op2 = force_reg (mode, op2);
1816
 
1817
  emit_insn (gen_slt_insn (op0, op1, op2));
1818
  DONE;
1819
}")
1820
 
1821
(define_insn "slt_insn"
1822
  [(set (match_operand:SI 0 "register_operand" "=r,r")
1823
        (lt:SI (match_operand:SI 1 "register_operand" "r,r")
1824
               (match_operand:SI 2 "reg_or_int16_operand" "r,J")))
1825
   (clobber (reg:CC 17))]
1826
  ""
1827
  "#"
1828
  [(set_attr "type" "multi")
1829
   (set_attr "length" "4,6")])
1830
 
1831
(define_split
1832
  [(set (match_operand:SI 0 "register_operand" "")
1833
        (lt:SI (match_operand:SI 1 "register_operand" "")
1834
               (match_operand:SI 2 "reg_or_int16_operand" "")))
1835
   (clobber (reg:CC 17))]
1836
  ""
1837
  [(set (reg:CC 17)
1838
        (lt:CC (match_dup 1)
1839
               (match_dup 2)))
1840
   (set (match_dup 0)
1841
        (ne:SI (reg:CC 17) (const_int 0)))]
1842
  "")
1843
 
1844
(define_expand "sle"
1845
  [(match_operand:SI 0 "register_operand" "")]
1846
  ""
1847
  "
1848
{
1849
  rtx op0 = operands[0];
1850
  rtx op1 = m32r_compare_op0;
1851
  rtx op2 = m32r_compare_op1;
1852
  enum machine_mode mode = GET_MODE (op0);
1853
 
1854
  if (mode != SImode)
1855
    FAIL;
1856
 
1857
  if (! register_operand (op1, mode))
1858
    op1 = force_reg (mode, op1);
1859
 
1860
  if (GET_CODE (op2) == CONST_INT)
1861
    {
1862
      HOST_WIDE_INT value = INTVAL (op2);
1863
      if (value >= 2147483647)
1864
        {
1865
          emit_move_insn (op0, const1_rtx);
1866
          DONE;
1867
        }
1868
 
1869
      op2 = GEN_INT (value+1);
1870
      if (value < -32768 || value >= 32767)
1871
        op2 = force_reg (mode, op2);
1872
 
1873
      emit_insn (gen_slt_insn (op0, op1, op2));
1874
      DONE;
1875
    }
1876
 
1877
  if (! register_operand (op2, mode))
1878
    op2 = force_reg (mode, op2);
1879
 
1880
  emit_insn (gen_sle_insn (op0, op1, op2));
1881
  DONE;
1882
}")
1883
 
1884
(define_insn "sle_insn"
1885
  [(set (match_operand:SI 0 "register_operand" "=r")
1886
        (le:SI (match_operand:SI 1 "register_operand" "r")
1887
               (match_operand:SI 2 "register_operand" "r")))
1888
   (clobber (reg:CC 17))]
1889
  ""
1890
  "#"
1891
  [(set_attr "type" "multi")
1892
   (set_attr "length" "8")])
1893
 
1894
(define_split
1895
  [(set (match_operand:SI 0 "register_operand" "")
1896
        (le:SI (match_operand:SI 1 "register_operand" "")
1897
               (match_operand:SI 2 "register_operand" "")))
1898
   (clobber (reg:CC 17))]
1899
  "!optimize_size"
1900
  [(set (reg:CC 17)
1901
        (lt:CC (match_dup 2)
1902
               (match_dup 1)))
1903
   (set (match_dup 0)
1904
        (ne:SI (reg:CC 17) (const_int 0)))
1905
   (set (match_dup 0)
1906
        (xor:SI (match_dup 0)
1907
                (const_int 1)))]
1908
  "")
1909
 
1910
;; If optimizing for space, use -(reg - 1) to invert the comparison rather than
1911
;; xor reg,reg,1 which might eliminate a NOP being inserted.
1912
(define_split
1913
  [(set (match_operand:SI 0 "register_operand" "")
1914
        (le:SI (match_operand:SI 1 "register_operand" "")
1915
               (match_operand:SI 2 "register_operand" "")))
1916
   (clobber (reg:CC 17))]
1917
  "optimize_size"
1918
  [(set (reg:CC 17)
1919
        (lt:CC (match_dup 2)
1920
               (match_dup 1)))
1921
   (set (match_dup 0)
1922
        (ne:SI (reg:CC 17) (const_int 0)))
1923
   (set (match_dup 0)
1924
        (plus:SI (match_dup 0)
1925
                 (const_int -1)))
1926
   (set (match_dup 0)
1927
        (neg:SI (match_dup 0)))]
1928
  "")
1929
 
1930
(define_expand "sgt"
1931
  [(match_operand:SI 0 "register_operand" "")]
1932
  ""
1933
  "
1934
{
1935
  rtx op0 = operands[0];
1936
  rtx op1 = m32r_compare_op0;
1937
  rtx op2 = m32r_compare_op1;
1938
  enum machine_mode mode = GET_MODE (op0);
1939
 
1940
  if (mode != SImode)
1941
    FAIL;
1942
 
1943
  if (! register_operand (op1, mode))
1944
    op1 = force_reg (mode, op1);
1945
 
1946
  if (! register_operand (op2, mode))
1947
    op2 = force_reg (mode, op2);
1948
 
1949
  emit_insn (gen_slt_insn (op0, op2, op1));
1950
  DONE;
1951
}")
1952
 
1953
(define_expand "sge"
1954
  [(match_operand:SI 0 "register_operand" "")]
1955
  ""
1956
  "
1957
{
1958
  rtx op0 = operands[0];
1959
  rtx op1 = m32r_compare_op0;
1960
  rtx op2 = m32r_compare_op1;
1961
  enum machine_mode mode = GET_MODE (op0);
1962
 
1963
  if (mode != SImode)
1964
    FAIL;
1965
 
1966
  if (! register_operand (op1, mode))
1967
    op1 = force_reg (mode, op1);
1968
 
1969
  if (! reg_or_int16_operand (op2, mode))
1970
    op2 = force_reg (mode, op2);
1971
 
1972
  emit_insn (gen_sge_insn (op0, op1, op2));
1973
  DONE;
1974
}")
1975
 
1976
(define_insn "sge_insn"
1977
  [(set (match_operand:SI 0 "register_operand" "=r,r")
1978
        (ge:SI (match_operand:SI 1 "register_operand" "r,r")
1979
               (match_operand:SI 2 "reg_or_int16_operand" "r,J")))
1980
   (clobber (reg:CC 17))]
1981
  ""
1982
  "#"
1983
  [(set_attr "type" "multi")
1984
   (set_attr "length" "8,10")])
1985
 
1986
(define_split
1987
  [(set (match_operand:SI 0 "register_operand" "")
1988
        (ge:SI (match_operand:SI 1 "register_operand" "")
1989
               (match_operand:SI 2 "reg_or_int16_operand" "")))
1990
   (clobber (reg:CC 17))]
1991
  "!optimize_size"
1992
  [(set (reg:CC 17)
1993
        (lt:CC (match_dup 1)
1994
               (match_dup 2)))
1995
   (set (match_dup 0)
1996
        (ne:SI (reg:CC 17) (const_int 0)))
1997
   (set (match_dup 0)
1998
        (xor:SI (match_dup 0)
1999
                (const_int 1)))]
2000
  "")
2001
 
2002
;; If optimizing for space, use -(reg - 1) to invert the comparison rather than
2003
;; xor reg,reg,1 which might eliminate a NOP being inserted.
2004
(define_split
2005
  [(set (match_operand:SI 0 "register_operand" "")
2006
        (ge:SI (match_operand:SI 1 "register_operand" "")
2007
               (match_operand:SI 2 "reg_or_int16_operand" "")))
2008
   (clobber (reg:CC 17))]
2009
  "optimize_size"
2010
  [(set (reg:CC 17)
2011
        (lt:CC (match_dup 1)
2012
               (match_dup 2)))
2013
   (set (match_dup 0)
2014
        (ne:SI (reg:CC 17) (const_int 0)))
2015
   (set (match_dup 0)
2016
        (plus:SI (match_dup 0)
2017
                 (const_int -1)))
2018
   (set (match_dup 0)
2019
        (neg:SI (match_dup 0)))]
2020
  "")
2021
 
2022
(define_expand "sltu"
2023
  [(match_operand:SI 0 "register_operand" "")]
2024
  ""
2025
  "
2026
{
2027
  rtx op0 = operands[0];
2028
  rtx op1 = m32r_compare_op0;
2029
  rtx op2 = m32r_compare_op1;
2030
  enum machine_mode mode = GET_MODE (op0);
2031
 
2032
  if (mode != SImode)
2033
    FAIL;
2034
 
2035
  if (! register_operand (op1, mode))
2036
    op1 = force_reg (mode, op1);
2037
 
2038
  if (! reg_or_int16_operand (op2, mode))
2039
    op2 = force_reg (mode, op2);
2040
 
2041
  emit_insn (gen_sltu_insn (op0, op1, op2));
2042
  DONE;
2043
}")
2044
 
2045
(define_insn "sltu_insn"
2046
  [(set (match_operand:SI 0 "register_operand" "=r,r")
2047
        (ltu:SI (match_operand:SI 1 "register_operand" "r,r")
2048
                (match_operand:SI 2 "reg_or_int16_operand" "r,J")))
2049
   (clobber (reg:CC 17))]
2050
  ""
2051
  "#"
2052
  [(set_attr "type" "multi")
2053
   (set_attr "length" "6,8")])
2054
 
2055
(define_split
2056
  [(set (match_operand:SI 0 "register_operand" "")
2057
        (ltu:SI (match_operand:SI 1 "register_operand" "")
2058
                (match_operand:SI 2 "reg_or_int16_operand" "")))
2059
   (clobber (reg:CC 17))]
2060
  ""
2061
  [(set (reg:CC 17)
2062
        (ltu:CC (match_dup 1)
2063
                (match_dup 2)))
2064
   (set (match_dup 0)
2065
        (ne:SI (reg:CC 17) (const_int 0)))]
2066
  "")
2067
 
2068
(define_expand "sleu"
2069
  [(match_operand:SI 0 "register_operand" "")]
2070
  ""
2071
  "
2072
{
2073
  rtx op0 = operands[0];
2074
  rtx op1 = m32r_compare_op0;
2075
  rtx op2 = m32r_compare_op1;
2076
  enum machine_mode mode = GET_MODE (op0);
2077
 
2078
  if (mode != SImode)
2079
    FAIL;
2080
 
2081
  if (GET_CODE (op2) == CONST_INT)
2082
    {
2083
      HOST_WIDE_INT value = INTVAL (op2);
2084
      if (value >= 2147483647)
2085
        {
2086
          emit_move_insn (op0, const1_rtx);
2087
          DONE;
2088
        }
2089
 
2090
      op2 = GEN_INT (value+1);
2091
      if (value < 0 || value >= 32767)
2092
        op2 = force_reg (mode, op2);
2093
 
2094
      emit_insn (gen_sltu_insn (op0, op1, op2));
2095
      DONE;
2096
    }
2097
 
2098
  if (! register_operand (op2, mode))
2099
    op2 = force_reg (mode, op2);
2100
 
2101
  emit_insn (gen_sleu_insn (op0, op1, op2));
2102
  DONE;
2103
}")
2104
 
2105
(define_insn "sleu_insn"
2106
  [(set (match_operand:SI 0 "register_operand" "=r")
2107
        (leu:SI (match_operand:SI 1 "register_operand" "r")
2108
                (match_operand:SI 2 "register_operand" "r")))
2109
   (clobber (reg:CC 17))]
2110
  ""
2111
  "#"
2112
  [(set_attr "type" "multi")
2113
   (set_attr "length" "8")])
2114
 
2115
(define_split
2116
  [(set (match_operand:SI 0 "register_operand" "")
2117
        (leu:SI (match_operand:SI 1 "register_operand" "")
2118
                (match_operand:SI 2 "register_operand" "")))
2119
   (clobber (reg:CC 17))]
2120
  "!optimize_size"
2121
  [(set (reg:CC 17)
2122
        (ltu:CC (match_dup 2)
2123
                (match_dup 1)))
2124
   (set (match_dup 0)
2125
        (ne:SI (reg:CC 17) (const_int 0)))
2126
   (set (match_dup 0)
2127
        (xor:SI (match_dup 0)
2128
                (const_int 1)))]
2129
  "")
2130
 
2131
;; If optimizing for space, use -(reg - 1) to invert the comparison rather than
2132
;; xor reg,reg,1 which might eliminate a NOP being inserted.
2133
(define_split
2134
  [(set (match_operand:SI 0 "register_operand" "")
2135
        (leu:SI (match_operand:SI 1 "register_operand" "")
2136
                (match_operand:SI 2 "register_operand" "")))
2137
   (clobber (reg:CC 17))]
2138
  "optimize_size"
2139
  [(set (reg:CC 17)
2140
        (ltu:CC (match_dup 2)
2141
                (match_dup 1)))
2142
   (set (match_dup 0)
2143
        (ne:SI (reg:CC 17) (const_int 0)))
2144
   (set (match_dup 0)
2145
        (plus:SI (match_dup 0)
2146
                 (const_int -1)))
2147
   (set (match_dup 0)
2148
        (neg:SI (match_dup 0)))]
2149
  "")
2150
 
2151
(define_expand "sgtu"
2152
  [(match_operand:SI 0 "register_operand" "")]
2153
  ""
2154
  "
2155
{
2156
  rtx op0 = operands[0];
2157
  rtx op1 = m32r_compare_op0;
2158
  rtx op2 = m32r_compare_op1;
2159
  enum machine_mode mode = GET_MODE (op0);
2160
 
2161
  if (mode != SImode)
2162
    FAIL;
2163
 
2164
  if (! register_operand (op1, mode))
2165
    op1 = force_reg (mode, op1);
2166
 
2167
  if (! register_operand (op2, mode))
2168
    op2 = force_reg (mode, op2);
2169
 
2170
  emit_insn (gen_sltu_insn (op0, op2, op1));
2171
  DONE;
2172
}")
2173
 
2174
(define_expand "sgeu"
2175
  [(match_operand:SI 0 "register_operand" "")]
2176
  ""
2177
  "
2178
{
2179
  rtx op0 = operands[0];
2180
  rtx op1 = m32r_compare_op0;
2181
  rtx op2 = m32r_compare_op1;
2182
  enum machine_mode mode = GET_MODE (op0);
2183
 
2184
  if (mode != SImode)
2185
    FAIL;
2186
 
2187
  if (! register_operand (op1, mode))
2188
    op1 = force_reg (mode, op1);
2189
 
2190
  if (! reg_or_int16_operand (op2, mode))
2191
    op2 = force_reg (mode, op2);
2192
 
2193
  emit_insn (gen_sgeu_insn (op0, op1, op2));
2194
  DONE;
2195
}")
2196
 
2197
(define_insn "sgeu_insn"
2198
  [(set (match_operand:SI 0 "register_operand" "=r,r")
2199
        (geu:SI (match_operand:SI 1 "register_operand" "r,r")
2200
                (match_operand:SI 2 "reg_or_int16_operand" "r,J")))
2201
   (clobber (reg:CC 17))]
2202
  ""
2203
  "#"
2204
  [(set_attr "type" "multi")
2205
   (set_attr "length" "8,10")])
2206
 
2207
(define_split
2208
  [(set (match_operand:SI 0 "register_operand" "")
2209
        (geu:SI (match_operand:SI 1 "register_operand" "")
2210
                (match_operand:SI 2 "reg_or_int16_operand" "")))
2211
   (clobber (reg:CC 17))]
2212
  "!optimize_size"
2213
  [(set (reg:CC 17)
2214
        (ltu:CC (match_dup 1)
2215
                (match_dup 2)))
2216
   (set (match_dup 0)
2217
        (ne:SI (reg:CC 17) (const_int 0)))
2218
   (set (match_dup 0)
2219
        (xor:SI (match_dup 0)
2220
                (const_int 1)))]
2221
  "")
2222
 
2223
;; If optimizing for space, use -(reg - 1) to invert the comparison rather than
2224
;; xor reg,reg,1 which might eliminate a NOP being inserted.
2225
(define_split
2226
  [(set (match_operand:SI 0 "register_operand" "")
2227
        (geu:SI (match_operand:SI 1 "register_operand" "")
2228
                (match_operand:SI 2 "reg_or_int16_operand" "")))
2229
   (clobber (reg:CC 17))]
2230
  "optimize_size"
2231
  [(set (reg:CC 17)
2232
        (ltu:CC (match_dup 1)
2233
                (match_dup 2)))
2234
   (set (match_dup 0)
2235
        (ne:SI (reg:CC 17) (const_int 0)))
2236
   (set (match_dup 0)
2237
        (plus:SI (match_dup 0)
2238
                 (const_int -1)))
2239
   (set (match_dup 0)
2240
        (neg:SI (match_dup 0)))]
2241
  "")
2242
 
2243
(define_insn "movcc_insn"
2244
  [(set (match_operand:SI 0 "register_operand" "=r")
2245
        (ne:SI (reg:CC 17) (const_int 0)))]
2246
  ""
2247
  "mvfc %0, cbr"
2248
  [(set_attr "type" "misc")
2249
   (set_attr "length" "2")])
2250
 
2251
 
2252
;; Unconditional and other jump instructions.
2253
 
2254
(define_insn "jump"
2255
  [(set (pc) (label_ref (match_operand 0 "" "")))]
2256
  ""
2257
  "bra %l0"
2258
  [(set_attr "type" "uncond_branch")
2259
   (set (attr "length") (if_then_else (ltu (plus (minus (match_dup 0) (pc))
2260
                                                 (const_int 400))
2261
                                           (const_int 800))
2262
                                      (const_int 2)
2263
                                      (const_int 4)))])
2264
 
2265
(define_insn "indirect_jump"
2266
  [(set (pc) (match_operand:SI 0 "address_operand" "p"))]
2267
  ""
2268
  "jmp %a0"
2269
  [(set_attr "type" "uncond_branch")
2270
   (set_attr "length" "2")])
2271
 
2272
(define_insn "return"
2273
  [(return)]
2274
  "direct_return ()"
2275
  "jmp lr"
2276
  [(set_attr "type" "uncond_branch")
2277
   (set_attr "length" "2")])
2278
 
2279
(define_expand "tablejump"
2280
  [(parallel [(set (pc) (match_operand 0 "register_operand" "r"))
2281
              (use (label_ref (match_operand 1 "" "")))])]
2282
  ""
2283
  "
2284
{
2285
  /* In pic mode, our address differences are against the base of the
2286
     table.  Add that base value back in; CSE ought to be able to combine
2287
     the two address loads.  */
2288
  if (flag_pic)
2289
    {
2290
      rtx tmp, tmp2;
2291
 
2292
      tmp = gen_rtx_LABEL_REF (Pmode, operands[1]);
2293
      tmp2 = operands[0];
2294
      tmp = gen_rtx_PLUS (Pmode, tmp2, tmp);
2295
      operands[0] = memory_address (Pmode, tmp);
2296
    }
2297
}")
2298
 
2299
(define_insn "*tablejump_insn"
2300
  [(set (pc) (match_operand:SI 0 "address_operand" "p"))
2301
   (use (label_ref (match_operand 1 "" "")))]
2302
  ""
2303
  "jmp %a0"
2304
  [(set_attr "type" "uncond_branch")
2305
   (set_attr "length" "2")])
2306
 
2307
(define_expand "call"
2308
  ;; operands[1] is stack_size_rtx
2309
  ;; operands[2] is next_arg_register
2310
  [(parallel [(call (match_operand:SI 0 "call_operand" "")
2311
                    (match_operand 1 "" ""))
2312
             (clobber (reg:SI 14))])]
2313
  ""
2314
  "
2315
{
2316
  if (flag_pic)
2317
    current_function_uses_pic_offset_table = 1;
2318
}")
2319
 
2320
(define_insn "*call_via_reg"
2321
  [(call (mem:SI (match_operand:SI 0 "register_operand" "r"))
2322
         (match_operand 1 "" ""))
2323
   (clobber (reg:SI 14))]
2324
  ""
2325
  "jl %0"
2326
  [(set_attr "type" "call")
2327
   (set_attr "length" "2")])
2328
 
2329
(define_insn "*call_via_label"
2330
  [(call (mem:SI (match_operand:SI 0 "call_address_operand" ""))
2331
         (match_operand 1 "" ""))
2332
   (clobber (reg:SI 14))]
2333
  ""
2334
  "*
2335
{
2336
  int call26_p = call26_operand (operands[0], FUNCTION_MODE);
2337
 
2338
  if (! call26_p)
2339
    {
2340
      /* We may not be able to reach with a `bl' insn so punt and leave it to
2341
         the linker.
2342
         We do this here, rather than doing a force_reg in the define_expand
2343
         so these insns won't be separated, say by scheduling, thus simplifying
2344
         the linker.  */
2345
      return \"seth r14,%T0\;add3 r14,r14,%B0\;jl r14\";
2346
    }
2347
  else
2348
    return \"bl %0\";
2349
}"
2350
  [(set_attr "type" "call")
2351
   (set (attr "length")
2352
        (if_then_else (eq (symbol_ref "call26_operand (operands[0], FUNCTION_MODE)")
2353
                          (const_int 0))
2354
                      (const_int 12) ; 10 + 2 for nop filler
2355
                      ; The return address must be on a 4 byte boundary so
2356
                      ; there's no point in using a value of 2 here.  A 2 byte
2357
                      ; insn may go in the left slot but we currently can't
2358
                      ; use such knowledge.
2359
                      (const_int 4)))])
2360
 
2361
(define_expand "call_value"
2362
  ;; operand 2 is stack_size_rtx
2363
  ;; operand 3 is next_arg_register
2364
  [(parallel [(set (match_operand 0 "register_operand" "=r")
2365
                   (call (match_operand:SI 1 "call_operand" "")
2366
                         (match_operand 2 "" "")))
2367
             (clobber (reg:SI 14))])]
2368
  ""
2369
  "
2370
{
2371
  if (flag_pic)
2372
    current_function_uses_pic_offset_table = 1;
2373
}")
2374
 
2375
(define_insn "*call_value_via_reg"
2376
  [(set (match_operand 0 "register_operand" "=r")
2377
        (call (mem:SI (match_operand:SI 1 "register_operand" "r"))
2378
              (match_operand 2 "" "")))
2379
   (clobber (reg:SI 14))]
2380
  ""
2381
  "jl %1"
2382
  [(set_attr "type" "call")
2383
   (set_attr "length" "2")])
2384
 
2385
(define_insn "*call_value_via_label"
2386
  [(set (match_operand 0 "register_operand" "=r")
2387
        (call (mem:SI (match_operand:SI 1 "call_address_operand" ""))
2388
              (match_operand 2 "" "")))
2389
   (clobber (reg:SI 14))]
2390
  ""
2391
  "*
2392
{
2393
  int call26_p = call26_operand (operands[1], FUNCTION_MODE);
2394
 
2395
  if (flag_pic)
2396
    current_function_uses_pic_offset_table = 1;
2397
 
2398
  if (! call26_p)
2399
    {
2400
      /* We may not be able to reach with a `bl' insn so punt and leave it to
2401
         the linker.
2402
         We do this here, rather than doing a force_reg in the define_expand
2403
         so these insns won't be separated, say by scheduling, thus simplifying
2404
         the linker.  */
2405
      return \"seth r14,%T1\;add3 r14,r14,%B1\;jl r14\";
2406
    }
2407
  else
2408
    return \"bl %1\";
2409
}"
2410
  [(set_attr "type" "call")
2411
   (set (attr "length")
2412
        (if_then_else (eq (symbol_ref "call26_operand (operands[1], FUNCTION_MODE)")
2413
                          (const_int 0))
2414
                      (const_int 12) ; 10 + 2 for nop filler
2415
                      ; The return address must be on a 4 byte boundary so
2416
                      ; there's no point in using a value of 2 here.  A 2 byte
2417
                      ; insn may go in the left slot but we currently can't
2418
                      ; use such knowledge.
2419
                      (const_int 4)))])
2420
 
2421
(define_insn "nop"
2422
  [(const_int 0)]
2423
  ""
2424
  "nop"
2425
  [(set_attr "type" "int2")
2426
   (set_attr "length" "2")])
2427
 
2428
;; UNSPEC_VOLATILE is considered to use and clobber all hard registers and
2429
;; all of memory.  This blocks insns from being moved across this point.
2430
 
2431
(define_insn "blockage"
2432
  [(unspec_volatile [(const_int 0)] UNSPECV_BLOCKAGE)]
2433
  ""
2434
  "")
2435
 
2436
;; Special pattern to flush the icache.
2437
 
2438
(define_insn "flush_icache"
2439
  [(unspec_volatile [(match_operand 0 "memory_operand" "m")]
2440
                    UNSPECV_FLUSH_ICACHE)
2441
   (match_operand 1 "" "")
2442
   (clobber (reg:SI 17))]
2443
  ""
2444
  "* return \"trap %#%1 ; flush-icache\";"
2445
  [(set_attr "type" "int4")
2446
   (set_attr "length" "4")])
2447
 
2448
;; Speed up fabs and provide correct sign handling for -0
2449
 
2450
(define_insn "absdf2"
2451
  [(set (match_operand:DF 0 "register_operand" "=r")
2452
        (abs:DF (match_operand:DF 1 "register_operand" "0")))]
2453
  ""
2454
  "#"
2455
  [(set_attr "type" "multi")
2456
   (set_attr "length" "4")])
2457
 
2458
(define_split
2459
  [(set (match_operand:DF 0 "register_operand" "")
2460
        (abs:DF (match_operand:DF 1 "register_operand" "")))]
2461
  "reload_completed"
2462
  [(set (match_dup 2)
2463
        (ashift:SI (match_dup 2)
2464
                   (const_int 1)))
2465
   (set (match_dup 2)
2466
        (lshiftrt:SI (match_dup 2)
2467
                     (const_int 1)))]
2468
  "operands[2] = gen_highpart (SImode, operands[0]);")
2469
 
2470
(define_insn "abssf2"
2471
  [(set (match_operand:SF 0 "register_operand" "=r")
2472
        (abs:SF (match_operand:SF 1 "register_operand" "0")))]
2473
  ""
2474
  "#"
2475
  [(set_attr "type" "multi")
2476
   (set_attr "length" "4")])
2477
 
2478
(define_split
2479
  [(set (match_operand:SF 0 "register_operand" "")
2480
        (abs:SF (match_operand:SF 1 "register_operand" "")))]
2481
  "reload_completed"
2482
  [(set (match_dup 2)
2483
        (ashift:SI (match_dup 2)
2484
                   (const_int 1)))
2485
   (set (match_dup 2)
2486
        (lshiftrt:SI (match_dup 2)
2487
                     (const_int 1)))]
2488
  "operands[2] = gen_highpart (SImode, operands[0]);")
2489
 
2490
;; Conditional move instructions
2491
;; Based on those done for the d10v
2492
 
2493
(define_expand "movsicc"
2494
  [
2495
   (set (match_operand:SI 0 "register_operand" "r")
2496
        (if_then_else:SI (match_operand 1 "" "")
2497
                         (match_operand:SI 2 "conditional_move_operand" "O")
2498
                         (match_operand:SI 3 "conditional_move_operand" "O")
2499
        )
2500
   )
2501
  ]
2502
  ""
2503
  "
2504
{
2505
  if (! zero_and_one (operands [2], operands [3]))
2506
    FAIL;
2507
 
2508
  /* Generate the comparison that will set the carry flag.  */
2509
  operands[1] = gen_compare (GET_CODE (operands[1]), m32r_compare_op0,
2510
                             m32r_compare_op1, TRUE);
2511
 
2512
  /* See other movsicc pattern below for reason why.  */
2513
  emit_insn (gen_blockage ());
2514
}")
2515
 
2516
;; Generate the conditional instructions based on how the carry flag is examined.
2517
(define_insn "*movsicc_internal"
2518
  [(set (match_operand:SI 0 "register_operand" "=r")
2519
        (if_then_else:SI (match_operand 1 "carry_compare_operand" "")
2520
                         (match_operand:SI 2 "conditional_move_operand" "O")
2521
                         (match_operand:SI 3 "conditional_move_operand" "O")
2522
        )
2523
   )]
2524
  "zero_and_one (operands [2], operands[3])"
2525
  "* return emit_cond_move (operands, insn);"
2526
  [(set_attr "type" "multi")
2527
   (set_attr "length" "8")
2528
  ]
2529
)
2530
 
2531
 
2532
;; Block moves, see m32r.c for more details.
2533
;; Argument 0 is the destination
2534
;; Argument 1 is the source
2535
;; Argument 2 is the length
2536
;; Argument 3 is the alignment
2537
 
2538
(define_expand "movmemsi"
2539
  [(parallel [(set (match_operand:BLK 0 "general_operand" "")
2540
                   (match_operand:BLK 1 "general_operand" ""))
2541
              (use (match_operand:SI  2 "immediate_operand" ""))
2542
              (use (match_operand:SI  3 "immediate_operand" ""))])]
2543
  ""
2544
  "
2545
{
2546
  if (operands[0])              /* Avoid unused code messages.  */
2547
    {
2548
     if (m32r_expand_block_move (operands))
2549
       DONE;
2550
     else
2551
       FAIL;
2552
    }
2553
}")
2554
 
2555
;; Insn generated by block moves
2556
 
2557
(define_insn "movmemsi_internal"
2558
  [(set (mem:BLK (match_operand:SI 0 "register_operand" "r"))   ;; destination
2559
        (mem:BLK (match_operand:SI 1 "register_operand" "r")))  ;; source
2560
   (use (match_operand:SI 2 "m32r_block_immediate_operand" "J"));; # bytes to move
2561
   (set (match_operand:SI 3 "register_operand" "=0")
2562
        (plus:SI (minus (match_dup 2) (const_int 4))
2563
                 (match_dup 0)))
2564
   (set (match_operand:SI 4 "register_operand" "=1")
2565
        (plus:SI (match_dup 1)
2566
                 (match_dup 2)))
2567
   (clobber (match_scratch:SI 5 "=&r"))  ;; temp1
2568
   (clobber (match_scratch:SI 6 "=&r"))] ;; temp2
2569
  ""
2570
  "* m32r_output_block_move (insn, operands); return \"\"; "
2571
  [(set_attr "type"     "store8")
2572
   (set_attr "length"   "72")]) ;; Maximum
2573
 
2574
;; PIC
2575
 
2576
/* When generating pic, we need to load the symbol offset into a register.
2577
   So that the optimizer does not confuse this with a normal symbol load
2578
   we use an unspec.  The offset will be loaded from a constant pool entry,
2579
   since that is the only type of relocation we can use.  */
2580
 
2581
(define_insn "pic_load_addr"
2582
  [(set (match_operand:SI 0 "register_operand" "=r")
2583
        (unspec:SI [(match_operand 1 "" "")] UNSPEC_PIC_LOAD_ADDR))]
2584
  "flag_pic"
2585
  "ld24 %0,%#%1"
2586
  [(set_attr "type" "int4")])
2587
 
2588
(define_insn "gotoff_load_addr"
2589
  [(set (match_operand:SI 0 "register_operand" "=r")
2590
        (unspec:SI [(match_operand 1 "" "")] UNSPEC_GOTOFF))]
2591
  "flag_pic"
2592
  "seth %0, %#shigh(%1@GOTOFF)\;add3 %0, %0, low(%1@GOTOFF)"
2593
  [(set_attr "type"     "int4")
2594
   (set_attr "length"   "8")])
2595
 
2596
;; Load program counter insns.
2597
 
2598
(define_insn "get_pc"
2599
  [(clobber (reg:SI 14))
2600
   (set (match_operand 0 "register_operand" "=r")
2601
        (unspec [(match_operand 1 "" "")] UNSPEC_GET_PC))
2602
   (use (match_operand:SI 2 "immediate_operand" ""))]
2603
  "flag_pic"
2604
  "*
2605
{
2606
  if (INTVAL(operands[2]))
2607
    return \"bl.s .+4\;ld24 %0,%#%1\;add %0,lr\";
2608
  else
2609
    return \"bl.s .+4\;seth %0,%#shigh(%1)\;add3 %0,%0,%#low(%1+4)\;add %0,lr\";}"
2610
  [(set (attr "length") (if_then_else (ne (match_dup 2) (const_int 0))
2611
                                      (const_int 8)
2612
                                      (const_int 12)))])
2613
 
2614
(define_expand "builtin_setjmp_receiver"
2615
  [(label_ref (match_operand 0 "" ""))]
2616
  "flag_pic"
2617
  "
2618
{
2619
  m32r_load_pic_register ();
2620
  DONE;
2621
}")

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.