summaryrefslogtreecommitdiff
path: root/gcc/config/rl78/constraints.md
blob: 209f1e660a176c343f15671005278484a6ff40eb (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
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
;;  Machine Description for Renesas RL78 processors
;;  Copyright (C) 2011-2015 Free Software Foundation, Inc.
;;  Contributed by Red Hat.

;; 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/>.

; Constraints in use:

; core:
; V X g i m n o p r s < >
; 0..9
; I..Q - integers
;   Int8 = 0..255
;   Int3 = 1..7
;   J = -255..0
;   K = 1
;   L = -1
;   M = 0
;   N = 2
;   O = -2
;   P = 1..15

; E..H - float constants

; RL78-specific
; a x b c d e h l w - 8-bit regs
; A B D T S - 16-bit regs
; R = all regular registers (A-L)
; Y - any valid memory
; Wxx - various memory addressing modes
; Qxx - conditionals
; U = usual memory references mov-able to/from AX
; v = virtual registers
; Zxx = specific virtual registers

(define_constraint "Int8"
  "Integer constant in the range 0 @dots{} 255."
  (and (match_code "const_int")
       (match_test "IN_RANGE (ival, 0, 255)")))

(define_constraint "Int3"
  "Integer constant in the range 1 @dots{} 7."
  (and (match_code "const_int")
       (match_test "IN_RANGE (ival, 1, 7)")))

(define_constraint "Iv08"
  "@internal
   Integer constant equal to 8."
  (and (match_code "const_int")
       (match_test "IN_RANGE (ival, 8, 8)")))

(define_constraint "Iv16"
  "@internal
   Integer constant equal to 16."
  (and (match_code "const_int")
       (match_test "IN_RANGE (ival, 16, 16)")))

(define_constraint "Iv24"
  "@internal
   Integer constant equal to 24."
  (and (match_code "const_int")
       (match_test "IN_RANGE (ival, 24, 24)")))

(define_constraint "Is09"
  "@internal
   Integer constant in the range 9 @dots{} 15 (for shifts)."
  (and (match_code "const_int")
       (match_test "IN_RANGE (ival, 9, 15)")))

(define_constraint "Is17"
  "@internal
   Integer constant in the range 17 @dots{} 23 (for shifts)."
  (and (match_code "const_int")
       (match_test "IN_RANGE (ival, 17, 23)")))

(define_constraint "Is25"
  "@internal
   Integer constant in the range 25 @dots{} 31 (for shifts)."
  (and (match_code "const_int")
       (match_test "IN_RANGE (ival, 25, 31)")))

(define_constraint "ISsi"
  "@internal
   Integer constant with bit 31 set."
  (and (match_code "const_int")
       (match_test "(ival & 0x80000000) != 0")))

(define_constraint "IShi"
  "@internal
   Integer constant with bit 15 set."
  (and (match_code "const_int")
       (match_test "(ival & 0x8000) != 0")))

(define_constraint "ISqi"
  "@internal
   Integer constant with bit 7 set."
  (and (match_code "const_int")
       (match_test "(ival & 0x80) != 0")))

(define_constraint "Ibqi"
  "@internal
   Integer constant with one bit in 0..7 set."
  (and (match_code "const_int")
       (match_test "(ival & 0xff) && (exact_log2 (ival & 0xff) >= 0)")))
(define_constraint "IBqi"
  "@internal
   Integer constant with one bit in 0..7 clear."
  (and (match_code "const_int")
       (match_test "(~ival & 0xff) && (exact_log2 (~ival & 0xff) >= 0)")))

(define_constraint "J"
  "Integer constant in the range -255 @dots{} 0"
  (and (match_code "const_int")
       (match_test "IN_RANGE (ival, -255, 0)")))

(define_constraint "K"
  "Integer constant 1."
  (and (match_code "const_int")
       (match_test "IN_RANGE (ival, 1, 1)")))

(define_constraint "L"
  "Integer constant -1."
  (and (match_code "const_int")
       (match_test "IN_RANGE (ival, -1, -1)")))

(define_constraint "M"
  "Integer constant 0."
  (and (match_code "const_int")
       (match_test "IN_RANGE (ival, 0, 0)")))

(define_constraint "N"
  "Integer constant 2."
  (and (match_code "const_int")
       (match_test "IN_RANGE (ival, 2, 2)")))

(define_constraint "O"
  "Integer constant -2."
  (and (match_code "const_int")
       (match_test "IN_RANGE (ival, -2, -2)")))

(define_constraint "P"
  "Integer constant 1..15"
  (and (match_code "const_int")
       (match_test "IN_RANGE (ival, 1, 15)")))

(define_register_constraint "R" "QI_REGS"
 "@code{A} through @code{L} registers.")

(define_register_constraint "a" "AREG"
 "The @code{A} register.")

(define_register_constraint "x" "XREG"
 "The @code{X} register.")

(define_register_constraint "b" "BREG"
 "The @code{B} register.")

(define_register_constraint "c" "CREG"
 "The @code{C} register.")

(define_register_constraint "d" "DREG"
 "The @code{D} register.")

(define_register_constraint "e" "EREG"
 "The @code{E} register.")

(define_register_constraint "h" "HREG"
 "The @code{H} register.")

(define_register_constraint "l" "LREG"
 "The @code{L} register.")

(define_register_constraint "w" "PSWREG"
 "The @code{PSW} register.")

(define_register_constraint "A" "AXREG"
 "The @code{AX} register.")

(define_register_constraint "B" "BCREG"
 "The @code{BC} register.")

(define_register_constraint "D" "DEREG"
 "The @code{DE} register.")

; because H + L = T, assuming A=1.
(define_register_constraint "T" "HLREG"
 "The @code{HL} register.")

(define_register_constraint "S" "SPREG"
 "The @code{SP} register.")

(define_register_constraint "v" "V_REGS"
 "The virtual registers.")

(define_register_constraint "Z08W" "R8W_REGS"
 "The R8 register, HImode.")

(define_register_constraint "Z10W" "R10W_REGS"
 "The R10 register, HImode.")

(define_register_constraint "Zint" "INT_REGS"
 "The interrupt registers.")

; All the memory addressing schemes the RL78 supports
; of the form W {register} {bytes of offset}
;          or W {register} {register}
; Additionally, the Cxx forms are the same as the Wxx forms, but without
; the ES: override.

; absolute address
(define_memory_constraint "Cab"
  "[addr]"
  (and (match_code "mem")
       (ior (match_test "CONSTANT_P (XEXP (op, 0))")
	    (match_test "GET_CODE (XEXP (op, 0)) == PLUS && GET_CODE (XEXP (XEXP (op, 0), 0)) == SYMBOL_REF"))
	    )
  )
(define_memory_constraint "Wab"
  "es:[addr]"
  (match_test "(rl78_es_addr (op) && satisfies_constraint_Cab (rl78_es_base (op)))
               || satisfies_constraint_Cab (op)")
  )

(define_memory_constraint "Cbc"
  "word16[BC]"
  (and (match_code "mem")
       (ior
	(and (match_code "reg" "0")
	     (match_test "REGNO (XEXP (op, 0)) == BC_REG"))
	(and (match_code "plus" "0")
	     (and (and (match_code "reg" "00")
		       (match_test "REGNO (XEXP (XEXP (op, 0), 0)) == BC_REG"))
		       (match_test "uword_operand (XEXP (XEXP (op, 0), 1), VOIDmode)"))))
       )
  )
(define_memory_constraint "Wbc"
  "es:word16[BC]"
  (match_test "(rl78_es_addr (op) && satisfies_constraint_Cbc (rl78_es_base (op)))
               || satisfies_constraint_Cbc (op)")
  )

(define_memory_constraint "Cde"
  "[DE]"
  (and (match_code "mem")
       (and (match_code "reg" "0")
	    (match_test "REGNO (XEXP (op, 0)) == DE_REG")))
  )
(define_memory_constraint "Wde"
  "es:[DE]"
  (match_test "(rl78_es_addr (op) && satisfies_constraint_Cde (rl78_es_base (op)))
               || satisfies_constraint_Cde (op)")
  )

(define_memory_constraint "Cca"
  "[AX..HL] for calls"
  (and (match_code "mem")
       (and (match_code "reg" "0")
	    (match_test "REGNO (XEXP (op, 0)) <= HL_REG")))
  )
(define_memory_constraint "Wca"
  "es:[AX..HL] for calls"
  (match_test "(rl78_es_addr (op) && satisfies_constraint_Cca (rl78_es_base (op)))
               || satisfies_constraint_Cca (op)")
  )

(define_memory_constraint "Ccv"
  "[AX..HL,r8-r31] for calls"
  (and (match_code "mem")
       (and (match_code "reg" "0")
	    (match_test "REGNO (XEXP (op, 0)) < 32")))
  )
(define_memory_constraint "Wcv"
  "es:[AX..HL,r8-r31] for calls"
  (match_test "(rl78_es_addr (op) && satisfies_constraint_Ccv (rl78_es_base (op)))
               || satisfies_constraint_Ccv (op)")
  )

(define_memory_constraint "Cd2"
  "word16[DE]"
  (and (match_code "mem")
       (ior
	(and (match_code "reg" "0")
	     (match_test "REGNO (XEXP (op, 0)) == DE_REG"))
	(and (match_code "plus" "0")
	     (and (and (match_code "reg" "00")
		       (match_test "REGNO (XEXP (XEXP (op, 0), 0)) == DE_REG"))
		       (match_test "uword_operand (XEXP (XEXP (op, 0), 1), VOIDmode)"))))
       )
  )
(define_memory_constraint "Wd2"
  "es:word16[DE]"
  (match_test "(rl78_es_addr (op) && satisfies_constraint_Cd2 (rl78_es_base (op)))
               || satisfies_constraint_Cd2 (op)")
  )

(define_memory_constraint "Chl"
  "[HL]"
  (and (match_code "mem")
       (and (match_code "reg" "0")
	    (match_test "REGNO (XEXP (op, 0)) == HL_REG")))
  )
(define_memory_constraint "Whl"
  "es:[HL]"
  (match_test "(rl78_es_addr (op) && satisfies_constraint_Chl (rl78_es_base (op)))
               || satisfies_constraint_Chl (op)")
  )

(define_memory_constraint "Ch1"
  "byte8[HL]"
  (and (match_code "mem")
       (and (match_code "plus" "0")
	    (and (and (match_code "reg" "00")
		      (match_test "REGNO (XEXP (XEXP (op, 0), 0)) == HL_REG"))
		      (match_test "ubyte_operand (XEXP (XEXP (op, 0), 1), VOIDmode)"))))
  )
(define_memory_constraint "Wh1"
  "es:byte8[HL]"
  (match_test "(rl78_es_addr (op) && satisfies_constraint_Ch1 (rl78_es_base (op)))
               || satisfies_constraint_Ch1 (op)")
  )

(define_memory_constraint "Chb"
  "[HL+B]"
  (and (match_code "mem")
       (match_test "rl78_hl_b_c_addr_p (XEXP (op, 0))"))
  )
(define_memory_constraint "Whb"
  "es:[HL+B]"
  (match_test "(rl78_es_addr (op) && satisfies_constraint_Chb (rl78_es_base (op)))
               || satisfies_constraint_Chb (op)")
  )

(define_memory_constraint "Cs1"
  "word8[SP]"
  (and (match_code "mem")
       (ior
	(and (match_code "reg" "0")
	     (match_test "REGNO (XEXP (op, 0)) == SP_REG"))
	(and (match_code "plus" "0")
	     (and (and (match_code "reg" "00")
		       (match_test "REGNO (XEXP (XEXP (op, 0), 0)) == SP_REG"))
		       (and (match_code "const_int" "01")
		            (match_test "IN_RANGE (INTVAL (XEXP (XEXP (op, 0), 1)), 0, 256 - GET_MODE_SIZE (GET_MODE (op)))")))))
       )
  )

(define_memory_constraint "Ws1"
  "es:word8[SP]"
  (match_test "(rl78_es_addr (op) && satisfies_constraint_Cs1 (rl78_es_base (op)))
               || satisfies_constraint_Cs1 (op)")
  )

(define_memory_constraint "Wfr"
  "ES/CS far pointer"
  (and (match_code "mem")
       (match_test "rl78_far_p (op)"))
  )

(define_memory_constraint "Wsa"
  "any SADDR memory access"
  (and (match_code "mem")
       (match_test "rl78_saddr_p (op)"))
)

(define_memory_constraint "Wsf"
  "any SFR memory access"
  (and (match_code "mem")
       (match_test "rl78_sfr_p (op)"))
)

(define_memory_constraint "Y"
  "any near legitimate memory access"
  (and (match_code "mem")
       (match_test "!rl78_far_p (op) && rl78_as_legitimate_address (VOIDmode, XEXP (op, 0), true, ADDR_SPACE_GENERIC)"))
)

(define_memory_constraint "U"
  "memory references valid with mov to/from a/ax"
  (and (match_code "mem")
       (match_test "rl78_virt_insns_ok ()
|| satisfies_constraint_Wab (op)
|| satisfies_constraint_Wbc (op)
|| satisfies_constraint_Wde (op)
|| satisfies_constraint_Wd2 (op)
|| satisfies_constraint_Whl (op)
|| satisfies_constraint_Wh1 (op)
|| satisfies_constraint_Whb (op)
|| satisfies_constraint_Ws1 (op)
|| satisfies_constraint_Wfr (op) ")))

(define_memory_constraint "Qbi"
  "built-in compare types"
  (match_code "eq,ne,gtu,ltu,geu,leu"))

(define_memory_constraint "Qsc"
  "synthetic compares"
  (match_code "gt,lt,ge,le"))

(define_constraint "Qs8"
  "Integer constant computed from (SUBREG (SYMREF))."
  (and (match_code "subreg")
       (match_test "GET_CODE (XEXP (op, 0)) == SYMBOL_REF"))
)