From: Eric Dumazet <dada1@cosmosbay.com>
To: Stephen Hemminger <shemminger@linux-foundation.org>
Cc: Andi Kleen <ak@suse.de>,
discuss@x86-64.org, linux-kernel@vger.kernel.org
Subject: Re: [PATCH] x86-64: memset optimization
Date: Sat, 18 Aug 2007 09:17:58 +0200 [thread overview]
Message-ID: <46C69D26.3000200@cosmosbay.com> (raw)
In-Reply-To: <20070817163446.3e63f208@freepuppy.rosehill.hemminger.net>
Stephen Hemminger a écrit :
> Optimize uses of memset with small constant offsets.
> This will generate smaller code, and avoid the slow rep/string instructions.
> Code copied from i386 with a little cleanup.
>
You obviously didnt test it, did you ?
How can you be sure this is going to speedup things then ?
> Signed-off-by: Stephen Hemminger <shemminger@linux-foundation.org>
>
> --- a/include/asm-x86_64/string.h 2007-08-17 15:14:32.000000000 -0700
> +++ b/include/asm-x86_64/string.h 2007-08-17 15:36:30.000000000 -0700
> @@ -42,9 +42,51 @@ extern void *__memcpy(void *to, const vo
> __ret = __builtin_memcpy((dst),(src),__len); \
> __ret; })
> #endif
> -
> #define __HAVE_ARCH_MEMSET
> -void *memset(void *s, int c, size_t n);
> +void *__memset(void *s, int c, size_t n);
> +
> +/* Optimize for cases of trivial memset's
> + * Compiler should optimize away all but the case used.
> + */
> +static __always_inline void *
> +__constant_c_and_count_memset(void *s, int c, size_t count)
> +{
> + unsigned long pattern = 0x01010101UL * (unsigned char) c;
Main difference between x86_64 and i386 is sizeof(long) being 8 instead of 4
Why not let gcc do its job about memset() ?
On x86_64 at least, modern gcc are smart enough.
> +
> + switch (count) {
> + case 0:
> + return s;
> + case 1:
> + *(unsigned char *)s = pattern;
> + return s;
> + case 2:
> + *(unsigned short *)s = pattern;
> + return s;
> + case 3:
> + *(unsigned short *)s = pattern;
> + *(2+(unsigned char *)s) = pattern;
> + return s;
> + case 4:
> + *(unsigned long *)s = pattern;
> + return s;
> + case 6:
> + *(unsigned long *)s = pattern;
> + *(2+(unsigned short *)s) = pattern;
> + return s;
> + case 8:
> + *(unsigned long *)s = pattern;
> + *(1+(unsigned long *)s) = pattern;
> + return s;
> + default:
> + return __memset(s, c, count);
> + }
> +}
> +#define memset(s, c, count) \
> + (__builtin_constant_p(c) \
> + ? __constant_c_and_count_memset((s),(c),(count)) \
> + : __memset((s),(c),(count)))
> +
> +
>
> #define __HAVE_ARCH_MEMMOVE
> void * memmove(void * dest,const void *src,size_t count);
> --- a/arch/x86_64/kernel/x8664_ksyms.c 2007-08-17 15:14:32.000000000 -0700
> +++ b/arch/x86_64/kernel/x8664_ksyms.c 2007-08-17 15:44:58.000000000 -0700
> @@ -48,10 +48,12 @@ EXPORT_SYMBOL(__read_lock_failed);
> #undef memmove
>
> extern void * memset(void *,int,__kernel_size_t);
> +extern void * __memset(void *,int,__kernel_size_t);
> extern void * memcpy(void *,const void *,__kernel_size_t);
> extern void * __memcpy(void *,const void *,__kernel_size_t);
>
> EXPORT_SYMBOL(memset);
> +EXPORT_SYMBOL(__memset);
> EXPORT_SYMBOL(memcpy);
> EXPORT_SYMBOL(__memcpy);
>
next prev parent reply other threads:[~2007-08-18 7:18 UTC|newest]
Thread overview: 13+ messages / expand[flat|nested] mbox.gz Atom feed top
2007-08-17 23:34 [PATCH] x86-64: memset optimization Stephen Hemminger
2007-08-18 7:17 ` Eric Dumazet [this message]
2007-08-18 9:46 ` Andi Kleen
2007-08-18 14:56 ` Stephen Hemminger
2007-08-18 18:55 ` Andi Kleen
2007-08-19 5:04 ` Stephen Hemminger
2007-08-19 18:24 ` [discuss] " Andi Kleen
2007-08-20 15:52 ` Stephen Hemminger
2007-08-20 15:51 ` Arjan van de Ven
2007-08-20 17:03 ` Roland Dreier
2007-08-20 18:16 ` Andi Kleen
2007-08-20 18:56 ` Jan Hubicka
2007-08-21 10:16 ` Denys Vlasenko
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=46C69D26.3000200@cosmosbay.com \
--to=dada1@cosmosbay.com \
--cc=ak@suse.de \
--cc=discuss@x86-64.org \
--cc=linux-kernel@vger.kernel.org \
--cc=shemminger@linux-foundation.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.