Skip to content

Commit

Permalink
encoder not force use VM
Browse files Browse the repository at this point in the history
  • Loading branch information
AsterDY committed May 28, 2024
1 parent 8d2e0d5 commit 7d9c287
Show file tree
Hide file tree
Showing 9 changed files with 93 additions and 160 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/compatibility_test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ jobs:
build:
strategy:
matrix:
go-version: [1.15.x, 1.16.x, 1.17.x, 1.18.x, 1.19.x, 1.20.x, 1.21.x, 1.22.x]
go-version: [1.16.x, 1.17.x, 1.18.x, 1.19.x, 1.20.x, 1.21.x, 1.22.x]
os: [arm, X64]
runs-on: ${{ matrix.os }}
steps:
Expand Down
4 changes: 0 additions & 4 deletions encoder/encoder_amd64.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,6 @@ import (
`github.com/bytedance/sonic/internal/encoder`
)

func init() {
encoder.ForceUseVM()
}

// EnableFallback indicates if encoder use fallback
const EnableFallback = false

Expand Down
32 changes: 32 additions & 0 deletions internal/rt/growslice.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,3 +29,35 @@ func GrowSlice(et *GoType, old GoSlice, cap int) GoSlice {
//go:linkname growslice runtime.growslice
//goland:noinspection GoUnusedParameter
func growslice(oldPtr unsafe.Pointer, newLen, oldCap, num int, et *GoType) GoSlice

//go:linkname makeslice runtime.makeslice
//goland:noinspection GoUnusedParameter
func makeslice(et *GoType, len int, cap int) unsafe.Pointer

func MakeSlice(oldPtr unsafe.Pointer, et *GoType, newLen int) *GoSlice {
if newLen == 0 {
return &GoSlice{
Ptr: ZSTPtr,
Len: 0,
Cap: 0,
}
}

if *(*unsafe.Pointer)(oldPtr) == nil {
return &GoSlice{
Ptr: makeslice(et, newLen, newLen),
Len: newLen,
Cap: newLen,
}
}

old := (*GoSlice)(oldPtr)
if old.Cap >= newLen {
old.Len = newLen
return old
}

new := GrowSlice(et, *old, newLen)
new.Len = newLen
return &new
}
34 changes: 33 additions & 1 deletion internal/rt/growslice_legacy.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,41 @@
package rt

import (
_ `unsafe`
`unsafe`
)

//go:linkname GrowSlice runtime.growslice
//goland:noinspection GoUnusedParameter
func GrowSlice(et *GoType, old GoSlice, cap int) GoSlice

//go:linkname makeslice runtime.makeslice
//goland:noinspection GoUnusedParameter
func makeslice(et *GoType, len int, cap int) unsafe.Pointer

func MakeSlice(oldPtr unsafe.Pointer, et *GoType, newLen int) *GoSlice {
if newLen == 0 {
return &GoSlice{
Ptr: ZSTPtr,
Len: 0,
Cap: 0,
}
}

if *(*unsafe.Pointer)(oldPtr) == nil {
return &GoSlice{
Ptr: makeslice(et, newLen, newLen),
Len: newLen,
Cap: newLen,
}
}

old := (*GoSlice)(oldPtr)
if old.Cap >= newLen {
old.Len = newLen
return old
}

new := GrowSlice(et, *old, newLen)
new.Len = newLen
return &new
}
16 changes: 16 additions & 0 deletions internal/rt/roundupsize_go122.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
//go:build go1.22 && !go1.23
// +build go1.22,!go1.23

package rt

import (
_ "unsafe"
)

//go:linkname rt_roundupsize runtime.roundupsize
func rt_roundupsize(size uintptr, noscan bool) uintptr

// a wrapper for fastmap
func roundupsize(size uintptr) uintptr {
return rt_roundupsize(size, MapType(MapEfaceType).Bucket.PtrData == 0)
}
11 changes: 11 additions & 0 deletions internal/rt/roundupsize_legacy.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
//go:build go1.16 && !go1.22
// +build go1.16,!go1.22

package rt

import (
_ "unsafe"
)

//go:linkname roundupsize runtime.roundupsize
func roundupsize(size uintptr) uintptr
58 changes: 0 additions & 58 deletions internal/rt/rt_stubs_go116.go

This file was deleted.

43 changes: 0 additions & 43 deletions internal/rt/rt_stubs_go120.go

This file was deleted.

53 changes: 0 additions & 53 deletions internal/rt/rt_stubs_go123.go

This file was deleted.

0 comments on commit 7d9c287

Please sign in to comment.