public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug inline-asm/43998]  New: inline assembler: can't set clobbering for input register
@ 2010-05-06  6:37 socketpair at gmail dot com
  2010-05-06  7:11 ` [Bug inline-asm/43998] " ubizjak at gmail dot com
                   ` (11 more replies)
  0 siblings, 12 replies; 14+ messages in thread
From: socketpair at gmail dot com @ 2010-05-06  6:37 UTC (permalink / raw)
  To: gcc-bugs

[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #1: Type: text/plain, Size: 1362 bytes --]

mmarkk@mmarkk-desktop:~/src/vmdetect$ gcc --version
gcc (Ubuntu 4.4.1-4ubuntu9) 4.4.1
----------------------------------------------
#include <sys/types.h> 
#include <stdio.h> 
int main (void)
{
  size_t ecx;
  asm ("cpuid": "=c" (ecx): "a" (0x1):"eax","ebx","edx");
  printf ("Suspected %s machine!\n", (ecx >> 31) ? "virtual" : "real");
  return 0;
}

mmarkk@mmarkk-desktop:~/src/vmdetect$ gcc 1main.c 
1main.c: In function ‘main’:
1main.c:7: error: can't find a register in class ‘AREG’ while reloading ‘asm’
1main.c:7: error: ‘asm’ operand has impossible constraints
------------------------------------------------
#include <sys/types.h> 
#include <stdio.h> 
int main (void)
{
  size_t ecx, dontneed;
  asm ("cpuid": "=c" (ecx),"=a"(dontneed): "a" (0x1):"ebx","edx");
  printf ("Suspected %s machine!\n", (ecx >> 31) ? "virtual" : "real");
  return 0;
}
works OK.

How to correctly say compiler about clobbering eax register ?


-- 
           Summary: inline assembler: can't set clobbering for input
                    register
           Product: gcc
           Version: 4.4.1
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: inline-asm
        AssignedTo: unassigned at gcc dot gnu dot org
        ReportedBy: socketpair at gmail dot com


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=43998


^ permalink raw reply	[flat|nested] 14+ messages in thread

* [Bug inline-asm/43998] inline assembler: can't set clobbering for input register
  2010-05-06  6:37 [Bug inline-asm/43998] New: inline assembler: can't set clobbering for input register socketpair at gmail dot com
@ 2010-05-06  7:11 ` ubizjak at gmail dot com
  2010-05-06  8:07 ` jakub at gcc dot gnu dot org
                   ` (10 subsequent siblings)
  11 siblings, 0 replies; 14+ messages in thread
From: ubizjak at gmail dot com @ 2010-05-06  7:11 UTC (permalink / raw)
  To: gcc-bugs



------- Comment #1 from ubizjak at gmail dot com  2010-05-06 07:11 -------
You can use cpuid.h.

BTW: Please ask questions about using gcc in gcc-help@ or elsewhere.

Not a bug.


-- 

ubizjak at gmail dot com changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|UNCONFIRMED                 |RESOLVED
         Resolution|                            |INVALID


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=43998


^ permalink raw reply	[flat|nested] 14+ messages in thread

* [Bug inline-asm/43998] inline assembler: can't set clobbering for input register
  2010-05-06  6:37 [Bug inline-asm/43998] New: inline assembler: can't set clobbering for input register socketpair at gmail dot com
  2010-05-06  7:11 ` [Bug inline-asm/43998] " ubizjak at gmail dot com
@ 2010-05-06  8:07 ` jakub at gcc dot gnu dot org
  2010-05-06 11:00 ` socketpair at gmail dot com
                   ` (9 subsequent siblings)
  11 siblings, 0 replies; 14+ messages in thread
From: jakub at gcc dot gnu dot org @ 2010-05-06  8:07 UTC (permalink / raw)
  To: gcc-bugs



------- Comment #2 from jakub at gcc dot gnu dot org  2010-05-06 08:06 -------
To answer the exact question, yes, using a dummy variable as output (perhaps
with "1" instead of "a" for the matching input) is the right fix.


-- 


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=43998


^ permalink raw reply	[flat|nested] 14+ messages in thread

* [Bug inline-asm/43998] inline assembler: can't set clobbering for input register
  2010-05-06  6:37 [Bug inline-asm/43998] New: inline assembler: can't set clobbering for input register socketpair at gmail dot com
  2010-05-06  7:11 ` [Bug inline-asm/43998] " ubizjak at gmail dot com
  2010-05-06  8:07 ` jakub at gcc dot gnu dot org
@ 2010-05-06 11:00 ` socketpair at gmail dot com
  2010-05-06 11:31 ` rguenth at gcc dot gnu dot org
                   ` (8 subsequent siblings)
  11 siblings, 0 replies; 14+ messages in thread
From: socketpair at gmail dot com @ 2010-05-06 11:00 UTC (permalink / raw)
  To: gcc-bugs



------- Comment #3 from socketpair at gmail dot com  2010-05-06 11:00 -------
Thanks alot, but I think it is bug in gcc inline assembler. I think I wrote
correct asm() line.

I know about cpuid.h
I listed this instruction just as example.


-- 

socketpair at gmail dot com changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|RESOLVED                    |UNCONFIRMED
         Resolution|INVALID                     |


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=43998


^ permalink raw reply	[flat|nested] 14+ messages in thread

* [Bug inline-asm/43998] inline assembler: can't set clobbering for input register
  2010-05-06  6:37 [Bug inline-asm/43998] New: inline assembler: can't set clobbering for input register socketpair at gmail dot com
                   ` (2 preceding siblings ...)
  2010-05-06 11:00 ` socketpair at gmail dot com
@ 2010-05-06 11:31 ` rguenth at gcc dot gnu dot org
  2010-05-06 11:41 ` socketpair at gmail dot com
                   ` (7 subsequent siblings)
  11 siblings, 0 replies; 14+ messages in thread
From: rguenth at gcc dot gnu dot org @ 2010-05-06 11:31 UTC (permalink / raw)
  To: gcc-bugs



------- Comment #4 from rguenth at gcc dot gnu dot org  2010-05-06 11:31 -------
You can't at the same time force something into aregs and clobber them.


-- 

rguenth at gcc dot gnu dot org changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|UNCONFIRMED                 |RESOLVED
         Resolution|                            |INVALID


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=43998


^ permalink raw reply	[flat|nested] 14+ messages in thread

* [Bug inline-asm/43998] inline assembler: can't set clobbering for input register
  2010-05-06  6:37 [Bug inline-asm/43998] New: inline assembler: can't set clobbering for input register socketpair at gmail dot com
                   ` (3 preceding siblings ...)
  2010-05-06 11:31 ` rguenth at gcc dot gnu dot org
@ 2010-05-06 11:41 ` socketpair at gmail dot com
  2010-05-06 13:09 ` hjl dot tools at gmail dot com
                   ` (6 subsequent siblings)
  11 siblings, 0 replies; 14+ messages in thread
From: socketpair at gmail dot com @ 2010-05-06 11:41 UTC (permalink / raw)
  To: gcc-bugs



------- Comment #5 from socketpair at gmail dot com  2010-05-06 11:41 -------
Well, how to say that to compiler:

This instruction receives input in register eax, but after executing it, eax
value will be corrupted. I don't need this new value, but compiler  should not
think that eax is preserved.


-- 


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=43998


^ permalink raw reply	[flat|nested] 14+ messages in thread

* [Bug inline-asm/43998] inline assembler: can't set clobbering for input register
  2010-05-06  6:37 [Bug inline-asm/43998] New: inline assembler: can't set clobbering for input register socketpair at gmail dot com
                   ` (4 preceding siblings ...)
  2010-05-06 11:41 ` socketpair at gmail dot com
@ 2010-05-06 13:09 ` hjl dot tools at gmail dot com
  2010-05-06 13:42 ` socketpair at gmail dot com
                   ` (5 subsequent siblings)
  11 siblings, 0 replies; 14+ messages in thread
From: hjl dot tools at gmail dot com @ 2010-05-06 13:09 UTC (permalink / raw)
  To: gcc-bugs



------- Comment #6 from hjl dot tools at gmail dot com  2010-05-06 13:09 -------
(In reply to comment #5)
> Well, how to say that to compiler:
> 
> This instruction receives input in register eax, but after executing it, eax
> value will be corrupted. I don't need this new value, but compiler  should not
> think that eax is preserved.
> 

Just make eax both input and output.


-- 


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=43998


^ permalink raw reply	[flat|nested] 14+ messages in thread

* [Bug inline-asm/43998] inline assembler: can't set clobbering for input register
  2010-05-06  6:37 [Bug inline-asm/43998] New: inline assembler: can't set clobbering for input register socketpair at gmail dot com
                   ` (5 preceding siblings ...)
  2010-05-06 13:09 ` hjl dot tools at gmail dot com
@ 2010-05-06 13:42 ` socketpair at gmail dot com
  2010-05-06 13:56 ` rguenth at gcc dot gnu dot org
                   ` (4 subsequent siblings)
  11 siblings, 0 replies; 14+ messages in thread
From: socketpair at gmail dot com @ 2010-05-06 13:42 UTC (permalink / raw)
  To: gcc-bugs



------- Comment #7 from socketpair at gmail dot com  2010-05-06 13:42 -------
> Just make eax both input and output.
it's not optimal. gcc will try to preserve new eax value. So it will not use
eax register in next instructions. If eax is really need, it will save it in
esi, edi or so on - it's redundant.


-- 

socketpair at gmail dot com changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|RESOLVED                    |UNCONFIRMED
         Resolution|INVALID                     |


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=43998


^ permalink raw reply	[flat|nested] 14+ messages in thread

* [Bug inline-asm/43998] inline assembler: can't set clobbering for input register
  2010-05-06  6:37 [Bug inline-asm/43998] New: inline assembler: can't set clobbering for input register socketpair at gmail dot com
                   ` (6 preceding siblings ...)
  2010-05-06 13:42 ` socketpair at gmail dot com
@ 2010-05-06 13:56 ` rguenth at gcc dot gnu dot org
  2010-05-06 15:04 ` socketpair at gmail dot com
                   ` (3 subsequent siblings)
  11 siblings, 0 replies; 14+ messages in thread
From: rguenth at gcc dot gnu dot org @ 2010-05-06 13:56 UTC (permalink / raw)
  To: gcc-bugs



------- Comment #8 from rguenth at gcc dot gnu dot org  2010-05-06 13:55 -------
(In reply to comment #7)
> > Just make eax both input and output.
> it's not optimal. gcc will try to preserve new eax value. So it will not use
> eax register in next instructions. If eax is really need, it will save it in
> esi, edi or so on - it's redundant.

Not if you make the output unused by not using it.


-- 

rguenth at gcc dot gnu dot org changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|UNCONFIRMED                 |RESOLVED
         Resolution|                            |INVALID


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=43998


^ permalink raw reply	[flat|nested] 14+ messages in thread

* [Bug inline-asm/43998] inline assembler: can't set clobbering for input register
  2010-05-06  6:37 [Bug inline-asm/43998] New: inline assembler: can't set clobbering for input register socketpair at gmail dot com
                   ` (7 preceding siblings ...)
  2010-05-06 13:56 ` rguenth at gcc dot gnu dot org
@ 2010-05-06 15:04 ` socketpair at gmail dot com
  2010-05-14  2:45 ` pinskia at gcc dot gnu dot org
                   ` (2 subsequent siblings)
  11 siblings, 0 replies; 14+ messages in thread
From: socketpair at gmail dot com @ 2010-05-06 15:04 UTC (permalink / raw)
  To: gcc-bugs



------- Comment #9 from socketpair at gmail dot com  2010-05-06 15:03 -------
> Not if you make the output unused by not using it.
I do not understand why gcc distinguish between 'specifying register as output'
and 'specifying as clobbering'.

I always considered, that 'clobber list' specify list of items which may be
changed *AFTER* the end of instruction(s). So I do not understand why adding
eax in clobber list will break compilation.

I found some posts where people create size_t dummy; and specify this variable
as output. insted of just specifying this register in clobber-list.

Why not to fix bug I have reported? Maybe convert to feature?


-- 

socketpair at gmail dot com changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|RESOLVED                    |UNCONFIRMED
         Resolution|INVALID                     |


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=43998


^ permalink raw reply	[flat|nested] 14+ messages in thread

* [Bug inline-asm/43998] inline assembler: can't set clobbering for input register
  2010-05-06  6:37 [Bug inline-asm/43998] New: inline assembler: can't set clobbering for input register socketpair at gmail dot com
                   ` (8 preceding siblings ...)
  2010-05-06 15:04 ` socketpair at gmail dot com
@ 2010-05-14  2:45 ` pinskia at gcc dot gnu dot org
  2010-05-14  6:31 ` socketpair at gmail dot com
  2010-05-14  7:11 ` ebotcazou at gcc dot gnu dot org
  11 siblings, 0 replies; 14+ messages in thread
From: pinskia at gcc dot gnu dot org @ 2010-05-14  2:45 UTC (permalink / raw)
  To: gcc-bugs



------- Comment #10 from pinskia at gcc dot gnu dot org  2010-05-14 02:44 -------
Because the way the constraints are implemented inside GCC, an input constraint
cannot overlap with a clobber.  As input constraint can stay in the same
register across the inline-asm so it does not make sense to have it as a
clobber.  Use an output register that says it clobbers that register.


-- 

pinskia at gcc dot gnu dot org changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|UNCONFIRMED                 |RESOLVED
         Resolution|                            |INVALID


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=43998


^ permalink raw reply	[flat|nested] 14+ messages in thread

* [Bug inline-asm/43998] inline assembler: can't set clobbering for input register
  2010-05-06  6:37 [Bug inline-asm/43998] New: inline assembler: can't set clobbering for input register socketpair at gmail dot com
                   ` (9 preceding siblings ...)
  2010-05-14  2:45 ` pinskia at gcc dot gnu dot org
@ 2010-05-14  6:31 ` socketpair at gmail dot com
  2010-05-14  7:11 ` ebotcazou at gcc dot gnu dot org
  11 siblings, 0 replies; 14+ messages in thread
From: socketpair at gmail dot com @ 2010-05-14  6:31 UTC (permalink / raw)
  To: gcc-bugs



------- Comment #11 from socketpair at gmail dot com  2010-05-14 06:31 -------
Suppose this:

volatile int x;
asm("something"::"a" (1))
x=1;

the compiler may think that "something" do not modify eax. So next assignment
may use eax ( mov eax, x ). So, "it does not make sense to have it as a
clobber" is not correct. does not it ?
-----------------
And the second, "Because the way the constraints are implemented inside GCC, an
input constraint cannot overlap with a clobber." - It definitely the bug.


-- 

socketpair at gmail dot com changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|RESOLVED                    |UNCONFIRMED
         Resolution|INVALID                     |


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=43998


^ permalink raw reply	[flat|nested] 14+ messages in thread

* [Bug inline-asm/43998] inline assembler: can't set clobbering for input register
  2010-05-06  6:37 [Bug inline-asm/43998] New: inline assembler: can't set clobbering for input register socketpair at gmail dot com
                   ` (10 preceding siblings ...)
  2010-05-14  6:31 ` socketpair at gmail dot com
@ 2010-05-14  7:11 ` ebotcazou at gcc dot gnu dot org
  11 siblings, 0 replies; 14+ messages in thread
From: ebotcazou at gcc dot gnu dot org @ 2010-05-14  7:11 UTC (permalink / raw)
  To: gcc-bugs



------- Comment #12 from ebotcazou at gcc dot gnu dot org  2010-05-14 07:10 -------
> the compiler may think that "something" do not modify eax. So next assignment
> may use eax ( mov eax, x ). So, "it does not make sense to have it as a
> clobber" is not correct. does not it ?

Andrew was saying that it doesn't make sense to consider input operands as
clobbered by an inline asm, generically.

> And the second, "Because the way the constraints are implemented inside GCC,
> an input constraint cannot overlap with a clobber." - It definitely the bug.

No, it isn't, it's clearly stated in the manual: "You may not write a clobber
description in a way that overlaps with an input or output operand."


-- 

ebotcazou at gcc dot gnu dot org changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |ebotcazou at gcc dot gnu dot
                   |                            |org
             Status|UNCONFIRMED                 |RESOLVED
         Resolution|                            |INVALID


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=43998


^ permalink raw reply	[flat|nested] 14+ messages in thread

* [Bug inline-asm/43998] inline assembler: can't set clobbering for input register
       [not found] <bug-43998-4@http.gcc.gnu.org/bugzilla/>
@ 2013-04-08  8:04 ` ilya.lesokhin at gmail dot com
  0 siblings, 0 replies; 14+ messages in thread
From: ilya.lesokhin at gmail dot com @ 2013-04-08  8:04 UTC (permalink / raw)
  To: gcc-bugs


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=43998

Ilya Lesokhin <ilya.lesokhin at gmail dot com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |ilya.lesokhin at gmail dot
                   |                            |com

--- Comment #13 from Ilya Lesokhin <ilya.lesokhin at gmail dot com> 2013-04-08 08:04:28 UTC ---
Andrew Pinski said:
>  Use an output register that says it clobbers that register.

This indeed works for normal inline assembler, but it doesn't work for asm goto
which currently doesn't have outputs.

maybe the Bug should be reopened for newer versions of GCC?


^ permalink raw reply	[flat|nested] 14+ messages in thread

end of thread, other threads:[~2013-04-08  8:04 UTC | newest]

Thread overview: 14+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2010-05-06  6:37 [Bug inline-asm/43998] New: inline assembler: can't set clobbering for input register socketpair at gmail dot com
2010-05-06  7:11 ` [Bug inline-asm/43998] " ubizjak at gmail dot com
2010-05-06  8:07 ` jakub at gcc dot gnu dot org
2010-05-06 11:00 ` socketpair at gmail dot com
2010-05-06 11:31 ` rguenth at gcc dot gnu dot org
2010-05-06 11:41 ` socketpair at gmail dot com
2010-05-06 13:09 ` hjl dot tools at gmail dot com
2010-05-06 13:42 ` socketpair at gmail dot com
2010-05-06 13:56 ` rguenth at gcc dot gnu dot org
2010-05-06 15:04 ` socketpair at gmail dot com
2010-05-14  2:45 ` pinskia at gcc dot gnu dot org
2010-05-14  6:31 ` socketpair at gmail dot com
2010-05-14  7:11 ` ebotcazou at gcc dot gnu dot org
     [not found] <bug-43998-4@http.gcc.gnu.org/bugzilla/>
2013-04-08  8:04 ` ilya.lesokhin at gmail dot com

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).