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

     1  // +build go1.16,!go1.17
     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  
    22      `github.com/bytedance/sonic/internal/jit`
    23      `github.com/twitchyliquid64/golang-asm/obj`
    24      `github.com/twitchyliquid64/golang-asm/obj/x86`
    25  )
    26  
    27  var (
    28      _V_writeBarrier = jit.Imm(int64(_runtime_writeBarrier))
    29  
    30      _F_gcWriteBarrierAX = jit.Func(gcWriteBarrierAX)
    31  )
    32  
    33  func (self *_Assembler) WritePtr(i int, ptr obj.Addr, rec obj.Addr) {
    34      if rec.Reg == x86.REG_AX || rec.Index == x86.REG_AX {
    35          panic("rec contains AX!")
    36      }
    37      self.Emit("MOVQ", _V_writeBarrier, _R10)
    38      self.Emit("CMPL", jit.Ptr(_R10, 0), jit.Imm(0))
    39      self.Sjmp("JE", "_no_writeBarrier" + strconv.Itoa(i) + "_{n}")
    40      self.Emit("MOVQ", ptr, _AX)
    41      self.xsave(_DI)
    42      self.Emit("LEAQ", rec, _DI)
    43      self.Emit("MOVQ", _F_gcWriteBarrierAX, _R10)  // MOVQ ${fn}, AX
    44      self.Rjmp("CALL", _R10)  
    45      self.xload(_DI)  
    46      self.Sjmp("JMP", "_end_writeBarrier" + strconv.Itoa(i) + "_{n}")
    47      self.Link("_no_writeBarrier" + strconv.Itoa(i) + "_{n}")
    48      self.Emit("MOVQ", ptr, rec)
    49      self.Link("_end_writeBarrier" + strconv.Itoa(i) + "_{n}")
    50  }
    51