But on gcc 9.3, atomic store with seq_cst order, will be compiled to mov+fence rather than xchg, see https://gcc.godbolt.org/z/ucbQt6 . Why do we use xchg rather than mov+fence in Go?
在 2020年4月28日星期二 UTC+8上午7:26:15,Ian Lance Taylor写道: > > On Sun, Apr 26, 2020 at 1:31 AM Cholerae Hu <chole...@gmail.com > <javascript:>> wrote: > > > > Atomic.StoreX doesn't return the old value of the given pointer, so lock > mov would work. Why do we use a xchg instead? It there any performance > issue? > > I assume that you are talking about Intel processors. Intel > processors do not have a lock mov instruction. > > From the Intel architecture manual: > > The LOCK prefix can be prepended only to the following > instructions and only to those forms > of the instructions where the destination operand is a memory > operand: ADD, ADC, AND, > BTC, BTR, BTS, CMPXCHG, CMPXCH8B, DEC, INC, NEG, NOT, OR, SBB, SUB, > XOR, > XADD, and XCHG. > > Ian > -- You received this message because you are subscribed to the Google Groups "golang-nuts" group. To unsubscribe from this group and stop receiving emails from it, send an email to golang-nuts+unsubscr...@googlegroups.com. To view this discussion on the web visit https://groups.google.com/d/msgid/golang-nuts/1103e78c-b7e9-489c-8d22-14569ac12992%40googlegroups.com.