testsuite: Fix optimize_one.c FAIL on i686-linux
[official-gcc.git] / gcc / config / riscv / sync-ztso.md
blob7121b97083f3dde34bf7f8da1fb5e86702733d2d
1 ;; Machine description for RISC-V atomic operations.
2 ;; Copyright (C) 2011-2024 Free Software Foundation, Inc.
3 ;; Contributed by Andrew Waterman (andrew@sifive.com).
4 ;; Based on MIPS target for GNU compiler.
6 ;; This file is part of GCC.
8 ;; GCC is free software; you can redistribute it and/or modify
9 ;; it under the terms of the GNU General Public License as published by
10 ;; the Free Software Foundation; either version 3, or (at your option)
11 ;; any later version.
13 ;; GCC is distributed in the hope that it will be useful,
14 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
15 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16 ;; GNU General Public License for more details.
18 ;; You should have received a copy of the GNU General Public License
19 ;; along with GCC; see the file COPYING3.  If not see
20 ;; <http://www.gnu.org/licenses/>.
22 ;; Memory barriers.
24 (define_insn "mem_thread_fence_ztso"
25   [(set (match_operand:BLK 0 "" "")
26         (unspec:BLK [(match_dup 0)] UNSPEC_MEMORY_BARRIER))
27    (match_operand:SI 1 "const_int_operand" "")]  ;; model
28   "TARGET_ZTSO"
29   {
30     enum memmodel model = (enum memmodel) INTVAL (operands[1]);
31     model = memmodel_base (model);
33     if (model == MEMMODEL_SEQ_CST)
34         return "fence\trw,rw";
35     else
36         gcc_unreachable ();
37   }
38   [(set_attr "type" "atomic")
39    (set (attr "length") (const_int 4))])
41 ;; Atomic memory operations.
43 (define_insn "atomic_load_ztso<mode>"
44   [(set (match_operand:ANYI 0 "register_operand" "=r")
45         (unspec_volatile:ANYI
46             [(match_operand:ANYI 1 "memory_operand" "A")
47              (match_operand:SI 2 "const_int_operand")]  ;; model
48          UNSPEC_ATOMIC_LOAD))]
49   "TARGET_ZTSO"
50   {
51     enum memmodel model = (enum memmodel) INTVAL (operands[2]);
52     model = memmodel_base (model);
54     if (model == MEMMODEL_SEQ_CST)
55       return "fence\trw,rw\;"
56              "<load>\t%0,%1";
57     else
58       return "<load>\t%0,%1";
59   }
60   [(set_attr "type" "multi")
61    (set (attr "length")
62         (symbol_ref "(is_mm_seq_cst (memmodel_from_int (INTVAL (operands[2]))) ? 8
63                       : 4)"))])
66 (define_insn "atomic_store_ztso<mode>"
67   [(set (match_operand:ANYI 0 "memory_operand" "=A")
68         (unspec_volatile:ANYI
69             [(match_operand:ANYI 1 "reg_or_0_operand" "rJ")
70              (match_operand:SI 2 "const_int_operand")]  ;; model
71          UNSPEC_ATOMIC_STORE))]
72   "TARGET_ZTSO"
73   {
74     enum memmodel model = (enum memmodel) INTVAL (operands[2]);
75     model = memmodel_base (model);
77     if (model == MEMMODEL_SEQ_CST)
78       return "<store>\t%z1,%0\;"
79              "fence\trw,rw";
80     else
81       return "<store>\t%z1,%0";
82   }
83   [(set_attr "type" "multi")
84    (set (attr "length")
85         (symbol_ref "(is_mm_seq_cst (memmodel_from_int (INTVAL (operands[2]))) ? 8
86                       : 4)"))])