mirror of
https://github.com/ii64/sonic.git
synced 2026-06-21 00:46:43 +08:00
opt: optimize decode slice (#409)
This commit is contained in:
parent
eaa70d4c25
commit
1724d3e2af
4 changed files with 47 additions and 5 deletions
|
|
@ -319,6 +319,7 @@ var _OpFuncTab = [256]func(*_Assembler, *_Instr) {
|
||||||
_OP_dismatch_err : (*_Assembler)._asm_OP_dismatch_err,
|
_OP_dismatch_err : (*_Assembler)._asm_OP_dismatch_err,
|
||||||
_OP_go_skip : (*_Assembler)._asm_OP_go_skip,
|
_OP_go_skip : (*_Assembler)._asm_OP_go_skip,
|
||||||
_OP_add : (*_Assembler)._asm_OP_add,
|
_OP_add : (*_Assembler)._asm_OP_add,
|
||||||
|
_OP_check_empty : (*_Assembler)._asm_OP_check_empty,
|
||||||
}
|
}
|
||||||
|
|
||||||
func (self *_Assembler) instr(v *_Instr) {
|
func (self *_Assembler) instr(v *_Instr) {
|
||||||
|
|
@ -1172,6 +1173,8 @@ var (
|
||||||
|
|
||||||
var (
|
var (
|
||||||
_F_FieldMap_GetCaseInsensitive obj.Addr
|
_F_FieldMap_GetCaseInsensitive obj.Addr
|
||||||
|
_Empty_Slice = make([]byte, 0)
|
||||||
|
_Zero_Base = int64(uintptr(((*rt.GoSlice)(unsafe.Pointer(&_Empty_Slice))).Ptr))
|
||||||
)
|
)
|
||||||
|
|
||||||
const (
|
const (
|
||||||
|
|
@ -1642,6 +1645,22 @@ func (self *_Assembler) _asm_OP_slice_init(p *_Instr) {
|
||||||
self.Emit("MOVQ" , _AX, jit.Ptr(_VP, 8)) // MOVQ AX, 8(VP)
|
self.Emit("MOVQ" , _AX, jit.Ptr(_VP, 8)) // MOVQ AX, 8(VP)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (self *_Assembler) _asm_OP_check_empty(p *_Instr) {
|
||||||
|
rbracket := p.vb()
|
||||||
|
if rbracket == ']' {
|
||||||
|
self.check_eof(1)
|
||||||
|
self.Emit("LEAQ", jit.Ptr(_IC, 1), _AX) // LEAQ 1(IC), AX
|
||||||
|
self.Emit("CMPB", jit.Sib(_IP, _IC, 1, 0), jit.Imm(int64(rbracket))) // CMPB (IP)(IC), ']'
|
||||||
|
self.Sjmp("JNE" , "_not_empty_array_{n}") // JNE _not_empty_array_{n}
|
||||||
|
self.Emit("MOVQ", _AX, _IC) // MOVQ AX, IC
|
||||||
|
self.Emit("MOVQ", jit.Imm(_Zero_Base), jit.Ptr(_VP, 0)) // MOVQ $zerobase, (VP)
|
||||||
|
self.Xjmp("JMP" , p.vi()) // JMP {p.vi()}
|
||||||
|
self.Link("_not_empty_array_{n}")
|
||||||
|
} else {
|
||||||
|
panic("only implement check empty array here!")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
func (self *_Assembler) _asm_OP_slice_append(p *_Instr) {
|
func (self *_Assembler) _asm_OP_slice_append(p *_Instr) {
|
||||||
self.Emit("MOVQ" , jit.Ptr(_VP, 8), _AX) // MOVQ 8(VP), AX
|
self.Emit("MOVQ" , jit.Ptr(_VP, 8), _AX) // MOVQ 8(VP), AX
|
||||||
self.Emit("CMPQ" , _AX, jit.Ptr(_VP, 16)) // CMPQ AX, 16(VP)
|
self.Emit("CMPQ" , _AX, jit.Ptr(_VP, 16)) // CMPQ AX, 16(VP)
|
||||||
|
|
|
||||||
|
|
@ -315,6 +315,7 @@ var _OpFuncTab = [256]func(*_Assembler, *_Instr) {
|
||||||
_OP_dismatch_err : (*_Assembler)._asm_OP_dismatch_err,
|
_OP_dismatch_err : (*_Assembler)._asm_OP_dismatch_err,
|
||||||
_OP_go_skip : (*_Assembler)._asm_OP_go_skip,
|
_OP_go_skip : (*_Assembler)._asm_OP_go_skip,
|
||||||
_OP_add : (*_Assembler)._asm_OP_add,
|
_OP_add : (*_Assembler)._asm_OP_add,
|
||||||
|
_OP_check_empty : (*_Assembler)._asm_OP_check_empty,
|
||||||
_OP_debug : (*_Assembler)._asm_OP_debug,
|
_OP_debug : (*_Assembler)._asm_OP_debug,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -1165,6 +1166,8 @@ var (
|
||||||
|
|
||||||
var (
|
var (
|
||||||
_F_FieldMap_GetCaseInsensitive obj.Addr
|
_F_FieldMap_GetCaseInsensitive obj.Addr
|
||||||
|
_Empty_Slice = make([]byte, 0)
|
||||||
|
_Zero_Base = int64(uintptr(((*rt.GoSlice)(unsafe.Pointer(&_Empty_Slice))).Ptr))
|
||||||
)
|
)
|
||||||
|
|
||||||
const (
|
const (
|
||||||
|
|
@ -1632,6 +1635,22 @@ func (self *_Assembler) _asm_OP_slice_init(p *_Instr) {
|
||||||
self.Link("_done_{n}") // _done_{n}
|
self.Link("_done_{n}") // _done_{n}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (self *_Assembler) _asm_OP_check_empty(p *_Instr) {
|
||||||
|
rbracket := p.vb()
|
||||||
|
if rbracket == ']' {
|
||||||
|
self.check_eof(1)
|
||||||
|
self.Emit("LEAQ", jit.Ptr(_IC, 1), _AX) // LEAQ 1(IC), AX
|
||||||
|
self.Emit("CMPB", jit.Sib(_IP, _IC, 1, 0), jit.Imm(int64(rbracket))) // CMPB (IP)(IC), ']'
|
||||||
|
self.Sjmp("JNE" , "_not_empty_array_{n}") // JNE _not_empty_array_{n}
|
||||||
|
self.Emit("MOVQ", _AX, _IC) // MOVQ AX, IC
|
||||||
|
self.Emit("MOVQ", jit.Imm(_Zero_Base), jit.Ptr(_VP, 0)) // MOVQ $zerobase, (VP)
|
||||||
|
self.Xjmp("JMP" , p.vi()) // JMP {p.vi()}
|
||||||
|
self.Link("_not_empty_array_{n}")
|
||||||
|
} else {
|
||||||
|
panic("only implement check empty array here!")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
func (self *_Assembler) _asm_OP_slice_append(p *_Instr) {
|
func (self *_Assembler) _asm_OP_slice_append(p *_Instr) {
|
||||||
self.Emit("MOVQ" , jit.Ptr(_VP, 8), _AX) // MOVQ 8(VP), AX
|
self.Emit("MOVQ" , jit.Ptr(_VP, 8), _AX) // MOVQ 8(VP), AX
|
||||||
self.Emit("CMPQ" , _AX, jit.Ptr(_VP, 16)) // CMPQ AX, 16(VP)
|
self.Emit("CMPQ" , _AX, jit.Ptr(_VP, 16)) // CMPQ AX, 16(VP)
|
||||||
|
|
|
||||||
|
|
@ -98,6 +98,7 @@ const (
|
||||||
_OP_dismatch_err
|
_OP_dismatch_err
|
||||||
_OP_go_skip
|
_OP_go_skip
|
||||||
_OP_add
|
_OP_add
|
||||||
|
_OP_check_empty
|
||||||
_OP_debug
|
_OP_debug
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
@ -174,6 +175,9 @@ var _OpNames = [256]string {
|
||||||
_OP_check_char_0 : "check_char_0",
|
_OP_check_char_0 : "check_char_0",
|
||||||
_OP_dismatch_err : "dismatch_err",
|
_OP_dismatch_err : "dismatch_err",
|
||||||
_OP_add : "add",
|
_OP_add : "add",
|
||||||
|
_OP_go_skip : "go_skip",
|
||||||
|
_OP_check_empty : "check_empty",
|
||||||
|
_OP_debug : "debug",
|
||||||
}
|
}
|
||||||
|
|
||||||
func (self _Op) String() string {
|
func (self _Op) String() string {
|
||||||
|
|
@ -806,11 +810,11 @@ func (self *_Compiler) compileSliceList(p *_Program, sp int, vt reflect.Type) {
|
||||||
}
|
}
|
||||||
|
|
||||||
func (self *_Compiler) compileSliceBody(p *_Program, sp int, et reflect.Type) {
|
func (self *_Compiler) compileSliceBody(p *_Program, sp int, et reflect.Type) {
|
||||||
p.rtt(_OP_slice_init, et)
|
|
||||||
p.add(_OP_save)
|
|
||||||
p.add(_OP_lspace)
|
p.add(_OP_lspace)
|
||||||
j := p.pc()
|
j := p.pc()
|
||||||
p.chr(_OP_check_char, ']')
|
p.chr(_OP_check_empty, ']')
|
||||||
|
p.rtt(_OP_slice_init, et)
|
||||||
|
p.add(_OP_save)
|
||||||
p.rtt(_OP_slice_append, et)
|
p.rtt(_OP_slice_append, et)
|
||||||
self.compileOne(p, sp + 1, et)
|
self.compileOne(p, sp + 1, et)
|
||||||
p.add(_OP_load)
|
p.add(_OP_load)
|
||||||
|
|
@ -823,9 +827,9 @@ func (self *_Compiler) compileSliceBody(p *_Program, sp int, et reflect.Type) {
|
||||||
self.compileOne(p, sp + 1, et)
|
self.compileOne(p, sp + 1, et)
|
||||||
p.add(_OP_load)
|
p.add(_OP_load)
|
||||||
p.int(_OP_goto, k0)
|
p.int(_OP_goto, k0)
|
||||||
p.pin(j)
|
|
||||||
p.pin(k1)
|
p.pin(k1)
|
||||||
p.add(_OP_drop)
|
p.add(_OP_drop)
|
||||||
|
p.pin(j)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (self *_Compiler) compileString(p *_Program, vt reflect.Type) {
|
func (self *_Compiler) compileString(p *_Program, vt reflect.Type) {
|
||||||
|
|
|
||||||
|
|
@ -26,7 +26,7 @@ import (
|
||||||
)
|
)
|
||||||
|
|
||||||
const (
|
const (
|
||||||
_MinSlice = 16
|
_MinSlice = 2
|
||||||
_MaxStack = 4096 // 4k slots
|
_MaxStack = 4096 // 4k slots
|
||||||
_MaxStackBytes = _MaxStack * _PtrBytes
|
_MaxStackBytes = _MaxStack * _PtrBytes
|
||||||
_MaxDigitNums = 800 // used in atof fallback algorithm
|
_MaxDigitNums = 800 // used in atof fallback algorithm
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue