summaryrefslogtreecommitdiff
path: root/gcc/config/ft32/constraints.md
blob: 6db1a7cf8ce2b684ac568337cd5ba35ae0191663 (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
;; Constraint definitions for FT32
;; Copyright (C) 2015-2016 Free Software Foundation, Inc.
;; Contributed by FTDI <support@ftdi.com>

;; 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
;; -------------------------------------------------------------------------

(define_memory_constraint "A"
  "An absolute address."
  (and (match_code "mem")
       (match_test "(!ft32_is_mem_pm(op))")
       (ior (match_test "GET_CODE (XEXP (op, 0)) == SYMBOL_REF")
            (match_test "GET_CODE (XEXP (op, 0)) == LABEL_REF")
            (match_test "GET_CODE (XEXP (op, 0)) == CONST_INT")
            (and (match_test "(GET_CODE (XEXP (op, 0)) == PLUS)")
                 (ior (match_test "GET_CODE (XEXP (XEXP (op, 0), 0)) == SYMBOL_REF")
                      (match_test "GET_CODE (XEXP (XEXP (op, 0), 0)) == LABEL_REF")
                      (match_test "GET_CODE (XEXP (XEXP (op, 0), 0)) == CONST_INT"))
                 (ior (match_test "GET_CODE (XEXP (XEXP (op, 0), 1)) == SYMBOL_REF")
                      (match_test "GET_CODE (XEXP (XEXP (op, 0), 1)) == LABEL_REF")
                      (match_test "GET_CODE (XEXP (XEXP (op, 0), 1)) == CONST_INT"))))))

(define_memory_constraint "B"
  "An offset address."
  (and (match_code "mem")
       (match_test "(!ft32_is_mem_pm(op))")
       (match_test "(GET_CODE (XEXP (op, 0)) == PLUS)")))

(define_memory_constraint "W"
  "A register indirect memory operand."
  (and (match_code "mem")
       (match_test "!ft32_is_mem_pm(op)
        && REG_P (XEXP (op, 0))
		    && REGNO_OK_FOR_BASE_P (REGNO (XEXP (op, 0)))")))

(define_memory_constraint "e"
  "An offset address."
  (and (match_code "mem")
       (match_test "ft32_is_mem_pm(op) && (
          (GET_CODE (XEXP (op, 0)) == SYMBOL_REF) ||
          (GET_CODE (XEXP (op, 0)) == LABEL_REF) ||
          (GET_CODE (XEXP (op, 0)) == CONST_INT) ||
          (GET_CODE (XEXP (op, 0)) == CONST))"
       )))

(define_memory_constraint "f"
  "An offset address."
  (and (match_code "mem")
       (match_test "ft32_is_mem_pm(op) && (
          ((GET_CODE (XEXP (op, 0)) == PLUS)) ||
          (GET_CODE (XEXP (op, 0)) == REG))"
       )))

(define_constraint "O"
  "The constant zero or one"
  (and (match_code "const_int")
       (match_test "((ival == 0) || (ival == 1))")))

(define_constraint "I"
  "A 16-bit signed constant (-32768..32767)"
  (and (match_code "const_int")
       (match_test "ival >= -32768 && ival <= 32767")))

(define_constraint "w"
  "A bitfield mask suitable for bext or bins"
  (and (match_code "const_int")
       (match_test "ft32_as_bitfield(ival) != -1")))

(define_constraint "x"
  "An inverted bitfield mask suitable for bext or bins"
  (and (match_code "const_int")
       (match_test "ft32_as_bitfield(0xffffffff ^ ival) != -1")))

(define_constraint "L"
  "A 16-bit unsigned constant, multiple of 4 (-65532..0)"
  (and (match_code "const_int")
       (match_test "-65532 <= ival && ival <= 0 && (ival & 3) == 0")))

(define_constraint "S"
  "A 20-bit signed constant (-524288..524287)"
  (ior
    (and (match_code "const_int")
         (match_test "ival >= -524288 && ival <= 524287"))
    (match_test "GET_CODE (op) == LABEL_REF")
    (match_test "GET_CODE (op) == SYMBOL_REF")
    (match_test "GET_CODE (op) == CONST")))

(define_constraint "b"
  "A constant for a bitfield width (1..16)"
  (and (match_code "const_int")
       (match_test "1 <= ival && ival <= 16")))

(define_constraint "KA"
  "A 10-bit signed constant (-512..511)"
  (and (match_code "const_int")
       (match_test "-512 <= ival && ival <= 511")))