Received: by 2002:a05:7412:8d08:b0:f9:2d0a:d759 with SMTP id bj8csp253524rdb; Sun, 17 Dec 2023 10:11:55 -0800 (PST) X-Google-Smtp-Source: AGHT+IH+/5OJb28qa798prFbeHuhQp0im8Qf6wRxwIV4PK09BkTaexqhNUBx/nH8WFs2+mDZ8OL2 X-Received: by 2002:a05:6808:1495:b0:3b9:e902:bb6 with SMTP id e21-20020a056808149500b003b9e9020bb6mr18362161oiw.89.1702836714776; Sun, 17 Dec 2023 10:11:54 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1702836714; cv=none; d=google.com; s=arc-20160816; b=S2+b1y73X9iJi2Se8JdLr2kZ1+7+JurXS8siq+tvi4Ax34v7seAterVnXO+MTmCLiE 9Pvr7t4R+xF0UUnSepi3rWMlp//MaYdTYtxYdwoiBr0Qu8pHGs+asDoRtMyq408T7FIr 4yyx4lu0NhYuo+egzCfOeI9TBIPOR9U9XK33OeyHmqu9YpoV+X10LAspn/QzVFw+6/ou 3j4kGCJzTFXMLLgooPoXrobanQiXb7Y7g3d7IorL9P68SI6yRG2r+Nf6XtmHJ48nlgzb CfKlRUiZWSIDsnOinVSMhCZYHYEQwmS7es/JqSEN7AcqhVtuC6enqB2Qh7gwNmkZ8Wgp mdNg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:content-language:mime-version :list-unsubscribe:list-subscribe:list-id:precedence:accept-language :in-reply-to:references:message-id:date:thread-index:thread-topic :subject:cc:to:from; bh=36adgu59t9w5iuUnrV+PBPp5BQw6hEmK4nrtiJzLiGc=; fh=oVjX24B+VH8muKPAgYA9AUUcWAqwirHcI+RgGShc97U=; b=Fh3oazsRxUIrBXHRwDAVtNK6LA6PBMkQiJLmUOwJtcg+8gqMY0J/6trHsipjtIXVSt CSg2lWN9sN1Mc4JR1brdOIcZ6qnTljm8fjSY1ISgDcUzbfo+b1wZjSQLtHibhh6HQs6E N/QC5Puxn8wBPIdcdzF5Wh+ubldA6t5alN51eOoSV58Wm8cYMSG855fepVAnR27K4/Zq bRXBNzJsg7CcbGK79Gzyebl08JGSf/yPrzNjthHyTcKu8WuN38oVr+hEXZP5Y7ETPM3P 70lRDt4artMz9kNQV44KB+/YPgyOPB5e0HwFkej77HjBMJZ+BqkSMERZbVEurXPW8BGK znYw== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel+bounces-2771-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-2771-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=aculab.com Return-Path: Received: from sv.mirrors.kernel.org (sv.mirrors.kernel.org. [2604:1380:45e3:2400::1]) by mx.google.com with ESMTPS id e33-20020a630f21000000b005c6faf0a670si15423410pgl.257.2023.12.17.10.11.54 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 17 Dec 2023 10:11:54 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-2771-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) client-ip=2604:1380:45e3:2400::1; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel+bounces-2771-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-2771-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=aculab.com 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 sv.mirrors.kernel.org (Postfix) with ESMTPS id 60860282CB0 for ; Sun, 17 Dec 2023 18:11:54 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id DF80347A66; Sun, 17 Dec 2023 18:11:24 +0000 (UTC) X-Original-To: linux-kernel@vger.kernel.org Received: from eu-smtp-delivery-151.mimecast.com (eu-smtp-delivery-151.mimecast.com [185.58.85.151]) (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 7767A481BE for ; Sun, 17 Dec 2023 18:11:22 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=ACULAB.COM Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=aculab.com Received: from AcuMS.aculab.com (156.67.243.121 [156.67.243.121]) by relay.mimecast.com with ESMTP with both STARTTLS and AUTH (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA384) id uk-mtapsc-8-8i7rSkpZMKS305nSrnFEhQ-1; Sun, 17 Dec 2023 18:11:13 +0000 X-MC-Unique: 8i7rSkpZMKS305nSrnFEhQ-1 Received: from AcuMS.Aculab.com (10.202.163.6) by AcuMS.aculab.com (10.202.163.6) with Microsoft SMTP Server (TLS) id 15.0.1497.48; Sun, 17 Dec 2023 18:10:54 +0000 Received: from AcuMS.Aculab.com ([::1]) by AcuMS.aculab.com ([::1]) with mapi id 15.00.1497.048; Sun, 17 Dec 2023 18:10:54 +0000 From: David Laight To: 'Ivan Orlov' , "paul.walmsley@sifive.com" , "palmer@dabbelt.com" , "aou@eecs.berkeley.edu" CC: "conor.dooley@microchip.com" , "ajones@ventanamicro.com" , "samuel@sholland.org" , "alexghiti@rivosinc.com" , "linux-riscv@lists.infradead.org" , "linux-kernel@vger.kernel.org" , "skhan@linuxfoundation.org" Subject: RE: [PATCH] riscv: lib: Optimize 'strlen' function Thread-Topic: [PATCH] riscv: lib: Optimize 'strlen' function Thread-Index: AQHaLduBo9lhsHug1EOTPi9OJpSM+LCtyBWA Date: Sun, 17 Dec 2023 18:10:54 +0000 Message-ID: References: <20231213154530.1970216-1-ivan.orlov0322@gmail.com> In-Reply-To: <20231213154530.1970216-1-ivan.orlov0322@gmail.com> Accept-Language: en-GB, en-US X-MS-Has-Attach: X-MS-TNEF-Correlator: x-ms-exchange-transport-fromentityheader: Hosted Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: aculab.com Content-Language: en-US Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: quoted-printable From: Ivan Orlov > Sent: 13 December 2023 15:46 Looking at the old code... > 1: > -=09lbu=09t0, 0(t1) > -=09beqz=09t0, 2f > -=09addi=09t1, t1, 1 > -=09j=091b I suspect there is (at least) a two clock stall between the 'ldu' and 'beqz'. Allowing for one clock for the 'predicted taken' branch that is 7 clocks/byte. Try this one - especially on 32bit: =09mov=09t0, a0 =09and=09t1, t0, 1 =09sub=09t0, t0, t1 =09bnez=09t1, 2f 1: =09ldb=09t1, 0(t0) 2:=09ldb=09t2, 1(t0) =09add=09t0, t0, 2 =09beqz=09t1, 3f =09bnez=09t2, 1b =09add=09t0, t0, 1 3:=09sub=09t0, t0, 2 =09sub=09a0, t0, a0 =09ret Might be 6 clocks for 2 bytes. The much smaller cache footprint will also help. =09David - Registered Address Lakeside, Bramley Road, Mount Farm, Milton Keynes, MK1 1= PT, UK Registration No: 1397386 (Wales)