From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail-ed1-x52d.google.com (mail-ed1-x52d.google.com [IPv6:2a00:1450:4864:20::52d]) by sourceware.org (Postfix) with ESMTPS id 61FB93833029 for ; Tue, 27 Apr 2021 15:17:21 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.3.2 sourceware.org 61FB93833029 Authentication-Results: sourceware.org; dmarc=none (p=none dis=none) header.from=sifive.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=jimw@sifive.com Received: by mail-ed1-x52d.google.com with SMTP id s15so70435448edd.4 for ; Tue, 27 Apr 2021 08:17:21 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sifive.com; s=google; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=tpgZxk0PS5NV2Xmydehh43HTkKrAyUS6EpPz9GCsRUs=; b=SWAQAJVtPyQ+XNfqZ3U1LpkGQrvW8IQV6XuUemHpc0Pun0lRofHYLf1BbfG9vAhQyD 4IDUvrxAlzVjeihDaKs9vN/2iJhz623HTbVhaGqu61oT1Brnb3WRbqBKWGivY7W9ESYD IIHj+L7q10ppHH4l8Vhh8WMbzn2uu3T1DiC8ioyq1RAwUsFOom2Kr3rxvQETzw/d9Z6C H/f1lKHArjnmPz5i3E6/VnArLsiq/Czto18/rNtayNQlE6uElNeIHv1sBgRCagAIAY/2 o1ZoudSeouAl8nhQ1bv80svhwP6eLYN1lxy0oBm5YNzjKtflgnXDF9iW5+nuWv7gvWmv LE3g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=tpgZxk0PS5NV2Xmydehh43HTkKrAyUS6EpPz9GCsRUs=; b=jjzbDMaW1rZOdMzHa2FUdKYrBxAk7xnTldxd1r6D/9Jc2jGSAPOVcI6kc5cWcwBP80 dY6LbNG0DHZlxLi1zwIGhAdE4WgvMBIUY0NDXPnGWvup2QvV3VqYkAs+xSP7vRGO6z1h YEAIz0IHgW+mFopnA8O5SqoiRIGeomCFXQKCp5GTL9hfCmWMQD+n+FAo9Bth6lThW4Yu 9LZfPx6IeCD+3LVaVl8yGKAyvu7asXioOtNeB/zuWPXeh6h5ESVbs+ObcFV9K8nr5AFV 83QVCslDEld80FJfGAZKiV3YKwMO/SMmfUekIvkOcPfUddfb53HgrYX8mG/BC0S7K5xz Bfbg== X-Gm-Message-State: AOAM531xxTG2bdcMwu89G+aJ+nhZ9gBMWp9q8pN5pOQG+uQaar9lITJF kggwWaF+mA0cVfv8Pu8O+IUos7dhZmcLIM6DMlKYBg== X-Google-Smtp-Source: ABdhPJydzBOZMVajc1yTqeOTBs0yX/Ud8zpn0klTH5pme5cJjj3HGn8H673WpuHLHPh4UMuoOf0cTAr8BwgvJtZRbjo= X-Received: by 2002:a05:6402:416:: with SMTP id q22mr5022699edv.204.1619536640513; Tue, 27 Apr 2021 08:17:20 -0700 (PDT) MIME-Version: 1.0 References: <20210426124552.3316789-1-cmuellner@gcc.gnu.org> <20210426124552.3316789-11-cmuellner@gcc.gnu.org> In-Reply-To: <20210426124552.3316789-11-cmuellner@gcc.gnu.org> From: Jim Wilson Date: Tue, 27 Apr 2021 08:17:09 -0700 Message-ID: Subject: Re: [PATCH 10/10] RISC-V: Provide programmatic implementation of CAS [PR 100266] To: Christoph Muellner Cc: GCC Patches , Kito Cheng X-Spam-Status: No, score=-2.8 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, HTML_MESSAGE, RCVD_IN_DNSWL_NONE, SPF_HELO_NONE, SPF_PASS, TXREP autolearn=ham autolearn_force=no version=3.4.2 X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on server2.sourceware.org Content-Type: text/plain; charset="UTF-8" X-Content-Filtered-By: Mailman/MimeDel 2.1.29 X-BeenThere: gcc-patches@gcc.gnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Gcc-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Tue, 27 Apr 2021 15:17:23 -0000 On Mon, Apr 26, 2021 at 5:46 AM Christoph Muellner wrote: > The existing CAS implementation uses an INSN definition, which provides > the core LR/SC sequence. Additionally to that, there is a follow-up code, > that evaluates the results and calculates the return values. > This has two drawbacks: a) an extension to sub-word CAS implementations > is not possible (even if, then it would be unmaintainable), and b) the > implementation is hard to maintain/improve. > This patch provides a programmatic implementation of CAS, similar > like many other architectures are having one. I noticed that when the address isn't already valid for lr/sc then we end up with extra instructions to fix the address. For instance, using gcc/testsuite/gcc.dg/atomic-compare-exchange-3.c, I get for the lr/sc loop .L2: addi a5,a3,%lo(v) lr.w a1, 0(a5) bne a1,a2,.L7 addi a1,a3,%lo(v) sc.w a5, a0, 0(a1) sext.w a5,a5 bne a5,zero,.L2 and note that there are two addi %lo instructions. The current code gives addi a4,a4,%lo(v) 1: lr.w a2,0(a4); bne a2,a5,1f; sc.w a6,a0,0(a4); bnez a6,1b; 1: which is better, as the address is fixed before the lr/sc loop. The sext is fixed by the REE patch, or by directly generating the sign-extending sc.w so that isn't an issue here. Jim