From: Chao-ying Fu <[email protected]> Ensure proper offset for subword data types on big-endian builds.
Before these changes, the following tests were failing: libatomic.c/atomic-compare-exchange-1.c execution test libatomic.c/atomic-compare-exchange-2.c execution test libatomic.c/atomic-exchange-1.c execution test libatomic.c/atomic-exchange-2.c execution test libatomic.c/atomic-op-1.c execution test libatomic.c/atomic-op-2.c execution test libatomic.c/generic-2.c execution test For the following configuriation: "-march=rv64imafd -mabi=lp64d -mcmodel=medlow". Signed-off-by: Aleksa Paunovic <[email protected]> libatomic/ChangeLog: * cas_n.c (SIZE): Adjust shift. * exch_n.c (SIZE): Likewise. * fop_n.c (SIZE): Likewise. * load_n.c (SIZE): Likewise. * store_n.c (SIZE): Likewise. * tas_n.c (SIZE): Likewise. --- libatomic/cas_n.c | 6 +++++- libatomic/exch_n.c | 6 +++++- libatomic/fop_n.c | 12 ++++++++++-- libatomic/load_n.c | 6 +++++- libatomic/store_n.c | 6 +++++- libatomic/tas_n.c | 6 +++++- 6 files changed, 35 insertions(+), 7 deletions(-) diff --git a/libatomic/cas_n.c b/libatomic/cas_n.c index d75c2ea5b998..ea0575922e66 100644 --- a/libatomic/cas_n.c +++ b/libatomic/cas_n.c @@ -61,7 +61,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); +#if WORDS_BIGENDIAN + shift = (WORDSIZE - N - ((uintptr_t)mptr % WORDSIZE)) * CHAR_BIT; +#else + shift = ((uintptr_t)mptr % WORDSIZE) * CHAR_BIT; +#endif mask = SIZE(MASK) << shift; } else diff --git a/libatomic/exch_n.c b/libatomic/exch_n.c index 263cf5b6ca73..5b15f1fd8285 100644 --- a/libatomic/exch_n.c +++ b/libatomic/exch_n.c @@ -78,7 +78,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); +#if WORDS_BIGENDIAN + shift = (WORDSIZE - N - ((uintptr_t)mptr % WORDSIZE)) * CHAR_BIT; +#else + shift = ((uintptr_t)mptr % WORDSIZE) * CHAR_BIT; +#endif mask = SIZE(MASK) << shift; } else diff --git a/libatomic/fop_n.c b/libatomic/fop_n.c index 954194a7371b..751569cc642f 100644 --- a/libatomic/fop_n.c +++ b/libatomic/fop_n.c @@ -114,7 +114,11 @@ SIZE(C2(libat_fetch_,NAME)) (UTYPE *mptr, UTYPE opval, int smodel) pre_barrier (smodel); wptr = (UWORD *)((uintptr_t)mptr & -WORDSIZE); - shift = (((uintptr_t)mptr % WORDSIZE) * CHAR_BIT) ^ SIZE(INVERT_MASK); +#if WORDS_BIGENDIAN + shift = (WORDSIZE - N - ((uintptr_t)mptr % WORDSIZE)) * CHAR_BIT; +#else + shift = ((uintptr_t)mptr % WORDSIZE) * CHAR_BIT; +#endif mask = SIZE(MASK) << shift; wopval = (UWORD)opval << shift; @@ -138,7 +142,11 @@ SIZE(C3(libat_,NAME,_fetch)) (UTYPE *mptr, UTYPE opval, int smodel) pre_barrier (smodel); wptr = (UWORD *)((uintptr_t)mptr & -WORDSIZE); - shift = (((uintptr_t)mptr % WORDSIZE) * CHAR_BIT) ^ SIZE(INVERT_MASK); +#if WORDS_BIGENDIAN + shift = (WORDSIZE - N - ((uintptr_t)mptr % WORDSIZE)) * CHAR_BIT; +#else + shift = ((uintptr_t)mptr % WORDSIZE) * CHAR_BIT; +#endif mask = SIZE(MASK) << shift; wopval = (UWORD)opval << shift; diff --git a/libatomic/load_n.c b/libatomic/load_n.c index 82c31cdce377..ef4acc67bac0 100644 --- a/libatomic/load_n.c +++ b/libatomic/load_n.c @@ -79,7 +79,11 @@ SIZE(libat_load) (UTYPE *mptr, int smodel) pre_barrier (smodel); wptr = (UWORD *)((uintptr_t)mptr & -WORDSIZE); - shift = (((uintptr_t)mptr % WORDSIZE) * CHAR_BIT) ^ SIZE(INVERT_MASK); +#if WORDS_BIGENDIAN + shift = (WORDSIZE - N - ((uintptr_t)mptr % WORDSIZE)) * CHAR_BIT; +#else + shift = ((uintptr_t)mptr % WORDSIZE) * CHAR_BIT; +#endif /* Exchange 0 with 0, placing the old value of *WPTR in T. */ t = 0; diff --git a/libatomic/store_n.c b/libatomic/store_n.c index 97a3133fa084..3f95110ca731 100644 --- a/libatomic/store_n.c +++ b/libatomic/store_n.c @@ -75,7 +75,11 @@ SIZE(libat_store) (UTYPE *mptr, UTYPE newval, int smodel) pre_barrier (smodel); wptr = (UWORD *)((uintptr_t)mptr & -WORDSIZE); - shift = (((uintptr_t)mptr % WORDSIZE) * CHAR_BIT) ^ SIZE(INVERT_MASK); +#if WORDS_BIGENDIAN + shift = (WORDSIZE - N - ((uintptr_t)mptr % WORDSIZE)) * CHAR_BIT; +#else + shift = ((uintptr_t)mptr % WORDSIZE) * CHAR_BIT; +#endif mask = SIZE(MASK) << shift; wnewval = (UWORD)newval << shift; diff --git a/libatomic/tas_n.c b/libatomic/tas_n.c index 036a3d23307d..9e436d2ef524 100644 --- a/libatomic/tas_n.c +++ b/libatomic/tas_n.c @@ -56,7 +56,11 @@ SIZE(libat_test_and_set) (UTYPE *mptr, int smodel) if (N < WORDSIZE) { wptr = (UWORD *)((uintptr_t)mptr & -WORDSIZE); - shift = SIZE(INVERT_MASK); +#if WORDS_BIGENDIAN + shift = (WORDSIZE - N) * CHAR_BIT; +#else + shift = 0; +#endif } else { -- 2.43.0
