From: Andrew Waterman Date: Wed, 21 Jan 2015 17:17:03 +0000 (+0000) Subject: Avoid misaligned atomic operations X-Git-Url: https://git.libre-soc.org/?a=commitdiff_plain;h=122a5d603b4c67952fb32742775e8a3a478c2075;p=gcc.git Avoid misaligned atomic operations Andrew Waterman * fop_n.c (libat_fetch_op): Align address to word boundary. (libat_op_fetch): Likewise. From-SVN: r219954 --- diff --git a/libatomic/ChangeLog b/libatomic/ChangeLog index ef5b6cdf0bf..50487255105 100644 --- a/libatomic/ChangeLog +++ b/libatomic/ChangeLog @@ -1,3 +1,8 @@ +2015-01-21 Andrew Waterman + + * fop_n.c (libat_fetch_op): Align address to word boundary. + (libat_op_fetch): Likewise. + 2015-01-16 Ilya Verbin PR testsuite/64605 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);