Received: by 2002:a05:6a10:f3d0:0:0:0:0 with SMTP id a16csp1635590pxv; Fri, 2 Jul 2021 08:30:08 -0700 (PDT) X-Google-Smtp-Source: ABdhPJy8mijX7tjV9z6ENRp8lUnH8q7+6QjFtq7BDXppzcjJH8YpZuKy+9HjkVFLAiyqRJRdVCLb X-Received: by 2002:a05:6602:2587:: with SMTP id p7mr486923ioo.12.1625239808005; Fri, 02 Jul 2021 08:30:08 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1625239807; cv=none; d=google.com; s=arc-20160816; b=l6AT31vsZb9o7eIS2K8qj4uP59eWzuuurDoehsPsC7Qgkyvd2Lp+ICAO9NxwMCsKs5 gp0dpTQkYCJJ9HV+Z0syMRpFnD+/PFhqvZR59cxmNV4VWLP56bdQBvKyvCb2Qi3OxlX/ VpxQp/5Gt1I2Alid/hCdvLdVfbyxrlAWJpDARr4llbt4YFWAd+f7kLCULiTkV60itiFd eylSoHS87YNqIJMVDPYpb+DW3yqwh8mtep/mwhW7VDZ7S46KBU9nVLAXLpcLLeC847L8 TdHZZduouUUYrMyFeRn9eYUnJt4Yry9/Sv760fz44hwgLS/TLjZ5JxRSXkrBF4rS1RGS dRPQ== 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:dkim-filter; bh=COfBRLi+BJ3qGAqOVgLUX0fhQNuQxKTydWlChw0BlLI=; b=lMcZ8dIG768nvMEp0bJF63ZPilUxRN29TM7tde1nuv5Vx6xpxICsyGOLwePyVnpkzv cjCHBRag2SnGbJQWgT/oabG6GUxUpU1KLU4VseAh5nXyLDDtbvCEtkTqyF+wKBIJZ/pP 1dyA2sqSV5YY3i0KdmDLrRC9Kw8LiswZrurjxntel+X3oFR4y7ks6xO3+dkpxJWMAMUE sYqoUupYiGsSpUY5y84p+QRXE+QAwq/34rKtT246g8jbXI6BMvx6FgOgEM80q/Cbac5p wPnmvQwcgcQ+JkbH0H6csjooiVYV6giBA5oVD5nBBPCkWRTZNrcfZY554AjpsiJ3tMin PJuA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linux.microsoft.com header.s=default header.b=tRGwEHas; 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; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linux.microsoft.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id m17si3834216ili.68.2021.07.02.08.29.55; Fri, 02 Jul 2021 08:30:07 -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=@linux.microsoft.com header.s=default header.b=tRGwEHas; 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; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linux.microsoft.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232875AbhGBOrZ (ORCPT + 99 others); Fri, 2 Jul 2021 10:47:25 -0400 Received: from linux.microsoft.com ([13.77.154.182]:54256 "EHLO linux.microsoft.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230424AbhGBOrZ (ORCPT ); Fri, 2 Jul 2021 10:47:25 -0400 Received: from mail-pl1-f180.google.com (mail-pl1-f180.google.com [209.85.214.180]) by linux.microsoft.com (Postfix) with ESMTPSA id B3BAF20B83F6; Fri, 2 Jul 2021 07:44:52 -0700 (PDT) DKIM-Filter: OpenDKIM Filter v2.11.0 linux.microsoft.com B3BAF20B83F6 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux.microsoft.com; s=default; t=1625237092; bh=COfBRLi+BJ3qGAqOVgLUX0fhQNuQxKTydWlChw0BlLI=; h=References:In-Reply-To:From:Date:Subject:To:Cc:From; b=tRGwEHasZTX06Egu9Ww7uR8RabiaJLr5vR4tlDPOfGgBdAE0IHk7ehSVCVKdwfsTX nDL34TDk/hAMHQ9GJhkVTEsbQH2mo7XE3c2M1Me7rIrRLOXwxwAPWBfJvYSqg0z0Re dE3HS528+HtMzM0UXqVixjAMR5aSPvt46WJVMjwM= Received: by mail-pl1-f180.google.com with SMTP id l19so450209plg.6; Fri, 02 Jul 2021 07:44:52 -0700 (PDT) X-Gm-Message-State: AOAM533bsPXci+LPKoOpKHNWaY8umg8/tkK2V6aEPpJiPLJHHcfxla5j XJhAbT1+3r4zVs4xSHOepXhNzjLxXkW5aWy7wJ8= X-Received: by 2002:a17:902:70c4:b029:129:45cd:aa90 with SMTP id l4-20020a17090270c4b029012945cdaa90mr123959plt.43.1625237092188; Fri, 02 Jul 2021 07:44:52 -0700 (PDT) MIME-Version: 1.0 References: <20210702123153.14093-1-mcroce@linux.microsoft.com> <20210702123153.14093-2-mcroce@linux.microsoft.com> <0e0fa030-8995-b930-5e22-954349a0b82e@codethink.co.uk> In-Reply-To: <0e0fa030-8995-b930-5e22-954349a0b82e@codethink.co.uk> From: Matteo Croce Date: Fri, 2 Jul 2021 16:44:16 +0200 X-Gmail-Original-Message-ID: Message-ID: Subject: Re: [PATCH v2 1/3] lib/string: optimized memcpy To: Ben Dooks Cc: Linux Kernel Mailing List , Nick Kossifidis , Guo Ren , Christoph Hellwig , David Laight , Palmer Dabbelt , Emil Renner Berthing , Drew Fustini , linux-arch , Andrew Morton , Nick Desaulniers , linux-riscv Content-Type: text/plain; charset="UTF-8" Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Fri, Jul 2, 2021 at 4:37 PM Ben Dooks wrote: > > On 02/07/2021 13:31, Matteo Croce wrote: > > From: Matteo Croce > > > > Rewrite the generic memcpy() to copy a word at time, without generating > > unaligned accesses. > > > > The procedure is made of three steps: > > First copy data one byte at time until the destination buffer is aligned > > to a long boundary. > > Then copy the data one long at time shifting the current and the next long > > to compose a long at every cycle. > > Finally, copy the remainder one byte at time. > > > > This is the improvement on RISC-V: > > > > original aligned: 75 Mb/s > > original unaligned: 75 Mb/s > > new aligned: 114 Mb/s > > new unaligned: 107 Mb/s > > > > and this the binary size increase according to bloat-o-meter: > > > > Function old new delta > > memcpy 36 324 +288 > > > > > > Signed-off-by: Matteo Croce > > --- > > lib/string.c | 80 ++++++++++++++++++++++++++++++++++++++++++++++++++-- > > 1 file changed, 77 insertions(+), 3 deletions(-) > > Doesn't arch/riscv/lib/memcpy.S also exist for an architecture > optimised version? I would have thought the lib/string.c version > was not being used? > > Yes, but this series started as C replacement for the assembly one, which generates unaligned accesses. Unfortunately the existing RISC-V processors can't handle unaligned accesses, so they are emulated with a terrible slowdown. Then, since there wasn't any riscv specific code, it was proposed as generic code: Discussion: https://lore.kernel.org/linux-riscv/20210617152754.17960-1-mcroce@linux.microsoft.com/ -- per aspera ad upstream