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

Subversion Repositories openrisc

[/] [openrisc/] [trunk/] [gnu-old/] [gcc-4.2.2/] [gcc/] [config/] [rs6000/] [predicates.md] - Blame information for rev 816

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 38 julius
;; Predicate definitions for POWER and PowerPC.
2
;; Copyright (C) 2005, 2006, 2007 Free Software Foundation, Inc.
3
;;
4
;; This file is part of GCC.
5
;;
6
;; GCC is free software; you can redistribute it and/or modify
7
;; it under the terms of the GNU General Public License as published by
8
;; the Free Software Foundation; either version 3, or (at your option)
9
;; any later version.
10
;;
11
;; GCC is distributed in the hope that it will be useful,
12
;; but WITHOUT ANY WARRANTY; without even the implied warranty of
13
;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14
;; GNU General Public License for more details.
15
;;
16
;; You should have received a copy of the GNU General Public License
17
;; along with GCC; see the file COPYING3.  If not see
18
;; .
19
 
20
;; Return 1 for anything except PARALLEL.
21
(define_predicate "any_operand"
22
  (match_code "const_int,const_double,const,symbol_ref,label_ref,subreg,reg,mem"))
23
 
24
;; Return 1 for any PARALLEL.
25
(define_predicate "any_parallel_operand"
26
  (match_code "parallel"))
27
 
28
;; Return 1 if op is COUNT register.
29
(define_predicate "count_register_operand"
30
  (and (match_code "reg")
31
       (match_test "REGNO (op) == COUNT_REGISTER_REGNUM
32
                    || REGNO (op) > LAST_VIRTUAL_REGISTER")))
33
 
34
;; Return 1 if op is an Altivec register.
35
(define_predicate "altivec_register_operand"
36
   (and (match_operand 0 "register_operand")
37
        (match_test "GET_CODE (op) != REG
38
                     || ALTIVEC_REGNO_P (REGNO (op))
39
                     || REGNO (op) > LAST_VIRTUAL_REGISTER")))
40
 
41
;; Return 1 if op is XER register.
42
(define_predicate "xer_operand"
43
  (and (match_code "reg")
44
       (match_test "XER_REGNO_P (REGNO (op))")))
45
 
46
;; Return 1 if op is a signed 5-bit constant integer.
47
(define_predicate "s5bit_cint_operand"
48
  (and (match_code "const_int")
49
       (match_test "INTVAL (op) >= -16 && INTVAL (op) <= 15")))
50
 
51
;; Return 1 if op is a unsigned 5-bit constant integer.
52
(define_predicate "u5bit_cint_operand"
53
  (and (match_code "const_int")
54
       (match_test "INTVAL (op) >= 0 && INTVAL (op) <= 31")))
55
 
56
;; Return 1 if op is a signed 8-bit constant integer.
57
;; Integer multiplication complete more quickly
58
(define_predicate "s8bit_cint_operand"
59
  (and (match_code "const_int")
60
       (match_test "INTVAL (op) >= -128 && INTVAL (op) <= 127")))
61
 
62
;; Return 1 if op is a constant integer that can fit in a D field.
63
(define_predicate "short_cint_operand"
64
  (and (match_code "const_int")
65
       (match_test "satisfies_constraint_I (op)")))
66
 
67
;; Return 1 if op is a constant integer that can fit in an unsigned D field.
68
(define_predicate "u_short_cint_operand"
69
  (and (match_code "const_int")
70
       (match_test "satisfies_constraint_K (op)")))
71
 
72
;; Return 1 if op is a constant integer that cannot fit in a signed D field.
73
(define_predicate "non_short_cint_operand"
74
  (and (match_code "const_int")
75
       (match_test "(unsigned HOST_WIDE_INT)
76
                    (INTVAL (op) + 0x8000) >= 0x10000")))
77
 
78
;; Return 1 if op is a positive constant integer that is an exact power of 2.
79
(define_predicate "exact_log2_cint_operand"
80
  (and (match_code "const_int")
81
       (match_test "INTVAL (op) > 0 && exact_log2 (INTVAL (op)) >= 0")))
82
 
83
;; Return 1 if op is a register that is not special.
84
(define_predicate "gpc_reg_operand"
85
   (and (match_operand 0 "register_operand")
86
        (match_test "(GET_CODE (op) != REG
87
                      || (REGNO (op) >= ARG_POINTER_REGNUM
88
                          && !XER_REGNO_P (REGNO (op)))
89
                      || REGNO (op) < MQ_REGNO)
90
                     && !((TARGET_E500_DOUBLE || TARGET_SPE)
91
                          && invalid_e500_subreg (op, mode))")))
92
 
93
;; Return 1 if op is a register that is a condition register field.
94
(define_predicate "cc_reg_operand"
95
   (and (match_operand 0 "register_operand")
96
        (match_test "GET_CODE (op) != REG
97
                     || REGNO (op) > LAST_VIRTUAL_REGISTER
98
                     || CR_REGNO_P (REGNO (op))")))
99
 
100
;; Return 1 if op is a register that is a condition register field not cr0.
101
(define_predicate "cc_reg_not_cr0_operand"
102
   (and (match_operand 0 "register_operand")
103
        (match_test "GET_CODE (op) != REG
104
                     || REGNO (op) > LAST_VIRTUAL_REGISTER
105
                     || CR_REGNO_NOT_CR0_P (REGNO (op))")))
106
 
107
;; Return 1 if op is a constant integer valid for D field
108
;; or non-special register register.
109
(define_predicate "reg_or_short_operand"
110
  (if_then_else (match_code "const_int")
111
    (match_operand 0 "short_cint_operand")
112
    (match_operand 0 "gpc_reg_operand")))
113
 
114
;; Return 1 if op is a constant integer valid whose negation is valid for
115
;; D field or non-special register register.
116
;; Do not allow a constant zero because all patterns that call this
117
;; predicate use "addic r1,r2,-const" to set carry when r2 is greater than
118
;; or equal to const, which does not work for zero.
119
(define_predicate "reg_or_neg_short_operand"
120
  (if_then_else (match_code "const_int")
121
    (match_test "satisfies_constraint_P (op)
122
                 && INTVAL (op) != 0")
123
    (match_operand 0 "gpc_reg_operand")))
124
 
125
;; Return 1 if op is a constant integer valid for DS field
126
;; or non-special register.
127
(define_predicate "reg_or_aligned_short_operand"
128
  (if_then_else (match_code "const_int")
129
    (and (match_operand 0 "short_cint_operand")
130
         (match_test "!(INTVAL (op) & 3)"))
131
    (match_operand 0 "gpc_reg_operand")))
132
 
133
;; Return 1 if op is a constant integer whose high-order 16 bits are zero
134
;; or non-special register.
135
(define_predicate "reg_or_u_short_operand"
136
  (if_then_else (match_code "const_int")
137
    (match_operand 0 "u_short_cint_operand")
138
    (match_operand 0 "gpc_reg_operand")))
139
 
140
;; Return 1 if op is any constant integer
141
;; or non-special register.
142
(define_predicate "reg_or_cint_operand"
143
  (ior (match_code "const_int")
144
       (match_operand 0 "gpc_reg_operand")))
145
 
146
;; Return 1 if op is a constant integer valid for addition
147
;; or non-special register.
148
(define_predicate "reg_or_add_cint_operand"
149
  (if_then_else (match_code "const_int")
150
    (match_test "(HOST_BITS_PER_WIDE_INT == 32
151
                  && (mode == SImode || INTVAL (op) < 0x7fff8000))
152
                 || ((unsigned HOST_WIDE_INT) (INTVAL (op) + 0x80008000)
153
                     < (unsigned HOST_WIDE_INT) 0x100000000ll)")
154
    (match_operand 0 "gpc_reg_operand")))
155
 
156
;; Return 1 if op is a constant integer valid for subtraction
157
;; or non-special register.
158
(define_predicate "reg_or_sub_cint_operand"
159
  (if_then_else (match_code "const_int")
160
    (match_test "(HOST_BITS_PER_WIDE_INT == 32
161
                  && (mode == SImode || - INTVAL (op) < 0x7fff8000))
162
                 || ((unsigned HOST_WIDE_INT) (- INTVAL (op)
163
                                               + (mode == SImode
164
                                                  ? 0x80000000 : 0x80008000))
165
                     < (unsigned HOST_WIDE_INT) 0x100000000ll)")
166
    (match_operand 0 "gpc_reg_operand")))
167
 
168
;; Return 1 if op is any 32-bit unsigned constant integer
169
;; or non-special register.
170
(define_predicate "reg_or_logical_cint_operand"
171
  (if_then_else (match_code "const_int")
172
    (match_test "(GET_MODE_BITSIZE (mode) > HOST_BITS_PER_WIDE_INT
173
                  && INTVAL (op) >= 0)
174
                 || ((INTVAL (op) & GET_MODE_MASK (mode)
175
                      & (~ (unsigned HOST_WIDE_INT) 0xffffffff)) == 0)")
176
    (if_then_else (match_code "const_double")
177
      (match_test "GET_MODE_BITSIZE (mode) > HOST_BITS_PER_WIDE_INT
178
                   && mode == DImode
179
                   && CONST_DOUBLE_HIGH (op) == 0")
180
      (match_operand 0 "gpc_reg_operand"))))
181
 
182
;; Return 1 if operand is a CONST_DOUBLE that can be set in a register
183
;; with no more than one instruction per word.
184
(define_predicate "easy_fp_constant"
185
  (match_code "const_double")
186
{
187
  long k[4];
188
  REAL_VALUE_TYPE rv;
189
 
190
  if (GET_MODE (op) != mode
191
      || (!SCALAR_FLOAT_MODE_P (mode) && mode != DImode))
192
    return 0;
193
 
194
  /* Consider all constants with -msoft-float to be easy.  */
195
  if ((TARGET_SOFT_FLOAT || TARGET_E500_SINGLE)
196
      && mode != DImode)
197
    return 1;
198
 
199
  if (DECIMAL_FLOAT_MODE_P (mode))
200
    return 0;
201
 
202
  /* If we are using V.4 style PIC, consider all constants to be hard.  */
203
  if (flag_pic && DEFAULT_ABI == ABI_V4)
204
    return 0;
205
 
206
#ifdef TARGET_RELOCATABLE
207
  /* Similarly if we are using -mrelocatable, consider all constants
208
     to be hard.  */
209
  if (TARGET_RELOCATABLE)
210
    return 0;
211
#endif
212
 
213
  switch (mode)
214
    {
215
    case TFmode:
216
      REAL_VALUE_FROM_CONST_DOUBLE (rv, op);
217
      REAL_VALUE_TO_TARGET_LONG_DOUBLE (rv, k);
218
 
219
      return (num_insns_constant_wide ((HOST_WIDE_INT) k[0]) == 1
220
              && num_insns_constant_wide ((HOST_WIDE_INT) k[1]) == 1
221
              && num_insns_constant_wide ((HOST_WIDE_INT) k[2]) == 1
222
              && num_insns_constant_wide ((HOST_WIDE_INT) k[3]) == 1);
223
 
224
    case DFmode:
225
      /* Force constants to memory before reload to utilize
226
         compress_float_constant.
227
         Avoid this when flag_unsafe_math_optimizations is enabled
228
         because RDIV division to reciprocal optimization is not able
229
         to regenerate the division.  */
230
      if (TARGET_E500_DOUBLE
231
          || (!reload_in_progress && !reload_completed
232
              && !flag_unsafe_math_optimizations))
233
        return 0;
234
 
235
      REAL_VALUE_FROM_CONST_DOUBLE (rv, op);
236
      REAL_VALUE_TO_TARGET_DOUBLE (rv, k);
237
 
238
      return (num_insns_constant_wide ((HOST_WIDE_INT) k[0]) == 1
239
              && num_insns_constant_wide ((HOST_WIDE_INT) k[1]) == 1);
240
 
241
    case SFmode:
242
      /* The constant 0.f is easy.  */
243
      if (op == CONST0_RTX (SFmode))
244
        return 1;
245
 
246
      /* Force constants to memory before reload to utilize
247
         compress_float_constant.
248
         Avoid this when flag_unsafe_math_optimizations is enabled
249
         because RDIV division to reciprocal optimization is not able
250
         to regenerate the division.  */
251
      if (!reload_in_progress && !reload_completed
252
          && !flag_unsafe_math_optimizations)
253
        return 0;
254
 
255
      REAL_VALUE_FROM_CONST_DOUBLE (rv, op);
256
      REAL_VALUE_TO_TARGET_SINGLE (rv, k[0]);
257
 
258
      return num_insns_constant_wide (k[0]) == 1;
259
 
260
  case DImode:
261
    return ((TARGET_POWERPC64
262
             && GET_CODE (op) == CONST_DOUBLE && CONST_DOUBLE_LOW (op) == 0)
263
            || (num_insns_constant (op, DImode) <= 2));
264
 
265
  case SImode:
266
    return 1;
267
 
268
  default:
269
    gcc_unreachable ();
270
  }
271
})
272
 
273
;; Return 1 if the operand is a CONST_VECTOR and can be loaded into a
274
;; vector register without using memory.
275
(define_predicate "easy_vector_constant"
276
  (match_code "const_vector")
277
{
278
  if (ALTIVEC_VECTOR_MODE (mode))
279
    {
280
      if (zero_constant (op, mode))
281
        return true;
282
      return easy_altivec_constant (op, mode);
283
    }
284
 
285
  if (SPE_VECTOR_MODE (mode))
286
    {
287
      int cst, cst2;
288
      if (zero_constant (op, mode))
289
        return true;
290
      if (GET_MODE_CLASS (mode) != MODE_VECTOR_INT)
291
        return false;
292
 
293
      /* Limit SPE vectors to 15 bits signed.  These we can generate with:
294
           li r0, CONSTANT1
295
           evmergelo r0, r0, r0
296
           li r0, CONSTANT2
297
 
298
         I don't know how efficient it would be to allow bigger constants,
299
         considering we'll have an extra 'ori' for every 'li'.  I doubt 5
300
         instructions is better than a 64-bit memory load, but I don't
301
         have the e500 timing specs.  */
302
      if (mode == V2SImode)
303
        {
304
          cst  = INTVAL (CONST_VECTOR_ELT (op, 0));
305
          cst2 = INTVAL (CONST_VECTOR_ELT (op, 1));
306
          return cst  >= -0x7fff && cst <= 0x7fff
307
                 && cst2 >= -0x7fff && cst2 <= 0x7fff;
308
        }
309
    }
310
 
311
  return false;
312
})
313
 
314
;; Same as easy_vector_constant but only for EASY_VECTOR_15_ADD_SELF.
315
(define_predicate "easy_vector_constant_add_self"
316
  (and (match_code "const_vector")
317
       (and (match_test "TARGET_ALTIVEC")
318
            (match_test "easy_altivec_constant (op, mode)")))
319
{
320
  rtx last = CONST_VECTOR_ELT (op, GET_MODE_NUNITS (mode) - 1);
321
  HOST_WIDE_INT val = ((INTVAL (last) & 0xff) ^ 0x80) - 0x80;
322
  return EASY_VECTOR_15_ADD_SELF (val);
323
})
324
 
325
;; Return 1 if operand is constant zero (scalars and vectors).
326
(define_predicate "zero_constant"
327
  (and (match_code "const_int,const_double,const_vector")
328
       (match_test "op == CONST0_RTX (mode)")))
329
 
330
;; Return 1 if operand is 0.0.
331
;; or non-special register register field no cr0
332
(define_predicate "zero_fp_constant"
333
  (and (match_code "const_double")
334
       (match_test "SCALAR_FLOAT_MODE_P (mode)
335
                    && op == CONST0_RTX (mode)")))
336
 
337
;; Return 1 if the operand is in volatile memory.  Note that during the
338
;; RTL generation phase, memory_operand does not return TRUE for volatile
339
;; memory references.  So this function allows us to recognize volatile
340
;; references where it's safe.
341
(define_predicate "volatile_mem_operand"
342
  (and (and (match_code "mem")
343
            (match_test "MEM_VOLATILE_P (op)"))
344
       (if_then_else (match_test "reload_completed")
345
         (match_operand 0 "memory_operand")
346
         (if_then_else (match_test "reload_in_progress")
347
           (match_test "strict_memory_address_p (mode, XEXP (op, 0))")
348
           (match_test "memory_address_p (mode, XEXP (op, 0))")))))
349
 
350
;; Return 1 if the operand is an offsettable memory operand.
351
(define_predicate "offsettable_mem_operand"
352
  (and (match_code "mem")
353
       (match_test "offsettable_address_p (reload_completed
354
                                           || reload_in_progress,
355
                                           mode, XEXP (op, 0))")))
356
 
357
;; Return 1 if the operand is a memory operand with an address divisible by 4
358
(define_predicate "word_offset_memref_operand"
359
  (and (match_operand 0 "memory_operand")
360
       (match_test "GET_CODE (XEXP (op, 0)) != PLUS
361
                    || ! REG_P (XEXP (XEXP (op, 0), 0))
362
                    || GET_CODE (XEXP (XEXP (op, 0), 1)) != CONST_INT
363
                    || INTVAL (XEXP (XEXP (op, 0), 1)) % 4 == 0")))
364
 
365
;; Return 1 if the operand is an indexed or indirect memory operand.
366
(define_predicate "indexed_or_indirect_operand"
367
  (match_code "mem")
368
{
369
  op = XEXP (op, 0);
370
  if (TARGET_ALTIVEC
371
      && ALTIVEC_VECTOR_MODE (mode)
372
      && GET_CODE (op) == AND
373
      && GET_CODE (XEXP (op, 1)) == CONST_INT
374
      && INTVAL (XEXP (op, 1)) == -16)
375
    op = XEXP (op, 0);
376
 
377
  return indexed_or_indirect_address (op, mode);
378
})
379
 
380
;; Return 1 if the operand is an indexed or indirect address.
381
(define_special_predicate "indexed_or_indirect_address"
382
  (and (match_test "REG_P (op)
383
                    || (GET_CODE (op) == PLUS
384
                        /* Omit testing REG_P (XEXP (op, 0)).  */
385
                        && REG_P (XEXP (op, 1)))")
386
       (match_operand 0 "address_operand")))
387
 
388
;; Used for the destination of the fix_truncdfsi2 expander.
389
;; If stfiwx will be used, the result goes to memory; otherwise,
390
;; we're going to emit a store and a load of a subreg, so the dest is a
391
;; register.
392
(define_predicate "fix_trunc_dest_operand"
393
  (if_then_else (match_test "! TARGET_E500_DOUBLE && TARGET_PPC_GFXOPT")
394
   (match_operand 0 "memory_operand")
395
   (match_operand 0 "gpc_reg_operand")))
396
 
397
;; Return 1 if the operand is either a non-special register or can be used
398
;; as the operand of a `mode' add insn.
399
(define_predicate "add_operand"
400
  (if_then_else (match_code "const_int")
401
    (match_test "satisfies_constraint_I (op)
402
                 || satisfies_constraint_L (op)")
403
    (match_operand 0 "gpc_reg_operand")))
404
 
405
;; Return 1 if OP is a constant but not a valid add_operand.
406
(define_predicate "non_add_cint_operand"
407
  (and (match_code "const_int")
408
       (match_test "!satisfies_constraint_I (op)
409
                    && !satisfies_constraint_L (op)")))
410
 
411
;; Return 1 if the operand is a constant that can be used as the operand
412
;; of an OR or XOR.
413
(define_predicate "logical_const_operand"
414
  (match_code "const_int,const_double")
415
{
416
  HOST_WIDE_INT opl, oph;
417
 
418
  if (GET_CODE (op) == CONST_INT)
419
    {
420
      opl = INTVAL (op) & GET_MODE_MASK (mode);
421
 
422
      if (HOST_BITS_PER_WIDE_INT <= 32
423
          && GET_MODE_BITSIZE (mode) > HOST_BITS_PER_WIDE_INT && opl < 0)
424
        return 0;
425
    }
426
  else if (GET_CODE (op) == CONST_DOUBLE)
427
    {
428
      gcc_assert (GET_MODE_BITSIZE (mode) > HOST_BITS_PER_WIDE_INT);
429
 
430
      opl = CONST_DOUBLE_LOW (op);
431
      oph = CONST_DOUBLE_HIGH (op);
432
      if (oph != 0)
433
        return 0;
434
    }
435
  else
436
    return 0;
437
 
438
  return ((opl & ~ (unsigned HOST_WIDE_INT) 0xffff) == 0
439
          || (opl & ~ (unsigned HOST_WIDE_INT) 0xffff0000) == 0);
440
})
441
 
442
;; Return 1 if the operand is a non-special register or a constant that
443
;; can be used as the operand of an OR or XOR.
444
(define_predicate "logical_operand"
445
  (ior (match_operand 0 "gpc_reg_operand")
446
       (match_operand 0 "logical_const_operand")))
447
 
448
;; Return 1 if op is a constant that is not a logical operand, but could
449
;; be split into one.
450
(define_predicate "non_logical_cint_operand"
451
  (and (match_code "const_int,const_double")
452
       (and (not (match_operand 0 "logical_operand"))
453
            (match_operand 0 "reg_or_logical_cint_operand"))))
454
 
455
;; Return 1 if op is a constant that can be encoded in a 32-bit mask,
456
;; suitable for use with rlwinm (no more than two 1->0 or 0->1
457
;; transitions).  Reject all ones and all zeros, since these should have
458
;; been optimized away and confuse the making of MB and ME.
459
(define_predicate "mask_operand"
460
  (match_code "const_int")
461
{
462
  HOST_WIDE_INT c, lsb;
463
 
464
  c = INTVAL (op);
465
 
466
  if (TARGET_POWERPC64)
467
    {
468
      /* Fail if the mask is not 32-bit.  */
469
      if (mode == DImode && (c & ~(unsigned HOST_WIDE_INT) 0xffffffff) != 0)
470
        return 0;
471
 
472
      /* Fail if the mask wraps around because the upper 32-bits of the
473
         mask will all be 1s, contrary to GCC's internal view.  */
474
      if ((c & 0x80000001) == 0x80000001)
475
        return 0;
476
    }
477
 
478
  /* We don't change the number of transitions by inverting,
479
     so make sure we start with the LS bit zero.  */
480
  if (c & 1)
481
    c = ~c;
482
 
483
  /* Reject all zeros or all ones.  */
484
  if (c == 0)
485
    return 0;
486
 
487
  /* Find the first transition.  */
488
  lsb = c & -c;
489
 
490
  /* Invert to look for a second transition.  */
491
  c = ~c;
492
 
493
  /* Erase first transition.  */
494
  c &= -lsb;
495
 
496
  /* Find the second transition (if any).  */
497
  lsb = c & -c;
498
 
499
  /* Match if all the bits above are 1's (or c is zero).  */
500
  return c == -lsb;
501
})
502
 
503
;; Return 1 for the PowerPC64 rlwinm corner case.
504
(define_predicate "mask_operand_wrap"
505
  (match_code "const_int")
506
{
507
  HOST_WIDE_INT c, lsb;
508
 
509
  c = INTVAL (op);
510
 
511
  if ((c & 0x80000001) != 0x80000001)
512
    return 0;
513
 
514
  c = ~c;
515
  if (c == 0)
516
    return 0;
517
 
518
  lsb = c & -c;
519
  c = ~c;
520
  c &= -lsb;
521
  lsb = c & -c;
522
  return c == -lsb;
523
})
524
 
525
;; Return 1 if the operand is a constant that is a PowerPC64 mask
526
;; suitable for use with rldicl or rldicr (no more than one 1->0 or 0->1
527
;; transition).  Reject all zeros, since zero should have been
528
;; optimized away and confuses the making of MB and ME.
529
(define_predicate "mask64_operand"
530
  (match_code "const_int")
531
{
532
  HOST_WIDE_INT c, lsb;
533
 
534
  c = INTVAL (op);
535
 
536
  /* Reject all zeros.  */
537
  if (c == 0)
538
    return 0;
539
 
540
  /* We don't change the number of transitions by inverting,
541
     so make sure we start with the LS bit zero.  */
542
  if (c & 1)
543
    c = ~c;
544
 
545
  /* Find the first transition.  */
546
  lsb = c & -c;
547
 
548
  /* Match if all the bits above are 1's (or c is zero).  */
549
  return c == -lsb;
550
})
551
 
552
;; Like mask64_operand, but allow up to three transitions.  This
553
;; predicate is used by insn patterns that generate two rldicl or
554
;; rldicr machine insns.
555
(define_predicate "mask64_2_operand"
556
  (match_code "const_int")
557
{
558
  HOST_WIDE_INT c, lsb;
559
 
560
  c = INTVAL (op);
561
 
562
  /* Disallow all zeros.  */
563
  if (c == 0)
564
    return 0;
565
 
566
  /* We don't change the number of transitions by inverting,
567
     so make sure we start with the LS bit zero.  */
568
  if (c & 1)
569
    c = ~c;
570
 
571
  /* Find the first transition.  */
572
  lsb = c & -c;
573
 
574
  /* Invert to look for a second transition.  */
575
  c = ~c;
576
 
577
  /* Erase first transition.  */
578
  c &= -lsb;
579
 
580
  /* Find the second transition.  */
581
  lsb = c & -c;
582
 
583
  /* Invert to look for a third transition.  */
584
  c = ~c;
585
 
586
  /* Erase second transition.  */
587
  c &= -lsb;
588
 
589
  /* Find the third transition (if any).  */
590
  lsb = c & -c;
591
 
592
  /* Match if all the bits above are 1's (or c is zero).  */
593
  return c == -lsb;
594
})
595
 
596
;; Like and_operand, but also match constants that can be implemented
597
;; with two rldicl or rldicr insns.
598
(define_predicate "and64_2_operand"
599
  (ior (match_operand 0 "mask64_2_operand")
600
       (if_then_else (match_test "fixed_regs[CR0_REGNO]")
601
         (match_operand 0 "gpc_reg_operand")
602
         (match_operand 0 "logical_operand"))))
603
 
604
;; Return 1 if the operand is either a non-special register or a
605
;; constant that can be used as the operand of a logical AND.
606
(define_predicate "and_operand"
607
  (ior (match_operand 0 "mask_operand")
608
       (ior (and (match_test "TARGET_POWERPC64 && mode == DImode")
609
                 (match_operand 0 "mask64_operand"))
610
            (if_then_else (match_test "fixed_regs[CR0_REGNO]")
611
              (match_operand 0 "gpc_reg_operand")
612
              (match_operand 0 "logical_operand")))))
613
 
614
;; Return 1 if the operand is either a logical operand or a short cint operand.
615
(define_predicate "scc_eq_operand"
616
  (ior (match_operand 0 "logical_operand")
617
       (match_operand 0 "short_cint_operand")))
618
 
619
;; Return 1 if the operand is a general non-special register or memory operand.
620
(define_predicate "reg_or_mem_operand"
621
     (ior (match_operand 0 "memory_operand")
622
          (ior (and (match_code "mem")
623
                    (match_test "macho_lo_sum_memory_operand (op, mode)"))
624
               (ior (match_operand 0 "volatile_mem_operand")
625
                    (match_operand 0 "gpc_reg_operand")))))
626
 
627
;; Return 1 if the operand is either an easy FP constant or memory or reg.
628
(define_predicate "reg_or_none500mem_operand"
629
  (if_then_else (match_code "mem")
630
     (and (match_test "!TARGET_E500_DOUBLE")
631
          (ior (match_operand 0 "memory_operand")
632
               (ior (match_test "macho_lo_sum_memory_operand (op, mode)")
633
                    (match_operand 0 "volatile_mem_operand"))))
634
     (match_operand 0 "gpc_reg_operand")))
635
 
636
;; Return 1 if the operand is CONST_DOUBLE 0, register or memory operand.
637
(define_predicate "zero_reg_mem_operand"
638
  (ior (match_operand 0 "zero_fp_constant")
639
       (match_operand 0 "reg_or_mem_operand")))
640
 
641
;; Return 1 if the operand is a general register or memory operand without
642
;; pre_inc or pre_dec, which produces invalid form of PowerPC lwa
643
;; instruction.
644
(define_predicate "lwa_operand"
645
  (match_code "reg,subreg,mem")
646
{
647
  rtx inner = op;
648
 
649
  if (reload_completed && GET_CODE (inner) == SUBREG)
650
    inner = SUBREG_REG (inner);
651
 
652
  return gpc_reg_operand (inner, mode)
653
    || (memory_operand (inner, mode)
654
        && GET_CODE (XEXP (inner, 0)) != PRE_INC
655
        && GET_CODE (XEXP (inner, 0)) != PRE_DEC
656
        && (GET_CODE (XEXP (inner, 0)) != PLUS
657
            || GET_CODE (XEXP (XEXP (inner, 0), 1)) != CONST_INT
658
            || INTVAL (XEXP (XEXP (inner, 0), 1)) % 4 == 0));
659
})
660
 
661
;; Return 1 if the operand, used inside a MEM, is a SYMBOL_REF.
662
(define_predicate "symbol_ref_operand"
663
  (and (match_code "symbol_ref")
664
       (match_test "(mode == VOIDmode || GET_MODE (op) == mode)
665
                    && (DEFAULT_ABI != ABI_AIX || SYMBOL_REF_FUNCTION_P (op))")))
666
 
667
;; Return 1 if op is an operand that can be loaded via the GOT.
668
;; or non-special register register field no cr0
669
(define_predicate "got_operand"
670
  (match_code "symbol_ref,const,label_ref"))
671
 
672
;; Return 1 if op is a simple reference that can be loaded via the GOT,
673
;; excluding labels involving addition.
674
(define_predicate "got_no_const_operand"
675
  (match_code "symbol_ref,label_ref"))
676
 
677
;; Return 1 if op is a SYMBOL_REF for a TLS symbol.
678
(define_predicate "rs6000_tls_symbol_ref"
679
  (and (match_code "symbol_ref")
680
       (match_test "RS6000_SYMBOL_REF_TLS_P (op)")))
681
 
682
;; Return 1 if the operand, used inside a MEM, is a valid first argument
683
;; to CALL.  This is a SYMBOL_REF, a pseudo-register, LR or CTR.
684
(define_predicate "call_operand"
685
  (if_then_else (match_code "reg")
686
     (match_test "REGNO (op) == LINK_REGISTER_REGNUM
687
                  || REGNO (op) == COUNT_REGISTER_REGNUM
688
                  || REGNO (op) >= FIRST_PSEUDO_REGISTER")
689
     (match_code "symbol_ref")))
690
 
691
;; Return 1 if the operand is a SYMBOL_REF for a function known to be in
692
;; this file.
693
(define_predicate "current_file_function_operand"
694
  (and (match_code "symbol_ref")
695
       (match_test "(DEFAULT_ABI != ABI_AIX || SYMBOL_REF_FUNCTION_P (op))
696
                    && ((SYMBOL_REF_LOCAL_P (op)
697
                         && (DEFAULT_ABI != ABI_AIX
698
                             || !SYMBOL_REF_EXTERNAL_P (op)))
699
                        || (op == XEXP (DECL_RTL (current_function_decl),
700
                                                  0)))")))
701
 
702
;; Return 1 if this operand is a valid input for a move insn.
703
(define_predicate "input_operand"
704
  (match_code "label_ref,symbol_ref,const,high,reg,subreg,mem,
705
               const_double,const_vector,const_int,plus")
706
{
707
  /* Memory is always valid.  */
708
  if (memory_operand (op, mode))
709
    return 1;
710
 
711
  /* For floating-point, easy constants are valid.  */
712
  if (SCALAR_FLOAT_MODE_P (mode)
713
      && CONSTANT_P (op)
714
      && easy_fp_constant (op, mode))
715
    return 1;
716
 
717
  /* Allow any integer constant.  */
718
  if (GET_MODE_CLASS (mode) == MODE_INT
719
      && (GET_CODE (op) == CONST_INT
720
          || GET_CODE (op) == CONST_DOUBLE))
721
    return 1;
722
 
723
  /* Allow easy vector constants.  */
724
  if (GET_CODE (op) == CONST_VECTOR
725
      && easy_vector_constant (op, mode))
726
    return 1;
727
 
728
  /* Do not allow invalid E500 subregs.  */
729
  if ((TARGET_E500_DOUBLE || TARGET_SPE)
730
      && GET_CODE (op) == SUBREG
731
      && invalid_e500_subreg (op, mode))
732
    return 0;
733
 
734
  /* For floating-point or multi-word mode, the only remaining valid type
735
     is a register.  */
736
  if (SCALAR_FLOAT_MODE_P (mode)
737
      || GET_MODE_SIZE (mode) > UNITS_PER_WORD)
738
    return register_operand (op, mode);
739
 
740
  /* The only cases left are integral modes one word or smaller (we
741
     do not get called for MODE_CC values).  These can be in any
742
     register.  */
743
  if (register_operand (op, mode))
744
    return 1;
745
 
746
  /* A SYMBOL_REF referring to the TOC is valid.  */
747
  if (legitimate_constant_pool_address_p (op))
748
    return 1;
749
 
750
  /* A constant pool expression (relative to the TOC) is valid */
751
  if (toc_relative_expr_p (op))
752
    return 1;
753
 
754
  /* V.4 allows SYMBOL_REFs and CONSTs that are in the small data region
755
     to be valid.  */
756
  if (DEFAULT_ABI == ABI_V4
757
      && (GET_CODE (op) == SYMBOL_REF || GET_CODE (op) == CONST)
758
      && small_data_operand (op, Pmode))
759
    return 1;
760
 
761
  return 0;
762
})
763
 
764
;; Return true if OP is an invalid SUBREG operation on the e500.
765
(define_predicate "rs6000_nonimmediate_operand"
766
  (match_code "reg,subreg,mem")
767
{
768
  if ((TARGET_E500_DOUBLE || TARGET_SPE)
769
      && GET_CODE (op) == SUBREG
770
      && invalid_e500_subreg (op, mode))
771
    return 0;
772
 
773
  return nonimmediate_operand (op, mode);
774
})
775
 
776
;; Return true if operand is boolean operator.
777
(define_predicate "boolean_operator"
778
  (match_code "and,ior,xor"))
779
 
780
;; Return true if operand is OR-form of boolean operator.
781
(define_predicate "boolean_or_operator"
782
  (match_code "ior,xor"))
783
 
784
;; Return true if operand is an equality operator.
785
(define_special_predicate "equality_operator"
786
  (match_code "eq,ne"))
787
 
788
;; Return true if operand is MIN or MAX operator.
789
(define_predicate "min_max_operator"
790
  (match_code "smin,smax,umin,umax"))
791
 
792
;; Return 1 if OP is a comparison operation that is valid for a branch
793
;; instruction.  We check the opcode against the mode of the CC value.
794
;; validate_condition_mode is an assertion.
795
(define_predicate "branch_comparison_operator"
796
   (and (match_operand 0 "comparison_operator")
797
        (and (match_test "GET_MODE_CLASS (GET_MODE (XEXP (op, 0))) == MODE_CC")
798
             (match_test "validate_condition_mode (GET_CODE (op),
799
                                                   GET_MODE (XEXP (op, 0))),
800
                          1"))))
801
 
802
;; Return 1 if OP is a comparison operation that is valid for an SCC insn --
803
;; it must be a positive comparison.
804
(define_predicate "scc_comparison_operator"
805
  (and (match_operand 0 "branch_comparison_operator")
806
       (match_code "eq,lt,gt,ltu,gtu,unordered")))
807
 
808
;; Return 1 if OP is a comparison operation that is valid for a branch
809
;; insn, which is true if the corresponding bit in the CC register is set.
810
(define_predicate "branch_positive_comparison_operator"
811
  (and (match_operand 0 "branch_comparison_operator")
812
       (match_code "eq,lt,gt,ltu,gtu,unordered")))
813
 
814
;; Return 1 is OP is a comparison operation that is valid for a trap insn.
815
(define_predicate "trap_comparison_operator"
816
   (and (match_operand 0 "comparison_operator")
817
        (match_code "eq,ne,le,lt,ge,gt,leu,ltu,geu,gtu")))
818
 
819
;; Return 1 if OP is a load multiple operation, known to be a PARALLEL.
820
(define_predicate "load_multiple_operation"
821
  (match_code "parallel")
822
{
823
  int count = XVECLEN (op, 0);
824
  unsigned int dest_regno;
825
  rtx src_addr;
826
  int i;
827
 
828
  /* Perform a quick check so we don't blow up below.  */
829
  if (count <= 1
830
      || GET_CODE (XVECEXP (op, 0, 0)) != SET
831
      || GET_CODE (SET_DEST (XVECEXP (op, 0, 0))) != REG
832
      || GET_CODE (SET_SRC (XVECEXP (op, 0, 0))) != MEM)
833
    return 0;
834
 
835
  dest_regno = REGNO (SET_DEST (XVECEXP (op, 0, 0)));
836
  src_addr = XEXP (SET_SRC (XVECEXP (op, 0, 0)), 0);
837
 
838
  for (i = 1; i < count; i++)
839
    {
840
      rtx elt = XVECEXP (op, 0, i);
841
 
842
      if (GET_CODE (elt) != SET
843
          || GET_CODE (SET_DEST (elt)) != REG
844
          || GET_MODE (SET_DEST (elt)) != SImode
845
          || REGNO (SET_DEST (elt)) != dest_regno + i
846
          || GET_CODE (SET_SRC (elt)) != MEM
847
          || GET_MODE (SET_SRC (elt)) != SImode
848
          || GET_CODE (XEXP (SET_SRC (elt), 0)) != PLUS
849
          || ! rtx_equal_p (XEXP (XEXP (SET_SRC (elt), 0), 0), src_addr)
850
          || GET_CODE (XEXP (XEXP (SET_SRC (elt), 0), 1)) != CONST_INT
851
          || INTVAL (XEXP (XEXP (SET_SRC (elt), 0), 1)) != i * 4)
852
        return 0;
853
    }
854
 
855
  return 1;
856
})
857
 
858
;; Return 1 if OP is a store multiple operation, known to be a PARALLEL.
859
;; The second vector element is a CLOBBER.
860
(define_predicate "store_multiple_operation"
861
  (match_code "parallel")
862
{
863
  int count = XVECLEN (op, 0) - 1;
864
  unsigned int src_regno;
865
  rtx dest_addr;
866
  int i;
867
 
868
  /* Perform a quick check so we don't blow up below.  */
869
  if (count <= 1
870
      || GET_CODE (XVECEXP (op, 0, 0)) != SET
871
      || GET_CODE (SET_DEST (XVECEXP (op, 0, 0))) != MEM
872
      || GET_CODE (SET_SRC (XVECEXP (op, 0, 0))) != REG)
873
    return 0;
874
 
875
  src_regno = REGNO (SET_SRC (XVECEXP (op, 0, 0)));
876
  dest_addr = XEXP (SET_DEST (XVECEXP (op, 0, 0)), 0);
877
 
878
  for (i = 1; i < count; i++)
879
    {
880
      rtx elt = XVECEXP (op, 0, i + 1);
881
 
882
      if (GET_CODE (elt) != SET
883
          || GET_CODE (SET_SRC (elt)) != REG
884
          || GET_MODE (SET_SRC (elt)) != SImode
885
          || REGNO (SET_SRC (elt)) != src_regno + i
886
          || GET_CODE (SET_DEST (elt)) != MEM
887
          || GET_MODE (SET_DEST (elt)) != SImode
888
          || GET_CODE (XEXP (SET_DEST (elt), 0)) != PLUS
889
          || ! rtx_equal_p (XEXP (XEXP (SET_DEST (elt), 0), 0), dest_addr)
890
          || GET_CODE (XEXP (XEXP (SET_DEST (elt), 0), 1)) != CONST_INT
891
          || INTVAL (XEXP (XEXP (SET_DEST (elt), 0), 1)) != i * 4)
892
        return 0;
893
    }
894
 
895
  return 1;
896
})
897
 
898
;; Return 1 if OP is valid for a save_world call in prologue, known to be
899
;; a PARLLEL.
900
(define_predicate "save_world_operation"
901
  (match_code "parallel")
902
{
903
  int index;
904
  int i;
905
  rtx elt;
906
  int count = XVECLEN (op, 0);
907
 
908
  if (count != 55)
909
    return 0;
910
 
911
  index = 0;
912
  if (GET_CODE (XVECEXP (op, 0, index++)) != CLOBBER
913
      || GET_CODE (XVECEXP (op, 0, index++)) != USE)
914
    return 0;
915
 
916
  for (i=1; i <= 18; i++)
917
    {
918
      elt = XVECEXP (op, 0, index++);
919
      if (GET_CODE (elt) != SET
920
          || GET_CODE (SET_DEST (elt)) != MEM
921
          || ! memory_operand (SET_DEST (elt), DFmode)
922
          || GET_CODE (SET_SRC (elt)) != REG
923
          || GET_MODE (SET_SRC (elt)) != DFmode)
924
        return 0;
925
    }
926
 
927
  for (i=1; i <= 12; i++)
928
    {
929
      elt = XVECEXP (op, 0, index++);
930
      if (GET_CODE (elt) != SET
931
          || GET_CODE (SET_DEST (elt)) != MEM
932
          || GET_CODE (SET_SRC (elt)) != REG
933
          || GET_MODE (SET_SRC (elt)) != V4SImode)
934
        return 0;
935
    }
936
 
937
  for (i=1; i <= 19; i++)
938
    {
939
      elt = XVECEXP (op, 0, index++);
940
      if (GET_CODE (elt) != SET
941
          || GET_CODE (SET_DEST (elt)) != MEM
942
          || ! memory_operand (SET_DEST (elt), Pmode)
943
          || GET_CODE (SET_SRC (elt)) != REG
944
          || GET_MODE (SET_SRC (elt)) != Pmode)
945
        return 0;
946
    }
947
 
948
  elt = XVECEXP (op, 0, index++);
949
  if (GET_CODE (elt) != SET
950
      || GET_CODE (SET_DEST (elt)) != MEM
951
      || ! memory_operand (SET_DEST (elt), Pmode)
952
      || GET_CODE (SET_SRC (elt)) != REG
953
      || REGNO (SET_SRC (elt)) != CR2_REGNO
954
      || GET_MODE (SET_SRC (elt)) != Pmode)
955
    return 0;
956
 
957
  if (GET_CODE (XVECEXP (op, 0, index++)) != USE
958
      || GET_CODE (XVECEXP (op, 0, index++)) != USE
959
      || GET_CODE (XVECEXP (op, 0, index++)) != CLOBBER)
960
    return 0;
961
  return 1;
962
})
963
 
964
;; Return 1 if OP is valid for a restore_world call in epilogue, known to be
965
;; a PARLLEL.
966
(define_predicate "restore_world_operation"
967
  (match_code "parallel")
968
{
969
  int index;
970
  int i;
971
  rtx elt;
972
  int count = XVECLEN (op, 0);
973
 
974
  if (count != 59)
975
    return 0;
976
 
977
  index = 0;
978
  if (GET_CODE (XVECEXP (op, 0, index++)) != RETURN
979
      || GET_CODE (XVECEXP (op, 0, index++)) != USE
980
      || GET_CODE (XVECEXP (op, 0, index++)) != USE
981
      || GET_CODE (XVECEXP (op, 0, index++)) != CLOBBER)
982
    return 0;
983
 
984
  elt = XVECEXP (op, 0, index++);
985
  if (GET_CODE (elt) != SET
986
      || GET_CODE (SET_SRC (elt)) != MEM
987
      || ! memory_operand (SET_SRC (elt), Pmode)
988
      || GET_CODE (SET_DEST (elt)) != REG
989
      || REGNO (SET_DEST (elt)) != CR2_REGNO
990
      || GET_MODE (SET_DEST (elt)) != Pmode)
991
    return 0;
992
 
993
  for (i=1; i <= 19; i++)
994
    {
995
      elt = XVECEXP (op, 0, index++);
996
      if (GET_CODE (elt) != SET
997
          || GET_CODE (SET_SRC (elt)) != MEM
998
          || ! memory_operand (SET_SRC (elt), Pmode)
999
          || GET_CODE (SET_DEST (elt)) != REG
1000
          || GET_MODE (SET_DEST (elt)) != Pmode)
1001
        return 0;
1002
    }
1003
 
1004
  for (i=1; i <= 12; i++)
1005
    {
1006
      elt = XVECEXP (op, 0, index++);
1007
      if (GET_CODE (elt) != SET
1008
          || GET_CODE (SET_SRC (elt)) != MEM
1009
          || GET_CODE (SET_DEST (elt)) != REG
1010
          || GET_MODE (SET_DEST (elt)) != V4SImode)
1011
        return 0;
1012
    }
1013
 
1014
  for (i=1; i <= 18; i++)
1015
    {
1016
      elt = XVECEXP (op, 0, index++);
1017
      if (GET_CODE (elt) != SET
1018
          || GET_CODE (SET_SRC (elt)) != MEM
1019
          || ! memory_operand (SET_SRC (elt), DFmode)
1020
          || GET_CODE (SET_DEST (elt)) != REG
1021
          || GET_MODE (SET_DEST (elt)) != DFmode)
1022
        return 0;
1023
    }
1024
 
1025
  if (GET_CODE (XVECEXP (op, 0, index++)) != CLOBBER
1026
      || GET_CODE (XVECEXP (op, 0, index++)) != CLOBBER
1027
      || GET_CODE (XVECEXP (op, 0, index++)) != CLOBBER
1028
      || GET_CODE (XVECEXP (op, 0, index++)) != CLOBBER
1029
      || GET_CODE (XVECEXP (op, 0, index++)) != USE)
1030
    return 0;
1031
  return 1;
1032
})
1033
 
1034
;; Return 1 if OP is valid for a vrsave call, known to be a PARALLEL.
1035
(define_predicate "vrsave_operation"
1036
  (match_code "parallel")
1037
{
1038
  int count = XVECLEN (op, 0);
1039
  unsigned int dest_regno, src_regno;
1040
  int i;
1041
 
1042
  if (count <= 1
1043
      || GET_CODE (XVECEXP (op, 0, 0)) != SET
1044
      || GET_CODE (SET_DEST (XVECEXP (op, 0, 0))) != REG
1045
      || GET_CODE (SET_SRC (XVECEXP (op, 0, 0))) != UNSPEC_VOLATILE
1046
      || XINT (SET_SRC (XVECEXP (op, 0, 0)), 1) != UNSPECV_SET_VRSAVE)
1047
    return 0;
1048
 
1049
  dest_regno = REGNO (SET_DEST (XVECEXP (op, 0, 0)));
1050
  src_regno  = REGNO (XVECEXP (SET_SRC (XVECEXP (op, 0, 0)), 0, 1));
1051
 
1052
  if (dest_regno != VRSAVE_REGNO || src_regno != VRSAVE_REGNO)
1053
    return 0;
1054
 
1055
  for (i = 1; i < count; i++)
1056
    {
1057
      rtx elt = XVECEXP (op, 0, i);
1058
 
1059
      if (GET_CODE (elt) != CLOBBER
1060
          && GET_CODE (elt) != SET)
1061
        return 0;
1062
    }
1063
 
1064
  return 1;
1065
})
1066
 
1067
;; Return 1 if OP is valid for mfcr insn, known to be a PARALLEL.
1068
(define_predicate "mfcr_operation"
1069
  (match_code "parallel")
1070
{
1071
  int count = XVECLEN (op, 0);
1072
  int i;
1073
 
1074
  /* Perform a quick check so we don't blow up below.  */
1075
  if (count < 1
1076
      || GET_CODE (XVECEXP (op, 0, 0)) != SET
1077
      || GET_CODE (SET_SRC (XVECEXP (op, 0, 0))) != UNSPEC
1078
      || XVECLEN (SET_SRC (XVECEXP (op, 0, 0)), 0) != 2)
1079
    return 0;
1080
 
1081
  for (i = 0; i < count; i++)
1082
    {
1083
      rtx exp = XVECEXP (op, 0, i);
1084
      rtx unspec;
1085
      int maskval;
1086
      rtx src_reg;
1087
 
1088
      src_reg = XVECEXP (SET_SRC (exp), 0, 0);
1089
 
1090
      if (GET_CODE (src_reg) != REG
1091
          || GET_MODE (src_reg) != CCmode
1092
          || ! CR_REGNO_P (REGNO (src_reg)))
1093
        return 0;
1094
 
1095
      if (GET_CODE (exp) != SET
1096
          || GET_CODE (SET_DEST (exp)) != REG
1097
          || GET_MODE (SET_DEST (exp)) != SImode
1098
          || ! INT_REGNO_P (REGNO (SET_DEST (exp))))
1099
        return 0;
1100
      unspec = SET_SRC (exp);
1101
      maskval = 1 << (MAX_CR_REGNO - REGNO (src_reg));
1102
 
1103
      if (GET_CODE (unspec) != UNSPEC
1104
          || XINT (unspec, 1) != UNSPEC_MOVESI_FROM_CR
1105
          || XVECLEN (unspec, 0) != 2
1106
          || XVECEXP (unspec, 0, 0) != src_reg
1107
          || GET_CODE (XVECEXP (unspec, 0, 1)) != CONST_INT
1108
          || INTVAL (XVECEXP (unspec, 0, 1)) != maskval)
1109
        return 0;
1110
    }
1111
  return 1;
1112
})
1113
 
1114
;; Return 1 if OP is valid for mtcrf insn, known to be a PARALLEL.
1115
(define_predicate "mtcrf_operation"
1116
  (match_code "parallel")
1117
{
1118
  int count = XVECLEN (op, 0);
1119
  int i;
1120
  rtx src_reg;
1121
 
1122
  /* Perform a quick check so we don't blow up below.  */
1123
  if (count < 1
1124
      || GET_CODE (XVECEXP (op, 0, 0)) != SET
1125
      || GET_CODE (SET_SRC (XVECEXP (op, 0, 0))) != UNSPEC
1126
      || XVECLEN (SET_SRC (XVECEXP (op, 0, 0)), 0) != 2)
1127
    return 0;
1128
  src_reg = XVECEXP (SET_SRC (XVECEXP (op, 0, 0)), 0, 0);
1129
 
1130
  if (GET_CODE (src_reg) != REG
1131
      || GET_MODE (src_reg) != SImode
1132
      || ! INT_REGNO_P (REGNO (src_reg)))
1133
    return 0;
1134
 
1135
  for (i = 0; i < count; i++)
1136
    {
1137
      rtx exp = XVECEXP (op, 0, i);
1138
      rtx unspec;
1139
      int maskval;
1140
 
1141
      if (GET_CODE (exp) != SET
1142
          || GET_CODE (SET_DEST (exp)) != REG
1143
          || GET_MODE (SET_DEST (exp)) != CCmode
1144
          || ! CR_REGNO_P (REGNO (SET_DEST (exp))))
1145
        return 0;
1146
      unspec = SET_SRC (exp);
1147
      maskval = 1 << (MAX_CR_REGNO - REGNO (SET_DEST (exp)));
1148
 
1149
      if (GET_CODE (unspec) != UNSPEC
1150
          || XINT (unspec, 1) != UNSPEC_MOVESI_TO_CR
1151
          || XVECLEN (unspec, 0) != 2
1152
          || XVECEXP (unspec, 0, 0) != src_reg
1153
          || GET_CODE (XVECEXP (unspec, 0, 1)) != CONST_INT
1154
          || INTVAL (XVECEXP (unspec, 0, 1)) != maskval)
1155
        return 0;
1156
    }
1157
  return 1;
1158
})
1159
 
1160
;; Return 1 if OP is valid for lmw insn, known to be a PARALLEL.
1161
(define_predicate "lmw_operation"
1162
  (match_code "parallel")
1163
{
1164
  int count = XVECLEN (op, 0);
1165
  unsigned int dest_regno;
1166
  rtx src_addr;
1167
  unsigned int base_regno;
1168
  HOST_WIDE_INT offset;
1169
  int i;
1170
 
1171
  /* Perform a quick check so we don't blow up below.  */
1172
  if (count <= 1
1173
      || GET_CODE (XVECEXP (op, 0, 0)) != SET
1174
      || GET_CODE (SET_DEST (XVECEXP (op, 0, 0))) != REG
1175
      || GET_CODE (SET_SRC (XVECEXP (op, 0, 0))) != MEM)
1176
    return 0;
1177
 
1178
  dest_regno = REGNO (SET_DEST (XVECEXP (op, 0, 0)));
1179
  src_addr = XEXP (SET_SRC (XVECEXP (op, 0, 0)), 0);
1180
 
1181
  if (dest_regno > 31
1182
      || count != 32 - (int) dest_regno)
1183
    return 0;
1184
 
1185
  if (legitimate_indirect_address_p (src_addr, 0))
1186
    {
1187
      offset = 0;
1188
      base_regno = REGNO (src_addr);
1189
      if (base_regno == 0)
1190
        return 0;
1191
    }
1192
  else if (rs6000_legitimate_offset_address_p (SImode, src_addr, 0))
1193
    {
1194
      offset = INTVAL (XEXP (src_addr, 1));
1195
      base_regno = REGNO (XEXP (src_addr, 0));
1196
    }
1197
  else
1198
    return 0;
1199
 
1200
  for (i = 0; i < count; i++)
1201
    {
1202
      rtx elt = XVECEXP (op, 0, i);
1203
      rtx newaddr;
1204
      rtx addr_reg;
1205
      HOST_WIDE_INT newoffset;
1206
 
1207
      if (GET_CODE (elt) != SET
1208
          || GET_CODE (SET_DEST (elt)) != REG
1209
          || GET_MODE (SET_DEST (elt)) != SImode
1210
          || REGNO (SET_DEST (elt)) != dest_regno + i
1211
          || GET_CODE (SET_SRC (elt)) != MEM
1212
          || GET_MODE (SET_SRC (elt)) != SImode)
1213
        return 0;
1214
      newaddr = XEXP (SET_SRC (elt), 0);
1215
      if (legitimate_indirect_address_p (newaddr, 0))
1216
        {
1217
          newoffset = 0;
1218
          addr_reg = newaddr;
1219
        }
1220
      else if (rs6000_legitimate_offset_address_p (SImode, newaddr, 0))
1221
        {
1222
          addr_reg = XEXP (newaddr, 0);
1223
          newoffset = INTVAL (XEXP (newaddr, 1));
1224
        }
1225
      else
1226
        return 0;
1227
      if (REGNO (addr_reg) != base_regno
1228
          || newoffset != offset + 4 * i)
1229
        return 0;
1230
    }
1231
 
1232
  return 1;
1233
})
1234
 
1235
;; Return 1 if OP is valid for stmw insn, known to be a PARALLEL.
1236
(define_predicate "stmw_operation"
1237
  (match_code "parallel")
1238
{
1239
  int count = XVECLEN (op, 0);
1240
  unsigned int src_regno;
1241
  rtx dest_addr;
1242
  unsigned int base_regno;
1243
  HOST_WIDE_INT offset;
1244
  int i;
1245
 
1246
  /* Perform a quick check so we don't blow up below.  */
1247
  if (count <= 1
1248
      || GET_CODE (XVECEXP (op, 0, 0)) != SET
1249
      || GET_CODE (SET_DEST (XVECEXP (op, 0, 0))) != MEM
1250
      || GET_CODE (SET_SRC (XVECEXP (op, 0, 0))) != REG)
1251
    return 0;
1252
 
1253
  src_regno = REGNO (SET_SRC (XVECEXP (op, 0, 0)));
1254
  dest_addr = XEXP (SET_DEST (XVECEXP (op, 0, 0)), 0);
1255
 
1256
  if (src_regno > 31
1257
      || count != 32 - (int) src_regno)
1258
    return 0;
1259
 
1260
  if (legitimate_indirect_address_p (dest_addr, 0))
1261
    {
1262
      offset = 0;
1263
      base_regno = REGNO (dest_addr);
1264
      if (base_regno == 0)
1265
        return 0;
1266
    }
1267
  else if (rs6000_legitimate_offset_address_p (SImode, dest_addr, 0))
1268
    {
1269
      offset = INTVAL (XEXP (dest_addr, 1));
1270
      base_regno = REGNO (XEXP (dest_addr, 0));
1271
    }
1272
  else
1273
    return 0;
1274
 
1275
  for (i = 0; i < count; i++)
1276
    {
1277
      rtx elt = XVECEXP (op, 0, i);
1278
      rtx newaddr;
1279
      rtx addr_reg;
1280
      HOST_WIDE_INT newoffset;
1281
 
1282
      if (GET_CODE (elt) != SET
1283
          || GET_CODE (SET_SRC (elt)) != REG
1284
          || GET_MODE (SET_SRC (elt)) != SImode
1285
          || REGNO (SET_SRC (elt)) != src_regno + i
1286
          || GET_CODE (SET_DEST (elt)) != MEM
1287
          || GET_MODE (SET_DEST (elt)) != SImode)
1288
        return 0;
1289
      newaddr = XEXP (SET_DEST (elt), 0);
1290
      if (legitimate_indirect_address_p (newaddr, 0))
1291
        {
1292
          newoffset = 0;
1293
          addr_reg = newaddr;
1294
        }
1295
      else if (rs6000_legitimate_offset_address_p (SImode, newaddr, 0))
1296
        {
1297
          addr_reg = XEXP (newaddr, 0);
1298
          newoffset = INTVAL (XEXP (newaddr, 1));
1299
        }
1300
      else
1301
        return 0;
1302
      if (REGNO (addr_reg) != base_regno
1303
          || newoffset != offset + 4 * i)
1304
        return 0;
1305
    }
1306
 
1307
  return 1;
1308
})

powered by: WebSVN 2.1.0

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