From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 3E117C61DA4 for ; Sat, 18 Mar 2023 08:02:54 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230063AbjCRICw (ORCPT ); Sat, 18 Mar 2023 04:02:52 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:53354 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230046AbjCRICj (ORCPT ); Sat, 18 Mar 2023 04:02:39 -0400 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id BC14B21977 for ; Sat, 18 Mar 2023 01:01:54 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1679126513; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=xbEE9rLsMkeSG6CkDtERD6c7FbVv+HEbsIDG5ynJNIc=; b=IRgROxCrZ7t5sjyyCbgdF1MPhdBWKMOKi67sriAH2QwkFZIxYGy9lWc6ZEErGIZLSvhSyy 6S9iAj2sZqmm26CuboNg6iKSoBuuxVP2a3EMkLrvEN4ZHHBcnlgDox+aqIuRFyHL7S5lzi kk8mcngHjE8O9ZwC1lEQlT2SkIM1NwA= Received: from mail-ot1-f70.google.com (mail-ot1-f70.google.com [209.85.210.70]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-567-8szKnRdvMyaPoKU3ZT1Sng-1; Sat, 18 Mar 2023 04:01:45 -0400 X-MC-Unique: 8szKnRdvMyaPoKU3ZT1Sng-1 Received: by mail-ot1-f70.google.com with SMTP id a15-20020a0568300b8f00b0069965814cf7so3332471otv.15 for ; Sat, 18 Mar 2023 01:01:44 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; t=1679126504; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=xbEE9rLsMkeSG6CkDtERD6c7FbVv+HEbsIDG5ynJNIc=; b=QoBRoPlAr7c9RYNKv5xwgQ07zgGnez+DkWX2ts0+pXApV05/5+ezXYNLGPjL4K0g98 lcfrYxAiL1xF/MQD+4aQuK7PFwPSpyxdOaSAdCZsb4Kfv0LPYE2hpK8PVnH70xHtqYGK /5wyDWqY/TdaFDMkqVmIx3DZhNmt5zPjz2YqwS9sHJg1GA8a9syQAPMkdJKmxCNV1JEd yhPmt6+vdVscofEdUQFZSH3gF09Wr07QP2KzeL9ge4hgXChFbPUqp/R9BPAnt6f9PkP1 NviQgEQgUYMtG7xlQeQIE8cGTapdzy4u5XihjAua9Q5iHk/Dj3Soa9lVULTrx7woal9Z E7Ew== X-Gm-Message-State: AO0yUKWeJ9TIFOx7HLjOZyMxUZG8uws/lfndqD1+oxrIAFRgUYpR9/Yw QoGjPXKuRGWlTRV++4vtj5iK6mTPGxw8EDOoxCDV3LD8iXk6soWeZraQ5AdQic9OQYyU03bghlg iwozw0E8vucGjdYtqXmRmYyb4 X-Received: by 2002:a9d:6d07:0:b0:699:a4f5:c951 with SMTP id o7-20020a9d6d07000000b00699a4f5c951mr545249otp.2.1679126504310; Sat, 18 Mar 2023 01:01:44 -0700 (PDT) X-Google-Smtp-Source: AK7set98ZKY0u5f8b+haxIAAI83p8gfQCrvcJ86i5uq8nFKjoznRe70RyMpyZxxyaIYMjXHy5gPGaQ== X-Received: by 2002:a9d:6d07:0:b0:699:a4f5:c951 with SMTP id o7-20020a9d6d07000000b00699a4f5c951mr545241otp.2.1679126504089; Sat, 18 Mar 2023 01:01:44 -0700 (PDT) Received: from localhost.localdomain ([2804:1b3:a801:b074:274d:d04e:badc:c89f]) by smtp.gmail.com with ESMTPSA id c3-20020a9d4803000000b0069dc250cb24sm1824462otf.3.2023.03.18.01.01.41 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 18 Mar 2023 01:01:43 -0700 (PDT) From: Leonardo Bras To: Paul Walmsley , Palmer Dabbelt , Albert Ou , Leonardo Bras , Guo Ren Cc: linux-riscv@lists.infradead.org, linux-kernel@vger.kernel.org Subject: [RFC PATCH 4/6] riscv/cmpxchg: Deduplicate xchg() asm functions Date: Sat, 18 Mar 2023 05:00:58 -0300 Message-Id: <20230318080059.1109286-5-leobras@redhat.com> X-Mailer: git-send-email 2.40.0 In-Reply-To: <20230318080059.1109286-1-leobras@redhat.com> References: <20230318080059.1109286-1-leobras@redhat.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org In this header every xchg define (_relaxed, _acquire, _release, vanilla) contain it's own asm file, both for 4-byte variables an 8-byte variables, on a total of 8 versions of mostly the same asm. This is usually bad, as it means any change may be done in up to 8 different places. Unify those versions by creating a new define with enough parameters to generate any version of the previous 8. (This did not cause any change in generated asm) Signed-off-by: Leonardo Bras --- arch/riscv/include/asm/cmpxchg.h | 63 ++++++++++---------------------- 1 file changed, 19 insertions(+), 44 deletions(-) diff --git a/arch/riscv/include/asm/cmpxchg.h b/arch/riscv/include/asm/cmpxchg.h index e49a2edc6f36c..13dc608229ef0 100644 --- a/arch/riscv/include/asm/cmpxchg.h +++ b/arch/riscv/include/asm/cmpxchg.h @@ -11,6 +11,17 @@ #include #include +#define ___xchg(sfx, prepend, append) \ +({ \ + __asm__ __volatile__ ( \ + prepend \ + " amoswap" sfx " %0, %2, %1\n" \ + append \ + : "=r" (__ret), "+A" (*__ptr) \ + : "r" (__new) \ + : "memory"); \ +}) + #define __xchg_relaxed(ptr, new, size) \ ({ \ __typeof__(ptr) __ptr = (ptr); \ @@ -18,18 +29,10 @@ __typeof__(*(ptr)) __ret; \ switch (size) { \ case 4: \ - __asm__ __volatile__ ( \ - " amoswap.w %0, %2, %1\n" \ - : "=r" (__ret), "+A" (*__ptr) \ - : "r" (__new) \ - : "memory"); \ + ___xchg(".w", "", ""); \ break; \ case 8: \ - __asm__ __volatile__ ( \ - " amoswap.d %0, %2, %1\n" \ - : "=r" (__ret), "+A" (*__ptr) \ - : "r" (__new) \ - : "memory"); \ + ___xchg(".d", "", ""); \ break; \ default: \ BUILD_BUG(); \ @@ -51,20 +54,10 @@ __typeof__(*(ptr)) __ret; \ switch (size) { \ case 4: \ - __asm__ __volatile__ ( \ - " amoswap.w %0, %2, %1\n" \ - RISCV_ACQUIRE_BARRIER \ - : "=r" (__ret), "+A" (*__ptr) \ - : "r" (__new) \ - : "memory"); \ + ___xchg(".w", "", RISCV_ACQUIRE_BARRIER); \ break; \ case 8: \ - __asm__ __volatile__ ( \ - " amoswap.d %0, %2, %1\n" \ - RISCV_ACQUIRE_BARRIER \ - : "=r" (__ret), "+A" (*__ptr) \ - : "r" (__new) \ - : "memory"); \ + ___xchg(".d", "", RISCV_ACQUIRE_BARRIER); \ break; \ default: \ BUILD_BUG(); \ @@ -86,20 +79,10 @@ __typeof__(*(ptr)) __ret; \ switch (size) { \ case 4: \ - __asm__ __volatile__ ( \ - RISCV_RELEASE_BARRIER \ - " amoswap.w %0, %2, %1\n" \ - : "=r" (__ret), "+A" (*__ptr) \ - : "r" (__new) \ - : "memory"); \ + ___xchg(".w", RISCV_RELEASE_BARRIER, ""); \ break; \ case 8: \ - __asm__ __volatile__ ( \ - RISCV_RELEASE_BARRIER \ - " amoswap.d %0, %2, %1\n" \ - : "=r" (__ret), "+A" (*__ptr) \ - : "r" (__new) \ - : "memory"); \ + ___xchg(".d", RISCV_RELEASE_BARRIER, ""); \ break; \ default: \ BUILD_BUG(); \ @@ -121,18 +104,10 @@ __typeof__(*(ptr)) __ret; \ switch (size) { \ case 4: \ - __asm__ __volatile__ ( \ - " amoswap.w.aqrl %0, %2, %1\n" \ - : "=r" (__ret), "+A" (*__ptr) \ - : "r" (__new) \ - : "memory"); \ + ___xchg("w.aqrl", "", ""); \ break; \ case 8: \ - __asm__ __volatile__ ( \ - " amoswap.d.aqrl %0, %2, %1\n" \ - : "=r" (__ret), "+A" (*__ptr) \ - : "r" (__new) \ - : "memory"); \ + ___xchg("d.aqrl", "", ""); \ break; \ default: \ BUILD_BUG(); \ -- 2.40.0 From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id BD335C7618B for ; Sat, 18 Mar 2023 08:03:32 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender: Content-Transfer-Encoding:Content-Type:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:MIME-Version:References:In-Reply-To: Message-Id:Date:Subject:Cc:To:From:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=OH/GiSnvHDPVnYpZj4KtdnlB39fWDnJTaeIzkztLDDE=; b=1IjyDiS4lah1ZT OJixEagPnAXoCS1MJSg3M53X0r5/3mSkz6r8EMScIbhaLeXAT/jn0DqBHUrYNxfc0Gb+ACPmfRHEd 2BvqKxgWqO2jTsSXdR27a4nZFLb3NtAF2gtHzl6EJwuGSlah3qiOdVAu1gkv2T3IQuhHTm8c+ZICx k3hUohaaav/ONtnHSWMVFroYHWg8XExrjJCPmGr974PiVFBr/QWtn3RaQx7OKeZn+5kl8WsEFvKIs ddLJDI/1fHomHphF9beB82mOVK8O5r2geUX4owAVv1gDTkKe4gfBHSDv6f2bONGMXqtCAL1m7To4a CsCTEDTKHZOpV25d+DEg==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.96 #2 (Red Hat Linux)) id 1pdRXC-004OWw-13; Sat, 18 Mar 2023 08:03:26 +0000 Received: from us-smtp-delivery-124.mimecast.com ([170.10.129.124]) by bombadil.infradead.org with esmtps (Exim 4.96 #2 (Red Hat Linux)) id 1pdRX8-004OUu-2W for linux-riscv@lists.infradead.org; Sat, 18 Mar 2023 08:03:24 +0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1679126601; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=xbEE9rLsMkeSG6CkDtERD6c7FbVv+HEbsIDG5ynJNIc=; b=T6DhJHYtHoCETn9yw0i1CJD89H/soHyvBP6HwCHe/NcFGbFOGDth8OTZYUVh1fOk/Xu01b /YC1a1BeAxcVR+myfhz4CIROEqnMCyzD/MMkBucnHHMGxb7a2JYfD5vZuRH3b7Fz8mpvjs DO6tvU5Sxy3cMUoEgLecJMEVy9/EO58= Received: from mail-ot1-f70.google.com (mail-ot1-f70.google.com [209.85.210.70]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-22-bjmlrMxGPkWgvTw5UIa7Kg-1; Sat, 18 Mar 2023 04:01:45 -0400 X-MC-Unique: bjmlrMxGPkWgvTw5UIa7Kg-1 Received: by mail-ot1-f70.google.com with SMTP id e8-20020a9d63c8000000b0069f0e0bd36cso86792otl.20 for ; Sat, 18 Mar 2023 01:01:44 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; t=1679126504; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=xbEE9rLsMkeSG6CkDtERD6c7FbVv+HEbsIDG5ynJNIc=; b=4X6ro6TxTtFslodR5kTmfQqQLJvms9gxrc4OYbLtsqiZ1VhEKAlIUuBciUCe2JRf8X k/7h42ZXtZtNJDdx0Au3oB/E2x9f/ofk51URSxhhR1eA2X5GEEi9xTfnesxlYjdaYLNK 5/NSnry6cwlbmNt4Ccv2oz4K2X5l/8ntV1+5hs5dgWMYonVFY87SM1WM9zMKY0ikqmqf rOZ11u/Qwkd2vNXGe3WO40P0w1EdEOsrDap2XbvLAA7c6hZUaGkU1Y+nOmzlOieB0fOR A41OZ0vZDwtun8pnx2HmiQhM5bs8TciquS1on4XsVgJQGz539Qo8wOiphvGngvLNXHE2 CJyg== X-Gm-Message-State: AO0yUKVbHAMnWXlSfg+gsR/RQ95FBOZSOyOTM5JtPfHl3cqntNv1Sdt8 5LWDjak28owy3edNVQlUWLwJcMBqJO09XqIHCxLAwzOFfArTagznN7+FudhwMvIfVvbETEyb9To ttkSaVFrK/yoOEjRcb0rHHHmn/rlx X-Received: by 2002:a9d:6d07:0:b0:699:a4f5:c951 with SMTP id o7-20020a9d6d07000000b00699a4f5c951mr545248otp.2.1679126504310; Sat, 18 Mar 2023 01:01:44 -0700 (PDT) X-Google-Smtp-Source: AK7set98ZKY0u5f8b+haxIAAI83p8gfQCrvcJ86i5uq8nFKjoznRe70RyMpyZxxyaIYMjXHy5gPGaQ== X-Received: by 2002:a9d:6d07:0:b0:699:a4f5:c951 with SMTP id o7-20020a9d6d07000000b00699a4f5c951mr545241otp.2.1679126504089; Sat, 18 Mar 2023 01:01:44 -0700 (PDT) Received: from localhost.localdomain ([2804:1b3:a801:b074:274d:d04e:badc:c89f]) by smtp.gmail.com with ESMTPSA id c3-20020a9d4803000000b0069dc250cb24sm1824462otf.3.2023.03.18.01.01.41 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 18 Mar 2023 01:01:43 -0700 (PDT) From: Leonardo Bras To: Paul Walmsley , Palmer Dabbelt , Albert Ou , Leonardo Bras , Guo Ren Cc: linux-riscv@lists.infradead.org, linux-kernel@vger.kernel.org Subject: [RFC PATCH 4/6] riscv/cmpxchg: Deduplicate xchg() asm functions Date: Sat, 18 Mar 2023 05:00:58 -0300 Message-Id: <20230318080059.1109286-5-leobras@redhat.com> X-Mailer: git-send-email 2.40.0 In-Reply-To: <20230318080059.1109286-1-leobras@redhat.com> References: <20230318080059.1109286-1-leobras@redhat.com> MIME-Version: 1.0 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20230318_010322_902679_9E7E03C2 X-CRM114-Status: GOOD ( 10.72 ) X-BeenThere: linux-riscv@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Sender: "linux-riscv" Errors-To: linux-riscv-bounces+linux-riscv=archiver.kernel.org@lists.infradead.org In this header every xchg define (_relaxed, _acquire, _release, vanilla) contain it's own asm file, both for 4-byte variables an 8-byte variables, on a total of 8 versions of mostly the same asm. This is usually bad, as it means any change may be done in up to 8 different places. Unify those versions by creating a new define with enough parameters to generate any version of the previous 8. (This did not cause any change in generated asm) Signed-off-by: Leonardo Bras --- arch/riscv/include/asm/cmpxchg.h | 63 ++++++++++---------------------- 1 file changed, 19 insertions(+), 44 deletions(-) diff --git a/arch/riscv/include/asm/cmpxchg.h b/arch/riscv/include/asm/cmpxchg.h index e49a2edc6f36c..13dc608229ef0 100644 --- a/arch/riscv/include/asm/cmpxchg.h +++ b/arch/riscv/include/asm/cmpxchg.h @@ -11,6 +11,17 @@ #include #include +#define ___xchg(sfx, prepend, append) \ +({ \ + __asm__ __volatile__ ( \ + prepend \ + " amoswap" sfx " %0, %2, %1\n" \ + append \ + : "=r" (__ret), "+A" (*__ptr) \ + : "r" (__new) \ + : "memory"); \ +}) + #define __xchg_relaxed(ptr, new, size) \ ({ \ __typeof__(ptr) __ptr = (ptr); \ @@ -18,18 +29,10 @@ __typeof__(*(ptr)) __ret; \ switch (size) { \ case 4: \ - __asm__ __volatile__ ( \ - " amoswap.w %0, %2, %1\n" \ - : "=r" (__ret), "+A" (*__ptr) \ - : "r" (__new) \ - : "memory"); \ + ___xchg(".w", "", ""); \ break; \ case 8: \ - __asm__ __volatile__ ( \ - " amoswap.d %0, %2, %1\n" \ - : "=r" (__ret), "+A" (*__ptr) \ - : "r" (__new) \ - : "memory"); \ + ___xchg(".d", "", ""); \ break; \ default: \ BUILD_BUG(); \ @@ -51,20 +54,10 @@ __typeof__(*(ptr)) __ret; \ switch (size) { \ case 4: \ - __asm__ __volatile__ ( \ - " amoswap.w %0, %2, %1\n" \ - RISCV_ACQUIRE_BARRIER \ - : "=r" (__ret), "+A" (*__ptr) \ - : "r" (__new) \ - : "memory"); \ + ___xchg(".w", "", RISCV_ACQUIRE_BARRIER); \ break; \ case 8: \ - __asm__ __volatile__ ( \ - " amoswap.d %0, %2, %1\n" \ - RISCV_ACQUIRE_BARRIER \ - : "=r" (__ret), "+A" (*__ptr) \ - : "r" (__new) \ - : "memory"); \ + ___xchg(".d", "", RISCV_ACQUIRE_BARRIER); \ break; \ default: \ BUILD_BUG(); \ @@ -86,20 +79,10 @@ __typeof__(*(ptr)) __ret; \ switch (size) { \ case 4: \ - __asm__ __volatile__ ( \ - RISCV_RELEASE_BARRIER \ - " amoswap.w %0, %2, %1\n" \ - : "=r" (__ret), "+A" (*__ptr) \ - : "r" (__new) \ - : "memory"); \ + ___xchg(".w", RISCV_RELEASE_BARRIER, ""); \ break; \ case 8: \ - __asm__ __volatile__ ( \ - RISCV_RELEASE_BARRIER \ - " amoswap.d %0, %2, %1\n" \ - : "=r" (__ret), "+A" (*__ptr) \ - : "r" (__new) \ - : "memory"); \ + ___xchg(".d", RISCV_RELEASE_BARRIER, ""); \ break; \ default: \ BUILD_BUG(); \ @@ -121,18 +104,10 @@ __typeof__(*(ptr)) __ret; \ switch (size) { \ case 4: \ - __asm__ __volatile__ ( \ - " amoswap.w.aqrl %0, %2, %1\n" \ - : "=r" (__ret), "+A" (*__ptr) \ - : "r" (__new) \ - : "memory"); \ + ___xchg("w.aqrl", "", ""); \ break; \ case 8: \ - __asm__ __volatile__ ( \ - " amoswap.d.aqrl %0, %2, %1\n" \ - : "=r" (__ret), "+A" (*__ptr) \ - : "r" (__new) \ - : "memory"); \ + ___xchg("d.aqrl", "", ""); \ break; \ default: \ BUILD_BUG(); \ -- 2.40.0 _______________________________________________ linux-riscv mailing list linux-riscv@lists.infradead.org http://lists.infradead.org/mailman/listinfo/linux-riscv