mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Andreas Kies <andikies@t-online.de>
To: linux-kernel@vger.kernel.org
Cc: Paolo Ornati <ornati@fastwebnet.it>
Subject: Re: A Bug in gcc or asm/string.h ?
Date: Tue, 28 Jun 2005 01:53:04 +0200	[thread overview]
Message-ID: <200506280153.04620.andikies@t-online.de> (raw)
In-Reply-To: <20050627214315.4b8850f5@localhost>

On Monday 27 June 2005 21:43, Paolo Ornati wrote:
> PS: I've readded LKML to CC, since I think that this is a problem with the
> ASM template

Yes, you are right, it is not a compiler bug.
My apologies to the GCC team, in case anyone has read it.

[...]

> A little better workaround would be to add "memory" to clobbered registers
> in the asm template:
>
> static inline int strcmp(const char * cs,const char * ct)
> {
> int d0, d1;
> register int __res;
> __asm__ __volatile__(
>         "1:\tlodsb\n\t"
>         "scasb\n\t"
>         "jne 2f\n\t"
>         "testb %%al,%%al\n\t"
>         "jne 1b\n\t"
>         "xorl %%eax,%%eax\n\t"
>         "jmp 3f\n"
>         "2:\tsbbl %%eax,%%eax\n\t"
>         "orb $1,%%al\n"
>         "3:"
>
>         :"=a" (__res), "=&S" (d0), "=&D" (d1)
>         :
>                      :"1" (cs),"2" (ct)
>                      : "memory"); // <--- workaround
>
> return __res;
> }
>
>
> In this way GCC puts everything is cached in register back to memory when
> you call strcmp()... but you can argue that this isn't optimal.

Indeed the compiler has to assume that any memory location has changed.

> I don't know if there is a better way... basically you need to tell GCC to
> NOT cache these values.

There is one, it says that cs and ct address structures with 4 gigabyte size.
This is anyway not 64 bit clean.

static inline int strcmp(const char * cs,const char * ct)
{
        int d0, d1;
        register int __res;
        __asm__ __volatile__(
                        "1:\tlodsb\n\t"
                        "scasb\n\t"
                        "jne 2f\n\t"
                        "testb %%al,%%al\n\t"
                        "jne 1b\n\t"
                        "xorl %%eax,%%eax\n\t"
                        "jmp 3f\n"
                        "2:\tsbbl %%eax,%%eax\n\t"
                        "orb $1,%%al\n"
                        "3:"
                        :"=a" (__res), "=&S" (d0), "=&D" (d1)
                        :"1" (cs),"2" (ct),
                        "m" ( *(struct { char __x[0xfffffff]; } *)cs),
                        "m" ( *(struct { char __x[0xfffffff]; } *)ct));
        return __res;
}


Now, how do i formally submit this as a bug report ?

Andreas.

  reply	other threads:[~2005-06-27 23:53 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2005-06-26 23:05 Andreas Kies
2005-06-27 14:04 ` Paolo Ornati
     [not found]   ` <200506272059.20477.andikies@t-online.de>
2005-06-27 19:43     ` Paolo Ornati
2005-06-27 23:53       ` Andreas Kies [this message]
2005-06-28  7:39         ` Paolo Ornati
2005-06-27 20:21 Nick Warne

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=200506280153.04620.andikies@t-online.de \
    --to=andikies@t-online.de \
    --cc=linux-kernel@vger.kernel.org \
    --cc=ornati@fastwebnet.it \
    /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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®