summaryrefslogtreecommitdiff
path: root/gcc/config/xtensa/predicates.md
blob: e02209ea4f34539c09108f19bbd985faab821b2c (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
;; Predicate definitions for Xtensa.
;; Copyright (C) 2005-2015 Free Software Foundation, Inc.
;;
;; This file is part of GCC.
;;
;; GCC is free software; you can redistribute it and/or modify
;; it under the terms of the GNU General Public License as published by
;; the Free Software Foundation; either version 3, or (at your option)
;; any later version.
;;
;; GCC is distributed in the hope that it will be useful,
;; but WITHOUT ANY WARRANTY; without even the implied warranty of
;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
;; GNU General Public License for more details.
;;
;; You should have received a copy of the GNU General Public License
;; along with GCC; see the file COPYING3.  If not see
;; <http://www.gnu.org/licenses/>.

(define_predicate "add_operand"
  (ior (and (match_code "const_int")
	    (match_test "xtensa_simm8 (INTVAL (op))
			 || xtensa_simm8x256 (INTVAL (op))"))
       (match_operand 0 "register_operand")))

(define_predicate "addsubx_operand"
  (and (match_code "const_int")
       (match_test "INTVAL (op) == 2
		    || INTVAL (op) == 4
		    || INTVAL (op) == 8")))

(define_predicate "arith_operand"
  (ior (and (match_code "const_int")
	    (match_test "xtensa_simm8 (INTVAL (op))"))
       (match_operand 0 "register_operand")))

;; Non-immediate operand excluding the constant pool.
(define_predicate "nonimmed_operand"
  (ior (and (match_operand 0 "memory_operand")
	    (match_test "!constantpool_mem_p (op)"))
       (match_operand 0 "register_operand")))

;; Memory operand excluding the constant pool.
(define_predicate "mem_operand"
  (and (match_operand 0 "memory_operand")
       (match_test "!constantpool_mem_p (op)")))

;; Memory operand in the constant pool.
(define_predicate "constantpool_operand"
  (match_test "constantpool_mem_p (op)"))

(define_predicate "mask_operand"
  (ior (and (match_code "const_int")
	    (match_test "xtensa_mask_immediate (INTVAL (op))"))
       (match_operand 0 "register_operand")))

(define_predicate "extui_fldsz_operand"
  (and (match_code "const_int")
       (match_test "xtensa_mask_immediate ((1 << INTVAL (op)) - 1)")))

(define_predicate "sext_operand"
  (if_then_else (match_test "TARGET_SEXT")
		(match_operand 0 "nonimmed_operand")
		(match_operand 0 "mem_operand")))

(define_predicate "sext_fldsz_operand"
  (and (match_code "const_int")
       (match_test "INTVAL (op) >= 8 && INTVAL (op) <= 23")))

(define_predicate "lsbitnum_operand"
  (and (match_code "const_int")
       (match_test "BITS_BIG_ENDIAN
		    ? (INTVAL (op) == BITS_PER_WORD - 1)
		    : (INTVAL (op) == 0)")))

(define_predicate "branch_operand"
  (ior (and (match_code "const_int")
	    (match_test "xtensa_b4const_or_zero (INTVAL (op))"))
       (match_operand 0 "register_operand")))

(define_predicate "ubranch_operand"
  (ior (and (match_code "const_int")
	    (match_test "xtensa_b4constu (INTVAL (op))"))
       (match_operand 0 "register_operand")))

(define_predicate "call_insn_operand"
  (match_code "const_int,const,symbol_ref,reg")
{
  if ((GET_CODE (op) == REG)
      && (op != arg_pointer_rtx)
      && ((REGNO (op) < FRAME_POINTER_REGNUM)
	  || (REGNO (op) > LAST_VIRTUAL_REGISTER)))
    return true;

  if (CONSTANT_ADDRESS_P (op))
    {
      /* Direct calls only allowed to static functions with PIC.  */
      if (flag_pic)
	{
	  tree callee;
	  const char * callee_sec, * caller_sec;

	  if (GET_CODE (op) != SYMBOL_REF
	      || !SYMBOL_REF_LOCAL_P (op) || SYMBOL_REF_EXTERNAL_P (op))
	    return false;

	  /* Don't attempt a direct call if the callee is known to be in
	     a different section, since there's a good chance it will be
	     out of range.  */

	  if (flag_function_sections
	      || DECL_ONE_ONLY (current_function_decl))
	    return false;
	  caller_sec = DECL_SECTION_NAME (current_function_decl);
	  callee = SYMBOL_REF_DECL (op);
	  if (callee)
	    {
	      if (DECL_ONE_ONLY (callee))
		return false;
	      callee_sec = DECL_SECTION_NAME (callee);
	      if (((caller_sec == NULL) ^ (callee_sec == NULL))
		  || (caller_sec != NULL
		      && caller_sec != callee_sec))
		return false;
	    }
	  else if (caller_sec)
	    return false;
	}
      return true;
    }

  return false;
})

(define_predicate "move_operand"
  (ior
     (ior (match_operand 0 "register_operand")
	  (and (match_operand 0 "memory_operand")
	       (match_test "!constantpool_mem_p (op)
			    || GET_MODE_SIZE (mode) % UNITS_PER_WORD == 0")))
     (ior (and (match_code "const_int")
	       (match_test "GET_MODE_CLASS (mode) == MODE_INT
			    && xtensa_simm12b (INTVAL (op))"))
	  (and (match_code "const_int,const_double,const,symbol_ref,label_ref")
	       (match_test "TARGET_CONST16 && CONSTANT_P (op)
			    && GET_MODE_SIZE (mode) % UNITS_PER_WORD == 0")))))

;; Accept the floating point constant 1 in the appropriate mode.
(define_predicate "const_float_1_operand"
  (match_code "const_double")
{
  REAL_VALUE_TYPE d;
  REAL_VALUE_FROM_CONST_DOUBLE (d, op);
  return REAL_VALUES_EQUAL (d, dconst1);
})

(define_predicate "fpmem_offset_operand"
  (and (match_code "const_int")
       (match_test "xtensa_mem_offset (INTVAL (op), SFmode)")))

(define_predicate "branch_operator"
  (match_code "eq,ne,lt,ge"))

(define_predicate "ubranch_operator"
  (match_code "ltu,geu"))

(define_predicate "boolean_operator"
  (match_code "eq,ne"))

(define_predicate "xtensa_cstoresi_operator"
  (match_code "eq,ne,gt,ge,lt,le"))

(define_predicate "tls_symbol_operand"
  (and (match_code "symbol_ref")
       (match_test "SYMBOL_REF_TLS_MODEL (op) != 0")))