public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c/39620] New: wrong assumption of clobbered registers of inline assembly
@ 2009-04-03 7:55 codemasterhs at yahoo dot de
2009-04-03 8:11 ` [Bug c/39620] " jakub at gcc dot gnu dot org
2009-04-03 8:30 ` codemasterhs at yahoo dot de
0 siblings, 2 replies; 3+ messages in thread
From: codemasterhs at yahoo dot de @ 2009-04-03 7:55 UTC (permalink / raw)
To: gcc-bugs
[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #1: Type: text/plain, Size: 1041 bytes --]
I have the following code:
static inline void zeromem4b(uint32t *dst, uint32t count) {
asm volatile("xor %%eax,%%eax\n\trep stosl"
:
:"c"(count),"D"(dst)
:"%eax", "cc", "memory");
}
If I call it and after it want to, e.g. print out the value of *dst it gives me
the value which it has after running the function. That means that gcc thinks
that "%edi" hasn´t changed, but it did and I can not put it into the clobbered
list, because this gives me an error.
I compile with "-O2 -Wall -fno-builtin -march=i586".
--
Summary: wrong assumption of clobbered registers of inline
assembly
Product: gcc
Version: 4.3.3
Status: UNCONFIRMED
Severity: normal
Priority: P3
Component: c
AssignedTo: unassigned at gcc dot gnu dot org
ReportedBy: codemasterhs at yahoo dot de
GCC host triplet: cygwin
GCC target triplet: i586 elf
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=39620
^ permalink raw reply [flat|nested] 3+ messages in thread
* [Bug c/39620] wrong assumption of clobbered registers of inline assembly
2009-04-03 7:55 [Bug c/39620] New: wrong assumption of clobbered registers of inline assembly codemasterhs at yahoo dot de
@ 2009-04-03 8:11 ` jakub at gcc dot gnu dot org
2009-04-03 8:30 ` codemasterhs at yahoo dot de
1 sibling, 0 replies; 3+ messages in thread
From: jakub at gcc dot gnu dot org @ 2009-04-03 8:11 UTC (permalink / raw)
To: gcc-bugs
------- Comment #1 from jakub at gcc dot gnu dot org 2009-04-03 08:11 -------
User error, if you don't tell gcc that %edi is clobbered, obviously it can
assume it hasn't.
As rep stosl modifies both %ecx and %edi, you can write e.g.:
int tmp1, tmp2;
asm volatile("xor %%eax,%%eax\n\trep stosl" : "=c" (tmp1), "=D" (tmp2) : "0"
(count), "1" (dst) : "%eax", "cc", "memory");
or:
asm volatile("xor %%eax,%%eax\n\trep stosl" : "+c" (count), "+D" (dst) : :
"%eax", "cc", "memory");
if you don't mind that the count and dst variables will change.
Also note that __builtin_memset (dst, '\0', count); will in most cases
result in more optimal code for your CPU, hardcoding these in assembly is
usually a bad idea.
--
jakub at gcc dot gnu dot org changed:
What |Removed |Added
----------------------------------------------------------------------------
Status|UNCONFIRMED |RESOLVED
Resolution| |INVALID
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=39620
^ permalink raw reply [flat|nested] 3+ messages in thread
* [Bug c/39620] wrong assumption of clobbered registers of inline assembly
2009-04-03 7:55 [Bug c/39620] New: wrong assumption of clobbered registers of inline assembly codemasterhs at yahoo dot de
2009-04-03 8:11 ` [Bug c/39620] " jakub at gcc dot gnu dot org
@ 2009-04-03 8:30 ` codemasterhs at yahoo dot de
1 sibling, 0 replies; 3+ messages in thread
From: codemasterhs at yahoo dot de @ 2009-04-03 8:30 UTC (permalink / raw)
To: gcc-bugs
[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #1: Type: text/plain, Size: 1472 bytes --]
------- Comment #2 from codemasterhs at yahoo dot de 2009-04-03 08:30 -------
Subject: Re: wrong assumption of clobbered registers of inline
assembly
The code is for my loader/os and so I can´t and do not want to use the
builtin functions.
Your 1st example works, but I find it a bit strange that I have to write
such code only to tell gcc, that 2 registers are clobbered! Your 2nd
example doesn´t work, because of the plus, this gives me an error.
I think the better way would be either gcc assumes that edi and ecx are
clobbered (which isn´t so) or I can specify that in the clobbered list
(which is not possible)!
jakub at gcc dot gnu dot org wrote:
> ------- Comment #1 from jakub at gcc dot gnu dot org 2009-04-03 08:11 -------
> User error, if you don't tell gcc that %edi is clobbered, obviously it can
> assume it hasn't.
> As rep stosl modifies both %ecx and %edi, you can write e.g.:
> int tmp1, tmp2;
> asm volatile("xor %%eax,%%eax\n\trep stosl" : "=c" (tmp1), "=D" (tmp2) : "0"
> (count), "1" (dst) : "%eax", "cc", "memory");
> or:
> asm volatile("xor %%eax,%%eax\n\trep stosl" : "+c" (count), "+D" (dst) : :
> "%eax", "cc", "memory");
> if you don't mind that the count and dst variables will change.
> Also note that __builtin_memset (dst, '\0', count); will in most cases
> result in more optimal code for your CPU, hardcoding these in assembly is
> usually a bad idea.
>
>
>
--
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=39620
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2009-04-03 8:30 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2009-04-03 7:55 [Bug c/39620] New: wrong assumption of clobbered registers of inline assembly codemasterhs at yahoo dot de
2009-04-03 8:11 ` [Bug c/39620] " jakub at gcc dot gnu dot org
2009-04-03 8:30 ` codemasterhs at yahoo dot de
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).