1 # --- T2-COPYRIGHT-NOTE-BEGIN ---
2 # T2 SDE: package/*/gcc/hotfix-revert-atomics.patch.microblaze
3 # Copyright (C) 2024 The T2 SDE Project
5 # This Copyright note is generated by scripts/Create-CopyPatch,
6 # more information can be found in the files COPYING and README.
8 # This patch file is dual-licensed. It is available under the license the
9 # patched project is licensed under, as long as it is an OpenSource license
10 # as defined at http://www.opensource.org/ (e.g. BSD, X11) or under the terms
11 # of the GNU General Public License version 2 as used by the T2 SDE.
12 # --- T2-COPYRIGHT-NOTE-END ---
14 diff --git a/gcc/builtins.cc b/gcc/builtins.cc
15 index 40dfd36a319..6e4274bb2a4 100644
18 @@ -8387,10 +8387,7 @@ expand_builtin (tree exp, rtx target, rtx subtarget, machine_mode mode,
21 case BUILT_IN_ATOMIC_TEST_AND_SET:
22 - target = expand_builtin_atomic_test_and_set (exp, target);
26 + return expand_builtin_atomic_test_and_set (exp, target);
28 case BUILT_IN_ATOMIC_CLEAR:
29 return expand_builtin_atomic_clear (exp);
30 diff --git a/gcc/optabs.cc b/gcc/optabs.cc
31 index e1898da2280..8b96f23aec0 100644
34 @@ -7080,17 +7080,25 @@ expand_atomic_test_and_set (rtx target, rtx mem, enum memmodel model)
35 /* Recall that the legacy lock_test_and_set optab was allowed to do magic
36 things with the value 1. Thus we try again without trueval. */
37 if (!ret && targetm.atomic_test_and_set_trueval != 1)
38 + ret = maybe_emit_sync_lock_test_and_set (subtarget, mem, const1_rtx, model);
40 + /* Failing all else, assume a single threaded environment and simply
41 + perform the operation. */
44 - ret = maybe_emit_sync_lock_test_and_set (subtarget, mem, const1_rtx, model);
45 + /* If the result is ignored skip the move to target. */
46 + if (subtarget != const0_rtx)
47 + emit_move_insn (subtarget, mem);
51 - /* Rectify the not-one trueval. */
52 - ret = emit_store_flag_force (target, NE, ret, const0_rtx, mode, 0, 1);
55 + emit_move_insn (mem, trueval);
59 + /* Recall that have to return a boolean value; rectify if trueval
60 + is not exactly one. */
61 + if (targetm.atomic_test_and_set_trueval != 1)
62 + ret = emit_store_flag_force (target, NE, ret, const0_rtx, mode, 0, 1);