From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1754546AbbIQIql (ORCPT ); Thu, 17 Sep 2015 04:46:41 -0400 Received: from smtp-out4.electric.net ([192.162.216.186]:60838 "EHLO smtp-out4.electric.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1753907AbbIQIqe (ORCPT ); Thu, 17 Sep 2015 04:46:34 -0400 From: David Laight To: "'Jaime Arrocha'" , "'Austin S Hemmelgarn'" , Steve Calfee , Eric Curtin CC: Valentina Manea , "shuah.kh@samsung.com" , USB list , "Kernel development list" Subject: RE: First kernel patch (optimization) Thread-Topic: First kernel patch (optimization) Thread-Index: AQHQ8HU1DYbiR3Tqn0q6zOVXzhX/z54/G9MwgADIvACAAIMdgA== Date: Thu, 17 Sep 2015 08:45:57 +0000 Message-ID: <063D6719AE5E284EB5DD2968C1650D6D1CB989FD@AcuExch.aculab.com> References: <1442346808-3784-1-git-send-email-ericcurtin17@gmail.com> <55F95671.6060405@gmail.com> <063D6719AE5E284EB5DD2968C1650D6D1CB97D13@AcuExch.aculab.com> <55FA1C36.7060007@innercoder.com> In-Reply-To: <55FA1C36.7060007@innercoder.com> Accept-Language: en-GB, en-US Content-Language: en-US X-MS-Has-Attach: X-MS-TNEF-Correlator: x-originating-ip: [10.202.99.200] Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 X-Outbound-IP: 213.249.233.130 X-Env-From: David.Laight@ACULAB.COM X-PolicySMART: 3396946, 3397078 Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Transfer-Encoding: 8bit X-MIME-Autoconverted: from base64 to 8bit by mail.home.local id t8H8klNg007944 From: Jaime Arrocha > Sent: 17 September 2015 02:50 .. > One interesting observation I found was that in O0 and O2, it does make > a call to strlen while in O1 it calculates > the length of the string using: > You want an 'xor %rcx,%rcx' here. > repnz scas %es:(%rdi),%al > not %rcx > sub $0x2,%rcx > > Why does it do that? Is the code above faster? If yes, why not do it in > O2 too? Because 'repnz scasb' is slow, especially on some cpu types. It may win for -Os on 32 bit systems. Pentium 4 netburst have about 40 clocks setup for all the 'rep' instructions, later cpus are better but you might still be talking double figures. On 64 bit cpu there are much faster ways of detecting a zero byte in a 64 bit word by using shifts and masks - so the function call can be a win. David ÿôèº{.nÇ+‰·Ÿ®‰­†+%ŠËÿ±éݶ¥Šwÿº{.nÇ+‰·¥Š{±þG«�éÿŠ{ayºʇڙë,j­¢f£¢·hš�ï�êÿ‘êçz_è®(­éšŽŠÝ¢j"�ú¶m§ÿÿ¾«þG«�éÿ¢¸?™¨è­Ú&£ø§~�á¶iO•æ¬z·švØ^¶m§ÿÿà ÿ¶ìÿ¢¸?–I¥