lists.openwall.net   lists  /  announce  owl-users  owl-dev  john-users  john-dev  passwdqc-users  yescrypt  popa3d-users  /  oss-security  kernel-hardening  musl  sabotage  tlsify  passwords  /  crypt-dev  xvendor  /  Bugtraq  Full-Disclosure  linux-kernel  linux-netdev  linux-ext4  linux-hardening  linux-cve-announce  PHC 
Open Source and information security mailing list archives
 
Hash Suite: Windows password security audit tool. GUI, reports in PDF.
[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <87wq3fnep7.fsf@mail.parknet.co.jp>
Date:	Thu, 19 Feb 2015 05:32:20 +0900
From:	OGAWA Hirofumi <hirofumi@...l.parknet.co.jp>
To:	Alexander Kuleshov <kuleshovmail@...il.com>
Cc:	linux-kernel@...r.kernel.org
Subject: Re: [PATCH] fs/fat: calculate checksum in a loop instead of directly calculating

Alexander Kuleshov <kuleshovmail@...il.com> writes:

> 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

Hm,

#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>

typedef unsigned char	__u8;
typedef unsigned char	u8;

#if 1
static inline unsigned char fat_checksum(const __u8 *name)
{
	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];
	return s;
}
#else
static inline unsigned char fat_checksum(const __u8 *name)
{
	unsigned char s = name[0];
	u8 i;
	for (i = 1; i < 11; i++)
		s = (s << 7) + (s >> 1) + name[i];
	return s;
}
#endif

static __attribute__ ((noinline)) int test(unsigned char *name)
{
	long i;
	for (i = 0; i < 100000000L; i++)
		name[i % 11] = fat_checksum(name);
	return name[0];
}

int main(int argc, char *argv[])
{
	printf("%u\n", test((unsigned char *)argv[1]));
	return 0;
}


  $ gcc --version
  gcc (Debian 4.9.1-19) 4.9.1
  Copyright (C) 2014 Free Software Foundation, Inc.
  This is free software; see the source for copying conditions.  There is NO
  warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.

  $ gcc -O2 -o c.inline c.c
  # change #if 1 => #if 0
  $ gcc -O2 -o c.loop c.c

  $ time ./c.inline aaaaaaaaaaa
  14

  real	0m0.550s
  user	0m0.548s
  sys	0m0.000s
  $ time ./c.loop aaaaaaaaaaa
  14

  real	0m0.901s
  user	0m0.896s
  sys	0m0.004s

This is my environment only? (gcc (Debian 4.9.1-19) 4.9.1)
-- 
OGAWA Hirofumi <hirofumi@...l.parknet.co.jp>
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@...r.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/

Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ