This is the mail archive of the
gcc@gcc.gnu.org
mailing list for the GCC project.
Re: m68k problem and libstdc++
- From: Peter Barada <pbarada at mail dot wm dot sps dot mot dot com>
- To: dalej at apple dot com
- Cc: rodrigc at mediaone dot net, dalej at apple dot com, libstdc++ at gcc dot gnu dot org, gcc at gcc dot gnu dot org, schwab at suse dot de
- Date: Fri, 4 Jan 2002 10:58:34 -0500
- Subject: Re: m68k problem and libstdc++
- References: <F5FF9F6A-00B0-11D6-94EE-003065C86F94@apple.com>
>CAS is an indivisible instruction intended to allow synchronization
>of multiple processors (the sequence above is straight out of one of
>Motorola's examples). I don't think there's any way to get that
>functionality on pre-68020 chips, so you'll have to conditionalize
>it away somehow. If supporting such chips is no longer required,
>and I would guess it's not, the easiest fix will be to pass a flag
>to the assembler telling it the target is 68020 or higher.
>(I know the architecture fairly well, at least I used to, but I'm
>not expert on multiprocessor synchronization.)
Since the straight 68k and 5x0x don't support CAS, you could:
#if defined(__mc68000__) || defined(__mcf5200__)
static inline _Atomic_word
__attribute__ ((__unused__))
__exchange_and_add (volatile _Atomic_word *__mem, int __val)
{
register _Atomic_word __result = *__mem;
register _Atomic_word __temp;
__asm__ __volatile__ ("1: move%.l %0,%1;"
" add%.l %2,%1;"
" cmp%.l %0,%3;"
" jbeq 2f;"
" move%.l %3,%0;"
" jra 1b;"
"2: move%.l %1,%3"
: "=d" (__result), "=&d" (__temp)
: "d" (__val), "m" (*__mem), "0" (__result)
: "memory");
return __result;
}
#else
static inline _Atomic_word
__attribute__ ((__unused__))
__exchange_and_add (volatile _Atomic_word *__mem, int __val)
{
register _Atomic_word __result = *__mem;
register _Atomic_word __temp;
__asm__ __volatile__ ("1: move%.l %0,%1;"
" add%.l %2,%1;"
" cas%.l %0,%1,%3;"
" jbne 1b"
: "=d" (__result), "=&d" (__temp)
: "d" (__val), "m" (*__mem), "0" (__result)
: "memory");
return __result;
}
#endif
That is if I read the manual correctly on cas which indicates that:
cas Dc,Du,<ea>
CAS compares the effective address operand to the compare
operand(Dc). If the operands are equal, the instruction writes the
update operand(Du) to the effective address operand; otherwise the
instruction writes the effective address operand to the compare
operand(Dc).
--
Peter Barada Peter.Barada@motorola.com
Wizard 781-852-2768 (direct)
WaveMark Solutions(wholly owned by Motorola) 781-270-0193 (fax)