From patchwork Tue Jul 20 16:33:08 2010 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ramana Radhakrishnan X-Patchwork-Id: 59345 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from sourceware.org (server1.sourceware.org [209.132.180.131]) by ozlabs.org (Postfix) with SMTP id 8CC62B6EFF for ; Wed, 21 Jul 2010 02:33:25 +1000 (EST) Received: (qmail 4558 invoked by alias); 20 Jul 2010 16:33:21 -0000 Received: (qmail 4543 invoked by uid 22791); 20 Jul 2010 16:33:19 -0000 X-SWARE-Spam-Status: No, hits=-2.0 required=5.0 tests=AWL, BAYES_00, T_RP_MATCHES_RCVD X-Spam-Check-By: sourceware.org Received: from cam-admin0.cambridge.arm.com (HELO cam-admin0.cambridge.arm.com) (217.140.96.50) by sourceware.org (qpsmtpd/0.43rc1) with ESMTP; Tue, 20 Jul 2010 16:33:14 +0000 Received: from cam-owa1.Emea.Arm.com (cam-owa1.emea.arm.com [10.1.255.62]) by cam-admin0.cambridge.arm.com (8.12.6/8.12.6) with ESMTP id o6KGXBF9018051 for ; Tue, 20 Jul 2010 17:33:11 +0100 (BST) Received: from [10.1.66.29] ([10.1.255.212]) by cam-owa1.Emea.Arm.com with Microsoft SMTPSVC(6.0.3790.0); Tue, 20 Jul 2010 17:33:09 +0100 Subject: [Patch ARM] Fix atomic nand operations. From: Ramana Radhakrishnan Reply-To: ramana.radhakrishnan@arm.com To: gcc-patches@gcc.gnu.org Cc: Richard Earnshaw , Marcus Shawcroft Date: Tue, 20 Jul 2010 17:33:08 +0100 Message-Id: <1279643588.23062.16.camel@e102325-lin.cambridge.arm.com> Mime-Version: 1.0 X-IsSubscribed: yes Mailing-List: contact gcc-patches-help@gcc.gnu.org; run by ezmlm Precedence: bulk List-Id: List-Unsubscribe: List-Archive: List-Post: List-Help: Sender: gcc-patches-owner@gcc.gnu.org Delivered-To: mailing list gcc-patches@gcc.gnu.org Hi , Marcus pointed out that the way we implement __sync_nand_and_fetch in the helper routines is broken today because of the way we test the value we get. http://gcc.gnu.org/onlinedocs/gcc-4.4.4/gcc/Atomic-Builtins.html#Atomic-Builtins and later - state that : Note: GCC 4.4 and later implement __sync_fetch_and_nand builtin as *ptr = ~(tmp & value) instead of *ptr = ~tmp & value. Shouldn't the implementation of this be changed to reflect the semantics of the documentation in all release branches ? Ok to commit on trunk and all release branches ? cheers Ramana 2010-07-20 Ramana Radhakrishnan * config/arm/linux-atomic.c (FETCH_AND_OP_WORD): Add appropriate paranthesis for prefix operations. (OP_AND_FETCH_WORD): Likewise. (SUBWORD_SYNC_OP): Likewise. Index: gcc/config/arm/linux-atomic.c =================================================================== --- gcc/config/arm/linux-atomic.c (revision 162305) +++ gcc/config/arm/linux-atomic.c (working copy) @@ -56,7 +56,7 @@ typedef void (__kernel_dmb_t) (void); \ do { \ tmp = *ptr; \ - failure = __kernel_cmpxchg (tmp, PFX_OP tmp INF_OP val, ptr); \ + failure = __kernel_cmpxchg (tmp, PFX_OP (tmp INF_OP val), ptr); \ } while (failure != 0); \ \ return tmp; \ @@ -88,8 +88,8 @@ FETCH_AND_OP_WORD (nand, ~, &) \ do { \ oldval = *wordptr; \ - newval = ((PFX_OP ((oldval & mask) >> shift) \ - INF_OP (unsigned int) val) << shift) & mask; \ + newval = ((PFX_OP (((oldval & mask) >> shift) \ + INF_OP (unsigned int) val) << shift)) & mask; \ newval |= oldval & ~mask; \ failure = __kernel_cmpxchg (oldval, newval, wordptr); \ } while (failure != 0); \ @@ -119,10 +119,10 @@ SUBWORD_SYNC_OP (nand, ~, &, char, 1, ol \ do { \ tmp = *ptr; \ - failure = __kernel_cmpxchg (tmp, PFX_OP tmp INF_OP val, ptr); \ + failure = __kernel_cmpxchg (tmp, PFX_OP (tmp INF_OP val), ptr); \ } while (failure != 0); \ \ - return PFX_OP tmp INF_OP val; \ + return PFX_OP (tmp INF_OP val); \ } OP_AND_FETCH_WORD (add, , +)