This is the mail archive of the crossgcc@sourceware.cygnus.com mailing list for the crossgcc project.

See the CrossGCC FAQ for lots more infromation.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]

gcc volatile behaviour


I have some problem with gcc/egcs crosscompiling to m68k.
The problem probably would be present on any target, actually.

When the value of an assignment expression where the left-hand side is 
volatile is used, gcc re-fetches the left-hand object. That is:

  volatile int a, b;
  a = b = 0;

compiles to

        clr.l b
        move.l b,%d0
        move.l %d0,a
 
Apart from the fact that the involvement of d0 is not really a
necessity (with -O3), I do not understand why does it fetch 'b' ?

Similarly, when one does stringcopy:

   strcpy( char *a char *b )
   {
     while( *a++ = *b++ );
   }
   
compiles the loop to the inefficient but correct

.L7:
        move.b (%a0)+,%d0
        move.b %d0,(%a1)+
        jbne .L7

Changing the declaration of 'a' to volatile char *a, the result is this:

.L7:
        move.b (%a1)+,(%a0)
        move.b (%a0)+,%d0
        jbne .L7
 
This means that the copy is not terminated when the '\0' is *written*
to the area pointed by 'a' but when a zero is *read back* from the given 
area. In case of HW buffers this may not be what the programmer had in 
mind, for buffers sometimes are write only, for example.

In every case, when the left hand operand of an assignment expression
is volatile and the value of the expression is ised, gcc and egcs read 
back the value from the volatile object instead of using the value
written to the object.

Is there any particular reason why gcc and egcs do this ?

Thanks,

Zoltan

------
Want more information?  See the CrossGCC FAQ, http://www.objsw.com/CrossGCC/
Want to unsubscribe? Send a note to crossgcc-unsubscribe@sourceware.cygnus.com


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]