All of lore.kernel.org
 help / color / mirror / Atom feed
From: Christian Franke <Christian.Franke@t-online.de>
To: The development of GNU GRUB <grub-devel@gnu.org>
Subject: Re: [PATCH] Optimise memset on i386
Date: Fri, 23 Jul 2010 19:34:51 +0200	[thread overview]
Message-ID: <4C49D2BB.4050901@t-online.de> (raw)
In-Reply-To: <AANLkTimsSzu6rMXAHenwjrV_uRJ8+MoHFtxAToJB4Qth@mail.gmail.com>

richardvoigt wrote:
>
> might I suggest:
>
> unsigned long patternl = pattern8;
> patternl |= patternl << 8;
> patternl |= patternl << 16;
> patternl |= patternl << 32;
> patternl |= patternl << 64;
>
> O(lg N) instead of O(N), no loop, no branches, and the compiler should 
> be smart enough to optimize away the last two lines on systems with 
> narrower long.

The latter is unfortunately not the case. At least gcc 4.5.0 prints a 
warning but still produces code.

$ cat <<EOF >f.c
unsigned long f(unsigned long x)
{
   x |= x << 32;
   x |= x << 64;
   return x;
}

$ gcc -O3 -S f.c
x.c: In function ‘f’:
x.c:3: warning: left shift count >= width of type
x.c:4: warning: left shift count >= width of type

$ cat f.s
...
         pushl   %ebp
         movl    $32, %ecx
         movl    %esp, %ebp
         movl    8(%ebp), %eax
         popl    %ebp
         movl    %eax, %edx
         sall    %cl, %edx
         movl    $64, %ecx
         orl     %eax, %edx
         movl    %edx, %eax
         sall    %cl, %eax
         orl     %edx, %eax
         ret


-- 
Regards,
Christian Franke



  reply	other threads:[~2010-07-23 17:35 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 [this message]
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

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=4C49D2BB.4050901@t-online.de \
    --to=christian.franke@t-online.de \
    --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.