Compiler use of ll/sc?

Article: Haswell Transactional Memory Alternatives
By: Paul A. Clayton (, August 28, 2012 9:28 am
Room: Moderated Discussions
Linus Torvalds ( on August 22, 2012 10:41 am wrote:
> More importantly, even if ll/sc could work in some particular
> case, realistically people wouldn't actually use ll/sc,
> because it's basically impossible to do portably, and it's
> not generally amenable to the compiler doing it
> automatically. In contrast, lock elision with small
> transactions is amenable to doing
> automatically from portable source code.

How can a compiler recognize a locked critical section and not be able to recognize at least most of the possible uses of ll/sc? Recognizing a sequence that only loads one value from memory, performs some computation, then replaces the value with a new value (and that being the only store operation and--at least for most ISAs--the only memory operations allowed are the ll/sc [IIRC, Alpha also failed sc on a taken branch.])

ll/sc is such a limited form of transactional memory that recognizing most possible uses would seem not to be too difficult.

Intel's HLE is very nice in allowing older hardware to run binaries with the new instructions. (Avoiding an alternative path--as necessary anyway for compatibility--also likely simplifies software development.) In theory, all future x86 implementations could support RTM, where a minimal implementation simply sets eax to indicate that this transaction will always fail and jumps to the fall-back path.

(An ISA could provide TM support by requiring the result register to be preset with an always-fail result and placing a branch--or a jump--to the alternative path immediately after the instruction that begins the transaction [which instruction would use a nop encoding]. The transaction beginning instruction would skip over the branch and on failure return to the branch instruction [though it could just store the target address]. On hardware that did not support transactions, the branch would be encountered and control would always follow the alternative path. If the ISA had an otherwise unused encoding for setting the result register to the always fail value, it might be safe to use such to being the transaction [The only problem would be that old software might accidentally trigger. A set result register to 1 followed by a branch not equal to zero might be usable as an unconditional jump is more likely to be used by older software {unless there is a path that jumps to the branch instruction}.]. I suspect that using a special transaction beginning instruction would be more desirable.)
< Previous Post in ThreadNext Post in Thread >
TopicPosted ByDate
Article: Haswell TM AlternativesDavid Kanter2012/08/21 09:17 PM
  Article: Haswell TM AlternativesH√•kan Winbom2012/08/21 11:52 PM
    Article: Haswell TM AlternativesDavid Kanter2012/08/22 01:06 AM
  Article: Haswell TM Alternativesanon2012/08/22 08:46 AM
    Article: Haswell TM AlternativesLinus Torvalds2012/08/22 09:16 AM
      Article: Haswell TM AlternativesDoug S2012/08/24 08:34 AM
    AMD's ASF even more limitedPaul A. Clayton2012/08/22 09:20 AM
      AMD's ASF even more limitedLinus Torvalds2012/08/22 09:41 AM
        Compiler use of ll/sc?Paul A. Clayton2012/08/28 09:28 AM
          Compiler use of ll/sc?Linus Torvalds2012/09/08 12:58 PM
            Lock recognition?Paul A. Clayton2012/09/10 01:17 PM
              Sorry, I was confusedPaul A. Clayton2012/09/13 10:56 AM
  Filter to detect store conflictsPaul A. Clayton2012/08/22 09:19 AM
  Article: Haswell TM Alternativesbakaneko2012/08/22 02:02 PM
    Article: Haswell TM AlternativesDavid Kanter2012/08/22 02:45 PM
      Article: Haswell TM Alternativesbakaneko2012/08/22 09:56 PM
  Cache line granularity?Paul A. Clayton2012/08/28 09:28 AM
    Cache line granularity?David Kanter2012/08/31 08:13 AM
      A looser definition might have advantagesPaul A. Clayton2012/09/01 06:29 AM
    Cache line granularity?rwessel2012/08/31 07:54 PM
      Alpha load locked granularityPaul A. Clayton2012/09/01 06:29 AM
        Alpha load locked granularityanon2012/09/02 05:23 PM
          Alpha pages groupsPaul A. Clayton2012/09/03 04:16 AM
  An alternative implementationMaynard Handley2012/11/20 09:52 PM
    An alternative implementationbakaneko2012/11/21 05:52 AM
      Guarding unread values?Paul A. Clayton2012/11/21 08:39 AM
        Guarding unread values?bakaneko2012/11/21 11:25 AM
    TM granularity and versioningPaul A. Clayton2012/11/21 08:27 AM
      TM granularity and versioningMaynard Handley2012/11/21 10:52 AM
        Indeed, TM (and coherence) has devilish details (NT)Paul A. Clayton2012/11/21 10:56 AM
Reply to this Topic
Body: No Text
How do you spell tangerine? ūüćä