github.com/goshafaq/sonic@v0.0.0-20231026082336-871835fb94c6/internal/encoder/asm_stubs_amd64_go121.go (about) 1 //go:build go1.21 && !go1.22 2 // +build go1.21,!go1.22 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_gcWriteBarrier2 = jit.Func(gcWriteBarrier2) 33 ) 34 35 func (self *_Assembler) WritePtr(i int, ptr obj.Addr, old obj.Addr) { 36 if old.Reg == x86.REG_AX || old.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(_SP_q) 43 self.Emit("MOVQ", _F_gcWriteBarrier2, _BX) // MOVQ ${fn}, AX 44 self.Rjmp("CALL", _BX) 45 self.Emit("MOVQ", ptr, jit.Ptr(_SP_q, 0)) 46 self.Emit("MOVQ", old, _AX) 47 self.Emit("MOVQ", _AX, jit.Ptr(_SP_q, 8)) 48 self.xload(_SP_q) 49 self.Link("_no_writeBarrier" + strconv.Itoa(i) + "_{n}") 50 self.Emit("MOVQ", ptr, old) 51 }