Skip to content

Commit

Permalink
microblaze: Fix atomic side effects.
Browse files Browse the repository at this point in the history
In atomic_compare_and_swapsi, add side effects to prevent incorrect
assumptions during optimization. Previously, the outputs were
considered unused; this generated assembly code with
undefined side effects after invocation of the atomic.

Signed-off-by: Kirk Meyer <kirk.meyer@sencore.com>
Signed-off-by: David Holsgrove <david.holsgrove@xilinx.com>

Conflicts:
	gcc/config/microblaze/microblaze.md

Attempts to fix picolibc Issue #460. Patch file taken and applied from:
https://github.com/Xilinx/meta-xilinx/blob/master/meta-microblaze/recipes-devtools/gcc/gcc-12/0008-Patch-microblaze-Fix-atomic-side-effects.patch

Signed-off-by: Alp Sayin <alpsayin@gmail.com>
  • Loading branch information
MBODAPAT authored and alpsayin committed Apr 18, 2023
1 parent b3e830d commit b4654fb
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 8 deletions.
3 changes: 3 additions & 0 deletions gcc/config/microblaze/microblaze.md
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,9 @@
(UNSPEC_TLS 106) ;; jump table
(UNSPEC_SET_TEXT 107) ;; set text start
(UNSPEC_TEXT 108) ;; data text relative
(UNSPECV_CAS_BOOL 201) ;; compare and swap (bool)
(UNSPECV_CAS_VAL 202) ;; compare and swap (val)
(UNSPECV_CAS_MEM 203) ;; compare and swap (mem)
])

(define_c_enum "unspec" [
Expand Down
21 changes: 13 additions & 8 deletions gcc/config/microblaze/sync.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,14 +18,19 @@
;; <http://www.gnu.org/licenses/>.

(define_insn "atomic_compare_and_swapsi"
[(match_operand:SI 0 "register_operand" "=&d") ;; bool output
(match_operand:SI 1 "register_operand" "=&d") ;; val output
(match_operand:SI 2 "nonimmediate_operand" "+Q") ;; memory
(match_operand:SI 3 "register_operand" "d") ;; expected value
(match_operand:SI 4 "register_operand" "d") ;; desired value
(match_operand:SI 5 "const_int_operand" "") ;; is_weak
(match_operand:SI 6 "const_int_operand" "") ;; mod_s
(match_operand:SI 7 "const_int_operand" "") ;; mod_f
[(set (match_operand:SI 0 "register_operand" "=&d") ;; bool output
(unspec_volatile:SI
[(match_operand:SI 2 "nonimmediate_operand" "+Q") ;; memory
(match_operand:SI 3 "register_operand" "d") ;; expected value
(match_operand:SI 4 "register_operand" "d")] ;; desired value
UNSPECV_CAS_BOOL))
(set (match_operand:SI 1 "register_operand" "=&d") ;; val output
(unspec_volatile:SI [(const_int 0)] UNSPECV_CAS_VAL))
(set (match_dup 2)
(unspec_volatile:SI [(const_int 0)] UNSPECV_CAS_MEM))
(match_operand:SI 5 "const_int_operand" "") ;; is_weak
(match_operand:SI 6 "const_int_operand" "") ;; mod_s
(match_operand:SI 7 "const_int_operand" "") ;; mod_f
(clobber (match_scratch:SI 8 "=&d"))]
""
{
Expand Down

0 comments on commit b4654fb

Please sign in to comment.