Received: by 2002:a05:6a10:1287:0:0:0:0 with SMTP id d7csp1137pxv; Wed, 21 Jul 2021 13:52:22 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzRW4TIZhPxDSX9zFC+J/LdxludRL2iMBdXSAipg+qh8fXa99Hw96t4cL2oPV7ZM5imy5fe X-Received: by 2002:a6b:7619:: with SMTP id g25mr27634776iom.151.1626900742588; Wed, 21 Jul 2021 13:52:22 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1626900742; cv=none; d=google.com; s=arc-20160816; b=P9WjBMyGbf6wlYAtpOqQGZjz/Rri3EC9+RpKNj2TVQgFCeojaXnrrW3zxKHtfz1Cya llRUzHZflTiPSDzpu7QsjX5RlhM7aE2uVeaozZvcSFvK8r0oemhEJTBuJalP5tSN09tE 7M3/FkMBdWSXTuXSvuAEpD0q5Js6xsTno1pUuTD/oWUApjB/aBtVxlvOeUQmb9Tv5Kfl oZyfnVZARny+PtAQ722fz7LyTbU7vJmsFllsfKrirl9V1lNjs7SeDoFsA/BpgBF+2D4y 9CxOKNS5kSJ1TfuWPKQVl88F1/VkArOJDO3VQFjSDDt9m0Wv3nfDkE2LzocUnR1EQKkW Y78g== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:to:subject:message-id:date:from:in-reply-to :references:mime-version:dkim-signature; bh=Wfplf+fD3sAhG/xYw9pABvgaxNvCuT0joqilD8I+WIY=; b=uPIbNgVB4s3v8VaXtkVqz7yWXQM+0xEDlf4FJTYY5sc3AdREiSCplazLR77hz3JFMC Zb8cgTYELCvfuTBWd/sE3bhb2SAAgM/eSGCHpnh6wYHbpnKMFayr6Ip5xrphVxOV7Ha+ QvsvUdU4iTmwPX7uD56B8tjeRIlZDzFq4k7pBG0fILbn4axyUaQc/KUS9P8ihgxRP1Jb UCaRQqYWR7IhRXOohrMhLq4lhxUK3WRZjdD2gnyrxiMPAIzbdCkxQ8QGd6lOTfegC+pX ckKxxqdYMFjtAusIcni+RqczGC0kPnGRosvpxCt1pclPZzCZdgPLCNPplS/aC6HRnu9h eFMA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linux-foundation.org header.s=google header.b=Cy+092dU; 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 a9si27488736ilr.103.2021.07.21.13.52.11; Wed, 21 Jul 2021 13:52:22 -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-foundation.org header.s=google header.b=Cy+092dU; 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 S231925AbhGUTrl (ORCPT + 99 others); Wed, 21 Jul 2021 15:47:41 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:54366 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231766AbhGUTrk (ORCPT ); Wed, 21 Jul 2021 15:47:40 -0400 Received: from mail-lj1-x22b.google.com (mail-lj1-x22b.google.com [IPv6:2a00:1450:4864:20::22b]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 102DEC061757 for ; Wed, 21 Jul 2021 13:28:16 -0700 (PDT) Received: by mail-lj1-x22b.google.com with SMTP id y7so4639850ljm.1 for ; Wed, 21 Jul 2021 13:28:15 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux-foundation.org; s=google; h=mime-version:references:in-reply-to:from:date:message-id:subject:to; bh=Wfplf+fD3sAhG/xYw9pABvgaxNvCuT0joqilD8I+WIY=; b=Cy+092dUMFCuH1x/9wzZLNPpohYwL5mLJ+XoNI+Yu8Va3rjvRxkCDSxK4HdOBvSFlS 0734f+bWrs/te02P8ApPWN8u9tATzWG8YVMRzmGI/BbmcsJ1RHcmjpVboynFKJRBL4z9 CEy0kwsNhs6vH5oTOf6B4dDodN/vfPbEOpwUw= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to; bh=Wfplf+fD3sAhG/xYw9pABvgaxNvCuT0joqilD8I+WIY=; b=UviO/yxM2QgQy/w/a0QA0RzmUpMMshDEkfks3W/j6Ra7bXafZ5CyLcSEWyKPdG2A7/ Moa+QeuD+iy12XGLSYlGNY7UZaTyaUIT6l7iXAlPC3ywBIXaVN4EZlJQdkF/UHfcZQmE Z4nEo6mno7TDfMD0hXT5x4S+q7qbFSYFB4FNGz2GCW9YCcg3heFed3kOiY0MZDYpkXRU lYgPpEetFs5YyU33QyFfOL3rdKL8dB0NUMP4t2SApORpmbJ7KB6SGDpJSC9fVwetFq6E 0sshJwZZCabl8sIi9Q0Crecf5TUiHuwgseB0Nmjdan+sWKamYun2Zd/Vh6sJTfOqf2WL lXaw== X-Gm-Message-State: AOAM533LV74kk+fM6SGGTc29WmUgeolT4aEJlb0fdF+VSSNO1uW/T5TU 1kxWGmpLGUD1I1pEnIC4OwU57xKOv1Zx+5Dp X-Received: by 2002:a2e:b0f6:: with SMTP id h22mr33709453ljl.274.1626899293909; Wed, 21 Jul 2021 13:28:13 -0700 (PDT) Received: from mail-lj1-f173.google.com (mail-lj1-f173.google.com. [209.85.208.173]) by smtp.gmail.com with ESMTPSA id u17sm1820221lfg.306.2021.07.21.13.28.13 for (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Wed, 21 Jul 2021 13:28:13 -0700 (PDT) Received: by mail-lj1-f173.google.com with SMTP id e14so4598448ljo.7 for ; Wed, 21 Jul 2021 13:28:13 -0700 (PDT) X-Received: by 2002:a2e:81c4:: with SMTP id s4mr32086757ljg.251.1626899292773; Wed, 21 Jul 2021 13:28:12 -0700 (PDT) MIME-Version: 1.0 References: <20210721135926.602840-1-nborisov@suse.com> <20210721201029.GQ19710@twin.jikos.cz> In-Reply-To: <20210721201029.GQ19710@twin.jikos.cz> From: Linus Torvalds Date: Wed, 21 Jul 2021 13:27:56 -0700 X-Gmail-Original-Message-ID: Message-ID: Subject: Re: [PATCH] lib/string: Bring optimized memcmp from glibc To: David Sterba , Linus Torvalds , Nikolay Borisov , Linux Kernel Mailing List , Nick Desaulniers , linux-fsdevel , Dave Chinner Content-Type: text/plain; charset="UTF-8" Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Wed, Jul 21, 2021 at 1:13 PM David Sterba wrote: > > adding a memcmp_large that compares by native words or u64 could be > the best option. Yeah, we could just special-case that one place. But see the patches I sent out - I think we can get the best of both worlds. A small and simple memcmp() that is good enough and not the _completely_ stupid thing we have now. The second patch I sent out even gets the mutually aligned case right. Of course, the glibc code also ended up unrolling things a bit, but honestly, the way it did it was too disgusting for words. And if it really turns out that the unrolling makes a big difference - although I doubt it's meaningful with any modern core - I can add a couple of lines to that simple patch I sent out to do that too. Without getting the monster that is that glibc code. Of course, my patch depends on the fact that "get_unaligned()" is cheap on all CPU's that really matter, and that caches aren't direct-mapped any more. The glibc code seems to be written for a world where registers are cheap, unaligned accesses are prohibitively expensive, and unrolling helps because L1 caches are direct-mapped and you really want to do chunking to not get silly way conflicts. If old-style Sparc or MIPS was our primary target, that would be one thing. But it really isn't. Linus