[Date Prev][Date Next] [Thread Prev][Thread Next] [Date Index] [Thread Index]

Re: How to tell the compiler NOT to assume cpu provides atomic instructions



*Please* do not CC me.  My M-F-T is set appropriately; please respect
it.

On Wed, Mar 16, 2011 at 11:03:17PM +0000, Martin wrote:
> 1. SPARC V8 only has very weak atomic ops (IIRC it's only test and set)
> which aren't sufficient to implement all of the GCC atomic built-ins
> without some extra work.  This is why there will be a need to provide
> your own implementation and a linking problem if you don't.
> 
> 2. SPARC V9 has CAS which allows most of the GCC atomic ops to be
> emulated but is 64 bit, which may not be what you want.

Debian only supports v9 processors, but the sparc port is 32-bit.  By
default, GCC uses -mcpu=ultrasparc and is configured for sparc-linux-gnu
(which is 32-bit).  There is no need to specify any flags to GCC, since
it does the right thing by default.  All UltraSPARC operations are
supported, but the code generated is 32-bit.

For example (truncated):

  blackhole ok % gcc -v foo.c              
  Using built-in specs.
  Target: sparc-linux-gnu
  Configured with: ../src/configure -v --with-pkgversion='Debian 4.4.5-13' --with-bugurl=file:///usr/share/doc/gcc-4.4/README.Bugs --enable-languages=c,c++,fortran,objc,obj-c++ --prefix=/usr --program-suffix=-4.4 --enable-shared --enable-multiarch --enable-linker-build-id --with-system-zlib --libexecdir=/usr/lib --without-included-gettext --enable-threads=posix --with-gxx-include-dir=/usr/include/c++/4.4 --libdir=/usr/lib --enable-nls --enable-clocale=gnu --enable-libstdcxx-debug --enable-objc-gc --enable-targets=all --with-long-double-128 --enable-checking=release --build=sparc-linux-gnu --host=sparc-linux-gnu --target=sparc-linux-gnu
  Thread model: posix
  gcc version 4.4.5 (Debian 4.4.5-13) 
  COLLECT_GCC_OPTIONS='-v' '-mcpu=ultrasparc'
   /usr/lib/gcc/sparc-linux-gnu/4.4.5/cc1 -quiet -v -D__sparc_v9__ foo.c -quiet -dumpbase foo.c -mcpu=ultrasparc -auxbase foo -version -o /tmp/cceKtrHZ.s

Note that it passes -mcpu=ultrasparc.

> By default I think GCC still generates V8 code on Debian, setting
> -mcpu=v8+ should do what you want.  Furthermore I might suggest using
> Hans Boehm's libatomic-ops:

  blackhole no % gcc -mcpu=v8+ foo.c   
  foo.c:1: error: bad value (v8+) for -mcpu= switch

I believe Debian's GCC does this by default already, with or without
-mv8plus:

  blackhole ok % file a.out              
  a.out: ELF 32-bit MSB executable, SPARC32PLUS, V8+ Required, version 1 (SYSV), dynamically linked (uses shared libs), for GNU/Linux 2.6.18, not stripped

-- 
brian m. carlson / brian with sandals: Houston, Texas, US
+1 832 623 2791 | http://www.crustytoothpaste.net/~bmc | My opinion only
OpenPGP: RSA v4 4096b: 88AC E9B2 9196 305B A994 7552 F1BA 225C 0223 B187

Attachment: signature.asc
Description: Digital signature


Reply to: