1 ;; GCC machine description for IA-64 synchronization instructions.
3 ;; Free Software Foundation, Inc.
5 ;; This file is part of GCC.
7 ;; GCC is free software; you can redistribute it and/or modify
8 ;; it under the terms of the GNU General Public License as published by
9 ;; the Free Software Foundation; either version 2, or (at your option)
12 ;; GCC is distributed in the hope that it will be useful,
13 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
14 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 ;; GNU General Public License for more details.
17 ;; You should have received a copy of the GNU General Public License
18 ;; along with GCC; see the file COPYING. If not, write to
19 ;; the Free Software Foundation, 51 Franklin Street, Fifth Floor,
20 ;; Boston, MA 02110-1301, USA.
22 (define_mode_macro IMODE [QI HI SI DI])
23 (define_mode_macro I124MODE [QI HI SI])
24 (define_mode_macro I48MODE [SI DI])
25 (define_mode_attr modesuffix [(QI "1") (HI "2") (SI "4") (DI "8")])
27 (define_code_macro FETCHOP [plus minus ior xor and])
28 (define_code_attr fetchop_name
29 [(plus "add") (minus "sub") (ior "ior") (xor "xor") (and "and")])
31 (define_insn "memory_barrier"
32 [(set (mem:BLK (match_scratch:DI 0 "X"))
33 (unspec:BLK [(mem:BLK (match_scratch:DI 1 "X"))] UNSPEC_MF))]
36 [(set_attr "itanium_class" "syst_m")])
38 (define_insn "fetchadd_acq_<mode>"
39 [(set (match_operand:I48MODE 0 "gr_register_operand" "=r")
40 (match_operand:I48MODE 1 "not_postinc_memory_operand" "+S"))
42 (unspec:I48MODE [(match_dup 1)
43 (match_operand:I48MODE 2 "fetchadd_operand" "n")]
44 UNSPEC_FETCHADD_ACQ))]
46 "fetchadd<modesuffix>.acq %0 = %1, %2"
47 [(set_attr "itanium_class" "sem")])
49 (define_expand "sync_<fetchop_name><mode>"
50 [(set (match_operand:IMODE 0 "memory_operand" "")
51 (FETCHOP:IMODE (match_dup 0)
52 (match_operand:IMODE 1 "general_operand" "")))]
55 ia64_expand_atomic_op (<CODE>, operands[0], operands[1], NULL, NULL);
59 (define_expand "sync_nand<mode>"
60 [(set (match_operand:IMODE 0 "memory_operand" "")
61 (and:IMODE (not:IMODE (match_dup 0))
62 (match_operand:IMODE 1 "general_operand" "")))]
65 ia64_expand_atomic_op (NOT, operands[0], operands[1], NULL, NULL);
69 (define_expand "sync_old_<fetchop_name><mode>"
70 [(set (match_operand:IMODE 0 "gr_register_operand" "")
72 (match_operand:IMODE 1 "memory_operand" "")
73 (match_operand:IMODE 2 "general_operand" "")))]
76 ia64_expand_atomic_op (<CODE>, operands[1], operands[2], operands[0], NULL);
80 (define_expand "sync_old_nand<mode>"
81 [(set (match_operand:IMODE 0 "gr_register_operand" "")
83 (not:IMODE (match_operand:IMODE 1 "memory_operand" ""))
84 (match_operand:IMODE 2 "general_operand" "")))]
87 ia64_expand_atomic_op (NOT, operands[1], operands[2], operands[0], NULL);
91 (define_expand "sync_new_<fetchop_name><mode>"
92 [(set (match_operand:IMODE 0 "gr_register_operand" "")
94 (match_operand:IMODE 1 "memory_operand" "")
95 (match_operand:IMODE 2 "general_operand" "")))]
98 ia64_expand_atomic_op (<CODE>, operands[1], operands[2], NULL, operands[0]);
102 (define_expand "sync_new_nand<mode>"
103 [(set (match_operand:IMODE 0 "gr_register_operand" "")
105 (not:IMODE (match_operand:IMODE 1 "memory_operand" ""))
106 (match_operand:IMODE 2 "general_operand" "")))]
109 ia64_expand_atomic_op (NOT, operands[1], operands[2], NULL, operands[0]);
113 (define_expand "sync_compare_and_swap<mode>"
114 [(match_operand:IMODE 0 "gr_register_operand" "")
115 (match_operand:IMODE 1 "memory_operand" "")
116 (match_operand:IMODE 2 "gr_register_operand" "")
117 (match_operand:IMODE 3 "gr_register_operand" "")]
120 rtx ccv = gen_rtx_REG (DImode, AR_CCV_REGNUM);
123 convert_move (ccv, operands[2], 1);
126 if (GET_MODE (dst) != DImode)
127 dst = gen_reg_rtx (DImode);
129 emit_insn (gen_memory_barrier ());
130 emit_insn (gen_cmpxchg_rel_<mode> (dst, operands[1], ccv, operands[3]));
132 if (dst != operands[0])
133 emit_move_insn (operands[0], gen_lowpart (<MODE>mode, dst));
137 (define_insn "cmpxchg_rel_<mode>"
138 [(set (match_operand:DI 0 "gr_register_operand" "=r")
140 (match_operand:I124MODE 1 "not_postinc_memory_operand" "+S")))
144 (match_operand:DI 2 "ar_ccv_reg_operand" "")
145 (match_operand:I124MODE 3 "gr_register_operand" "r")]
146 UNSPEC_CMPXCHG_ACQ))]
148 "cmpxchg<modesuffix>.rel %0 = %1, %3, %2"
149 [(set_attr "itanium_class" "sem")])
151 (define_insn "cmpxchg_rel_di"
152 [(set (match_operand:DI 0 "gr_register_operand" "=r")
153 (match_operand:DI 1 "not_postinc_memory_operand" "+S"))
155 (unspec:DI [(match_dup 1)
156 (match_operand:DI 2 "ar_ccv_reg_operand" "")
157 (match_operand:DI 3 "gr_register_operand" "r")]
158 UNSPEC_CMPXCHG_ACQ))]
160 "cmpxchg8.rel %0 = %1, %3, %2"
161 [(set_attr "itanium_class" "sem")])
163 (define_insn "sync_lock_test_and_set<mode>"
164 [(set (match_operand:IMODE 0 "gr_register_operand" "=r")
165 (match_operand:IMODE 1 "not_postinc_memory_operand" "+S"))
167 (match_operand:IMODE 2 "gr_register_operand" "r"))]
169 "xchg<modesuffix> %0 = %1, %2"
170 [(set_attr "itanium_class" "sem")])
172 (define_expand "sync_lock_release<mode>"
173 [(set (match_operand:IMODE 0 "memory_operand" "")
174 (match_operand:IMODE 1 "gr_reg_or_0_operand" ""))]
177 gcc_assert (MEM_VOLATILE_P (operands[0]));