github.com/goshafaq/sonic@v0.0.0-20231026082336-871835fb94c6/internal/encoder/asm_stubs_amd64_go117.go (about)

     1  //go:build go1.17 && !go1.21
     2  // +build go1.17,!go1.21
     3  
     4  // Copyright 2023 CloudWeGo Authors
     5  //
     6  // Licensed under the Apache License, Version 2.0 (the "License");
     7  // you may not use this file except in compliance with the License.
     8  // You may obtain a copy of the License at
     9  //
    10  //     http://www.apache.org/licenses/LICENSE-2.0
    11  //
    12  // Unless required by applicable law or agreed to in writing, software
    13  // distributed under the License is distributed on an "AS IS" BASIS,
    14  // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    15  // See the License for the specific language governing permissions and
    16  // limitations under the License.
    17  
    18  package encoder
    19  
    20  import (
    21  	"strconv"
    22  	"unsafe"
    23  
    24  	"github.com/goshafaq/sonic/internal/jit"
    25  	"github.com/twitchyliquid64/golang-asm/obj"
    26  	"github.com/twitchyliquid64/golang-asm/obj/x86"
    27  )
    28  
    29  var (
    30  	_V_writeBarrier = jit.Imm(int64(uintptr(unsafe.Pointer(&_runtime_writeBarrier))))
    31  
    32  	_F_gcWriteBarrierAX = jit.Func(gcWriteBarrierAX)
    33  )
    34  
    35  func (self *_Assembler) WritePtr(i int, ptr obj.Addr, rec obj.Addr) {
    36  	if rec.Reg == x86.REG_AX || rec.Index == x86.REG_AX {
    37  		panic("rec contains AX!")
    38  	}
    39  	self.Emit("MOVQ", _V_writeBarrier, _BX)
    40  	self.Emit("CMPL", jit.Ptr(_BX, 0), jit.Imm(0))
    41  	self.Sjmp("JE", "_no_writeBarrier"+strconv.Itoa(i)+"_{n}")
    42  	self.xsave(_DI)
    43  	self.Emit("MOVQ", ptr, _AX)
    44  	self.Emit("LEAQ", rec, _DI)
    45  	self.Emit("MOVQ", _F_gcWriteBarrierAX, _BX) // MOVQ ${fn}, AX
    46  	self.Rjmp("CALL", _BX)
    47  	self.xload(_DI)
    48  	self.Sjmp("JMP", "_end_writeBarrier"+strconv.Itoa(i)+"_{n}")
    49  	self.Link("_no_writeBarrier" + strconv.Itoa(i) + "_{n}")
    50  	self.Emit("MOVQ", ptr, rec)
    51  	self.Link("_end_writeBarrier" + strconv.Itoa(i) + "_{n}")
    52  }