Received: by 2002:a05:6a10:206:0:0:0:0 with SMTP id 6csp3829098pxj; Mon, 21 Jun 2021 07:30:50 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwozJqxZZuF2bRL/12iDjfs1YamWM5E5uqOM9O+yh2v088GH/vI4aJOyfMa1131qrA85Ain X-Received: by 2002:aa7:c686:: with SMTP id n6mr10442133edq.0.1624285850383; Mon, 21 Jun 2021 07:30:50 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1624285850; cv=none; d=google.com; s=arc-20160816; b=MMqzBAl1wYouSs9MVhdoFmM327q7UtCVsCntvobaN0aNxWvsV+SwiuN2sGyVFAHFg0 GSKuNfk+vreevkC8gVYESRFlTVHG6+tYtZTnJEL5/bUmkHs+SD7ck2tevWFOBt9VJzvO qJqGwYi4Lj5BUguoROnJxZF0wvk20+hw1H1Se2ikolhxG6FG+P2+yLXX1/8mjAuKGbdn vtnzzJWMx9KWOdxIKt0Ixh42J1IB4KS9E3futn0r40UlQ5AFtpazz/3NAVHFJslStcI8 YSO3q0IPFizQtFcPbb4v99MnhLhEHQYzhJnZ+oEStDBtHHWdKxn2AlBgqkXamq8VVbzz 4nIw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:in-reply-to:content-disposition:mime-version :references:message-id:subject:cc:to:from:date:dkim-signature; bh=MMc2KGdoutHfZtgfbYoRfjF4kYXtJrSnb/pfXowYFuM=; b=UL40QOXR37RcAAR4r/iV7CrR11uMRXTDb0SXdBr9QCFRsC16kP3sCFgxMaAm8JDDM6 MWTQqtVeas1nll7u5Qv3HDDqkyG6zvqTVzBAkacpUeqr+YTyOK4p5UG9ZcRP5K0eyEPJ bfAMyn5K4F9C3ZSf/LDIZmdZOvqWYcrKO1uafQWBdE4U+Ca9bYX+KJlIkOnHPfs7L8Fv XTCRwgGzre8YAEpIjGutHcTOxgPvR9rXZ8NtjRvO5BUJpBnt5AsyMqKrp8oxuVwgW9dx 87tgkT6B00JhkUdKewmNBkUWvkzyb9Pg0wLR+Jd+01YnqZoDPVT71dOK3JJKMKdMo7b5 3jqw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@infradead.org header.s=casper.20170209 header.b=a7IMFKTT; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id i17si15230538edb.326.2021.06.21.07.30.28; Mon, 21 Jun 2021 07:30:50 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@infradead.org header.s=casper.20170209 header.b=a7IMFKTT; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230118AbhFUO3Y (ORCPT + 99 others); Mon, 21 Jun 2021 10:29:24 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:58148 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229904AbhFUO3W (ORCPT ); Mon, 21 Jun 2021 10:29:22 -0400 Received: from casper.infradead.org (casper.infradead.org [IPv6:2001:8b0:10b:1236::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 22462C061574; Mon, 21 Jun 2021 07:27:08 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=casper.20170209; h=In-Reply-To:Content-Type:MIME-Version: References:Message-ID:Subject:Cc:To:From:Date:Sender:Reply-To: Content-Transfer-Encoding:Content-ID:Content-Description; bh=MMc2KGdoutHfZtgfbYoRfjF4kYXtJrSnb/pfXowYFuM=; b=a7IMFKTTLtH6QzE9oeMOnqWREB k74qpt9XqgIAsd8S9v9Ne2UShz2hSFYEGNbPUZtSwlg+cIk8tvrsOyP3mi08RLF+ZMj62OG1F9+Pw gaZfMY5/ziFDUMvDSiNQbxCElDxzlJ2zoObDofYFLCNtlPs+d2JeEYWboNKhJBP0sw3nMOecTf5sN qBJ3hi+T4QI/DgkLXEzsg5FZspWeU9g1Vh6c3WyJCA0rin+yrt/aImCiv373zIVGxKTlNTLV2eS4w vF3yy0w1zUvMUi8wRFYqbH8xoYyX6W3wpoTGoKnu9clF8lCNq0Yo86bQOCpOhXV75gOxYMj2R5CT7 3I3pdb6g==; Received: from hch by casper.infradead.org with local (Exim 4.94.2 #2 (Red Hat Linux)) id 1lvKsh-00DB4u-Dk; Mon, 21 Jun 2021 14:26:38 +0000 Date: Mon, 21 Jun 2021 15:26:31 +0100 From: Christoph Hellwig 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 1/3] riscv: optimized memcpy Message-ID: References: <20210617152754.17960-1-mcroce@linux.microsoft.com> <20210617152754.17960-2-mcroce@linux.microsoft.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20210617152754.17960-2-mcroce@linux.microsoft.com> X-SRS-Rewrite: SMTP reverse-path rewritten from by casper.infradead.org. See http://www.infradead.org/rpr.html Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Thu, Jun 17, 2021 at 05:27:52PM +0200, Matteo Croce wrote: > +extern void *memcpy(void *dest, const void *src, size_t count); > +extern void *__memcpy(void *dest, const void *src, size_t count); No need for externs. > +++ b/arch/riscv/lib/string.c Nothing in her looks RISC-V specific. Why doesn't this go into lib/ so that other architectures can use it as well. > +#include I think you only need export.h. > +void *__memcpy(void *dest, const void *src, size_t count) > +{ > + const int bytes_long = BITS_PER_LONG / 8; > +#ifndef CONFIG_HAVE_EFFICIENT_UNALIGNED_ACCESS > + const int mask = bytes_long - 1; > + const int distance = (src - dest) & mask; > +#endif > + union const_types s = { .u8 = src }; > + union types d = { .u8 = dest }; > + > +#ifndef CONFIG_HAVE_EFFICIENT_UNALIGNED_ACCESS > + if (count < MIN_THRESHOLD) Using IS_ENABLED we can avoid a lot of the mess in this function. int distance = 0; if (!IS_ENABLED(CONFIG_HAVE_EFFICIENT_UNALIGNED_ACCESS)) { if (count < MIN_THRESHOLD) goto copy_remainder; /* copy a byte at time until destination is aligned */ for (; count && d.uptr & mask; count--) *d.u8++ = *s.u8++; distance = (src - dest) & mask; } if (distance) { ... > + /* 32/64 bit wide copy from s to d. > + * d is aligned now but s is not, so read s alignment wise, > + * and do proper shift to get the right value. > + * Works only on Little Endian machines. > + */ Normal kernel comment style always start with a: /* > + for (next = s.ulong[0]; count >= bytes_long + mask; count -= bytes_long) { Please avoid the pointlessly overlong line. And (just as a matter of personal preference) I find for loop that don't actually use a single iterator rather confusing. Wjy not simply: next = s.ulong[0]; while (count >= bytes_long + mask) { ... count -= bytes_long; }