github.com/bytedance/sonic@v1.11.7-0.20240517092252-d2edb31b167b/internal/encoder/asm_stubs_amd64_go117.go (about)

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