Hi Fred,
Can you try compiling this short C program:
volatile int a;
int main(void)
{
__sync_fetch_and_add(&a, 1);
return a;
}
For me, with GCC 4.2.1, this Just Works™. If it doesn't for you, can
you try compiling it with gcc -S and take a look at the generated .s
file? It should contain this short sequence:
lock
addl $1, a
If instead it contains:
call __sync_fetch_and_add
Then something weird is going on - the compiler is generating a call
to the implementation in libgcc_s, which should only be used for non-
x86 platforms.
If we can't manage to get this working in the general case, then you
can use this little program in the configure script - if it runs and
exits then the compiler supports this extension (both recent gcc and
clang do, so it should become increasingly-well supported over time).
I'm still surprised that it doesn't work for you - I've not had any
problems with it for a couple of years on FreeBSD, and I was under the
impression GCC supported Linux better than FreeBSD.
David
On 5 May 2009, at 08:46, Fred Kiefer wrote:
David Chisnall wrote:
I think it's important to work out why it is failing on your machine.
The reason I suggested this change is that, for me, looking at the
assembly, it generates the same code as our inline asm on x86 but
also
works on non-x86 platforms that we currently use a painfully slow
code
path for.
I fully agree with you here.
I am using GCC 4.2.1, and this compiles correctly with no -march=
anything specified. If I specify -march=i386 it still generates the
LOCK. Looking more deeply at the ISA references, it appears that the
LOCK prefix was part of the original 80386 instruction set, so this
is
atomic on any x86 processor (it was the CMPXCHG instruction and
friends
that came in with the 80486).
That would be great, in this case, we did not loose any compatibility
with the last change and also wont with the new one.
Possibly the GCC version check is incorrect. According to the gcc
docs,
these functions appeared in 4.1.0, however it seems that 4.2 is when
they became well-supported. Possibly setting 4.2.0 or 4.2.1 as the
minimum GCC version to adopt them will be better?
Again you are correct, better require a gcc version where we can be
sure
it supports this correctly. Still this does not help on my machine,
as I
wrote in the first mail I have gcc 4.3.2 installed. Here are the
full specs:
gcc -dumpspecs
*asm:
%{v:-V} %{Qy:} %{!Qn:-Qy} %{n} %{T} %{Ym,*} %{Yd,*} %{Wa,*:%*}
*asm_debug:
%{gstabs*:--gstabs}%{!gstabs*:%{g*:--gdwarf2}}
%{fdebug-prefix-map=*:--debug-prefix-map %*}
*asm_final:
*asm_options:
%{--target-help:%:print-asm-header()} %a %Y %{c:%W{o*}%{!o*:-o
%w%b%O}}%{!c:-o %d%w%u%O}
*invoke_as:
%{!S:-o %|.s |
as %(asm_options) %|.s %A }
*cpp:
%{posix:-D_POSIX_SOURCE} %{pthread:-D_REENTRANT}
*cpp_options:
%(cpp_unique_options) %1 %{m*} %{std*&ansi&trigraphs} %{W*&pedantic*}
%{w} %{f*} %{g*:%{!g0:%{!fno-working-directory:-fworking-directory}}}
%{O*} %{undef} %{save-temps:-fpch-preprocess}
*cpp_debug_options:
%{d*}
*cpp_unique_options:
%{C|CC:%{!E:%eGCC does not support -C or -CC without -E}} %{!Q:-quiet}
%{nostdinc*} %{C} %{CC} %{v} %{I*&F*} %{P} %I %{MD:-MD
%{!o:%b.d}%{o*:%.d%*}} %{MMD:-MMD %{!o:%b.d}%{o*:%.d%*}} %{M} %{MM}
%{MF*} %{MG} %{MP} %{MQ*} %{MT*}
%{!E:%{!M:%{!MM:%{!MT:%{!MQ:%{MD|MMD:%{o*:-MQ %*}}}}}}} %{remap}
%{g3|ggdb3|gstabs3|gcoff3|gxcoff3|gvms3:-dD} %{H} %C %{D*&U*&A*} %{i*}
%Z %i %{fmudflap:-D_MUDFLAP -include mf-runtime.h}
%{fmudflapth:-D_MUDFLAP -D_MUDFLAPTH -include mf-runtime.h} %{E|M|MM:
%W{o*}}
*trad_capable_cpp:
cc1 -E %{traditional|ftraditional|traditional-cpp:-traditional-cpp}
*cc1:
%(cc1_cpu) %{profile:-p}
*cc1_options:
%{pg:%{fomit-frame-pointer:%e-pg and -fomit-frame-pointer are
incompatible}} %1 %{!Q:-quiet} -dumpbase %B %{d*} %{m*} %{a*}
%{c|S:%{o*:-auxbase-strip %*}%{!o*:-auxbase %b}}%{!c:%{!S:-auxbase
%b}}
%{g*} %{O*} %{W*&pedantic*} %{w} %{std*&ansi&trigraphs} %{v:-version}
%{pg:-p} %{p} %{f*} %{undef} %{Qn:-fno-ident} %{--help:--help}
%{--target-help:--target-help} %{--help=*:--help=%(VALUE)}
%{!fsyntax-only:%{S:%W{o*}%{!o*:-o %b.s}}} %{fsyntax-only:-o %j}
%{-param*} %{fmudflap|fmudflapth:-fno-builtin -fno-merge-constants}
%{coverage:-fprofile-arcs -ftest-coverage}
*cc1plus:
*link_gcc_c_sequence:
%{static:--start-group} %G %L %{static:--end-group}%{!static:%G}
*link_ssp:
%{fstack-protector:}
*endfile:
%{ffast-math|funsafe-math-optimizations:crtfastmath.o%s}
%{mpc32:crtprec32.o%s} %{mpc64:crtprec64.o%s}
%{mpc80:crtprec80.o%s} %{shared|pie:crtendS.o%s;:crtend.o%s}
crtn.o%s
*link:
%{!r:--build-id} %{!static:--eh-frame-hdr} -m %(link_emulation)
%{shared:-shared} %{!shared: %{!ibcs: %{!static:
%{rdynamic:-export-dynamic} %{!dynamic-linker:-dynamic-linker
%(dynamic_linker)}} %{static:-static}}}
*lib:
%{pthread:-lpthread} %{shared:-lc} %{!shared:%{mieee-fp:-lieee}
%{profile:-lc_p}%{!profile:-lc}}
*mfwrap:
%{static: %{fmudflap|fmudflapth: --wrap=malloc --wrap=free
--wrap=calloc --wrap=realloc --wrap=mmap --wrap=munmap --wrap=alloca}
%{fmudflapth: --wrap=pthread_create}} %{fmudflap|fmudflapth: --
wrap=main}
*mflib:
%{fmudflap|fmudflapth: -export-dynamic}
*link_gomp:
*libgcc:
%{static|static-libgcc:-lgcc
-lgcc_eh}%{!static:%{!static-libgcc:%{!shared-libgcc:-lgcc --as-needed
-lgcc_s --no-as-needed}%{shared-libgcc:-lgcc_s%{!shared: -lgcc}}}}
*startfile:
%{!shared: %{pg|p|profile:gcrt1.o%s;pie:Scrt1.o%s;:crt1.o%s}}
crti.o%s %{static:crtbeginT.o%s;shared|pie:crtbeginS.o%s;:crtbegin.o
%s}
*switches_need_spaces:
*cross_compile:
0
*version:
4.3.2
*multilib:
. ;
*multilib_defaults:
*multilib_extra:
*multilib_matches:
*multilib_exclusions:
*multilib_options:
*linker:
collect2
*link_libgcc:
%D
*md_exec_prefix:
*md_startfile_prefix:
*md_startfile_prefix_1:
*startfile_prefix_spec:
*sysroot_spec:
--sysroot=%R
*sysroot_suffix_spec:
*sysroot_hdrs_suffix_spec:
*cc1_cpu:
%{mcpu=*:-mtune=%* %n`-mcpu=' is deprecated. Use `-mtune=' or '-
march='
instead.
} %<mcpu=* %{mintel-syntax:-masm=intel %n`-mintel-syntax' is
deprecated.
Use `-masm=intel' instead.
} %{mno-intel-syntax:-masm=att %n`-mno-intel-syntax' is deprecated.
Use
`-masm=att' instead.
}%{march=native:%<march=native %:local_cpu_detect(arch)
%{!mtune=*:%<mtune=native %:local_cpu_detect(tune)}}
%{mtune=native:%<mtune=native %:local_cpu_detect(tune)}
*link_emulation:
elf_i386
*dynamic_linker:
%{muclibc:%{mglibc:%e-mglibc and -muclibc used
together}/lib/ld-uClibc.so.0;:/lib/ld-linux.so.2}
*link_command:
%{!fsyntax-only:%{!c:%{!M:%{!MM:%{!E:%{!S: %(linker) %l %{pie:-pie}
%X %{o*} %{A} %{d} %{e*} %{m} %{N} %{n} %{r} %{s} %{t} %{u*} %{x}
%{z} %{Z} %{!A:%{!nostdlib:%{!nostartfiles:%S}}} %{static:} %{L*}
%(mfwrap) %(link_libgcc) %o
%{fopenmp|ftree-parallelize-loops=*:%:include(libgomp.spec)%
(link_gomp)}
%(mflib) %{fprofile-arcs|fprofile-generate|coverage:-lgcov}
%{!nostdlib:%{!nodefaultlibs:%(link_ssp) %(link_gcc_c_sequence)}}
%{!A:%{!nostdlib:%{!nostartfiles:%E}}} %{T*} }}}}}}
_______________________________________________
Gnustep-dev mailing list
Gnustep-dev@gnu.org
http://lists.gnu.org/mailman/listinfo/gnustep-dev
_______________________________________________
Gnustep-dev mailing list
Gnustep-dev@gnu.org
http://lists.gnu.org/mailman/listinfo/gnustep-dev