From patchwork Fri Feb 4 00:49:50 2011 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ian Lance Taylor X-Patchwork-Id: 81783 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 29C32B7102 for ; Fri, 4 Feb 2011 11:50:07 +1100 (EST) Received: (qmail 12591 invoked by alias); 4 Feb 2011 00:50:05 -0000 Received: (qmail 12581 invoked by uid 22791); 4 Feb 2011 00:50:04 -0000 X-SWARE-Spam-Status: No, hits=-2.6 required=5.0 tests=AWL, BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, RCVD_IN_DNSWL_LOW, SPF_HELO_PASS, TW_CP, T_RP_MATCHES_RCVD, T_TVD_MIME_NO_HEADERS X-Spam-Check-By: sourceware.org Received: from smtp-out.google.com (HELO smtp-out.google.com) (74.125.121.67) by sourceware.org (qpsmtpd/0.43rc1) with ESMTP; Fri, 04 Feb 2011 00:49:57 +0000 Received: from kpbe14.cbf.corp.google.com (kpbe14.cbf.corp.google.com [172.25.105.78]) by smtp-out.google.com with ESMTP id p140nsDv026960 for ; Thu, 3 Feb 2011 16:49:54 -0800 Received: from iwc10 (iwc10.prod.google.com [10.241.65.138]) by kpbe14.cbf.corp.google.com with ESMTP id p140nrtn017561 (version=TLSv1/SSLv3 cipher=RC4-MD5 bits=128 verify=NOT) for ; Thu, 3 Feb 2011 16:49:53 -0800 Received: by iwc10 with SMTP id 10so1735331iwc.17 for ; Thu, 03 Feb 2011 16:49:53 -0800 (PST) Received: by 10.42.224.193 with SMTP id ip1mr13460031icb.479.1296780593078; Thu, 03 Feb 2011 16:49:53 -0800 (PST) Received: from coign.google.com ([216.239.45.130]) by mx.google.com with ESMTPS id c4sm79912ict.19.2011.02.03.16.49.51 (version=TLSv1/SSLv3 cipher=RC4-MD5); Thu, 03 Feb 2011 16:49:52 -0800 (PST) From: Ian Lance Taylor To: gcc-patches@gcc.gnu.org, gofrontend-dev@googlegroups.com Subject: libgo patch committed: Implement ____sync_fetch_and_add_4 if needed Date: Thu, 03 Feb 2011 16:49:50 -0800 Message-ID: User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/23.1 (gnu/linux) MIME-Version: 1.0 X-System-Of-Record: true 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 This patch to libgo implements __sync_fetch_and_add_4 if the compiler/libgcc do not provide it. The implementation is very dumb but should suffice to get code working. Bootstrapped and ran Go testsuite on x86_64-unknown-linux-gnu. Committed to mainline. Ian diff -r a2c5a4b59a32 libgo/configure.ac --- a/libgo/configure.ac Wed Feb 02 17:50:33 2011 -0800 +++ b/libgo/configure.ac Thu Feb 03 15:07:33 2011 -0800 @@ -396,6 +396,20 @@ [Define to 1 if the compiler provides the __sync_bool_compare_and_swap function for uint32]) fi +AC_CACHE_CHECK([for __sync_fetch_and_add_4], +[libgo_cv_func___sync_fetch_and_add_4], +[AC_LINK_IFELSE([ +typedef unsigned int uint32 __attribute__ ((mode (SI))); +uint32 i; +int main() { return __sync_fetch_and_add (&i, 1); } +], +[libgo_cv_func___sync_fetch_and_add_4=yes], +[libgo_cv_func___sync_fetch_and_add_4=no])]) +if test "$libgo_cv_func___sync_fetch_and_add_4" = "yes"; then + AC_DEFINE(HAVE_SYNC_FETCH_AND_ADD_4, 1, + [Define to 1 if the compiler provides the __sync_fetch_and_add function for uint32]) +fi + dnl For x86 we want to use the -minline-all-stringops option to avoid dnl forcing a stack split when calling memcpy and friends. AC_CACHE_CHECK([whether compiler supports -minline-all-stringops], diff -r a2c5a4b59a32 libgo/runtime/go-semacquire.c --- a/libgo/runtime/go-semacquire.c Wed Feb 02 17:50:33 2011 -0800 +++ b/libgo/runtime/go-semacquire.c Thu Feb 03 15:07:33 2011 -0800 @@ -117,3 +117,35 @@ __go_assert (i == 0); } } + + +#ifndef HAVE_SYNC_FETCH_AND_ADD_4 + +/* For targets which don't have the required sync support. Really + this should be provided by gcc itself. FIXME. */ + +static pthread_mutex_t sync_lock = PTHREAD_MUTEX_INITIALIZER; + +uint32 +__sync_fetch_and_add_4(uint32*, uint32) + __attribute__((visibility("hidden"))); + +uint32 +__sync_fetch_and_add_4(uint32* ptr, uint32 add) +{ + int i; + uint32 ret; + + i = pthread_mutex_lock(&sync_lock); + __go_assert(i == 0); + + ret = *ptr; + *ptr += add; + + i = pthread_mutex_unlock(&sync_lock); + __go_assert(i == 0); + + return ret; +} + +#endif