
On Tue, 30 Mar 2010, Khiszinsky, Maxim wrote:
Helge Bahmann wrote:
Sure, if you turn optimization off, code looks ridiculous. Both gcc (tested with various versions ranging from 3.3 to 4.4) and msvc (visual studio express) optimize the switch/case with constant operand into nothingness.
Sorry, the problem observed on MS VC++ 2008 x86 with full optimization and SSE instruction set. See my previous answer to Phil with explanations.
I see, and I would wager to guess that the problem with the following: atomic64_t v ; v = _mm_loadl_epi64( (__m128i *) pMem ).m128i_i64[0] ; are the funky type-casts confusing aliasing analysis sufficiently so that the compiler believes that "order" might be modified by the above statements. You could try changing that to something like: __m128i i = _mm_loadl_epi64( (__m128i * _Restrict) pMem); if (order == ...) ... return i.m128i_i64[0]; I can assure you that MSVC does not have an "intrinsic" problem with making the desired optimization (at least I know of no such problem with Boost.Atomic).
I would however be very interested in sparc and ia64 atomic operations, would you be interested in implementing (or lending me a hand) them for boost.atomic?
You may try CDS implementation of sparc and ia64 atomics: cds\compiler\gcc\ia64\atomic.h - for itanium ia64 cds\compiler\gcc\sparc\atomic.h - for sparc 64bit mode These files contain template and common versions of 32bit and 64bit atomic primitives.
If you need I can extract it from CDS for you, no problem. It works well with CDS tests but I'm not sure whether it is correct...
Thanks will look into that and send you a version for testing Best regards Helge