This is the mail archive of the libstdc++@gcc.gnu.org mailing list for the libstdc++ project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

gcc 3.2.3 config/os/bits/i386/atomicity.h broken


Hi,

This area of libstdc++-v3 appears to have had significant
work after the 3.2 branch was cut so I don't know if this
bug is still there.  

This file uses instructions which are not available on a
plain i386.  

http://webster.cs.ucr.edu/Page_TechDocs/Doc386/s15_06.html
points out that an exception 6 (illegal instruction) will
be generated if lock is used with any instruction other than
the list.  xadd is not on this list.  Further
http://www.geocrawler.com/archives/3/35/2002/6/50/9063492/
points out that BSWAP, CMPXCHG, XADD are 486 and above.  So
the code in this file is wrong.

In fact, the config/i386 and config/i486 have the same code.

I only see one way to implement this on an i386 in user space.
Add a spin lock variable (could be static to function) and do
a locked exchange on it.  When you get the lock, do a regular
fetch and add.  Something like this for pure i386 targets
(written in mail so forgive sloppiness):

static inline _Atomic_word
__attribute__ ((__unused__))
__exchange_and_add (volatile _Atomic_word *__mem, int __val)
{
  register _Atomic_word __result, __tmp;
  static volatile _Atomic_word __lock = 1;

 /* obtain the atomic exchange/add lock */
  do {
    __tmp = 0;
    __asm__ __volatile__("xchgl %0,%1"
             :"=r" (__tmp)
             :"m" (&__lock), "0" (__lock)
             :"memory");
  } while ( __tmp == 0 );
  
    __result = *__mem;
    *__mem += __val;
  
  /* release spin lock */
  __lock = 1;

  return __result;
}



As best I can tell, in gcc 3.3 and later, there is no support
for atomicity.h on the basic i386 at all.  Is this right?
If this implementation works, could it be conditionally used
in the x86 atomicity.h for the vanilla i386 and included
in the single file?

Thanks.

-- 
Joel Sherrill, Ph.D.             Director of Research & Development
joel at OARcorp dot com                 On-Line Applications Research
Ask me about RTEMS: a free RTOS  Huntsville AL 35805
Support Available                (256) 722-9985


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