Skip to Main Content

DevOps, CI/CD and Automation

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

Interested in getting your voice heard by members of the Developer Marketing team at Oracle? Check out this post for AppDev or this post for AI focus group information.

sunCC chokes on inline assembler (boost 1.49 compilation)

919808Feb 25 2012 — edited Feb 26 2012
Hello.

In my quest to get a project compiled which depends on boost (amongst others), I tried to compile boost 1.49. After small modifications, the compile went peacefully but sunCC chokes on some assembler which is unfortunately required for parts that the project depends on.

Here is a small testcase. The atomic_add32() is taken straight from boost. What is interesting though is that if no -xO flag is set, sunCC compiles without any warnings/errors but seems to ignore the assembler because it produces the wrong output (5 instead of 30). As soon as a -xO[0-5] is set, the following error is produced: "test.cpp", [main]:ube: error: Invalid reference to argument '0' in GASM Inlining

Again, I am using a x86_64 Linux (Gentoo) with Studio 12.3 and gcc 4.6.2 (if that matters). Naturally, gcc/icc/path64 all compile is code just fine and produce the right result.

-----
#include <stdint.h>
#include <iostream>

inline uint32_t atomic_add32(volatile uint32_t *mem, uint32_t val)
{
int r;

asm volatile
(
"lock\n\t"
"xadd %1, %0":
"+m"( *mem ), "=r"( r ): // outputs (%0, %1)
"1"( val ): // inputs (%2 == %1)
"memory", "cc" // clobbers
);

return r;
}

int main(void)
{
uint32_t test = 5;

atomic_add32(&test, 25);

std::cout << test << std::endl;

return 0;
}
-----

Thanks for any help in advance.

So long,
matthias

Comments

Locked Post
New comments cannot be posted to this locked post.

Post Details

Locked on Mar 25 2012
Added on Feb 25 2012
6 comments
1,156 views