Received: by 2002:a05:6358:4e97:b0:b3:742d:4702 with SMTP id ce23csp6087rwb; Fri, 12 Aug 2022 13:09:52 -0700 (PDT) X-Google-Smtp-Source: AA6agR5HBtDdG7oIBaW2qnjUKLzinBdoiNalSz90jDuWoB62razuTepmwHloPORGvn8LHcEMZ/D0 X-Received: by 2002:a05:6402:20b:b0:440:cb9f:c469 with SMTP id t11-20020a056402020b00b00440cb9fc469mr5027946edv.420.1660334991774; Fri, 12 Aug 2022 13:09:51 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1660334991; cv=none; d=google.com; s=arc-20160816; b=Nm21+89d0QrvLpohCQ8UAOMW0KwGndtWYy6BNuSjjWwXP2Hph7UEwlq/jdJsqri47e PdAhkZZ/mGLvtOYniS6y98mpv4rc651984cDMjl7iaLgl4kLMmTfdUPJylVSuYvLgb9G ZQI2fLeQzYZtVxvAxDDkvj8KXsfpq4+osJBGtNo56eed2bcuqQA2oQ96E0VZoegAa5Sk Y59orXEJLcNWjpxGqkIKFrNvB88zTWHkDIhNH/wK2B+QAbpFeW9yN/hFpdRdrXH2l/A6 2sSGVis9Jo1RsBD2aFdqpZS4b2Zo9UlUpliyK0Hd3USurPESBgqW3tR6lZaeXD1HWb6b dzHw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:user-agent:in-reply-to:content-disposition :mime-version:references:message-id:subject:cc:to:from:date :dkim-signature; bh=2QJgRfvIpZnynJdWuRXNSUiG+jDqoYFliXMFXCfhwRU=; b=JD+JVJdGI5Od/Pyda9bIh7ZJOhZvDCjpmrbTy4UP6/72MifmHLdj2F6XOugKw4Wiu4 1xDwzl55soxJGieCbojngjFQqExe1V1M6s8U39sG4vY7Gipaqe6ohMxzKaxGFRP1MXcM uaZSO2mEQUq8L478aaF+r2bey1mMVckI6q7b6GWhNC/1ERRQowoJcj8QYKFEG/Yy+Gxf eOZtDuWJGyVcSepx1EN1kKWasmNOn+ZJaJjyUhx+qRflO7Ydx38zN+iNVPPy1s+CpGs6 FUVIk+7wmZyb9DHu6aKkmbRhKWtJJmOUD5eik9yDxIcPQt6xSj0YhqejaZK9Qa+puCVg JtdQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@ucw.cz header.s=gen1 header.b="HeMLp/tr"; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=ucw.cz Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id f19-20020a170906139300b007303646197csi2046091ejc.596.2022.08.12.13.09.25; Fri, 12 Aug 2022 13:09:51 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@ucw.cz header.s=gen1 header.b="HeMLp/tr"; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=ucw.cz Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S237787AbiHLTGi (ORCPT + 99 others); Fri, 12 Aug 2022 15:06:38 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:38940 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S237856AbiHLTGg (ORCPT ); Fri, 12 Aug 2022 15:06:36 -0400 Received: from jabberwock.ucw.cz (jabberwock.ucw.cz [46.255.230.98]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 5D84183F2C for ; Fri, 12 Aug 2022 12:06:35 -0700 (PDT) Received: by jabberwock.ucw.cz (Postfix, from userid 1017) id 1B4571C000B; Fri, 12 Aug 2022 21:06:33 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ucw.cz; s=gen1; t=1660331193; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: in-reply-to:in-reply-to:references:references; bh=2QJgRfvIpZnynJdWuRXNSUiG+jDqoYFliXMFXCfhwRU=; b=HeMLp/tr+Zr1tt3v59W9Z8SpAd/dUIWX0QQ7Te8bWFamWrkcVk1dsN4u6Mj/grGp+kEGzO vCLqQ5uVPqBZgoyHxIuiZvKExbfFY7WTXjZ/ORf9iNrkYYEKKoILx90f/aJM2Ur74UiaXU k4aSOA8NiAI4SnQaMqpOVbU/kiwsxWQ= Date: Fri, 12 Aug 2022 21:06:31 +0200 From: Pavel Machek To: Yu-Jen Chang Cc: andy@kernel.org, akinobu.mita@gmail.com, jserv@ccns.ncku.edu.tw, linux-kernel@vger.kernel.org Subject: Re: [PATCH 0/2] Optimize memchr() Message-ID: <20220812190631.GA1347@bug> References: <20220710142822.52539-1-arthurchang09@gmail.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20220710142822.52539-1-arthurchang09@gmail.com> User-Agent: Mutt/1.5.23 (2014-03-12) X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,SPF_HELO_NONE,SPF_NONE, T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Hi! > This patche series optimized "memchr()" and add a macro for > "memchr_inv()" so that both funtions can use it to generate bit mask. > > The original implementaion of "memchr()" is based on byte-wise comparison, > which do not fully use 64-bit or 32-bit register in CPU. We implement a > word-wise comparison so that at least 4 bytes can be compared at the same > time. The optimized "memchr()" is nearly 4x faster than the original one > for long strings. In Linux Kernel, we find that the length of the string Well... how much slower is it for short strings? > searched by "memchr()" is up to 512 bytes in drivers/misc/lkdtm/heap.c. > In our test, the optimized version is about 20% faster if the target > character is at the end of the string when going through a 512-byte > string. "What is the average length passed to memchr" would be more useful question. Best regards, Pavel