Thanks, solved my problem

在2023年1月17日星期二 UTC+8 00:49:03<Ian Lance Taylor> 写道:

> On Mon, Jan 16, 2023 at 8:43 AM j2gg0s <feys...@gmail.com> wrote:
> >
> > As a newbie of golang's assembly, i cant understand why we MOVQ DX CX 
> twice in runtime.gogo. WHY?
>
> I don't see any MOVQ DX, CX instructions here. Can you clarify by
> saying exactly which instructions you are asking about?
>
> Note that MOVQ 0(DX), CX treats DX as a memory address, and moves the
> 8-byte value at that address into CX. And MOVQ DX, g(CX) treats CX as
> a memory address, and moves the value in DX into the address as "g"
> bytes offset from the address in CX.
>
> Ian
>
>
> > Source code:
> > ```
> > 255 // func gogo(buf *gobuf)
> > 256 // restore state from Gobuf; longjmp
> > 257 TEXT runtime·gogo(SB), NOSPLIT, $0-8
> > 258 MOVQ buf+0(FP), BX // gobuf
> > 259 MOVQ gobuf_g(BX), DX
> > 260 MOVQ 0(DX), CX // make sure g != nil
> > 261 JMP gogo<>(SB)
> > 262
> > 263 TEXT gogo<>(SB), NOSPLIT, $0
> > 264 get_tls(CX)
> > 265 MOVQ DX, g(CX)
> > 266 MOVQ DX, R14 // set the g register
> > 267 MOVQ gobuf_sp(BX), SP // restore SP
> > 268 MOVQ gobuf_ret(BX), AX
> > 269 MOVQ gobuf_ctxt(BX), DX
> > 270 MOVQ gobuf_bp(BX), BP
> > 271 MOVQ $0, gobuf_sp(BX) // clear to help garbage collector
> > 272 MOVQ $0, gobuf_ret(BX)
> > 273 MOVQ $0, gobuf_ctxt(BX)
> > 274 MOVQ $0, gobuf_bp(BX)
> > 275 MOVQ gobuf_pc(BX), BX
> > 276 JMP BX
> > ```
> >
> > Link: 
> https://github.com/golang/go/blob/go1.17.13/src/runtime/asm_amd64.s#L255
> >
> >
> > --
> > 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...@googlegroups.com.
> > To view this discussion on the web visit 
> https://groups.google.com/d/msgid/golang-nuts/5fafeb38-1bc7-4a96-b386-41e14c431273n%40googlegroups.com
> .
>

-- 
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/3ba1a60a-f0be-497c-bdda-f72316cc1d2an%40googlegroups.com.

Reply via email to