diff --git a/.github/workflows/benchmark-linux-arm64.yml b/.github/workflows/benchmark-linux-arm64.yml index 909d48a4a..8027e6077 100644 --- a/.github/workflows/benchmark-linux-arm64.yml +++ b/.github/workflows/benchmark-linux-arm64.yml @@ -11,9 +11,6 @@ jobs: - uses: actions/checkout@v2 - - name: Check Branch - run: ./check_branch_name.sh ${{ github.head_ref }} - - name: Set up Go uses: actions/setup-go@v2 with: @@ -27,4 +24,4 @@ jobs: ${{ runner.os }}-go- - name: Benchmark sonic - run: sh bench-arm.sh \ No newline at end of file + run: sh scripts/bench-arm.sh \ No newline at end of file diff --git a/.github/workflows/benchmark-linux-x64.yml b/.github/workflows/benchmark-linux-x64.yml index 4b3845679..41f271434 100644 --- a/.github/workflows/benchmark-linux-x64.yml +++ b/.github/workflows/benchmark-linux-x64.yml @@ -11,9 +11,6 @@ jobs: - uses: actions/checkout@v2 - - name: Check Branch - run: ./check_branch_name.sh ${{ github.head_ref }} - - name: Set up Go uses: actions/setup-go@v2 with: @@ -27,4 +24,4 @@ jobs: ${{ runner.os }}-go- - name: Benchmark sonic - run: sh bench.sh \ No newline at end of file + run: sh scripts/bench.sh \ No newline at end of file diff --git a/.github/workflows/push-check-windows.yml b/.github/workflows/compatibility_test-windows.yml similarity index 54% rename from .github/workflows/push-check-windows.yml rename to .github/workflows/compatibility_test-windows.yml index bcb20afb9..309f454ad 100644 --- a/.github/workflows/push-check-windows.yml +++ b/.github/workflows/compatibility_test-windows.yml @@ -1,4 +1,4 @@ -name: Push Check Windows-X64 +name: Compatibility Test Windows-X64 on: pull_request @@ -23,5 +23,18 @@ jobs: restore-keys: | ${{ runner.os }}-go- - - name: Compatibility Test - run: go test -v . + - name: main + run: | + set GOMAXPROCS=4 + go test -v -race github.com/bytedance/sonic + + - name: ast + run: | + set GOMAXPROCS=4 + go test -v -race github.com/bytedance/sonic/ast + + - name: external + run: | + cd ./external_jsonlib_test + set GOMAXPROCS=4 + go test -v -race ./... diff --git a/.github/workflows/push-check-linux-arm64.yml b/.github/workflows/compatibility_test.yml similarity index 75% rename from .github/workflows/push-check-linux-arm64.yml rename to .github/workflows/compatibility_test.yml index 45be72629..c474159cd 100644 --- a/.github/workflows/push-check-linux-arm64.yml +++ b/.github/workflows/compatibility_test.yml @@ -1,4 +1,4 @@ -name: Push Check Linux-ARM +name: Compatibility Test Linux-X64|ARM on: pull_request @@ -6,8 +6,8 @@ jobs: build: strategy: matrix: - go-version: [1.15.x, 1.16.x, 1.20.x] - os: [arm] + go-version: [1.15.x, 1.16.x, 1.17.x, 1.18.x, 1.19.x, 1.20.x] + os: [arm, X64] runs-on: ${{ matrix.os }} steps: - name: Clear repository @@ -27,8 +27,11 @@ jobs: restore-keys: | ${{ runner.os }}-go- - - name: Compatibility Test - main + - name: main run: GOMAXPROCS=4 go test -v -race github.com/bytedance/sonic - - name: Compatibility Test - ast + - name: ast run: GOMAXPROCS=4 go test -v -race github.com/bytedance/sonic/ast + + - name: qemu + run: sh scripts/qemu.sh \ No newline at end of file diff --git a/.github/workflows/fuzzing-linux-x64.yml b/.github/workflows/fuzzing-linux-x64.yml index 550210930..d7246b2f1 100644 --- a/.github/workflows/fuzzing-linux-x64.yml +++ b/.github/workflows/fuzzing-linux-x64.yml @@ -1,4 +1,4 @@ -name: Fuzz Linux-X64 +name: Fuzz Test Linux-X64 on: pull_request @@ -11,9 +11,6 @@ jobs: - uses: actions/checkout@v2 - - name: Check Branch - run: ./check_branch_name.sh ${{ github.head_ref }} - - name: Set up Go uses: actions/setup-go@v2 with: diff --git a/.github/workflows/push-check-go118.yml b/.github/workflows/generic_test.yml similarity index 75% rename from .github/workflows/push-check-go118.yml rename to .github/workflows/generic_test.yml index 7308fc78b..3ebe1a8dc 100644 --- a/.github/workflows/push-check-go118.yml +++ b/.github/workflows/generic_test.yml @@ -1,4 +1,4 @@ -name: Push Check Go1.18-Linux-X64 +name: Generic Test Go1.18-Linux-X64 on: pull_request @@ -23,10 +23,5 @@ jobs: restore-keys: | ${{ runner.os }}-go- - - name: Unit Test - run: | - GOMAXPROCS=4 go test -v -race ./... - GOMAXPROCS=4 go test -v -race ./external_jsonlib_test/... - - name: Generic Test run: GOMAXPROCS=4 go test -v -race ./generic_test \ No newline at end of file diff --git a/.github/workflows/go_latest_test.yml b/.github/workflows/go_latest_test.yml new file mode 100644 index 000000000..66b172007 --- /dev/null +++ b/.github/workflows/go_latest_test.yml @@ -0,0 +1,28 @@ +name: Unit Test Go-Latest-Linux-X64 + +on: push + +jobs: + build: + runs-on: [self-hosted, X64] + steps: + - name: Clear repository + run: sudo rm -fr $GITHUB_WORKSPACE && mkdir $GITHUB_WORKSPACE + + - uses: actions/checkout@v2 + + - name: Set up Go + uses: actions/setup-go@v2 + with: + go-version: 1.20.6 + + - uses: actions/cache@v2 + with: + path: ~/go/pkg/mod + key: ${{ runner.os }}-go-${{ hashFiles('**/go.sum') }} + restore-keys: | + ${{ runner.os }}-go- + + - name: script + run: | + sh ./scripts/go_latest.sh go1.21.0 diff --git a/.github/workflows/license-check.yml b/.github/workflows/license-check.yml index a2142dc1a..d27b33730 100644 --- a/.github/workflows/license-check.yml +++ b/.github/workflows/license-check.yml @@ -15,3 +15,6 @@ jobs: uses: apache/skywalking-eyes/header@v0.4.0 env: GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + + - name: Check Branch + run: ./scripts/check_branch_name.sh ${{ github.head_ref }} diff --git a/.github/workflows/push-check-qemu.yml b/.github/workflows/push-check-qemu.yml deleted file mode 100644 index fa144db54..000000000 --- a/.github/workflows/push-check-qemu.yml +++ /dev/null @@ -1,36 +0,0 @@ -name: Push Check Linux-Qemu - -on: pull_request - -jobs: - build: - strategy: - matrix: - go-version: [1.16.x, 1.20.x] - os: [arm] - runs-on: ${{ matrix.os }} - steps: - - name: Clear repository - run: sudo rm -fr $GITHUB_WORKSPACE && mkdir $GITHUB_WORKSPACE - - - uses: actions/checkout@v2 - - - name: Set up Go - uses: actions/setup-go@v2 - with: - go-version: ${{ matrix.go-version }} - - - uses: actions/cache@v2 - with: - path: ~/go/pkg/mod - key: ${{ runner.os }}-go-${{ hashFiles('**/go.sum') }} - restore-keys: | - ${{ runner.os }}-go- - - - name: Compatibility Test - qemu - run: | - printf ' #!/bin/bash\n if [ ! -x "/usr/bin/qemu-x86_64" ];then\n sudo apt-get update\n sudo apt-get -y install make gcc g++ libglib2.0-dev libpixman-1-dev libfdt-dev python3-pip ninja-build\n sudo pip3 install meson\n wget https://download.qemu.org/qemu-6.2.0.tar.xz\n tar -xvf qemu-6.2.0.tar.xz\n cd qemu-6.2.0\n sudo ./configure\n sudo make -j 4\n sudo make install\n cd ..\n cp /usr/local/bin/qemu-x86_64 /usr/bin/qemu-x86_64\n fi\n' > qemu_install.sh - chmod +x qemu_install.sh - ./qemu_install.sh - GOARCH=amd64 go test -c . - qemu-x86_64 -cpu max ./sonic.test -test.v \ No newline at end of file diff --git a/.github/workflows/push-check-linux-x64.yml b/.github/workflows/unit_test-linux-x64.yml similarity index 81% rename from .github/workflows/push-check-linux-x64.yml rename to .github/workflows/unit_test-linux-x64.yml index 2b2b434b1..b8fa87f55 100644 --- a/.github/workflows/push-check-linux-x64.yml +++ b/.github/workflows/unit_test-linux-x64.yml @@ -1,12 +1,12 @@ -name: Push Check Linux-X64 +name: Unit Test Linux-X64 -on: pull_request +on: push jobs: build: strategy: matrix: - go-version: [1.16.x, 1.17.x, 1.19.x, 1.20.x] + go-version: [1.16.x, 1.17.x, 1.18.x, 1.19.x, 1.20.x] runs-on: [self-hosted, X64] steps: - name: Clear repository @@ -31,8 +31,11 @@ jobs: - name: Unit Test run: | go test -race -covermode=atomic -coverprofile=coverage.txt ./... - cd ./external_jsonlib_test - go test -v ./... + - name: external + run: | + cd ./external_jsonlib_test + GOMAXPROCS=4 go test -v -race ./... + - name: Codecov run: bash <(curl -s https://codecov.io/bash) diff --git a/ast/api_amd64.go b/ast/api_amd64.go index a0f268448..da6738efd 100644 --- a/ast/api_amd64.go +++ b/ast/api_amd64.go @@ -1,4 +1,4 @@ -// +build amd64,go1.16,!go1.21 +// +build amd64,go1.16,!go1.22 /* * Copyright 2022 ByteDance Inc. diff --git a/ast/api_amd64_test.go b/ast/api_amd64_test.go index ee8a324bc..6b9354ac4 100644 --- a/ast/api_amd64_test.go +++ b/ast/api_amd64_test.go @@ -1,5 +1,4 @@ -//go:build amd64 && go1.16 && !go1.21 -// +build amd64,go1.16,!go1.21 +// +build amd64,go1.16,!go1.22 /* * Copyright 2022 ByteDance Inc. diff --git a/ast/api_compat.go b/ast/api_compat.go index 6a48786e7..7b475eb61 100644 --- a/ast/api_compat.go +++ b/ast/api_compat.go @@ -1,4 +1,4 @@ -// +build !amd64 !go1.16 go1.21 +// +build !amd64 !go1.16 go1.22 /* * Copyright 2022 ByteDance Inc. diff --git a/compat.go b/compat.go index 58b10d6a8..ec414c0cf 100644 --- a/compat.go +++ b/compat.go @@ -1,4 +1,4 @@ -// +build !amd64 !go1.16 go1.21 +// +build !amd64 !go1.16 go1.22 /* * Copyright 2021 ByteDance Inc. diff --git a/decode_float_test.go b/decode_float_test.go index c735ec5a4..ebc7f4c11 100644 --- a/decode_float_test.go +++ b/decode_float_test.go @@ -1,4 +1,4 @@ -// +build amd64,go1.16,!go1.21 +// +build amd64,go1.16,!go1.22 /* * Copyright 2021 ByteDance Inc. diff --git a/decode_test.go b/decode_test.go index 6f1bc7855..46830f6fc 100644 --- a/decode_test.go +++ b/decode_test.go @@ -1,4 +1,4 @@ -// +build amd64,go1.16,!go1.21 +// +build amd64,go1.16,!go1.22 /* * Copyright 2021 ByteDance Inc. diff --git a/decoder/decoder_amd64.go b/decoder/decoder_amd64.go index 3dc32a0af..7c2845514 100644 --- a/decoder/decoder_amd64.go +++ b/decoder/decoder_amd64.go @@ -1,4 +1,4 @@ -// +build amd64,go1.16,!go1.21 +// +build amd64,go1.16,!go1.22 /* * Copyright 2023 ByteDance Inc. diff --git a/decoder/decoder_amd64_test.go b/decoder/decoder_amd64_test.go index f24da896e..3284c4681 100644 --- a/decoder/decoder_amd64_test.go +++ b/decoder/decoder_amd64_test.go @@ -1,4 +1,4 @@ -// +build amd64,go1.16,!go1.21 +// +build amd64,go1.16,!go1.22 /* * Copyright 2021 ByteDance Inc. diff --git a/decoder/decoder_compat.go b/decoder/decoder_compat.go index d25b0dfea..466d842e8 100644 --- a/decoder/decoder_compat.go +++ b/decoder/decoder_compat.go @@ -1,5 +1,4 @@ -//go:build !amd64 || !go1.16 || go1.21 -// +build !amd64 !go1.16 go1.21 +// +build !amd64 !go1.16 go1.22 /* * Copyright 2023 ByteDance Inc. @@ -170,35 +169,13 @@ func Pretouch(vt reflect.Type, opts ...option.CompileOption) error { return nil } -type StreamDecoder struct { - r io.Reader - buf []byte - scanp int - scanned int64 - err error - Decoder -} +type StreamDecoder = json.Decoder // NewStreamDecoder adapts to encoding/json.NewDecoder API. // // NewStreamDecoder returns a new decoder that reads from r. func NewStreamDecoder(r io.Reader) *StreamDecoder { - return &StreamDecoder{r : r} -} - -// Decode decodes input stream into val with corresponding data. -// Redundantly bytes may be read and left in its buffer, and can be used at next call. -// Either io error from underlying io.Reader (except io.EOF) -// or syntax error from data will be recorded and stop subsequently decoding. -func (self *StreamDecoder) Decode(val interface{}) (err error) { - dec := json.NewDecoder(self.r) - if (self.f | uint64(OptionUseNumber)) != 0 { - dec.UseNumber() - } - if (self.f | uint64(OptionDisableUnknown)) != 0 { - dec.DisallowUnknownFields() - } - return dec.Decode(val) + return json.NewDecoder(r) } // SyntaxError represents json syntax error diff --git a/encode_test.go b/encode_test.go index 6c2d94eb6..88734cd4d 100644 --- a/encode_test.go +++ b/encode_test.go @@ -1,4 +1,4 @@ -// +build amd64,go1.16,!go1.21 +// +build amd64,go1.16,!go1.22 /* * Copyright 2021 ByteDance Inc. diff --git a/encoder/encoder_amd64.go b/encoder/encoder_amd64.go index cd137cec1..0ef336b72 100644 --- a/encoder/encoder_amd64.go +++ b/encoder/encoder_amd64.go @@ -1,4 +1,4 @@ -// +build amd64,go1.16,!go1.21 +// +build amd64,go1.16,!go1.22 /* * Copyright 2023 ByteDance Inc. diff --git a/encoder/encoder_amd64_test.go b/encoder/encoder_amd64_test.go index 657e2a725..56db9c3df 100644 --- a/encoder/encoder_amd64_test.go +++ b/encoder/encoder_amd64_test.go @@ -1,4 +1,4 @@ -// +build amd64,go1.16,!go1.21 +// +build amd64,go1.16,!go1.22 /* * Copyright 2021 ByteDance Inc. diff --git a/encoder/encoder_compat.go b/encoder/encoder_compat.go index 6d65c3db8..222eea5b2 100644 --- a/encoder/encoder_compat.go +++ b/encoder/encoder_compat.go @@ -1,4 +1,4 @@ -// +build !amd64 !go1.16 go1.21 +// +build !amd64 !go1.16 go1.22 /* * Copyright 2023 ByteDance Inc. @@ -216,23 +216,12 @@ func Valid(data []byte) (ok bool, start int) { } // StreamEncoder uses io.Writer as -type StreamEncoder struct { - w io.Writer - Encoder -} +type StreamEncoder = json.Encoder // NewStreamEncoder adapts to encoding/json.NewDecoder API. // // NewStreamEncoder returns a new encoder that write to w. func NewStreamEncoder(w io.Writer) *StreamEncoder { - return &StreamEncoder{w: w} + return json.NewEncoder(w) } -// Encode encodes interface{} as JSON to io.Writer -func (enc *StreamEncoder) Encode(val interface{}) (err error) { - jenc := json.NewEncoder(enc.w) - jenc.SetEscapeHTML((enc.Opts & EscapeHTML) != 0) - jenc.SetIndent(enc.prefix, enc.indent) - err = jenc.Encode(val) - return err -} diff --git a/external_jsonlib_test/go.mod b/external_jsonlib_test/go.mod index 9da75fd7b..98081e754 100644 --- a/external_jsonlib_test/go.mod +++ b/external_jsonlib_test/go.mod @@ -4,16 +4,17 @@ go 1.18 require ( github.com/buger/jsonparser v1.1.1 - github.com/bytedance/sonic v1.4.0 + github.com/bytedance/sonic v1.10.0-rc github.com/goccy/go-json v0.9.11 github.com/json-iterator/go v1.1.12 - github.com/stretchr/testify v1.8.0 + github.com/stretchr/testify v1.8.1 github.com/tidwall/gjson v1.14.3 github.com/tidwall/sjson v1.2.5 ) require ( - github.com/chenzhuoyu/base64x v0.0.0-20211019084208-fb5309c8db06 // indirect + github.com/chenzhuoyu/base64x v0.0.0-20230717121745-296ad89f973d // indirect + github.com/chenzhuoyu/iasm v0.9.0 // indirect github.com/davecgh/go-spew v1.1.1 // indirect github.com/klauspost/cpuid/v2 v2.0.9 // indirect github.com/modern-go/concurrent v0.0.0-20180228061459-e0a39a4cb421 // indirect @@ -25,3 +26,5 @@ require ( golang.org/x/arch v0.0.0-20210923205945-b76863e36670 // indirect gopkg.in/yaml.v3 v3.0.1 // indirect ) + +replace github.com/bytedance/sonic => ../. diff --git a/external_jsonlib_test/go.sum b/external_jsonlib_test/go.sum index de08058d0..c0406d53e 100644 --- a/external_jsonlib_test/go.sum +++ b/external_jsonlib_test/go.sum @@ -1,13 +1,12 @@ github.com/buger/jsonparser v1.1.1 h1:2PnMjfWD7wBILjqQbt530v576A/cAbQvEW9gGIpYMUs= github.com/buger/jsonparser v1.1.1/go.mod h1:6RYKKt7H4d4+iWqouImQ9R2FZql3VbhNgx27UK13J/0= -github.com/bytedance/sonic v1.4.0 h1:d6vgPhwgHfpmEiz/9Fzea9fGzWY7RO1TQEySBiRwDLY= -github.com/bytedance/sonic v1.4.0/go.mod h1:V973WhNhGmvHxW6nQmsHEfHaoU9F3zTF+93rH03hcUQ= -github.com/chenzhuoyu/base64x v0.0.0-20211019084208-fb5309c8db06 h1:1sDoSuDPWzhkdzNVxCxtIaKiAe96ESVPv8coGwc1gZ4= -github.com/chenzhuoyu/base64x v0.0.0-20211019084208-fb5309c8db06/go.mod h1:DH46F32mSOjUmXrMHnKwZdA8wcEefY7UVqBKYGjpdQY= +github.com/chenzhuoyu/base64x v0.0.0-20230717121745-296ad89f973d h1:77cEq6EriyTZ0g/qfRdp61a3Uu/AWrgIq2s0ClJV1g0= +github.com/chenzhuoyu/base64x v0.0.0-20230717121745-296ad89f973d/go.mod h1:8EPpVsBuRksnlj1mLy4AWzRNQYxauNi62uWcE3to6eA= +github.com/chenzhuoyu/iasm v0.9.0 h1:9fhXjVzq5hUy2gkhhgHl95zG2cEAhw9OSGs8toWWAwo= +github.com/chenzhuoyu/iasm v0.9.0/go.mod h1:Xjy2NpN3h7aUqeqM+woSuuvxmIe6+DDsiNLIrkAmYog= github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c= github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= -github.com/goccy/go-json v0.9.4/go.mod h1:6MelG93GURQebXPDq3khkgXZkazVtN9CRI+MGFi0w8I= github.com/goccy/go-json v0.9.11 h1:/pAaQDLHEoCq/5FFmSKBswWmK6H0e8g4159Kc/X/nqk= github.com/goccy/go-json v0.9.11/go.mod h1:6MelG93GURQebXPDq3khkgXZkazVtN9CRI+MGFi0w8I= github.com/google/gofuzz v1.0.0/go.mod h1:dBl0BpW6vV/+mYPU4Po3pmUjxk6FQPldtuIdl/M65Eg= @@ -15,6 +14,7 @@ github.com/json-iterator/go v1.1.12 h1:PV8peI4a0ysnczrg+LtxykD8LfKY9ML6u2jnxaEnr github.com/json-iterator/go v1.1.12/go.mod h1:e30LSqwooZae/UwlEbR2852Gd8hjQvJoHmT4TnhNGBo= github.com/klauspost/cpuid/v2 v2.0.9 h1:lgaqFMSdTdQYdZ04uHyN2d/eKdOMyi2YLSvlQIBFYa4= github.com/klauspost/cpuid/v2 v2.0.9/go.mod h1:FInQzS24/EEf25PyTYn52gqo7WaD8xa0213Md/qVLRg= +github.com/knz/go-libedit v1.10.1/go.mod h1:MZTVkCWyz0oBc7JOWP3wNAzd002ZbM/5hgShxwh4x8M= github.com/modern-go/concurrent v0.0.0-20180228061459-e0a39a4cb421 h1:ZqeYNhU3OHLH3mGKHDcjJRFFRrJa6eAM5H+CtDdOsPc= github.com/modern-go/concurrent v0.0.0-20180228061459-e0a39a4cb421/go.mod h1:6dJC0mAP4ikYIbvyc7fijjWJddQyLn8Ig3JB5CqoB9Q= github.com/modern-go/reflect2 v1.0.2 h1:xBagoLtFs94CBntxluKeaWgTMpvLxC4ur3nMaC9Gz0M= @@ -23,13 +23,13 @@ github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZb github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4= github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME= github.com/stretchr/objx v0.4.0/go.mod h1:YvHI0jy2hoMjB+UWwv71VJQ9isScKT/TqJzVSSt89Yw= +github.com/stretchr/objx v0.5.0/go.mod h1:Yh+to48EsGEfYuaHDzXPcE3xhTkx73EhmCGUpEOglKo= github.com/stretchr/testify v1.3.0/go.mod h1:M5WIy9Dh21IEIfnGCwXGc5bZfKNJtfHm1UVUgZn+9EI= github.com/stretchr/testify v1.7.0/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg= github.com/stretchr/testify v1.7.1/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg= -github.com/stretchr/testify v1.8.0 h1:pSgiaMZlXftHpm5L7V1+rVB+AZJydKsMxsQBIJw4PKk= github.com/stretchr/testify v1.8.0/go.mod h1:yNjHg4UonilssWZ8iaSj1OCr/vHnekPRkoO+kdMU+MU= -github.com/tidwall/gjson v1.12.1/go.mod h1:/wbyibRr2FHMks5tjHJ5F8dMZh3AcwJEMf5vlfC0lxk= -github.com/tidwall/gjson v1.13.0/go.mod h1:/wbyibRr2FHMks5tjHJ5F8dMZh3AcwJEMf5vlfC0lxk= +github.com/stretchr/testify v1.8.1 h1:w7B6lhMri9wdJUVmEZPGGhZzrYTPvgJArz7wNPgYKsk= +github.com/stretchr/testify v1.8.1/go.mod h1:w2LPCIKwWwSfY2zedu0+kehJoqGctiVI29o6fzry7u4= github.com/tidwall/gjson v1.14.2/go.mod h1:/wbyibRr2FHMks5tjHJ5F8dMZh3AcwJEMf5vlfC0lxk= github.com/tidwall/gjson v1.14.3 h1:9jvXn7olKEHU1S9vwoMGliaT8jq1vJ7IH/n9zD9Dnlw= github.com/tidwall/gjson v1.14.3/go.mod h1:/wbyibRr2FHMks5tjHJ5F8dMZh3AcwJEMf5vlfC0lxk= @@ -37,7 +37,6 @@ github.com/tidwall/match v1.1.1 h1:+Ho715JplO36QYgwN9PGYNhgZvoUSc9X2c80KVTi+GA= github.com/tidwall/match v1.1.1/go.mod h1:eRSPERbgtNPcGhD8UCthc6PmLEQXEWd3PRB5JTxsfmM= github.com/tidwall/pretty v1.2.0 h1:RWIZEg2iJ8/g6fDDYzMpobmaoGh5OLl4AXtGUGPcqCs= github.com/tidwall/pretty v1.2.0/go.mod h1:ITEVvHYasfjBbM0u2Pg8T2nJnzm8xPwvNhhsoaGGjNU= -github.com/tidwall/sjson v1.2.4/go.mod h1:098SZ494YoMWPmMO6ct4dcFnqxwj9r/gF0Etp19pSNM= github.com/tidwall/sjson v1.2.5 h1:kLy8mja+1c9jlljvWTlSazM7cKDRfJuR/bOJhcY5NcY= github.com/tidwall/sjson v1.2.5/go.mod h1:Fvgq9kS/6ociJEDnK0Fk1cpYF4FIW6ZF7LAe+6jwd28= github.com/twitchyliquid64/golang-asm v0.15.1 h1:SU5vSMR7hnwNxj24w34ZyCi/FmDZTkS4MhqMhdFk5YI= @@ -49,4 +48,5 @@ gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8 gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM= gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA= gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM= +nullprogram.com/x/optparse v1.0.0/go.mod h1:KdyPE+Igbe0jQUrVfMqDMeJQIJZEuyV7pjYmp6pbG50= rsc.io/pdf v0.1.1/go.mod h1:n8OzWcQ6Sp37PL01nO98y4iUCRdTGarVfzxY20ICaU4= diff --git a/fuzz/go.mod b/fuzz/go.mod index eeb666d86..a2e66f559 100644 --- a/fuzz/go.mod +++ b/fuzz/go.mod @@ -4,13 +4,14 @@ go 1.18 require ( github.com/bytedance/gopkg v0.0.0-20221122125632-68358b8ecec6 - github.com/bytedance/sonic v1.5.0 + github.com/bytedance/sonic v1.10.0-rc github.com/davecgh/go-spew v1.1.1 github.com/stretchr/testify v1.8.1 ) require ( - github.com/chenzhuoyu/base64x v0.0.0-20221115062448-fe3a3abad311 // indirect + github.com/chenzhuoyu/base64x v0.0.0-20230717121745-296ad89f973d // indirect + github.com/chenzhuoyu/iasm v0.9.0 // indirect github.com/klauspost/cpuid/v2 v2.0.9 // indirect github.com/pmezard/go-difflib v1.0.0 // indirect github.com/twitchyliquid64/golang-asm v0.15.1 // indirect diff --git a/fuzz/go.sum b/fuzz/go.sum index 8ff686334..df0ddd776 100644 --- a/fuzz/go.sum +++ b/fuzz/go.sum @@ -1,12 +1,15 @@ github.com/bytedance/gopkg v0.0.0-20221122125632-68358b8ecec6 h1:FCLDGi1EmB7JzjVVYNZiqc/zAJj2BQ5M0lfkVOxbfs8= github.com/bytedance/gopkg v0.0.0-20221122125632-68358b8ecec6/go.mod h1:5FoAH5xUHHCMDvQPy1rnj8moqLkLHFaDVBjHhcFwEi0= -github.com/chenzhuoyu/base64x v0.0.0-20221115062448-fe3a3abad311 h1:qSGYFH7+jGhDF8vLC+iwCD4WpbV1EBDSzWkJODFLams= -github.com/chenzhuoyu/base64x v0.0.0-20221115062448-fe3a3abad311/go.mod h1:b583jCggY9gE99b6G5LEC39OIiVsWj+R97kbl5odCEk= +github.com/chenzhuoyu/base64x v0.0.0-20230717121745-296ad89f973d h1:77cEq6EriyTZ0g/qfRdp61a3Uu/AWrgIq2s0ClJV1g0= +github.com/chenzhuoyu/base64x v0.0.0-20230717121745-296ad89f973d/go.mod h1:8EPpVsBuRksnlj1mLy4AWzRNQYxauNi62uWcE3to6eA= +github.com/chenzhuoyu/iasm v0.9.0 h1:9fhXjVzq5hUy2gkhhgHl95zG2cEAhw9OSGs8toWWAwo= +github.com/chenzhuoyu/iasm v0.9.0/go.mod h1:Xjy2NpN3h7aUqeqM+woSuuvxmIe6+DDsiNLIrkAmYog= github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c= github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= github.com/klauspost/cpuid/v2 v2.0.9 h1:lgaqFMSdTdQYdZ04uHyN2d/eKdOMyi2YLSvlQIBFYa4= github.com/klauspost/cpuid/v2 v2.0.9/go.mod h1:FInQzS24/EEf25PyTYn52gqo7WaD8xa0213Md/qVLRg= +github.com/knz/go-libedit v1.10.1/go.mod h1:MZTVkCWyz0oBc7JOWP3wNAzd002ZbM/5hgShxwh4x8M= github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM= github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4= github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME= @@ -28,4 +31,5 @@ gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8 gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM= gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA= gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM= +nullprogram.com/x/optparse v1.0.0/go.mod h1:KdyPE+Igbe0jQUrVfMqDMeJQIJZEuyV7pjYmp6pbG50= rsc.io/pdf v0.1.1/go.mod h1:n8OzWcQ6Sp37PL01nO98y4iUCRdTGarVfzxY20ICaU4= diff --git a/internal/decoder/asm_stubs_amd64_go116.go b/internal/decoder/asm_stubs_amd64_go116.go new file mode 100644 index 000000000..4c4c850ac --- /dev/null +++ b/internal/decoder/asm_stubs_amd64_go116.go @@ -0,0 +1,130 @@ +// +build go1.16,!go1.17 + +// Copyright 2023 CloudWeGo Authors +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +package decoder + +import ( + `strconv` + _ `unsafe` + + `github.com/bytedance/sonic/internal/jit` + `github.com/bytedance/sonic/internal/rt` + `github.com/twitchyliquid64/golang-asm/obj` + `github.com/twitchyliquid64/golang-asm/obj/x86` +) + +var _runtime_writeBarrier uintptr = rt.GcwbAddr() + +//go:linkname gcWriteBarrierAX runtime.gcWriteBarrier +func gcWriteBarrierAX() + +var ( + _V_writeBarrier = jit.Imm(int64(_runtime_writeBarrier)) + + _F_gcWriteBarrierAX = jit.Func(gcWriteBarrierAX) +) + +func (self *_Assembler) WritePtrAX(i int, rec obj.Addr, saveDI bool) { + self.Emit("MOVQ", _V_writeBarrier, _R10) + self.Emit("CMPL", jit.Ptr(_R10, 0), jit.Imm(0)) + self.Sjmp("JE", "_no_writeBarrier" + strconv.Itoa(i) + "_{n}") + if saveDI { + self.save(_DI) + } + self.Emit("LEAQ", rec, _DI) + self.Emit("MOVQ", _F_gcWriteBarrierAX, _R10) // MOVQ ${fn}, AX + self.Rjmp("CALL", _R10) + if saveDI { + self.load(_DI) + } + self.Sjmp("JMP", "_end_writeBarrier" + strconv.Itoa(i) + "_{n}") + self.Link("_no_writeBarrier" + strconv.Itoa(i) + "_{n}") + self.Emit("MOVQ", _AX, rec) + self.Link("_end_writeBarrier" + strconv.Itoa(i) + "_{n}") +} + +func (self *_Assembler) WriteRecNotAX(i int, ptr obj.Addr, rec obj.Addr, saveDI bool, saveAX bool) { + if rec.Reg == x86.REG_AX || rec.Index == x86.REG_AX { + panic("rec contains AX!") + } + self.Emit("MOVQ", _V_writeBarrier, _R10) + self.Emit("CMPL", jit.Ptr(_R10, 0), jit.Imm(0)) + self.Sjmp("JE", "_no_writeBarrier" + strconv.Itoa(i) + "_{n}") + if saveAX { + self.Emit("XCHGQ", ptr, _AX) + } else { + self.Emit("MOVQ", ptr, _AX) + } + if saveDI { + self.save(_DI) + } + self.Emit("LEAQ", rec, _DI) + self.Emit("MOVQ", _F_gcWriteBarrierAX, _R10) // MOVQ ${fn}, AX + self.Rjmp("CALL", _R10) + if saveDI { + self.load(_DI) + } + if saveAX { + self.Emit("XCHGQ", ptr, _AX) + } + self.Sjmp("JMP", "_end_writeBarrier" + strconv.Itoa(i) + "_{n}") + self.Link("_no_writeBarrier" + strconv.Itoa(i) + "_{n}") + self.Emit("MOVQ", ptr, rec) + self.Link("_end_writeBarrier" + strconv.Itoa(i) + "_{n}") +} + + +func (self *_ValueDecoder) WritePtrAX(i int, rec obj.Addr, saveDI bool) { + self.Emit("MOVQ", _V_writeBarrier, _R10) + self.Emit("CMPL", jit.Ptr(_R10, 0), jit.Imm(0)) + self.Sjmp("JE", "_no_writeBarrier" + strconv.Itoa(i) + "_{n}") + if saveDI { + self.save(_DI) + } + self.Emit("LEAQ", rec, _DI) + self.Emit("MOVQ", _F_gcWriteBarrierAX, _R10) // MOVQ ${fn}, AX + self.Rjmp("CALL", _R10) + if saveDI { + self.load(_DI) + } + self.Sjmp("JMP", "_end_writeBarrier" + strconv.Itoa(i) + "_{n}") + self.Link("_no_writeBarrier" + strconv.Itoa(i) + "_{n}") + self.Emit("MOVQ", _AX, rec) + self.Link("_end_writeBarrier" + strconv.Itoa(i) + "_{n}") +} + +func (self *_ValueDecoder) WriteRecNotAX(i int, ptr obj.Addr, rec obj.Addr, saveDI bool) { + if rec.Reg == x86.REG_AX || rec.Index == x86.REG_AX { + panic("rec contains AX!") + } + self.Emit("MOVQ", _V_writeBarrier, _R10) + self.Emit("CMPL", jit.Ptr(_R10, 0), jit.Imm(0)) + self.Sjmp("JE", "_no_writeBarrier" + strconv.Itoa(i) + "_{n}") + self.Emit("MOVQ", ptr, _AX) + if saveDI { + self.save(_DI) + } + self.Emit("LEAQ", rec, _DI) + self.Emit("MOVQ", _F_gcWriteBarrierAX, _R10) // MOVQ ${fn}, AX + self.Rjmp("CALL", _R10) + if saveDI { + self.load(_DI) + } + self.Sjmp("JMP", "_end_writeBarrier" + strconv.Itoa(i) + "_{n}") + self.Link("_no_writeBarrier" + strconv.Itoa(i) + "_{n}") + self.Emit("MOVQ", ptr, rec) + self.Link("_end_writeBarrier" + strconv.Itoa(i) + "_{n}") +} diff --git a/internal/decoder/asm_stubs_amd64_go117.go b/internal/decoder/asm_stubs_amd64_go117.go new file mode 100644 index 000000000..b0125a792 --- /dev/null +++ b/internal/decoder/asm_stubs_amd64_go117.go @@ -0,0 +1,126 @@ +// +build go1.17,!go1.21 + +// Copyright 2023 CloudWeGo Authors +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +package decoder + +import ( + `strconv` + `unsafe` + + `github.com/bytedance/sonic/internal/jit` + `github.com/twitchyliquid64/golang-asm/obj` + `github.com/twitchyliquid64/golang-asm/obj/x86` +) + +//go:linkname _runtime_writeBarrier runtime.writeBarrier +var _runtime_writeBarrier uintptr + +//go:linkname gcWriteBarrierAX runtime.gcWriteBarrier +func gcWriteBarrierAX() + +var ( + _V_writeBarrier = jit.Imm(int64(uintptr(unsafe.Pointer(&_runtime_writeBarrier)))) + + _F_gcWriteBarrierAX = jit.Func(gcWriteBarrierAX) +) + +func (self *_Assembler) WritePtrAX(i int, rec obj.Addr, saveDI bool) { + self.Emit("MOVQ", _V_writeBarrier, _R9) + self.Emit("CMPL", jit.Ptr(_R9, 0), jit.Imm(0)) + self.Sjmp("JE", "_no_writeBarrier" + strconv.Itoa(i) + "_{n}") + if saveDI { + self.save(_DI) + } + self.Emit("LEAQ", rec, _DI) + self.call(_F_gcWriteBarrierAX) + if saveDI { + self.load(_DI) + } + self.Sjmp("JMP", "_end_writeBarrier" + strconv.Itoa(i) + "_{n}") + self.Link("_no_writeBarrier" + strconv.Itoa(i) + "_{n}") + self.Emit("MOVQ", _AX, rec) + self.Link("_end_writeBarrier" + strconv.Itoa(i) + "_{n}") +} + +func (self *_Assembler) WriteRecNotAX(i int, ptr obj.Addr, rec obj.Addr, saveDI bool, saveAX bool) { + if rec.Reg == x86.REG_AX || rec.Index == x86.REG_AX { + panic("rec contains AX!") + } + self.Emit("MOVQ", _V_writeBarrier, _R9) + self.Emit("CMPL", jit.Ptr(_R9, 0), jit.Imm(0)) + self.Sjmp("JE", "_no_writeBarrier" + strconv.Itoa(i) + "_{n}") + if saveAX { + self.Emit("XCHGQ", ptr, _AX) + } else { + self.Emit("MOVQ", ptr, _AX) + } + if saveDI { + self.save(_DI) + } + self.Emit("LEAQ", rec, _DI) + self.call(_F_gcWriteBarrierAX) + if saveDI { + self.load(_DI) + } + if saveAX { + self.Emit("XCHGQ", ptr, _AX) + } + self.Sjmp("JMP", "_end_writeBarrier" + strconv.Itoa(i) + "_{n}") + self.Link("_no_writeBarrier" + strconv.Itoa(i) + "_{n}") + self.Emit("MOVQ", ptr, rec) + self.Link("_end_writeBarrier" + strconv.Itoa(i) + "_{n}") +} + + +func (self *_ValueDecoder) WritePtrAX(i int, rec obj.Addr, saveDI bool) { + self.Emit("MOVQ", _V_writeBarrier, _R9) + self.Emit("CMPL", jit.Ptr(_R9, 0), jit.Imm(0)) + self.Sjmp("JE", "_no_writeBarrier" + strconv.Itoa(i) + "_{n}") + if saveDI { + self.save(_DI) + } + self.Emit("LEAQ", rec, _DI) + self.call(_F_gcWriteBarrierAX) + if saveDI { + self.load(_DI) + } + self.Sjmp("JMP", "_end_writeBarrier" + strconv.Itoa(i) + "_{n}") + self.Link("_no_writeBarrier" + strconv.Itoa(i) + "_{n}") + self.Emit("MOVQ", _AX, rec) + self.Link("_end_writeBarrier" + strconv.Itoa(i) + "_{n}") +} + +func (self *_ValueDecoder) WriteRecNotAX(i int, ptr obj.Addr, rec obj.Addr, saveDI bool) { + if rec.Reg == x86.REG_AX || rec.Index == x86.REG_AX { + panic("rec contains AX!") + } + self.Emit("MOVQ", _V_writeBarrier, _AX) + self.Emit("CMPL", jit.Ptr(_AX, 0), jit.Imm(0)) + self.Sjmp("JE", "_no_writeBarrier" + strconv.Itoa(i) + "_{n}") + self.Emit("MOVQ", ptr, _AX) + if saveDI { + self.save(_DI) + } + self.Emit("LEAQ", rec, _DI) + self.call(_F_gcWriteBarrierAX) + if saveDI { + self.load(_DI) + } + self.Sjmp("JMP", "_end_writeBarrier" + strconv.Itoa(i) + "_{n}") + self.Link("_no_writeBarrier" + strconv.Itoa(i) + "_{n}") + self.Emit("MOVQ", ptr, rec) + self.Link("_end_writeBarrier" + strconv.Itoa(i) + "_{n}") +} diff --git a/internal/decoder/asm_stubs_amd64_go121.go b/internal/decoder/asm_stubs_amd64_go121.go new file mode 100644 index 000000000..018892f59 --- /dev/null +++ b/internal/decoder/asm_stubs_amd64_go121.go @@ -0,0 +1,133 @@ +// +build go1.21,!go1.22 + +// Copyright 2023 CloudWeGo Authors +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +package decoder + +import ( + `strconv` + `unsafe` + + `github.com/bytedance/sonic/internal/jit` + `github.com/twitchyliquid64/golang-asm/obj` + `github.com/twitchyliquid64/golang-asm/obj/x86` +) + +//go:linkname _runtime_writeBarrier runtime.writeBarrier +var _runtime_writeBarrier uintptr + +//go:nosplit +//go:linkname gcWriteBarrier2 runtime.gcWriteBarrier2 +func gcWriteBarrier2() + +// Notice: gcWriteBarrier must use R11 register!! +var _R11 = _IC + +var ( + _V_writeBarrier = jit.Imm(int64(uintptr(unsafe.Pointer(&_runtime_writeBarrier)))) + + _F_gcWriteBarrier2 = jit.Func(gcWriteBarrier2) +) + +func (self *_Assembler) WritePtrAX(i int, rec obj.Addr, saveDI bool) { + self.Emit("MOVQ", _V_writeBarrier, _R9) + self.Emit("CMPL", jit.Ptr(_R9, 0), jit.Imm(0)) + self.Sjmp("JE", "_no_writeBarrier" + strconv.Itoa(i) + "_{n}") + if saveDI { + self.save(_DI, _R11) + } else { + self.save(_R11) + } + self.Emit("MOVQ", _F_gcWriteBarrier2, _R11) + self.Rjmp("CALL", _R11) + self.Emit("MOVQ", _AX, jit.Ptr(_R11, 0)) + self.Emit("MOVQ", rec, _DI) + self.Emit("MOVQ", _DI, jit.Ptr(_R11, 8)) + if saveDI { + self.load(_DI, _R11) + } else { + self.load(_R11) + } + self.Link("_no_writeBarrier" + strconv.Itoa(i) + "_{n}") + self.Emit("MOVQ", _AX, rec) +} + +func (self *_Assembler) WriteRecNotAX(i int, ptr obj.Addr, rec obj.Addr, saveDI bool, saveAX bool) { + if rec.Reg == x86.REG_AX || rec.Index == x86.REG_AX { + panic("rec contains AX!") + } + self.Emit("MOVQ", _V_writeBarrier, _R9) + self.Emit("CMPL", jit.Ptr(_R9, 0), jit.Imm(0)) + self.Sjmp("JE", "_no_writeBarrier" + strconv.Itoa(i) + "_{n}") + if saveAX { + self.save(_AX, _R11) + } else { + self.save(_R11) + } + self.Emit("MOVQ", _F_gcWriteBarrier2, _R11) + self.Rjmp("CALL", _R11) + self.Emit("MOVQ", ptr, jit.Ptr(_R11, 0)) + self.Emit("MOVQ", rec, _AX) + self.Emit("MOVQ", _AX, jit.Ptr(_R11, 8)) + self.load(_R11) + if saveAX { + self.load(_AX, _R11) + } else { + self.load(_R11) + } + self.Link("_no_writeBarrier" + strconv.Itoa(i) + "_{n}") + self.Emit("MOVQ", ptr, rec) +} + +func (self *_ValueDecoder) WritePtrAX(i int, rec obj.Addr, saveDI bool) { + self.Emit("MOVQ", _V_writeBarrier, _R9) + self.Emit("CMPL", jit.Ptr(_R9, 0), jit.Imm(0)) + self.Sjmp("JE", "_no_writeBarrier" + strconv.Itoa(i) + "_{n}") + if saveDI { + self.save(_DI, _R11) + } else { + self.save(_R11) + } + self.Emit("MOVQ", _F_gcWriteBarrier2, _R11) + self.Rjmp("CALL", _R11) + self.Emit("MOVQ", _AX, jit.Ptr(_R11, 0)) + self.Emit("MOVQ", rec, _DI) + self.Emit("MOVQ", _DI, jit.Ptr(_R11, 8)) + if saveDI { + self.load(_DI, _R11) + } else { + self.load(_R11) + } + self.Link("_no_writeBarrier" + strconv.Itoa(i) + "_{n}") + self.Emit("MOVQ", _AX, rec) +} + +func (self *_ValueDecoder) WriteRecNotAX(i int, ptr obj.Addr, rec obj.Addr, saveDI bool) { + if rec.Reg == x86.REG_AX || rec.Index == x86.REG_AX { + panic("rec contains AX!") + } + self.Emit("MOVQ", _V_writeBarrier, _AX) + self.Emit("CMPL", jit.Ptr(_AX, 0), jit.Imm(0)) + self.Sjmp("JE", "_no_writeBarrier" + strconv.Itoa(i) + "_{n}") + self.save(_R11) + self.Emit("MOVQ", _F_gcWriteBarrier2, _R11) + self.Rjmp("CALL", _R11) + self.Emit("MOVQ", ptr, jit.Ptr(_R11, 0)) + self.Emit("MOVQ", rec, _AX) + self.Emit("MOVQ", _AX, jit.Ptr(_R11, 8)) + self.load(_R11) + self.Link("_no_writeBarrier" + strconv.Itoa(i) + "_{n}") + self.Emit("MOVQ", ptr, rec) +} \ No newline at end of file diff --git a/internal/decoder/assembler_amd64_go117.go b/internal/decoder/assembler_regabi_amd64.go similarity index 97% rename from internal/decoder/assembler_amd64_go117.go rename to internal/decoder/assembler_regabi_amd64.go index a6874a6fa..3d223e14e 100644 --- a/internal/decoder/assembler_amd64_go117.go +++ b/internal/decoder/assembler_regabi_amd64.go @@ -1,5 +1,5 @@ -//go:build go1.17 && !go1.21 -// +build go1.17,!go1.21 +//go:build go1.17 && !go1.22 +// +build go1.17,!go1.22 /* * Copyright 2021 ByteDance Inc. @@ -24,7 +24,6 @@ import ( `fmt` `math` `reflect` - `strconv` `unsafe` `github.com/bytedance/sonic/internal/caching` @@ -33,7 +32,6 @@ import ( `github.com/bytedance/sonic/internal/native/types` `github.com/bytedance/sonic/internal/rt` `github.com/twitchyliquid64/golang-asm/obj` - `github.com/twitchyliquid64/golang-asm/obj/x86` ) /** Register Allocations @@ -1929,62 +1927,3 @@ func (self *_Assembler) print_gc(i int, p1 *_Instr, p2 *_Instr) { self.Emit("MOVQ", jit.Imm(int64(i)), _AX) // MOVQ $(i), (SP) self.call_go(_F_println) } - -//go:linkname _runtime_writeBarrier runtime.writeBarrier -var _runtime_writeBarrier uintptr - -//go:linkname gcWriteBarrierAX runtime.gcWriteBarrier -func gcWriteBarrierAX() - -var ( - _V_writeBarrier = jit.Imm(int64(uintptr(unsafe.Pointer(&_runtime_writeBarrier)))) - - _F_gcWriteBarrierAX = jit.Func(gcWriteBarrierAX) -) - -func (self *_Assembler) WritePtrAX(i int, rec obj.Addr, saveDI bool) { - self.Emit("MOVQ", _V_writeBarrier, _R9) - self.Emit("CMPL", jit.Ptr(_R9, 0), jit.Imm(0)) - self.Sjmp("JE", "_no_writeBarrier" + strconv.Itoa(i) + "_{n}") - if saveDI { - self.save(_DI) - } - self.Emit("LEAQ", rec, _DI) - self.call(_F_gcWriteBarrierAX) - if saveDI { - self.load(_DI) - } - self.Sjmp("JMP", "_end_writeBarrier" + strconv.Itoa(i) + "_{n}") - self.Link("_no_writeBarrier" + strconv.Itoa(i) + "_{n}") - self.Emit("MOVQ", _AX, rec) - self.Link("_end_writeBarrier" + strconv.Itoa(i) + "_{n}") -} - -func (self *_Assembler) WriteRecNotAX(i int, ptr obj.Addr, rec obj.Addr, saveDI bool, saveAX bool) { - if rec.Reg == x86.REG_AX || rec.Index == x86.REG_AX { - panic("rec contains AX!") - } - self.Emit("MOVQ", _V_writeBarrier, _R9) - self.Emit("CMPL", jit.Ptr(_R9, 0), jit.Imm(0)) - self.Sjmp("JE", "_no_writeBarrier" + strconv.Itoa(i) + "_{n}") - if saveAX { - self.Emit("XCHGQ", ptr, _AX) - } else { - self.Emit("MOVQ", ptr, _AX) - } - if saveDI { - self.save(_DI) - } - self.Emit("LEAQ", rec, _DI) - self.call(_F_gcWriteBarrierAX) - if saveDI { - self.load(_DI) - } - if saveAX { - self.Emit("XCHGQ", ptr, _AX) - } - self.Sjmp("JMP", "_end_writeBarrier" + strconv.Itoa(i) + "_{n}") - self.Link("_no_writeBarrier" + strconv.Itoa(i) + "_{n}") - self.Emit("MOVQ", ptr, rec) - self.Link("_end_writeBarrier" + strconv.Itoa(i) + "_{n}") -} diff --git a/internal/decoder/assembler_amd64_go116.go b/internal/decoder/assembler_stkabi_amd64.go similarity index 97% rename from internal/decoder/assembler_amd64_go116.go rename to internal/decoder/assembler_stkabi_amd64.go index 7a2285a07..57a38b420 100644 --- a/internal/decoder/assembler_amd64_go116.go +++ b/internal/decoder/assembler_stkabi_amd64.go @@ -1,4 +1,4 @@ -// +build go1.15,!go1.17 +// +build go1.16,!go1.17 /* * Copyright 2021 ByteDance Inc. @@ -23,7 +23,6 @@ import ( `fmt` `math` `reflect` - `strconv` `unsafe` `github.com/bytedance/sonic/internal/caching` @@ -32,7 +31,6 @@ import ( `github.com/bytedance/sonic/internal/native/types` `github.com/bytedance/sonic/internal/rt` `github.com/twitchyliquid64/golang-asm/obj` - `github.com/twitchyliquid64/golang-asm/obj/x86` ) /** Register Allocations @@ -1949,63 +1947,3 @@ func (self *_Assembler) print_gc(i int, p1 *_Instr, p2 *_Instr) { self.Emit("MOVQ", jit.Imm(int64(i)), jit.Ptr(_SP, 0)) // MOVQ $(i), (SP) self.call_go(_F_println) } - -var _runtime_writeBarrier uintptr = rt.GcwbAddr() - -//go:linkname gcWriteBarrierAX runtime.gcWriteBarrier -func gcWriteBarrierAX() - -var ( - _V_writeBarrier = jit.Imm(int64(_runtime_writeBarrier)) - - _F_gcWriteBarrierAX = jit.Func(gcWriteBarrierAX) -) - -func (self *_Assembler) WritePtrAX(i int, rec obj.Addr, saveDI bool) { - self.Emit("MOVQ", _V_writeBarrier, _R10) - self.Emit("CMPL", jit.Ptr(_R10, 0), jit.Imm(0)) - self.Sjmp("JE", "_no_writeBarrier" + strconv.Itoa(i) + "_{n}") - if saveDI { - self.save(_DI) - } - self.Emit("LEAQ", rec, _DI) - self.Emit("MOVQ", _F_gcWriteBarrierAX, _R10) // MOVQ ${fn}, AX - self.Rjmp("CALL", _R10) - if saveDI { - self.load(_DI) - } - self.Sjmp("JMP", "_end_writeBarrier" + strconv.Itoa(i) + "_{n}") - self.Link("_no_writeBarrier" + strconv.Itoa(i) + "_{n}") - self.Emit("MOVQ", _AX, rec) - self.Link("_end_writeBarrier" + strconv.Itoa(i) + "_{n}") -} - -func (self *_Assembler) WriteRecNotAX(i int, ptr obj.Addr, rec obj.Addr, saveDI bool, saveAX bool) { - if rec.Reg == x86.REG_AX || rec.Index == x86.REG_AX { - panic("rec contains AX!") - } - self.Emit("MOVQ", _V_writeBarrier, _R10) - self.Emit("CMPL", jit.Ptr(_R10, 0), jit.Imm(0)) - self.Sjmp("JE", "_no_writeBarrier" + strconv.Itoa(i) + "_{n}") - if saveAX { - self.Emit("XCHGQ", ptr, _AX) - } else { - self.Emit("MOVQ", ptr, _AX) - } - if saveDI { - self.save(_DI) - } - self.Emit("LEAQ", rec, _DI) - self.Emit("MOVQ", _F_gcWriteBarrierAX, _R10) // MOVQ ${fn}, AX - self.Rjmp("CALL", _R10) - if saveDI { - self.load(_DI) - } - if saveAX { - self.Emit("XCHGQ", ptr, _AX) - } - self.Sjmp("JMP", "_end_writeBarrier" + strconv.Itoa(i) + "_{n}") - self.Link("_no_writeBarrier" + strconv.Itoa(i) + "_{n}") - self.Emit("MOVQ", ptr, rec) - self.Link("_end_writeBarrier" + strconv.Itoa(i) + "_{n}") -} \ No newline at end of file diff --git a/internal/decoder/assembler_test.go b/internal/decoder/assembler_test.go index ff373914b..d2237b402 100644 --- a/internal/decoder/assembler_test.go +++ b/internal/decoder/assembler_test.go @@ -31,12 +31,6 @@ import ( `github.com/stretchr/testify/require` ) -func TestAssembler_PrologueAndEpilogue(t *testing.T) { - a := newAssembler(nil) - _, e := a.Load()("", 0, nil, nil, 0, "", nil) - assert.Nil(t, e) -} - var utextVar []byte type UtextValue int @@ -675,6 +669,7 @@ func TestAssembler_OpCode(t *testing.T) { } for _, tv := range tests { t.Run(tv.key, func(t *testing.T) { + println(tv.key) testOpCode(t, &tv) }) } @@ -706,6 +701,12 @@ func TestAssembler_DecodeStruct(t *testing.T) { }, v) } +func TestAssembler_PrologueAndEpilogue(t *testing.T) { + a := newAssembler(nil) + _, e := a.Load()("", 0, nil, nil, 0, "", nil) + assert.Nil(t, e) +} + type Tx struct { x int } diff --git a/internal/decoder/generic_amd64_go117.go b/internal/decoder/generic_regabi_amd64.go similarity index 95% rename from internal/decoder/generic_amd64_go117.go rename to internal/decoder/generic_regabi_amd64.go index df1cd9f5b..337af054c 100644 --- a/internal/decoder/generic_amd64_go117.go +++ b/internal/decoder/generic_regabi_amd64.go @@ -1,5 +1,4 @@ -//go:build go1.17 && !go1.21 -// +build go1.17,!go1.21 +// +build go1.17,!go1.22 /* * Copyright 2021 ByteDance Inc. @@ -23,13 +22,11 @@ import ( `encoding/json` `fmt` `reflect` - `strconv` `github.com/bytedance/sonic/internal/jit` `github.com/bytedance/sonic/internal/native` `github.com/bytedance/sonic/internal/native/types` `github.com/twitchyliquid64/golang-asm/obj` - `github.com/twitchyliquid64/golang-asm/obj/x86` ) /** Crucial Registers: @@ -286,7 +283,7 @@ func (self *_ValueDecoder) compile() { self.Emit("LEAQ", _VAR_ss, _CX) // LEAQ ss, CX self.Emit("MOVQ", _VAR_df, _R8) // MOVQ $df, R8 self.Emit("BTSQ", jit.Imm(_F_allow_control), _R8) // ANDQ $1<<_F_allow_control, R8 - self.callc(_F_value) // CALL value + self.callc(_F_value) // CALL value self.Emit("MOVQ", _AX, _IC) // MOVQ AX, IC /* check for errors */ @@ -720,46 +717,6 @@ func (self *_ValueDecoder) compile() { } } -func (self *_ValueDecoder) WritePtrAX(i int, rec obj.Addr, saveDI bool) { - self.Emit("MOVQ", _V_writeBarrier, _R9) - self.Emit("CMPL", jit.Ptr(_R9, 0), jit.Imm(0)) - self.Sjmp("JE", "_no_writeBarrier" + strconv.Itoa(i) + "_{n}") - if saveDI { - self.save(_DI) - } - self.Emit("LEAQ", rec, _DI) - self.call(_F_gcWriteBarrierAX) - if saveDI { - self.load(_DI) - } - self.Sjmp("JMP", "_end_writeBarrier" + strconv.Itoa(i) + "_{n}") - self.Link("_no_writeBarrier" + strconv.Itoa(i) + "_{n}") - self.Emit("MOVQ", _AX, rec) - self.Link("_end_writeBarrier" + strconv.Itoa(i) + "_{n}") -} - -func (self *_ValueDecoder) WriteRecNotAX(i int, ptr obj.Addr, rec obj.Addr, saveDI bool) { - if rec.Reg == x86.REG_AX || rec.Index == x86.REG_AX { - panic("rec contains AX!") - } - self.Emit("MOVQ", _V_writeBarrier, _AX) - self.Emit("CMPL", jit.Ptr(_AX, 0), jit.Imm(0)) - self.Sjmp("JE", "_no_writeBarrier" + strconv.Itoa(i) + "_{n}") - self.Emit("MOVQ", ptr, _AX) - if saveDI { - self.save(_DI) - } - self.Emit("LEAQ", rec, _DI) - self.call(_F_gcWriteBarrierAX) - if saveDI { - self.load(_DI) - } - self.Sjmp("JMP", "_end_writeBarrier" + strconv.Itoa(i) + "_{n}") - self.Link("_no_writeBarrier" + strconv.Itoa(i) + "_{n}") - self.Emit("MOVQ", ptr, rec) - self.Link("_end_writeBarrier" + strconv.Itoa(i) + "_{n}") -} - /** Generic Decoder **/ var ( diff --git a/internal/decoder/generic_amd64_go117_test.s b/internal/decoder/generic_regabi_amd64_test.s similarity index 97% rename from internal/decoder/generic_amd64_go117_test.s rename to internal/decoder/generic_regabi_amd64_test.s index 6c2686de9..1c46928de 100644 --- a/internal/decoder/generic_amd64_go117_test.s +++ b/internal/decoder/generic_regabi_amd64_test.s @@ -1,4 +1,4 @@ -// +build go1.17,!go1.21 +// +build go1.17,!go1.22 // // Copyright 2021 ByteDance Inc. diff --git a/internal/decoder/generic_amd64_go116.go b/internal/decoder/generic_stkabi_amd64.go similarity index 95% rename from internal/decoder/generic_amd64_go116.go rename to internal/decoder/generic_stkabi_amd64.go index 8ce4bd880..8ce5c2926 100644 --- a/internal/decoder/generic_amd64_go116.go +++ b/internal/decoder/generic_stkabi_amd64.go @@ -1,4 +1,4 @@ -// +build go1.15,!go1.17 +// +build go1.16,!go1.17 /* * Copyright 2021 ByteDance Inc. @@ -22,13 +22,11 @@ import ( `encoding/json` `fmt` `reflect` - `strconv` `github.com/bytedance/sonic/internal/jit` `github.com/bytedance/sonic/internal/native` `github.com/bytedance/sonic/internal/native/types` `github.com/twitchyliquid64/golang-asm/obj` - `github.com/twitchyliquid64/golang-asm/obj/x86` ) /** Crucial Registers: @@ -723,48 +721,6 @@ func (self *_ValueDecoder) compile() { } } -func (self *_ValueDecoder) WritePtrAX(i int, rec obj.Addr, saveDI bool) { - self.Emit("MOVQ", _V_writeBarrier, _R10) - self.Emit("CMPL", jit.Ptr(_R10, 0), jit.Imm(0)) - self.Sjmp("JE", "_no_writeBarrier" + strconv.Itoa(i) + "_{n}") - if saveDI { - self.save(_DI) - } - self.Emit("LEAQ", rec, _DI) - self.Emit("MOVQ", _F_gcWriteBarrierAX, _R10) // MOVQ ${fn}, AX - self.Rjmp("CALL", _R10) - if saveDI { - self.load(_DI) - } - self.Sjmp("JMP", "_end_writeBarrier" + strconv.Itoa(i) + "_{n}") - self.Link("_no_writeBarrier" + strconv.Itoa(i) + "_{n}") - self.Emit("MOVQ", _AX, rec) - self.Link("_end_writeBarrier" + strconv.Itoa(i) + "_{n}") -} - -func (self *_ValueDecoder) WriteRecNotAX(i int, ptr obj.Addr, rec obj.Addr, saveDI bool) { - if rec.Reg == x86.REG_AX || rec.Index == x86.REG_AX { - panic("rec contains AX!") - } - self.Emit("MOVQ", _V_writeBarrier, _R10) - self.Emit("CMPL", jit.Ptr(_R10, 0), jit.Imm(0)) - self.Sjmp("JE", "_no_writeBarrier" + strconv.Itoa(i) + "_{n}") - self.Emit("MOVQ", ptr, _AX) - if saveDI { - self.save(_DI) - } - self.Emit("LEAQ", rec, _DI) - self.Emit("MOVQ", _F_gcWriteBarrierAX, _R10) // MOVQ ${fn}, AX - self.Rjmp("CALL", _R10) - if saveDI { - self.load(_DI) - } - self.Sjmp("JMP", "_end_writeBarrier" + strconv.Itoa(i) + "_{n}") - self.Link("_no_writeBarrier" + strconv.Itoa(i) + "_{n}") - self.Emit("MOVQ", ptr, rec) - self.Link("_end_writeBarrier" + strconv.Itoa(i) + "_{n}") -} - /** Generic Decoder **/ var ( diff --git a/internal/decoder/generic_amd64_test.s b/internal/decoder/generic_stkabi_amd64_test.s similarity index 97% rename from internal/decoder/generic_amd64_test.s rename to internal/decoder/generic_stkabi_amd64_test.s index 36cb1f5f3..4e509c2f8 100644 --- a/internal/decoder/generic_amd64_test.s +++ b/internal/decoder/generic_stkabi_amd64_test.s @@ -1,4 +1,4 @@ -// +build go1.15,!go1.17 +// +build go1.16,!go1.17 // // Copyright 2021 ByteDance Inc. diff --git a/internal/decoder/stubs_go115.go b/internal/decoder/stubs_go116.go similarity index 99% rename from internal/decoder/stubs_go115.go rename to internal/decoder/stubs_go116.go index 1a0917c3c..c6e133d8c 100644 --- a/internal/decoder/stubs_go115.go +++ b/internal/decoder/stubs_go116.go @@ -1,4 +1,4 @@ -// +build go1.15,!go1.20 +// +build go1.16,!go1.20 /* * Copyright 2021 ByteDance Inc. diff --git a/internal/decoder/stubs_go120.go b/internal/decoder/stubs_go120.go index ea97fcb1f..73960ea14 100644 --- a/internal/decoder/stubs_go120.go +++ b/internal/decoder/stubs_go120.go @@ -82,23 +82,23 @@ func makemap_small() unsafe.Pointer //go:linkname mapassign runtime.mapassign //goland:noinspection GoUnusedParameter -func mapassign(t *rt.GoType, h unsafe.Pointer, k unsafe.Pointer) unsafe.Pointer +func mapassign(t *rt.GoMapType, h unsafe.Pointer, k unsafe.Pointer) unsafe.Pointer //go:linkname mapassign_fast32 runtime.mapassign_fast32 //goland:noinspection GoUnusedParameter -func mapassign_fast32(t *rt.GoType, h unsafe.Pointer, k uint32) unsafe.Pointer +func mapassign_fast32(t *rt.GoMapType, h unsafe.Pointer, k uint32) unsafe.Pointer //go:linkname mapassign_fast64 runtime.mapassign_fast64 //goland:noinspection GoUnusedParameter -func mapassign_fast64(t *rt.GoType, h unsafe.Pointer, k uint64) unsafe.Pointer +func mapassign_fast64(t *rt.GoMapType, h unsafe.Pointer, k uint64) unsafe.Pointer //go:linkname mapassign_fast64ptr runtime.mapassign_fast64ptr //goland:noinspection GoUnusedParameter -func mapassign_fast64ptr(t *rt.GoType, h unsafe.Pointer, k unsafe.Pointer) unsafe.Pointer +func mapassign_fast64ptr(t *rt.GoMapType, h unsafe.Pointer, k unsafe.Pointer) unsafe.Pointer //go:linkname mapassign_faststr runtime.mapassign_faststr //goland:noinspection GoUnusedParameter -func mapassign_faststr(t *rt.GoType, h unsafe.Pointer, s string) unsafe.Pointer +func mapassign_faststr(t *rt.GoMapType, h unsafe.Pointer, s string) unsafe.Pointer //go:nosplit //go:linkname memclrHasPointers runtime.memclrHasPointers diff --git a/internal/encoder/asm_stubs_amd64_go116.go b/internal/encoder/asm_stubs_amd64_go116.go new file mode 100644 index 000000000..0a99f30ab --- /dev/null +++ b/internal/encoder/asm_stubs_amd64_go116.go @@ -0,0 +1,51 @@ +// +build go1.16,!go1.17 + +// Copyright 2023 CloudWeGo Authors +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +package encoder + +import ( + `strconv` + + `github.com/bytedance/sonic/internal/jit` + `github.com/twitchyliquid64/golang-asm/obj` + `github.com/twitchyliquid64/golang-asm/obj/x86` +) + +var ( + _V_writeBarrier = jit.Imm(int64(_runtime_writeBarrier)) + + _F_gcWriteBarrierAX = jit.Func(gcWriteBarrierAX) +) + +func (self *_Assembler) WritePtr(i int, ptr obj.Addr, rec obj.Addr) { + if rec.Reg == x86.REG_AX || rec.Index == x86.REG_AX { + panic("rec contains AX!") + } + self.Emit("MOVQ", _V_writeBarrier, _R10) + self.Emit("CMPL", jit.Ptr(_R10, 0), jit.Imm(0)) + self.Sjmp("JE", "_no_writeBarrier" + strconv.Itoa(i) + "_{n}") + self.Emit("MOVQ", ptr, _AX) + self.xsave(_DI) + self.Emit("LEAQ", rec, _DI) + self.Emit("MOVQ", _F_gcWriteBarrierAX, _R10) // MOVQ ${fn}, AX + self.Rjmp("CALL", _R10) + self.xload(_DI) + self.Sjmp("JMP", "_end_writeBarrier" + strconv.Itoa(i) + "_{n}") + self.Link("_no_writeBarrier" + strconv.Itoa(i) + "_{n}") + self.Emit("MOVQ", ptr, rec) + self.Link("_end_writeBarrier" + strconv.Itoa(i) + "_{n}") +} + diff --git a/internal/encoder/asm_stubs_amd64_go117.go b/internal/encoder/asm_stubs_amd64_go117.go new file mode 100644 index 000000000..5a3cf1a60 --- /dev/null +++ b/internal/encoder/asm_stubs_amd64_go117.go @@ -0,0 +1,51 @@ +// +build go1.17,!go1.21 + +// Copyright 2023 CloudWeGo Authors +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +package encoder + +import ( + `strconv` + `unsafe` + + `github.com/bytedance/sonic/internal/jit` + `github.com/twitchyliquid64/golang-asm/obj` + `github.com/twitchyliquid64/golang-asm/obj/x86` +) + +var ( + _V_writeBarrier = jit.Imm(int64(uintptr(unsafe.Pointer(&_runtime_writeBarrier)))) + + _F_gcWriteBarrierAX = jit.Func(gcWriteBarrierAX) +) + +func (self *_Assembler) WritePtr(i int, ptr obj.Addr, rec obj.Addr) { + if rec.Reg == x86.REG_AX || rec.Index == x86.REG_AX { + panic("rec contains AX!") + } + self.Emit("MOVQ", _V_writeBarrier, _BX) + self.Emit("CMPL", jit.Ptr(_BX, 0), jit.Imm(0)) + self.Sjmp("JE", "_no_writeBarrier" + strconv.Itoa(i) + "_{n}") + self.xsave(_DI) + self.Emit("MOVQ", ptr, _AX) + self.Emit("LEAQ", rec, _DI) + self.Emit("MOVQ", _F_gcWriteBarrierAX, _BX) // MOVQ ${fn}, AX + self.Rjmp("CALL", _BX) + self.xload(_DI) + self.Sjmp("JMP", "_end_writeBarrier" + strconv.Itoa(i) + "_{n}") + self.Link("_no_writeBarrier" + strconv.Itoa(i) + "_{n}") + self.Emit("MOVQ", ptr, rec) + self.Link("_end_writeBarrier" + strconv.Itoa(i) + "_{n}") +} diff --git a/internal/encoder/asm_stubs_amd64_go121.go b/internal/encoder/asm_stubs_amd64_go121.go new file mode 100644 index 000000000..2f9445ac4 --- /dev/null +++ b/internal/encoder/asm_stubs_amd64_go121.go @@ -0,0 +1,50 @@ +// +build go1.21,!go1.22 + +// Copyright 2023 CloudWeGo Authors +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +package encoder + +import ( + `strconv` + `unsafe` + + `github.com/bytedance/sonic/internal/jit` + `github.com/twitchyliquid64/golang-asm/obj` + `github.com/twitchyliquid64/golang-asm/obj/x86` +) + +var ( + _V_writeBarrier = jit.Imm(int64(uintptr(unsafe.Pointer(&_runtime_writeBarrier)))) + + _F_gcWriteBarrier2 = jit.Func(gcWriteBarrier2) +) + +func (self *_Assembler) WritePtr(i int, ptr obj.Addr, old obj.Addr) { + if old.Reg == x86.REG_AX || old.Index == x86.REG_AX { + panic("rec contains AX!") + } + self.Emit("MOVQ", _V_writeBarrier, _BX) + self.Emit("CMPL", jit.Ptr(_BX, 0), jit.Imm(0)) + self.Sjmp("JE", "_no_writeBarrier" + strconv.Itoa(i) + "_{n}") + self.xsave(_SP_q) + self.Emit("MOVQ", _F_gcWriteBarrier2, _BX) // MOVQ ${fn}, AX + self.Rjmp("CALL", _BX) + self.Emit("MOVQ", ptr, jit.Ptr(_SP_q, 0)) + self.Emit("MOVQ", old, _AX) + self.Emit("MOVQ", _AX, jit.Ptr(_SP_q, 8)) + self.xload(_SP_q) + self.Link("_no_writeBarrier" + strconv.Itoa(i) + "_{n}") + self.Emit("MOVQ", ptr, old) +} diff --git a/internal/encoder/assembler_amd64_go117.go b/internal/encoder/assembler_regabi_amd64.go similarity index 97% rename from internal/encoder/assembler_amd64_go117.go rename to internal/encoder/assembler_regabi_amd64.go index 79efe7580..a89364b14 100644 --- a/internal/encoder/assembler_amd64_go117.go +++ b/internal/encoder/assembler_regabi_amd64.go @@ -1,5 +1,5 @@ -//go:build go1.17 && !go1.21 -// +build go1.17,!go1.21 +//go:build go1.17 && !go1.22 +// +build go1.17,!go1.22 /* * Copyright 2021 ByteDance Inc. @@ -435,8 +435,8 @@ func (self *_Assembler) save_state() { self.Sjmp("JAE" , _LB_error_too_deep) // JA _error_too_deep self.Emit("MOVQ", _SP_x, jit.Sib(_ST, _CX, 1, 8)) // MOVQ SP.x, 8(ST)(CX) self.Emit("MOVQ", _SP_f, jit.Sib(_ST, _CX, 1, 16)) // MOVQ SP.f, 16(ST)(CX) - self.WriteRecNotAX(0, _SP_p, jit.Sib(_ST, _CX, 1, 24)) // MOVQ SP.p, 24(ST)(CX) - self.WriteRecNotAX(1, _SP_q, jit.Sib(_ST, _CX, 1, 32)) // MOVQ SP.q, 32(ST)(CX) + self.WritePtr(0, _SP_p, jit.Sib(_ST, _CX, 1, 24)) // MOVQ SP.p, 24(ST)(CX) + self.WritePtr(1, _SP_q, jit.Sib(_ST, _CX, 1, 32)) // MOVQ SP.q, 32(ST)(CX) self.Emit("MOVQ", _R9, jit.Ptr(_ST, 0)) // MOVQ R9, (ST) } @@ -1175,28 +1175,3 @@ func (self *_Assembler) print_gc(i int, p1 *_Instr, p2 *_Instr) { self.Emit("MOVQ", jit.Imm(int64(i)), _AX) // MOVQ $(i), CX self.call_go(_F_println) } - -var ( - _V_writeBarrier = jit.Imm(int64(uintptr(unsafe.Pointer(&_runtime_writeBarrier)))) - - _F_gcWriteBarrierAX = jit.Func(gcWriteBarrierAX) -) - -func (self *_Assembler) WriteRecNotAX(i int, ptr obj.Addr, rec obj.Addr) { - if rec.Reg == x86.REG_AX || rec.Index == x86.REG_AX { - panic("rec contains AX!") - } - self.Emit("MOVQ", _V_writeBarrier, _BX) - self.Emit("CMPL", jit.Ptr(_BX, 0), jit.Imm(0)) - self.Sjmp("JE", "_no_writeBarrier" + strconv.Itoa(i) + "_{n}") - self.xsave(_DI) - self.Emit("MOVQ", ptr, _AX) - self.Emit("LEAQ", rec, _DI) - self.Emit("MOVQ", _F_gcWriteBarrierAX, _BX) // MOVQ ${fn}, AX - self.Rjmp("CALL", _BX) - self.xload(_DI) - self.Sjmp("JMP", "_end_writeBarrier" + strconv.Itoa(i) + "_{n}") - self.Link("_no_writeBarrier" + strconv.Itoa(i) + "_{n}") - self.Emit("MOVQ", ptr, rec) - self.Link("_end_writeBarrier" + strconv.Itoa(i) + "_{n}") -} diff --git a/internal/encoder/assembler_amd64_go116.go b/internal/encoder/assembler_stkabi_amd64.go similarity index 97% rename from internal/encoder/assembler_amd64_go116.go rename to internal/encoder/assembler_stkabi_amd64.go index 40497d60b..89dafc84e 100644 --- a/internal/encoder/assembler_amd64_go116.go +++ b/internal/encoder/assembler_stkabi_amd64.go @@ -1,4 +1,4 @@ -// +build go1.15,!go1.17 +// +build go1.16,!go1.17 /* * Copyright 2021 ByteDance Inc. @@ -421,8 +421,8 @@ func (self *_Assembler) save_state() { self.Sjmp("JAE" , _LB_error_too_deep) // JA _error_too_deep self.Emit("MOVQ", _SP_x, jit.Sib(_ST, _CX, 1, 8)) // MOVQ SP.x, 8(ST)(CX) self.Emit("MOVQ", _SP_f, jit.Sib(_ST, _CX, 1, 16)) // MOVQ SP.f, 16(ST)(CX) - self.WriteRecNotAX(0, _SP_p, jit.Sib(_ST, _CX, 1, 24)) // MOVQ SP.p, 24(ST)(CX) - self.WriteRecNotAX(1, _SP_q, jit.Sib(_ST, _CX, 1, 32)) // MOVQ SP.q, 32(ST)(CX) + self.WritePtr(0, _SP_p, jit.Sib(_ST, _CX, 1, 24)) // MOVQ SP.p, 24(ST)(CX) + self.WritePtr(1, _SP_q, jit.Sib(_ST, _CX, 1, 32)) // MOVQ SP.q, 32(ST)(CX) self.Emit("MOVQ", _R8, jit.Ptr(_ST, 0)) // MOVQ R8, (ST) } @@ -1173,28 +1173,3 @@ func (self *_Assembler) print_gc(i int, p1 *_Instr, p2 *_Instr) { self.Emit("MOVQ", jit.Imm(int64(i)), jit.Ptr(_SP, 0)) // MOVQ $(i), (SP) self.call_go(_F_println) } - -var ( - _V_writeBarrier = jit.Imm(int64(_runtime_writeBarrier)) - - _F_gcWriteBarrierAX = jit.Func(gcWriteBarrierAX) -) - -func (self *_Assembler) WriteRecNotAX(i int, ptr obj.Addr, rec obj.Addr) { - if rec.Reg == x86.REG_AX || rec.Index == x86.REG_AX { - panic("rec contains AX!") - } - self.Emit("MOVQ", _V_writeBarrier, _R10) - self.Emit("CMPL", jit.Ptr(_R10, 0), jit.Imm(0)) - self.Sjmp("JE", "_no_writeBarrier" + strconv.Itoa(i) + "_{n}") - self.Emit("MOVQ", ptr, _AX) - self.xsave(_DI) - self.Emit("LEAQ", rec, _DI) - self.Emit("MOVQ", _F_gcWriteBarrierAX, _R10) // MOVQ ${fn}, AX - self.Rjmp("CALL", _R10) - self.xload(_DI) - self.Sjmp("JMP", "_end_writeBarrier" + strconv.Itoa(i) + "_{n}") - self.Link("_no_writeBarrier" + strconv.Itoa(i) + "_{n}") - self.Emit("MOVQ", ptr, rec) - self.Link("_end_writeBarrier" + strconv.Itoa(i) + "_{n}") -} \ No newline at end of file diff --git a/internal/encoder/assembler_test.go b/internal/encoder/assembler_test.go index 2cbb8801f..825cc498a 100644 --- a/internal/encoder/assembler_test.go +++ b/internal/encoder/assembler_test.go @@ -34,6 +34,7 @@ import ( func TestEncoderMemoryCorruption(t *testing.T) { println("TestEncoderMemoryCorruption") + runtime.GC() var m = map[string]interface{}{ "1": map[string]interface{} { `"`+strings.Repeat("a", int(option.DefaultEncoderBufferSize) - 38)+`"`: "b", @@ -162,7 +163,8 @@ func TestAssembler_OpCode(t *testing.T) { }, }, } - tests := []testOps {{ + tests := []testOps { + { key: "_OP_null", ins: []_Instr{newInsOp(_OP_null)}, exp: "null", @@ -347,7 +349,8 @@ func TestAssembler_OpCode(t *testing.T) { ins: []_Instr{newInsVt(_OP_marshal, jsonMarshalerType)}, exp: "123456789", val: &jifp, - }, { + }, + { key: "_OP_recurse", ins: mustCompile(rec), exp: `{"a":123,"p":{"a":789,"p":{"a":777,"q":[{"a":999,"q":null,"r":{"` + diff --git a/internal/encoder/debug_go116.go b/internal/encoder/debug_go116.go index 4bc9c15c1..d8d0c45cc 100644 --- a/internal/encoder/debug_go116.go +++ b/internal/encoder/debug_go116.go @@ -1,4 +1,4 @@ -// +build go1.15,!go1.17 +// +build go1.16,!go1.17 /* * Copyright 2021 ByteDance Inc. diff --git a/internal/encoder/debug_go117.go b/internal/encoder/debug_go117.go index 7311f3421..56a6cbf5e 100644 --- a/internal/encoder/debug_go117.go +++ b/internal/encoder/debug_go117.go @@ -1,4 +1,4 @@ -// +build go1.17,!go1.21 +// +build go1.17,!go1.22 /* * Copyright 2021 ByteDance Inc. diff --git a/internal/encoder/stubs_go116.go b/internal/encoder/stubs_go116.go index 40d06f4af..5577c58d7 100644 --- a/internal/encoder/stubs_go116.go +++ b/internal/encoder/stubs_go116.go @@ -1,4 +1,4 @@ -// +build go1.15,!go1.17 +// +build go1.16,!go1.17 /* * Copyright 2021 ByteDance Inc. diff --git a/internal/encoder/stubs_go120.go b/internal/encoder/stubs_go120.go index 2cabc8b4b..94a2c0f56 100644 --- a/internal/encoder/stubs_go120.go +++ b/internal/encoder/stubs_go120.go @@ -1,4 +1,4 @@ -// +build go1.20 +// +build go1.20,!go1.21 /* * Copyright 2021 ByteDance Inc. diff --git a/internal/encoder/stubs_go121.go b/internal/encoder/stubs_go121.go new file mode 100644 index 000000000..e194fbbf3 --- /dev/null +++ b/internal/encoder/stubs_go121.go @@ -0,0 +1,66 @@ +// +build go1.21 + +/* + * Copyright 2021 ByteDance Inc. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package encoder + +import ( + `unsafe` + + _ `github.com/chenzhuoyu/base64x` + + `github.com/bytedance/sonic/internal/rt` +) + +//go:linkname _subr__b64encode github.com/chenzhuoyu/base64x._subr__b64encode +var _subr__b64encode uintptr + +//go:noescape +//go:linkname memmove runtime.memmove +//goland:noinspection GoUnusedParameter +func memmove(to unsafe.Pointer, from unsafe.Pointer, n uintptr) + +//go:linkname growslice reflect.growslice +//goland:noinspection GoUnusedParameter +func growslice(et *rt.GoType, old rt.GoSlice, cap int) rt.GoSlice + +//go:linkname assertI2I runtime.assertI2I2 +//goland:noinspection GoUnusedParameter +func assertI2I(inter *rt.GoType, i rt.GoIface) rt.GoIface + +//go:linkname mapiternext runtime.mapiternext +//goland:noinspection GoUnusedParameter +func mapiternext(it *rt.GoMapIterator) + +//go:linkname mapiterinit runtime.mapiterinit +//goland:noinspection GoUnusedParameter +func mapiterinit(t *rt.GoMapType, m *rt.GoMap, it *rt.GoMapIterator) + +//go:linkname isValidNumber encoding/json.isValidNumber +//goland:noinspection GoUnusedParameter +func isValidNumber(s string) bool + +//go:noescape +//go:linkname memclrNoHeapPointers runtime.memclrNoHeapPointers +//goland:noinspection GoUnusedParameter +func memclrNoHeapPointers(ptr unsafe.Pointer, n uintptr) + +//go:linkname _runtime_writeBarrier runtime.writeBarrier +var _runtime_writeBarrier uintptr + +//go:linkname gcWriteBarrier2 runtime.gcWriteBarrier2 +func gcWriteBarrier2() diff --git a/internal/resolver/stubs.go b/internal/resolver/stubs_compat.go similarity index 98% rename from internal/resolver/stubs.go rename to internal/resolver/stubs_compat.go index ac27aa3d6..a3479543d 100644 --- a/internal/resolver/stubs.go +++ b/internal/resolver/stubs_compat.go @@ -1,3 +1,5 @@ +// +build !go1.21 + /* * Copyright 2021 ByteDance Inc. * diff --git a/internal/resolver/stubs_latest.go b/internal/resolver/stubs_latest.go new file mode 100644 index 000000000..f5a9bff2b --- /dev/null +++ b/internal/resolver/stubs_latest.go @@ -0,0 +1,48 @@ +// +build go1.21 + +/* + * Copyright 2021 ByteDance Inc. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package resolver + +import ( + _ `encoding/json` + `reflect` + _ `unsafe` +) + +type StdField struct { + name string + nameBytes []byte + nameNonEsc string + nameEscHTML string + tag bool + index []int + typ reflect.Type + omitEmpty bool + quoted bool + encoder func() +} + +type StdStructFields struct { + list []StdField + nameIndex map[string]*StdField + byFoldedName map[string]*StdField +} + +//go:noescape +//go:linkname typeFields encoding/json.typeFields +func typeFields(_ reflect.Type) StdStructFields diff --git a/loader/funcdata_go121.go b/loader/funcdata_go121.go new file mode 100644 index 000000000..f50663e2a --- /dev/null +++ b/loader/funcdata_go121.go @@ -0,0 +1,119 @@ +//go:build go1.21 && !go1.22 +// +build go1.21,!go1.22 + +/* + * Copyright 2021 ByteDance Inc. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package loader + +import ( + `unsafe` + `github.com/bytedance/sonic/internal/rt` +) + +const ( + _Magic uint32 = 0xFFFFFFF1 +) + +type moduledata struct { + pcHeader *pcHeader + funcnametab []byte + cutab []uint32 + filetab []byte + pctab []byte + pclntable []byte + ftab []funcTab + findfunctab uintptr + minpc, maxpc uintptr // first func address, last func address + last func size + + text, etext uintptr // start/end of text, (etext-text) must be greater than MIN_FUNC + noptrdata, enoptrdata uintptr + data, edata uintptr + bss, ebss uintptr + noptrbss, enoptrbss uintptr + covctrs, ecovctrs uintptr + end, gcdata, gcbss uintptr + types, etypes uintptr + rodata uintptr + gofunc uintptr // go.func.* is actual funcinfo object in image + + textsectmap []textSection // see runtime/symtab.go: textAddr() + typelinks []int32 // offsets from types + itablinks []*rt.GoItab + + ptab []ptabEntry + + pluginpath string + pkghashes []modulehash + + // This slice records the initializing tasks that need to be + // done to start up the program. It is built by the linker. + inittasks []unsafe.Pointer + + modulename string + modulehashes []modulehash + + hasmain uint8 // 1 if module contains the main function, 0 otherwise + + gcdatamask, gcbssmask bitVector + + typemap map[int32]*rt.GoType // offset to *_rtype in previous module + + bad bool // module failed to load and should be ignored + + next *moduledata +} + +type _func struct { + entryOff uint32 // start pc, as offset from moduledata.text/pcHeader.textStart + nameOff int32 // function name, as index into moduledata.funcnametab. + + args int32 // in/out args size + deferreturn uint32 // offset of start of a deferreturn call instruction from entry, if any. + + pcsp uint32 + pcfile uint32 + pcln uint32 + npcdata uint32 + cuOffset uint32 // runtime.cutab offset of this function's CU + startLine int32 // line number of start of function (func keyword/TEXT directive) + funcID uint8 // set for certain special runtime functions + flag uint8 + _ [1]byte // pad + nfuncdata uint8 // + + // The end of the struct is followed immediately by two variable-length + // arrays that reference the pcdata and funcdata locations for this + // function. + + // pcdata contains the offset into moduledata.pctab for the start of + // that index's table. e.g., + // &moduledata.pctab[_func.pcdata[_PCDATA_UnsafePoint]] is the start of + // the unsafe point table. + // + // An offset of 0 indicates that there is no table. + // + // pcdata [npcdata]uint32 + + // funcdata contains the offset past moduledata.gofunc which contains a + // pointer to that index's funcdata. e.g., + // *(moduledata.gofunc + _func.funcdata[_FUNCDATA_ArgsPointerMaps]) is + // the argument pointer map. + // + // An offset of ^uint32(0) indicates that there is no entry. + // + // funcdata [nfuncdata]uint32 +} diff --git a/loader/funcdata_latest.go b/loader/funcdata_latest.go index b343d6682..52c6097fb 100644 --- a/loader/funcdata_latest.go +++ b/loader/funcdata_latest.go @@ -1,5 +1,5 @@ -// go:build go1.18 && !go1.21 -// +build go1.18,!go1.21 +// go:build go1.18 && !go1.22 +// +build go1.18,!go1.22 /* * Copyright 2021 ByteDance Inc. diff --git a/loader/loader_latest.go b/loader/loader_latest.go index 8b7231eb9..b6e3e75f8 100644 --- a/loader/loader_latest.go +++ b/loader/loader_latest.go @@ -1,5 +1,5 @@ -//go:build go1.16 && !go1.21 -// +build go1.16,!go1.21 +//go:build go1.16 && !go1.22 +// +build go1.16,!go1.22 /* * Copyright 2021 ByteDance Inc. diff --git a/bench-arm.sh b/scripts/bench-arm.sh similarity index 100% rename from bench-arm.sh rename to scripts/bench-arm.sh diff --git a/bench.py b/scripts/bench.py similarity index 86% rename from bench.py rename to scripts/bench.py index 1d4c35739..fe62686ea 100755 --- a/bench.py +++ b/scripts/bench.py @@ -19,7 +19,7 @@ import subprocess import argparse -gbench_prefix = "SONIC_NO_ASYNC_GC=1 go test -benchmem -run=none " +gbench_prefix = "SONIC_NO_ASYNC_GC=1 %s test -benchmem -run=none " def run(cmd): print(cmd) @@ -73,17 +73,22 @@ def compare(args): # benchmark current branch (fd, target) = tempfile.mkstemp(".target.txt") - run("%s %s ./... 2>&1 | tee %s" %(gbench_prefix, args, target)) - + run("%s %s ./... 2>&1 | tee %s" %(gbench_prefix % "go", args, target)) + + # trying to switch to the latest main branch run("git checkout -- .") if current_branch != "main": run("git checkout main") run("git pull --allow-unrelated-histories origin main") - # benchmark main branch (fd, main) = tempfile.mkstemp(".main.txt") - run("%s %s ./... 2>&1 | tee %s" %(gbench_prefix, args, main)) + if gobin != "go": + # change GOROOT + run("export GOROOT=%s" % gobin) + run("%s %s ./... 2>&1 | tee %s" %(gbench_prefix % (gobin+"/bin/go")), args, main) + else: + run("%s %s ./... 2>&1 | tee %s" %(gbench_prefix % "go", args, main)) # diff the result # benchstat = "go get golang.org/x/perf/cmd/benchstat && go install golang.org/x/perf/cmd/benchstat" @@ -93,6 +98,7 @@ def compare(args): # restore branch if current_branch != "main": run("git checkout %s"%(current_branch)) + run("patch -p1 < %s" % (diff)) return target @@ -106,8 +112,16 @@ def main(): help='benchmark the times') argparser.add_argument('-r', '--repeat_times', dest='count', required=False, help='benchmark the count') + argparser.add_argument('-go', '--go_bin_path', dest='gobin', required=False, + help='benchmark the count') args = argparser.parse_args() + global gobin + if args.gobin: + gobin = args.gobin + else: + gobin = "go" + if args.filter: gbench_args = "-bench=%s"%(args.filter) else: diff --git a/bench.sh b/scripts/bench.sh similarity index 100% rename from bench.sh rename to scripts/bench.sh diff --git a/check_branch_name.sh b/scripts/check_branch_name.sh similarity index 100% rename from check_branch_name.sh rename to scripts/check_branch_name.sh diff --git a/scripts/go_latest.sh b/scripts/go_latest.sh new file mode 100755 index 000000000..4f37d67fb --- /dev/null +++ b/scripts/go_latest.sh @@ -0,0 +1,20 @@ +#!/bin/ba +TAG=$1 + +git clone https://github.com/golang/go.git $TAG + +cd $TAG/src +git checkout -b build/$TAG $TAG + +./all.bash + +cd .. +export GOROOT=$PWD +export PATH=$GOROOT/bin:$PATH +go version + +cd .. +GOMAXPROCS=4 go test -v -race . +GOMAXPROCS=4 go test -v -race github.com/bytedance/sonic/ast +GOMAXPROCS=4 go test -v -race github.com/bytedance/sonic/internal/encoder +GOMAXPROCS=4 go test -v -race github.com/bytedance/sonic/internal/decoder diff --git a/scripts/qemu.sh b/scripts/qemu.sh new file mode 100644 index 000000000..8c9b868e9 --- /dev/null +++ b/scripts/qemu.sh @@ -0,0 +1,9 @@ +#!/bin/sh +arch=$(uname -m) +if echo $arch | grep -q 'arm'; then + printf ' #!/bin/bash\n if [ ! -x "/usr/bin/qemu-x86_64" ];then\n sudo apt-get update\n sudo apt-get -y install make gcc g++ libglib2.0-dev libpixman-1-dev libfdt-dev python3-pip ninja-build\n sudo pip3 install meson\n wget https://download.qemu.org/qemu-6.2.0.tar.xz\n tar -xvf qemu-6.2.0.tar.xz\n cd qemu-6.2.0\n sudo ./configure\n sudo make -j 4\n sudo make install\n cd ..\n cp /usr/local/bin/qemu-x86_64 /usr/bin/qemu-x86_64\n fi\n' > qemu_install.sh + chmod +x qemu_install.sh + ./qemu_install.sh + GOARCH=amd64 go test -c . + qemu-x86_64 -cpu max ./sonic.test -test.v +fi \ No newline at end of file diff --git a/search_test.go b/search_test.go index 59e5a353d..4e8c7c4df 100644 --- a/search_test.go +++ b/search_test.go @@ -1,4 +1,4 @@ -// +build amd64,go1.16,!go1.21 +// +build amd64,go1.16,!go1.22 /* * Copyright 2021 ByteDance Inc. diff --git a/sonic.go b/sonic.go index b394aa6de..58edb2829 100644 --- a/sonic.go +++ b/sonic.go @@ -1,4 +1,4 @@ -// +build amd64,go1.16,!go1.21 +// +build amd64,go1.16,!go1.22 /* * Copyright 2021 ByteDance Inc. diff --git a/use_number_test.go b/use_number_test.go index ab97a710f..bdaed778a 100644 --- a/use_number_test.go +++ b/use_number_test.go @@ -1,4 +1,4 @@ -// +build amd64,go1.16,!go1.21 +// +build amd64,go1.16,!go1.22 /* * Copyright 2021 ByteDance Inc.