Received: by 2002:a05:7412:31a9:b0:e2:908c:2ebd with SMTP id et41csp5030379rdb; Fri, 15 Sep 2023 23:19:38 -0700 (PDT) X-Google-Smtp-Source: AGHT+IGnbnBTy2DVlCOCnmG11Zz0VxZx4XAiOBl8sU33zb8RQ+s+k+QpcF9XK/LvpiXGm/kTGTnE X-Received: by 2002:a17:902:74cc:b0:1bc:8c6c:217d with SMTP id f12-20020a17090274cc00b001bc8c6c217dmr3718242plt.61.1694845177817; Fri, 15 Sep 2023 23:19:37 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1694845177; cv=none; d=google.com; s=arc-20160816; b=NBawPjCFRTntkkIYoQkMwURGuExz7E6xIi636c1Z9E7qFKqlgQ/1RH5vobPXxDspJl AFEi9XDPNnuUWq2IDKMF+D8CpdwT7ewGdy6IVoX+Or3aS39Vr/h0CGcB/L9Bvppnj0Pu APZt9h7h9+a0rv9HvQ4fV2NJJRhBq3yDisgTr+2jK1GY4J1MYWmoU9Uz/14suXZrQTkt jYSzX+o5USzlIhOVxhqyqak0XkVbS9DT5ZhVdp28Y0QL1QRWqOcwcHhF8lSBNXR1P461 shY7vdDT9kiH81lhDUxkhVC5mfuTeMwuFkLrSjEMdtkN1UAdArjUuhVRy7HovHeUAUvL zxTQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:cc:to:subject:message-id:date:from:in-reply-to :references:mime-version:dkim-signature; bh=KAndjmnR48WE2pCpGu0IjwxW3tK8pfCDH+nJM9LoF4g=; fh=JY/F9LeLFL3FDiCohieSaX8VOe13jdw7HyQ14LJIEMU=; b=NcFmfmk39urtJlezAQtZKGKqHTCqqxjRsV31dViUSHaThCVBYpfnd9rnNoQ333udOF B/gHOt9vkHGvM9vnbLTkBmU7fkg0kZJIkdQCKISkx4RkcECbQJZBYUNOX0AAtZk5af9g zS8+GGJ5YNiZ7RtOkBiaUIvAtbppwLVGaGr7riGN5xdEVGu/q0r7q3QwjwXwHvuo8pq0 2Nb3fBQAuvjpat8pE7ZaeYxlD7KMgCia4vu+gfJDSXtA/gUWYErsKW5+xqyOmyPYsW94 72wVab7il8mbAyzsfZsL6vgFKRk0zFbzWgg0lcJaAdp+icccSwHxwl/Dt8VEF++HfZ7S gGLQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linux-foundation.org header.s=google header.b="UU/zFBi2"; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.35 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from groat.vger.email (groat.vger.email. [23.128.96.35]) by mx.google.com with ESMTPS id x14-20020a170902ec8e00b001c427a74e31si2785537plg.628.2023.09.15.23.19.25 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 15 Sep 2023 23:19:37 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.35 as permitted sender) client-ip=23.128.96.35; Authentication-Results: mx.google.com; dkim=pass header.i=@linux-foundation.org header.s=google header.b="UU/zFBi2"; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.35 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by groat.vger.email (Postfix) with ESMTP id 0EF2883C82D9; Fri, 15 Sep 2023 19:04:52 -0700 (PDT) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.10 at groat.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S236139AbjIPCDv (ORCPT + 99 others); Fri, 15 Sep 2023 22:03:51 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:45632 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S236656AbjIPCDS (ORCPT ); Fri, 15 Sep 2023 22:03:18 -0400 Received: from mail-lj1-x233.google.com (mail-lj1-x233.google.com [IPv6:2a00:1450:4864:20::233]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 91E7C2735 for ; Fri, 15 Sep 2023 19:01:34 -0700 (PDT) Received: by mail-lj1-x233.google.com with SMTP id 38308e7fff4ca-2bb9a063f26so43727311fa.2 for ; Fri, 15 Sep 2023 19:01:34 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux-foundation.org; s=google; t=1694829692; x=1695434492; darn=vger.kernel.org; h=cc:to:subject:message-id:date:from:in-reply-to:references :mime-version:from:to:cc:subject:date:message-id:reply-to; bh=KAndjmnR48WE2pCpGu0IjwxW3tK8pfCDH+nJM9LoF4g=; b=UU/zFBi267VWGewKzj3NnFippMQA7FWpN6AdgfauBJCkHA5tgrUe8LbkdFzwcyomGH vg88ayiWthiGiGokkBRE3nJ1sx9LcLBtLYKDhbLrFaVwJJIYDaM9XlwQuZqQa3P6+c3r tJwuZZPSD9tEaM28+N3oj7JLXPw1Oi3eal/lI= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1694829692; x=1695434492; h=cc:to:subject:message-id:date:from:in-reply-to:references :mime-version:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=KAndjmnR48WE2pCpGu0IjwxW3tK8pfCDH+nJM9LoF4g=; b=f/OjCOpwgAOvx53TAT+CWfm+xJBl+fARUYxw3XhZz1Pzp288NV1I/LoVLHSbQtpQQo 8wEu7AhuzctcJbZo0INioZL0yWXG963AkCSQ6H6l334vUSZ2VK8sWaCi3CBHulg3AOw4 nnQCr2IuA9Z5kZL0DkODljVEPuqIYnk/xWXs1za5eOYKYiUyyhbpx/OrIu8JgFJml6gj 4X2cB/cRXiM9wqOSlXrRzuNdrTQd//5iQrm0jdYZssIk4JYPCYSNM+Vo6nR5RWPm5zSG AumGaZN/+C3SCRvbKGUbujmj66VIJQXsHw8NVlUaVn+03acXhdmPMaUZqI/Ik7PSg/u2 K/9Q== X-Gm-Message-State: AOJu0Yyi+aer+Ak9MAY78v+k9kil6GnBGVDaGV4RkGw+mZj2k3G1wZNF R/fwc4oFS1TWXx07M/sbKS7UX+BOrugyLlHS4jrhVw4u X-Received: by 2002:a2e:9014:0:b0:2bf:a0d1:b122 with SMTP id h20-20020a2e9014000000b002bfa0d1b122mr2912976ljg.5.1694829692389; Fri, 15 Sep 2023 19:01:32 -0700 (PDT) Received: from mail-ej1-f46.google.com (mail-ej1-f46.google.com. [209.85.218.46]) by smtp.gmail.com with ESMTPSA id ck19-20020a170906c45300b0099297c99314sm3108240ejb.113.2023.09.15.19.01.31 for (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Fri, 15 Sep 2023 19:01:31 -0700 (PDT) Received: by mail-ej1-f46.google.com with SMTP id a640c23a62f3a-9a9f139cd94so356357566b.2 for ; Fri, 15 Sep 2023 19:01:31 -0700 (PDT) X-Received: by 2002:a17:906:100b:b0:9a2:28dc:4168 with SMTP id 11-20020a170906100b00b009a228dc4168mr2220828ejm.61.1694829690885; Fri, 15 Sep 2023 19:01:30 -0700 (PDT) MIME-Version: 1.0 References: <20230915183707.2707298-1-willy@infradead.org> <20230915183707.2707298-9-willy@infradead.org> In-Reply-To: From: Linus Torvalds Date: Fri, 15 Sep 2023 19:01:14 -0700 X-Gmail-Original-Message-ID: Message-ID: Subject: Re: [PATCH 08/17] alpha: Implement xor_unlock_is_negative_byte To: Matthew Wilcox Cc: linux-kernel@vger.kernel.org, linux-fsdevel@vger.kernel.org, linux-arch@vger.kernel.org, Nicholas Piggin Content-Type: text/plain; charset="UTF-8" X-Spam-Status: No, score=-0.9 required=5.0 tests=DKIM_SIGNED,DKIM_VALID, DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI, SPF_HELO_NONE,SPF_PASS autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on groat.vger.email Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-Greylist: Sender passed SPF test, not delayed by milter-greylist-4.6.4 (groat.vger.email [0.0.0.0]); Fri, 15 Sep 2023 19:04:52 -0700 (PDT) On Fri, 15 Sept 2023 at 17:38, Matthew Wilcox wrote: > > On Fri, Sep 15, 2023 at 05:27:17PM -0700, Linus Torvalds wrote: > > On Fri, 15 Sept 2023 at 11:37, Matthew Wilcox (Oracle) > > wrote: > > > > > > + "1: ldl_l %0,%4\n" > > > + " xor %0,%3,%0\n" > > > + " xor %0,%3,%2\n" > > > + " stl_c %0,%1\n" > > > > What an odd thing to do. > > > > Why don't you just save the old value? That double xor looks all kinds > > of strange, and is a data dependency for no good reason that I can > > see. > > > > Why isn't this "ldl_l + mov %0,%2 + xor + stl_c" instead? > > > > Not that I think alpha matters, but since I was looking through the > > series, this just made me go "Whaa?" > > Well, this is my first time writing Alpha assembler ;-) I stole this > from ATOMIC_OP_RETURN: > > "1: ldl_l %0,%1\n" \ > " " #asm_op " %0,%3,%2\n" \ > " " #asm_op " %0,%3,%0\n" \ Note how that does "orig" assignment first (ie the '%2" destination is the first instruction), unlike your version. So in that ATOMIC_OP_RETURN, it does indeed do the same ALU op twice, but there's no data dependency between the two, so they can execute in parallel. > but yes, mov would do the trick here. Is it really faster than xor? No, I think "mov src,dst" is just a pseudo-op for "or src,src,dst", there's no actual "mov" instruction, iirc. So it's an ALU op too. What makes your version expensive is the data dependency, not the ALU op. So the *odd* thing is not that you have two xor's per se, but how you create the original value by xor'ing the value once, and then xoring the new value with the same mask, giving you the original value back - but with that odd data dependency so that it won't schedule in the same cycle. Does any of this matter? Nope. It's alpha. There's probably a handful of machines, and it's maybe one extra cycle. It's really the oddity that threw me. In ATOMIC_OP_RETURN, the reason it does that op twice is simply that it wants to return the new value. But you literally made it return the *old* value by doing an xor twice in succession, which reverses the bits twice. Was that really what you intended? Linus