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