Received: by 2002:a05:7412:d1aa:b0:fc:a2b0:25d7 with SMTP id ba42csp964008rdb; Tue, 30 Jan 2024 04:13:20 -0800 (PST) X-Google-Smtp-Source: AGHT+IF1ztdv0lfEr+l/USK5FMw2X8gHAh0SUVYdC5xVM9k0S29pMy/P0sq0nzMtjNP08aQRQKBv X-Received: by 2002:a17:902:ea0c:b0:1d8:dc04:254b with SMTP id s12-20020a170902ea0c00b001d8dc04254bmr1818353plg.46.1706616800509; Tue, 30 Jan 2024 04:13:20 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1706616800; cv=pass; d=google.com; s=arc-20160816; b=qY9qTo6/GEsyq7GiHgU3Gt94jkRmVJZzpsdoRkDjfchYuJvffUBAz+DHRGq65bm6Ur Cf2CekxlntdcfCrN46CuGld36QtVDP96lETYvVK7WQU9NF+8OP1R6Wi4c4PeYEQQQ4xW LWUROFnTLNlIbI7zjXeUBgu4DQM7Um13v9IGMhPS+1hlaAYnXZsjHQeTkXe4vQRMXVZ6 +yYBltPz/bm9fT8PaE2HNnqJn/G0Y4m/fUXT2+dk3zeo9IQHg8AacgL3A9vhn/fbfxx1 sXFQOe3ZuGC3pYoCyCmSnZvCFpaBekIcLRdJORiv02XzWdXUx9MjXgxu4qrYW04mL5T9 37ig== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=in-reply-to:content-disposition:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:references:message-id:subject:cc :to:from:date:dkim-signature; bh=Un4sMBz8IWjCwiu9ckLig42gi4M2ZWfwOc36wW8HeME=; fh=DLmumNNCMnzYWvd8+LxzRuP5JGkmdTNvNLRdIZA8wtQ=; b=l8Z82Z+NCjnXiD8DnwuzrATRKSwwIlSZzEomX8oYNZQ4pZleW+tAHyGWum4VIztQyT mI49LPNgdc2D+o2n0VOuCuyge2HBE2t4cgQpG9Jd/fVbagC4oAcJMdK/dru5v/QI7Kgt 207tt1vNpWMdLgGsHvJZK7vObR/1IZZbUFeO0y4T8a/9CGwJxVeb6u7Lo2lqa0PCh8wo nfsHhadBThPn8x8zWh4rBw33xF4LDikyRfsO3cDlUwGajj/2e0626wbuM9SGh4f1XigR v0LaOASJLor6bdUg9lQwURuLv2mpYyce++qfpSVZzkR+93nLwMX071ra3TS7Ki35Lnnc Ih0w== ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=Jp8N5znL; arc=pass (i=1 dkim=pass dkdomain=kernel.org); spf=pass (google.com: domain of linux-kernel+bounces-44543-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.48.161 as permitted sender) smtp.mailfrom="linux-kernel+bounces-44543-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from sy.mirrors.kernel.org (sy.mirrors.kernel.org. [147.75.48.161]) by mx.google.com with ESMTPS id l16-20020a170903245000b001d916995426si425868pls.92.2024.01.30.04.13.19 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 30 Jan 2024 04:13:20 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-44543-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.48.161 as permitted sender) client-ip=147.75.48.161; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=Jp8N5znL; arc=pass (i=1 dkim=pass dkdomain=kernel.org); spf=pass (google.com: domain of linux-kernel+bounces-44543-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.48.161 as permitted sender) smtp.mailfrom="linux-kernel+bounces-44543-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by sy.mirrors.kernel.org (Postfix) with ESMTPS id 700FFB29D5C for ; Tue, 30 Jan 2024 11:48:28 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 85C0467E75; Tue, 30 Jan 2024 11:43:35 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="Jp8N5znL" Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 82B3E67A19 for ; Tue, 30 Jan 2024 11:43:34 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1706615014; cv=none; b=XzmdCbq8GTH/bdEqtYpU6br7MDg2nTBujwtGz34+pVyh6Te5xk2AlPh9YNKnF7U8H7xAtoG9lioBUWj1COis0NF3wkCQ9l3lTUIphqbK57UG2sWNWOdTsA4cFi80UFg4S733+lHnZnFeh6MZa66O0jW4e0YAhOsmy+1eQYT0GJs= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1706615014; c=relaxed/simple; bh=1dvspfcJflTfBs11wiC68BBxE/i2yh/F5YLwP7Tw4mk=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=kzbheVo33uPgqEGX5ndp+00A2WTcg//uCef35dYbt0bWRyE3lQKBs3EHh6sZgWozOWVuH2XOSOWfVXhjkekpKT//W1CD9DVlBR27odN7xYuTl42imnyLHSUdIbCvy3HqKylefSHmL9vXOSWFoa2i7FGA++MnR5z2OlZMly1v6pM= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=Jp8N5znL; arc=none smtp.client-ip=10.30.226.201 Received: by smtp.kernel.org (Postfix) with ESMTPSA id 808ECC433F1; Tue, 30 Jan 2024 11:43:32 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1706615014; bh=1dvspfcJflTfBs11wiC68BBxE/i2yh/F5YLwP7Tw4mk=; h=Date:From:To:Cc:Subject:References:In-Reply-To:From; b=Jp8N5znLrchQW7iQQFTKbpb455YiKpVWmC2a96EWlFM2XehFfkc5+M2RDR2OcG0dy ekgA/SJ68RF1kQSb8q2wpNOpWX/9ry/nzv4+NjK1fCgaEnbShPFVLMf+X86KBDNzxB GPF+8bbGMHRhf0TLxcacVIfmcc3td0bU1Qtj5wJUku5E9qlg4E3nry9a6Nrm9Hzz9j ByFXdex/dIT7RE4ozYSKyeMZll6aTcvvWs7YtAHTgwuCeffG9/bq/FXJvc1qb9iJ/7 wYKi0RiLZX0yY2Q2H+pxX8uDgNFxn1dZO2bn5KgB5CMTuxl4zxSHEmCGGHTwUhhy9Q XiPWxhcLiPLfA== Date: Tue, 30 Jan 2024 19:30:43 +0800 From: Jisheng Zhang To: David Laight Cc: Paul Walmsley , Palmer Dabbelt , Albert Ou , "linux-riscv@lists.infradead.org" , "linux-kernel@vger.kernel.org" , Matteo Croce , kernel test robot Subject: Re: [PATCH 2/3] riscv: optimized memmove Message-ID: References: <20240128111013.2450-1-jszhang@kernel.org> <20240128111013.2450-3-jszhang@kernel.org> <59bed43df37b4361a8a1cb31b8582e9b@AcuMS.aculab.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Disposition: inline In-Reply-To: <59bed43df37b4361a8a1cb31b8582e9b@AcuMS.aculab.com> On Sun, Jan 28, 2024 at 12:47:00PM +0000, David Laight wrote: > From: Jisheng Zhang > > Sent: 28 January 2024 11:10 > > > > When the destination buffer is before the source one, or when the > > buffers doesn't overlap, it's safe to use memcpy() instead, which is > > optimized to use a bigger data size possible. > > > ... > > + * Simply check if the buffer overlaps an call memcpy() in case, > > + * otherwise do a simple one byte at time backward copy. > > I'd at least do a 64bit copy loop if the addresses are aligned. > > Thinks a bit more.... > > Put the copy 64 bytes code (the body of the memcpy() loop) > into it an inline function and call it with increasing addresses > in memcpy() are decrementing addresses in memmove. Hi David, Besides the 64 bytes copy, there's another optimization in __memcpy: word-by-word copy even if s and d are not aligned. So if we make the two optimizd copy as inline functions and call them in memmove(), we almost duplicate the __memcpy code, so I think directly calling __memcpy is a bit better. Thanks > > So memcpy() contains: > src_lim = src_lim + count; > ... alignment copy > for (; src + 64 <= src_lim; src += 64; dest += 64) > copy_64_bytes(dest, src); > ... tail copy > > Then you can do something very similar for backwards copies. > > David > > - > Registered Address Lakeside, Bramley Road, Mount Farm, Milton Keynes, MK1 1PT, UK > Registration No: 1397386 (Wales) >