From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mailman by lists.gnu.org with archive (Exim 4.43) id 1Oe7WJ-0001Q0-AJ for mharc-grub-devel@gnu.org; Wed, 28 Jul 2010 10:22:07 -0400 Received: from [140.186.70.92] (port=59123 helo=eggs.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1Oe7WD-0001Pf-2B for grub-devel@gnu.org; Wed, 28 Jul 2010 10:22:05 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.69) (envelope-from ) id 1Oe7W8-00052W-Cx for grub-devel@gnu.org; Wed, 28 Jul 2010 10:22:00 -0400 Received: from mail-fx0-f41.google.com ([209.85.161.41]:64293) by eggs.gnu.org with esmtp (Exim 4.69) (envelope-from ) id 1Oe7W8-00052L-8P for grub-devel@gnu.org; Wed, 28 Jul 2010 10:21:56 -0400 Received: by fxm20 with SMTP id 20so1389352fxm.0 for ; Wed, 28 Jul 2010 07:21:54 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=domainkey-signature:received:received:message-id:date:from :user-agent:mime-version:to:subject:references:in-reply-to :x-enigmail-version:content-type; bh=L3MjeGB0QPQpcPAaKyTRxlko6x8sXRijfaMCOWZc5PQ=; b=E05TJXUtvRYu0rOrr2ZXyNR9ji0MN5way8oT+zAjJCBTZ8UccjJyZ9ZAP7mLFto0lk ES0+l6YBVtCdpbdccXCfTOo4g9JH5QQHpbh5K39EceccF35APCq2gr0SZgo5XgI/VhNW /hM17YfJJfy71lQMxRCnbtWKkiYmL+9NXPAcA= DomainKey-Signature: a=rsa-sha1; c=nofws; d=gmail.com; s=gamma; h=message-id:date:from:user-agent:mime-version:to:subject:references :in-reply-to:x-enigmail-version:content-type; b=cEq1kqOHIqDloV+VTTFtPh7FUKk2ouw7yJC4fbsGQVwjbV+WSyb9bJuPb3msPeR6iG GDxXg6YDwX5U+2hxbuha+TbHXQYHViEOYcZPnAiW22yPfUCYEZ/A8eCxVzS0GFc8sVEL z2oftUXf1VInDKVfXLdubU2A0x+Q+YABqjbvo= Received: by 10.223.120.82 with SMTP id c18mr10020509far.69.1280326914668; Wed, 28 Jul 2010 07:21:54 -0700 (PDT) Received: from debian.bg45.phnet (vpn-global-165-dhcp.ethz.ch [129.132.211.165]) by mx.google.com with ESMTPS id y2sm2591747fau.12.2010.07.28.07.21.52 (version=TLSv1/SSLv3 cipher=RC4-MD5); Wed, 28 Jul 2010 07:21:52 -0700 (PDT) Message-ID: <4C503CF1.3090706@gmail.com> Date: Wed, 28 Jul 2010 17:21:37 +0300 From: =?UTF-8?B?VmxhZGltaXIgJ8+GLWNvZGVyL3BoY29kZXInIFNlcmJpbmVua28=?= User-Agent: Mozilla/5.0 (X11; U; Linux x86_64; en-US; rv:1.9.1.10) Gecko/20100620 Icedove/3.0.5 MIME-Version: 1.0 To: grub-devel@gnu.org References: <20100623213838.GI21862@riva.ucam.org> <4C24F508.6040501@gmail.com> <20100723111440.GU21862@riva.ucam.org> In-Reply-To: <20100723111440.GU21862@riva.ucam.org> X-Enigmail-Version: 1.0.1 Content-Type: multipart/signed; micalg=pgp-sha512; protocol="application/pgp-signature"; boundary="------------enig71D442E239D66E7516A773C8" X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.6 (newer, 2) Subject: Re: [PATCH] Optimise memset on i386 X-BeenThere: grub-devel@gnu.org X-Mailman-Version: 2.1.5 Precedence: list Reply-To: The development of GNU GRUB List-Id: The development of GNU GRUB List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Wed, 28 Jul 2010 14:22:06 -0000 This is an OpenPGP/MIME signed message (RFC 2440 and 3156) --------------enig71D442E239D66E7516A773C8 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: quoted-printable On 07/23/2010 02:14 PM, Colin Watson wrote: > On Fri, Jun 25, 2010 at 08:27:20PM +0200, Vladimir '=CF=86-coder/phcode= r' Serbinenko wrote: > =20 >>> +void * >>> +grub_memset (void *s, int c, grub_size_t n) >>> +{ >>> + unsigned char *p =3D (unsigned char *) s; >>> + >>> + while (n--) >>> + *p++ =3D (unsigned char) c; >>> + >>> + return s; >>> +} >>> =20 >> Attached is a possible generic implementation. Not even compile-tested= =2E >> Could you test it and compare disasm of this version on i386 and glibc= >> i386 version. Perhaps they are equivalent. If they are for maintainanc= e >> reasons it's better to always use generic one. >> =20 > Thanks for this, and sorry for my delay. > > I haven't compared the disassembly, but once I fixed up your code it > performed within about 10% of the optimised version I posted before, so= > about 640ms original, 160ms with i386-specific memset, and 176ms with > your generic memset. Even though that isn't quite equivalent, I don't > think that 16ms is going to be a major problem, and so I would suggest > going with the generic version. Please check the following. > > 2010-07-23 Vladimir Serbinenko > 2010-07-23 Colin Watson > > * kern/misc.c (grub_memset): Optimise to reduce cache stalls. > > =20 Go ahead. > =3D=3D=3D modified file 'kern/misc.c' > --- kern/misc.c 2010-07-02 17:35:07 +0000 > +++ kern/misc.c 2010-07-23 11:05:32 +0000 > @@ -518,12 +518,39 @@ grub_strndup (const char *s, grub_size_t > } > =20 > void * > -grub_memset (void *s, int c, grub_size_t n) > +grub_memset (void *s, int c, grub_size_t len) > { > - unsigned char *p =3D (unsigned char *) s; > + void *p =3D s; > + grub_uint8_t pattern8 =3D c; > =20 > - while (n--) > - *p++ =3D (unsigned char) c; > + if (len >=3D 3 * sizeof (unsigned long)) > + { > + unsigned long patternl =3D 0; > + grub_size_t i; > + > + for (i =3D 0; i < sizeof (unsigned long); i++) > + patternl |=3D ((unsigned long) pattern8) << (8 * i); > + > + while (len > 0 && (((grub_addr_t) p) & (sizeof (unsigned long) -= 1))) > + { > + *(grub_uint8_t *) p =3D pattern8; > + p =3D (grub_uint8_t *) p + 1; > + len--; > + } > + while (len >=3D sizeof (unsigned long)) > + { > + *(unsigned long *) p =3D patternl; > + p =3D (unsigned long *) p + 1; > + len -=3D sizeof (unsigned long); > + } > + } > + > + while (len > 0) > + { > + *(grub_uint8_t *) p =3D pattern8; > + p =3D (grub_uint8_t *) p + 1; > + len--; > + } > =20 > return s; > } > > =20 --=20 Regards Vladimir '=CF=86-coder/phcoder' Serbinenko --------------enig71D442E239D66E7516A773C8 Content-Type: application/pgp-signature; name="signature.asc" Content-Description: OpenPGP digital signature Content-Disposition: attachment; filename="signature.asc" -----BEGIN PGP SIGNATURE----- Version: GnuPG v1.4.10 (GNU/Linux) Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org/ iF4EAREKAAYFAkxQPP4ACgkQNak7dOguQgmf/gEAjaLqIpOHYngtgTOtd9VZ1Z6M wzL23AwIVHA80iW0XY4A/jL0fHZdGqV2qsBTD6KyZXRK4xM0LCVbJd+th25+bETr =MI/e -----END PGP SIGNATURE----- --------------enig71D442E239D66E7516A773C8--