All the AMD64 atomic instructions, exposed as Go functions:
LOCK {ADD,ADC,AND,BTC,BTR,BTS,CMPXCHG,CMPXCH8B,CMPXCHG16B,DEC,INC,NEG,NOT,OR,SBB,SUB,XOR,XADD}
andXCHG
, for all possible operand sizesXBEGIN
,XABORT
,XEND
andXTEST
(Intel TSX RTM transactional memory instructions)
- This is currently an AMD64-only package; none of the functions are available if not building for
amd64
. - Some of the functions are hard to use reliably due to the nature of the Go compiler (e.g. those that depend on the contents of the FLAGS register, like
AddWithCarry
orSubtractWithBorrow
); they are included for completeness and because they can be used, if proper care is used. - Before using the TSX RTM functions, you must ensure that the processors supports them by using e.g. github.com/intel-go/cpuid:
if cpuid.HasExtendedFeature(cpuid.RTM) { // OK to use XBEGIN/XTEST/XABORT/XEND }
The atomics instructions are defined in gen.go
. gen.go
will produce the files atomic_amd64.{go,s}
by running:
go generate gen.go