Skip to main content
daviddavid94
Associate II
March 23, 2011
Question

Atomically incremented sequence number using LDREX/STREX for GCC

  • March 23, 2011
  • 5 replies
  • 1129 views
Posted on March 23, 2011 at 04:18

Atomically incremented sequence number using LDREX/STREX for GCC

    This topic has been closed for replies.

    5 replies

    domen23
    Associate II
    May 17, 2011
    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).

    domen23
    Associate II
    May 17, 2011
    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
    May 17, 2011
    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!

    daviddavid94
    Associate II
    May 17, 2011
    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
    May 17, 2011
    Posted on May 17, 2011 at 14:29

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