delorie.com/archives/browse.cgi   search  
Mail Archives: djgpp/1995/05/09/11:05:52

Date: Tue, 9 May 1995 16:09:41 +0300
From: eliz AT is DOT elta DOT co DOT il (Eli Zaretskii)
To: djgpp AT sun DOT soe DOT clarkson DOT edu
Subject: Re: What does __volatile__ mean?

Some time ago there was a thread about inline assembly moved by
compiler optimizations out of its place.  Could the message
below bring a salvation to whoever complained about it?  If it
is indeed the solution, please tell me so it could be included
in the future revisions of the DJGPP FAQ list.

----- Begin Included Message -----

From help-gcc-ownrr AT prep DOT ai DOT mit DOT edu Tue May  9 14:33 IDT 1995
To: help-gcc AT prep DOT ai DOT mit DOT edu
Date: 9 May 95 08:31:19 +0100
From: djanssen AT mswe DOT dnet DOT ms DOT philips DOT nl (Ton Janssen)
Subject: Re: What does __volatile__ mean?

In article <3o9lre$1215 AT rs18 DOT hrz DOT th-darmstadt DOT de>, wosch AT rbg DOT informatik DOT th-darmstadt DOT de (olav woelfelschneider) writes:
> Hi folks,
> 
> Well, what does it mean if you declare an inline __volatile__ ?
> Like for example in:
> 
> 
> extern inline char * strcpy(char * dest,const char *src) {
>   char *xdest = dest;
> 
>   __asm__ __volatile__
>        ("1:\tmoveb %1@+,%0@+\n\t"
>         "bne 1b"
>         : "=a" (dest), "=a" (src)
>         : "0" (dest), "1" (src) : "memory");
>   return xdest;
> }
> 
Hi Olav,

An abstract of 'Using and Porting GNU-CC' (Richard M. Stallman)
Chapter 4: GNU extensions to the C-language, page 95:

-Quote-

If an 'asm' has output operands, GNU-CC assumes for optimization purposes
that the instruction has no side effects except to change the output
operands. This does not mean that instructions with a side effect cannot
be used, but you must be carefull, because the compiler may eliminate them
if the output operands aren't used, or move them out of loops, or replace
two with one if they constitute a common sub-expression. Also, if your
instruction does have a side-effect on a variable that otherwise appears
not to change, the old value of the variable may be re-used later if it
happens to be found in a register.

You can prevent an 'asm' instruction from being deleted, moved significantly,
or combined, by writing the keyword 'volatile' after the 'asm'.

-End Quote-

You probably realize that the chance that the compiler does something
wrong regarding optimzations is larger when the function is declared 'inline'.

Hope this helps.

Kind Regards,
-- 
+-----------------------------------------------------------------------------+
|	Ton Janssen	MR-TSSW, Philips Medical Systems Best, The Netherlands|
|	===========     Room: QR-1151,	Tel: +31-40-763084		      |
|	Send EMAIL to:	djanssen AT mswe DOT dnet DOT ms DOT philips DOT nl	{;-)          |
+-----------------------------------------------------------------------------+


----- End Included Message -----

- Raw text -


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