From 28d6ca4b60ef362dd30f28ed9a48f6d36c9741af Mon Sep 17 00:00:00 2001 From: Andreas Schwab Date: Mon, 31 Mar 2003 16:01:09 +0000 Subject: [PATCH] (atomic_increment_and_test): Define. (atomic_decrement_and_test): Fix test. --- sysdeps/m68k/m68020/bits/atomic.h | 42 +++++++++++++++++++++++++++++++++++---- 1 file changed, 38 insertions(+), 4 deletions(-) diff --git a/sysdeps/m68k/m68020/bits/atomic.h b/sysdeps/m68k/m68020/bits/atomic.h index 80b5b8f..6978b27 100644 --- a/sysdeps/m68k/m68020/bits/atomic.h +++ b/sysdeps/m68k/m68020/bits/atomic.h @@ -179,18 +179,52 @@ typedef uintmax_t uatomic_max_t; } \ }) +#define atomic_increment_and_test(mem) \ + ({ char __result; \ + if (sizeof (*(mem)) == 1) \ + __asm __volatile ("addq%.b %#1,%1; seq %0" \ + : "=dm" (__result), "=m" (*(mem)) \ + : "1" (*(mem))); \ + else if (sizeof (*(mem)) == 2) \ + __asm __volatile ("addq%.w %#1,%1; seq %0" \ + : "=dm" (__result), "=m" (*(mem)) \ + : "1" (*(mem))); \ + else if (sizeof (*(mem)) == 4) \ + __asm __volatile ("addq%.l %#1,%1; seq %0" \ + : "=dm" (__result), "=m" (*(mem)) \ + : "1" (*(mem))); \ + else \ + { \ + __typeof (mem) __memp = (mem); \ + __typeof (*(mem)) __oldval = *__memp; \ + __typeof (*(mem)) __temp; \ + __asm __volatile ("1: move%.l %1,%2;" \ + " move%.l %R1,%R2;" \ + " addq%.l %#1,%2;" \ + " addx%.l %5,%R2;" \ + " seq %0;" \ + " cas2%.l %1:%R1,%2:%R2,(%3):(%4);" \ + " jbne 1b" \ + : "=&dm" (__result), "=d" (__oldval), \ + "=&d" (__temp) \ + : "r" (__memp), "r" ((char *) __memp + 4), \ + "d" (0), "1" (__oldval) \ + : "memory"); \ + } \ + __result; }) + #define atomic_decrement_and_test(mem) \ ({ char __result; \ if (sizeof (*(mem)) == 1) \ - __asm __volatile ("subq%.b %#1,%1; scs %0" \ + __asm __volatile ("subq%.b %#1,%1; seq %0" \ : "=dm" (__result), "=m" (*(mem)) \ : "1" (*(mem))); \ else if (sizeof (*(mem)) == 2) \ - __asm __volatile ("subq%.w %#1,%1; scs %0" \ + __asm __volatile ("subq%.w %#1,%1; seq %0" \ : "=dm" (__result), "=m" (*(mem)) \ : "1" (*(mem))); \ else if (sizeof (*(mem)) == 4) \ - __asm __volatile ("subq%.l %#1,%1; scs %0" \ + __asm __volatile ("subq%.l %#1,%1; seq %0" \ : "=dm" (__result), "=m" (*(mem)) \ : "1" (*(mem))); \ else \ @@ -202,7 +236,7 @@ typedef uintmax_t uatomic_max_t; " move%.l %R1,%R2;" \ " subq%.l %#1,%2;" \ " subx%.l %5,%R2;" \ - " scs %0;" \ + " seq %0;" \ " cas2%.l %1:%R1,%2:%R2,(%3):(%4);" \ " jbne 1b" \ : "=&dm" (__result), "=d" (__oldval), \ -- 2.7.4