www.delorie.com/archives/browse.cgi   search  
Mail Archives: djgpp/2000/04/13/10:55:46

From: buers AT gmx DOT de (Dieter Buerssner)
Newsgroups: comp.os.msdos.djgpp
Subject: Re: inefficiency of GCC output code & -O problem
Date: 13 Apr 2000 14:14:21 GMT
Lines: 63
Message-ID: <8d4rse.3vvrn3d.0@buerssner-17104.user.cis.dfn.de>
References: <200004121649 DOT SAA12655 AT acp3bf DOT physik DOT rwth-aachen DOT de> <38F4C0D9 DOT C73A8E0A AT mtu-net DOT ru>
NNTP-Posting-Host: pec-142-24.tnt9.s2.uunet.de (149.225.142.24)
Mime-Version: 1.0
X-Trace: fu-berlin.de 955635261 7477284 149.225.142.24 (16 [17104])
X-Posting-Agent: Hamster/1.3.13.0
User-Agent: Xnews/03.02.04
To: djgpp AT delorie DOT com
DJ-Gateway: from newsgroup comp.os.msdos.djgpp
Reply-To: djgpp AT delorie DOT com

Alexei A. Frounze wrote:

>Better try it under 2.95.2. You'll encounter the same thingy.
>AND THE CODE IS DEFINETELY NOT BUGGY!!! the program compiles and works
>as it should. Don't you think if program works normally, source is okay
>too? Or you think EXE is no made out of the source at all???

Why are you shouting. You'd do better, trying to understand
the answers. Hans-Bernhard tried to be helpful, and your code
is buggy. That it can compile to and executable and work as
expected, is no proof at all.

>> Obviously, the assembler doesn't consider (-192(%ebp)) to be a correct
>> address operand for fstcw. Changing the code to

And the assembler is obviously correct to show an error.
 
>>         fstcw %0

IHMO, this alone won't work though.

>"(address)" means reference to RAM in AT&T syntax, so I always keep
>these parentheses. IMO GCC doesn't convert inline ASM to the ASM
>recognized by AS. 

Gcc will do fine, with correct inline code. Also your use of
references throughout your code will make many code snippets
less efficient, than the straightforward C implementation.

>Btw, the following program compiles both with -O2 and w/o -O at all:
>----------8<----------
>#include <stdlib.h>
>#include <stdio.h>
>#include <conio.h>
>
>int main() {
>  int a=1, b=2, c=3, d;
>
>  clrscr();
>  
>  __asm__ __volatile__ ("
>    fstcw (%3)
>    movl  (%0), %%eax
>    addl  (%1), %%eax
>    addl  (%2), %%eax
>    movl  %%eax, (%3)"
>  :
>  : "g" (&a), "g" (&b), "g" (&c), "g" (&d)
>  : "eax"
>  );

And this is as wrong, as the other code. If it works as expected,
you are just lucky, that gcc has four free registers, so that
all "g" are actually treated as "r". With minor changes in main, that do 
not touch your variables and your __asm__ (...), this will produce wrong
code.

>  printf ("%d\n", d);
>  return 0;
>}

-- 
Regards, Dieter

- Raw text -


  webmaster     delorie software   privacy  
  Copyright © 2019   by DJ Delorie     Updated Jul 2019