Skip to content

Commit

Permalink
Enable GCC atomics on ppc and ppc64.
Browse files Browse the repository at this point in the history
  • Loading branch information
Alex Rønne Petersen committed Jul 20, 2013
1 parent 579148e commit 93acdb1
Show file tree
Hide file tree
Showing 3 changed files with 1 addition and 202 deletions.
2 changes: 1 addition & 1 deletion configure.in
Original file line number Diff line number Diff line change
Expand Up @@ -2764,7 +2764,7 @@ esac
dnl Use GCC atomic ops if they work on the target.
if test x$GCC = "xyes"; then
case $TARGET in
X86 | AMD64)
X86 | AMD64 | POWERPC | POWERPC64)
AC_DEFINE(USE_GCC_ATOMIC_OPS, 1, [...])
;;
esac
Expand Down
185 changes: 0 additions & 185 deletions mono/utils/atomic.h
Original file line number Diff line number Diff line change
Expand Up @@ -396,191 +396,6 @@ InterlockedExchangeAdd(volatile gint32 *val, gint32 add)
return(ret);
}

#elif defined(__mono_ppc__)

#ifdef G_COMPILER_CODEWARRIOR
static inline gint32 InterlockedIncrement(volatile register gint32 *val)
{
gint32 result = 0, tmp;
register gint32 result = 0;
register gint32 tmp;

asm
{
@1:
lwarx tmp, 0, val
addi result, tmp, 1
stwcx. result, 0, val
bne- @1
}

return result;
}

static inline gint32 InterlockedDecrement(register volatile gint32 *val)
{
register gint32 result = 0;
register gint32 tmp;

asm
{
@1:
lwarx tmp, 0, val
addi result, tmp, -1
stwcx. result, 0, val
bne- @1
}

return result;
}
#define InterlockedCompareExchangePointer(dest,exch,comp) (void*)InterlockedCompareExchange((volatile gint32 *)(dest), (gint32)(exch), (gint32)(comp))

static inline gint32 InterlockedCompareExchange(volatile register gint32 *dest, register gint32 exch, register gint32 comp)
{
register gint32 tmp = 0;

asm
{
@1:
lwarx tmp, 0, dest
cmpw tmp, comp
bne- @2
stwcx. exch, 0, dest
bne- @1
@2:
}

return tmp;
}
static inline gint32 InterlockedExchange(register volatile gint32 *dest, register gint32 exch)
{
register gint32 tmp = 0;

asm
{
@1:
lwarx tmp, 0, dest
stwcx. exch, 0, dest
bne- @1
}

return tmp;
}
#define InterlockedExchangePointer(dest,exch) (void*)InterlockedExchange((volatile gint32 *)(dest), (gint32)(exch))
#else

#if defined(__mono_ppc64__) && !defined(__mono_ilp32__)
#define LDREGX "ldarx"
#define STREGCXD "stdcx."
#define CMPREG "cmpd"
#else
#define LDREGX "lwarx"
#define STREGCXD "stwcx."
#define CMPREG "cmpw"
#endif

static inline gint32 InterlockedIncrement(volatile gint32 *val)
{
gint32 result = 0, tmp;

__asm__ __volatile__ ("\n1:\n\t"
"lwarx %0, 0, %2\n\t"
"addi %1, %0, 1\n\t"
"stwcx. %1, 0, %2\n\t"
"bne- 1b"
: "=&b" (result), "=&b" (tmp): "r" (val): "cc", "memory");
return result + 1;
}

static inline gint32 InterlockedDecrement(volatile gint32 *val)
{
gint32 result = 0, tmp;

__asm__ __volatile__ ("\n1:\n\t"
"lwarx %0, 0, %2\n\t"
"addi %1, %0, -1\n\t"
"stwcx. %1, 0, %2\n\t"
"bne- 1b"
: "=&b" (result), "=&b" (tmp): "r" (val): "cc", "memory");
return result - 1;
}

static inline gpointer InterlockedCompareExchangePointer (volatile gpointer *dest,
gpointer exch, gpointer comp)
{
gpointer tmp = NULL;

__asm__ __volatile__ ("\n1:\n\t"
LDREGX " %0, 0, %1\n\t"
CMPREG " %0, %2\n\t"
"bne- 2f\n\t"
STREGCXD " %3, 0, %1\n\t"
"bne- 1b\n"
"2:"
: "=&r" (tmp)
: "b" (dest), "r" (comp), "r" (exch): "cc", "memory");
return(tmp);
}

static inline gint32 InterlockedCompareExchange(volatile gint32 *dest,
gint32 exch, gint32 comp) {
gint32 tmp = 0;

__asm__ __volatile__ ("\n1:\n\t"
"lwarx %0, 0, %1\n\t"
"cmpw %0, %2\n\t"
"bne- 2f\n\t"
"stwcx. %3, 0, %1\n\t"
"bne- 1b\n"
"2:"
: "=&r" (tmp)
: "b" (dest), "r" (comp), "r" (exch): "cc", "memory");
return(tmp);
}

static inline gint32 InterlockedExchange(volatile gint32 *dest, gint32 exch)
{
gint32 tmp = 0;

__asm__ __volatile__ ("\n1:\n\t"
"lwarx %0, 0, %2\n\t"
"stwcx. %3, 0, %2\n\t"
"bne 1b"
: "=r" (tmp) : "0" (tmp), "b" (dest), "r" (exch): "cc", "memory");
return(tmp);
}

static inline gpointer InterlockedExchangePointer (volatile gpointer *dest, gpointer exch)
{
gpointer tmp = NULL;

__asm__ __volatile__ ("\n1:\n\t"
LDREGX " %0, 0, %2\n\t"
STREGCXD " %3, 0, %2\n\t"
"bne 1b"
: "=r" (tmp) : "0" (tmp), "b" (dest), "r" (exch): "cc", "memory");
return(tmp);
}

static inline gint32 InterlockedExchangeAdd(volatile gint32 *dest, gint32 add)
{
gint32 result, tmp;
__asm__ __volatile__ ("\n1:\n\t"
"lwarx %0, 0, %2\n\t"
"add %1, %0, %3\n\t"
"stwcx. %1, 0, %2\n\t"
"bne 1b"
: "=&r" (result), "=&r" (tmp)
: "r" (dest), "r" (add) : "cc", "memory");
return(result);
}

#undef LDREGX
#undef STREGCXD
#undef CMPREG

#endif /* !G_COMPILER_CODEWARRIOR */

#elif defined(__arm__)

#ifdef __native_client__
Expand Down
16 changes: 0 additions & 16 deletions mono/utils/mono-membar.h
Original file line number Diff line number Diff line change
Expand Up @@ -76,22 +76,6 @@ static inline void mono_memory_write_barrier (void)
{
mono_memory_barrier ();
}
#elif defined(__ppc__) || defined(__powerpc__) || defined(__ppc64__)
static inline void mono_memory_barrier (void)
{
__asm__ __volatile__ ("sync" : : : "memory");
}

static inline void mono_memory_read_barrier (void)
{
mono_memory_barrier ();
}

static inline void mono_memory_write_barrier (void)
{
__asm__ __volatile__ ("eieio" : : : "memory");
}

#elif defined(__arm__)
static inline void mono_memory_barrier (void)
{
Expand Down

0 comments on commit 93acdb1

Please sign in to comment.