cancel
Showing results for 
Search instead for 
Did you mean: 

Atomically incremented sequence number using LDREX/STREX for GCC

daviddavid94
Associate II
Posted on March 23, 2011 at 04:18

Atomically incremented sequence number using LDREX/STREX for GCC

5 REPLIES 5
domen23
Associate II
Posted on May 17, 2011 at 14:29

gcc warns because you list operands as input/output.

List them as clobbered (dunno how to have named clobbered operands though).

daviddavid94
Associate II
Posted on May 17, 2011 at 14:29

It was my impression that ''clobbered'' is specifically for registers used explicitly in the ASM code - that's the primary reason for using symbolics, so the compiler can determine for itself which registers to use, because it selects them itself. And as you note, there does not appear to be a way to denote ''clobbered'' symbolics.

I suspect GCC warns, because it is not fully aware of the STREX and LDREX instruction formats.

That's just a guess, but I did an experiment. I replaced LDREXH with LDRH, replaced STREXH with STRH (removing the result register argument), and removed the ''result'' input/output specifier, and the CMP instruction which reads ''result''. That code produced no warnings, which implies to me that GCC understands the nature of LDRH and STRH operands, but not LDREXH and STREXH operands - otherwise it would have continued to warn about the ''temp_reg'' usage.

daviddavid94
Associate II
Posted on May 17, 2011 at 14:29

D'oh! Please disregard 2nd and 3rd paragraphs of my prior post.

Bad experiment, I neglected to remove the initialiser from ''temp_reg''. When I did so, GCC *did* warn about its use, so that guess of mine was wrong.

Sorry about that!

domen23
Associate II
Posted on May 17, 2011 at 14:29

Actually, reading

www.cs.dartmouth.edu/~sergey/cs108/2009/gcc-inline-asm.pdf

it says you should use =&r for temporary registers.

Output only will also get rid of the initialization warning.

daviddavid94
Associate II
Posted on May 17, 2011 at 14:29

Thank you Domen! Using =&r does exactly what I wanted for those registers.