How to get `gcc` to generate `bts` instruction for x86-64 from standard C?

前端 未结 3 2009
谎友^
谎友^ 2020-12-16 13:41

Inspired by a recent question, I\'d like to know if anyone knows how to get gcc to generate the x86-64 bts instruction (bit test and set) on the Li

3条回答
  •  一整个雨季
    2020-12-16 14:02

    I believe (but am not certain) that neither the C++ or C standards have any mechanisms for these types of synchronization mechanisms yet. Support for higher level synchronization mechanisms are in various states of standardization, but I don't even think one of those would allow you the access of the type of primitive you're after.

    Are you programming lock-free datastructures where locks are insufficient?

    You probably want to just go ahead and use gcc's non-standard extensions and/or operating system or library provided synchronization primitives. I would bet there's a library that might provide the type of portability you're looking for if you're concerned about using compiler intrinsics. (Though really, I think most people just bite the bullet and use gcc-specific code when they need it. Not ideal, but the standards haven't really been keeping up.)

提交回复
热议问题