-
Notifications
You must be signed in to change notification settings - Fork 335
Add unsafe little endian loaders #1036
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from 4 commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
179af51
Add unsafe little endian loaders
klauspost fef4be6
Try new test matrix
klauspost 1471edf
Fix field name.
klauspost bd64698
Use in buff0, s2 go decoder.
klauspost a5e5c92
Merge branch 'master' into add-unsafe-loader
klauspost 2fcbfef
Avoid loop bounds check.
klauspost 75ce7ef
Avoid length check on callers.
klauspost 4a12004
Use in more places.
klauspost b959ae3
Bump s2sx version
klauspost 209574e
Update docs
klauspost File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -32,18 +32,24 @@ jobs: | |
- name: Test | ||
run: go test ./... | ||
|
||
- name: Test Noasm | ||
- name: Test No-asm | ||
run: go test -tags=noasm ./... | ||
|
||
- name: Test No-unsafe | ||
run: go test -tags=nounsafe ./... | ||
|
||
- name: Test No-unsafe, noasm | ||
run: go test -tags="nounsafe,noasm" ./... | ||
|
||
- name: Test Race 1 CPU | ||
env: | ||
CGO_ENABLED: 1 | ||
run: go test -cpu=1 -short -race -v ./... | ||
run: go test -cpu=1 -short -race -tags=nounsafe -v ./... | ||
|
||
- name: Test Race 4 CPU | ||
env: | ||
CGO_ENABLED: 1 | ||
run: go test -cpu=4 -short -race -v ./... | ||
run: go test -cpu=4 -short -race -tags=nounsafe -v ./... | ||
|
||
generate: | ||
strategy: | ||
|
@@ -112,6 +118,9 @@ jobs: | |
env: | ||
CGO_ENABLED: 0 | ||
runs-on: ubuntu-latest | ||
strategy: | ||
matrix: | ||
tags: [ 'nounsafe', '"noasm,nounsafe"' ] | ||
steps: | ||
- name: Set up Go | ||
uses: actions/[email protected] | ||
|
@@ -121,28 +130,23 @@ jobs: | |
- name: Checkout code | ||
uses: actions/checkout@v4 | ||
|
||
- name: S2/FuzzDictBlocks | ||
run: go test -run=none -fuzz=FuzzDictBlocks -fuzztime=100000x -test.fuzzminimizetime=10ms ./s2/. | ||
- name: S2/FuzzDictBlocks/${{ matrix.tags }} | ||
run: go test -tags=${{ matrix.tags }} -run=none -fuzz=FuzzDictBlocks -fuzztime=100000x -test.fuzzminimizetime=10ms ./s2/. | ||
|
||
- name: S2/FuzzEncodingBlocks | ||
run: go test -run=none -fuzz=FuzzEncodingBlocks -fuzztime=500000x -test.fuzzminimizetime=10ms ./s2/. | ||
- name: S2/FuzzEncodingBlocks/${{ matrix.tags }} | ||
run: go test -tags=${{ matrix.tags }} -run=none -fuzz=FuzzEncodingBlocks -fuzztime=500000x -test.fuzzminimizetime=10ms ./s2/. | ||
|
||
- name: S2/FuzzLZ4Block | ||
run: go test -run=none -fuzz=FuzzLZ4Block -fuzztime=500000x -test.fuzzminimizetime=10ms ./s2/. | ||
- name: S2/FuzzLZ4Block/${{ matrix.tags }} | ||
run: go test -tags=${{ matrix.tags }} -run=none -fuzz=FuzzLZ4Block -fuzztime=500000x -test.fuzzminimizetime=10ms ./s2/. | ||
|
||
- name: S2/FuzzDictBlocks/noasm | ||
run: go test -tags=noasm -run=none -fuzz=FuzzDictBlocks -fuzztime=100000x -test.fuzzminimizetime=10ms ./s2/. | ||
|
||
- name: S2/FuzzEncodingBlocks/noasm | ||
run: go test -tags=noasm -run=none -fuzz=FuzzEncodingBlocks -fuzztime=500000x -test.fuzzminimizetime=10ms ./s2/. | ||
|
||
- name: S2/FuzzLZ4Block/noasm | ||
run: go test -tags=noasm -run=none -fuzz=FuzzLZ4Block -fuzztime=500000x -test.fuzzminimizetime=10ms ./s2/. | ||
|
||
fuzz-zstd: | ||
env: | ||
CGO_ENABLED: 0 | ||
runs-on: ubuntu-latest | ||
strategy: | ||
matrix: | ||
tags: [ 'nounsafe', '"noasm,nounsafe"' ] | ||
steps: | ||
- name: Set up Go | ||
uses: actions/[email protected] | ||
|
@@ -152,57 +156,44 @@ jobs: | |
- name: Checkout code | ||
uses: actions/checkout@v4 | ||
|
||
- name: zstd/FuzzDecodeAll | ||
run: go test -run=none -fuzz=FuzzDecodeAll -fuzztime=500000x -test.fuzzminimizetime=10ms ./zstd/. | ||
- name: zstd/FuzzDecodeAll/${{ matrix.tags }} | ||
run: go test -tags=${{ matrix.tags }} -run=none -fuzz=FuzzDecodeAll -fuzztime=500000x -test.fuzzminimizetime=10ms ./zstd/. | ||
|
||
- name: zstd/FuzzDecAllNoBMI2 | ||
run: go test -run=none -fuzz=FuzzDecAllNoBMI2 -fuzztime=500000x -test.fuzzminimizetime=10ms ./zstd/. | ||
- name: zstd/FuzzDecAllNoBMI2/${{ matrix.tags }} | ||
run: go test -tags=${{ matrix.tags }} -run=none -fuzz=FuzzDecAllNoBMI2 -fuzztime=500000x -test.fuzzminimizetime=10ms ./zstd/. | ||
|
||
- name: zstd/FuzzDecoder | ||
run: go test -run=none -fuzz=FuzzDecoder -fuzztime=500000x -test.fuzzminimizetime=10ms ./zstd/. | ||
- name: zstd/FuzzDecoder/${{ matrix.tags }} | ||
run: go test -tags=${{ matrix.tags }} -run=none -fuzz=FuzzDecoder -fuzztime=500000x -test.fuzzminimizetime=10ms ./zstd/. | ||
|
||
- name: zstd/FuzzNoBMI2Dec | ||
run: go test -run=none -fuzz=FuzzNoBMI2Dec -fuzztime=500000x -test.fuzzminimizetime=10ms ./zstd/. | ||
- name: zstd/FuzzNoBMI2Dec/${{ matrix.tags }} | ||
run: go test -tags=${{ matrix.tags }} -run=none -fuzz=FuzzNoBMI2Dec -fuzztime=500000x -test.fuzzminimizetime=10ms ./zstd/. | ||
|
||
- name: zstd/FuzzEncoding | ||
run: cd zstd&&go test -run=none -fuzz=FuzzEncoding -fuzztime=250000x -test.fuzzminimizetime=10ms -fuzz-end=3&&cd .. | ||
|
||
- name: zstd/FuzzDecodeAll/noasm | ||
run: go test -tags=noasm -run=none -fuzz=FuzzDecodeAll -fuzztime=500000x -test.fuzzminimizetime=10ms ./zstd/. | ||
|
||
- name: zstd/FuzzDecoder/noasm | ||
run: go test -tags=noasm -run=none -fuzz=FuzzDecoder -fuzztime=500000x -test.fuzzminimizetime=10ms ./zstd/. | ||
|
||
- name: zstd/FuzzEncoding/noasm | ||
run: cd zstd&&go test -tags=noasm -run=none -fuzz=FuzzEncoding -fuzztime=250000x -test.fuzzminimizetime=10ms -fuzz-end=3&&cd .. | ||
|
||
- name: zstd/FuzzEncodingBest | ||
run: cd zstd&&go test -run=none -fuzz=FuzzEncoding -fuzztime=25000x -test.fuzzminimizetime=10ms -fuzz-start=4&&cd .. | ||
- name: zstd/FuzzEncoding/${{ matrix.tags }} | ||
run: cd zstd&&go test -tags=${{ matrix.tags }} -run=none -fuzz=FuzzEncoding -fuzztime=250000x -test.fuzzminimizetime=10ms -fuzz-end=3&&cd .. | ||
|
||
fuzz-other: | ||
env: | ||
CGO_ENABLED: 0 | ||
runs-on: ubuntu-latest | ||
strategy: | ||
matrix: | ||
tags: [ 'nounsafe', '"noasm,nounsafe"' ] | ||
steps: | ||
- name: Set up Go | ||
uses: actions/[email protected] | ||
with: | ||
go-version: 1.23.x | ||
|
||
- name: Checkout code | ||
uses: actions/checkout@v4 | ||
|
||
- name: flate/FuzzEncoding | ||
run: go test -run=none -fuzz=FuzzEncoding -fuzztime=100000x -test.fuzzminimizetime=10ms ./flate/. | ||
|
||
- name: flate/FuzzEncoding/noasm | ||
run: go test -run=none -tags=noasm -fuzz=FuzzEncoding -fuzztime=100000x -test.fuzzminimizetime=10ms ./flate/. | ||
- name: flate/FuzzEncoding/${{ matrix.tags }} | ||
run: go test -tags=${{ matrix.tags }} -run=none -fuzz=FuzzEncoding -fuzztime=100000x -test.fuzzminimizetime=10ms ./flate/. | ||
|
||
- name: zip/FuzzReader | ||
run: go test -run=none -fuzz=FuzzReader -fuzztime=500000x -test.fuzzminimizetime=10ms ./zip/. | ||
- name: zip/FuzzReader/${{ matrix.tags }} | ||
run: go test -tags=${{ matrix.tags }} -run=none -fuzz=FuzzReader -fuzztime=500000x -test.fuzzminimizetime=10ms ./zip/. | ||
|
||
- name: fse/FuzzCompress | ||
run: go test -run=none -fuzz=FuzzCompress -fuzztime=1000000x -test.fuzzminimizetime=10ms ./fse/. | ||
- name: fse/FuzzCompress/${{ matrix.tags }} | ||
run: go test -tags=${{ matrix.tags }} -run=none -fuzz=FuzzCompress -fuzztime=1000000x -test.fuzzminimizetime=10ms ./fse/. | ||
|
||
- name: fse/FuzzDecompress | ||
run: go test -run=none -fuzz=FuzzDecompress -fuzztime=1000000x -test.fuzzminimizetime=10ms ./fse/. | ||
- name: fse/FuzzDecompress/${{ matrix.tags }} | ||
run: go test -tags=${{ matrix.tags }} -run=none -fuzz=FuzzDecompress -fuzztime=1000000x -test.fuzzminimizetime=10ms ./fse/. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,4 @@ | ||
//go:build go1.18 | ||
// +build go1.18 | ||
|
||
package flate | ||
|
||
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
package le | ||
|
||
type Indexer interface { | ||
int | int8 | int16 | int32 | int64 | uint | uint8 | uint16 | uint32 | uint64 | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
//go:build !(amd64 || arm64 || ppc64le || riscv64) || nounsafe || purego || appengine | ||
|
||
package le | ||
|
||
import ( | ||
"encoding/binary" | ||
) | ||
|
||
func Load16[I Indexer](b []byte, i I) uint16 { | ||
return binary.LittleEndian.Uint16(b[i:]) | ||
} | ||
|
||
func Load32[I Indexer](b []byte, i I) uint32 { | ||
return binary.LittleEndian.Uint32(b[i:]) | ||
} | ||
|
||
func Load64[I Indexer](b []byte, i I) uint64 { | ||
return binary.LittleEndian.Uint64(b[i:]) | ||
} | ||
|
||
func Store16(b []byte, v uint16) { | ||
binary.LittleEndian.PutUint16(b, v) | ||
} | ||
|
||
func Store32(b []byte, v uint32) { | ||
binary.LittleEndian.PutUint32(b, v) | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
// We enable 64 bit LE platforms: | ||
|
||
//go:build (amd64 || arm64 || ppc64le || riscv64) && !nounsafe && !purego && !appengine | ||
|
||
package le | ||
|
||
import ( | ||
"unsafe" | ||
) | ||
|
||
func Load16[I Indexer](b []byte, i I) uint16 { | ||
//return binary.LittleEndian.Uint16(b[i:]) | ||
//return *(*uint16)(unsafe.Pointer(&b[i])) | ||
return *(*uint16)(unsafe.Pointer(uintptr(unsafe.Pointer(&b[0])) + uintptr(i)*unsafe.Sizeof(b[0]))) | ||
} | ||
|
||
func Load32[I Indexer](b []byte, i I) uint32 { | ||
//return binary.LittleEndian.Uint32(b[i:]) | ||
//return *(*uint32)(unsafe.Pointer(&b[i])) | ||
return *(*uint32)(unsafe.Pointer(uintptr(unsafe.Pointer(&b[0])) + uintptr(i)*unsafe.Sizeof(b[0]))) | ||
} | ||
|
||
func Load64[I Indexer](b []byte, i I) uint64 { | ||
//return binary.LittleEndian.Uint64(b[i:]) | ||
//return *(*uint64)(unsafe.Pointer(&b[i])) | ||
return *(*uint64)(unsafe.Pointer(uintptr(unsafe.Pointer(&b[0])) + uintptr(i)*unsafe.Sizeof(b[0]))) | ||
} | ||
klauspost marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
func Store16(b []byte, v uint16) { | ||
//binary.LittleEndian.PutUint16(b, v) | ||
*(*uint16)(unsafe.Pointer(&b[0])) = v | ||
} | ||
klauspost marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
func Store32(b []byte, v uint32) { | ||
//binary.LittleEndian.PutUint32(b, v) | ||
*(*uint32)(unsafe.Pointer(&b[0])) = v | ||
} | ||
klauspost marked this conversation as resolved.
Show resolved
Hide resolved
|
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.