Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1753729AbbBRTqK (ORCPT ); Wed, 18 Feb 2015 14:46:10 -0500 Received: from mail-ob0-f169.google.com ([209.85.214.169]:62937 "EHLO mail-ob0-f169.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751734AbbBRTqI (ORCPT ); Wed, 18 Feb 2015 14:46:08 -0500 MIME-Version: 1.0 In-Reply-To: <878ufvowcd.fsf@mail.parknet.co.jp> References: <1424285300-14431-1-git-send-email-kuleshovmail@gmail.com> <878ufvowcd.fsf@mail.parknet.co.jp> Date: Thu, 19 Feb 2015 01:46:07 +0600 Message-ID: Subject: Re: [PATCH] fs/fat: calculate checksum in a loop instead of directly calculating From: Alexander Kuleshov To: OGAWA Hirofumi Cc: linux-kernel@vger.kernel.org Content-Type: text/plain; charset=UTF-8 Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Length: 2001 Lines: 69 Hello, I tested two simple program with this (gcc-4.9.1) Results are following: time ./test_with_loop real 0m0.001s user 0m0.000s sys 0m0.001s And time ./test_direct_calculation: real 0m0.002s user 0m0.000s sys 0m0.001s As you can see result almsot the same. Also i compared assembly output from two these programras and there are two notes: 1. Assembly output of the program with loop is half as much than program with directly rotation, but ofcourse we can't take it for rule here. Current version prepares stack and than just does: addq $1, %rax movzbl (%rax), %eax addl %edx, %eax movb %al, -1(%rbp) movzbl -1(%rbp), %eax rorb %al movl %eax, %edx movq -24(%rbp), %rax 11 times, but version with loop does the same but with cmp/jump. Thank you. 2015-02-19 1:25 GMT+06:00 OGAWA Hirofumi : > Alexander Kuleshov writes: > >> static inline unsigned char fat_checksum(const __u8 *name) >> { >> + u8 i; >> unsigned char s = name[0]; >> - s = (s<<7) + (s>>1) + name[1]; s = (s<<7) + (s>>1) + name[2]; >> - s = (s<<7) + (s>>1) + name[3]; s = (s<<7) + (s>>1) + name[4]; >> - s = (s<<7) + (s>>1) + name[5]; s = (s<<7) + (s>>1) + name[6]; >> - s = (s<<7) + (s>>1) + name[7]; s = (s<<7) + (s>>1) + name[8]; >> - s = (s<<7) + (s>>1) + name[9]; s = (s<<7) + (s>>1) + name[10]; >> + >> + for (i = 1; i < 11; i++) >> + s = (s << 7) + (s >> 1) + name[i]; >> + >> return s; >> } > > When I wrote this, IIRC, there was measurable performance > difference. All major gcc versions are enough smart now to optimize this? > -- > OGAWA Hirofumi -- To unsubscribe from this list: send the line "unsubscribe linux-kernel" in the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html Please read the FAQ at http://www.tux.org/lkml/