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 X-Spam-Level: X-Spam-Status: No, score=-3.5 required=3.0 tests=BAYES_00,DKIM_INVALID, DKIM_SIGNED,HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI,SPF_HELO_NONE, SPF_PASS autolearn=no autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id EB05EC4743C for ; Tue, 22 Jun 2021 00:46:25 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id C457E6124B for ; Tue, 22 Jun 2021 00:46:25 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230040AbhFVAsj (ORCPT ); Mon, 21 Jun 2021 20:48:39 -0400 Received: from mailgate.ics.forth.gr ([139.91.1.2]:56467 "EHLO mailgate.ics.forth.gr" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229762AbhFVAsj (ORCPT ); Mon, 21 Jun 2021 20:48:39 -0400 Received: from av3.ics.forth.gr (av3in.ics.forth.gr [139.91.1.77]) by mailgate.ics.forth.gr (8.15.2/ICS-FORTH/V10-1.8-GATE) with ESMTP id 15M0kNwa035486 for ; Tue, 22 Jun 2021 03:46:23 +0300 (EEST) DKIM-Signature: v=1; a=rsa-sha256; d=ics.forth.gr; s=av; c=relaxed/simple; q=dns/txt; i=@ics.forth.gr; t=1624322777; x=1626914777; h=From:Sender:Reply-To:Subject:Date:Message-ID:To:Cc:MIME-Version:Content-Type: Content-Transfer-Encoding:Content-ID:Content-Description:Resent-Date:Resent-From: Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:In-Reply-To:References:List-Id: List-Help:List-Unsubscribe:List-Subscribe:List-Post:List-Owner:List-Archive; bh=0TIRxIkkteAzwssAi+Hquy4jV1LNAzUACaNk/lpu6ew=; b=o0fdKLodMohtHshXDEq8hARatX0xabreVNwHrHMQWImCnCFn6ep0idKk/EOR4NXv /FQKsPndB+8o4mbmcwBPNpepmlZ9r3x6BsRyrSNJxxMSgH0ce6UNNx7efv6yMFqq wp/v2TdlOCgFY2p09yGgMivS3YxdQWYB8AUuVLZKbvq+1wN6mHGuG8CHrcyWMRvk gFKiVMe1ZkJj+wPWBUmxK3Xq7OsFRdZCv0jIjsoUHUpuSgF8HI+lQKCBibpTXW2N qhkliIkVjFHoLLY6D9K5rOr7qz2QRXLbvL/xUeVDwEKLTyMn2ZSSMvFUSBSKNE3S UFfITKPcba/Ia5+02Q/oFQ==; X-AuditID: 8b5b014d-962f1700000067b6-be-60d132d912be Received: from enigma.ics.forth.gr (enigma.ics.forth.gr [139.91.151.35]) by av3.ics.forth.gr (Symantec Messaging Gateway) with SMTP id 51.60.26550.9D231D06; Tue, 22 Jun 2021 03:46:17 +0300 (EEST) X-ICS-AUTH-INFO: Authenticated user: at ics.forth.gr MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 8bit Date: Tue, 22 Jun 2021 03:46:16 +0300 From: Nick Kossifidis To: Matteo Croce Cc: linux-riscv@lists.infradead.org, linux-kernel@vger.kernel.org, linux-arch@vger.kernel.org, Paul Walmsley , Palmer Dabbelt , Albert Ou , Atish Patra , Emil Renner Berthing , Akira Tsukamoto , Drew Fustini , Bin Meng , David Laight , Guo Ren Subject: Re: [PATCH v3 2/3] riscv: optimized memmove Organization: FORTH In-Reply-To: <20210617152754.17960-3-mcroce@linux.microsoft.com> References: <20210617152754.17960-1-mcroce@linux.microsoft.com> <20210617152754.17960-3-mcroce@linux.microsoft.com> Message-ID: <3a71b234ec05b6ce842a3d6da552ba30@mailhost.ics.forth.gr> X-Sender: mick@mailhost.ics.forth.gr User-Agent: Roundcube Webmail/1.3.16 X-Brightmail-Tracker: H4sIAAAAAAAAA+NgF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17 18:27, Matteo Croce έγραψε: > + > +/* > + * Simply check if the buffer overlaps an call memcpy() in case, > + * otherwise do a simple one byte at time backward copy. > + */ > +void *__memmove(void *dest, const void *src, size_t count) > +{ > + if (dest < src || src + count <= dest) > + return memcpy(dest, src, count); > + > + if (dest > src) { > + const char *s = src + count; > + char *tmp = dest + count; > + > + while (count--) > + *--tmp = *--s; > + } > + return dest; > +} > +EXPORT_SYMBOL(__memmove); > + Copying backwards byte-per-byte is suboptimal, I understand this is not a very common scenario but you could at least check if they are both word-aligned e.g. (((src + len) | (dst + len)) & mask), or missaligned by the same offset e.g. (((src + len) ^ (dst + len)) & mask) and still end up doing word-by-word copying. Ideally it would be great if you re-used the same technique you used for forwards copying on your memcpy. > +void *memmove(void *dest, const void *src, size_t count) __weak > __alias(__memmove); > +EXPORT_SYMBOL(memmove); As I mentioned on your memcpy patch, if you implement memmove, you can just alias memcpy to memmove and we won't have to worry about memcpy being used on overlapping regions.