From owner-svn-src-stable-9@FreeBSD.ORG Fri May 25 17:50:51 2012 Return-Path: Delivered-To: svn-src-stable-9@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34]) by hub.freebsd.org (Postfix) with ESMTP id 7F665106566C; Fri, 25 May 2012 17:50:51 +0000 (UTC) (envelope-from marius@FreeBSD.org) Received: from svn.freebsd.org (svn.freebsd.org [IPv6:2001:4f8:fff6::2c]) by mx1.freebsd.org (Postfix) with ESMTP id 657FB8FC0C; Fri, 25 May 2012 17:50:51 +0000 (UTC) Received: from svn.freebsd.org (localhost [127.0.0.1]) by svn.freebsd.org (8.14.4/8.14.4) with ESMTP id q4PHopFx024910; Fri, 25 May 2012 17:50:51 GMT (envelope-from marius@svn.freebsd.org) Received: (from marius@localhost) by svn.freebsd.org (8.14.4/8.14.4/Submit) id q4PHop6g024892; Fri, 25 May 2012 17:50:51 GMT (envelope-from marius@svn.freebsd.org) Message-Id: <201205251750.q4PHop6g024892@svn.freebsd.org> From: Marius Strobl Date: Fri, 25 May 2012 17:50:51 +0000 (UTC) To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-stable@freebsd.org, svn-src-stable-9@freebsd.org X-SVN-Group: stable-9 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Cc: Subject: svn commit: r236016 - stable/9/lib/libcompiler_rt X-BeenThere: svn-src-stable-9@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: SVN commit messages for only the 9-stable src tree List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Fri, 25 May 2012 17:50:51 -0000 Author: marius Date: Fri May 25 17:50:50 2012 New Revision: 236016 URL: http://svn.freebsd.org/changeset/base/236016 Log: MFC: r228919 Add locally implemented atomic intrinsics to libcompiler_rt. The built-in atomic operations are not implemented in our version of GCC 4.2 for the ARM and MIPS architectures. Instead of emitting locked instructions, they generate calls to functions that can be implemented in the C runtime. Only implement the atomic operations that are used by for datatype sizes that are supported by atomic(9). This means that on these architectures, we can only use atomic operations on 32-bits and 64-bits variables, which is typically sufficient. This makes work on all architectures except MIPS, since MIPS still uses libgcc. Added: stable/9/lib/libcompiler_rt/__sync_fetch_and_add_4.c - copied unchanged from r228919, head/lib/libcompiler_rt/__sync_fetch_and_add_4.c stable/9/lib/libcompiler_rt/__sync_fetch_and_add_8.c - copied unchanged from r228919, head/lib/libcompiler_rt/__sync_fetch_and_add_8.c stable/9/lib/libcompiler_rt/__sync_fetch_and_and_4.c - copied unchanged from r228919, head/lib/libcompiler_rt/__sync_fetch_and_and_4.c stable/9/lib/libcompiler_rt/__sync_fetch_and_and_8.c - copied unchanged from r228919, head/lib/libcompiler_rt/__sync_fetch_and_and_8.c stable/9/lib/libcompiler_rt/__sync_fetch_and_op_n.h - copied unchanged from r228919, head/lib/libcompiler_rt/__sync_fetch_and_op_n.h stable/9/lib/libcompiler_rt/__sync_fetch_and_or_4.c - copied unchanged from r228919, head/lib/libcompiler_rt/__sync_fetch_and_or_4.c stable/9/lib/libcompiler_rt/__sync_fetch_and_or_8.c - copied unchanged from r228919, head/lib/libcompiler_rt/__sync_fetch_and_or_8.c stable/9/lib/libcompiler_rt/__sync_fetch_and_sub_4.c - copied unchanged from r228919, head/lib/libcompiler_rt/__sync_fetch_and_sub_4.c stable/9/lib/libcompiler_rt/__sync_fetch_and_sub_8.c - copied unchanged from r228919, head/lib/libcompiler_rt/__sync_fetch_and_sub_8.c stable/9/lib/libcompiler_rt/__sync_fetch_and_xor_4.c - copied unchanged from r228919, head/lib/libcompiler_rt/__sync_fetch_and_xor_4.c stable/9/lib/libcompiler_rt/__sync_fetch_and_xor_8.c - copied unchanged from r228919, head/lib/libcompiler_rt/__sync_fetch_and_xor_8.c stable/9/lib/libcompiler_rt/__sync_lock_test_and_set_4.c - copied unchanged from r228919, head/lib/libcompiler_rt/__sync_lock_test_and_set_4.c stable/9/lib/libcompiler_rt/__sync_lock_test_and_set_8.c - copied unchanged from r228919, head/lib/libcompiler_rt/__sync_lock_test_and_set_8.c stable/9/lib/libcompiler_rt/__sync_val_compare_and_swap_4.c - copied unchanged from r228919, head/lib/libcompiler_rt/__sync_val_compare_and_swap_4.c stable/9/lib/libcompiler_rt/__sync_val_compare_and_swap_8.c - copied unchanged from r228919, head/lib/libcompiler_rt/__sync_val_compare_and_swap_8.c stable/9/lib/libcompiler_rt/__sync_val_compare_and_swap_n.h - copied unchanged from r228919, head/lib/libcompiler_rt/__sync_val_compare_and_swap_n.h Modified: stable/9/lib/libcompiler_rt/Makefile Directory Properties: stable/9/lib/libcompiler_rt/ (props changed) Modified: stable/9/lib/libcompiler_rt/Makefile ============================================================================== --- stable/9/lib/libcompiler_rt/Makefile Fri May 25 17:48:45 2012 (r236015) +++ stable/9/lib/libcompiler_rt/Makefile Fri May 25 17:50:50 2012 (r236016) @@ -148,6 +148,26 @@ SRCF+= adddf3 \ umodsi3 .endif +# FreeBSD-specific atomic intrinsics. +.if ${MACHINE_CPUARCH} == "arm" || ${MACHINE_CPUARCH} == "mips" +SRCF+= __sync_fetch_and_add_4 \ + __sync_fetch_and_and_4 \ + __sync_fetch_and_or_4 \ + __sync_fetch_and_sub_4 \ + __sync_fetch_and_xor_4 \ + __sync_lock_test_and_set_4 \ + __sync_val_compare_and_swap_4 +.endif +.if ${MACHINE_ARCH:Mmips64*} != "" +SRCF+= __sync_fetch_and_add_8 \ + __sync_fetch_and_and_8 \ + __sync_fetch_and_or_8 \ + __sync_fetch_and_sub_8 \ + __sync_fetch_and_xor_8 \ + __sync_lock_test_and_set_8 \ + __sync_val_compare_and_swap_8 +.endif + .for file in ${SRCF} . if ${MACHINE_CPUARCH} != "arm" && exists(${CRTSRC}/${CRTARCH}/${file}.S) SRCS+= ${file}.S Copied: stable/9/lib/libcompiler_rt/__sync_fetch_and_add_4.c (from r228919, head/lib/libcompiler_rt/__sync_fetch_and_add_4.c) ============================================================================== --- /dev/null 00:00:00 1970 (empty, because file is newly added) +++ stable/9/lib/libcompiler_rt/__sync_fetch_and_add_4.c Fri May 25 17:50:50 2012 (r236016, copy of r228919, head/lib/libcompiler_rt/__sync_fetch_and_add_4.c) @@ -0,0 +1,6 @@ +/* $FreeBSD$ */ +#define NAME __sync_fetch_and_add_4 +#define TYPE uint32_t +#define FETCHADD(x, y) atomic_fetchadd_32(x, y) + +#include "__sync_fetch_and_op_n.h" Copied: stable/9/lib/libcompiler_rt/__sync_fetch_and_add_8.c (from r228919, head/lib/libcompiler_rt/__sync_fetch_and_add_8.c) ============================================================================== --- /dev/null 00:00:00 1970 (empty, because file is newly added) +++ stable/9/lib/libcompiler_rt/__sync_fetch_and_add_8.c Fri May 25 17:50:50 2012 (r236016, copy of r228919, head/lib/libcompiler_rt/__sync_fetch_and_add_8.c) @@ -0,0 +1,6 @@ +/* $FreeBSD$ */ +#define NAME __sync_fetch_and_add_8 +#define TYPE uint64_t +#define FETCHADD(x, y) atomic_fetchadd_64(x, y) + +#include "__sync_fetch_and_op_n.h" Copied: stable/9/lib/libcompiler_rt/__sync_fetch_and_and_4.c (from r228919, head/lib/libcompiler_rt/__sync_fetch_and_and_4.c) ============================================================================== --- /dev/null 00:00:00 1970 (empty, because file is newly added) +++ stable/9/lib/libcompiler_rt/__sync_fetch_and_and_4.c Fri May 25 17:50:50 2012 (r236016, copy of r228919, head/lib/libcompiler_rt/__sync_fetch_and_and_4.c) @@ -0,0 +1,7 @@ +/* $FreeBSD$ */ +#define NAME __sync_fetch_and_and_4 +#define TYPE uint32_t +#define CMPSET atomic_cmpset_32 +#define EXPRESSION t & value + +#include "__sync_fetch_and_op_n.h" Copied: stable/9/lib/libcompiler_rt/__sync_fetch_and_and_8.c (from r228919, head/lib/libcompiler_rt/__sync_fetch_and_and_8.c) ============================================================================== --- /dev/null 00:00:00 1970 (empty, because file is newly added) +++ stable/9/lib/libcompiler_rt/__sync_fetch_and_and_8.c Fri May 25 17:50:50 2012 (r236016, copy of r228919, head/lib/libcompiler_rt/__sync_fetch_and_and_8.c) @@ -0,0 +1,7 @@ +/* $FreeBSD$ */ +#define NAME __sync_fetch_and_and_8 +#define TYPE uint64_t +#define CMPSET atomic_cmpset_64 +#define EXPRESSION t & value + +#include "__sync_fetch_and_op_n.h" Copied: stable/9/lib/libcompiler_rt/__sync_fetch_and_op_n.h (from r228919, head/lib/libcompiler_rt/__sync_fetch_and_op_n.h) ============================================================================== --- /dev/null 00:00:00 1970 (empty, because file is newly added) +++ stable/9/lib/libcompiler_rt/__sync_fetch_and_op_n.h Fri May 25 17:50:50 2012 (r236016, copy of r228919, head/lib/libcompiler_rt/__sync_fetch_and_op_n.h) @@ -0,0 +1,47 @@ +/*- + * Copyright (c) 2011 Ed Schouten + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + */ + +#include +__FBSDID("$FreeBSD$"); + +#include +#include + +TYPE +NAME(volatile TYPE *ptr, TYPE value) +{ + TYPE t; + +#ifdef FETCHADD + t = FETCHADD(ptr, value); +#else + do { + t = *ptr; + } while (!CMPSET(ptr, t, EXPRESSION)); +#endif + + return (t); +} Copied: stable/9/lib/libcompiler_rt/__sync_fetch_and_or_4.c (from r228919, head/lib/libcompiler_rt/__sync_fetch_and_or_4.c) ============================================================================== --- /dev/null 00:00:00 1970 (empty, because file is newly added) +++ stable/9/lib/libcompiler_rt/__sync_fetch_and_or_4.c Fri May 25 17:50:50 2012 (r236016, copy of r228919, head/lib/libcompiler_rt/__sync_fetch_and_or_4.c) @@ -0,0 +1,7 @@ +/* $FreeBSD$ */ +#define NAME __sync_fetch_and_or_4 +#define TYPE uint32_t +#define CMPSET atomic_cmpset_32 +#define EXPRESSION t | value + +#include "__sync_fetch_and_op_n.h" Copied: stable/9/lib/libcompiler_rt/__sync_fetch_and_or_8.c (from r228919, head/lib/libcompiler_rt/__sync_fetch_and_or_8.c) ============================================================================== --- /dev/null 00:00:00 1970 (empty, because file is newly added) +++ stable/9/lib/libcompiler_rt/__sync_fetch_and_or_8.c Fri May 25 17:50:50 2012 (r236016, copy of r228919, head/lib/libcompiler_rt/__sync_fetch_and_or_8.c) @@ -0,0 +1,7 @@ +/* $FreeBSD$ */ +#define NAME __sync_fetch_and_or_8 +#define TYPE uint64_t +#define CMPSET atomic_cmpset_64 +#define EXPRESSION t | value + +#include "__sync_fetch_and_op_n.h" Copied: stable/9/lib/libcompiler_rt/__sync_fetch_and_sub_4.c (from r228919, head/lib/libcompiler_rt/__sync_fetch_and_sub_4.c) ============================================================================== --- /dev/null 00:00:00 1970 (empty, because file is newly added) +++ stable/9/lib/libcompiler_rt/__sync_fetch_and_sub_4.c Fri May 25 17:50:50 2012 (r236016, copy of r228919, head/lib/libcompiler_rt/__sync_fetch_and_sub_4.c) @@ -0,0 +1,6 @@ +/* $FreeBSD$ */ +#define NAME __sync_fetch_and_sub_4 +#define TYPE uint32_t +#define FETCHADD(x, y) atomic_fetchadd_32(x, -(y)) + +#include "__sync_fetch_and_op_n.h" Copied: stable/9/lib/libcompiler_rt/__sync_fetch_and_sub_8.c (from r228919, head/lib/libcompiler_rt/__sync_fetch_and_sub_8.c) ============================================================================== --- /dev/null 00:00:00 1970 (empty, because file is newly added) +++ stable/9/lib/libcompiler_rt/__sync_fetch_and_sub_8.c Fri May 25 17:50:50 2012 (r236016, copy of r228919, head/lib/libcompiler_rt/__sync_fetch_and_sub_8.c) @@ -0,0 +1,6 @@ +/* $FreeBSD$ */ +#define NAME __sync_fetch_and_sub_8 +#define TYPE uint64_t +#define FETCHADD(x, y) atomic_fetchadd_64(x, -(y)) + +#include "__sync_fetch_and_op_n.h" Copied: stable/9/lib/libcompiler_rt/__sync_fetch_and_xor_4.c (from r228919, head/lib/libcompiler_rt/__sync_fetch_and_xor_4.c) ============================================================================== --- /dev/null 00:00:00 1970 (empty, because file is newly added) +++ stable/9/lib/libcompiler_rt/__sync_fetch_and_xor_4.c Fri May 25 17:50:50 2012 (r236016, copy of r228919, head/lib/libcompiler_rt/__sync_fetch_and_xor_4.c) @@ -0,0 +1,7 @@ +/* $FreeBSD$ */ +#define NAME __sync_fetch_and_xor_4 +#define TYPE uint32_t +#define CMPSET atomic_cmpset_32 +#define EXPRESSION t ^ value + +#include "__sync_fetch_and_op_n.h" Copied: stable/9/lib/libcompiler_rt/__sync_fetch_and_xor_8.c (from r228919, head/lib/libcompiler_rt/__sync_fetch_and_xor_8.c) ============================================================================== --- /dev/null 00:00:00 1970 (empty, because file is newly added) +++ stable/9/lib/libcompiler_rt/__sync_fetch_and_xor_8.c Fri May 25 17:50:50 2012 (r236016, copy of r228919, head/lib/libcompiler_rt/__sync_fetch_and_xor_8.c) @@ -0,0 +1,7 @@ +/* $FreeBSD$ */ +#define NAME __sync_fetch_and_xor_8 +#define TYPE uint64_t +#define CMPSET atomic_cmpset_64 +#define EXPRESSION t ^ value + +#include "__sync_fetch_and_op_n.h" Copied: stable/9/lib/libcompiler_rt/__sync_lock_test_and_set_4.c (from r228919, head/lib/libcompiler_rt/__sync_lock_test_and_set_4.c) ============================================================================== --- /dev/null 00:00:00 1970 (empty, because file is newly added) +++ stable/9/lib/libcompiler_rt/__sync_lock_test_and_set_4.c Fri May 25 17:50:50 2012 (r236016, copy of r228919, head/lib/libcompiler_rt/__sync_lock_test_and_set_4.c) @@ -0,0 +1,7 @@ +/* $FreeBSD$ */ +#define NAME __sync_lock_test_and_set_4 +#define TYPE uint32_t +#define CMPSET atomic_cmpset_32 +#define EXPRESSION value + +#include "__sync_fetch_and_op_n.h" Copied: stable/9/lib/libcompiler_rt/__sync_lock_test_and_set_8.c (from r228919, head/lib/libcompiler_rt/__sync_lock_test_and_set_8.c) ============================================================================== --- /dev/null 00:00:00 1970 (empty, because file is newly added) +++ stable/9/lib/libcompiler_rt/__sync_lock_test_and_set_8.c Fri May 25 17:50:50 2012 (r236016, copy of r228919, head/lib/libcompiler_rt/__sync_lock_test_and_set_8.c) @@ -0,0 +1,7 @@ +/* $FreeBSD$ */ +#define NAME __sync_lock_test_and_set_8 +#define TYPE uint64_t +#define CMPSET atomic_cmpset_64 +#define EXPRESSION value + +#include "__sync_fetch_and_op_n.h" Copied: stable/9/lib/libcompiler_rt/__sync_val_compare_and_swap_4.c (from r228919, head/lib/libcompiler_rt/__sync_val_compare_and_swap_4.c) ============================================================================== --- /dev/null 00:00:00 1970 (empty, because file is newly added) +++ stable/9/lib/libcompiler_rt/__sync_val_compare_and_swap_4.c Fri May 25 17:50:50 2012 (r236016, copy of r228919, head/lib/libcompiler_rt/__sync_val_compare_and_swap_4.c) @@ -0,0 +1,6 @@ +/* $FreeBSD$ */ +#define NAME __sync_val_compare_and_swap_4 +#define TYPE uint32_t +#define CMPSET atomic_cmpset_32 + +#include "__sync_val_compare_and_swap_n.h" Copied: stable/9/lib/libcompiler_rt/__sync_val_compare_and_swap_8.c (from r228919, head/lib/libcompiler_rt/__sync_val_compare_and_swap_8.c) ============================================================================== --- /dev/null 00:00:00 1970 (empty, because file is newly added) +++ stable/9/lib/libcompiler_rt/__sync_val_compare_and_swap_8.c Fri May 25 17:50:50 2012 (r236016, copy of r228919, head/lib/libcompiler_rt/__sync_val_compare_and_swap_8.c) @@ -0,0 +1,6 @@ +/* $FreeBSD$ */ +#define NAME __sync_val_compare_and_swap_8 +#define TYPE uint64_t +#define CMPSET atomic_cmpset_64 + +#include "__sync_val_compare_and_swap_n.h" Copied: stable/9/lib/libcompiler_rt/__sync_val_compare_and_swap_n.h (from r228919, head/lib/libcompiler_rt/__sync_val_compare_and_swap_n.h) ============================================================================== --- /dev/null 00:00:00 1970 (empty, because file is newly added) +++ stable/9/lib/libcompiler_rt/__sync_val_compare_and_swap_n.h Fri May 25 17:50:50 2012 (r236016, copy of r228919, head/lib/libcompiler_rt/__sync_val_compare_and_swap_n.h) @@ -0,0 +1,45 @@ +/*- + * Copyright (c) 2011 Ed Schouten + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + */ + +#include +__FBSDID("$FreeBSD$"); + +#include +#include + +TYPE +NAME(volatile TYPE *ptr, TYPE oldval, TYPE newval) +{ + TYPE t; + + while (!CMPSET(ptr, oldval, newval)) { + t = *ptr; + if (t != oldval) + return (t); + } + + return (oldval); +}