diff options
author | Andrew Waterman <waterman@cs.berkeley.edu> | 2015-01-21 17:17:03 +0000 |
---|---|---|
committer | Richard Henderson <rth@gcc.gnu.org> | 2015-01-21 09:17:03 -0800 |
commit | 122a5d603b4c67952fb32742775e8a3a478c2075 (patch) | |
tree | 789c86c5c0fcde33931533dbfc334718e3029274 /libatomic/fop_n.c | |
parent | f81f49c180b52f3c408923f8efb09fba557f467e (diff) |
Avoid misaligned atomic operations
Andrew Waterman <waterman@cs.berkeley.edu>
* fop_n.c (libat_fetch_op): Align address to word boundary.
(libat_op_fetch): Likewise.
From-SVN: r219954
Diffstat (limited to 'libatomic/fop_n.c')
-rw-r--r-- | libatomic/fop_n.c | 12 |
1 files changed, 6 insertions, 6 deletions
diff --git a/libatomic/fop_n.c b/libatomic/fop_n.c index 307184d429a..854d648638d 100644 --- a/libatomic/fop_n.c +++ b/libatomic/fop_n.c @@ -112,9 +112,9 @@ SIZE(C2(libat_fetch_,NAME)) (UTYPE *mptr, UTYPE opval, int smodel) pre_barrier (smodel); - wptr = (UWORD *)mptr; - shift = 0; - mask = -1; + wptr = (UWORD *)((uintptr_t)mptr & -WORDSIZE); + shift = (((uintptr_t)mptr % WORDSIZE) * CHAR_BIT) ^ SIZE(INVERT_MASK); + mask = SIZE(MASK) << shift; wopval = (UWORD)opval << shift; woldval = __atomic_load_n (wptr, __ATOMIC_RELAXED); @@ -136,9 +136,9 @@ SIZE(C3(libat_,NAME,_fetch)) (UTYPE *mptr, UTYPE opval, int smodel) pre_barrier (smodel); - wptr = (UWORD *)mptr; - shift = 0; - mask = -1; + wptr = (UWORD *)((uintptr_t)mptr & -WORDSIZE); + shift = (((uintptr_t)mptr % WORDSIZE) * CHAR_BIT) ^ SIZE(INVERT_MASK); + mask = SIZE(MASK) << shift; wopval = (UWORD)opval << shift; woldval = __atomic_load_n (wptr, __ATOMIC_RELAXED); |