github.com/bytedance/sonic@v1.11.7-0.20240517092252-d2edb31b167b/internal/decoder/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 decoder
    18  
    19  import (
    20      `strconv`
    21      _ `unsafe`
    22  
    23      `github.com/bytedance/sonic/internal/jit`
    24      `github.com/bytedance/sonic/internal/rt`
    25      `github.com/twitchyliquid64/golang-asm/obj`
    26      `github.com/twitchyliquid64/golang-asm/obj/x86`
    27  )
    28  
    29  var _runtime_writeBarrier uintptr = rt.GcwbAddr()
    30  
    31  //go:linkname gcWriteBarrierAX runtime.gcWriteBarrier
    32  func gcWriteBarrierAX()
    33  
    34  var (
    35      _V_writeBarrier = jit.Imm(int64(_runtime_writeBarrier))
    36  
    37      _F_gcWriteBarrierAX = jit.Func(gcWriteBarrierAX)
    38  )
    39  
    40  func (self *_Assembler) WritePtrAX(i int, rec obj.Addr, saveDI bool) {
    41      self.Emit("MOVQ", _V_writeBarrier, _R10)
    42      self.Emit("CMPL", jit.Ptr(_R10, 0), jit.Imm(0))
    43      self.Sjmp("JE", "_no_writeBarrier" + strconv.Itoa(i) + "_{n}")
    44      if saveDI {
    45          self.save(_DI)
    46      }
    47      self.Emit("LEAQ", rec, _DI)
    48      self.Emit("MOVQ", _F_gcWriteBarrierAX, _R10)  // MOVQ ${fn}, AX
    49      self.Rjmp("CALL", _R10)  
    50      if saveDI {
    51          self.load(_DI)
    52      }    
    53      self.Sjmp("JMP", "_end_writeBarrier" + strconv.Itoa(i) + "_{n}")
    54      self.Link("_no_writeBarrier" + strconv.Itoa(i) + "_{n}")
    55      self.Emit("MOVQ", _AX, rec)
    56      self.Link("_end_writeBarrier" + strconv.Itoa(i) + "_{n}")
    57  }
    58  
    59  func (self *_Assembler) WriteRecNotAX(i int, ptr obj.Addr, rec obj.Addr, saveDI bool, saveAX bool) {
    60      if rec.Reg == x86.REG_AX || rec.Index == x86.REG_AX {
    61          panic("rec contains AX!")
    62      }
    63      self.Emit("MOVQ", _V_writeBarrier, _R10)
    64      self.Emit("CMPL", jit.Ptr(_R10, 0), jit.Imm(0))
    65      self.Sjmp("JE", "_no_writeBarrier" + strconv.Itoa(i) + "_{n}")
    66      if saveAX {
    67          self.Emit("XCHGQ", ptr, _AX)
    68      } else {
    69          self.Emit("MOVQ", ptr, _AX)
    70      }
    71      if saveDI {
    72          self.save(_DI)
    73      }
    74      self.Emit("LEAQ", rec, _DI)
    75      self.Emit("MOVQ", _F_gcWriteBarrierAX, _R10)  // MOVQ ${fn}, AX
    76      self.Rjmp("CALL", _R10)  
    77      if saveDI {
    78          self.load(_DI)
    79      } 
    80      if saveAX {
    81          self.Emit("XCHGQ", ptr, _AX)
    82      }    
    83      self.Sjmp("JMP", "_end_writeBarrier" + strconv.Itoa(i) + "_{n}")
    84      self.Link("_no_writeBarrier" + strconv.Itoa(i) + "_{n}")
    85      self.Emit("MOVQ", ptr, rec)
    86      self.Link("_end_writeBarrier" + strconv.Itoa(i) + "_{n}")
    87  }
    88  
    89  
    90  func (self *_ValueDecoder) WritePtrAX(i int, rec obj.Addr, saveDI bool) {
    91      self.Emit("MOVQ", _V_writeBarrier, _R10)
    92      self.Emit("CMPL", jit.Ptr(_R10, 0), jit.Imm(0))
    93      self.Sjmp("JE", "_no_writeBarrier" + strconv.Itoa(i) + "_{n}")
    94      if saveDI {
    95          self.save(_DI)
    96      }
    97      self.Emit("LEAQ", rec, _DI)
    98      self.Emit("MOVQ", _F_gcWriteBarrierAX, _R10)  // MOVQ ${fn}, AX
    99      self.Rjmp("CALL", _R10)  
   100      if saveDI {
   101          self.load(_DI)
   102      }    
   103      self.Sjmp("JMP", "_end_writeBarrier" + strconv.Itoa(i) + "_{n}")
   104      self.Link("_no_writeBarrier" + strconv.Itoa(i) + "_{n}")
   105      self.Emit("MOVQ", _AX, rec)
   106      self.Link("_end_writeBarrier" + strconv.Itoa(i) + "_{n}")
   107  }
   108  
   109  func (self *_ValueDecoder) WriteRecNotAX(i int, ptr obj.Addr, rec obj.Addr, saveDI bool) {
   110      if rec.Reg == x86.REG_AX || rec.Index == x86.REG_AX {
   111          panic("rec contains AX!")
   112      }
   113      self.Emit("MOVQ", _V_writeBarrier, _R10)
   114      self.Emit("CMPL", jit.Ptr(_R10, 0), jit.Imm(0))
   115      self.Sjmp("JE", "_no_writeBarrier" + strconv.Itoa(i) + "_{n}")
   116      self.Emit("MOVQ", ptr, _AX)
   117      if saveDI {
   118          self.save(_DI)
   119      }
   120      self.Emit("LEAQ", rec, _DI)
   121      self.Emit("MOVQ", _F_gcWriteBarrierAX, _R10)  // MOVQ ${fn}, AX
   122      self.Rjmp("CALL", _R10)  
   123      if saveDI {
   124          self.load(_DI)
   125      }    
   126      self.Sjmp("JMP", "_end_writeBarrier" + strconv.Itoa(i) + "_{n}")
   127      self.Link("_no_writeBarrier" + strconv.Itoa(i) + "_{n}")
   128      self.Emit("MOVQ", ptr, rec)
   129      self.Link("_end_writeBarrier" + strconv.Itoa(i) + "_{n}")
   130  }