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 825CEC6FD20 for ; Wed, 22 Mar 2023 00:45:43 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229799AbjCVApl (ORCPT ); Tue, 21 Mar 2023 20:45:41 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:42864 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229964AbjCVApZ (ORCPT ); Tue, 21 Mar 2023 20:45:25 -0400 Received: from mail-ed1-x532.google.com (mail-ed1-x532.google.com [IPv6:2a00:1450:4864:20::532]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id CC1B639BB3 for ; Tue, 21 Mar 2023 17:45:23 -0700 (PDT) Received: by mail-ed1-x532.google.com with SMTP id ek18so66644084edb.6 for ; Tue, 21 Mar 2023 17:45:23 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; t=1679445922; h=in-reply-to:content-disposition:mime-version:references:message-id :subject:cc:to:from:date:from:to:cc:subject:date:message-id:reply-to; bh=rrtn8nmTpdpmlgteuK1+I9kCTEi3WBSapYh/Vb77bok=; b=VW31Rf9rgwMP9zlJPFNGWbV/hbH9wFiZ9VXmZSwuQsH+/Lwds11o8qr14npM4cUj9p 2z1mwUFi9nvypKReOlWlhwqyw/WvoPUvkTAeIwGPSrw6tcZr0QSL9m/EmLybxR2c/8dA uxGa3OdLJAVyZnZkBGKhx3UyuFp26ofXvTDURP4Gtawcv5r5JsahT+G+0px4ilVqFRGm 0zpONLmv1eqvpK2id/1vhlb6fwSPOXgCQxjy3yhaf+lnNN/8y4qEKUCE4/Aj4Z3LBFs0 04ocCUbGQr6uscy1auN6Wn5lcJe0dGi9r5k2wOv0LMioodyuuAk3ibVkaIldh8IQO4U3 QPhA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; t=1679445922; h=in-reply-to:content-disposition:mime-version:references:message-id :subject:cc:to:from:date:x-gm-message-state:from:to:cc:subject:date :message-id:reply-to; bh=rrtn8nmTpdpmlgteuK1+I9kCTEi3WBSapYh/Vb77bok=; b=wH/0N3Y7RiXl7lYIUZcTvpTucESfV68h2L46UNFBAxJqjYlFiUrWzcKVF7OOh0UIql 5rX1ZZDmqAnfxZ7NgqigCsra/Czhyc119HVtN078PGuFDEZ0y0vYn7bsPrpst7tKaWYw tKhLZwkGcBPMxAG0bpXxK9Ecvt9fRbnBUQNDNI/DRlDpl3B35fx3RgWm5elQ8yWvEyYm gT2eXZigHWePKm4C5xBL3HHdmt0LCprEsDrRsRvLmrpDqnn6AeNxYqlT8Z3ZtnCIaVzF gxhMKAmVzykXh1Spa/jWeOfp5Em4v16xaVwPDSEgTmuQ1+kA0a1TTzJJpFu/A5SIXiar B17g== X-Gm-Message-State: AO0yUKUiA+NZwLnD3JO10wfQAVK1RNQGo6iblY+mhc4IzD/j7cDtorwz 35XAZoB4jrLpCaF6HkKy0YU= X-Google-Smtp-Source: AK7set9+toSZFFbOheWMw08WFtHuw2LBGIYFjBR36MoXWEw//iln1ImIgpEqD5zQkjHozI7eOTQi5g== X-Received: by 2002:a17:906:b115:b0:8b1:76ca:f228 with SMTP id u21-20020a170906b11500b008b176caf228mr4968055ejy.39.1679445922119; Tue, 21 Mar 2023 17:45:22 -0700 (PDT) Received: from andrea (93-41-0-79.ip79.fastwebnet.it. [93.41.0.79]) by smtp.gmail.com with ESMTPSA id u24-20020a17090657d800b00934823127c8sm3249365ejr.78.2023.03.21.17.45.21 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 21 Mar 2023 17:45:21 -0700 (PDT) Date: Wed, 22 Mar 2023 01:45:14 +0100 From: Andrea Parri To: Leonardo Bras Cc: Paul Walmsley , Palmer Dabbelt , Albert Ou , Guo Ren , linux-riscv@lists.infradead.org, linux-kernel@vger.kernel.org Subject: Re: [RESEND RFC PATCH v2 1/6] riscv/cmpxchg: Deduplicate cmpxchg() asm functions Message-ID: References: <20230321074249.2221674-1-leobras@redhat.com> <20230321074249.2221674-2-leobras@redhat.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20230321074249.2221674-2-leobras@redhat.com> Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Tue, Mar 21, 2023 at 04:42:44AM -0300, Leonardo Bras wrote: > In this header every cmpxchg 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 | 102 ++++++++----------------------- > 1 file changed, 24 insertions(+), 78 deletions(-) Diff looks nice, > +#define ___cmpxchg(lr_sfx, sc_sfx, prepend, append) \ > +{ \ > + __asm__ __volatile__ ( \ > + prepend \ > + "0: lr" lr_sfx " %0, %2\n" \ > + " bne %0, %z3, 1f\n" \ > + " sc" sc_sfx " %1, %z4, %2\n" \ > + " bnez %1, 0b\n" \ > + append \ > + "1:\n" \ > + : "=&r" (__ret), "=&r" (__rc), "+A" (*__ptr) \ > + : "rJ" ((long)__old), "rJ" (__new) \ > + : "memory"); \ > +} Though I'm not really a fan of macros depending on local variables with "magic" names, can this be avoided? Thanks, Andrea