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

PS: I've readded LKML to CC, since I think that this is a problem with the
ASM template


On Mon, 27 Jun 2005 20:59:20 +0200
Andreas Kies <andikies@t-online.de> wrote:

> Them it works, but that's not a solution at all. "volatile" destroys more
> or  less all optimizations.

Yes... I know, it was just to see what was the problem.


The problem is that GCC is caching in registers the value of "ptr[0]" and/or
"ptr[1]" and/or "ptr[2]".

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.


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

I think that nobody hits this bug because the typical usage is different...
something like this:

	...
	char *str = "Hello!";		// or even char str[] = "Hello!";
	...
	strcmp (str, other_str);
	...

In this way "Hello!" _IS_ allocated in memory and "str" points to it.... GCC
optimizations can't hurt here (I hope ;).


CONCLUSION: I think that it should be fixed... but adding "memory" doesn't
seems The Right Thing to do.

--
	Paolo Ornati
	Linux 2.6.12.1 on x86_64

  parent reply	other threads:[~2005-06-27 19:46 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2005-06-26 23:05 A Bug in gcc or asm/string.h ? Andreas Kies
2005-06-27 14:04 ` Paolo Ornati
     [not found]   ` <200506272059.20477.andikies@t-online.de>
2005-06-27 19:43     ` Paolo Ornati [this message]
2005-06-27 23:53       ` Andreas Kies
2005-06-28  7:39         ` Paolo Ornati
  -- strict thread matches above, loose matches on Subject: below --
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=20050627214315.4b8850f5@localhost \
    --to=ornati@fastwebnet.it \
    --cc=andikies@t-online.de \
    --cc=linux-kernel@vger.kernel.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.