Debian Codegraph @

gcc/config/microblaze/sync.md

raw
1 ;; Machine description for Xilinx MicroBlaze synchronization instructions.
2 ;; Copyright (C) 2011-2025 Free Software Foundation, Inc.
3 ;;
4 ;; This file is part of GCC.
5 ;;
6 ;; GCC is free software; you can redistribute it and/or modify it
7 ;; under the terms of the GNU General Public License as published
8 ;; by the Free Software Foundation; either version 3, or (at your
9 ;; option) any later version.
10 ;;
11 ;; GCC is distributed in the hope that it will be useful, but WITHOUT
12 ;; ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
13 ;; or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public
14 ;; License for more details.
15 ;;
16 ;; You should have received a copy of the GNU General Public License
17 ;; along with GCC; see the file COPYING3. If not see
18 ;; <http://www.gnu.org/licenses/>.
19
20 (define_insn "atomic_compare_and_swapsi"
21 [(set (match_operand:SI 0 "register_operand" "=&d") ;; bool output
22 (unspec_volatile:SI
23 [(match_operand:SI 2 "nonimmediate_operand" "+Q") ;; memory
24 (match_operand:SI 3 "register_operand" "d") ;; expected value
25 (match_operand:SI 4 "register_operand" "d")] ;; desired value
26 UNSPECV_CAS_BOOL))
27 (set (match_operand:SI 1 "register_operand" "=&d") ;; val output
28 (unspec_volatile:SI [(const_int 0)] UNSPECV_CAS_VAL))
29 (set (match_dup 2)
30 (unspec_volatile:SI [(const_int 0)] UNSPECV_CAS_MEM))
31 (match_operand:SI 5 "const_int_operand" "") ;; is_weak
32 (match_operand:SI 6 "const_int_operand" "") ;; mod_s
33 (match_operand:SI 7 "const_int_operand" "") ;; mod_f
34 (clobber (match_scratch:SI 8 "=&d"))]
35 ""
36 {
37 return "add \t%0,r0,r0\n\t"
38 "lwx \t%1,%y2,r0\n\t"
39 "addic\t%8,r0,0\n\t"
40 "bnei \t%8,.-8\n\t"
41 "cmp \t%8,%1,%3\n\t"
42 "bnei \t%8,.+20\n\t"
43 "swx \t%4,%y2,r0\n\t"
44 "addic\t%8,r0,0\n\t"
45 "bnei \t%8,.-28\n\t"
46 "addi \t%0,r0,1";
47 }
48 [(set_attr "type" "atomic")
49 (set_attr "mode" "SI")
50 (set_attr "length" "40")]
51 )
52
53 ;;
54 ;;
55 ;;
56 ;;
57 (define_insn "atomic_fetch_<atomic_optab>si"
58 [(set (match_operand:SI 0 "register_operand" "=&d")
59 (match_operand:SI 1 "memory_operand" "+Q"))
60 (set (match_dup 1)
61 (unspec_volatile:SI
62 [(any_atomic:SI (match_dup 1)
63 (match_operand:SI 2 "register_operand" "d"))
64 (match_operand:SI 3 "const_int_operand")] ;; model
65 UNSPECV_ATOMIC_FETCH_OP))
66 (clobber (match_scratch:SI 4 "=&d"))] ;; tmp_1
67 ""
68 {
69 return
70 "lwx \t%0,%y1,r0\n\t"
71 "addic\t%4,r0,0\n\t"
72 "bnei \t%4,.-8\n\t"
73 "<atomic_optab>\t%4,%0,%2\n\t"
74 "swx \t%4,%y1,r0\n\t"
75 "addic\t%4,r0,0\n\t"
76 "bnei \t%4,.-24";
77 }
78 [(set_attr "type" "atomic")
79 (set_attr "mode" "SI")
80 (set_attr "length" "28")])
81
82 ;;
83 ;; MicroBlaze only supports lx/sx instructions for word mode only
84 ;;
85 ;; Use shift|mask magic to implement atomic_test_and_set using lwx/swx
86 ;;
87 (define_expand "atomic_test_and_set"
88 [(match_operand:QI 0 "register_operand" "") ;; bool output
89 (match_operand:QI 1 "memory_operand" "m") ;; memory
90 (match_operand:SI 2 "const_int_operand" "")] ;; model
91 ""
92 {
93 rtx old = gen_reg_rtx (SImode);
94 rtx mem = operands[1];
95 rtx model = operands[2];
96 rtx set = gen_reg_rtx (SImode);
97 rtx aligned_mem = gen_reg_rtx (SImode);
98 rtx shift = gen_reg_rtx (SImode);
99
100 microblaze_subword_address (mem, &aligned_mem, &shift);
101
102 emit_move_insn (set, GEN_INT (1));
103 rtx shifted_set = gen_reg_rtx (SImode);
104
105 emit_move_insn (shifted_set, gen_rtx_ASHIFT (SImode, set, shift));
106
107 emit_insn (gen_atomic_fetch_orsi (old, aligned_mem, shifted_set, model));
108
109 emit_move_insn (old, gen_rtx_ASHIFTRT (SImode, old, shift));
110
111 emit_move_insn (operands[0], gen_lowpart (QImode, old));
112
113 DONE;
114 })