Skip to content

Commit

Permalink
support other go versions
Browse files Browse the repository at this point in the history
  • Loading branch information
AsterDY committed Aug 25, 2023
1 parent 1f6a6c3 commit 84a089d
Show file tree
Hide file tree
Showing 5 changed files with 41 additions and 13 deletions.
30 changes: 23 additions & 7 deletions internal/encoder/assembler_stkabi_amd64.go
Original file line number Diff line number Diff line change
Expand Up @@ -414,6 +414,20 @@ const (
_StackLimit = _MaxStack * _StateSize
)

var (
_F_mallocgc = jit.Func(mallocgc)
)

func (self *_Assembler) valloc(vt reflect.Type, ret obj.Addr) {
self.Emit("MOVQ", jit.Imm(int64(vt.Size())), _AX) // MOVQ ${vt.Size()}, AX
self.Emit("MOVQ", _AX, jit.Ptr(_SP, 0)) // MOVQ AX, (SP)
self.Emit("MOVQ", jit.Type(vt), _AX) // MOVQ ${vt}, AX
self.Emit("MOVQ", _AX, jit.Ptr(_SP, 8)) // MOVQ AX, 8(SP)
self.Emit("MOVB", jit.Imm(1), jit.Ptr(_SP, 16)) // MOVB $1, 16(SP)
self.call_go(_F_mallocgc) // CALL_GO mallocgc
self.Emit("MOVQ", jit.Ptr(_SP, 24), ret) // MOVQ 24(SP), ${ret}
}

func (self *_Assembler) save_state() {
self.Emit("MOVQ", jit.Ptr(_ST, 0), _CX) // MOVQ (ST), CX
self.Emit("LEAQ", jit.Ptr(_CX, _StateSize), _R8) // LEAQ _StateSize(CX), R8
Expand Down Expand Up @@ -1008,21 +1022,23 @@ func (self *_Assembler) _asm_OP_drop_2(_ *_Instr) {
}

func (self *_Assembler) _asm_OP_recurse(p *_Instr) {
self.prep_buffer() // MOVE {buf}, (SP)
vt, pv := p.vp()
self.Emit("MOVQ", jit.Type(vt), _AX) // MOVQ $(type(p.vt())), AX
self.Emit("MOVQ", _AX, jit.Ptr(_SP, 8)) // MOVQ AX, 8(SP)

/* check for indirection */
if !rt.UnpackType(vt).Indirect() {
self.Emit("MOVQ", _SP_p, _AX) // MOVQ SP.p, AX
self.Emit("MOVQ", _SP_p, _CX)
} else {
self.Emit("MOVQ", _SP_p, _VAR_vp) // MOVQ SP.p, 48(SP)
self.Emit("LEAQ", _VAR_vp, _AX) // LEAQ 48(SP), AX
self.valloc(ptrType, _CX)
self.Emit("MOVQ", _CX, _VAR_vp)
self.WritePtr(3, _SP_p, jit.Ptr(_CX, 0))
}

self.prep_buffer() // MOVE {buf}, (SP)
self.Emit("MOVQ", jit.Type(vt), _AX) // MOVQ $(type(p.vt())), AX
self.Emit("MOVQ", _AX, jit.Ptr(_SP, 8)) // MOVQ AX, 8(SP)

/* call the encoder */
self.Emit("MOVQ" , _AX, jit.Ptr(_SP, 16)) // MOVQ AX, 16(SP)
self.Emit("MOVQ" , _CX, jit.Ptr(_SP, 16)) // MOVQ CX, 16(SP)
self.Emit("MOVQ" , _ST, jit.Ptr(_SP, 24)) // MOVQ ST, 24(SP)
self.Emit("MOVQ" , _ARG_fv, _AX) // MOVQ fv, AX
if pv {
Expand Down
12 changes: 6 additions & 6 deletions internal/encoder/mapiter.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,13 +17,13 @@
package encoder

import (
"encoding"
"reflect"
"sync"
"unsafe"
`encoding`
`reflect`
`sync`
`unsafe`

"github.com/bytedance/sonic/internal/native"
"github.com/bytedance/sonic/internal/rt"
`github.com/bytedance/sonic/internal/native`
`github.com/bytedance/sonic/internal/rt`
)

type _MapPair struct {
Expand Down
4 changes: 4 additions & 0 deletions internal/encoder/stubs_go116.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,10 @@ import (
//go:linkname _subr__b64encode github.com/chenzhuoyu/base64x._subr__b64encode
var _subr__b64encode uintptr

//go:linkname mallocgc runtime.mallocgc
//goland:noinspection GoUnusedParameter
func mallocgc(size uintptr, typ *rt.GoType, needzero bool) unsafe.Pointer

//go:noescape
//go:linkname memmove runtime.memmove
//goland:noinspection GoUnusedParameter
Expand Down
4 changes: 4 additions & 0 deletions internal/encoder/stubs_go117.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,10 @@ import (
//go:linkname _subr__b64encode github.com/chenzhuoyu/base64x._subr__b64encode
var _subr__b64encode uintptr

//go:linkname mallocgc runtime.mallocgc
//goland:noinspection GoUnusedParameter
func mallocgc(size uintptr, typ *rt.GoType, needzero bool) unsafe.Pointer

//go:noescape
//go:linkname memmove runtime.memmove
//goland:noinspection GoUnusedParameter
Expand Down
4 changes: 4 additions & 0 deletions internal/encoder/stubs_go121.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,10 @@ import (
//go:linkname _subr__b64encode github.com/chenzhuoyu/base64x._subr__b64encode
var _subr__b64encode uintptr

//go:linkname mallocgc runtime.mallocgc
//goland:noinspection GoUnusedParameter
func mallocgc(size uintptr, typ *rt.GoType, needzero bool) unsafe.Pointer

//go:noescape
//go:linkname memmove runtime.memmove
//goland:noinspection GoUnusedParameter
Expand Down

0 comments on commit 84a089d

Please sign in to comment.