From: "Vladimir 'φ-coder/phcoder' Serbinenko" <phcoder@gmail.com>
To: grub-devel@gnu.org
Subject: Re: [PATCH] Optimise memset on i386
Date: Wed, 28 Jul 2010 17:21:37 +0300 [thread overview]
Message-ID: <4C503CF1.3090706@gmail.com> (raw)
In-Reply-To: <20100723111440.GU21862@riva.ucam.org>
[-- Attachment #1: Type: text/plain, Size: 2655 bytes --]
On 07/23/2010 02:14 PM, Colin Watson wrote:
> On Fri, Jun 25, 2010 at 08:27:20PM +0200, Vladimir 'φ-coder/phcoder' Serbinenko wrote:
>
>>> +void *
>>> +grub_memset (void *s, int c, grub_size_t n)
>>> +{
>>> + unsigned char *p = (unsigned char *) s;
>>> +
>>> + while (n--)
>>> + *p++ = (unsigned char) c;
>>> +
>>> + return s;
>>> +}
>>>
>> Attached is a possible generic implementation. Not even compile-tested.
>> Could you test it and compare disasm of this version on i386 and glibc
>> i386 version. Perhaps they are equivalent. If they are for maintainance
>> reasons it's better to always use generic one.
>>
> 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 <phcoder@gmail.com>
> 2010-07-23 Colin Watson <cjwatson@ubuntu.com>
>
> * kern/misc.c (grub_memset): Optimise to reduce cache stalls.
>
>
Go ahead.
> === 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
> }
>
> void *
> -grub_memset (void *s, int c, grub_size_t n)
> +grub_memset (void *s, int c, grub_size_t len)
> {
> - unsigned char *p = (unsigned char *) s;
> + void *p = s;
> + grub_uint8_t pattern8 = c;
>
> - while (n--)
> - *p++ = (unsigned char) c;
> + if (len >= 3 * sizeof (unsigned long))
> + {
> + unsigned long patternl = 0;
> + grub_size_t i;
> +
> + for (i = 0; i < sizeof (unsigned long); i++)
> + patternl |= ((unsigned long) pattern8) << (8 * i);
> +
> + while (len > 0 && (((grub_addr_t) p) & (sizeof (unsigned long) - 1)))
> + {
> + *(grub_uint8_t *) p = pattern8;
> + p = (grub_uint8_t *) p + 1;
> + len--;
> + }
> + while (len >= sizeof (unsigned long))
> + {
> + *(unsigned long *) p = patternl;
> + p = (unsigned long *) p + 1;
> + len -= sizeof (unsigned long);
> + }
> + }
> +
> + while (len > 0)
> + {
> + *(grub_uint8_t *) p = pattern8;
> + p = (grub_uint8_t *) p + 1;
> + len--;
> + }
>
> return s;
> }
>
>
--
Regards
Vladimir 'φ-coder/phcoder' Serbinenko
[-- Attachment #2: OpenPGP digital signature --]
[-- Type: application/pgp-signature, Size: 294 bytes --]
prev parent reply other threads:[~2010-07-28 14:22 UTC|newest]
Thread overview: 10+ messages / expand[flat|nested] mbox.gz Atom feed top
2010-06-23 21:38 [PATCH] Optimise memset on i386 Colin Watson
2010-06-25 18:04 ` Vladimir 'φ-coder/phcoder' Serbinenko
2010-06-25 18:27 ` Vladimir 'φ-coder/phcoder' Serbinenko
2010-07-23 11:14 ` Colin Watson
2010-07-23 15:56 ` richardvoigt
2010-07-23 17:34 ` Christian Franke
2010-07-23 19:48 ` richardvoigt
2010-07-23 20:09 ` richardvoigt
2010-07-24 22:40 ` Colin Watson
2010-07-28 14:21 ` Vladimir 'φ-coder/phcoder' Serbinenko [this message]
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=4C503CF1.3090706@gmail.com \
--to=phcoder@gmail.com \
--cc=grub-devel@gnu.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.