@@ -60,7 +60,11 @@ SIZE(libat_compare_exchange) (UTYPE *mptr, UTYPE *eptr, UTYPE newval,
if (N < WORDSIZE)
{
wptr = (UWORD *)((uintptr_t)mptr & -WORDSIZE);
- shift = (((uintptr_t)mptr % WORDSIZE) * CHAR_BIT) ^ SIZE(INVERT_MASK);
+#ifdef __ARMEB__
+ shift = ((WORDSIZE - N - ((uintptr_t)mptr % WORDSIZE)) * CHAR_BIT);
+#else
+ shift = (((uintptr_t)mptr % WORDSIZE) * CHAR_BIT);
+#endif
mask = SIZE(MASK) << shift;
}
else
@@ -88,7 +88,11 @@ SIZE(libat_exchange) (UTYPE *mptr, UTYPE newval, int smodel)
__atomic_thread_fence (__ATOMIC_SEQ_CST);
wptr = (UWORD *)((uintptr_t)mptr & -WORDSIZE);
- shift = (((uintptr_t)mptr % WORDSIZE) * CHAR_BIT) ^ INVERT_MASK_1;
+#ifdef __ARMEB__
+ shift = ((WORDSIZE - N - ((uintptr_t)mptr % WORDSIZE)) * CHAR_BIT);
+#else
+ shift = (((uintptr_t)mptr % WORDSIZE) * CHAR_BIT);
+#endif
mask = MASK_1 << shift;
wnewval = newval << shift;
@@ -77,7 +77,11 @@ SIZE(libat_exchange) (UTYPE *mptr, UTYPE newval, int smodel)
if (N < WORDSIZE)
{
wptr = (UWORD *)((uintptr_t)mptr & -WORDSIZE);
- shift = (((uintptr_t)mptr % WORDSIZE) * CHAR_BIT) ^ SIZE(INVERT_MASK);
+#ifdef __ARMEB__
+ shift = ((WORDSIZE - N - ((uintptr_t)mptr % WORDSIZE)) * CHAR_BIT);
+#else
+ shift = (((uintptr_t)mptr % WORDSIZE) * CHAR_BIT);
+#endif
mask = SIZE(MASK) << shift;
}
else
@@ -113,7 +113,11 @@ SIZE(C2(libat_fetch_,NAME)) (UTYPE *mptr, UTYPE opval, int smodel)
pre_barrier (smodel);
wptr = (UWORD *)mptr;
+#ifdef __ARMEB__
+ shift = (WORDSIZE - N) * CHAR_BIT;
+#else
shift = 0;
+#endif
mask = -1;
wopval = (UWORD)opval << shift;
@@ -137,7 +141,11 @@ SIZE(C3(libat_,NAME,_fetch)) (UTYPE *mptr, UTYPE opval, int smodel)
pre_barrier (smodel);
wptr = (UWORD *)mptr;
+#ifdef __ARMEB__
+ shift = (WORDSIZE - N) * CHAR_BIT;
+#else
shift = 0;
+#endif
mask = -1;
wopval = (UWORD)opval << shift;