Compare commits
5 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
9bac4fb257 | ||
|
|
7958db9c0d | ||
|
|
4869c146fe | ||
|
|
b26387ea9b | ||
|
|
76a660ebed |
12
DESIGN
Normal file
12
DESIGN
Normal file
@@ -0,0 +1,12 @@
|
|||||||
|
Для irc admin-модуля:
|
||||||
|
|
||||||
|
1. берём pebbledb как бэкэнд сохранения настроек.
|
||||||
|
|
||||||
|
2. имплементировать trusted-участников чятика для настройки бота под конкретный канальчик.
|
||||||
|
Есть два варианта:
|
||||||
|
- ручной список в конфиге, где прописывается owner бота и доверенные лица (опционально доверенных можно прописывать в pebbledb admin_db)
|
||||||
|
- доверенными являются op-ы
|
||||||
|
|
||||||
|
Первый вариант - довольно гибкий, но у нас всегда bot owner является доверенным. Не то чтобы это неправильно. Но с другой стороны можно сделать owner-а суперадмином, а другим админам дать возможность добавлять user-ов для своего канальчика в список доверенных. И запретить удалять себя из списка доверенных.
|
||||||
|
|
||||||
|
Второй вариант проще. И выглядит более привычным в текущих реалиях. Но есть нюанс - у нас нету простой возможности вынуть список участников вместе с флагами (предположительно). Кроме того, необходимо писать обработчк ивентов для всех изменений состояний юзеров (join/part и op/deop) для поддержания списка участников в актуальном состоянии.
|
||||||
14
Makefile
14
Makefile
@@ -1,7 +1,7 @@
|
|||||||
#!/usr/bin/env gmake -f
|
#!/usr/bin/env gmake -f
|
||||||
|
|
||||||
GOOPTS=CGO_ENABLED=0
|
GOOPTS=CGO_ENABLED=0
|
||||||
BUILDOPTS=-ldflags="-s -w" -a -gcflags=all=-l
|
BUILDOPTS=-ldflags="-s -w" -a -gcflags=all=-l -trimpath
|
||||||
|
|
||||||
all: clean build
|
all: clean build
|
||||||
|
|
||||||
@@ -12,12 +12,10 @@ build:
|
|||||||
clean:
|
clean:
|
||||||
go clean
|
go clean
|
||||||
|
|
||||||
wipe:
|
upgrade:
|
||||||
go clean
|
rm -rf vendor
|
||||||
rm -rf go.{mod,sum}
|
go get -d -u -t ./...
|
||||||
|
go mod tidy
|
||||||
prep:
|
go mod vendor
|
||||||
go mod init main
|
|
||||||
go mod tidy -compat=1.18
|
|
||||||
|
|
||||||
# vim: set ft=make noet ai ts=4 sw=4 sts=4:
|
# vim: set ft=make noet ai ts=4 sw=4 sts=4:
|
||||||
|
|||||||
2
README
2
README
@@ -13,7 +13,7 @@ aleesa-irc-go
|
|||||||
|
|
||||||
Как это собрать?
|
Как это собрать?
|
||||||
-----------------------------------------------------------------------------------------------------------------------
|
-----------------------------------------------------------------------------------------------------------------------
|
||||||
Понадобится golang версии 1.18 или более новая.
|
Понадобится golang версии 1.19 или более новая.
|
||||||
|
|
||||||
Сам процесс сборки простой, достаточно запустить:
|
Сам процесс сборки простой, достаточно запустить:
|
||||||
make
|
make
|
||||||
|
|||||||
1
README.txt
Symbolic link
1
README.txt
Symbolic link
@@ -0,0 +1 @@
|
|||||||
|
README
|
||||||
14
TODO
Normal file
14
TODO
Normal file
@@ -0,0 +1,14 @@
|
|||||||
|
[ ] Имплементировать IRC (например, через https://github.com/thoj/go-ircevent)
|
||||||
|
[*] irc в виде горутинки на вход, как irc-клиент + обработчик входящих ивентов - ctcp-сообщений, dcc и вот это всё
|
||||||
|
[ ] подумать про настройки и нужность админской части (скорее всего нужно, для настройки функций ботов для канала)
|
||||||
|
[ ] подумать, про инвайт бота и про удаление бота средствами !nick get lost, если бот заапрувлен, но уже надоел.
|
||||||
|
[+] irc в виде функи для сообщений на выход, собственно, её будут дёргать как обработчик redis-сообщений, так модуль протокола irc
|
||||||
|
[+] реализовать ограничитель сообщений в единицу времени
|
||||||
|
|
||||||
|
[+] Исправить парсер конфига
|
||||||
|
|
||||||
|
[ ] Мульти-инстанс. В формате нескольких сервисов с отдельными конфигами. (Описать мульти-инстанс в readme)
|
||||||
|
[ ] Вариант запуска как с помощью симлинка (поиск конфига по имени бинаря).
|
||||||
|
[ ] Вариант запуска с указанием положения конфига.
|
||||||
|
|
||||||
|
[ ] Дописать всякие необязательные .md-файлы :)
|
||||||
46
go.mod
46
go.mod
@@ -1,32 +1,40 @@
|
|||||||
module aleesa-irc-go
|
module aleesa-irc-go
|
||||||
|
|
||||||
go 1.18
|
go 1.19
|
||||||
|
|
||||||
require (
|
require (
|
||||||
github.com/cockroachdb/errors v1.8.1
|
github.com/cockroachdb/errors v1.9.1
|
||||||
github.com/cockroachdb/pebble v0.0.0-20220729140737-245afda9c39f
|
github.com/cockroachdb/pebble v0.0.0-20230517202617-f6eaf9a696e6
|
||||||
github.com/go-redis/redis/v8 v8.11.5
|
github.com/go-redis/redis/v8 v8.11.5
|
||||||
github.com/hjson/hjson-go v3.1.0+incompatible
|
github.com/hjson/hjson-go v3.3.0+incompatible
|
||||||
github.com/sirupsen/logrus v1.8.1
|
github.com/sirupsen/logrus v1.9.2
|
||||||
github.com/thoj/go-ircevent v0.0.0-20210723090443-73e444401d64
|
github.com/thoj/go-ircevent v0.0.0-20210723090443-73e444401d64
|
||||||
)
|
)
|
||||||
|
|
||||||
require (
|
require (
|
||||||
github.com/DataDog/zstd v1.4.5 // indirect
|
github.com/DataDog/zstd v1.5.5 // indirect
|
||||||
github.com/HdrHistogram/hdrhistogram-go v1.1.2 // indirect
|
github.com/beorn7/perks v1.0.1 // indirect
|
||||||
github.com/cespare/xxhash/v2 v2.1.2 // indirect
|
github.com/cespare/xxhash/v2 v2.2.0 // indirect
|
||||||
github.com/cockroachdb/logtags v0.0.0-20190617123548-eb05cc24525f // indirect
|
github.com/cockroachdb/logtags v0.0.0-20230118201751-21c54148d20b // indirect
|
||||||
github.com/cockroachdb/redact v1.0.8 // indirect
|
github.com/cockroachdb/redact v1.1.4 // indirect
|
||||||
github.com/cockroachdb/sentry-go v0.6.1-cockroachdb.2 // indirect
|
|
||||||
github.com/dgryski/go-rendezvous v0.0.0-20200823014737-9f7001d12a5f // indirect
|
github.com/dgryski/go-rendezvous v0.0.0-20200823014737-9f7001d12a5f // indirect
|
||||||
github.com/gogo/protobuf v1.3.1 // indirect
|
github.com/getsentry/sentry-go v0.21.0 // indirect
|
||||||
github.com/golang/snappy v0.0.3 // indirect
|
github.com/gogo/protobuf v1.3.2 // indirect
|
||||||
github.com/klauspost/compress v1.11.7 // indirect
|
github.com/golang/protobuf v1.5.3 // indirect
|
||||||
github.com/kr/pretty v0.1.0 // indirect
|
github.com/golang/snappy v0.0.4 // indirect
|
||||||
|
github.com/klauspost/compress v1.16.5 // indirect
|
||||||
|
github.com/kr/pretty v0.3.1 // indirect
|
||||||
github.com/kr/text v0.2.0 // indirect
|
github.com/kr/text v0.2.0 // indirect
|
||||||
|
github.com/matttproud/golang_protobuf_extensions v1.0.4 // indirect
|
||||||
github.com/pkg/errors v0.9.1 // indirect
|
github.com/pkg/errors v0.9.1 // indirect
|
||||||
golang.org/x/exp v0.0.0-20200513190911-00229845015e // indirect
|
github.com/prometheus/client_golang v1.15.1 // indirect
|
||||||
golang.org/x/net v0.0.0-20210614182718-04defd469f4e // indirect
|
github.com/prometheus/client_model v0.4.0 // indirect
|
||||||
golang.org/x/sys v0.0.0-20211216021012-1d35b9e2eb4e // indirect
|
github.com/prometheus/common v0.43.0 // indirect
|
||||||
golang.org/x/text v0.3.6 // indirect
|
github.com/prometheus/procfs v0.9.0 // indirect
|
||||||
|
github.com/rogpeppe/go-internal v1.10.0 // indirect
|
||||||
|
golang.org/x/exp v0.0.0-20230515195305-f3d0a9c9a5cc // indirect
|
||||||
|
golang.org/x/net v0.10.0 // indirect
|
||||||
|
golang.org/x/sys v0.8.0 // indirect
|
||||||
|
golang.org/x/text v0.9.0 // indirect
|
||||||
|
google.golang.org/protobuf v1.30.0 // indirect
|
||||||
)
|
)
|
||||||
|
|||||||
288
go.sum
288
go.sum
@@ -1,39 +1,34 @@
|
|||||||
cloud.google.com/go v0.26.0/go.mod h1:aQUYkXzVsufM+DwF1aE+0xfcU+56JwCaLick0ClmMTw=
|
cloud.google.com/go v0.26.0/go.mod h1:aQUYkXzVsufM+DwF1aE+0xfcU+56JwCaLick0ClmMTw=
|
||||||
dmitri.shuralyov.com/gpu/mtl v0.0.0-20190408044501-666a987793e9/go.mod h1:H6x//7gZCb22OMCxBHrMx7a5I7Hp++hsVxbQ4BYO7hU=
|
|
||||||
github.com/AndreasBriese/bbloom v0.0.0-20190306092124-e2d15f34fcf9/go.mod h1:bOvUY6CB00SOBii9/FifXqc0awNKxLFCL/+pkDPuyl8=
|
github.com/AndreasBriese/bbloom v0.0.0-20190306092124-e2d15f34fcf9/go.mod h1:bOvUY6CB00SOBii9/FifXqc0awNKxLFCL/+pkDPuyl8=
|
||||||
github.com/BurntSushi/toml v0.3.1/go.mod h1:xHWCNGjB5oqiDr8zfno3MHue2Ht5sIBksp03qcyfWMU=
|
github.com/BurntSushi/toml v0.3.1/go.mod h1:xHWCNGjB5oqiDr8zfno3MHue2Ht5sIBksp03qcyfWMU=
|
||||||
github.com/BurntSushi/xgb v0.0.0-20160522181843-27f122750802/go.mod h1:IVnqGOEym/WlBOVXweHU+Q+/VP0lqqI8lqeDx9IjBqo=
|
github.com/CloudyKit/fastprinter v0.0.0-20200109182630-33d98a066a53/go.mod h1:+3IMCy2vIlbG1XG/0ggNQv0SvxCAIpPM5b1nCz56Xno=
|
||||||
github.com/CloudyKit/fastprinter v0.0.0-20170127035650-74b38d55f37a/go.mod h1:EFZQ978U7x8IRnstaskI3IysnWY5Ao3QgZUKOXlsAdw=
|
github.com/CloudyKit/jet/v3 v3.0.0/go.mod h1:HKQPgSJmdK8hdoAbKUUWajkHyHo4RaU5rMdUywE7VMo=
|
||||||
github.com/CloudyKit/jet v2.1.3-0.20180809161101-62edd43e4f88+incompatible/go.mod h1:HPYO+50pSWkPoj9Q/eq0aRGByCL6ScRlUmiEX5Zgm+w=
|
github.com/DataDog/zstd v1.5.5 h1:oWf5W7GtOLgp6bciQYDmhHHjdhYkALu6S/5Ni9ZgSvQ=
|
||||||
github.com/DataDog/zstd v1.4.5 h1:EndNeuB0l9syBZhut0wns3gV1hL8zX8LIu6ZiVHWLIQ=
|
github.com/DataDog/zstd v1.5.5/go.mod h1:g4AWEaM3yOg3HYfnJ3YIawPnVdXJh9QME85blwSAmyw=
|
||||||
github.com/DataDog/zstd v1.4.5/go.mod h1:1jcaCB/ufaK+sKp1NBhlGmpz41jOoPQ35bpF36t7BBo=
|
|
||||||
github.com/HdrHistogram/hdrhistogram-go v1.1.2 h1:5IcZpTvzydCQeHzK4Ef/D5rrSqwxob0t8PQPMybUNFM=
|
|
||||||
github.com/HdrHistogram/hdrhistogram-go v1.1.2/go.mod h1:yDgFjdqOqDEKOvasDdhWNXYg9BVp4O+o5f6V/ehm6Oo=
|
|
||||||
github.com/Joker/hpp v1.0.0/go.mod h1:8x5n+M1Hp5hC0g8okX3sR3vFQwynaX/UgSOM9MeBKzY=
|
github.com/Joker/hpp v1.0.0/go.mod h1:8x5n+M1Hp5hC0g8okX3sR3vFQwynaX/UgSOM9MeBKzY=
|
||||||
github.com/Joker/jade v1.0.1-0.20190614124447-d475f43051e7/go.mod h1:6E6s8o2AE4KhCrqr6GRJjdC/gNfTdxkIXvuGZZda2VM=
|
|
||||||
github.com/Shopify/goreferrer v0.0.0-20181106222321-ec9c9a553398/go.mod h1:a1uqRtAwp2Xwc6WNPJEufxJ7fx3npB4UV/JOLmbu5I0=
|
github.com/Shopify/goreferrer v0.0.0-20181106222321-ec9c9a553398/go.mod h1:a1uqRtAwp2Xwc6WNPJEufxJ7fx3npB4UV/JOLmbu5I0=
|
||||||
github.com/ajg/form v1.5.1/go.mod h1:uL1WgH+h2mgNtvBq0339dVnzXdBETtL2LeUXaIv25UY=
|
github.com/ajg/form v1.5.1/go.mod h1:uL1WgH+h2mgNtvBq0339dVnzXdBETtL2LeUXaIv25UY=
|
||||||
github.com/ajstarks/svgo v0.0.0-20180226025133-644b8db467af/go.mod h1:K08gAheRH3/J6wwsYMMT4xOr94bZjxIelGM0+d/wbFw=
|
|
||||||
github.com/armon/consul-api v0.0.0-20180202201655-eb2c6b5be1b6/go.mod h1:grANhF5doyWs3UAsr3K4I6qtAmlQcZDesFNEHPZAzj8=
|
github.com/armon/consul-api v0.0.0-20180202201655-eb2c6b5be1b6/go.mod h1:grANhF5doyWs3UAsr3K4I6qtAmlQcZDesFNEHPZAzj8=
|
||||||
github.com/aymerick/raymond v2.0.3-0.20180322193309-b565731e1464+incompatible/go.mod h1:osfaiScAUVup+UC9Nfq76eWqDhXlp+4UYaA8uhTBO6g=
|
github.com/aymerick/raymond v2.0.3-0.20180322193309-b565731e1464+incompatible/go.mod h1:osfaiScAUVup+UC9Nfq76eWqDhXlp+4UYaA8uhTBO6g=
|
||||||
|
github.com/beorn7/perks v1.0.1 h1:VlbKKnNfV8bJzeqoa4cOKqO6bYr3WgKZxO8Z16+hsOM=
|
||||||
|
github.com/beorn7/perks v1.0.1/go.mod h1:G2ZrVWU2WbWT9wwq4/hrbKbnv/1ERSJQ0ibhJ6rlkpw=
|
||||||
github.com/census-instrumentation/opencensus-proto v0.2.1/go.mod h1:f6KPmirojxKA12rnyqOA5BBL4O983OfeGPqjHWSTneU=
|
github.com/census-instrumentation/opencensus-proto v0.2.1/go.mod h1:f6KPmirojxKA12rnyqOA5BBL4O983OfeGPqjHWSTneU=
|
||||||
github.com/cespare/xxhash/v2 v2.1.1/go.mod h1:VGX0DQ3Q6kWi7AoAeZDth3/j3BFtOZR5XLFGgcrjCOs=
|
github.com/cespare/xxhash/v2 v2.2.0 h1:DC2CZ1Ep5Y4k3ZQ899DldepgrayRUGE6BBZ/cd9Cj44=
|
||||||
github.com/cespare/xxhash/v2 v2.1.2 h1:YRXhKfTDauu4ajMg1TPgFO5jnlC2HCbmLXMcTG5cbYE=
|
github.com/cespare/xxhash/v2 v2.2.0/go.mod h1:VGX0DQ3Q6kWi7AoAeZDth3/j3BFtOZR5XLFGgcrjCOs=
|
||||||
github.com/cespare/xxhash/v2 v2.1.2/go.mod h1:VGX0DQ3Q6kWi7AoAeZDth3/j3BFtOZR5XLFGgcrjCOs=
|
|
||||||
github.com/client9/misspell v0.3.4/go.mod h1:qj6jICC3Q7zFZvVWo7KLAzC3yx5G7kyvSDkc90ppPyw=
|
github.com/client9/misspell v0.3.4/go.mod h1:qj6jICC3Q7zFZvVWo7KLAzC3yx5G7kyvSDkc90ppPyw=
|
||||||
github.com/cncf/udpa/go v0.0.0-20191209042840-269d4d468f6f/go.mod h1:M8M6+tZqaGXZJjfX53e64911xZQV5JYwmTeXPW+k8Sc=
|
github.com/cncf/udpa/go v0.0.0-20201120205902-5459f2c99403/go.mod h1:WmhPx2Nbnhtbo57+VJT5O0JRkEi1Wbu0z5j0R8u5Hbk=
|
||||||
github.com/cockroachdb/datadriven v1.0.0/go.mod h1:5Ib8Meh+jk1RlHIXej6Pzevx/NLlNvQB9pmSBZErGA4=
|
github.com/cockroachdb/datadriven v1.0.2/go.mod h1:a9RdTaap04u637JoCzcUoIcDmvwSUtcUFtT/C3kJlTU=
|
||||||
github.com/cockroachdb/errors v1.6.1/go.mod h1:tm6FTP5G81vwJ5lC0SizQo374JNCOPrHyXGitRJoDqM=
|
github.com/cockroachdb/datadriven v1.0.3-0.20230413201302-be42291fc80f h1:otljaYPt5hWxV3MUfO5dFPFiOXg9CyG5/kCfayTqsJ4=
|
||||||
github.com/cockroachdb/errors v1.8.1 h1:A5+txlVZfOqFBDa4mGz2bUWSp0aHElvHX2bKkdbQu+Y=
|
github.com/cockroachdb/errors v1.9.1 h1:yFVvsI0VxmRShfawbt/laCIDy/mtTqqnvoNgiy5bEV8=
|
||||||
github.com/cockroachdb/errors v1.8.1/go.mod h1:qGwQn6JmZ+oMjuLwjWzUNqblqk0xl4CVV3SQbGwK7Ac=
|
github.com/cockroachdb/errors v1.9.1/go.mod h1:2sxOtL2WIc096WSZqZ5h8fa17rdDq9HZOZLBCor4mBk=
|
||||||
github.com/cockroachdb/logtags v0.0.0-20190617123548-eb05cc24525f h1:o/kfcElHqOiXqcou5a3rIlMc7oJbMQkeLk0VQJ7zgqY=
|
github.com/cockroachdb/logtags v0.0.0-20211118104740-dabe8e521a4f/go.mod h1:Vz9DsVWQQhf3vs21MhPMZpMGSht7O/2vFW2xusFUVOs=
|
||||||
github.com/cockroachdb/logtags v0.0.0-20190617123548-eb05cc24525f/go.mod h1:i/u985jwjWRlyHXQbwatDASoW0RMlZ/3i9yJHE2xLkI=
|
github.com/cockroachdb/logtags v0.0.0-20230118201751-21c54148d20b h1:r6VH0faHjZeQy818SGhaone5OnYfxFR/+AzdY3sf5aE=
|
||||||
github.com/cockroachdb/pebble v0.0.0-20220729140737-245afda9c39f h1:ZGX53mhE1cb3CoICFir642DOR6JzSSkft0M9L806Wgo=
|
github.com/cockroachdb/logtags v0.0.0-20230118201751-21c54148d20b/go.mod h1:Vz9DsVWQQhf3vs21MhPMZpMGSht7O/2vFW2xusFUVOs=
|
||||||
github.com/cockroachdb/pebble v0.0.0-20220729140737-245afda9c39f/go.mod h1:890yq1fUb9b6dGNwssgeUO5vQV9qfXnCPxAJhBQfXw0=
|
github.com/cockroachdb/pebble v0.0.0-20230517202617-f6eaf9a696e6 h1:qmPygPODBjUWt7dT3kR118Yn7y0Ol6ULetf78jj/fNQ=
|
||||||
github.com/cockroachdb/redact v1.0.8 h1:8QG/764wK+vmEYoOlfobpe12EQcS81ukx/a4hdVMxNw=
|
github.com/cockroachdb/pebble v0.0.0-20230517202617-f6eaf9a696e6/go.mod h1:TkdVsGYRqtULUppt2RbC+YaKtTHnHoWa2apfFrSKABw=
|
||||||
github.com/cockroachdb/redact v1.0.8/go.mod h1:BVNblN9mBWFyMyqK1k3AAiSxhvhfK2oOZZ2lK+dpvRg=
|
github.com/cockroachdb/redact v1.1.3/go.mod h1:BVNblN9mBWFyMyqK1k3AAiSxhvhfK2oOZZ2lK+dpvRg=
|
||||||
github.com/cockroachdb/sentry-go v0.6.1-cockroachdb.2 h1:IKgmqgMQlVJIZj19CdocBeSfSaiCbEBZGKODaixqtHM=
|
github.com/cockroachdb/redact v1.1.4 h1:Y0XrVI2FAyofNyGveodTN//qdpPtFKcKTeCBsK3AHAQ=
|
||||||
github.com/cockroachdb/sentry-go v0.6.1-cockroachdb.2/go.mod h1:8BT+cPK6xvFOcRlk0R8eg+OTkcqI6baNH4xAkpiYVvQ=
|
github.com/cockroachdb/redact v1.1.4/go.mod h1:BVNblN9mBWFyMyqK1k3AAiSxhvhfK2oOZZ2lK+dpvRg=
|
||||||
github.com/codegangsta/inject v0.0.0-20150114235600-33e0aa1cb7c0/go.mod h1:4Zcjuz89kmFXt9morQgcfYZAYZ5n8WHjt81YYWIwtTM=
|
github.com/codegangsta/inject v0.0.0-20150114235600-33e0aa1cb7c0/go.mod h1:4Zcjuz89kmFXt9morQgcfYZAYZ5n8WHjt81YYWIwtTM=
|
||||||
github.com/coreos/etcd v3.3.10+incompatible/go.mod h1:uF7uidLiAD3TWHmW31ZFd/JWoc32PjwdhPthX9715RE=
|
github.com/coreos/etcd v3.3.10+incompatible/go.mod h1:uF7uidLiAD3TWHmW31ZFd/JWoc32PjwdhPthX9715RE=
|
||||||
github.com/coreos/go-etcd v2.0.0+incompatible/go.mod h1:Jez6KQU2B/sWsbdaef3ED8NzMklzPG4d5KIOhIy30Tk=
|
github.com/coreos/go-etcd v2.0.0+incompatible/go.mod h1:Jez6KQU2B/sWsbdaef3ED8NzMklzPG4d5KIOhIy30Tk=
|
||||||
@@ -44,32 +39,29 @@ github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSs
|
|||||||
github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=
|
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/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
|
||||||
github.com/dgraph-io/badger v1.6.0/go.mod h1:zwt7syl517jmP8s94KqSxTlM6IMsdhYy6psNgSztDR4=
|
github.com/dgraph-io/badger v1.6.0/go.mod h1:zwt7syl517jmP8s94KqSxTlM6IMsdhYy6psNgSztDR4=
|
||||||
github.com/dgrijalva/jwt-go v3.2.0+incompatible/go.mod h1:E3ru+11k8xSBh+hMPgOLZmtrrCbhqsmaPHjLKYnJCaQ=
|
|
||||||
github.com/dgryski/go-farm v0.0.0-20190423205320-6a90982ecee2/go.mod h1:SqUrOPUnsFjfmXRMNPybcSiG0BgUW2AuFH8PAnS2iTw=
|
github.com/dgryski/go-farm v0.0.0-20190423205320-6a90982ecee2/go.mod h1:SqUrOPUnsFjfmXRMNPybcSiG0BgUW2AuFH8PAnS2iTw=
|
||||||
github.com/dgryski/go-rendezvous v0.0.0-20200823014737-9f7001d12a5f h1:lO4WD4F/rVNCu3HqELle0jiPLLBs70cWOduZpkS1E78=
|
github.com/dgryski/go-rendezvous v0.0.0-20200823014737-9f7001d12a5f h1:lO4WD4F/rVNCu3HqELle0jiPLLBs70cWOduZpkS1E78=
|
||||||
github.com/dgryski/go-rendezvous v0.0.0-20200823014737-9f7001d12a5f/go.mod h1:cuUVRXasLTGF7a8hSLbxyZXjz+1KgoB3wDUb6vlszIc=
|
github.com/dgryski/go-rendezvous v0.0.0-20200823014737-9f7001d12a5f/go.mod h1:cuUVRXasLTGF7a8hSLbxyZXjz+1KgoB3wDUb6vlszIc=
|
||||||
github.com/dustin/go-humanize v1.0.0/go.mod h1:HtrtbFcZ19U5GC7JDqmcUSB87Iq5E25KnS6fMYU6eOk=
|
github.com/dustin/go-humanize v1.0.0/go.mod h1:HtrtbFcZ19U5GC7JDqmcUSB87Iq5E25KnS6fMYU6eOk=
|
||||||
github.com/eknkc/amber v0.0.0-20171010120322-cdade1c07385/go.mod h1:0vRUJqYpeSZifjYj7uP3BG/gKcuzL9xWVV/Y+cK33KM=
|
github.com/eknkc/amber v0.0.0-20171010120322-cdade1c07385/go.mod h1:0vRUJqYpeSZifjYj7uP3BG/gKcuzL9xWVV/Y+cK33KM=
|
||||||
github.com/envoyproxy/go-control-plane v0.9.0/go.mod h1:YTl/9mNaCwkRvm6d1a2C3ymFceY/DCBVvsKhRF0iEA4=
|
github.com/envoyproxy/go-control-plane v0.9.0/go.mod h1:YTl/9mNaCwkRvm6d1a2C3ymFceY/DCBVvsKhRF0iEA4=
|
||||||
github.com/envoyproxy/go-control-plane v0.9.4/go.mod h1:6rpuAdCZL397s3pYoYcLgu1mIlRU8Am5FuJP05cCM98=
|
github.com/envoyproxy/go-control-plane v0.9.1-0.20191026205805-5f8ba28d4473/go.mod h1:YTl/9mNaCwkRvm6d1a2C3ymFceY/DCBVvsKhRF0iEA4=
|
||||||
|
github.com/envoyproxy/go-control-plane v0.9.9-0.20210217033140-668b12f5399d/go.mod h1:cXg6YxExXjJnVBQHBLXeUAgxn2UodCpnH306RInaBQk=
|
||||||
github.com/envoyproxy/protoc-gen-validate v0.1.0/go.mod h1:iSmxcyjqTsJpI2R4NaDN7+kN2VEUnK/pcBlmesArF7c=
|
github.com/envoyproxy/protoc-gen-validate v0.1.0/go.mod h1:iSmxcyjqTsJpI2R4NaDN7+kN2VEUnK/pcBlmesArF7c=
|
||||||
github.com/etcd-io/bbolt v1.3.3/go.mod h1:ZF2nL25h33cCyBtcyWeZ2/I3HQOfTP+0PIEvHjkjCrw=
|
github.com/etcd-io/bbolt v1.3.3/go.mod h1:ZF2nL25h33cCyBtcyWeZ2/I3HQOfTP+0PIEvHjkjCrw=
|
||||||
github.com/fasthttp-contrib/websocket v0.0.0-20160511215533-1f3b11f56072/go.mod h1:duJ4Jxv5lDcvg4QuQr0oowTf7dz4/CR8NtyCooz9HL8=
|
github.com/fasthttp-contrib/websocket v0.0.0-20160511215533-1f3b11f56072/go.mod h1:duJ4Jxv5lDcvg4QuQr0oowTf7dz4/CR8NtyCooz9HL8=
|
||||||
github.com/fatih/structs v1.1.0/go.mod h1:9NiDSp5zOcgEDl+j00MP/WkGVPOlPRLejGD8Ga6PJ7M=
|
github.com/fatih/structs v1.1.0/go.mod h1:9NiDSp5zOcgEDl+j00MP/WkGVPOlPRLejGD8Ga6PJ7M=
|
||||||
github.com/flosch/pongo2 v0.0.0-20190707114632-bbf5a6c351f4/go.mod h1:T9YF2M40nIgbVgp3rreNmTged+9HrbNTIQf1PsaIiTA=
|
|
||||||
github.com/fogleman/gg v1.2.1-0.20190220221249-0403632d5b90/go.mod h1:R/bRT+9gY/C5z7JzPU0zXsXHKM4/ayA+zqcVNZzPa1k=
|
|
||||||
github.com/fsnotify/fsnotify v1.4.7/go.mod h1:jwhsz4b93w/PPRr/qN1Yymfu8t87LnFCMoQvtojpjFo=
|
github.com/fsnotify/fsnotify v1.4.7/go.mod h1:jwhsz4b93w/PPRr/qN1Yymfu8t87LnFCMoQvtojpjFo=
|
||||||
github.com/fsnotify/fsnotify v1.4.9 h1:hsms1Qyu0jgnwNXIxa+/V/PDsU6CfLf6CNO8H7IWoS4=
|
github.com/fsnotify/fsnotify v1.4.9 h1:hsms1Qyu0jgnwNXIxa+/V/PDsU6CfLf6CNO8H7IWoS4=
|
||||||
github.com/fsnotify/fsnotify v1.4.9/go.mod h1:znqG4EE+3YCdAaPaxE2ZRY/06pZUdp0tY4IgpuI1SZQ=
|
|
||||||
github.com/gavv/httpexpect v2.0.0+incompatible/go.mod h1:x+9tiU1YnrOvnB725RkpoLv1M62hOWzwo5OXotisrKc=
|
github.com/gavv/httpexpect v2.0.0+incompatible/go.mod h1:x+9tiU1YnrOvnB725RkpoLv1M62hOWzwo5OXotisrKc=
|
||||||
github.com/ghemawat/stream v0.0.0-20171120220530-696b145b53b9/go.mod h1:106OIgooyS7OzLDOpUGgm9fA3bQENb/cFSyyBmMoJDs=
|
github.com/getsentry/sentry-go v0.12.0/go.mod h1:NSap0JBYWzHND8oMbyi0+XZhUalc1TBdRL1M71JZW2c=
|
||||||
|
github.com/getsentry/sentry-go v0.21.0 h1:c9l5F1nPF30JIppulk4veau90PK6Smu3abgVtVQWon4=
|
||||||
|
github.com/getsentry/sentry-go v0.21.0/go.mod h1:lc76E2QywIyW8WuBnwl8Lc4bkmQH4+w1gwTf25trprY=
|
||||||
github.com/gin-contrib/sse v0.0.0-20190301062529-5545eab6dad3/go.mod h1:VJ0WA2NBN22VlZ2dKZQPAPnyWw5XTlK1KymzLKsr59s=
|
github.com/gin-contrib/sse v0.0.0-20190301062529-5545eab6dad3/go.mod h1:VJ0WA2NBN22VlZ2dKZQPAPnyWw5XTlK1KymzLKsr59s=
|
||||||
github.com/gin-gonic/gin v1.4.0/go.mod h1:OW2EZn3DO8Ln9oIKOvM++LBO+5UPHJJDH72/q/3rZdM=
|
github.com/gin-gonic/gin v1.4.0/go.mod h1:OW2EZn3DO8Ln9oIKOvM++LBO+5UPHJJDH72/q/3rZdM=
|
||||||
github.com/go-check/check v0.0.0-20180628173108-788fd7840127/go.mod h1:9ES+weclKsC9YodN5RgxqK/VD9HM9JsCSh7rNhMZE98=
|
github.com/go-check/check v0.0.0-20180628173108-788fd7840127/go.mod h1:9ES+weclKsC9YodN5RgxqK/VD9HM9JsCSh7rNhMZE98=
|
||||||
github.com/go-errors/errors v1.0.1 h1:LUHzmkK3GUKUrL/1gfBUxAHzcev3apQlezX/+O7ma6w=
|
|
||||||
github.com/go-errors/errors v1.0.1/go.mod h1:f4zRHt4oKfwPJE5k8C9vpYG+aDHdBFUsgrm6/TyX73Q=
|
github.com/go-errors/errors v1.0.1/go.mod h1:f4zRHt4oKfwPJE5k8C9vpYG+aDHdBFUsgrm6/TyX73Q=
|
||||||
github.com/go-gl/glfw v0.0.0-20190409004039-e6da0acd62b1/go.mod h1:vR7hzQXu2zJy9AVAgeJqvqgH9Q5CA+iKCZ2gyEVpxRU=
|
github.com/go-errors/errors v1.4.2 h1:J6MZopCL4uSllY1OfXM374weqZFFItUbrImctkmUxIA=
|
||||||
github.com/go-gl/glfw/v3.3/glfw v0.0.0-20200222043503-6f7a984d4dc4/go.mod h1:tQ2UAYgL5IevRw8kRxooKSPJfGvJ9fJQFa0TUsXzTg8=
|
|
||||||
github.com/go-martini/martini v0.0.0-20170121215854-22fa46961aab/go.mod h1:/P9AEU963A2AYjv4d1V5eVL1CQbEJq6aCNHDDjibzu8=
|
github.com/go-martini/martini v0.0.0-20170121215854-22fa46961aab/go.mod h1:/P9AEU963A2AYjv4d1V5eVL1CQbEJq6aCNHDDjibzu8=
|
||||||
github.com/go-redis/redis/v8 v8.11.5 h1:AcZZR7igkdvfVmQTPnu9WE37LRrO/YrBH5zWyjDC0oI=
|
github.com/go-redis/redis/v8 v8.11.5 h1:AcZZR7igkdvfVmQTPnu9WE37LRrO/YrBH5zWyjDC0oI=
|
||||||
github.com/go-redis/redis/v8 v8.11.5/go.mod h1:gREzHqY1hg6oD9ngVRbLStwAWKhA0FEgq8Jd4h5lpwo=
|
github.com/go-redis/redis/v8 v8.11.5/go.mod h1:gREzHqY1hg6oD9ngVRbLStwAWKhA0FEgq8Jd4h5lpwo=
|
||||||
@@ -77,117 +69,143 @@ github.com/gobwas/httphead v0.0.0-20180130184737-2c6c146eadee/go.mod h1:L0fX3K22
|
|||||||
github.com/gobwas/pool v0.2.0/go.mod h1:q8bcK0KcYlCgd9e7WYLm9LpyS+YeLd8JVDW6WezmKEw=
|
github.com/gobwas/pool v0.2.0/go.mod h1:q8bcK0KcYlCgd9e7WYLm9LpyS+YeLd8JVDW6WezmKEw=
|
||||||
github.com/gobwas/ws v1.0.2/go.mod h1:szmBTxLgaFppYjEmNtny/v3w89xOydFnnZMcgRRu/EM=
|
github.com/gobwas/ws v1.0.2/go.mod h1:szmBTxLgaFppYjEmNtny/v3w89xOydFnnZMcgRRu/EM=
|
||||||
github.com/gogo/googleapis v0.0.0-20180223154316-0cd9801be74a/go.mod h1:gf4bu3Q80BeJ6H1S1vYPm8/ELATdvryBaNFGgqEef3s=
|
github.com/gogo/googleapis v0.0.0-20180223154316-0cd9801be74a/go.mod h1:gf4bu3Q80BeJ6H1S1vYPm8/ELATdvryBaNFGgqEef3s=
|
||||||
|
github.com/gogo/googleapis v1.4.1/go.mod h1:2lpHqI5OcWCtVElxXnPt+s8oJvMpySlOyM6xDCrzib4=
|
||||||
github.com/gogo/protobuf v1.2.0/go.mod h1:r8qH/GZQm5c6nD/R0oafs1akxWv10x8SbQlK7atdtwQ=
|
github.com/gogo/protobuf v1.2.0/go.mod h1:r8qH/GZQm5c6nD/R0oafs1akxWv10x8SbQlK7atdtwQ=
|
||||||
github.com/gogo/protobuf v1.3.1 h1:DqDEcV5aeaTmdFBePNpYsp3FlcVH/2ISVVM9Qf8PSls=
|
github.com/gogo/protobuf v1.3.2 h1:Ov1cvc58UF3b5XjBnZv7+opcTcQFZebYjWzi34vdm4Q=
|
||||||
github.com/gogo/protobuf v1.3.1/go.mod h1:SlYgWuQ5SjCEi6WLHjHCa1yvBfUnHcTbrrZtXPKa29o=
|
github.com/gogo/protobuf v1.3.2/go.mod h1:P1XiOD3dCwIKUDQYPy72D8LYyHL2YPYrpS2s69NZV8Q=
|
||||||
github.com/gogo/status v1.1.0/go.mod h1:BFv9nrluPLmrS0EmGVvLaPNmRosr9KapBYd5/hpY1WM=
|
github.com/gogo/status v1.1.0/go.mod h1:BFv9nrluPLmrS0EmGVvLaPNmRosr9KapBYd5/hpY1WM=
|
||||||
github.com/golang/freetype v0.0.0-20170609003504-e2365dfdc4a0/go.mod h1:E/TSTwGwJL78qG/PmXZO1EjYhfJinVAhrmmHX6Z8B9k=
|
github.com/golang-jwt/jwt v3.2.2+incompatible/go.mod h1:8pz2t5EyA70fFQQSrl6XZXzqecmYZeUEB8OUGHkxJ+I=
|
||||||
github.com/golang/glog v0.0.0-20160126235308-23def4e6c14b/go.mod h1:SBH7ygxi8pfUlaOkMMuAQtPIUF8ecWP5IEl/CR7VP2Q=
|
github.com/golang/glog v0.0.0-20160126235308-23def4e6c14b/go.mod h1:SBH7ygxi8pfUlaOkMMuAQtPIUF8ecWP5IEl/CR7VP2Q=
|
||||||
github.com/golang/mock v1.1.1/go.mod h1:oTYuIxOrZwtPieC+H1uAHpcLFnEyAGVDL/k47Jfbm0A=
|
github.com/golang/mock v1.1.1/go.mod h1:oTYuIxOrZwtPieC+H1uAHpcLFnEyAGVDL/k47Jfbm0A=
|
||||||
github.com/golang/protobuf v1.2.0/go.mod h1:6lQm79b+lXiMfvg/cZm0SGofjICqVBUtrP5yJMmIC1U=
|
github.com/golang/protobuf v1.2.0/go.mod h1:6lQm79b+lXiMfvg/cZm0SGofjICqVBUtrP5yJMmIC1U=
|
||||||
github.com/golang/protobuf v1.3.1/go.mod h1:6lQm79b+lXiMfvg/cZm0SGofjICqVBUtrP5yJMmIC1U=
|
github.com/golang/protobuf v1.3.1/go.mod h1:6lQm79b+lXiMfvg/cZm0SGofjICqVBUtrP5yJMmIC1U=
|
||||||
github.com/golang/protobuf v1.3.2/go.mod h1:6lQm79b+lXiMfvg/cZm0SGofjICqVBUtrP5yJMmIC1U=
|
github.com/golang/protobuf v1.3.2/go.mod h1:6lQm79b+lXiMfvg/cZm0SGofjICqVBUtrP5yJMmIC1U=
|
||||||
github.com/golang/protobuf v1.3.3/go.mod h1:vzj43D7+SQXF/4pzW/hwtAqwc6iTitCiVSaWz5lYuqw=
|
|
||||||
github.com/golang/protobuf v1.4.0-rc.1/go.mod h1:ceaxUfeHdC40wWswd/P6IGgMaK3YpKi5j83Wpe3EHw8=
|
github.com/golang/protobuf v1.4.0-rc.1/go.mod h1:ceaxUfeHdC40wWswd/P6IGgMaK3YpKi5j83Wpe3EHw8=
|
||||||
github.com/golang/protobuf v1.4.0-rc.1.0.20200221234624-67d41d38c208/go.mod h1:xKAWHe0F5eneWXFV3EuXVDTCmh+JuBKY0li0aMyXATA=
|
github.com/golang/protobuf v1.4.0-rc.1.0.20200221234624-67d41d38c208/go.mod h1:xKAWHe0F5eneWXFV3EuXVDTCmh+JuBKY0li0aMyXATA=
|
||||||
github.com/golang/protobuf v1.4.0-rc.2/go.mod h1:LlEzMj4AhA7rCAGe4KMBDvJI+AwstrUpVNzEA03Pprs=
|
github.com/golang/protobuf v1.4.0-rc.2/go.mod h1:LlEzMj4AhA7rCAGe4KMBDvJI+AwstrUpVNzEA03Pprs=
|
||||||
github.com/golang/protobuf v1.4.0-rc.4.0.20200313231945-b860323f09d0/go.mod h1:WU3c8KckQ9AFe+yFwt9sWVRKCVIyN9cPHBJSNnbL67w=
|
github.com/golang/protobuf v1.4.0-rc.4.0.20200313231945-b860323f09d0/go.mod h1:WU3c8KckQ9AFe+yFwt9sWVRKCVIyN9cPHBJSNnbL67w=
|
||||||
github.com/golang/protobuf v1.4.0/go.mod h1:jodUvKwWbYaEsadDk5Fwe5c77LiNKVO9IDvqG2KuDX0=
|
github.com/golang/protobuf v1.4.0/go.mod h1:jodUvKwWbYaEsadDk5Fwe5c77LiNKVO9IDvqG2KuDX0=
|
||||||
|
github.com/golang/protobuf v1.4.1/go.mod h1:U8fpvMrcmy5pZrNK1lt4xCsGvpyWQ/VVv6QDs8UjoX8=
|
||||||
github.com/golang/protobuf v1.4.2/go.mod h1:oDoupMAO8OvCJWAcko0GGGIgR6R6ocIYbsSw735rRwI=
|
github.com/golang/protobuf v1.4.2/go.mod h1:oDoupMAO8OvCJWAcko0GGGIgR6R6ocIYbsSw735rRwI=
|
||||||
github.com/golang/snappy v0.0.3 h1:fHPg5GQYlCeLIPB9BZqMVR5nR9A+IM5zcgeTdjMYmLA=
|
github.com/golang/protobuf v1.5.0/go.mod h1:FsONVRAS9T7sI+LIUmWTfcYkHO4aIWwzhcaSAoJOfIk=
|
||||||
github.com/golang/snappy v0.0.3/go.mod h1:/XxbfmMg8lxefKM7IXC3fBNl/7bRcc72aCRzEWrmP2Q=
|
github.com/golang/protobuf v1.5.2/go.mod h1:XVQd3VNwM+JqD3oG2Ue2ip4fOMUkwXdXDdiuN0vRsmY=
|
||||||
|
github.com/golang/protobuf v1.5.3 h1:KhyjKVUg7Usr/dYsdSqoFveMYd5ko72D+zANwlG1mmg=
|
||||||
|
github.com/golang/protobuf v1.5.3/go.mod h1:XVQd3VNwM+JqD3oG2Ue2ip4fOMUkwXdXDdiuN0vRsmY=
|
||||||
|
github.com/golang/snappy v0.0.4 h1:yAGX7huGHXlcLOEtBnF4w7FQwA26wojNCwOYAEhLjQM=
|
||||||
|
github.com/golang/snappy v0.0.4/go.mod h1:/XxbfmMg8lxefKM7IXC3fBNl/7bRcc72aCRzEWrmP2Q=
|
||||||
github.com/gomodule/redigo v1.7.1-0.20190724094224-574c33c3df38/go.mod h1:B4C85qUVwatsJoIUNIfCRsp7qO0iAmpGFZ4EELWSbC4=
|
github.com/gomodule/redigo v1.7.1-0.20190724094224-574c33c3df38/go.mod h1:B4C85qUVwatsJoIUNIfCRsp7qO0iAmpGFZ4EELWSbC4=
|
||||||
github.com/google/go-cmp v0.2.0/go.mod h1:oXzfMopK8JAjlY9xF4vHSVASa0yLyX7SntLO5aqRK0M=
|
github.com/google/go-cmp v0.2.0/go.mod h1:oXzfMopK8JAjlY9xF4vHSVASa0yLyX7SntLO5aqRK0M=
|
||||||
github.com/google/go-cmp v0.3.0/go.mod h1:8QqcDgzrUqlUb/G2PQTWiueGozuR1884gddMywk6iLU=
|
github.com/google/go-cmp v0.3.0/go.mod h1:8QqcDgzrUqlUb/G2PQTWiueGozuR1884gddMywk6iLU=
|
||||||
github.com/google/go-cmp v0.3.1/go.mod h1:8QqcDgzrUqlUb/G2PQTWiueGozuR1884gddMywk6iLU=
|
github.com/google/go-cmp v0.3.1/go.mod h1:8QqcDgzrUqlUb/G2PQTWiueGozuR1884gddMywk6iLU=
|
||||||
github.com/google/go-cmp v0.4.0/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE=
|
github.com/google/go-cmp v0.4.0/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE=
|
||||||
github.com/google/go-cmp v0.5.4 h1:L8R9j+yAqZuZjsqh/z+F1NCffTKKLShY6zXTItVIZ8M=
|
github.com/google/go-cmp v0.5.0/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE=
|
||||||
github.com/google/go-cmp v0.5.4/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE=
|
github.com/google/go-cmp v0.5.5/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE=
|
||||||
|
github.com/google/go-cmp v0.5.9 h1:O2Tfq5qg4qc4AmwVlvv0oLiVAGB7enBSJ2x2DqQFi38=
|
||||||
github.com/google/go-querystring v1.0.0/go.mod h1:odCYkC5MyYFN7vkCjXpyrEuKhc/BUO6wN/zVPAxq5ck=
|
github.com/google/go-querystring v1.0.0/go.mod h1:odCYkC5MyYFN7vkCjXpyrEuKhc/BUO6wN/zVPAxq5ck=
|
||||||
|
github.com/google/gofuzz v1.0.0/go.mod h1:dBl0BpW6vV/+mYPU4Po3pmUjxk6FQPldtuIdl/M65Eg=
|
||||||
|
github.com/google/uuid v1.1.2/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo=
|
||||||
github.com/gopherjs/gopherjs v0.0.0-20181017120253-0766667cb4d1/go.mod h1:wJfORRmW1u3UXTncJ5qlYoELFm8eSnnEO6hX4iZ3EWY=
|
github.com/gopherjs/gopherjs v0.0.0-20181017120253-0766667cb4d1/go.mod h1:wJfORRmW1u3UXTncJ5qlYoELFm8eSnnEO6hX4iZ3EWY=
|
||||||
github.com/gorilla/websocket v1.4.0/go.mod h1:E7qHFY5m1UJ88s3WnNqhKjPHQ0heANvMoAMk2YaljkQ=
|
github.com/gorilla/websocket v1.4.1/go.mod h1:YR8l580nyteQvAITg2hZ9XVh4b55+EU/adAjf1fMHhE=
|
||||||
github.com/hashicorp/go-version v1.2.0/go.mod h1:fltr4n8CU8Ke44wwGCBoEymUuxUHl09ZGVZPK5anwXA=
|
github.com/hashicorp/go-version v1.2.0/go.mod h1:fltr4n8CU8Ke44wwGCBoEymUuxUHl09ZGVZPK5anwXA=
|
||||||
github.com/hashicorp/go-version v1.6.0/go.mod h1:fltr4n8CU8Ke44wwGCBoEymUuxUHl09ZGVZPK5anwXA=
|
|
||||||
github.com/hashicorp/hcl v1.0.0/go.mod h1:E5yfLk+7swimpb2L/Alb/PJmXilQ/rhwaUYs4T20WEQ=
|
github.com/hashicorp/hcl v1.0.0/go.mod h1:E5yfLk+7swimpb2L/Alb/PJmXilQ/rhwaUYs4T20WEQ=
|
||||||
github.com/hjson/hjson-go v3.1.0+incompatible h1:DY/9yE8ey8Zv22bY+mHV1uk2yRy0h8tKhZ77hEdi0Aw=
|
github.com/hjson/hjson-go v3.3.0+incompatible h1:Rqr+Ya+0aCJMjaE4s8E9YKvuJLuLVpEvz4ONum52vnI=
|
||||||
github.com/hjson/hjson-go v3.1.0+incompatible/go.mod h1:qsetwF8NlsTsOTwZTApNlTCerV+b2GjYRRcIk4JMFio=
|
github.com/hjson/hjson-go v3.3.0+incompatible/go.mod h1:qsetwF8NlsTsOTwZTApNlTCerV+b2GjYRRcIk4JMFio=
|
||||||
github.com/hpcloud/tail v1.0.0/go.mod h1:ab1qPbhIpdTxEkNHXyeSf5vhxWSCs/tWer42PpOxQnU=
|
github.com/hpcloud/tail v1.0.0/go.mod h1:ab1qPbhIpdTxEkNHXyeSf5vhxWSCs/tWer42PpOxQnU=
|
||||||
github.com/hydrogen18/memlistener v0.0.0-20141126152155-54553eb933fb/go.mod h1:qEIFzExnS6016fRpRfxrExeVn2gbClQA99gQhnIcdhE=
|
github.com/hydrogen18/memlistener v0.0.0-20200120041712-dcc25e7acd91/go.mod h1:qEIFzExnS6016fRpRfxrExeVn2gbClQA99gQhnIcdhE=
|
||||||
github.com/imkira/go-interpol v1.1.0/go.mod h1:z0h2/2T3XF8kyEPpRgJ3kmNv+C43p+I/CoI+jC3w2iA=
|
github.com/imkira/go-interpol v1.1.0/go.mod h1:z0h2/2T3XF8kyEPpRgJ3kmNv+C43p+I/CoI+jC3w2iA=
|
||||||
github.com/inconshreveable/mousetrap v1.0.0/go.mod h1:PxqpIevigyE2G7u3NXJIT2ANytuPF1OarO4DADm73n8=
|
github.com/inconshreveable/mousetrap v1.0.0/go.mod h1:PxqpIevigyE2G7u3NXJIT2ANytuPF1OarO4DADm73n8=
|
||||||
github.com/iris-contrib/blackfriday v2.0.0+incompatible/go.mod h1:UzZ2bDEoaSGPbkg6SAB4att1aAwTmVIx/5gCVqeyUdI=
|
github.com/iris-contrib/blackfriday v2.0.0+incompatible/go.mod h1:UzZ2bDEoaSGPbkg6SAB4att1aAwTmVIx/5gCVqeyUdI=
|
||||||
github.com/iris-contrib/go.uuid v2.0.0+incompatible/go.mod h1:iz2lgM/1UnEf1kP0L/+fafWORmlnuysV2EMP8MW+qe0=
|
github.com/iris-contrib/go.uuid v2.0.0+incompatible/go.mod h1:iz2lgM/1UnEf1kP0L/+fafWORmlnuysV2EMP8MW+qe0=
|
||||||
github.com/iris-contrib/i18n v0.0.0-20171121225848-987a633949d0/go.mod h1:pMCz62A0xJL6I+umB2YTlFRwWXaDFA0jy+5HzGiJjqI=
|
github.com/iris-contrib/jade v1.1.3/go.mod h1:H/geBymxJhShH5kecoiOCSssPX7QWYH7UaeZTSWddIk=
|
||||||
|
github.com/iris-contrib/pongo2 v0.0.1/go.mod h1:Ssh+00+3GAZqSQb30AvBRNxBx7rf0GqwkjqxNd0u65g=
|
||||||
github.com/iris-contrib/schema v0.0.1/go.mod h1:urYA3uvUNG1TIIjOSCzHr9/LmbQo8LrOcOqfqxa4hXw=
|
github.com/iris-contrib/schema v0.0.1/go.mod h1:urYA3uvUNG1TIIjOSCzHr9/LmbQo8LrOcOqfqxa4hXw=
|
||||||
github.com/json-iterator/go v1.1.6/go.mod h1:+SdeFBvtyEkXs7REEP0seUULqWtbJapLOCVDaaPEHmU=
|
github.com/json-iterator/go v1.1.6/go.mod h1:+SdeFBvtyEkXs7REEP0seUULqWtbJapLOCVDaaPEHmU=
|
||||||
|
github.com/json-iterator/go v1.1.9/go.mod h1:KdQUCv79m/52Kvf8AW2vK1V8akMuk1QjK/uOdHXbAo4=
|
||||||
github.com/jtolds/gls v4.20.0+incompatible/go.mod h1:QJZ7F/aHp+rZTRtaJ1ow/lLfFfVYBRgL+9YlvaHOwJU=
|
github.com/jtolds/gls v4.20.0+incompatible/go.mod h1:QJZ7F/aHp+rZTRtaJ1ow/lLfFfVYBRgL+9YlvaHOwJU=
|
||||||
github.com/juju/errors v0.0.0-20181118221551-089d3ea4e4d5/go.mod h1:W54LbzXuIE0boCoNJfwqpmkKJ1O4TCTZMetAt6jGk7Q=
|
|
||||||
github.com/juju/loggo v0.0.0-20180524022052-584905176618/go.mod h1:vgyd7OREkbtVEN/8IXZe5Ooef3LQePvuBm9UWj6ZL8U=
|
|
||||||
github.com/juju/testing v0.0.0-20180920084828-472a3e8b2073/go.mod h1:63prj8cnj0tU0S9OHjGJn+b1h0ZghCndfnbQolrYTwA=
|
|
||||||
github.com/jung-kurt/gofpdf v1.0.3-0.20190309125859-24315acbbda5/go.mod h1:7Id9E/uU8ce6rXgefFLlgrJj/GYY22cpxn+r32jIOes=
|
|
||||||
github.com/k0kubun/colorstring v0.0.0-20150214042306-9440f1994b88/go.mod h1:3w7q1U84EfirKl04SVQ/s7nPm1ZPhiXd34z40TNz36k=
|
github.com/k0kubun/colorstring v0.0.0-20150214042306-9440f1994b88/go.mod h1:3w7q1U84EfirKl04SVQ/s7nPm1ZPhiXd34z40TNz36k=
|
||||||
github.com/kataras/golog v0.0.9/go.mod h1:12HJgwBIZFNGL0EJnMRhmvGA0PQGx8VFwrZtM4CqbAk=
|
github.com/kataras/golog v0.0.10/go.mod h1:yJ8YKCmyL+nWjERB90Qwn+bdyBZsaQwU3bTVFgkFIp8=
|
||||||
github.com/kataras/iris/v12 v12.0.1/go.mod h1:udK4vLQKkdDqMGJJVd/msuMtN6hpYJhg/lSzuxjhO+U=
|
github.com/kataras/iris/v12 v12.1.8/go.mod h1:LMYy4VlP67TQ3Zgriz8RE2h2kMZV2SgMYbq3UhfoFmE=
|
||||||
github.com/kataras/neffos v0.0.10/go.mod h1:ZYmJC07hQPW67eKuzlfY7SO3bC0mw83A3j6im82hfqw=
|
github.com/kataras/neffos v0.0.14/go.mod h1:8lqADm8PnbeFfL7CLXh1WHw53dG27MC3pgi2R1rmoTE=
|
||||||
github.com/kataras/pio v0.0.0-20190103105442-ea782b38602d/go.mod h1:NV88laa9UiiDuX9AhMbDPkGYSPugBOV6yTZB1l2K9Z0=
|
github.com/kataras/pio v0.0.2/go.mod h1:hAoW0t9UmXi4R5Oyq5Z4irTbaTsOemSrDGUtaTl7Dro=
|
||||||
github.com/kisielk/errcheck v1.2.0/go.mod h1:/BMXB+zMLi60iA8Vv6Ksmxu/1UDYcXs4uQLJ+jE2L00=
|
github.com/kataras/sitemap v0.0.5/go.mod h1:KY2eugMKiPwsJgx7+U103YZehfvNGOXURubcGyk0Bz8=
|
||||||
|
github.com/kisielk/errcheck v1.5.0/go.mod h1:pFxgyoBC7bSaBwPgfKdkLd5X25qrDl4LWUI2bnpBCr8=
|
||||||
github.com/kisielk/gotool v1.0.0/go.mod h1:XhKaO+MFFWcvkIS/tQcRk01m1F5IRFswLeQ+oQHNcck=
|
github.com/kisielk/gotool v1.0.0/go.mod h1:XhKaO+MFFWcvkIS/tQcRk01m1F5IRFswLeQ+oQHNcck=
|
||||||
github.com/klauspost/compress v1.8.2/go.mod h1:RyIbtBH6LamlWaDj8nUwkbUhJ87Yi3uG0guNDohfE1A=
|
github.com/klauspost/compress v1.8.2/go.mod h1:RyIbtBH6LamlWaDj8nUwkbUhJ87Yi3uG0guNDohfE1A=
|
||||||
github.com/klauspost/compress v1.9.0/go.mod h1:RyIbtBH6LamlWaDj8nUwkbUhJ87Yi3uG0guNDohfE1A=
|
github.com/klauspost/compress v1.9.7/go.mod h1:RyIbtBH6LamlWaDj8nUwkbUhJ87Yi3uG0guNDohfE1A=
|
||||||
github.com/klauspost/compress v1.11.7 h1:0hzRabrMN4tSTvMfnL3SCv1ZGeAP23ynzodBgaHeMeg=
|
github.com/klauspost/compress v1.16.5 h1:IFV2oUNUzZaz+XyusxpLzpzS8Pt5rh0Z16For/djlyI=
|
||||||
github.com/klauspost/compress v1.11.7/go.mod h1:aoV0uJVorq1K+umq18yTdKaF57EivdYsUV+/s2qKfXs=
|
github.com/klauspost/compress v1.16.5/go.mod h1:ntbaceVETuRiXiv4DpjP66DpAtAGkEQskQzEyD//IeE=
|
||||||
github.com/klauspost/cpuid v1.2.1/go.mod h1:Pj4uuM528wm8OyEC2QMXAi2YiTZ96dNQPGgoMS4s3ek=
|
github.com/klauspost/cpuid v1.2.1/go.mod h1:Pj4uuM528wm8OyEC2QMXAi2YiTZ96dNQPGgoMS4s3ek=
|
||||||
github.com/kr/pretty v0.1.0 h1:L/CwN0zerZDmRFUapSPitk6f+Q3+0za1rQkzVuMiMFI=
|
|
||||||
github.com/kr/pretty v0.1.0/go.mod h1:dAy3ld7l9f0ibDNOQOHHMYYIIbhfbHSm3C4ZsoJORNo=
|
github.com/kr/pretty v0.1.0/go.mod h1:dAy3ld7l9f0ibDNOQOHHMYYIIbhfbHSm3C4ZsoJORNo=
|
||||||
|
github.com/kr/pretty v0.3.0/go.mod h1:640gp4NfQd8pI5XOwp5fnNeVWj67G7CFk/SaSQn7NBk=
|
||||||
|
github.com/kr/pretty v0.3.1 h1:flRD4NNwYAUpkphVc1HcthR4KEIFJ65n8Mw5qdRn3LE=
|
||||||
|
github.com/kr/pretty v0.3.1/go.mod h1:hoEshYVHaxMs3cyo3Yncou5ZscifuDolrwPKZanG3xk=
|
||||||
github.com/kr/pty v1.1.1/go.mod h1:pFQYn66WHrOpPYNljwOMqo10TkYh1fy3cYio2l3bCsQ=
|
github.com/kr/pty v1.1.1/go.mod h1:pFQYn66WHrOpPYNljwOMqo10TkYh1fy3cYio2l3bCsQ=
|
||||||
github.com/kr/text v0.1.0/go.mod h1:4Jbv+DJW3UT/LiOwJeYQe1efqtUx/iVham/4vfdArNI=
|
github.com/kr/text v0.1.0/go.mod h1:4Jbv+DJW3UT/LiOwJeYQe1efqtUx/iVham/4vfdArNI=
|
||||||
github.com/kr/text v0.2.0 h1:5Nx0Ya0ZqY2ygV366QzturHI13Jq95ApcVaJBhpS+AY=
|
github.com/kr/text v0.2.0 h1:5Nx0Ya0ZqY2ygV366QzturHI13Jq95ApcVaJBhpS+AY=
|
||||||
github.com/kr/text v0.2.0/go.mod h1:eLer722TekiGuMkidMxC/pM04lWEeraHUUmBw8l2grE=
|
github.com/kr/text v0.2.0/go.mod h1:eLer722TekiGuMkidMxC/pM04lWEeraHUUmBw8l2grE=
|
||||||
github.com/labstack/echo/v4 v4.1.11/go.mod h1:i541M3Fj6f76NZtHSj7TXnyM8n2gaodfvfxNnFqi74g=
|
github.com/labstack/echo/v4 v4.5.0/go.mod h1:czIriw4a0C1dFun+ObrXp7ok03xON0N1awStJ6ArI7Y=
|
||||||
github.com/labstack/gommon v0.3.0/go.mod h1:MULnywXg0yavhxWKc+lOruYdAhDwPK9wf0OL7NoOu+k=
|
github.com/labstack/gommon v0.3.0/go.mod h1:MULnywXg0yavhxWKc+lOruYdAhDwPK9wf0OL7NoOu+k=
|
||||||
github.com/magiconair/properties v1.8.0/go.mod h1:PppfXfuXeibc/6YijjN8zIbojt8czPbwD3XqdrwzmxQ=
|
github.com/magiconair/properties v1.8.0/go.mod h1:PppfXfuXeibc/6YijjN8zIbojt8czPbwD3XqdrwzmxQ=
|
||||||
github.com/mattn/go-colorable v0.1.2/go.mod h1:U0ppj6V5qS13XJ6of8GYAs25YV2eR4EVcfRqFIhoBtE=
|
github.com/mattn/go-colorable v0.1.2/go.mod h1:U0ppj6V5qS13XJ6of8GYAs25YV2eR4EVcfRqFIhoBtE=
|
||||||
|
github.com/mattn/go-colorable v0.1.8/go.mod h1:u6P/XSegPjTcexA+o6vUJrdnUu04hMope9wVRipJSqc=
|
||||||
|
github.com/mattn/go-colorable v0.1.11/go.mod h1:u5H1YNBxpqRaxsYJYSkiCWKzEfiAb1Gb520KVy5xxl4=
|
||||||
github.com/mattn/go-isatty v0.0.7/go.mod h1:Iq45c/XA43vh69/j3iqttzPXn0bhXyGjM0Hdxcsrc5s=
|
github.com/mattn/go-isatty v0.0.7/go.mod h1:Iq45c/XA43vh69/j3iqttzPXn0bhXyGjM0Hdxcsrc5s=
|
||||||
github.com/mattn/go-isatty v0.0.8/go.mod h1:Iq45c/XA43vh69/j3iqttzPXn0bhXyGjM0Hdxcsrc5s=
|
github.com/mattn/go-isatty v0.0.8/go.mod h1:Iq45c/XA43vh69/j3iqttzPXn0bhXyGjM0Hdxcsrc5s=
|
||||||
github.com/mattn/go-isatty v0.0.9/go.mod h1:YNRxwqDuOph6SZLI9vUUz6OYw3QyUt7WiY2yME+cCiQ=
|
github.com/mattn/go-isatty v0.0.9/go.mod h1:YNRxwqDuOph6SZLI9vUUz6OYw3QyUt7WiY2yME+cCiQ=
|
||||||
|
github.com/mattn/go-isatty v0.0.12/go.mod h1:cbi8OIDigv2wuxKPP5vlRcQ1OAZbq2CE4Kysco4FUpU=
|
||||||
|
github.com/mattn/go-isatty v0.0.14/go.mod h1:7GGIvUiUoEMVVmxf/4nioHXj79iQHKdU27kJ6hsGG94=
|
||||||
github.com/mattn/goveralls v0.0.2/go.mod h1:8d1ZMHsd7fW6IRPKQh46F2WRpyib5/X4FOpevwGNQEw=
|
github.com/mattn/goveralls v0.0.2/go.mod h1:8d1ZMHsd7fW6IRPKQh46F2WRpyib5/X4FOpevwGNQEw=
|
||||||
github.com/mediocregopher/mediocre-go-lib v0.0.0-20181029021733-cb65787f37ed/go.mod h1:dSsfyI2zABAdhcbvkXqgxOxrCsbYeHCPgrZkku60dSg=
|
github.com/matttproud/golang_protobuf_extensions v1.0.4 h1:mmDVorXM7PCGKw94cs5zkfA9PSy5pEvNWRP0ET0TIVo=
|
||||||
github.com/mediocregopher/radix/v3 v3.3.0/go.mod h1:EmfVyvspXz1uZEyPBMyGK+kjWiKQGvsUt6O3Pj+LDCQ=
|
github.com/matttproud/golang_protobuf_extensions v1.0.4/go.mod h1:BSXmuO+STAnVfrANrmjBb36TMTDstsz7MSK+HVaYKv4=
|
||||||
|
github.com/mediocregopher/radix/v3 v3.4.2/go.mod h1:8FL3F6UQRXHXIBSPUs5h0RybMF8i4n7wVopoX3x7Bv8=
|
||||||
github.com/microcosm-cc/bluemonday v1.0.2/go.mod h1:iVP4YcDBq+n/5fb23BhYFvIMq/leAFZyRl6bYmGDlGc=
|
github.com/microcosm-cc/bluemonday v1.0.2/go.mod h1:iVP4YcDBq+n/5fb23BhYFvIMq/leAFZyRl6bYmGDlGc=
|
||||||
github.com/mitchellh/go-homedir v1.1.0/go.mod h1:SfyaCUpYCn1Vlf4IUYiD9fPX4A5wJrkLzIz1N1q0pr0=
|
github.com/mitchellh/go-homedir v1.1.0/go.mod h1:SfyaCUpYCn1Vlf4IUYiD9fPX4A5wJrkLzIz1N1q0pr0=
|
||||||
github.com/mitchellh/mapstructure v1.1.2/go.mod h1:FVVH3fgwuzCH5S8UJGiWEs2h04kUh9fWfEaFds41c1Y=
|
github.com/mitchellh/mapstructure v1.1.2/go.mod h1:FVVH3fgwuzCH5S8UJGiWEs2h04kUh9fWfEaFds41c1Y=
|
||||||
|
github.com/modern-go/concurrent v0.0.0-20180228061459-e0a39a4cb421/go.mod h1:6dJC0mAP4ikYIbvyc7fijjWJddQyLn8Ig3JB5CqoB9Q=
|
||||||
github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd/go.mod h1:6dJC0mAP4ikYIbvyc7fijjWJddQyLn8Ig3JB5CqoB9Q=
|
github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd/go.mod h1:6dJC0mAP4ikYIbvyc7fijjWJddQyLn8Ig3JB5CqoB9Q=
|
||||||
|
github.com/modern-go/reflect2 v0.0.0-20180701023420-4b7aa43c6742/go.mod h1:bx2lNnkwVCuqBIxFjflWJWanXIb3RllmbCylyMrvgv0=
|
||||||
github.com/modern-go/reflect2 v1.0.1/go.mod h1:bx2lNnkwVCuqBIxFjflWJWanXIb3RllmbCylyMrvgv0=
|
github.com/modern-go/reflect2 v1.0.1/go.mod h1:bx2lNnkwVCuqBIxFjflWJWanXIb3RllmbCylyMrvgv0=
|
||||||
github.com/moul/http2curl v1.0.0/go.mod h1:8UbvGypXm98wA/IqH45anm5Y2Z6ep6O31QGOAZ3H0fQ=
|
github.com/moul/http2curl v1.0.0/go.mod h1:8UbvGypXm98wA/IqH45anm5Y2Z6ep6O31QGOAZ3H0fQ=
|
||||||
github.com/nats-io/nats.go v1.8.1/go.mod h1:BrFz9vVn0fU3AcH9Vn4Kd7W0NpJ651tD5omQ3M8LwxM=
|
github.com/nats-io/jwt v0.3.0/go.mod h1:fRYCDE99xlTsqUzISS1Bi75UBJ6ljOJQOAAu5VglpSg=
|
||||||
github.com/nats-io/nkeys v0.0.2/go.mod h1:dab7URMsZm6Z/jp9Z5UGa87Uutgc2mVpXLC4B7TDb/4=
|
github.com/nats-io/nats.go v1.9.1/go.mod h1:ZjDU1L/7fJ09jvUSRVBR2e7+RnLiiIQyqyzEE/Zbp4w=
|
||||||
|
github.com/nats-io/nkeys v0.1.0/go.mod h1:xpnFELMwJABBLVhffcfd1MZx6VsNRFpEugbxziKVo7w=
|
||||||
github.com/nats-io/nuid v1.0.1/go.mod h1:19wcPz3Ph3q0Jbyiqsd0kePYG7A95tJPxeL+1OSON2c=
|
github.com/nats-io/nuid v1.0.1/go.mod h1:19wcPz3Ph3q0Jbyiqsd0kePYG7A95tJPxeL+1OSON2c=
|
||||||
github.com/niemeyer/pretty v0.0.0-20200227124842-a10e7caefd8e/go.mod h1:zD1mROLANZcx1PVRCS0qkT7pwLkGfwJo4zjcN/Tysno=
|
|
||||||
github.com/nxadm/tail v1.4.4/go.mod h1:kenIhsEOeOJmVchQTgglprH7qJGnHDVpk1VPCcaMI8A=
|
|
||||||
github.com/nxadm/tail v1.4.8 h1:nPr65rt6Y5JFSKQO7qToXr7pePgD6Gwiw05lkbyAQTE=
|
github.com/nxadm/tail v1.4.8 h1:nPr65rt6Y5JFSKQO7qToXr7pePgD6Gwiw05lkbyAQTE=
|
||||||
github.com/onsi/ginkgo v1.6.0/go.mod h1:lLunBs/Ym6LB5Z9jYTR76FiuTmxDTDusOGeTQH+WWjE=
|
github.com/onsi/ginkgo v1.6.0/go.mod h1:lLunBs/Ym6LB5Z9jYTR76FiuTmxDTDusOGeTQH+WWjE=
|
||||||
github.com/onsi/ginkgo v1.12.1/go.mod h1:zj2OWP4+oCPe1qIXoGWkgMRwljMUYCdkwsT2108oapk=
|
github.com/onsi/ginkgo v1.10.3/go.mod h1:lLunBs/Ym6LB5Z9jYTR76FiuTmxDTDusOGeTQH+WWjE=
|
||||||
github.com/onsi/ginkgo v1.13.0/go.mod h1:+REjRxOmWfHCjfv9TTWB1jD1Frx4XydAD3zm1lskyM0=
|
|
||||||
github.com/onsi/ginkgo v1.16.5 h1:8xi0RTUf59SOSfEtZMvwTvXYMzG4gV23XVHOZiXNtnE=
|
github.com/onsi/ginkgo v1.16.5 h1:8xi0RTUf59SOSfEtZMvwTvXYMzG4gV23XVHOZiXNtnE=
|
||||||
github.com/onsi/gomega v1.7.1/go.mod h1:XdKZgCCFLUoM/7CFJVPcG8C1xQ1AJ0vpAezJrB7JYyY=
|
github.com/onsi/gomega v1.7.1/go.mod h1:XdKZgCCFLUoM/7CFJVPcG8C1xQ1AJ0vpAezJrB7JYyY=
|
||||||
github.com/onsi/gomega v1.10.1/go.mod h1:iN09h71vgCQne3DLsj+A5owkum+a2tYe+TOCB1ybHNo=
|
|
||||||
github.com/onsi/gomega v1.18.1 h1:M1GfJqGRrBrrGGsbxzV5dqM2U2ApXefZCQpkukxYRLE=
|
github.com/onsi/gomega v1.18.1 h1:M1GfJqGRrBrrGGsbxzV5dqM2U2ApXefZCQpkukxYRLE=
|
||||||
github.com/pelletier/go-toml v1.2.0/go.mod h1:5z9KED0ma1S8pY6P1sdut58dfprrGBbd/94hg7ilaic=
|
github.com/pelletier/go-toml v1.2.0/go.mod h1:5z9KED0ma1S8pY6P1sdut58dfprrGBbd/94hg7ilaic=
|
||||||
github.com/pingcap/errors v0.11.4 h1:lFuQV/oaUMGcD2tqt+01ROSmJs75VG1ToEOkZIZ4nE4=
|
github.com/pingcap/errors v0.11.4 h1:lFuQV/oaUMGcD2tqt+01ROSmJs75VG1ToEOkZIZ4nE4=
|
||||||
github.com/pingcap/errors v0.11.4/go.mod h1:Oi8TUi2kEtXXLMJk9l1cGmz20kV3TaQ0usTwv5KuLY8=
|
github.com/pingcap/errors v0.11.4/go.mod h1:Oi8TUi2kEtXXLMJk9l1cGmz20kV3TaQ0usTwv5KuLY8=
|
||||||
|
github.com/pkg/diff v0.0.0-20210226163009-20ebb0f2a09e/go.mod h1:pJLUxLENpZxwdsKMEsNbx1VGcRFpLqf3715MtcvvzbA=
|
||||||
github.com/pkg/errors v0.8.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0=
|
github.com/pkg/errors v0.8.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0=
|
||||||
github.com/pkg/errors v0.9.1 h1:FEBLx1zS214owpjy7qsBeixbURkuhQAwrK5UwLGTwt4=
|
github.com/pkg/errors v0.9.1 h1:FEBLx1zS214owpjy7qsBeixbURkuhQAwrK5UwLGTwt4=
|
||||||
github.com/pkg/errors v0.9.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0=
|
github.com/pkg/errors v0.9.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0=
|
||||||
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
|
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/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
|
||||||
|
github.com/prometheus/client_golang v1.15.1 h1:8tXpTmJbyH5lydzFPoxSIJ0J46jdh3tylbvM1xCv0LI=
|
||||||
|
github.com/prometheus/client_golang v1.15.1/go.mod h1:e9yaBhRPU2pPNsZwE+JdQl0KEt1N9XgF6zxWmaC0xOk=
|
||||||
github.com/prometheus/client_model v0.0.0-20190812154241-14fe0d1b01d4/go.mod h1:xMI15A0UPsDsEKsMN9yxemIoYk6Tm2C1GtYGdfGttqA=
|
github.com/prometheus/client_model v0.0.0-20190812154241-14fe0d1b01d4/go.mod h1:xMI15A0UPsDsEKsMN9yxemIoYk6Tm2C1GtYGdfGttqA=
|
||||||
|
github.com/prometheus/client_model v0.4.0 h1:5lQXD3cAg1OXBf4Wq03gTrXHeaV0TQvGfUooCfx1yqY=
|
||||||
|
github.com/prometheus/client_model v0.4.0/go.mod h1:oMQmHW1/JoDwqLtg57MGgP/Fb1CJEYF2imWWhWtMkYU=
|
||||||
|
github.com/prometheus/common v0.43.0 h1:iq+BVjvYLei5f27wiuNiB1DN6DYQkp1c8Bx0Vykh5us=
|
||||||
|
github.com/prometheus/common v0.43.0/go.mod h1:NCvr5cQIh3Y/gy73/RdVtC9r8xxrxwJnB+2lB3BxrFc=
|
||||||
|
github.com/prometheus/procfs v0.9.0 h1:wzCHvIvM5SxWqYvwgVL7yJY8Lz3PKn49KQtpgMYJfhI=
|
||||||
|
github.com/prometheus/procfs v0.9.0/go.mod h1:+pB4zwohETzFnmlpe6yd2lSc+0/46IYZRB/chUwxUZY=
|
||||||
|
github.com/rogpeppe/go-internal v1.6.1/go.mod h1:xXDCJY+GAPziupqXw64V24skbSoqbTEfhy4qGm1nDQc=
|
||||||
|
github.com/rogpeppe/go-internal v1.8.1/go.mod h1:JeRgkft04UBgHMgCIwADu4Pn6Mtm5d4nPKWu0nJ5d+o=
|
||||||
|
github.com/rogpeppe/go-internal v1.9.0/go.mod h1:WtVeX8xhTBvf0smdhujwtBcq4Qrzq/fJaraNFVN+nFs=
|
||||||
|
github.com/rogpeppe/go-internal v1.10.0 h1:TMyTOH3F/DB16zRVcYyreMH6GnZZrwQVAoYjRBZyWFQ=
|
||||||
|
github.com/rogpeppe/go-internal v1.10.0/go.mod h1:UQnix2H7Ngw/k4C5ijL5+65zddjncjaFoBhdsK/akog=
|
||||||
github.com/russross/blackfriday v1.5.2/go.mod h1:JO/DiYxRf+HjHt06OyowR9PTA263kcR/rfWxYHBV53g=
|
github.com/russross/blackfriday v1.5.2/go.mod h1:JO/DiYxRf+HjHt06OyowR9PTA263kcR/rfWxYHBV53g=
|
||||||
github.com/ryanuber/columnize v2.1.0+incompatible/go.mod h1:sm1tb6uqfes/u+d4ooFouqFdy9/2g9QGwK3SQygK0Ts=
|
github.com/ryanuber/columnize v2.1.0+incompatible/go.mod h1:sm1tb6uqfes/u+d4ooFouqFdy9/2g9QGwK3SQygK0Ts=
|
||||||
github.com/sclevine/agouti v3.0.0+incompatible/go.mod h1:b4WX9W9L1sfQKXeJf1mUTLZKJ48R1S7H23Ji7oFO5Bw=
|
github.com/schollz/closestmatch v2.1.0+incompatible/go.mod h1:RtP1ddjLong6gTkbtmuhtR2uUrrJOpYzYRvbcPAid+g=
|
||||||
github.com/sergi/go-diff v1.1.0/go.mod h1:STckp+ISIX8hZLjrqAeVduY0gWCT9IjLuqbuNXdaHfM=
|
github.com/sergi/go-diff v1.0.0/go.mod h1:0CfEIISq7TuYL3j771MWULgwwjU+GofnZX9QAmXWZgo=
|
||||||
github.com/shurcooL/sanitized_anchor_name v1.0.0/go.mod h1:1NzhyTcUVG4SuEtjjoZeVRXNmyL/1OwPU0+IJeTBvfc=
|
github.com/shurcooL/sanitized_anchor_name v1.0.0/go.mod h1:1NzhyTcUVG4SuEtjjoZeVRXNmyL/1OwPU0+IJeTBvfc=
|
||||||
github.com/sirupsen/logrus v1.8.1 h1:dJKuHgqk1NNQlqoA6BTlM1Wf9DOH3NBjQyu0h9+AZZE=
|
github.com/sirupsen/logrus v1.9.2 h1:oxx1eChJGI6Uks2ZC4W1zpLlVgqB8ner4EuQwV4Ik1Y=
|
||||||
github.com/sirupsen/logrus v1.8.1/go.mod h1:yWOB1SBYBC5VeMP7gHvWumXLIWorT60ONWic61uBYv0=
|
github.com/sirupsen/logrus v1.9.2/go.mod h1:naHLuLoDiP4jHNo9R0sCBMtWGeIprob74mVsIT4qYEQ=
|
||||||
github.com/smartystreets/assertions v0.0.0-20180927180507-b2de0cb4f26d/go.mod h1:OnSkiWE9lh6wB0YB77sQom3nweQdgAjqCqsofrRNTgc=
|
github.com/smartystreets/assertions v0.0.0-20180927180507-b2de0cb4f26d/go.mod h1:OnSkiWE9lh6wB0YB77sQom3nweQdgAjqCqsofrRNTgc=
|
||||||
github.com/smartystreets/goconvey v1.6.4/go.mod h1:syvi0/a8iFYH4r/RixwvyeAJjdLS9QV7WQ/tjFTllLA=
|
github.com/smartystreets/goconvey v1.6.4/go.mod h1:syvi0/a8iFYH4r/RixwvyeAJjdLS9QV7WQ/tjFTllLA=
|
||||||
github.com/spf13/afero v1.1.2/go.mod h1:j4pytiNVoe2o6bmDsKpLACNPDBIoEAkihy7loJ1B0CQ=
|
github.com/spf13/afero v1.1.2/go.mod h1:j4pytiNVoe2o6bmDsKpLACNPDBIoEAkihy7loJ1B0CQ=
|
||||||
@@ -200,16 +218,20 @@ github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+
|
|||||||
github.com/stretchr/testify v1.2.2/go.mod h1:a8OnRcib4nhh0OaRAV+Yts87kKdq0PP7pXfy6kDkUVs=
|
github.com/stretchr/testify v1.2.2/go.mod h1:a8OnRcib4nhh0OaRAV+Yts87kKdq0PP7pXfy6kDkUVs=
|
||||||
github.com/stretchr/testify v1.3.0/go.mod h1:M5WIy9Dh21IEIfnGCwXGc5bZfKNJtfHm1UVUgZn+9EI=
|
github.com/stretchr/testify v1.3.0/go.mod h1:M5WIy9Dh21IEIfnGCwXGc5bZfKNJtfHm1UVUgZn+9EI=
|
||||||
github.com/stretchr/testify v1.4.0/go.mod h1:j7eGeouHqKxXV5pUuKE4zz7dFj8WfuZ+81PSLYec5m4=
|
github.com/stretchr/testify v1.4.0/go.mod h1:j7eGeouHqKxXV5pUuKE4zz7dFj8WfuZ+81PSLYec5m4=
|
||||||
github.com/stretchr/testify v1.7.0 h1:nwc3DEeHmmLAfoZucVR881uASk0Mfjw8xYJ99tb5CcY=
|
github.com/stretchr/testify v1.5.1/go.mod h1:5W2xD1RspED5o8YsWQXVCued0rvSQ+mT+I5cxcmMvtA=
|
||||||
github.com/stretchr/testify v1.7.0/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg=
|
github.com/stretchr/testify v1.7.0/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg=
|
||||||
|
github.com/stretchr/testify v1.8.2 h1:+h33VjcLVPDHtOdpUCuF+7gSuG3yGIftsP1YvFihtJ8=
|
||||||
github.com/thoj/go-ircevent v0.0.0-20210723090443-73e444401d64 h1:l/T7dYuJEQZOwVOpjIXr1180aM9PZL/d1MnMVIxefX4=
|
github.com/thoj/go-ircevent v0.0.0-20210723090443-73e444401d64 h1:l/T7dYuJEQZOwVOpjIXr1180aM9PZL/d1MnMVIxefX4=
|
||||||
github.com/thoj/go-ircevent v0.0.0-20210723090443-73e444401d64/go.mod h1:Q1NAJOuRdQCqN/VIWdnaaEhV8LpeO2rtlBP7/iDJNII=
|
github.com/thoj/go-ircevent v0.0.0-20210723090443-73e444401d64/go.mod h1:Q1NAJOuRdQCqN/VIWdnaaEhV8LpeO2rtlBP7/iDJNII=
|
||||||
github.com/ugorji/go v1.1.4/go.mod h1:uQMGLiO92mf5W77hV/PUCpI3pbzQx3CRekS0kk+RGrc=
|
github.com/ugorji/go v1.1.4/go.mod h1:uQMGLiO92mf5W77hV/PUCpI3pbzQx3CRekS0kk+RGrc=
|
||||||
|
github.com/ugorji/go v1.1.7/go.mod h1:kZn38zHttfInRq0xu/PH0az30d+z6vm202qpg1oXVMw=
|
||||||
github.com/ugorji/go/codec v0.0.0-20181204163529-d75b2dcb6bc8/go.mod h1:VFNgLljTbGfSG7qAOspJ7OScBnGdDN/yBr0sguwnwf0=
|
github.com/ugorji/go/codec v0.0.0-20181204163529-d75b2dcb6bc8/go.mod h1:VFNgLljTbGfSG7qAOspJ7OScBnGdDN/yBr0sguwnwf0=
|
||||||
|
github.com/ugorji/go/codec v1.1.7/go.mod h1:Ax+UKWsSmolVDwsd+7N3ZtXu+yMGCf907BLYF3GoBXY=
|
||||||
github.com/urfave/negroni v1.0.0/go.mod h1:Meg73S6kFm/4PpbYdq35yYWoCZ9mS/YSx+lKnmiohz4=
|
github.com/urfave/negroni v1.0.0/go.mod h1:Meg73S6kFm/4PpbYdq35yYWoCZ9mS/YSx+lKnmiohz4=
|
||||||
github.com/valyala/bytebufferpool v1.0.0/go.mod h1:6bBcMArwyJ5K/AmCkWv1jt77kVWyCJ6HpOuEn7z0Csc=
|
github.com/valyala/bytebufferpool v1.0.0/go.mod h1:6bBcMArwyJ5K/AmCkWv1jt77kVWyCJ6HpOuEn7z0Csc=
|
||||||
github.com/valyala/fasthttp v1.6.0/go.mod h1:FstJa9V+Pj9vQ7OJie2qMHdwemEDaDiSdBnvPM1Su9w=
|
github.com/valyala/fasthttp v1.6.0/go.mod h1:FstJa9V+Pj9vQ7OJie2qMHdwemEDaDiSdBnvPM1Su9w=
|
||||||
github.com/valyala/fasttemplate v1.0.1/go.mod h1:UQGH1tvbgY+Nz5t2n7tXsz52dQxojPUpymEIMZ47gx8=
|
github.com/valyala/fasttemplate v1.0.1/go.mod h1:UQGH1tvbgY+Nz5t2n7tXsz52dQxojPUpymEIMZ47gx8=
|
||||||
|
github.com/valyala/fasttemplate v1.2.1/go.mod h1:KHLXt3tVN2HBp8eijSv/kGJopbvo7S+qRAEEKiv+SiQ=
|
||||||
github.com/valyala/tcplisten v0.0.0-20161114210144-ceec8f93295a/go.mod h1:v3UYOV9WzVtRmSR+PDvWpU/qWl4Wa5LApYYX4ZtKbio=
|
github.com/valyala/tcplisten v0.0.0-20161114210144-ceec8f93295a/go.mod h1:v3UYOV9WzVtRmSR+PDvWpU/qWl4Wa5LApYYX4ZtKbio=
|
||||||
github.com/xeipuuv/gojsonpointer v0.0.0-20180127040702-4e3ac2762d5f/go.mod h1:N2zxlSyiKSe5eX1tZViRH5QA0qijqEDrYZiPEAiq3wU=
|
github.com/xeipuuv/gojsonpointer v0.0.0-20180127040702-4e3ac2762d5f/go.mod h1:N2zxlSyiKSe5eX1tZViRH5QA0qijqEDrYZiPEAiq3wU=
|
||||||
github.com/xeipuuv/gojsonreference v0.0.0-20180127040603-bd5ef7bd5415/go.mod h1:GwrjFmJcFw6At/Gs6z4yjiIwzuJ1/+UwLxMQDVQXShQ=
|
github.com/xeipuuv/gojsonreference v0.0.0-20180127040603-bd5ef7bd5415/go.mod h1:GwrjFmJcFw6At/Gs6z4yjiIwzuJ1/+UwLxMQDVQXShQ=
|
||||||
@@ -219,29 +241,28 @@ github.com/yalp/jsonpath v0.0.0-20180802001716-5cc68e5049a0/go.mod h1:/LWChgwKmv
|
|||||||
github.com/yudai/gojsondiff v1.0.0/go.mod h1:AY32+k2cwILAkW1fbgxQ5mUmMiZFgLIV+FBNExI05xg=
|
github.com/yudai/gojsondiff v1.0.0/go.mod h1:AY32+k2cwILAkW1fbgxQ5mUmMiZFgLIV+FBNExI05xg=
|
||||||
github.com/yudai/golcs v0.0.0-20170316035057-ecda9a501e82/go.mod h1:lgjkn3NuSvDfVJdfcVVdX+jpBxNmX4rDAzaS45IcYoM=
|
github.com/yudai/golcs v0.0.0-20170316035057-ecda9a501e82/go.mod h1:lgjkn3NuSvDfVJdfcVVdX+jpBxNmX4rDAzaS45IcYoM=
|
||||||
github.com/yudai/pp v2.0.1+incompatible/go.mod h1:PuxR/8QJ7cyCkFp/aUDS+JY727OFEZkTdatxwunjIkc=
|
github.com/yudai/pp v2.0.1+incompatible/go.mod h1:PuxR/8QJ7cyCkFp/aUDS+JY727OFEZkTdatxwunjIkc=
|
||||||
|
github.com/yuin/goldmark v1.1.27/go.mod h1:3hX8gzYuyVAZsxl0MRgGTJEmQBFcNTphYh9decYSb74=
|
||||||
|
github.com/yuin/goldmark v1.2.1/go.mod h1:3hX8gzYuyVAZsxl0MRgGTJEmQBFcNTphYh9decYSb74=
|
||||||
|
github.com/yuin/goldmark v1.3.5/go.mod h1:mwnBkeHKe2W/ZEtQ+71ViKU8L12m81fl3OWwC1Zlc8k=
|
||||||
golang.org/x/crypto v0.0.0-20181203042331-505ab145d0a9/go.mod h1:6SG95UA2DQfeDnfUPMdvaQW0Q7yPrPDi9nlGo2tz2b4=
|
golang.org/x/crypto v0.0.0-20181203042331-505ab145d0a9/go.mod h1:6SG95UA2DQfeDnfUPMdvaQW0Q7yPrPDi9nlGo2tz2b4=
|
||||||
golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w=
|
golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w=
|
||||||
golang.org/x/crypto v0.0.0-20190510104115-cbcb75029529/go.mod h1:yigFU9vqHzYiE8UmvKecakEJjdnWj3jj499lnFckfCI=
|
|
||||||
golang.org/x/crypto v0.0.0-20190701094942-4def268fd1a4/go.mod h1:yigFU9vqHzYiE8UmvKecakEJjdnWj3jj499lnFckfCI=
|
golang.org/x/crypto v0.0.0-20190701094942-4def268fd1a4/go.mod h1:yigFU9vqHzYiE8UmvKecakEJjdnWj3jj499lnFckfCI=
|
||||||
golang.org/x/crypto v0.0.0-20191011191535-87dc89f01550/go.mod h1:yigFU9vqHzYiE8UmvKecakEJjdnWj3jj499lnFckfCI=
|
golang.org/x/crypto v0.0.0-20191011191535-87dc89f01550/go.mod h1:yigFU9vqHzYiE8UmvKecakEJjdnWj3jj499lnFckfCI=
|
||||||
golang.org/x/exp v0.0.0-20180321215751-8460e604b9de/go.mod h1:CJ0aWSM057203Lf6IL+f9T1iT9GByDxfZKAQTCR3kQA=
|
golang.org/x/crypto v0.0.0-20191227163750-53104e6ec876/go.mod h1:LzIPMQfyMNhhGPhUkYOs5KpL4U8rLKemX1yGLhDgUto=
|
||||||
golang.org/x/exp v0.0.0-20180807140117-3d87b88a115f/go.mod h1:CJ0aWSM057203Lf6IL+f9T1iT9GByDxfZKAQTCR3kQA=
|
golang.org/x/crypto v0.0.0-20200622213623-75b288015ac9/go.mod h1:LzIPMQfyMNhhGPhUkYOs5KpL4U8rLKemX1yGLhDgUto=
|
||||||
|
golang.org/x/crypto v0.0.0-20210322153248-0c34fe9e7dc2/go.mod h1:T9bdIzuCu7OtxOm1hfPfRQxPLYneinmdGuTeoZ9dtd4=
|
||||||
|
golang.org/x/crypto v0.0.0-20210921155107-089bfa567519/go.mod h1:GvvjBRRGRdwPK5ydBHafDWAxML/pGHZbMvKqRZ5+Abc=
|
||||||
golang.org/x/exp v0.0.0-20190121172915-509febef88a4/go.mod h1:CJ0aWSM057203Lf6IL+f9T1iT9GByDxfZKAQTCR3kQA=
|
golang.org/x/exp v0.0.0-20190121172915-509febef88a4/go.mod h1:CJ0aWSM057203Lf6IL+f9T1iT9GByDxfZKAQTCR3kQA=
|
||||||
golang.org/x/exp v0.0.0-20190125153040-c74c464bbbf2/go.mod h1:CJ0aWSM057203Lf6IL+f9T1iT9GByDxfZKAQTCR3kQA=
|
golang.org/x/exp v0.0.0-20230515195305-f3d0a9c9a5cc h1:mCRnTeVUjcrhlRmO0VK8a6k6Rrf6TF9htwo2pJVSjIU=
|
||||||
golang.org/x/exp v0.0.0-20190306152737-a1d7652674e8/go.mod h1:CJ0aWSM057203Lf6IL+f9T1iT9GByDxfZKAQTCR3kQA=
|
golang.org/x/exp v0.0.0-20230515195305-f3d0a9c9a5cc/go.mod h1:V1LtkGg67GoY2N1AnLN78QLrzxkLyJw7RJb1gzOOz9w=
|
||||||
golang.org/x/exp v0.0.0-20191030013958-a1ab85dbe136/go.mod h1:JXzH8nQsPlswgeRAPE3MuO9GYsAcnJvJ4vnMwN/5qkY=
|
|
||||||
golang.org/x/exp v0.0.0-20200513190911-00229845015e h1:rMqLP+9XLy+LdbCXHjJHAmTfXCr93W7oruWA6Hq1Alc=
|
|
||||||
golang.org/x/exp v0.0.0-20200513190911-00229845015e/go.mod h1:4M0jN8W1tt0AVLNr8HDosyJCDCDuyL9N9+3m7wDWgKw=
|
|
||||||
golang.org/x/image v0.0.0-20180708004352-c73c2afc3b81/go.mod h1:ux5Hcp/YLpHSI86hEcLt0YII63i6oz57MZXIpbrjZUs=
|
|
||||||
golang.org/x/image v0.0.0-20190227222117-0694c2d4d067/go.mod h1:kZ7UVZpmo3dzQBMxlp+ypCbDeSB+sBbTgSJuh5dn5js=
|
|
||||||
golang.org/x/image v0.0.0-20190802002840-cff245a6509b/go.mod h1:FeLwcggjj3mMvU+oOTbSwawSJRM1uh48EjtB4UJZlP0=
|
|
||||||
golang.org/x/lint v0.0.0-20181026193005-c67002cb31c3/go.mod h1:UVdnD1Gm6xHRNCYTkRU2/jEulfH38KcIWyp/GAMgvoE=
|
golang.org/x/lint v0.0.0-20181026193005-c67002cb31c3/go.mod h1:UVdnD1Gm6xHRNCYTkRU2/jEulfH38KcIWyp/GAMgvoE=
|
||||||
golang.org/x/lint v0.0.0-20190227174305-5b3e6a55c961/go.mod h1:wehouNa3lNwaWXcvxsM5YxQ5yQlVC4a0KAMCusXpPoU=
|
golang.org/x/lint v0.0.0-20190227174305-5b3e6a55c961/go.mod h1:wehouNa3lNwaWXcvxsM5YxQ5yQlVC4a0KAMCusXpPoU=
|
||||||
golang.org/x/lint v0.0.0-20190313153728-d0100b6bd8b3/go.mod h1:6SW0HCj/g11FgYtHlgUYUwCkIfeOF89ocIRzGO/8vkc=
|
golang.org/x/lint v0.0.0-20190313153728-d0100b6bd8b3/go.mod h1:6SW0HCj/g11FgYtHlgUYUwCkIfeOF89ocIRzGO/8vkc=
|
||||||
golang.org/x/mobile v0.0.0-20190719004257-d2bd2a29d028/go.mod h1:E/iHnbuqvinMTCcRqshq8CkpyQDoeVncDDYHnLhea+o=
|
golang.org/x/lint v0.0.0-20210508222113-6edffad5e616/go.mod h1:3xt1FjdF8hUf6vQPIChWIBhFzV8gjjsPE/fR3IyQdNY=
|
||||||
golang.org/x/mod v0.1.0/go.mod h1:0QHyrYULN0/3qlju5TqG8bIK38QM8yzMo5ekMj3DlcY=
|
|
||||||
golang.org/x/mod v0.1.1-0.20191105210325-c90efee705ee/go.mod h1:QqPTAvyqsEbceGzBzNggFXnrqF1CaUcvgkdR5Ot7KZg=
|
golang.org/x/mod v0.1.1-0.20191105210325-c90efee705ee/go.mod h1:QqPTAvyqsEbceGzBzNggFXnrqF1CaUcvgkdR5Ot7KZg=
|
||||||
golang.org/x/mod v0.1.1-0.20191107180719-034126e5016b/go.mod h1:QqPTAvyqsEbceGzBzNggFXnrqF1CaUcvgkdR5Ot7KZg=
|
golang.org/x/mod v0.2.0/go.mod h1:s0Qsj1ACt9ePp/hMypM3fl4fZqREWJwdYDEqhRiZZUA=
|
||||||
|
golang.org/x/mod v0.3.0/go.mod h1:s0Qsj1ACt9ePp/hMypM3fl4fZqREWJwdYDEqhRiZZUA=
|
||||||
|
golang.org/x/mod v0.4.2/go.mod h1:s0Qsj1ACt9ePp/hMypM3fl4fZqREWJwdYDEqhRiZZUA=
|
||||||
golang.org/x/net v0.0.0-20180724234803-3673e40ba225/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4=
|
golang.org/x/net v0.0.0-20180724234803-3673e40ba225/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4=
|
||||||
golang.org/x/net v0.0.0-20180826012351-8a410e7b638d/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4=
|
golang.org/x/net v0.0.0-20180826012351-8a410e7b638d/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4=
|
||||||
golang.org/x/net v0.0.0-20180906233101-161cd47e91fd/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4=
|
golang.org/x/net v0.0.0-20180906233101-161cd47e91fd/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4=
|
||||||
@@ -253,96 +274,119 @@ golang.org/x/net v0.0.0-20190404232315-eb5bcb51f2a3/go.mod h1:t9HGtf8HONx5eT2rtn
|
|||||||
golang.org/x/net v0.0.0-20190503192946-f4e77d36d62c/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg=
|
golang.org/x/net v0.0.0-20190503192946-f4e77d36d62c/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg=
|
||||||
golang.org/x/net v0.0.0-20190620200207-3b0461eec859/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s=
|
golang.org/x/net v0.0.0-20190620200207-3b0461eec859/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s=
|
||||||
golang.org/x/net v0.0.0-20190827160401-ba9fcec4b297/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s=
|
golang.org/x/net v0.0.0-20190827160401-ba9fcec4b297/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s=
|
||||||
golang.org/x/net v0.0.0-20200520004742-59133d7f0dd7/go.mod h1:qpuaurCH72eLCgpAm/N6yyVIVM9cpaDIP3A8BGJEC5A=
|
golang.org/x/net v0.0.0-20191209160850-c0dbc17a3553/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s=
|
||||||
golang.org/x/net v0.0.0-20210614182718-04defd469f4e h1:XpT3nA5TvE525Ne3hInMh6+GETgn27Zfm9dxsThnX2Q=
|
golang.org/x/net v0.0.0-20200226121028-0de0cce0169b/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s=
|
||||||
|
golang.org/x/net v0.0.0-20201021035429-f5854403a974/go.mod h1:sp8m0HH+o8qH0wwXwYZr8TS3Oi6o0r6Gce1SSxlDquU=
|
||||||
|
golang.org/x/net v0.0.0-20210226172049-e18ecbb05110/go.mod h1:m0MpNAwzfU5UDzcl9v0D8zg8gWTRqZa9RBIspLL5mdg=
|
||||||
|
golang.org/x/net v0.0.0-20210405180319-a5a99cb37ef4/go.mod h1:p54w0d4576C0XHj96bSt6lcn1PtDYWL6XObtHCRCNQM=
|
||||||
golang.org/x/net v0.0.0-20210614182718-04defd469f4e/go.mod h1:9nx3DQGgdP8bBQD5qxJ1jj9UTztislL4KSBs9R2vV5Y=
|
golang.org/x/net v0.0.0-20210614182718-04defd469f4e/go.mod h1:9nx3DQGgdP8bBQD5qxJ1jj9UTztislL4KSBs9R2vV5Y=
|
||||||
|
golang.org/x/net v0.0.0-20211008194852-3b03d305991f/go.mod h1:9nx3DQGgdP8bBQD5qxJ1jj9UTztislL4KSBs9R2vV5Y=
|
||||||
|
golang.org/x/net v0.10.0 h1:X2//UzNDwYmtCLn7To6G58Wr6f5ahEAQgKNzv9Y951M=
|
||||||
|
golang.org/x/net v0.10.0/go.mod h1:0qNGK6F8kojg2nk9dLZ2mShWaEBan6FAoqfSigmmuDg=
|
||||||
golang.org/x/oauth2 v0.0.0-20180821212333-d2e6202438be/go.mod h1:N/0e6XlmueqKjAGxoOufVs8QHGRruUQn6yWY3a++T0U=
|
golang.org/x/oauth2 v0.0.0-20180821212333-d2e6202438be/go.mod h1:N/0e6XlmueqKjAGxoOufVs8QHGRruUQn6yWY3a++T0U=
|
||||||
golang.org/x/sync v0.0.0-20180314180146-1d60e4601c6f/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
|
golang.org/x/sync v0.0.0-20180314180146-1d60e4601c6f/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
|
||||||
golang.org/x/sync v0.0.0-20181108010431-42b317875d0f/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
|
golang.org/x/sync v0.0.0-20181108010431-42b317875d0f/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
|
||||||
|
golang.org/x/sync v0.0.0-20181221193216-37e7f081c4d4/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
|
||||||
golang.org/x/sync v0.0.0-20190227155943-e225da77a7e6/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
|
golang.org/x/sync v0.0.0-20190227155943-e225da77a7e6/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
|
||||||
golang.org/x/sync v0.0.0-20190423024810-112230192c58/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
|
golang.org/x/sync v0.0.0-20190423024810-112230192c58/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
|
||||||
golang.org/x/sync v0.0.0-20201020160332-67f06af15bc9 h1:SQFwaSi55rU7vdNs9Yr0Z324VNlrF+0wMqRXT4St8ck=
|
golang.org/x/sync v0.0.0-20190911185100-cd5d95a43a6e/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
|
||||||
golang.org/x/sync v0.0.0-20201020160332-67f06af15bc9/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
|
golang.org/x/sync v0.0.0-20201020160332-67f06af15bc9/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
|
||||||
|
golang.org/x/sync v0.0.0-20210220032951-036812b2e83c/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
|
||||||
|
golang.org/x/sync v0.1.0 h1:wsuoTGHzEhffawBOhz5CYhcrV4IdKZbEyZjBMuTp12o=
|
||||||
golang.org/x/sys v0.0.0-20180830151530-49385e6e1522/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
|
golang.org/x/sys v0.0.0-20180830151530-49385e6e1522/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
|
||||||
golang.org/x/sys v0.0.0-20180909124046-d0be0721c37e/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
|
golang.org/x/sys v0.0.0-20180909124046-d0be0721c37e/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
|
||||||
golang.org/x/sys v0.0.0-20181205085412-a5c9d58dba9a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
|
golang.org/x/sys v0.0.0-20181205085412-a5c9d58dba9a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
|
||||||
golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
|
golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
|
||||||
golang.org/x/sys v0.0.0-20190222072716-a9d3bda3a223/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
|
golang.org/x/sys v0.0.0-20190222072716-a9d3bda3a223/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
|
||||||
golang.org/x/sys v0.0.0-20190312061237-fead79001313/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
|
|
||||||
golang.org/x/sys v0.0.0-20190412213103-97732733099d/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
|
golang.org/x/sys v0.0.0-20190412213103-97732733099d/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
|
||||||
golang.org/x/sys v0.0.0-20190626221950-04f50cda93cb/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
|
golang.org/x/sys v0.0.0-20190626221950-04f50cda93cb/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
|
||||||
golang.org/x/sys v0.0.0-20190813064441-fde4db37ae7a/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
|
golang.org/x/sys v0.0.0-20190813064441-fde4db37ae7a/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
|
||||||
golang.org/x/sys v0.0.0-20190904154756-749cb33beabd/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
|
golang.org/x/sys v0.0.0-20200116001909-b77594299b42/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
|
||||||
golang.org/x/sys v0.0.0-20191001151750-bb3f8db39f24/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
|
golang.org/x/sys v0.0.0-20200223170610-d5e6a3e2c0ae/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
|
||||||
golang.org/x/sys v0.0.0-20191005200804-aed5e4c7ecf9/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
|
golang.org/x/sys v0.0.0-20200930185726-fdedc70b468f/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
|
||||||
golang.org/x/sys v0.0.0-20191026070338-33540a1f6037/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
|
|
||||||
golang.org/x/sys v0.0.0-20191120155948-bd437916bb0e/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
|
|
||||||
golang.org/x/sys v0.0.0-20200323222414-85ca7c5b95cd/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
|
|
||||||
golang.org/x/sys v0.0.0-20200519105757-fe76b779f299/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
|
|
||||||
golang.org/x/sys v0.0.0-20201119102817-f84b799fce68/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
|
golang.org/x/sys v0.0.0-20201119102817-f84b799fce68/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
|
||||||
|
golang.org/x/sys v0.0.0-20210330210617-4fbd30eecc44/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
|
||||||
|
golang.org/x/sys v0.0.0-20210403161142-5e06dd20ab57/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
|
||||||
golang.org/x/sys v0.0.0-20210423082822-04245dca01da/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
|
golang.org/x/sys v0.0.0-20210423082822-04245dca01da/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
|
||||||
golang.org/x/sys v0.0.0-20210909193231-528a39cd75f3/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
|
golang.org/x/sys v0.0.0-20210510120138-977fb7262007/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
|
||||||
golang.org/x/sys v0.0.0-20211216021012-1d35b9e2eb4e h1:fLOSk5Q00efkSvAm+4xcoXD+RRmLmmulPn5I3Y9F2EM=
|
golang.org/x/sys v0.0.0-20210615035016-665e8c7367d1/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
|
||||||
golang.org/x/sys v0.0.0-20211216021012-1d35b9e2eb4e/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
|
golang.org/x/sys v0.0.0-20210630005230-0f9fa26af87c/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
|
||||||
|
golang.org/x/sys v0.0.0-20210927094055-39ccf1dd6fa6/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
|
||||||
|
golang.org/x/sys v0.0.0-20211007075335-d3039528d8ac/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
|
||||||
|
golang.org/x/sys v0.0.0-20220209214540-3681064d5158/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
|
||||||
|
golang.org/x/sys v0.0.0-20220715151400-c0bba94af5f8/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
|
||||||
|
golang.org/x/sys v0.8.0 h1:EBmGv8NaZBZTWvrbjNoL6HVt+IVy3QDQpJs7VRIw3tU=
|
||||||
|
golang.org/x/sys v0.8.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
|
||||||
golang.org/x/term v0.0.0-20201126162022-7de9c90e9dd1/go.mod h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo=
|
golang.org/x/term v0.0.0-20201126162022-7de9c90e9dd1/go.mod h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo=
|
||||||
golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
|
golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
|
||||||
golang.org/x/text v0.3.2/go.mod h1:bEr9sfX3Q8Zfm5fL9x+3itogRgK3+ptLWKqgva+5dAk=
|
golang.org/x/text v0.3.2/go.mod h1:bEr9sfX3Q8Zfm5fL9x+3itogRgK3+ptLWKqgva+5dAk=
|
||||||
golang.org/x/text v0.3.6 h1:aRYxNxv6iGQlyVaZmk6ZgYEDa+Jg18DxebPSrd6bg1M=
|
golang.org/x/text v0.3.3/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ=
|
||||||
|
golang.org/x/text v0.3.5/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ=
|
||||||
golang.org/x/text v0.3.6/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ=
|
golang.org/x/text v0.3.6/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ=
|
||||||
golang.org/x/tools v0.0.0-20180525024113-a5b4c53f6e8b/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ=
|
golang.org/x/text v0.3.7/go.mod h1:u+2+/6zg+i71rQMx5EYifcz6MCKuco9NR6JIITiCfzQ=
|
||||||
|
golang.org/x/text v0.9.0 h1:2sjJmO8cDvYveuX97RDLsxlyUxLl+GHoLxBiRdHllBE=
|
||||||
|
golang.org/x/text v0.9.0/go.mod h1:e1OnstbJyHTd6l/uOt8jFFHp6TRDWZR/bV3emEE/zU8=
|
||||||
|
golang.org/x/time v0.0.0-20201208040808-7e3f01d25324/go.mod h1:tRJNPiyCQ0inRvYxbN9jk5I+vvW/OXSQhTDSoE431IQ=
|
||||||
golang.org/x/tools v0.0.0-20180917221912-90fa682c2a6e/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ=
|
golang.org/x/tools v0.0.0-20180917221912-90fa682c2a6e/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ=
|
||||||
golang.org/x/tools v0.0.0-20181030221726-6c7e314b6563/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ=
|
|
||||||
golang.org/x/tools v0.0.0-20181221001348-537d06c36207/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ=
|
golang.org/x/tools v0.0.0-20181221001348-537d06c36207/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ=
|
||||||
golang.org/x/tools v0.0.0-20190114222345-bf090417da8b/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ=
|
golang.org/x/tools v0.0.0-20190114222345-bf090417da8b/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ=
|
||||||
golang.org/x/tools v0.0.0-20190206041539-40960b6deb8e/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ=
|
|
||||||
golang.org/x/tools v0.0.0-20190226205152-f727befe758c/go.mod h1:9Yl7xja0Znq3iFh3HoIrodX9oNMXvdceNzlUR8zjMvY=
|
golang.org/x/tools v0.0.0-20190226205152-f727befe758c/go.mod h1:9Yl7xja0Znq3iFh3HoIrodX9oNMXvdceNzlUR8zjMvY=
|
||||||
golang.org/x/tools v0.0.0-20190311212946-11955173bddd/go.mod h1:LCzVGOaR6xXOjkQ3onu1FJEFr0SW1gC7cKk1uF8kGRs=
|
golang.org/x/tools v0.0.0-20190311212946-11955173bddd/go.mod h1:LCzVGOaR6xXOjkQ3onu1FJEFr0SW1gC7cKk1uF8kGRs=
|
||||||
golang.org/x/tools v0.0.0-20190327201419-c70d86f8b7cf/go.mod h1:LCzVGOaR6xXOjkQ3onu1FJEFr0SW1gC7cKk1uF8kGRs=
|
golang.org/x/tools v0.0.0-20190327201419-c70d86f8b7cf/go.mod h1:LCzVGOaR6xXOjkQ3onu1FJEFr0SW1gC7cKk1uF8kGRs=
|
||||||
golang.org/x/tools v0.0.0-20190328211700-ab21143f2384/go.mod h1:LCzVGOaR6xXOjkQ3onu1FJEFr0SW1gC7cKk1uF8kGRs=
|
golang.org/x/tools v0.0.0-20190328211700-ab21143f2384/go.mod h1:LCzVGOaR6xXOjkQ3onu1FJEFr0SW1gC7cKk1uF8kGRs=
|
||||||
golang.org/x/tools v0.0.0-20190524140312-2c0ae7006135/go.mod h1:RgjU9mgBXZiqYHBnxXauZ1Gv1EHHAz9KjViQ78xBX0Q=
|
golang.org/x/tools v0.0.0-20190524140312-2c0ae7006135/go.mod h1:RgjU9mgBXZiqYHBnxXauZ1Gv1EHHAz9KjViQ78xBX0Q=
|
||||||
golang.org/x/tools v0.0.0-20191012152004-8de300cfc20a/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo=
|
golang.org/x/tools v0.0.0-20191119224855-298f0cb1881e/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo=
|
||||||
golang.org/x/tools v0.0.0-20200207183749-b753a1ba74fa/go.mod h1:TB2adYChydJhpapKDTa4BR/hXlZSLoq2Wpct/0txZ28=
|
golang.org/x/tools v0.0.0-20200130002326-2f3ba24bd6e7/go.mod h1:TB2adYChydJhpapKDTa4BR/hXlZSLoq2Wpct/0txZ28=
|
||||||
|
golang.org/x/tools v0.0.0-20200619180055-7c47624df98f/go.mod h1:EkVYQZoAsY45+roYkvgYkIh4xh/qjgUK9TdY2XT94GE=
|
||||||
|
golang.org/x/tools v0.0.0-20210106214847-113979e3529a/go.mod h1:emZCQorbCU4vsT4fOWvOPXz4eW1wZW4PmDk9uLelYpA=
|
||||||
|
golang.org/x/tools v0.1.3/go.mod h1:o0xws9oXOQQZyjljx8fwUC0k7L1pTE6eaCbjGeHmOkk=
|
||||||
golang.org/x/xerrors v0.0.0-20190717185122-a985d3407aa7/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
|
golang.org/x/xerrors v0.0.0-20190717185122-a985d3407aa7/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
|
||||||
golang.org/x/xerrors v0.0.0-20191011141410-1b5146add898/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
|
golang.org/x/xerrors v0.0.0-20191011141410-1b5146add898/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
|
||||||
golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
|
golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
|
||||||
golang.org/x/xerrors v0.0.0-20200804184101-5ec99f83aff1 h1:go1bK/D/BFZV2I8cIQd1NKEZ+0owSTG1fDTci4IqFcE=
|
|
||||||
golang.org/x/xerrors v0.0.0-20200804184101-5ec99f83aff1/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
|
golang.org/x/xerrors v0.0.0-20200804184101-5ec99f83aff1/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
|
||||||
gonum.org/v1/gonum v0.0.0-20180816165407-929014505bf4/go.mod h1:Y+Yx5eoAFn32cQvJDxZx5Dpnq+c3wtXuadVZAcxbbBo=
|
|
||||||
gonum.org/v1/gonum v0.8.2 h1:CCXrcPKiGGotvnN6jfUsKk4rRqm7q09/YbKb5xCEvtM=
|
|
||||||
gonum.org/v1/gonum v0.8.2/go.mod h1:oe/vMfY3deqTw+1EZJhuvEW2iwGF1bW9wwu7XCu0+v0=
|
|
||||||
gonum.org/v1/netlib v0.0.0-20190313105609-8cb42192e0e0/go.mod h1:wa6Ws7BG/ESfp6dHfk7C6KdzKA7wR7u/rKwOGE66zvw=
|
|
||||||
gonum.org/v1/plot v0.0.0-20190515093506-e2840ee46a6b/go.mod h1:Wt8AAjI+ypCyYX3nZBvf6cAIx93T+c/OS2HFAYskSZc=
|
|
||||||
google.golang.org/appengine v1.1.0/go.mod h1:EbEs0AVv82hx2wNQdGPgUI5lhzA/G0D9YwlJXL52JkM=
|
google.golang.org/appengine v1.1.0/go.mod h1:EbEs0AVv82hx2wNQdGPgUI5lhzA/G0D9YwlJXL52JkM=
|
||||||
google.golang.org/appengine v1.4.0/go.mod h1:xpcJRLb0r/rnEns0DIKYYv+WjYCduHsrkT7/EB5XEv4=
|
google.golang.org/appengine v1.4.0/go.mod h1:xpcJRLb0r/rnEns0DIKYYv+WjYCduHsrkT7/EB5XEv4=
|
||||||
google.golang.org/genproto v0.0.0-20180518175338-11a468237815/go.mod h1:JiN7NxoALGmiZfu7CAH4rXhgtRTLTxftemlI0sWmxmc=
|
google.golang.org/genproto v0.0.0-20180518175338-11a468237815/go.mod h1:JiN7NxoALGmiZfu7CAH4rXhgtRTLTxftemlI0sWmxmc=
|
||||||
google.golang.org/genproto v0.0.0-20180817151627-c66870c02cf8/go.mod h1:JiN7NxoALGmiZfu7CAH4rXhgtRTLTxftemlI0sWmxmc=
|
google.golang.org/genproto v0.0.0-20180817151627-c66870c02cf8/go.mod h1:JiN7NxoALGmiZfu7CAH4rXhgtRTLTxftemlI0sWmxmc=
|
||||||
google.golang.org/genproto v0.0.0-20190819201941-24fa4b261c55/go.mod h1:DMBHOl98Agz4BDEuKkezgsaosCRResVns1a3J2ZsMNc=
|
google.golang.org/genproto v0.0.0-20190819201941-24fa4b261c55/go.mod h1:DMBHOl98Agz4BDEuKkezgsaosCRResVns1a3J2ZsMNc=
|
||||||
|
google.golang.org/genproto v0.0.0-20200526211855-cb27e3aa2013/go.mod h1:NbSheEEYHJ7i3ixzK3sjbqSGDJWnxyFXZblF3eUsNvo=
|
||||||
|
google.golang.org/genproto v0.0.0-20210624195500-8bfb893ecb84/go.mod h1:SzzZ/N+nwJDaO1kznhnlzqS8ocJICar6hYhVyhi++24=
|
||||||
google.golang.org/grpc v1.12.0/go.mod h1:yo6s7OP7yaDglbqo1J04qKzAhqBH6lvTonzMVmEdcZw=
|
google.golang.org/grpc v1.12.0/go.mod h1:yo6s7OP7yaDglbqo1J04qKzAhqBH6lvTonzMVmEdcZw=
|
||||||
google.golang.org/grpc v1.19.0/go.mod h1:mqu4LbDTu4XGKhr4mRzUsmM4RtVoemTSY81AxZiDr8c=
|
google.golang.org/grpc v1.19.0/go.mod h1:mqu4LbDTu4XGKhr4mRzUsmM4RtVoemTSY81AxZiDr8c=
|
||||||
google.golang.org/grpc v1.23.0/go.mod h1:Y5yQAOtifL1yxbo5wqy6BxZv8vAUGQwXBOALyacEbxg=
|
google.golang.org/grpc v1.23.0/go.mod h1:Y5yQAOtifL1yxbo5wqy6BxZv8vAUGQwXBOALyacEbxg=
|
||||||
google.golang.org/grpc v1.25.1/go.mod h1:c3i+UQWmh7LiEpx4sFZnkU36qjEYZ0imhYfXVyQciAY=
|
google.golang.org/grpc v1.25.1/go.mod h1:c3i+UQWmh7LiEpx4sFZnkU36qjEYZ0imhYfXVyQciAY=
|
||||||
google.golang.org/grpc v1.29.1/go.mod h1:itym6AZVZYACWQqET3MqgPpjcuV5QH3BxFS3IjizoKk=
|
google.golang.org/grpc v1.27.0/go.mod h1:qbnxyOmOxrQa7FizSgH+ReBfzJrCY1pSN7KXBS8abTk=
|
||||||
|
google.golang.org/grpc v1.38.0/go.mod h1:NREThFqKR1f3iQ6oBuvc5LadQuXVGo9rkm5ZGrQdJfM=
|
||||||
google.golang.org/protobuf v0.0.0-20200109180630-ec00e32a8dfd/go.mod h1:DFci5gLYBciE7Vtevhsrf46CRTquxDuWsQurQQe4oz8=
|
google.golang.org/protobuf v0.0.0-20200109180630-ec00e32a8dfd/go.mod h1:DFci5gLYBciE7Vtevhsrf46CRTquxDuWsQurQQe4oz8=
|
||||||
google.golang.org/protobuf v0.0.0-20200221191635-4d8936d0db64/go.mod h1:kwYJMbMJ01Woi6D6+Kah6886xMZcty6N08ah7+eCXa0=
|
google.golang.org/protobuf v0.0.0-20200221191635-4d8936d0db64/go.mod h1:kwYJMbMJ01Woi6D6+Kah6886xMZcty6N08ah7+eCXa0=
|
||||||
google.golang.org/protobuf v0.0.0-20200228230310-ab0ca4ff8a60/go.mod h1:cfTl7dwQJ+fmap5saPgwCLgHXTUD7jkjRqWcaiX5VyM=
|
google.golang.org/protobuf v0.0.0-20200228230310-ab0ca4ff8a60/go.mod h1:cfTl7dwQJ+fmap5saPgwCLgHXTUD7jkjRqWcaiX5VyM=
|
||||||
google.golang.org/protobuf v1.20.1-0.20200309200217-e05f789c0967/go.mod h1:A+miEFZTKqfCUM6K7xSMQL9OKL/b6hQv+e19PK+JZNE=
|
google.golang.org/protobuf v1.20.1-0.20200309200217-e05f789c0967/go.mod h1:A+miEFZTKqfCUM6K7xSMQL9OKL/b6hQv+e19PK+JZNE=
|
||||||
google.golang.org/protobuf v1.21.0/go.mod h1:47Nbq4nVaFHyn7ilMalzfO3qCViNmqZ2kzikPIcrTAo=
|
google.golang.org/protobuf v1.21.0/go.mod h1:47Nbq4nVaFHyn7ilMalzfO3qCViNmqZ2kzikPIcrTAo=
|
||||||
|
google.golang.org/protobuf v1.22.0/go.mod h1:EGpADcykh3NcUnDUJcl1+ZksZNG86OlYog2l/sGQquU=
|
||||||
google.golang.org/protobuf v1.23.0/go.mod h1:EGpADcykh3NcUnDUJcl1+ZksZNG86OlYog2l/sGQquU=
|
google.golang.org/protobuf v1.23.0/go.mod h1:EGpADcykh3NcUnDUJcl1+ZksZNG86OlYog2l/sGQquU=
|
||||||
|
google.golang.org/protobuf v1.23.1-0.20200526195155-81db48ad09cc/go.mod h1:EGpADcykh3NcUnDUJcl1+ZksZNG86OlYog2l/sGQquU=
|
||||||
|
google.golang.org/protobuf v1.25.0/go.mod h1:9JNX74DMeImyA3h4bdi1ymwjUzf21/xIlbajtzgsN7c=
|
||||||
|
google.golang.org/protobuf v1.26.0-rc.1/go.mod h1:jlhhOSvTdKEhbULTjvd4ARK9grFBp09yW+WbY/TyQbw=
|
||||||
|
google.golang.org/protobuf v1.26.0/go.mod h1:9q0QmTI4eRPtz6boOQmLYwt+qCgq0jsYwAQnmE0givc=
|
||||||
|
google.golang.org/protobuf v1.30.0 h1:kPPoIgf3TsEvrm0PFe15JQ+570QVxYzEvvHqChK+cng=
|
||||||
|
google.golang.org/protobuf v1.30.0/go.mod h1:HV8QOd/L58Z+nl8r43ehVNZIU/HEI6OcFqwMG9pJV4I=
|
||||||
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
|
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
|
||||||
|
gopkg.in/check.v1 v1.0.0-20180628173108-788fd7840127/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
|
||||||
gopkg.in/check.v1 v1.0.0-20190902080502-41f04d3bba15/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
|
gopkg.in/check.v1 v1.0.0-20190902080502-41f04d3bba15/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
|
||||||
gopkg.in/check.v1 v1.0.0-20200227125254-8fa46927fb4f/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
|
gopkg.in/errgo.v2 v2.1.0/go.mod h1:hNsd1EY+bozCKY1Ytp96fpM3vjJbqLJn88ws8XvfDNI=
|
||||||
gopkg.in/fsnotify.v1 v1.4.7/go.mod h1:Tz8NjZHkW78fSQdbUxIjBTcgA1z1m8ZHf0WmKUhAMys=
|
gopkg.in/fsnotify.v1 v1.4.7/go.mod h1:Tz8NjZHkW78fSQdbUxIjBTcgA1z1m8ZHf0WmKUhAMys=
|
||||||
gopkg.in/go-playground/assert.v1 v1.2.1/go.mod h1:9RXL0bg/zibRAgZUYszZSwO/z8Y/a8bDuhia5mkpMnE=
|
gopkg.in/go-playground/assert.v1 v1.2.1/go.mod h1:9RXL0bg/zibRAgZUYszZSwO/z8Y/a8bDuhia5mkpMnE=
|
||||||
gopkg.in/go-playground/validator.v8 v8.18.2/go.mod h1:RX2a/7Ha8BgOhfk7j780h4/u/RRjR0eouCJSH80/M2Y=
|
gopkg.in/go-playground/validator.v8 v8.18.2/go.mod h1:RX2a/7Ha8BgOhfk7j780h4/u/RRjR0eouCJSH80/M2Y=
|
||||||
|
gopkg.in/ini.v1 v1.51.1/go.mod h1:pNLf8WUiyNEtQjuu5G5vTm06TEv9tsIgeAvK8hOrP4k=
|
||||||
gopkg.in/mgo.v2 v2.0.0-20180705113604-9856a29383ce/go.mod h1:yeKp02qBN3iKW1OzL3MGk2IdtZzaj7SFntXj72NppTA=
|
gopkg.in/mgo.v2 v2.0.0-20180705113604-9856a29383ce/go.mod h1:yeKp02qBN3iKW1OzL3MGk2IdtZzaj7SFntXj72NppTA=
|
||||||
gopkg.in/tomb.v1 v1.0.0-20141024135613-dd632973f1e7 h1:uRGJdciOHaEIrze2W8Q3AKkepLTh2hOroT7a+7czfdQ=
|
gopkg.in/tomb.v1 v1.0.0-20141024135613-dd632973f1e7 h1:uRGJdciOHaEIrze2W8Q3AKkepLTh2hOroT7a+7czfdQ=
|
||||||
gopkg.in/tomb.v1 v1.0.0-20141024135613-dd632973f1e7/go.mod h1:dt/ZhP58zS4L8KSrWDmTeBkI65Dw0HsyUHuEVlX15mw=
|
gopkg.in/tomb.v1 v1.0.0-20141024135613-dd632973f1e7/go.mod h1:dt/ZhP58zS4L8KSrWDmTeBkI65Dw0HsyUHuEVlX15mw=
|
||||||
gopkg.in/yaml.v2 v2.2.2/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI=
|
gopkg.in/yaml.v2 v2.2.2/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI=
|
||||||
gopkg.in/yaml.v2 v2.2.4/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI=
|
gopkg.in/yaml.v2 v2.2.4/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI=
|
||||||
gopkg.in/yaml.v2 v2.3.0/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI=
|
|
||||||
gopkg.in/yaml.v2 v2.4.0 h1:D8xgwECY7CYvx+Y2n4sBz93Jn9JRvxdiyyo8CTfuKaY=
|
gopkg.in/yaml.v2 v2.4.0 h1:D8xgwECY7CYvx+Y2n4sBz93Jn9JRvxdiyyo8CTfuKaY=
|
||||||
gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c h1:dUUwHk2QECo/6vqA44rthZ8ie2QXMNeKRTHCNY2nXvo=
|
gopkg.in/yaml.v3 v3.0.0-20191120175047-4206685974f2/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
|
||||||
gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
|
gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
|
||||||
|
gopkg.in/yaml.v3 v3.0.0-20210107192922-496545a6307b/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
|
||||||
|
gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA=
|
||||||
honnef.co/go/tools v0.0.0-20190102054323-c2f93a96b099/go.mod h1:rf3lG4BRIbNafJWhAfAdb/ePZxsR/4RtNHQocxwk9r4=
|
honnef.co/go/tools v0.0.0-20190102054323-c2f93a96b099/go.mod h1:rf3lG4BRIbNafJWhAfAdb/ePZxsR/4RtNHQocxwk9r4=
|
||||||
honnef.co/go/tools v0.0.0-20190523083050-ea95bdfd59fc/go.mod h1:rf3lG4BRIbNafJWhAfAdb/ePZxsR/4RtNHQocxwk9r4=
|
honnef.co/go/tools v0.0.0-20190523083050-ea95bdfd59fc/go.mod h1:rf3lG4BRIbNafJWhAfAdb/ePZxsR/4RtNHQocxwk9r4=
|
||||||
rsc.io/pdf v0.1.1/go.mod h1:n8OzWcQ6Sp37PL01nO98y4iUCRdTGarVfzxY20ICaU4=
|
|
||||||
|
|||||||
@@ -33,6 +33,7 @@ func ircMsgParser(channel string, nick string, user string, source string, msg s
|
|||||||
message.From = config.Redis.MyChannel
|
message.From = config.Redis.MyChannel
|
||||||
message.Userid = user // как его видит сервер
|
message.Userid = user // как его видит сервер
|
||||||
message.Chatid = channel // чятик, в который написал user
|
message.Chatid = channel // чятик, в который написал user
|
||||||
|
message.Threadid = "" // тредиков в irc нету, поэтому это поле отправляем пустым
|
||||||
message.Plugin = config.Redis.MyChannel
|
message.Plugin = config.Redis.MyChannel
|
||||||
message.Mode = "public"
|
message.Mode = "public"
|
||||||
// Предполагается, что на команды бот автоматом отвечает
|
// Предполагается, что на команды бот автоматом отвечает
|
||||||
@@ -181,10 +182,10 @@ func ircMsgParser(channel string, nick string, user string, source string, msg s
|
|||||||
// Общий список простых команд
|
// Общий список простых команд
|
||||||
cmds := []string{"ping", "пинг", "пинх", "pong", "понг", "понх", "coin", "монетка", "roll", "dice", "кости",
|
cmds := []string{"ping", "пинг", "пинх", "pong", "понг", "понх", "coin", "монетка", "roll", "dice", "кости",
|
||||||
"ver", "version", "версия", "хэлп", "halp", "kde", "кде", "lat", "лат", "friday", "пятница", "proverb",
|
"ver", "version", "версия", "хэлп", "halp", "kde", "кде", "lat", "лат", "friday", "пятница", "proverb",
|
||||||
"пословица", "fortune", "фортунка", "f", "ф", "anek", "анек", "анекдот", "buni", "cat", "кис", "drink",
|
"пословица", "пословиться", "fortune", "фортунка", "f", "ф", "anek", "анек", "анекдот", "buni", "cat",
|
||||||
"праздник", "fox", "лис", "frog", "лягушка", "horse", "лошадь", "лошадка", "monkeyuser", "owl", "сова",
|
"кис", "drink", "праздник", "fox", "лис", "frog", "лягушка", "horse", "лошадь", "лошадка", "monkeyuser",
|
||||||
"сыч", "rabbit", "bunny", "кролик", "snail", "улитка", "xkcd", "dig", "копать", "fish", "fishing", "рыба",
|
"owl", "сова", "сыч", "rabbit", "bunny", "кролик", "snail", "улитка", "xkcd", "dig", "копать", "fish",
|
||||||
"рыбка", "рыбалка", "karma", "карма"}
|
"fishing", "рыба", "рыбка", "рыбалка", "karma", "карма"}
|
||||||
|
|
||||||
for _, command := range cmds {
|
for _, command := range cmds {
|
||||||
if cmd == command {
|
if cmd == command {
|
||||||
@@ -311,6 +312,7 @@ func ircMsgParser(channel string, nick string, user string, source string, msg s
|
|||||||
message.From = config.Redis.MyChannel
|
message.From = config.Redis.MyChannel
|
||||||
message.Userid = user // как его видит сервер
|
message.Userid = user // как его видит сервер
|
||||||
message.Chatid = channel // чятик, в который написал user
|
message.Chatid = channel // чятик, в который написал user
|
||||||
|
message.Threadid = "" // тредиков в irc нету, поэтому это поле отправляем пустым
|
||||||
message.Message = msg
|
message.Message = msg
|
||||||
message.Plugin = config.Redis.MyChannel
|
message.Plugin = config.Redis.MyChannel
|
||||||
message.Mode = "public"
|
message.Mode = "public"
|
||||||
|
|||||||
2
types.go
2
types.go
@@ -40,6 +40,7 @@ type rMsg struct {
|
|||||||
From string `json:"from,omitempty"`
|
From string `json:"from,omitempty"`
|
||||||
Chatid string `json:"chatid,omitempty"`
|
Chatid string `json:"chatid,omitempty"`
|
||||||
Userid string `json:"userid,omitempty"`
|
Userid string `json:"userid,omitempty"`
|
||||||
|
Threadid string `json:"threadid,omitempty"`
|
||||||
Message string `json:"message,omitempty"`
|
Message string `json:"message,omitempty"`
|
||||||
Plugin string `json:"plugin,omitempty"`
|
Plugin string `json:"plugin,omitempty"`
|
||||||
Mode string `json:"mode,omitempty"`
|
Mode string `json:"mode,omitempty"`
|
||||||
@@ -59,6 +60,7 @@ type sMsg struct {
|
|||||||
From string `json:"from"`
|
From string `json:"from"`
|
||||||
Chatid string `json:"chatid"`
|
Chatid string `json:"chatid"`
|
||||||
Userid string `json:"userid"`
|
Userid string `json:"userid"`
|
||||||
|
Threadid string `json:"threadid"`
|
||||||
Message string `json:"message"`
|
Message string `json:"message"`
|
||||||
Plugin string `json:"plugin"`
|
Plugin string `json:"plugin"`
|
||||||
Mode string `json:"mode"`
|
Mode string `json:"mode"`
|
||||||
|
|||||||
3
util.go
3
util.go
@@ -3,7 +3,6 @@ package main
|
|||||||
import (
|
import (
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
"fmt"
|
"fmt"
|
||||||
"io/ioutil"
|
|
||||||
"os"
|
"os"
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
"syscall"
|
"syscall"
|
||||||
@@ -44,7 +43,7 @@ func readConfig() {
|
|||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
|
|
||||||
buf, err := ioutil.ReadFile(location)
|
buf, err := os.ReadFile(location)
|
||||||
|
|
||||||
// Не удалось прочитать, попробуем следующего кандидата
|
// Не удалось прочитать, попробуем следующего кандидата
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
|||||||
22
vendor/github.com/DataDog/zstd/README.md
generated
vendored
22
vendor/github.com/DataDog/zstd/README.md
generated
vendored
@@ -6,8 +6,8 @@
|
|||||||
|
|
||||||
[C Zstd Homepage](https://github.com/facebook/zstd)
|
[C Zstd Homepage](https://github.com/facebook/zstd)
|
||||||
|
|
||||||
The current headers and C files are from *v1.4.4* (Commit
|
The current headers and C files are from *v1.5.0* (Commit
|
||||||
[10f0e699](https://github.com/facebook/zstd/releases/tag/v1.4.4)).
|
[10f0e699](https://github.com/facebook/zstd/releases/tag/v1.5.0)).
|
||||||
|
|
||||||
## Usage
|
## Usage
|
||||||
|
|
||||||
@@ -19,6 +19,21 @@ There are two main APIs:
|
|||||||
The compress/decompress APIs mirror that of lz4, while the streaming API was
|
The compress/decompress APIs mirror that of lz4, while the streaming API was
|
||||||
designed to be a drop-in replacement for zlib.
|
designed to be a drop-in replacement for zlib.
|
||||||
|
|
||||||
|
### Building against an external libzstd
|
||||||
|
|
||||||
|
By default, zstd source code is vendored in this repository and the binding will be built with
|
||||||
|
the vendored source code bundled.
|
||||||
|
|
||||||
|
If you want to build this binding against an external static or shared libzstd library, you can
|
||||||
|
use the `external_libzstd` build tag. This will look for the libzstd pkg-config file and extract
|
||||||
|
build and linking parameters from that pkg-config file.
|
||||||
|
|
||||||
|
Note that it requires at least libzstd 1.4.0.
|
||||||
|
|
||||||
|
```bash
|
||||||
|
go build -tags external_libzstd
|
||||||
|
```
|
||||||
|
|
||||||
### Simple `Compress/Decompress`
|
### Simple `Compress/Decompress`
|
||||||
|
|
||||||
|
|
||||||
@@ -60,6 +75,9 @@ NewWriterLevelDict(w io.Writer, level int, dict []byte) *Writer
|
|||||||
// Write compresses the input data and write it to the underlying writer
|
// Write compresses the input data and write it to the underlying writer
|
||||||
(w *Writer) Write(p []byte) (int, error)
|
(w *Writer) Write(p []byte) (int, error)
|
||||||
|
|
||||||
|
// Flush writes any unwritten data to the underlying writer
|
||||||
|
(w *Writer) Flush() error
|
||||||
|
|
||||||
// Close flushes the buffer and frees C zstd objects
|
// Close flushes the buffer and frees C zstd objects
|
||||||
(w *Writer) Close() error
|
(w *Writer) Close() error
|
||||||
```
|
```
|
||||||
|
|||||||
8
vendor/github.com/DataDog/zstd/ZSTD_LICENSE
generated
vendored
8
vendor/github.com/DataDog/zstd/ZSTD_LICENSE
generated
vendored
@@ -2,7 +2,7 @@ BSD License
|
|||||||
|
|
||||||
For Zstandard software
|
For Zstandard software
|
||||||
|
|
||||||
Copyright (c) 2016-present, Facebook, Inc. All rights reserved.
|
Copyright (c) Meta Platforms, Inc. and affiliates. All rights reserved.
|
||||||
|
|
||||||
Redistribution and use in source and binary forms, with or without modification,
|
Redistribution and use in source and binary forms, with or without modification,
|
||||||
are permitted provided that the following conditions are met:
|
are permitted provided that the following conditions are met:
|
||||||
@@ -14,9 +14,9 @@ are permitted provided that the following conditions are met:
|
|||||||
this list of conditions and the following disclaimer in the documentation
|
this list of conditions and the following disclaimer in the documentation
|
||||||
and/or other materials provided with the distribution.
|
and/or other materials provided with the distribution.
|
||||||
|
|
||||||
* Neither the name Facebook nor the names of its contributors may be used to
|
* Neither the name Facebook, nor Meta, nor the names of its contributors may
|
||||||
endorse or promote products derived from this software without specific
|
be used to endorse or promote products derived from this software without
|
||||||
prior written permission.
|
specific prior written permission.
|
||||||
|
|
||||||
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
|
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
|
||||||
ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
|
ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
|
||||||
|
|||||||
58
vendor/github.com/DataDog/zstd/allocations.h
generated
vendored
Normal file
58
vendor/github.com/DataDog/zstd/allocations.h
generated
vendored
Normal file
@@ -0,0 +1,58 @@
|
|||||||
|
#ifndef USE_EXTERNAL_ZSTD
|
||||||
|
/*
|
||||||
|
* Copyright (c) Meta Platforms, Inc. and affiliates.
|
||||||
|
* All rights reserved.
|
||||||
|
*
|
||||||
|
* This source code is licensed under both the BSD-style license (found in the
|
||||||
|
* LICENSE file in the root directory of this source tree) and the GPLv2 (found
|
||||||
|
* in the COPYING file in the root directory of this source tree).
|
||||||
|
* You may select, at your option, one of the above-listed licenses.
|
||||||
|
*/
|
||||||
|
|
||||||
|
/* This file provides custom allocation primitives
|
||||||
|
*/
|
||||||
|
|
||||||
|
#define ZSTD_DEPS_NEED_MALLOC
|
||||||
|
#include "zstd_deps.h" /* ZSTD_malloc, ZSTD_calloc, ZSTD_free, ZSTD_memset */
|
||||||
|
|
||||||
|
#include "mem.h" /* MEM_STATIC */
|
||||||
|
#define ZSTD_STATIC_LINKING_ONLY
|
||||||
|
#include "zstd.h" /* ZSTD_customMem */
|
||||||
|
|
||||||
|
#ifndef ZSTD_ALLOCATIONS_H
|
||||||
|
#define ZSTD_ALLOCATIONS_H
|
||||||
|
|
||||||
|
/* custom memory allocation functions */
|
||||||
|
|
||||||
|
MEM_STATIC void* ZSTD_customMalloc(size_t size, ZSTD_customMem customMem)
|
||||||
|
{
|
||||||
|
if (customMem.customAlloc)
|
||||||
|
return customMem.customAlloc(customMem.opaque, size);
|
||||||
|
return ZSTD_malloc(size);
|
||||||
|
}
|
||||||
|
|
||||||
|
MEM_STATIC void* ZSTD_customCalloc(size_t size, ZSTD_customMem customMem)
|
||||||
|
{
|
||||||
|
if (customMem.customAlloc) {
|
||||||
|
/* calloc implemented as malloc+memset;
|
||||||
|
* not as efficient as calloc, but next best guess for custom malloc */
|
||||||
|
void* const ptr = customMem.customAlloc(customMem.opaque, size);
|
||||||
|
ZSTD_memset(ptr, 0, size);
|
||||||
|
return ptr;
|
||||||
|
}
|
||||||
|
return ZSTD_calloc(1, size);
|
||||||
|
}
|
||||||
|
|
||||||
|
MEM_STATIC void ZSTD_customFree(void* ptr, ZSTD_customMem customMem)
|
||||||
|
{
|
||||||
|
if (ptr!=NULL) {
|
||||||
|
if (customMem.customFree)
|
||||||
|
customMem.customFree(customMem.opaque, ptr);
|
||||||
|
else
|
||||||
|
ZSTD_free(ptr);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
#endif /* ZSTD_ALLOCATIONS_H */
|
||||||
|
|
||||||
|
#endif /* USE_EXTERNAL_ZSTD */
|
||||||
203
vendor/github.com/DataDog/zstd/bits.h
generated
vendored
Normal file
203
vendor/github.com/DataDog/zstd/bits.h
generated
vendored
Normal file
@@ -0,0 +1,203 @@
|
|||||||
|
#ifndef USE_EXTERNAL_ZSTD
|
||||||
|
/*
|
||||||
|
* Copyright (c) Meta Platforms, Inc. and affiliates.
|
||||||
|
* All rights reserved.
|
||||||
|
*
|
||||||
|
* This source code is licensed under both the BSD-style license (found in the
|
||||||
|
* LICENSE file in the root directory of this source tree) and the GPLv2 (found
|
||||||
|
* in the COPYING file in the root directory of this source tree).
|
||||||
|
* You may select, at your option, one of the above-listed licenses.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#ifndef ZSTD_BITS_H
|
||||||
|
#define ZSTD_BITS_H
|
||||||
|
|
||||||
|
#include "mem.h"
|
||||||
|
|
||||||
|
MEM_STATIC unsigned ZSTD_countTrailingZeros32_fallback(U32 val)
|
||||||
|
{
|
||||||
|
assert(val != 0);
|
||||||
|
{
|
||||||
|
static const U32 DeBruijnBytePos[32] = {0, 1, 28, 2, 29, 14, 24, 3,
|
||||||
|
30, 22, 20, 15, 25, 17, 4, 8,
|
||||||
|
31, 27, 13, 23, 21, 19, 16, 7,
|
||||||
|
26, 12, 18, 6, 11, 5, 10, 9};
|
||||||
|
return DeBruijnBytePos[((U32) ((val & -(S32) val) * 0x077CB531U)) >> 27];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
MEM_STATIC unsigned ZSTD_countTrailingZeros32(U32 val)
|
||||||
|
{
|
||||||
|
assert(val != 0);
|
||||||
|
# if defined(_MSC_VER)
|
||||||
|
# if STATIC_BMI2 == 1
|
||||||
|
return (unsigned)_tzcnt_u32(val);
|
||||||
|
# else
|
||||||
|
if (val != 0) {
|
||||||
|
unsigned long r;
|
||||||
|
_BitScanForward(&r, val);
|
||||||
|
return (unsigned)r;
|
||||||
|
} else {
|
||||||
|
/* Should not reach this code path */
|
||||||
|
__assume(0);
|
||||||
|
}
|
||||||
|
# endif
|
||||||
|
# elif defined(__GNUC__) && (__GNUC__ >= 4)
|
||||||
|
return (unsigned)__builtin_ctz(val);
|
||||||
|
# else
|
||||||
|
return ZSTD_countTrailingZeros32_fallback(val);
|
||||||
|
# endif
|
||||||
|
}
|
||||||
|
|
||||||
|
MEM_STATIC unsigned ZSTD_countLeadingZeros32_fallback(U32 val) {
|
||||||
|
assert(val != 0);
|
||||||
|
{
|
||||||
|
static const U32 DeBruijnClz[32] = {0, 9, 1, 10, 13, 21, 2, 29,
|
||||||
|
11, 14, 16, 18, 22, 25, 3, 30,
|
||||||
|
8, 12, 20, 28, 15, 17, 24, 7,
|
||||||
|
19, 27, 23, 6, 26, 5, 4, 31};
|
||||||
|
val |= val >> 1;
|
||||||
|
val |= val >> 2;
|
||||||
|
val |= val >> 4;
|
||||||
|
val |= val >> 8;
|
||||||
|
val |= val >> 16;
|
||||||
|
return 31 - DeBruijnClz[(val * 0x07C4ACDDU) >> 27];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
MEM_STATIC unsigned ZSTD_countLeadingZeros32(U32 val)
|
||||||
|
{
|
||||||
|
assert(val != 0);
|
||||||
|
# if defined(_MSC_VER)
|
||||||
|
# if STATIC_BMI2 == 1
|
||||||
|
return (unsigned)_lzcnt_u32(val);
|
||||||
|
# else
|
||||||
|
if (val != 0) {
|
||||||
|
unsigned long r;
|
||||||
|
_BitScanReverse(&r, val);
|
||||||
|
return (unsigned)(31 - r);
|
||||||
|
} else {
|
||||||
|
/* Should not reach this code path */
|
||||||
|
__assume(0);
|
||||||
|
}
|
||||||
|
# endif
|
||||||
|
# elif defined(__GNUC__) && (__GNUC__ >= 4)
|
||||||
|
return (unsigned)__builtin_clz(val);
|
||||||
|
# else
|
||||||
|
return ZSTD_countLeadingZeros32_fallback(val);
|
||||||
|
# endif
|
||||||
|
}
|
||||||
|
|
||||||
|
MEM_STATIC unsigned ZSTD_countTrailingZeros64(U64 val)
|
||||||
|
{
|
||||||
|
assert(val != 0);
|
||||||
|
# if defined(_MSC_VER) && defined(_WIN64)
|
||||||
|
# if STATIC_BMI2 == 1
|
||||||
|
return (unsigned)_tzcnt_u64(val);
|
||||||
|
# else
|
||||||
|
if (val != 0) {
|
||||||
|
unsigned long r;
|
||||||
|
_BitScanForward64(&r, val);
|
||||||
|
return (unsigned)r;
|
||||||
|
} else {
|
||||||
|
/* Should not reach this code path */
|
||||||
|
__assume(0);
|
||||||
|
}
|
||||||
|
# endif
|
||||||
|
# elif defined(__GNUC__) && (__GNUC__ >= 4) && defined(__LP64__)
|
||||||
|
return (unsigned)__builtin_ctzll(val);
|
||||||
|
# else
|
||||||
|
{
|
||||||
|
U32 mostSignificantWord = (U32)(val >> 32);
|
||||||
|
U32 leastSignificantWord = (U32)val;
|
||||||
|
if (leastSignificantWord == 0) {
|
||||||
|
return 32 + ZSTD_countTrailingZeros32(mostSignificantWord);
|
||||||
|
} else {
|
||||||
|
return ZSTD_countTrailingZeros32(leastSignificantWord);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
# endif
|
||||||
|
}
|
||||||
|
|
||||||
|
MEM_STATIC unsigned ZSTD_countLeadingZeros64(U64 val)
|
||||||
|
{
|
||||||
|
assert(val != 0);
|
||||||
|
# if defined(_MSC_VER) && defined(_WIN64)
|
||||||
|
# if STATIC_BMI2 == 1
|
||||||
|
return (unsigned)_lzcnt_u64(val);
|
||||||
|
# else
|
||||||
|
if (val != 0) {
|
||||||
|
unsigned long r;
|
||||||
|
_BitScanReverse64(&r, val);
|
||||||
|
return (unsigned)(63 - r);
|
||||||
|
} else {
|
||||||
|
/* Should not reach this code path */
|
||||||
|
__assume(0);
|
||||||
|
}
|
||||||
|
# endif
|
||||||
|
# elif defined(__GNUC__) && (__GNUC__ >= 4)
|
||||||
|
return (unsigned)(__builtin_clzll(val));
|
||||||
|
# else
|
||||||
|
{
|
||||||
|
U32 mostSignificantWord = (U32)(val >> 32);
|
||||||
|
U32 leastSignificantWord = (U32)val;
|
||||||
|
if (mostSignificantWord == 0) {
|
||||||
|
return 32 + ZSTD_countLeadingZeros32(leastSignificantWord);
|
||||||
|
} else {
|
||||||
|
return ZSTD_countLeadingZeros32(mostSignificantWord);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
# endif
|
||||||
|
}
|
||||||
|
|
||||||
|
MEM_STATIC unsigned ZSTD_NbCommonBytes(size_t val)
|
||||||
|
{
|
||||||
|
if (MEM_isLittleEndian()) {
|
||||||
|
if (MEM_64bits()) {
|
||||||
|
return ZSTD_countTrailingZeros64((U64)val) >> 3;
|
||||||
|
} else {
|
||||||
|
return ZSTD_countTrailingZeros32((U32)val) >> 3;
|
||||||
|
}
|
||||||
|
} else { /* Big Endian CPU */
|
||||||
|
if (MEM_64bits()) {
|
||||||
|
return ZSTD_countLeadingZeros64((U64)val) >> 3;
|
||||||
|
} else {
|
||||||
|
return ZSTD_countLeadingZeros32((U32)val) >> 3;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
MEM_STATIC unsigned ZSTD_highbit32(U32 val) /* compress, dictBuilder, decodeCorpus */
|
||||||
|
{
|
||||||
|
assert(val != 0);
|
||||||
|
return 31 - ZSTD_countLeadingZeros32(val);
|
||||||
|
}
|
||||||
|
|
||||||
|
/* ZSTD_rotateRight_*():
|
||||||
|
* Rotates a bitfield to the right by "count" bits.
|
||||||
|
* https://en.wikipedia.org/w/index.php?title=Circular_shift&oldid=991635599#Implementing_circular_shifts
|
||||||
|
*/
|
||||||
|
MEM_STATIC
|
||||||
|
U64 ZSTD_rotateRight_U64(U64 const value, U32 count) {
|
||||||
|
assert(count < 64);
|
||||||
|
count &= 0x3F; /* for fickle pattern recognition */
|
||||||
|
return (value >> count) | (U64)(value << ((0U - count) & 0x3F));
|
||||||
|
}
|
||||||
|
|
||||||
|
MEM_STATIC
|
||||||
|
U32 ZSTD_rotateRight_U32(U32 const value, U32 count) {
|
||||||
|
assert(count < 32);
|
||||||
|
count &= 0x1F; /* for fickle pattern recognition */
|
||||||
|
return (value >> count) | (U32)(value << ((0U - count) & 0x1F));
|
||||||
|
}
|
||||||
|
|
||||||
|
MEM_STATIC
|
||||||
|
U16 ZSTD_rotateRight_U16(U16 const value, U32 count) {
|
||||||
|
assert(count < 16);
|
||||||
|
count &= 0x0F; /* for fickle pattern recognition */
|
||||||
|
return (value >> count) | (U16)(value << ((0U - count) & 0x0F));
|
||||||
|
}
|
||||||
|
|
||||||
|
#endif /* ZSTD_BITS_H */
|
||||||
|
|
||||||
|
#endif /* USE_EXTERNAL_ZSTD */
|
||||||
172
vendor/github.com/DataDog/zstd/bitstream.h
generated
vendored
172
vendor/github.com/DataDog/zstd/bitstream.h
generated
vendored
@@ -1,35 +1,16 @@
|
|||||||
|
#ifndef USE_EXTERNAL_ZSTD
|
||||||
/* ******************************************************************
|
/* ******************************************************************
|
||||||
bitstream
|
* bitstream
|
||||||
Part of FSE library
|
* Part of FSE library
|
||||||
Copyright (C) 2013-present, Yann Collet.
|
* Copyright (c) Meta Platforms, Inc. and affiliates.
|
||||||
|
*
|
||||||
BSD 2-Clause License (http://www.opensource.org/licenses/bsd-license.php)
|
* You can contact the author at :
|
||||||
|
* - Source repository : https://github.com/Cyan4973/FiniteStateEntropy
|
||||||
Redistribution and use in source and binary forms, with or without
|
*
|
||||||
modification, are permitted provided that the following conditions are
|
* This source code is licensed under both the BSD-style license (found in the
|
||||||
met:
|
* LICENSE file in the root directory of this source tree) and the GPLv2 (found
|
||||||
|
* in the COPYING file in the root directory of this source tree).
|
||||||
* Redistributions of source code must retain the above copyright
|
* You may select, at your option, one of the above-listed licenses.
|
||||||
notice, this list of conditions and the following disclaimer.
|
|
||||||
* Redistributions in binary form must reproduce the above
|
|
||||||
copyright notice, this list of conditions and the following disclaimer
|
|
||||||
in the documentation and/or other materials provided with the
|
|
||||||
distribution.
|
|
||||||
|
|
||||||
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
|
||||||
"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
|
||||||
LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
|
||||||
A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
|
|
||||||
OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
|
||||||
SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
|
||||||
LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
|
||||||
DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
|
||||||
THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
|
||||||
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
|
||||||
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
|
||||||
|
|
||||||
You can contact the author at :
|
|
||||||
- Source repository : https://github.com/Cyan4973/FiniteStateEntropy
|
|
||||||
****************************************************************** */
|
****************************************************************** */
|
||||||
#ifndef BITSTREAM_H_MODULE
|
#ifndef BITSTREAM_H_MODULE
|
||||||
#define BITSTREAM_H_MODULE
|
#define BITSTREAM_H_MODULE
|
||||||
@@ -37,7 +18,6 @@
|
|||||||
#if defined (__cplusplus)
|
#if defined (__cplusplus)
|
||||||
extern "C" {
|
extern "C" {
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* This API consists of small unitary functions, which must be inlined for best performance.
|
* This API consists of small unitary functions, which must be inlined for best performance.
|
||||||
* Since link-time-optimization is not available for all compilers,
|
* Since link-time-optimization is not available for all compilers,
|
||||||
@@ -48,17 +28,21 @@ extern "C" {
|
|||||||
* Dependencies
|
* Dependencies
|
||||||
******************************************/
|
******************************************/
|
||||||
#include "mem.h" /* unaligned access routines */
|
#include "mem.h" /* unaligned access routines */
|
||||||
|
#include "compiler.h" /* UNLIKELY() */
|
||||||
#include "debug.h" /* assert(), DEBUGLOG(), RAWLOG() */
|
#include "debug.h" /* assert(), DEBUGLOG(), RAWLOG() */
|
||||||
#include "error_private.h" /* error codes and messages */
|
#include "error_private.h" /* error codes and messages */
|
||||||
|
#include "bits.h" /* ZSTD_highbit32 */
|
||||||
|
|
||||||
|
|
||||||
/*=========================================
|
/*=========================================
|
||||||
* Target specific
|
* Target specific
|
||||||
=========================================*/
|
=========================================*/
|
||||||
#if defined(__BMI__) && defined(__GNUC__)
|
#ifndef ZSTD_NO_INTRINSICS
|
||||||
# include <immintrin.h> /* support for bextr (experimental) */
|
# if (defined(__BMI__) || defined(__BMI2__)) && defined(__GNUC__)
|
||||||
#elif defined(__ICCARM__)
|
# include <immintrin.h> /* support for bextr (experimental)/bzhi */
|
||||||
|
# elif defined(__ICCARM__)
|
||||||
# include <intrinsics.h>
|
# include <intrinsics.h>
|
||||||
|
# endif
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#define STREAM_ACCUMULATOR_MIN_32 25
|
#define STREAM_ACCUMULATOR_MIN_32 25
|
||||||
@@ -150,39 +134,6 @@ MEM_STATIC void BIT_flushBitsFast(BIT_CStream_t* bitC);
|
|||||||
MEM_STATIC size_t BIT_readBitsFast(BIT_DStream_t* bitD, unsigned nbBits);
|
MEM_STATIC size_t BIT_readBitsFast(BIT_DStream_t* bitD, unsigned nbBits);
|
||||||
/* faster, but works only if nbBits >= 1 */
|
/* faster, but works only if nbBits >= 1 */
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/*-**************************************************************
|
|
||||||
* Internal functions
|
|
||||||
****************************************************************/
|
|
||||||
MEM_STATIC unsigned BIT_highbit32 (U32 val)
|
|
||||||
{
|
|
||||||
assert(val != 0);
|
|
||||||
{
|
|
||||||
# if defined(_MSC_VER) /* Visual */
|
|
||||||
unsigned long r=0;
|
|
||||||
_BitScanReverse ( &r, val );
|
|
||||||
return (unsigned) r;
|
|
||||||
# elif defined(__GNUC__) && (__GNUC__ >= 3) /* Use GCC Intrinsic */
|
|
||||||
return __builtin_clz (val) ^ 31;
|
|
||||||
# elif defined(__ICCARM__) /* IAR Intrinsic */
|
|
||||||
return 31 - __CLZ(val);
|
|
||||||
# else /* Software version */
|
|
||||||
static const unsigned DeBruijnClz[32] = { 0, 9, 1, 10, 13, 21, 2, 29,
|
|
||||||
11, 14, 16, 18, 22, 25, 3, 30,
|
|
||||||
8, 12, 20, 28, 15, 17, 24, 7,
|
|
||||||
19, 27, 23, 6, 26, 5, 4, 31 };
|
|
||||||
U32 v = val;
|
|
||||||
v |= v >> 1;
|
|
||||||
v |= v >> 2;
|
|
||||||
v |= v >> 4;
|
|
||||||
v |= v >> 8;
|
|
||||||
v |= v >> 16;
|
|
||||||
return DeBruijnClz[ (U32) (v * 0x07C4ACDDU) >> 27];
|
|
||||||
# endif
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/*===== Local Constants =====*/
|
/*===== Local Constants =====*/
|
||||||
static const unsigned BIT_mask[] = {
|
static const unsigned BIT_mask[] = {
|
||||||
0, 1, 3, 7, 0xF, 0x1F,
|
0, 1, 3, 7, 0xF, 0x1F,
|
||||||
@@ -212,16 +163,26 @@ MEM_STATIC size_t BIT_initCStream(BIT_CStream_t* bitC,
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
MEM_STATIC FORCE_INLINE_ATTR size_t BIT_getLowerBits(size_t bitContainer, U32 const nbBits)
|
||||||
|
{
|
||||||
|
#if defined(STATIC_BMI2) && STATIC_BMI2 == 1 && !defined(ZSTD_NO_INTRINSICS)
|
||||||
|
return _bzhi_u64(bitContainer, nbBits);
|
||||||
|
#else
|
||||||
|
assert(nbBits < BIT_MASK_SIZE);
|
||||||
|
return bitContainer & BIT_mask[nbBits];
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
|
||||||
/*! BIT_addBits() :
|
/*! BIT_addBits() :
|
||||||
* can add up to 31 bits into `bitC`.
|
* can add up to 31 bits into `bitC`.
|
||||||
* Note : does not check for register overflow ! */
|
* Note : does not check for register overflow ! */
|
||||||
MEM_STATIC void BIT_addBits(BIT_CStream_t* bitC,
|
MEM_STATIC void BIT_addBits(BIT_CStream_t* bitC,
|
||||||
size_t value, unsigned nbBits)
|
size_t value, unsigned nbBits)
|
||||||
{
|
{
|
||||||
MEM_STATIC_ASSERT(BIT_MASK_SIZE == 32);
|
DEBUG_STATIC_ASSERT(BIT_MASK_SIZE == 32);
|
||||||
assert(nbBits < BIT_MASK_SIZE);
|
assert(nbBits < BIT_MASK_SIZE);
|
||||||
assert(nbBits + bitC->bitPos < sizeof(bitC->bitContainer) * 8);
|
assert(nbBits + bitC->bitPos < sizeof(bitC->bitContainer) * 8);
|
||||||
bitC->bitContainer |= (value & BIT_mask[nbBits]) << bitC->bitPos;
|
bitC->bitContainer |= BIT_getLowerBits(value, nbBits) << bitC->bitPos;
|
||||||
bitC->bitPos += nbBits;
|
bitC->bitPos += nbBits;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -291,7 +252,7 @@ MEM_STATIC size_t BIT_closeCStream(BIT_CStream_t* bitC)
|
|||||||
*/
|
*/
|
||||||
MEM_STATIC size_t BIT_initDStream(BIT_DStream_t* bitD, const void* srcBuffer, size_t srcSize)
|
MEM_STATIC size_t BIT_initDStream(BIT_DStream_t* bitD, const void* srcBuffer, size_t srcSize)
|
||||||
{
|
{
|
||||||
if (srcSize < 1) { memset(bitD, 0, sizeof(*bitD)); return ERROR(srcSize_wrong); }
|
if (srcSize < 1) { ZSTD_memset(bitD, 0, sizeof(*bitD)); return ERROR(srcSize_wrong); }
|
||||||
|
|
||||||
bitD->start = (const char*)srcBuffer;
|
bitD->start = (const char*)srcBuffer;
|
||||||
bitD->limitPtr = bitD->start + sizeof(bitD->bitContainer);
|
bitD->limitPtr = bitD->start + sizeof(bitD->bitContainer);
|
||||||
@@ -300,7 +261,7 @@ MEM_STATIC size_t BIT_initDStream(BIT_DStream_t* bitD, const void* srcBuffer, si
|
|||||||
bitD->ptr = (const char*)srcBuffer + srcSize - sizeof(bitD->bitContainer);
|
bitD->ptr = (const char*)srcBuffer + srcSize - sizeof(bitD->bitContainer);
|
||||||
bitD->bitContainer = MEM_readLEST(bitD->ptr);
|
bitD->bitContainer = MEM_readLEST(bitD->ptr);
|
||||||
{ BYTE const lastByte = ((const BYTE*)srcBuffer)[srcSize-1];
|
{ BYTE const lastByte = ((const BYTE*)srcBuffer)[srcSize-1];
|
||||||
bitD->bitsConsumed = lastByte ? 8 - BIT_highbit32(lastByte) : 0; /* ensures bitsConsumed is always set */
|
bitD->bitsConsumed = lastByte ? 8 - ZSTD_highbit32(lastByte) : 0; /* ensures bitsConsumed is always set */
|
||||||
if (lastByte == 0) return ERROR(GENERIC); /* endMark not present */ }
|
if (lastByte == 0) return ERROR(GENERIC); /* endMark not present */ }
|
||||||
} else {
|
} else {
|
||||||
bitD->ptr = bitD->start;
|
bitD->ptr = bitD->start;
|
||||||
@@ -308,27 +269,27 @@ MEM_STATIC size_t BIT_initDStream(BIT_DStream_t* bitD, const void* srcBuffer, si
|
|||||||
switch(srcSize)
|
switch(srcSize)
|
||||||
{
|
{
|
||||||
case 7: bitD->bitContainer += (size_t)(((const BYTE*)(srcBuffer))[6]) << (sizeof(bitD->bitContainer)*8 - 16);
|
case 7: bitD->bitContainer += (size_t)(((const BYTE*)(srcBuffer))[6]) << (sizeof(bitD->bitContainer)*8 - 16);
|
||||||
/* fall-through */
|
ZSTD_FALLTHROUGH;
|
||||||
|
|
||||||
case 6: bitD->bitContainer += (size_t)(((const BYTE*)(srcBuffer))[5]) << (sizeof(bitD->bitContainer)*8 - 24);
|
case 6: bitD->bitContainer += (size_t)(((const BYTE*)(srcBuffer))[5]) << (sizeof(bitD->bitContainer)*8 - 24);
|
||||||
/* fall-through */
|
ZSTD_FALLTHROUGH;
|
||||||
|
|
||||||
case 5: bitD->bitContainer += (size_t)(((const BYTE*)(srcBuffer))[4]) << (sizeof(bitD->bitContainer)*8 - 32);
|
case 5: bitD->bitContainer += (size_t)(((const BYTE*)(srcBuffer))[4]) << (sizeof(bitD->bitContainer)*8 - 32);
|
||||||
/* fall-through */
|
ZSTD_FALLTHROUGH;
|
||||||
|
|
||||||
case 4: bitD->bitContainer += (size_t)(((const BYTE*)(srcBuffer))[3]) << 24;
|
case 4: bitD->bitContainer += (size_t)(((const BYTE*)(srcBuffer))[3]) << 24;
|
||||||
/* fall-through */
|
ZSTD_FALLTHROUGH;
|
||||||
|
|
||||||
case 3: bitD->bitContainer += (size_t)(((const BYTE*)(srcBuffer))[2]) << 16;
|
case 3: bitD->bitContainer += (size_t)(((const BYTE*)(srcBuffer))[2]) << 16;
|
||||||
/* fall-through */
|
ZSTD_FALLTHROUGH;
|
||||||
|
|
||||||
case 2: bitD->bitContainer += (size_t)(((const BYTE*)(srcBuffer))[1]) << 8;
|
case 2: bitD->bitContainer += (size_t)(((const BYTE*)(srcBuffer))[1]) << 8;
|
||||||
/* fall-through */
|
ZSTD_FALLTHROUGH;
|
||||||
|
|
||||||
default: break;
|
default: break;
|
||||||
}
|
}
|
||||||
{ BYTE const lastByte = ((const BYTE*)srcBuffer)[srcSize-1];
|
{ BYTE const lastByte = ((const BYTE*)srcBuffer)[srcSize-1];
|
||||||
bitD->bitsConsumed = lastByte ? 8 - BIT_highbit32(lastByte) : 0;
|
bitD->bitsConsumed = lastByte ? 8 - ZSTD_highbit32(lastByte) : 0;
|
||||||
if (lastByte == 0) return ERROR(corruption_detected); /* endMark not present */
|
if (lastByte == 0) return ERROR(corruption_detected); /* endMark not present */
|
||||||
}
|
}
|
||||||
bitD->bitsConsumed += (U32)(sizeof(bitD->bitContainer) - srcSize)*8;
|
bitD->bitsConsumed += (U32)(sizeof(bitD->bitContainer) - srcSize)*8;
|
||||||
@@ -337,23 +298,26 @@ MEM_STATIC size_t BIT_initDStream(BIT_DStream_t* bitD, const void* srcBuffer, si
|
|||||||
return srcSize;
|
return srcSize;
|
||||||
}
|
}
|
||||||
|
|
||||||
MEM_STATIC size_t BIT_getUpperBits(size_t bitContainer, U32 const start)
|
MEM_STATIC FORCE_INLINE_ATTR size_t BIT_getUpperBits(size_t bitContainer, U32 const start)
|
||||||
{
|
{
|
||||||
return bitContainer >> start;
|
return bitContainer >> start;
|
||||||
}
|
}
|
||||||
|
|
||||||
MEM_STATIC size_t BIT_getMiddleBits(size_t bitContainer, U32 const start, U32 const nbBits)
|
MEM_STATIC FORCE_INLINE_ATTR size_t BIT_getMiddleBits(size_t bitContainer, U32 const start, U32 const nbBits)
|
||||||
{
|
{
|
||||||
U32 const regMask = sizeof(bitContainer)*8 - 1;
|
U32 const regMask = sizeof(bitContainer)*8 - 1;
|
||||||
/* if start > regMask, bitstream is corrupted, and result is undefined */
|
/* if start > regMask, bitstream is corrupted, and result is undefined */
|
||||||
assert(nbBits < BIT_MASK_SIZE);
|
assert(nbBits < BIT_MASK_SIZE);
|
||||||
|
/* x86 transform & ((1 << nbBits) - 1) to bzhi instruction, it is better
|
||||||
|
* than accessing memory. When bmi2 instruction is not present, we consider
|
||||||
|
* such cpus old (pre-Haswell, 2013) and their performance is not of that
|
||||||
|
* importance.
|
||||||
|
*/
|
||||||
|
#if defined(__x86_64__) || defined(_M_X86)
|
||||||
|
return (bitContainer >> (start & regMask)) & ((((U64)1) << nbBits) - 1);
|
||||||
|
#else
|
||||||
return (bitContainer >> (start & regMask)) & BIT_mask[nbBits];
|
return (bitContainer >> (start & regMask)) & BIT_mask[nbBits];
|
||||||
}
|
#endif
|
||||||
|
|
||||||
MEM_STATIC size_t BIT_getLowerBits(size_t bitContainer, U32 const nbBits)
|
|
||||||
{
|
|
||||||
assert(nbBits < BIT_MASK_SIZE);
|
|
||||||
return bitContainer & BIT_mask[nbBits];
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/*! BIT_lookBits() :
|
/*! BIT_lookBits() :
|
||||||
@@ -362,7 +326,7 @@ MEM_STATIC size_t BIT_getLowerBits(size_t bitContainer, U32 const nbBits)
|
|||||||
* On 32-bits, maxNbBits==24.
|
* On 32-bits, maxNbBits==24.
|
||||||
* On 64-bits, maxNbBits==56.
|
* On 64-bits, maxNbBits==56.
|
||||||
* @return : value extracted */
|
* @return : value extracted */
|
||||||
MEM_STATIC size_t BIT_lookBits(const BIT_DStream_t* bitD, U32 nbBits)
|
MEM_STATIC FORCE_INLINE_ATTR size_t BIT_lookBits(const BIT_DStream_t* bitD, U32 nbBits)
|
||||||
{
|
{
|
||||||
/* arbitrate between double-shift and shift+mask */
|
/* arbitrate between double-shift and shift+mask */
|
||||||
#if 1
|
#if 1
|
||||||
@@ -385,7 +349,7 @@ MEM_STATIC size_t BIT_lookBitsFast(const BIT_DStream_t* bitD, U32 nbBits)
|
|||||||
return (bitD->bitContainer << (bitD->bitsConsumed & regMask)) >> (((regMask+1)-nbBits) & regMask);
|
return (bitD->bitContainer << (bitD->bitsConsumed & regMask)) >> (((regMask+1)-nbBits) & regMask);
|
||||||
}
|
}
|
||||||
|
|
||||||
MEM_STATIC void BIT_skipBits(BIT_DStream_t* bitD, U32 nbBits)
|
MEM_STATIC FORCE_INLINE_ATTR void BIT_skipBits(BIT_DStream_t* bitD, U32 nbBits)
|
||||||
{
|
{
|
||||||
bitD->bitsConsumed += nbBits;
|
bitD->bitsConsumed += nbBits;
|
||||||
}
|
}
|
||||||
@@ -394,7 +358,7 @@ MEM_STATIC void BIT_skipBits(BIT_DStream_t* bitD, U32 nbBits)
|
|||||||
* Read (consume) next n bits from local register and update.
|
* Read (consume) next n bits from local register and update.
|
||||||
* Pay attention to not read more than nbBits contained into local register.
|
* Pay attention to not read more than nbBits contained into local register.
|
||||||
* @return : extracted value. */
|
* @return : extracted value. */
|
||||||
MEM_STATIC size_t BIT_readBits(BIT_DStream_t* bitD, unsigned nbBits)
|
MEM_STATIC FORCE_INLINE_ATTR size_t BIT_readBits(BIT_DStream_t* bitD, unsigned nbBits)
|
||||||
{
|
{
|
||||||
size_t const value = BIT_lookBits(bitD, nbBits);
|
size_t const value = BIT_lookBits(bitD, nbBits);
|
||||||
BIT_skipBits(bitD, nbBits);
|
BIT_skipBits(bitD, nbBits);
|
||||||
@@ -402,7 +366,7 @@ MEM_STATIC size_t BIT_readBits(BIT_DStream_t* bitD, unsigned nbBits)
|
|||||||
}
|
}
|
||||||
|
|
||||||
/*! BIT_readBitsFast() :
|
/*! BIT_readBitsFast() :
|
||||||
* unsafe version; only works only if nbBits >= 1 */
|
* unsafe version; only works if nbBits >= 1 */
|
||||||
MEM_STATIC size_t BIT_readBitsFast(BIT_DStream_t* bitD, unsigned nbBits)
|
MEM_STATIC size_t BIT_readBitsFast(BIT_DStream_t* bitD, unsigned nbBits)
|
||||||
{
|
{
|
||||||
size_t const value = BIT_lookBitsFast(bitD, nbBits);
|
size_t const value = BIT_lookBitsFast(bitD, nbBits);
|
||||||
@@ -411,21 +375,35 @@ MEM_STATIC size_t BIT_readBitsFast(BIT_DStream_t* bitD, unsigned nbBits)
|
|||||||
return value;
|
return value;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/*! BIT_reloadDStreamFast() :
|
||||||
|
* Similar to BIT_reloadDStream(), but with two differences:
|
||||||
|
* 1. bitsConsumed <= sizeof(bitD->bitContainer)*8 must hold!
|
||||||
|
* 2. Returns BIT_DStream_overflow when bitD->ptr < bitD->limitPtr, at this
|
||||||
|
* point you must use BIT_reloadDStream() to reload.
|
||||||
|
*/
|
||||||
|
MEM_STATIC BIT_DStream_status BIT_reloadDStreamFast(BIT_DStream_t* bitD)
|
||||||
|
{
|
||||||
|
if (UNLIKELY(bitD->ptr < bitD->limitPtr))
|
||||||
|
return BIT_DStream_overflow;
|
||||||
|
assert(bitD->bitsConsumed <= sizeof(bitD->bitContainer)*8);
|
||||||
|
bitD->ptr -= bitD->bitsConsumed >> 3;
|
||||||
|
bitD->bitsConsumed &= 7;
|
||||||
|
bitD->bitContainer = MEM_readLEST(bitD->ptr);
|
||||||
|
return BIT_DStream_unfinished;
|
||||||
|
}
|
||||||
|
|
||||||
/*! BIT_reloadDStream() :
|
/*! BIT_reloadDStream() :
|
||||||
* Refill `bitD` from buffer previously set in BIT_initDStream() .
|
* Refill `bitD` from buffer previously set in BIT_initDStream() .
|
||||||
* This function is safe, it guarantees it will not read beyond src buffer.
|
* This function is safe, it guarantees it will not read beyond src buffer.
|
||||||
* @return : status of `BIT_DStream_t` internal register.
|
* @return : status of `BIT_DStream_t` internal register.
|
||||||
* when status == BIT_DStream_unfinished, internal register is filled with at least 25 or 57 bits */
|
* when status == BIT_DStream_unfinished, internal register is filled with at least 25 or 57 bits */
|
||||||
MEM_STATIC BIT_DStream_status BIT_reloadDStream(BIT_DStream_t* bitD)
|
MEM_STATIC FORCE_INLINE_ATTR BIT_DStream_status BIT_reloadDStream(BIT_DStream_t* bitD)
|
||||||
{
|
{
|
||||||
if (bitD->bitsConsumed > (sizeof(bitD->bitContainer)*8)) /* overflow detected, like end of stream */
|
if (bitD->bitsConsumed > (sizeof(bitD->bitContainer)*8)) /* overflow detected, like end of stream */
|
||||||
return BIT_DStream_overflow;
|
return BIT_DStream_overflow;
|
||||||
|
|
||||||
if (bitD->ptr >= bitD->limitPtr) {
|
if (bitD->ptr >= bitD->limitPtr) {
|
||||||
bitD->ptr -= bitD->bitsConsumed >> 3;
|
return BIT_reloadDStreamFast(bitD);
|
||||||
bitD->bitsConsumed &= 7;
|
|
||||||
bitD->bitContainer = MEM_readLEST(bitD->ptr);
|
|
||||||
return BIT_DStream_unfinished;
|
|
||||||
}
|
}
|
||||||
if (bitD->ptr == bitD->start) {
|
if (bitD->ptr == bitD->start) {
|
||||||
if (bitD->bitsConsumed < sizeof(bitD->bitContainer)*8) return BIT_DStream_endOfBuffer;
|
if (bitD->bitsConsumed < sizeof(bitD->bitContainer)*8) return BIT_DStream_endOfBuffer;
|
||||||
@@ -458,3 +436,5 @@ MEM_STATIC unsigned BIT_endOfDStream(const BIT_DStream_t* DStream)
|
|||||||
#endif
|
#endif
|
||||||
|
|
||||||
#endif /* BITSTREAM_H_MODULE */
|
#endif /* BITSTREAM_H_MODULE */
|
||||||
|
|
||||||
|
#endif /* USE_EXTERNAL_ZSTD */
|
||||||
|
|||||||
137
vendor/github.com/DataDog/zstd/clevels.h
generated
vendored
Normal file
137
vendor/github.com/DataDog/zstd/clevels.h
generated
vendored
Normal file
@@ -0,0 +1,137 @@
|
|||||||
|
#ifndef USE_EXTERNAL_ZSTD
|
||||||
|
/*
|
||||||
|
* Copyright (c) Meta Platforms, Inc. and affiliates.
|
||||||
|
* All rights reserved.
|
||||||
|
*
|
||||||
|
* This source code is licensed under both the BSD-style license (found in the
|
||||||
|
* LICENSE file in the root directory of this source tree) and the GPLv2 (found
|
||||||
|
* in the COPYING file in the root directory of this source tree).
|
||||||
|
* You may select, at your option, one of the above-listed licenses.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#ifndef ZSTD_CLEVELS_H
|
||||||
|
#define ZSTD_CLEVELS_H
|
||||||
|
|
||||||
|
#define ZSTD_STATIC_LINKING_ONLY /* ZSTD_compressionParameters */
|
||||||
|
#include "zstd.h"
|
||||||
|
|
||||||
|
/*-===== Pre-defined compression levels =====-*/
|
||||||
|
|
||||||
|
#define ZSTD_MAX_CLEVEL 22
|
||||||
|
|
||||||
|
#ifdef __GNUC__
|
||||||
|
__attribute__((__unused__))
|
||||||
|
#endif
|
||||||
|
|
||||||
|
static const ZSTD_compressionParameters ZSTD_defaultCParameters[4][ZSTD_MAX_CLEVEL+1] = {
|
||||||
|
{ /* "default" - for any srcSize > 256 KB */
|
||||||
|
/* W, C, H, S, L, TL, strat */
|
||||||
|
{ 19, 12, 13, 1, 6, 1, ZSTD_fast }, /* base for negative levels */
|
||||||
|
{ 19, 13, 14, 1, 7, 0, ZSTD_fast }, /* level 1 */
|
||||||
|
{ 20, 15, 16, 1, 6, 0, ZSTD_fast }, /* level 2 */
|
||||||
|
{ 21, 16, 17, 1, 5, 0, ZSTD_dfast }, /* level 3 */
|
||||||
|
{ 21, 18, 18, 1, 5, 0, ZSTD_dfast }, /* level 4 */
|
||||||
|
{ 21, 18, 19, 3, 5, 2, ZSTD_greedy }, /* level 5 */
|
||||||
|
{ 21, 18, 19, 3, 5, 4, ZSTD_lazy }, /* level 6 */
|
||||||
|
{ 21, 19, 20, 4, 5, 8, ZSTD_lazy }, /* level 7 */
|
||||||
|
{ 21, 19, 20, 4, 5, 16, ZSTD_lazy2 }, /* level 8 */
|
||||||
|
{ 22, 20, 21, 4, 5, 16, ZSTD_lazy2 }, /* level 9 */
|
||||||
|
{ 22, 21, 22, 5, 5, 16, ZSTD_lazy2 }, /* level 10 */
|
||||||
|
{ 22, 21, 22, 6, 5, 16, ZSTD_lazy2 }, /* level 11 */
|
||||||
|
{ 22, 22, 23, 6, 5, 32, ZSTD_lazy2 }, /* level 12 */
|
||||||
|
{ 22, 22, 22, 4, 5, 32, ZSTD_btlazy2 }, /* level 13 */
|
||||||
|
{ 22, 22, 23, 5, 5, 32, ZSTD_btlazy2 }, /* level 14 */
|
||||||
|
{ 22, 23, 23, 6, 5, 32, ZSTD_btlazy2 }, /* level 15 */
|
||||||
|
{ 22, 22, 22, 5, 5, 48, ZSTD_btopt }, /* level 16 */
|
||||||
|
{ 23, 23, 22, 5, 4, 64, ZSTD_btopt }, /* level 17 */
|
||||||
|
{ 23, 23, 22, 6, 3, 64, ZSTD_btultra }, /* level 18 */
|
||||||
|
{ 23, 24, 22, 7, 3,256, ZSTD_btultra2}, /* level 19 */
|
||||||
|
{ 25, 25, 23, 7, 3,256, ZSTD_btultra2}, /* level 20 */
|
||||||
|
{ 26, 26, 24, 7, 3,512, ZSTD_btultra2}, /* level 21 */
|
||||||
|
{ 27, 27, 25, 9, 3,999, ZSTD_btultra2}, /* level 22 */
|
||||||
|
},
|
||||||
|
{ /* for srcSize <= 256 KB */
|
||||||
|
/* W, C, H, S, L, T, strat */
|
||||||
|
{ 18, 12, 13, 1, 5, 1, ZSTD_fast }, /* base for negative levels */
|
||||||
|
{ 18, 13, 14, 1, 6, 0, ZSTD_fast }, /* level 1 */
|
||||||
|
{ 18, 14, 14, 1, 5, 0, ZSTD_dfast }, /* level 2 */
|
||||||
|
{ 18, 16, 16, 1, 4, 0, ZSTD_dfast }, /* level 3 */
|
||||||
|
{ 18, 16, 17, 3, 5, 2, ZSTD_greedy }, /* level 4.*/
|
||||||
|
{ 18, 17, 18, 5, 5, 2, ZSTD_greedy }, /* level 5.*/
|
||||||
|
{ 18, 18, 19, 3, 5, 4, ZSTD_lazy }, /* level 6.*/
|
||||||
|
{ 18, 18, 19, 4, 4, 4, ZSTD_lazy }, /* level 7 */
|
||||||
|
{ 18, 18, 19, 4, 4, 8, ZSTD_lazy2 }, /* level 8 */
|
||||||
|
{ 18, 18, 19, 5, 4, 8, ZSTD_lazy2 }, /* level 9 */
|
||||||
|
{ 18, 18, 19, 6, 4, 8, ZSTD_lazy2 }, /* level 10 */
|
||||||
|
{ 18, 18, 19, 5, 4, 12, ZSTD_btlazy2 }, /* level 11.*/
|
||||||
|
{ 18, 19, 19, 7, 4, 12, ZSTD_btlazy2 }, /* level 12.*/
|
||||||
|
{ 18, 18, 19, 4, 4, 16, ZSTD_btopt }, /* level 13 */
|
||||||
|
{ 18, 18, 19, 4, 3, 32, ZSTD_btopt }, /* level 14.*/
|
||||||
|
{ 18, 18, 19, 6, 3,128, ZSTD_btopt }, /* level 15.*/
|
||||||
|
{ 18, 19, 19, 6, 3,128, ZSTD_btultra }, /* level 16.*/
|
||||||
|
{ 18, 19, 19, 8, 3,256, ZSTD_btultra }, /* level 17.*/
|
||||||
|
{ 18, 19, 19, 6, 3,128, ZSTD_btultra2}, /* level 18.*/
|
||||||
|
{ 18, 19, 19, 8, 3,256, ZSTD_btultra2}, /* level 19.*/
|
||||||
|
{ 18, 19, 19, 10, 3,512, ZSTD_btultra2}, /* level 20.*/
|
||||||
|
{ 18, 19, 19, 12, 3,512, ZSTD_btultra2}, /* level 21.*/
|
||||||
|
{ 18, 19, 19, 13, 3,999, ZSTD_btultra2}, /* level 22.*/
|
||||||
|
},
|
||||||
|
{ /* for srcSize <= 128 KB */
|
||||||
|
/* W, C, H, S, L, T, strat */
|
||||||
|
{ 17, 12, 12, 1, 5, 1, ZSTD_fast }, /* base for negative levels */
|
||||||
|
{ 17, 12, 13, 1, 6, 0, ZSTD_fast }, /* level 1 */
|
||||||
|
{ 17, 13, 15, 1, 5, 0, ZSTD_fast }, /* level 2 */
|
||||||
|
{ 17, 15, 16, 2, 5, 0, ZSTD_dfast }, /* level 3 */
|
||||||
|
{ 17, 17, 17, 2, 4, 0, ZSTD_dfast }, /* level 4 */
|
||||||
|
{ 17, 16, 17, 3, 4, 2, ZSTD_greedy }, /* level 5 */
|
||||||
|
{ 17, 16, 17, 3, 4, 4, ZSTD_lazy }, /* level 6 */
|
||||||
|
{ 17, 16, 17, 3, 4, 8, ZSTD_lazy2 }, /* level 7 */
|
||||||
|
{ 17, 16, 17, 4, 4, 8, ZSTD_lazy2 }, /* level 8 */
|
||||||
|
{ 17, 16, 17, 5, 4, 8, ZSTD_lazy2 }, /* level 9 */
|
||||||
|
{ 17, 16, 17, 6, 4, 8, ZSTD_lazy2 }, /* level 10 */
|
||||||
|
{ 17, 17, 17, 5, 4, 8, ZSTD_btlazy2 }, /* level 11 */
|
||||||
|
{ 17, 18, 17, 7, 4, 12, ZSTD_btlazy2 }, /* level 12 */
|
||||||
|
{ 17, 18, 17, 3, 4, 12, ZSTD_btopt }, /* level 13.*/
|
||||||
|
{ 17, 18, 17, 4, 3, 32, ZSTD_btopt }, /* level 14.*/
|
||||||
|
{ 17, 18, 17, 6, 3,256, ZSTD_btopt }, /* level 15.*/
|
||||||
|
{ 17, 18, 17, 6, 3,128, ZSTD_btultra }, /* level 16.*/
|
||||||
|
{ 17, 18, 17, 8, 3,256, ZSTD_btultra }, /* level 17.*/
|
||||||
|
{ 17, 18, 17, 10, 3,512, ZSTD_btultra }, /* level 18.*/
|
||||||
|
{ 17, 18, 17, 5, 3,256, ZSTD_btultra2}, /* level 19.*/
|
||||||
|
{ 17, 18, 17, 7, 3,512, ZSTD_btultra2}, /* level 20.*/
|
||||||
|
{ 17, 18, 17, 9, 3,512, ZSTD_btultra2}, /* level 21.*/
|
||||||
|
{ 17, 18, 17, 11, 3,999, ZSTD_btultra2}, /* level 22.*/
|
||||||
|
},
|
||||||
|
{ /* for srcSize <= 16 KB */
|
||||||
|
/* W, C, H, S, L, T, strat */
|
||||||
|
{ 14, 12, 13, 1, 5, 1, ZSTD_fast }, /* base for negative levels */
|
||||||
|
{ 14, 14, 15, 1, 5, 0, ZSTD_fast }, /* level 1 */
|
||||||
|
{ 14, 14, 15, 1, 4, 0, ZSTD_fast }, /* level 2 */
|
||||||
|
{ 14, 14, 15, 2, 4, 0, ZSTD_dfast }, /* level 3 */
|
||||||
|
{ 14, 14, 14, 4, 4, 2, ZSTD_greedy }, /* level 4 */
|
||||||
|
{ 14, 14, 14, 3, 4, 4, ZSTD_lazy }, /* level 5.*/
|
||||||
|
{ 14, 14, 14, 4, 4, 8, ZSTD_lazy2 }, /* level 6 */
|
||||||
|
{ 14, 14, 14, 6, 4, 8, ZSTD_lazy2 }, /* level 7 */
|
||||||
|
{ 14, 14, 14, 8, 4, 8, ZSTD_lazy2 }, /* level 8.*/
|
||||||
|
{ 14, 15, 14, 5, 4, 8, ZSTD_btlazy2 }, /* level 9.*/
|
||||||
|
{ 14, 15, 14, 9, 4, 8, ZSTD_btlazy2 }, /* level 10.*/
|
||||||
|
{ 14, 15, 14, 3, 4, 12, ZSTD_btopt }, /* level 11.*/
|
||||||
|
{ 14, 15, 14, 4, 3, 24, ZSTD_btopt }, /* level 12.*/
|
||||||
|
{ 14, 15, 14, 5, 3, 32, ZSTD_btultra }, /* level 13.*/
|
||||||
|
{ 14, 15, 15, 6, 3, 64, ZSTD_btultra }, /* level 14.*/
|
||||||
|
{ 14, 15, 15, 7, 3,256, ZSTD_btultra }, /* level 15.*/
|
||||||
|
{ 14, 15, 15, 5, 3, 48, ZSTD_btultra2}, /* level 16.*/
|
||||||
|
{ 14, 15, 15, 6, 3,128, ZSTD_btultra2}, /* level 17.*/
|
||||||
|
{ 14, 15, 15, 7, 3,256, ZSTD_btultra2}, /* level 18.*/
|
||||||
|
{ 14, 15, 15, 8, 3,256, ZSTD_btultra2}, /* level 19.*/
|
||||||
|
{ 14, 15, 15, 8, 3,512, ZSTD_btultra2}, /* level 20.*/
|
||||||
|
{ 14, 15, 15, 9, 3,512, ZSTD_btultra2}, /* level 21.*/
|
||||||
|
{ 14, 15, 15, 10, 3,999, ZSTD_btultra2}, /* level 22.*/
|
||||||
|
},
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
#endif /* ZSTD_CLEVELS_H */
|
||||||
|
|
||||||
|
#endif /* USE_EXTERNAL_ZSTD */
|
||||||
242
vendor/github.com/DataDog/zstd/compiler.h
generated
vendored
242
vendor/github.com/DataDog/zstd/compiler.h
generated
vendored
@@ -1,5 +1,6 @@
|
|||||||
|
#ifndef USE_EXTERNAL_ZSTD
|
||||||
/*
|
/*
|
||||||
* Copyright (c) 2016-present, Yann Collet, Facebook, Inc.
|
* Copyright (c) Meta Platforms, Inc. and affiliates.
|
||||||
* All rights reserved.
|
* All rights reserved.
|
||||||
*
|
*
|
||||||
* This source code is licensed under both the BSD-style license (found in the
|
* This source code is licensed under both the BSD-style license (found in the
|
||||||
@@ -11,13 +12,15 @@
|
|||||||
#ifndef ZSTD_COMPILER_H
|
#ifndef ZSTD_COMPILER_H
|
||||||
#define ZSTD_COMPILER_H
|
#define ZSTD_COMPILER_H
|
||||||
|
|
||||||
|
#include "portability_macros.h"
|
||||||
|
|
||||||
/*-*******************************************************
|
/*-*******************************************************
|
||||||
* Compiler specifics
|
* Compiler specifics
|
||||||
*********************************************************/
|
*********************************************************/
|
||||||
/* force inlining */
|
/* force inlining */
|
||||||
|
|
||||||
#if !defined(ZSTD_NO_INLINE)
|
#if !defined(ZSTD_NO_INLINE)
|
||||||
#if defined (__GNUC__) || defined(__cplusplus) || defined(__STDC_VERSION__) && __STDC_VERSION__ >= 199901L /* C99 */
|
#if (defined(__GNUC__) && !defined(__STRICT_ANSI__)) || defined(__cplusplus) || defined(__STDC_VERSION__) && __STDC_VERSION__ >= 199901L /* C99 */
|
||||||
# define INLINE_KEYWORD inline
|
# define INLINE_KEYWORD inline
|
||||||
#else
|
#else
|
||||||
# define INLINE_KEYWORD
|
# define INLINE_KEYWORD
|
||||||
@@ -38,6 +41,17 @@
|
|||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
/**
|
||||||
|
On MSVC qsort requires that functions passed into it use the __cdecl calling conversion(CC).
|
||||||
|
This explicitly marks such functions as __cdecl so that the code will still compile
|
||||||
|
if a CC other than __cdecl has been made the default.
|
||||||
|
*/
|
||||||
|
#if defined(_MSC_VER)
|
||||||
|
# define WIN_CDECL __cdecl
|
||||||
|
#else
|
||||||
|
# define WIN_CDECL
|
||||||
|
#endif
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* FORCE_INLINE_TEMPLATE is used to define C "templates", which take constant
|
* FORCE_INLINE_TEMPLATE is used to define C "templates", which take constant
|
||||||
* parameters. They must be inlined for the compiler to eliminate the constant
|
* parameters. They must be inlined for the compiler to eliminate the constant
|
||||||
@@ -79,30 +93,19 @@
|
|||||||
# endif
|
# endif
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
|
||||||
/* target attribute */
|
/* target attribute */
|
||||||
#ifndef __has_attribute
|
|
||||||
#define __has_attribute(x) 0 /* Compatibility with non-clang compilers. */
|
|
||||||
#endif
|
|
||||||
#if defined(__GNUC__) || defined(__ICCARM__)
|
#if defined(__GNUC__) || defined(__ICCARM__)
|
||||||
# define TARGET_ATTRIBUTE(target) __attribute__((__target__(target)))
|
# define TARGET_ATTRIBUTE(target) __attribute__((__target__(target)))
|
||||||
#else
|
#else
|
||||||
# define TARGET_ATTRIBUTE(target)
|
# define TARGET_ATTRIBUTE(target)
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
/* Enable runtime BMI2 dispatch based on the CPU.
|
/* Target attribute for BMI2 dynamic dispatch.
|
||||||
* Enabled for clang & gcc >=4.8 on x86 when BMI2 isn't enabled by default.
|
* Enable lzcnt, bmi, and bmi2.
|
||||||
|
* We test for bmi1 & bmi2. lzcnt is included in bmi1.
|
||||||
*/
|
*/
|
||||||
#ifndef DYNAMIC_BMI2
|
#define BMI2_TARGET_ATTRIBUTE TARGET_ATTRIBUTE("lzcnt,bmi,bmi2")
|
||||||
#if ((defined(__clang__) && __has_attribute(__target__)) \
|
|
||||||
|| (defined(__GNUC__) \
|
|
||||||
&& (__GNUC__ >= 5 || (__GNUC__ == 4 && __GNUC_MINOR__ >= 8)))) \
|
|
||||||
&& (defined(__x86_64__) || defined(_M_X86)) \
|
|
||||||
&& !defined(__BMI2__)
|
|
||||||
# define DYNAMIC_BMI2 1
|
|
||||||
#else
|
|
||||||
# define DYNAMIC_BMI2 0
|
|
||||||
#endif
|
|
||||||
#endif
|
|
||||||
|
|
||||||
/* prefetch
|
/* prefetch
|
||||||
* can be disabled, by declaring NO_PREFETCH build macro */
|
* can be disabled, by declaring NO_PREFETCH build macro */
|
||||||
@@ -117,6 +120,9 @@
|
|||||||
# elif defined(__GNUC__) && ( (__GNUC__ >= 4) || ( (__GNUC__ == 3) && (__GNUC_MINOR__ >= 1) ) )
|
# elif defined(__GNUC__) && ( (__GNUC__ >= 4) || ( (__GNUC__ == 3) && (__GNUC_MINOR__ >= 1) ) )
|
||||||
# define PREFETCH_L1(ptr) __builtin_prefetch((ptr), 0 /* rw==read */, 3 /* locality */)
|
# define PREFETCH_L1(ptr) __builtin_prefetch((ptr), 0 /* rw==read */, 3 /* locality */)
|
||||||
# define PREFETCH_L2(ptr) __builtin_prefetch((ptr), 0 /* rw==read */, 2 /* locality */)
|
# define PREFETCH_L2(ptr) __builtin_prefetch((ptr), 0 /* rw==read */, 2 /* locality */)
|
||||||
|
# elif defined(__aarch64__)
|
||||||
|
# define PREFETCH_L1(ptr) __asm__ __volatile__("prfm pldl1keep, %0" ::"Q"(*(ptr)))
|
||||||
|
# define PREFETCH_L2(ptr) __asm__ __volatile__("prfm pldl2keep, %0" ::"Q"(*(ptr)))
|
||||||
# else
|
# else
|
||||||
# define PREFETCH_L1(ptr) (void)(ptr) /* disabled */
|
# define PREFETCH_L1(ptr) (void)(ptr) /* disabled */
|
||||||
# define PREFETCH_L2(ptr) (void)(ptr) /* disabled */
|
# define PREFETCH_L2(ptr) (void)(ptr) /* disabled */
|
||||||
@@ -135,8 +141,9 @@
|
|||||||
}
|
}
|
||||||
|
|
||||||
/* vectorization
|
/* vectorization
|
||||||
* older GCC (pre gcc-4.3 picked as the cutoff) uses a different syntax */
|
* older GCC (pre gcc-4.3 picked as the cutoff) uses a different syntax,
|
||||||
#if !defined(__clang__) && defined(__GNUC__)
|
* and some compilers, like Intel ICC and MCST LCC, do not support it at all. */
|
||||||
|
#if !defined(__INTEL_COMPILER) && !defined(__clang__) && defined(__GNUC__) && !defined(__LCC__)
|
||||||
# if (__GNUC__ == 4 && __GNUC_MINOR__ > 3) || (__GNUC__ >= 5)
|
# if (__GNUC__ == 4 && __GNUC_MINOR__ > 3) || (__GNUC__ >= 5)
|
||||||
# define DONT_VECTORIZE __attribute__((optimize("no-tree-vectorize")))
|
# define DONT_VECTORIZE __attribute__((optimize("no-tree-vectorize")))
|
||||||
# else
|
# else
|
||||||
@@ -146,6 +153,25 @@
|
|||||||
# define DONT_VECTORIZE
|
# define DONT_VECTORIZE
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
/* Tell the compiler that a branch is likely or unlikely.
|
||||||
|
* Only use these macros if it causes the compiler to generate better code.
|
||||||
|
* If you can remove a LIKELY/UNLIKELY annotation without speed changes in gcc
|
||||||
|
* and clang, please do.
|
||||||
|
*/
|
||||||
|
#if defined(__GNUC__)
|
||||||
|
#define LIKELY(x) (__builtin_expect((x), 1))
|
||||||
|
#define UNLIKELY(x) (__builtin_expect((x), 0))
|
||||||
|
#else
|
||||||
|
#define LIKELY(x) (x)
|
||||||
|
#define UNLIKELY(x) (x)
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#if __has_builtin(__builtin_unreachable) || (defined(__GNUC__) && (__GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ >= 5)))
|
||||||
|
# define ZSTD_UNREACHABLE { assert(0), __builtin_unreachable(); }
|
||||||
|
#else
|
||||||
|
# define ZSTD_UNREACHABLE { assert(0); }
|
||||||
|
#endif
|
||||||
|
|
||||||
/* disable warnings */
|
/* disable warnings */
|
||||||
#ifdef _MSC_VER /* Visual Studio */
|
#ifdef _MSC_VER /* Visual Studio */
|
||||||
# include <intrin.h> /* For Visual 2005 */
|
# include <intrin.h> /* For Visual 2005 */
|
||||||
@@ -156,4 +182,180 @@
|
|||||||
# pragma warning(disable : 4324) /* disable: C4324: padded structure */
|
# pragma warning(disable : 4324) /* disable: C4324: padded structure */
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
/*Like DYNAMIC_BMI2 but for compile time determination of BMI2 support*/
|
||||||
|
#ifndef STATIC_BMI2
|
||||||
|
# if defined(_MSC_VER) && (defined(_M_X64) || defined(_M_I86))
|
||||||
|
# ifdef __AVX2__ //MSVC does not have a BMI2 specific flag, but every CPU that supports AVX2 also supports BMI2
|
||||||
|
# define STATIC_BMI2 1
|
||||||
|
# endif
|
||||||
|
# elif defined(__BMI2__) && defined(__x86_64__) && defined(__GNUC__)
|
||||||
|
# define STATIC_BMI2 1
|
||||||
|
# endif
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#ifndef STATIC_BMI2
|
||||||
|
#define STATIC_BMI2 0
|
||||||
|
#endif
|
||||||
|
|
||||||
|
/* compile time determination of SIMD support */
|
||||||
|
#if !defined(ZSTD_NO_INTRINSICS)
|
||||||
|
# if defined(__SSE2__) || defined(_M_AMD64) || (defined (_M_IX86) && defined(_M_IX86_FP) && (_M_IX86_FP >= 2))
|
||||||
|
# define ZSTD_ARCH_X86_SSE2
|
||||||
|
# endif
|
||||||
|
# if defined(__ARM_NEON) || defined(_M_ARM64)
|
||||||
|
# define ZSTD_ARCH_ARM_NEON
|
||||||
|
# endif
|
||||||
|
#
|
||||||
|
# if defined(ZSTD_ARCH_X86_SSE2)
|
||||||
|
# include <emmintrin.h>
|
||||||
|
# elif defined(ZSTD_ARCH_ARM_NEON)
|
||||||
|
# include <arm_neon.h>
|
||||||
|
# endif
|
||||||
|
#endif
|
||||||
|
|
||||||
|
/* C-language Attributes are added in C23. */
|
||||||
|
#if defined(__STDC_VERSION__) && (__STDC_VERSION__ > 201710L) && defined(__has_c_attribute)
|
||||||
|
# define ZSTD_HAS_C_ATTRIBUTE(x) __has_c_attribute(x)
|
||||||
|
#else
|
||||||
|
# define ZSTD_HAS_C_ATTRIBUTE(x) 0
|
||||||
|
#endif
|
||||||
|
|
||||||
|
/* Only use C++ attributes in C++. Some compilers report support for C++
|
||||||
|
* attributes when compiling with C.
|
||||||
|
*/
|
||||||
|
#if defined(__cplusplus) && defined(__has_cpp_attribute)
|
||||||
|
# define ZSTD_HAS_CPP_ATTRIBUTE(x) __has_cpp_attribute(x)
|
||||||
|
#else
|
||||||
|
# define ZSTD_HAS_CPP_ATTRIBUTE(x) 0
|
||||||
|
#endif
|
||||||
|
|
||||||
|
/* Define ZSTD_FALLTHROUGH macro for annotating switch case with the 'fallthrough' attribute.
|
||||||
|
* - C23: https://en.cppreference.com/w/c/language/attributes/fallthrough
|
||||||
|
* - CPP17: https://en.cppreference.com/w/cpp/language/attributes/fallthrough
|
||||||
|
* - Else: __attribute__((__fallthrough__))
|
||||||
|
*/
|
||||||
|
#ifndef ZSTD_FALLTHROUGH
|
||||||
|
# if ZSTD_HAS_C_ATTRIBUTE(fallthrough)
|
||||||
|
# define ZSTD_FALLTHROUGH [[fallthrough]]
|
||||||
|
# elif ZSTD_HAS_CPP_ATTRIBUTE(fallthrough)
|
||||||
|
# define ZSTD_FALLTHROUGH [[fallthrough]]
|
||||||
|
# elif __has_attribute(__fallthrough__)
|
||||||
|
/* Leading semicolon is to satisfy gcc-11 with -pedantic. Without the semicolon
|
||||||
|
* gcc complains about: a label can only be part of a statement and a declaration is not a statement.
|
||||||
|
*/
|
||||||
|
# define ZSTD_FALLTHROUGH ; __attribute__((__fallthrough__))
|
||||||
|
# else
|
||||||
|
# define ZSTD_FALLTHROUGH
|
||||||
|
# endif
|
||||||
|
#endif
|
||||||
|
|
||||||
|
/*-**************************************************************
|
||||||
|
* Alignment check
|
||||||
|
*****************************************************************/
|
||||||
|
|
||||||
|
/* this test was initially positioned in mem.h,
|
||||||
|
* but this file is removed (or replaced) for linux kernel
|
||||||
|
* so it's now hosted in compiler.h,
|
||||||
|
* which remains valid for both user & kernel spaces.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#ifndef ZSTD_ALIGNOF
|
||||||
|
# if defined(__GNUC__) || defined(_MSC_VER)
|
||||||
|
/* covers gcc, clang & MSVC */
|
||||||
|
/* note : this section must come first, before C11,
|
||||||
|
* due to a limitation in the kernel source generator */
|
||||||
|
# define ZSTD_ALIGNOF(T) __alignof(T)
|
||||||
|
|
||||||
|
# elif defined(__STDC_VERSION__) && (__STDC_VERSION__ >= 201112L)
|
||||||
|
/* C11 support */
|
||||||
|
# include <stdalign.h>
|
||||||
|
# define ZSTD_ALIGNOF(T) alignof(T)
|
||||||
|
|
||||||
|
# else
|
||||||
|
/* No known support for alignof() - imperfect backup */
|
||||||
|
# define ZSTD_ALIGNOF(T) (sizeof(void*) < sizeof(T) ? sizeof(void*) : sizeof(T))
|
||||||
|
|
||||||
|
# endif
|
||||||
|
#endif /* ZSTD_ALIGNOF */
|
||||||
|
|
||||||
|
/*-**************************************************************
|
||||||
|
* Sanitizer
|
||||||
|
*****************************************************************/
|
||||||
|
|
||||||
|
/* Issue #3240 reports an ASAN failure on an llvm-mingw build. Out of an
|
||||||
|
* abundance of caution, disable our custom poisoning on mingw. */
|
||||||
|
#ifdef __MINGW32__
|
||||||
|
#ifndef ZSTD_ASAN_DONT_POISON_WORKSPACE
|
||||||
|
#define ZSTD_ASAN_DONT_POISON_WORKSPACE 1
|
||||||
|
#endif
|
||||||
|
#ifndef ZSTD_MSAN_DONT_POISON_WORKSPACE
|
||||||
|
#define ZSTD_MSAN_DONT_POISON_WORKSPACE 1
|
||||||
|
#endif
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#if ZSTD_MEMORY_SANITIZER && !defined(ZSTD_MSAN_DONT_POISON_WORKSPACE)
|
||||||
|
/* Not all platforms that support msan provide sanitizers/msan_interface.h.
|
||||||
|
* We therefore declare the functions we need ourselves, rather than trying to
|
||||||
|
* include the header file... */
|
||||||
|
#include <stddef.h> /* size_t */
|
||||||
|
#define ZSTD_DEPS_NEED_STDINT
|
||||||
|
#include "zstd_deps.h" /* intptr_t */
|
||||||
|
|
||||||
|
/* Make memory region fully initialized (without changing its contents). */
|
||||||
|
void __msan_unpoison(const volatile void *a, size_t size);
|
||||||
|
|
||||||
|
/* Make memory region fully uninitialized (without changing its contents).
|
||||||
|
This is a legacy interface that does not update origin information. Use
|
||||||
|
__msan_allocated_memory() instead. */
|
||||||
|
void __msan_poison(const volatile void *a, size_t size);
|
||||||
|
|
||||||
|
/* Returns the offset of the first (at least partially) poisoned byte in the
|
||||||
|
memory range, or -1 if the whole range is good. */
|
||||||
|
intptr_t __msan_test_shadow(const volatile void *x, size_t size);
|
||||||
|
|
||||||
|
/* Print shadow and origin for the memory range to stderr in a human-readable
|
||||||
|
format. */
|
||||||
|
void __msan_print_shadow(const volatile void *x, size_t size);
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#if ZSTD_ADDRESS_SANITIZER && !defined(ZSTD_ASAN_DONT_POISON_WORKSPACE)
|
||||||
|
/* Not all platforms that support asan provide sanitizers/asan_interface.h.
|
||||||
|
* We therefore declare the functions we need ourselves, rather than trying to
|
||||||
|
* include the header file... */
|
||||||
|
#include <stddef.h> /* size_t */
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Marks a memory region (<c>[addr, addr+size)</c>) as unaddressable.
|
||||||
|
*
|
||||||
|
* This memory must be previously allocated by your program. Instrumented
|
||||||
|
* code is forbidden from accessing addresses in this region until it is
|
||||||
|
* unpoisoned. This function is not guaranteed to poison the entire region -
|
||||||
|
* it could poison only a subregion of <c>[addr, addr+size)</c> due to ASan
|
||||||
|
* alignment restrictions.
|
||||||
|
*
|
||||||
|
* \note This function is not thread-safe because no two threads can poison or
|
||||||
|
* unpoison memory in the same memory region simultaneously.
|
||||||
|
*
|
||||||
|
* \param addr Start of memory region.
|
||||||
|
* \param size Size of memory region. */
|
||||||
|
void __asan_poison_memory_region(void const volatile *addr, size_t size);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Marks a memory region (<c>[addr, addr+size)</c>) as addressable.
|
||||||
|
*
|
||||||
|
* This memory must be previously allocated by your program. Accessing
|
||||||
|
* addresses in this region is allowed until this region is poisoned again.
|
||||||
|
* This function could unpoison a super-region of <c>[addr, addr+size)</c> due
|
||||||
|
* to ASan alignment restrictions.
|
||||||
|
*
|
||||||
|
* \note This function is not thread-safe because no two threads can
|
||||||
|
* poison or unpoison memory in the same memory region simultaneously.
|
||||||
|
*
|
||||||
|
* \param addr Start of memory region.
|
||||||
|
* \param size Size of memory region. */
|
||||||
|
void __asan_unpoison_memory_region(void const volatile *addr, size_t size);
|
||||||
|
#endif
|
||||||
|
|
||||||
#endif /* ZSTD_COMPILER_H */
|
#endif /* ZSTD_COMPILER_H */
|
||||||
|
|
||||||
|
#endif /* USE_EXTERNAL_ZSTD */
|
||||||
|
|||||||
122
vendor/github.com/DataDog/zstd/cover.c
generated
vendored
122
vendor/github.com/DataDog/zstd/cover.c
generated
vendored
@@ -1,5 +1,6 @@
|
|||||||
|
#ifndef USE_EXTERNAL_ZSTD
|
||||||
/*
|
/*
|
||||||
* Copyright (c) 2016-present, Yann Collet, Facebook, Inc.
|
* Copyright (c) Meta Platforms, Inc. and affiliates.
|
||||||
* All rights reserved.
|
* All rights reserved.
|
||||||
*
|
*
|
||||||
* This source code is licensed under both the BSD-style license (found in the
|
* This source code is licensed under both the BSD-style license (found in the
|
||||||
@@ -26,47 +27,65 @@
|
|||||||
#include <string.h> /* memset */
|
#include <string.h> /* memset */
|
||||||
#include <time.h> /* clock */
|
#include <time.h> /* clock */
|
||||||
|
|
||||||
|
#ifndef ZDICT_STATIC_LINKING_ONLY
|
||||||
|
# define ZDICT_STATIC_LINKING_ONLY
|
||||||
|
#endif
|
||||||
|
|
||||||
#include "mem.h" /* read */
|
#include "mem.h" /* read */
|
||||||
#include "pool.h"
|
#include "pool.h"
|
||||||
#include "threading.h"
|
#include "threading.h"
|
||||||
#include "cover.h"
|
|
||||||
#include "zstd_internal.h" /* includes zstd.h */
|
#include "zstd_internal.h" /* includes zstd.h */
|
||||||
#ifndef ZDICT_STATIC_LINKING_ONLY
|
#include "bits.h" /* ZSTD_highbit32 */
|
||||||
#define ZDICT_STATIC_LINKING_ONLY
|
|
||||||
#endif
|
|
||||||
#include "zdict.h"
|
#include "zdict.h"
|
||||||
|
#include "cover.h"
|
||||||
|
|
||||||
/*-*************************************
|
/*-*************************************
|
||||||
* Constants
|
* Constants
|
||||||
***************************************/
|
***************************************/
|
||||||
|
/**
|
||||||
|
* There are 32bit indexes used to ref samples, so limit samples size to 4GB
|
||||||
|
* on 64bit builds.
|
||||||
|
* For 32bit builds we choose 1 GB.
|
||||||
|
* Most 32bit platforms have 2GB user-mode addressable space and we allocate a large
|
||||||
|
* contiguous buffer, so 1GB is already a high limit.
|
||||||
|
*/
|
||||||
#define COVER_MAX_SAMPLES_SIZE (sizeof(size_t) == 8 ? ((unsigned)-1) : ((unsigned)1 GB))
|
#define COVER_MAX_SAMPLES_SIZE (sizeof(size_t) == 8 ? ((unsigned)-1) : ((unsigned)1 GB))
|
||||||
#define DEFAULT_SPLITPOINT 1.0
|
#define COVER_DEFAULT_SPLITPOINT 1.0
|
||||||
|
|
||||||
/*-*************************************
|
/*-*************************************
|
||||||
* Console display
|
* Console display
|
||||||
***************************************/
|
***************************************/
|
||||||
static int g_displayLevel = 2;
|
#ifndef LOCALDISPLAYLEVEL
|
||||||
|
static int g_displayLevel = 0;
|
||||||
|
#endif
|
||||||
|
#undef DISPLAY
|
||||||
#define DISPLAY(...) \
|
#define DISPLAY(...) \
|
||||||
{ \
|
{ \
|
||||||
fprintf(stderr, __VA_ARGS__); \
|
fprintf(stderr, __VA_ARGS__); \
|
||||||
fflush(stderr); \
|
fflush(stderr); \
|
||||||
}
|
}
|
||||||
|
#undef LOCALDISPLAYLEVEL
|
||||||
#define LOCALDISPLAYLEVEL(displayLevel, l, ...) \
|
#define LOCALDISPLAYLEVEL(displayLevel, l, ...) \
|
||||||
if (displayLevel >= l) { \
|
if (displayLevel >= l) { \
|
||||||
DISPLAY(__VA_ARGS__); \
|
DISPLAY(__VA_ARGS__); \
|
||||||
} /* 0 : no display; 1: errors; 2: default; 3: details; 4: debug */
|
} /* 0 : no display; 1: errors; 2: default; 3: details; 4: debug */
|
||||||
|
#undef DISPLAYLEVEL
|
||||||
#define DISPLAYLEVEL(l, ...) LOCALDISPLAYLEVEL(g_displayLevel, l, __VA_ARGS__)
|
#define DISPLAYLEVEL(l, ...) LOCALDISPLAYLEVEL(g_displayLevel, l, __VA_ARGS__)
|
||||||
|
|
||||||
|
#ifndef LOCALDISPLAYUPDATE
|
||||||
|
static const clock_t g_refreshRate = CLOCKS_PER_SEC * 15 / 100;
|
||||||
|
static clock_t g_time = 0;
|
||||||
|
#endif
|
||||||
|
#undef LOCALDISPLAYUPDATE
|
||||||
#define LOCALDISPLAYUPDATE(displayLevel, l, ...) \
|
#define LOCALDISPLAYUPDATE(displayLevel, l, ...) \
|
||||||
if (displayLevel >= l) { \
|
if (displayLevel >= l) { \
|
||||||
if ((clock() - g_time > refreshRate) || (displayLevel >= 4)) { \
|
if ((clock() - g_time > g_refreshRate) || (displayLevel >= 4)) { \
|
||||||
g_time = clock(); \
|
g_time = clock(); \
|
||||||
DISPLAY(__VA_ARGS__); \
|
DISPLAY(__VA_ARGS__); \
|
||||||
} \
|
} \
|
||||||
}
|
}
|
||||||
|
#undef DISPLAYUPDATE
|
||||||
#define DISPLAYUPDATE(l, ...) LOCALDISPLAYUPDATE(g_displayLevel, l, __VA_ARGS__)
|
#define DISPLAYUPDATE(l, ...) LOCALDISPLAYUPDATE(g_displayLevel, l, __VA_ARGS__)
|
||||||
static const clock_t refreshRate = CLOCKS_PER_SEC * 15 / 100;
|
|
||||||
static clock_t g_time = 0;
|
|
||||||
|
|
||||||
/*-*************************************
|
/*-*************************************
|
||||||
* Hash table
|
* Hash table
|
||||||
@@ -120,9 +139,9 @@ static int COVER_map_init(COVER_map_t *map, U32 size) {
|
|||||||
/**
|
/**
|
||||||
* Internal hash function
|
* Internal hash function
|
||||||
*/
|
*/
|
||||||
static const U32 prime4bytes = 2654435761U;
|
static const U32 COVER_prime4bytes = 2654435761U;
|
||||||
static U32 COVER_map_hash(COVER_map_t *map, U32 key) {
|
static U32 COVER_map_hash(COVER_map_t *map, U32 key) {
|
||||||
return (key * prime4bytes) >> (32 - map->sizeLog);
|
return (key * COVER_prime4bytes) >> (32 - map->sizeLog);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -215,7 +234,7 @@ typedef struct {
|
|||||||
} COVER_ctx_t;
|
} COVER_ctx_t;
|
||||||
|
|
||||||
/* We need a global context for qsort... */
|
/* We need a global context for qsort... */
|
||||||
static COVER_ctx_t *g_ctx = NULL;
|
static COVER_ctx_t *g_coverCtx = NULL;
|
||||||
|
|
||||||
/*-*************************************
|
/*-*************************************
|
||||||
* Helper functions
|
* Helper functions
|
||||||
@@ -258,11 +277,11 @@ static int COVER_cmp8(COVER_ctx_t *ctx, const void *lp, const void *rp) {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Same as COVER_cmp() except ties are broken by pointer value
|
* Same as COVER_cmp() except ties are broken by pointer value
|
||||||
* NOTE: g_ctx must be set to call this function. A global is required because
|
* NOTE: g_coverCtx must be set to call this function. A global is required because
|
||||||
* qsort doesn't take an opaque pointer.
|
* qsort doesn't take an opaque pointer.
|
||||||
*/
|
*/
|
||||||
static int COVER_strict_cmp(const void *lp, const void *rp) {
|
static int WIN_CDECL COVER_strict_cmp(const void *lp, const void *rp) {
|
||||||
int result = COVER_cmp(g_ctx, lp, rp);
|
int result = COVER_cmp(g_coverCtx, lp, rp);
|
||||||
if (result == 0) {
|
if (result == 0) {
|
||||||
result = lp < rp ? -1 : 1;
|
result = lp < rp ? -1 : 1;
|
||||||
}
|
}
|
||||||
@@ -271,8 +290,8 @@ static int COVER_strict_cmp(const void *lp, const void *rp) {
|
|||||||
/**
|
/**
|
||||||
* Faster version for d <= 8.
|
* Faster version for d <= 8.
|
||||||
*/
|
*/
|
||||||
static int COVER_strict_cmp8(const void *lp, const void *rp) {
|
static int WIN_CDECL COVER_strict_cmp8(const void *lp, const void *rp) {
|
||||||
int result = COVER_cmp8(g_ctx, lp, rp);
|
int result = COVER_cmp8(g_coverCtx, lp, rp);
|
||||||
if (result == 0) {
|
if (result == 0) {
|
||||||
result = lp < rp ? -1 : 1;
|
result = lp < rp ? -1 : 1;
|
||||||
}
|
}
|
||||||
@@ -524,7 +543,7 @@ static void COVER_ctx_destroy(COVER_ctx_t *ctx) {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Prepare a context for dictionary building.
|
* Prepare a context for dictionary building.
|
||||||
* The context is only dependent on the parameter `d` and can used multiple
|
* The context is only dependent on the parameter `d` and can be used multiple
|
||||||
* times.
|
* times.
|
||||||
* Returns 0 on success or error code on error.
|
* Returns 0 on success or error code on error.
|
||||||
* The context must be destroyed with `COVER_ctx_destroy()`.
|
* The context must be destroyed with `COVER_ctx_destroy()`.
|
||||||
@@ -603,7 +622,7 @@ static size_t COVER_ctx_init(COVER_ctx_t *ctx, const void *samplesBuffer,
|
|||||||
/* qsort doesn't take an opaque pointer, so pass as a global.
|
/* qsort doesn't take an opaque pointer, so pass as a global.
|
||||||
* On OpenBSD qsort() is not guaranteed to be stable, their mergesort() is.
|
* On OpenBSD qsort() is not guaranteed to be stable, their mergesort() is.
|
||||||
*/
|
*/
|
||||||
g_ctx = ctx;
|
g_coverCtx = ctx;
|
||||||
#if defined(__OpenBSD__)
|
#if defined(__OpenBSD__)
|
||||||
mergesort(ctx->suffix, ctx->suffixSize, sizeof(U32),
|
mergesort(ctx->suffix, ctx->suffixSize, sizeof(U32),
|
||||||
(ctx->d <= 8 ? &COVER_strict_cmp8 : &COVER_strict_cmp));
|
(ctx->d <= 8 ? &COVER_strict_cmp8 : &COVER_strict_cmp));
|
||||||
@@ -629,7 +648,7 @@ static size_t COVER_ctx_init(COVER_ctx_t *ctx, const void *samplesBuffer,
|
|||||||
|
|
||||||
void COVER_warnOnSmallCorpus(size_t maxDictSize, size_t nbDmers, int displayLevel)
|
void COVER_warnOnSmallCorpus(size_t maxDictSize, size_t nbDmers, int displayLevel)
|
||||||
{
|
{
|
||||||
const double ratio = (double)nbDmers / maxDictSize;
|
const double ratio = (double)nbDmers / (double)maxDictSize;
|
||||||
if (ratio >= 10) {
|
if (ratio >= 10) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@@ -725,7 +744,7 @@ ZDICTLIB_API size_t ZDICT_trainFromBuffer_cover(
|
|||||||
COVER_map_t activeDmers;
|
COVER_map_t activeDmers;
|
||||||
parameters.splitPoint = 1.0;
|
parameters.splitPoint = 1.0;
|
||||||
/* Initialize global data */
|
/* Initialize global data */
|
||||||
g_displayLevel = parameters.zParams.notificationLevel;
|
g_displayLevel = (int)parameters.zParams.notificationLevel;
|
||||||
/* Checks */
|
/* Checks */
|
||||||
if (!COVER_checkParameters(parameters, dictBufferCapacity)) {
|
if (!COVER_checkParameters(parameters, dictBufferCapacity)) {
|
||||||
DISPLAYLEVEL(1, "Cover parameters incorrect\n");
|
DISPLAYLEVEL(1, "Cover parameters incorrect\n");
|
||||||
@@ -933,9 +952,17 @@ void COVER_best_finish(COVER_best_t *best, ZDICT_cover_params_t parameters,
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static COVER_dictSelection_t setDictSelection(BYTE* buf, size_t s, size_t csz)
|
||||||
|
{
|
||||||
|
COVER_dictSelection_t ds;
|
||||||
|
ds.dictContent = buf;
|
||||||
|
ds.dictSize = s;
|
||||||
|
ds.totalCompressedSize = csz;
|
||||||
|
return ds;
|
||||||
|
}
|
||||||
|
|
||||||
COVER_dictSelection_t COVER_dictSelectionError(size_t error) {
|
COVER_dictSelection_t COVER_dictSelectionError(size_t error) {
|
||||||
COVER_dictSelection_t selection = { NULL, 0, error };
|
return setDictSelection(NULL, 0, error);
|
||||||
return selection;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
unsigned COVER_dictSelectionIsError(COVER_dictSelection_t selection) {
|
unsigned COVER_dictSelectionIsError(COVER_dictSelection_t selection) {
|
||||||
@@ -946,7 +973,7 @@ void COVER_dictSelectionFree(COVER_dictSelection_t selection){
|
|||||||
free(selection.dictContent);
|
free(selection.dictContent);
|
||||||
}
|
}
|
||||||
|
|
||||||
COVER_dictSelection_t COVER_selectDict(BYTE* customDictContent,
|
COVER_dictSelection_t COVER_selectDict(BYTE* customDictContent, size_t dictBufferCapacity,
|
||||||
size_t dictContentSize, const BYTE* samplesBuffer, const size_t* samplesSizes, unsigned nbFinalizeSamples,
|
size_t dictContentSize, const BYTE* samplesBuffer, const size_t* samplesSizes, unsigned nbFinalizeSamples,
|
||||||
size_t nbCheckSamples, size_t nbSamples, ZDICT_cover_params_t params, size_t* offsets, size_t totalCompressedSize) {
|
size_t nbCheckSamples, size_t nbSamples, ZDICT_cover_params_t params, size_t* offsets, size_t totalCompressedSize) {
|
||||||
|
|
||||||
@@ -954,8 +981,8 @@ COVER_dictSelection_t COVER_selectDict(BYTE* customDictContent,
|
|||||||
size_t largestCompressed = 0;
|
size_t largestCompressed = 0;
|
||||||
BYTE* customDictContentEnd = customDictContent + dictContentSize;
|
BYTE* customDictContentEnd = customDictContent + dictContentSize;
|
||||||
|
|
||||||
BYTE * largestDictbuffer = (BYTE *)malloc(dictContentSize);
|
BYTE * largestDictbuffer = (BYTE *)malloc(dictBufferCapacity);
|
||||||
BYTE * candidateDictBuffer = (BYTE *)malloc(dictContentSize);
|
BYTE * candidateDictBuffer = (BYTE *)malloc(dictBufferCapacity);
|
||||||
double regressionTolerance = ((double)params.shrinkDictMaxRegression / 100.0) + 1.00;
|
double regressionTolerance = ((double)params.shrinkDictMaxRegression / 100.0) + 1.00;
|
||||||
|
|
||||||
if (!largestDictbuffer || !candidateDictBuffer) {
|
if (!largestDictbuffer || !candidateDictBuffer) {
|
||||||
@@ -967,7 +994,7 @@ COVER_dictSelection_t COVER_selectDict(BYTE* customDictContent,
|
|||||||
/* Initial dictionary size and compressed size */
|
/* Initial dictionary size and compressed size */
|
||||||
memcpy(largestDictbuffer, customDictContent, dictContentSize);
|
memcpy(largestDictbuffer, customDictContent, dictContentSize);
|
||||||
dictContentSize = ZDICT_finalizeDictionary(
|
dictContentSize = ZDICT_finalizeDictionary(
|
||||||
largestDictbuffer, dictContentSize, customDictContent, dictContentSize,
|
largestDictbuffer, dictBufferCapacity, customDictContent, dictContentSize,
|
||||||
samplesBuffer, samplesSizes, nbFinalizeSamples, params.zParams);
|
samplesBuffer, samplesSizes, nbFinalizeSamples, params.zParams);
|
||||||
|
|
||||||
if (ZDICT_isError(dictContentSize)) {
|
if (ZDICT_isError(dictContentSize)) {
|
||||||
@@ -988,9 +1015,8 @@ COVER_dictSelection_t COVER_selectDict(BYTE* customDictContent,
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (params.shrinkDict == 0) {
|
if (params.shrinkDict == 0) {
|
||||||
COVER_dictSelection_t selection = { largestDictbuffer, dictContentSize, totalCompressedSize };
|
|
||||||
free(candidateDictBuffer);
|
free(candidateDictBuffer);
|
||||||
return selection;
|
return setDictSelection(largestDictbuffer, dictContentSize, totalCompressedSize);
|
||||||
}
|
}
|
||||||
|
|
||||||
largestDict = dictContentSize;
|
largestDict = dictContentSize;
|
||||||
@@ -1001,7 +1027,7 @@ COVER_dictSelection_t COVER_selectDict(BYTE* customDictContent,
|
|||||||
while (dictContentSize < largestDict) {
|
while (dictContentSize < largestDict) {
|
||||||
memcpy(candidateDictBuffer, largestDictbuffer, largestDict);
|
memcpy(candidateDictBuffer, largestDictbuffer, largestDict);
|
||||||
dictContentSize = ZDICT_finalizeDictionary(
|
dictContentSize = ZDICT_finalizeDictionary(
|
||||||
candidateDictBuffer, dictContentSize, customDictContentEnd - dictContentSize, dictContentSize,
|
candidateDictBuffer, dictBufferCapacity, customDictContentEnd - dictContentSize, dictContentSize,
|
||||||
samplesBuffer, samplesSizes, nbFinalizeSamples, params.zParams);
|
samplesBuffer, samplesSizes, nbFinalizeSamples, params.zParams);
|
||||||
|
|
||||||
if (ZDICT_isError(dictContentSize)) {
|
if (ZDICT_isError(dictContentSize)) {
|
||||||
@@ -1022,20 +1048,16 @@ COVER_dictSelection_t COVER_selectDict(BYTE* customDictContent,
|
|||||||
return COVER_dictSelectionError(totalCompressedSize);
|
return COVER_dictSelectionError(totalCompressedSize);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (totalCompressedSize <= largestCompressed * regressionTolerance) {
|
if ((double)totalCompressedSize <= (double)largestCompressed * regressionTolerance) {
|
||||||
COVER_dictSelection_t selection = { candidateDictBuffer, dictContentSize, totalCompressedSize };
|
|
||||||
free(largestDictbuffer);
|
free(largestDictbuffer);
|
||||||
return selection;
|
return setDictSelection( candidateDictBuffer, dictContentSize, totalCompressedSize );
|
||||||
}
|
}
|
||||||
dictContentSize *= 2;
|
dictContentSize *= 2;
|
||||||
}
|
}
|
||||||
dictContentSize = largestDict;
|
dictContentSize = largestDict;
|
||||||
totalCompressedSize = largestCompressed;
|
totalCompressedSize = largestCompressed;
|
||||||
{
|
|
||||||
COVER_dictSelection_t selection = { largestDictbuffer, dictContentSize, totalCompressedSize };
|
|
||||||
free(candidateDictBuffer);
|
free(candidateDictBuffer);
|
||||||
return selection;
|
return setDictSelection( largestDictbuffer, dictContentSize, totalCompressedSize );
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -1053,18 +1075,19 @@ typedef struct COVER_tryParameters_data_s {
|
|||||||
* This function is thread safe if zstd is compiled with multithreaded support.
|
* This function is thread safe if zstd is compiled with multithreaded support.
|
||||||
* It takes its parameters as an *OWNING* opaque pointer to support threading.
|
* It takes its parameters as an *OWNING* opaque pointer to support threading.
|
||||||
*/
|
*/
|
||||||
static void COVER_tryParameters(void *opaque) {
|
static void COVER_tryParameters(void *opaque)
|
||||||
|
{
|
||||||
/* Save parameters as local variables */
|
/* Save parameters as local variables */
|
||||||
COVER_tryParameters_data_t *const data = (COVER_tryParameters_data_t *)opaque;
|
COVER_tryParameters_data_t *const data = (COVER_tryParameters_data_t*)opaque;
|
||||||
const COVER_ctx_t *const ctx = data->ctx;
|
const COVER_ctx_t *const ctx = data->ctx;
|
||||||
const ZDICT_cover_params_t parameters = data->parameters;
|
const ZDICT_cover_params_t parameters = data->parameters;
|
||||||
size_t dictBufferCapacity = data->dictBufferCapacity;
|
size_t dictBufferCapacity = data->dictBufferCapacity;
|
||||||
size_t totalCompressedSize = ERROR(GENERIC);
|
size_t totalCompressedSize = ERROR(GENERIC);
|
||||||
/* Allocate space for hash table, dict, and freqs */
|
/* Allocate space for hash table, dict, and freqs */
|
||||||
COVER_map_t activeDmers;
|
COVER_map_t activeDmers;
|
||||||
BYTE *const dict = (BYTE * const)malloc(dictBufferCapacity);
|
BYTE* const dict = (BYTE*)malloc(dictBufferCapacity);
|
||||||
COVER_dictSelection_t selection = COVER_dictSelectionError(ERROR(GENERIC));
|
COVER_dictSelection_t selection = COVER_dictSelectionError(ERROR(GENERIC));
|
||||||
U32 *freqs = (U32 *)malloc(ctx->suffixSize * sizeof(U32));
|
U32* const freqs = (U32*)malloc(ctx->suffixSize * sizeof(U32));
|
||||||
if (!COVER_map_init(&activeDmers, parameters.k - parameters.d + 1)) {
|
if (!COVER_map_init(&activeDmers, parameters.k - parameters.d + 1)) {
|
||||||
DISPLAYLEVEL(1, "Failed to allocate dmer map: out of memory\n");
|
DISPLAYLEVEL(1, "Failed to allocate dmer map: out of memory\n");
|
||||||
goto _cleanup;
|
goto _cleanup;
|
||||||
@@ -1079,7 +1102,7 @@ static void COVER_tryParameters(void *opaque) {
|
|||||||
{
|
{
|
||||||
const size_t tail = COVER_buildDictionary(ctx, freqs, &activeDmers, dict,
|
const size_t tail = COVER_buildDictionary(ctx, freqs, &activeDmers, dict,
|
||||||
dictBufferCapacity, parameters);
|
dictBufferCapacity, parameters);
|
||||||
selection = COVER_selectDict(dict + tail, dictBufferCapacity - tail,
|
selection = COVER_selectDict(dict + tail, dictBufferCapacity, dictBufferCapacity - tail,
|
||||||
ctx->samples, ctx->samplesSizes, (unsigned)ctx->nbTrainSamples, ctx->nbTrainSamples, ctx->nbSamples, parameters, ctx->offsets,
|
ctx->samples, ctx->samplesSizes, (unsigned)ctx->nbTrainSamples, ctx->nbTrainSamples, ctx->nbSamples, parameters, ctx->offsets,
|
||||||
totalCompressedSize);
|
totalCompressedSize);
|
||||||
|
|
||||||
@@ -1094,19 +1117,18 @@ _cleanup:
|
|||||||
free(data);
|
free(data);
|
||||||
COVER_map_destroy(&activeDmers);
|
COVER_map_destroy(&activeDmers);
|
||||||
COVER_dictSelectionFree(selection);
|
COVER_dictSelectionFree(selection);
|
||||||
if (freqs) {
|
|
||||||
free(freqs);
|
free(freqs);
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
ZDICTLIB_API size_t ZDICT_optimizeTrainFromBuffer_cover(
|
ZDICTLIB_API size_t ZDICT_optimizeTrainFromBuffer_cover(
|
||||||
void *dictBuffer, size_t dictBufferCapacity, const void *samplesBuffer,
|
void* dictBuffer, size_t dictBufferCapacity, const void* samplesBuffer,
|
||||||
const size_t *samplesSizes, unsigned nbSamples,
|
const size_t* samplesSizes, unsigned nbSamples,
|
||||||
ZDICT_cover_params_t *parameters) {
|
ZDICT_cover_params_t* parameters)
|
||||||
|
{
|
||||||
/* constants */
|
/* constants */
|
||||||
const unsigned nbThreads = parameters->nbThreads;
|
const unsigned nbThreads = parameters->nbThreads;
|
||||||
const double splitPoint =
|
const double splitPoint =
|
||||||
parameters->splitPoint <= 0.0 ? DEFAULT_SPLITPOINT : parameters->splitPoint;
|
parameters->splitPoint <= 0.0 ? COVER_DEFAULT_SPLITPOINT : parameters->splitPoint;
|
||||||
const unsigned kMinD = parameters->d == 0 ? 6 : parameters->d;
|
const unsigned kMinD = parameters->d == 0 ? 6 : parameters->d;
|
||||||
const unsigned kMaxD = parameters->d == 0 ? 8 : parameters->d;
|
const unsigned kMaxD = parameters->d == 0 ? 8 : parameters->d;
|
||||||
const unsigned kMinK = parameters->k == 0 ? 50 : parameters->k;
|
const unsigned kMinK = parameters->k == 0 ? 50 : parameters->k;
|
||||||
@@ -1234,3 +1256,5 @@ ZDICTLIB_API size_t ZDICT_optimizeTrainFromBuffer_cover(
|
|||||||
return dictSize;
|
return dictSize;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#endif /* USE_EXTERNAL_ZSTD */
|
||||||
|
|||||||
22
vendor/github.com/DataDog/zstd/cover.h
generated
vendored
22
vendor/github.com/DataDog/zstd/cover.h
generated
vendored
@@ -1,3 +1,18 @@
|
|||||||
|
#ifndef USE_EXTERNAL_ZSTD
|
||||||
|
/*
|
||||||
|
* Copyright (c) Meta Platforms, Inc. and affiliates.
|
||||||
|
* All rights reserved.
|
||||||
|
*
|
||||||
|
* This source code is licensed under both the BSD-style license (found in the
|
||||||
|
* LICENSE file in the root directory of this source tree) and the GPLv2 (found
|
||||||
|
* in the COPYING file in the root directory of this source tree).
|
||||||
|
* You may select, at your option, one of the above-listed licenses.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#ifndef ZDICT_STATIC_LINKING_ONLY
|
||||||
|
# define ZDICT_STATIC_LINKING_ONLY
|
||||||
|
#endif
|
||||||
|
|
||||||
#include <stdio.h> /* fprintf */
|
#include <stdio.h> /* fprintf */
|
||||||
#include <stdlib.h> /* malloc, free, qsort */
|
#include <stdlib.h> /* malloc, free, qsort */
|
||||||
#include <string.h> /* memset */
|
#include <string.h> /* memset */
|
||||||
@@ -6,9 +21,6 @@
|
|||||||
#include "pool.h"
|
#include "pool.h"
|
||||||
#include "threading.h"
|
#include "threading.h"
|
||||||
#include "zstd_internal.h" /* includes zstd.h */
|
#include "zstd_internal.h" /* includes zstd.h */
|
||||||
#ifndef ZDICT_STATIC_LINKING_ONLY
|
|
||||||
#define ZDICT_STATIC_LINKING_ONLY
|
|
||||||
#endif
|
|
||||||
#include "zdict.h"
|
#include "zdict.h"
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -142,6 +154,8 @@ void COVER_dictSelectionFree(COVER_dictSelection_t selection);
|
|||||||
* smallest dictionary within a specified regression of the compressed size
|
* smallest dictionary within a specified regression of the compressed size
|
||||||
* from the largest dictionary.
|
* from the largest dictionary.
|
||||||
*/
|
*/
|
||||||
COVER_dictSelection_t COVER_selectDict(BYTE* customDictContent,
|
COVER_dictSelection_t COVER_selectDict(BYTE* customDictContent, size_t dictBufferCapacity,
|
||||||
size_t dictContentSize, const BYTE* samplesBuffer, const size_t* samplesSizes, unsigned nbFinalizeSamples,
|
size_t dictContentSize, const BYTE* samplesBuffer, const size_t* samplesSizes, unsigned nbFinalizeSamples,
|
||||||
size_t nbCheckSamples, size_t nbSamples, ZDICT_cover_params_t params, size_t* offsets, size_t totalCompressedSize);
|
size_t nbCheckSamples, size_t nbSamples, ZDICT_cover_params_t params, size_t* offsets, size_t totalCompressedSize);
|
||||||
|
|
||||||
|
#endif /* USE_EXTERNAL_ZSTD */
|
||||||
|
|||||||
7
vendor/github.com/DataDog/zstd/cpu.h
generated
vendored
7
vendor/github.com/DataDog/zstd/cpu.h
generated
vendored
@@ -1,5 +1,6 @@
|
|||||||
|
#ifndef USE_EXTERNAL_ZSTD
|
||||||
/*
|
/*
|
||||||
* Copyright (c) 2018-present, Facebook, Inc.
|
* Copyright (c) Meta Platforms, Inc. and affiliates.
|
||||||
* All rights reserved.
|
* All rights reserved.
|
||||||
*
|
*
|
||||||
* This source code is licensed under both the BSD-style license (found in the
|
* This source code is licensed under both the BSD-style license (found in the
|
||||||
@@ -16,8 +17,6 @@
|
|||||||
* https://github.com/facebook/folly/blob/master/folly/CpuId.h
|
* https://github.com/facebook/folly/blob/master/folly/CpuId.h
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include <string.h>
|
|
||||||
|
|
||||||
#include "mem.h"
|
#include "mem.h"
|
||||||
|
|
||||||
#ifdef _MSC_VER
|
#ifdef _MSC_VER
|
||||||
@@ -213,3 +212,5 @@ MEM_STATIC ZSTD_cpuid_t ZSTD_cpuid(void) {
|
|||||||
#undef X
|
#undef X
|
||||||
|
|
||||||
#endif /* ZSTD_COMMON_CPU_H */
|
#endif /* ZSTD_COMMON_CPU_H */
|
||||||
|
|
||||||
|
#endif /* USE_EXTERNAL_ZSTD */
|
||||||
|
|||||||
45
vendor/github.com/DataDog/zstd/debug.c
generated
vendored
45
vendor/github.com/DataDog/zstd/debug.c
generated
vendored
@@ -1,35 +1,16 @@
|
|||||||
|
#ifndef USE_EXTERNAL_ZSTD
|
||||||
/* ******************************************************************
|
/* ******************************************************************
|
||||||
debug
|
* debug
|
||||||
Part of FSE library
|
* Part of FSE library
|
||||||
Copyright (C) 2013-present, Yann Collet.
|
* Copyright (c) Meta Platforms, Inc. and affiliates.
|
||||||
|
*
|
||||||
BSD 2-Clause License (http://www.opensource.org/licenses/bsd-license.php)
|
* You can contact the author at :
|
||||||
|
* - Source repository : https://github.com/Cyan4973/FiniteStateEntropy
|
||||||
Redistribution and use in source and binary forms, with or without
|
*
|
||||||
modification, are permitted provided that the following conditions are
|
* This source code is licensed under both the BSD-style license (found in the
|
||||||
met:
|
* LICENSE file in the root directory of this source tree) and the GPLv2 (found
|
||||||
|
* in the COPYING file in the root directory of this source tree).
|
||||||
* Redistributions of source code must retain the above copyright
|
* You may select, at your option, one of the above-listed licenses.
|
||||||
notice, this list of conditions and the following disclaimer.
|
|
||||||
* Redistributions in binary form must reproduce the above
|
|
||||||
copyright notice, this list of conditions and the following disclaimer
|
|
||||||
in the documentation and/or other materials provided with the
|
|
||||||
distribution.
|
|
||||||
|
|
||||||
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
|
||||||
"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
|
||||||
LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
|
||||||
A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
|
|
||||||
OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
|
||||||
SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
|
||||||
LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
|
||||||
DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
|
||||||
THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
|
||||||
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
|
||||||
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
|
||||||
|
|
||||||
You can contact the author at :
|
|
||||||
- Source repository : https://github.com/Cyan4973/FiniteStateEntropy
|
|
||||||
****************************************************************** */
|
****************************************************************** */
|
||||||
|
|
||||||
|
|
||||||
@@ -42,3 +23,5 @@
|
|||||||
#include "debug.h"
|
#include "debug.h"
|
||||||
|
|
||||||
int g_debuglevel = DEBUGLEVEL;
|
int g_debuglevel = DEBUGLEVEL;
|
||||||
|
|
||||||
|
#endif /* USE_EXTERNAL_ZSTD */
|
||||||
|
|||||||
66
vendor/github.com/DataDog/zstd/debug.h
generated
vendored
66
vendor/github.com/DataDog/zstd/debug.h
generated
vendored
@@ -1,35 +1,16 @@
|
|||||||
|
#ifndef USE_EXTERNAL_ZSTD
|
||||||
/* ******************************************************************
|
/* ******************************************************************
|
||||||
debug
|
* debug
|
||||||
Part of FSE library
|
* Part of FSE library
|
||||||
Copyright (C) 2013-present, Yann Collet.
|
* Copyright (c) Meta Platforms, Inc. and affiliates.
|
||||||
|
*
|
||||||
BSD 2-Clause License (http://www.opensource.org/licenses/bsd-license.php)
|
* You can contact the author at :
|
||||||
|
* - Source repository : https://github.com/Cyan4973/FiniteStateEntropy
|
||||||
Redistribution and use in source and binary forms, with or without
|
*
|
||||||
modification, are permitted provided that the following conditions are
|
* This source code is licensed under both the BSD-style license (found in the
|
||||||
met:
|
* LICENSE file in the root directory of this source tree) and the GPLv2 (found
|
||||||
|
* in the COPYING file in the root directory of this source tree).
|
||||||
* Redistributions of source code must retain the above copyright
|
* You may select, at your option, one of the above-listed licenses.
|
||||||
notice, this list of conditions and the following disclaimer.
|
|
||||||
* Redistributions in binary form must reproduce the above
|
|
||||||
copyright notice, this list of conditions and the following disclaimer
|
|
||||||
in the documentation and/or other materials provided with the
|
|
||||||
distribution.
|
|
||||||
|
|
||||||
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
|
||||||
"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
|
||||||
LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
|
||||||
A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
|
|
||||||
OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
|
||||||
SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
|
||||||
LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
|
||||||
DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
|
||||||
THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
|
||||||
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
|
||||||
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
|
||||||
|
|
||||||
You can contact the author at :
|
|
||||||
- Source repository : https://github.com/Cyan4973/FiniteStateEntropy
|
|
||||||
****************************************************************** */
|
****************************************************************** */
|
||||||
|
|
||||||
|
|
||||||
@@ -71,15 +52,6 @@ extern "C" {
|
|||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
|
||||||
/* DEBUGFILE can be defined externally,
|
|
||||||
* typically through compiler command line.
|
|
||||||
* note : currently useless.
|
|
||||||
* Value must be stderr or stdout */
|
|
||||||
#ifndef DEBUGFILE
|
|
||||||
# define DEBUGFILE stderr
|
|
||||||
#endif
|
|
||||||
|
|
||||||
|
|
||||||
/* recommended values for DEBUGLEVEL :
|
/* recommended values for DEBUGLEVEL :
|
||||||
* 0 : release mode, no debug, all run-time checks disabled
|
* 0 : release mode, no debug, all run-time checks disabled
|
||||||
* 1 : enables assert() only, no display
|
* 1 : enables assert() only, no display
|
||||||
@@ -96,7 +68,8 @@ extern "C" {
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
#if (DEBUGLEVEL>=1)
|
#if (DEBUGLEVEL>=1)
|
||||||
# include <assert.h>
|
# define ZSTD_DEPS_NEED_ASSERT
|
||||||
|
# include "zstd_deps.h"
|
||||||
#else
|
#else
|
||||||
# ifndef assert /* assert may be already defined, due to prior #include <assert.h> */
|
# ifndef assert /* assert may be already defined, due to prior #include <assert.h> */
|
||||||
# define assert(condition) ((void)0) /* disable assert (default) */
|
# define assert(condition) ((void)0) /* disable assert (default) */
|
||||||
@@ -104,7 +77,8 @@ extern "C" {
|
|||||||
#endif
|
#endif
|
||||||
|
|
||||||
#if (DEBUGLEVEL>=2)
|
#if (DEBUGLEVEL>=2)
|
||||||
# include <stdio.h>
|
# define ZSTD_DEPS_NEED_IO
|
||||||
|
# include "zstd_deps.h"
|
||||||
extern int g_debuglevel; /* the variable is only declared,
|
extern int g_debuglevel; /* the variable is only declared,
|
||||||
it actually lives in debug.c,
|
it actually lives in debug.c,
|
||||||
and is shared by the whole process.
|
and is shared by the whole process.
|
||||||
@@ -114,12 +88,12 @@ extern int g_debuglevel; /* the variable is only declared,
|
|||||||
|
|
||||||
# define RAWLOG(l, ...) { \
|
# define RAWLOG(l, ...) { \
|
||||||
if (l<=g_debuglevel) { \
|
if (l<=g_debuglevel) { \
|
||||||
fprintf(stderr, __VA_ARGS__); \
|
ZSTD_DEBUG_PRINT(__VA_ARGS__); \
|
||||||
} }
|
} }
|
||||||
# define DEBUGLOG(l, ...) { \
|
# define DEBUGLOG(l, ...) { \
|
||||||
if (l<=g_debuglevel) { \
|
if (l<=g_debuglevel) { \
|
||||||
fprintf(stderr, __FILE__ ": " __VA_ARGS__); \
|
ZSTD_DEBUG_PRINT(__FILE__ ": " __VA_ARGS__); \
|
||||||
fprintf(stderr, " \n"); \
|
ZSTD_DEBUG_PRINT(" \n"); \
|
||||||
} }
|
} }
|
||||||
#else
|
#else
|
||||||
# define RAWLOG(l, ...) {} /* disabled */
|
# define RAWLOG(l, ...) {} /* disabled */
|
||||||
@@ -132,3 +106,5 @@ extern int g_debuglevel; /* the variable is only declared,
|
|||||||
#endif
|
#endif
|
||||||
|
|
||||||
#endif /* DEBUG_H_12987983217 */
|
#endif /* DEBUG_H_12987983217 */
|
||||||
|
|
||||||
|
#endif /* USE_EXTERNAL_ZSTD */
|
||||||
|
|||||||
5
vendor/github.com/DataDog/zstd/divsufsort.c
generated
vendored
5
vendor/github.com/DataDog/zstd/divsufsort.c
generated
vendored
@@ -1,3 +1,4 @@
|
|||||||
|
#ifndef USE_EXTERNAL_ZSTD
|
||||||
/*
|
/*
|
||||||
* divsufsort.c for libdivsufsort-lite
|
* divsufsort.c for libdivsufsort-lite
|
||||||
* Copyright (c) 2003-2008 Yuta Mori All Rights Reserved.
|
* Copyright (c) 2003-2008 Yuta Mori All Rights Reserved.
|
||||||
@@ -1576,7 +1577,7 @@ note:
|
|||||||
/* Construct the inverse suffix array of type B* suffixes using trsort. */
|
/* Construct the inverse suffix array of type B* suffixes using trsort. */
|
||||||
trsort(ISAb, SA, m, 1);
|
trsort(ISAb, SA, m, 1);
|
||||||
|
|
||||||
/* Set the sorted order of tyoe B* suffixes. */
|
/* Set the sorted order of type B* suffixes. */
|
||||||
for(i = n - 1, j = m, c0 = T[n - 1]; 0 <= i;) {
|
for(i = n - 1, j = m, c0 = T[n - 1]; 0 <= i;) {
|
||||||
for(--i, c1 = c0; (0 <= i) && ((c0 = T[i]) >= c1); --i, c1 = c0) { }
|
for(--i, c1 = c0; (0 <= i) && ((c0 = T[i]) >= c1); --i, c1 = c0) { }
|
||||||
if(0 <= i) {
|
if(0 <= i) {
|
||||||
@@ -1911,3 +1912,5 @@ divbwt(const unsigned char *T, unsigned char *U, int *A, int n, unsigned char *
|
|||||||
|
|
||||||
return pidx;
|
return pidx;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#endif /* USE_EXTERNAL_ZSTD */
|
||||||
|
|||||||
3
vendor/github.com/DataDog/zstd/divsufsort.h
generated
vendored
3
vendor/github.com/DataDog/zstd/divsufsort.h
generated
vendored
@@ -1,3 +1,4 @@
|
|||||||
|
#ifndef USE_EXTERNAL_ZSTD
|
||||||
/*
|
/*
|
||||||
* divsufsort.h for libdivsufsort-lite
|
* divsufsort.h for libdivsufsort-lite
|
||||||
* Copyright (c) 2003-2008 Yuta Mori All Rights Reserved.
|
* Copyright (c) 2003-2008 Yuta Mori All Rights Reserved.
|
||||||
@@ -65,3 +66,5 @@ divbwt(const unsigned char *T, unsigned char *U, int *A, int n, unsigned char *
|
|||||||
#endif /* __cplusplus */
|
#endif /* __cplusplus */
|
||||||
|
|
||||||
#endif /* _DIVSUFSORT_H */
|
#endif /* _DIVSUFSORT_H */
|
||||||
|
|
||||||
|
#endif /* USE_EXTERNAL_ZSTD */
|
||||||
|
|||||||
267
vendor/github.com/DataDog/zstd/entropy_common.c
generated
vendored
267
vendor/github.com/DataDog/zstd/entropy_common.c
generated
vendored
@@ -1,36 +1,17 @@
|
|||||||
/*
|
#ifndef USE_EXTERNAL_ZSTD
|
||||||
Common functions of New Generation Entropy library
|
/* ******************************************************************
|
||||||
Copyright (C) 2016, Yann Collet.
|
* Common functions of New Generation Entropy library
|
||||||
|
* Copyright (c) Meta Platforms, Inc. and affiliates.
|
||||||
BSD 2-Clause License (http://www.opensource.org/licenses/bsd-license.php)
|
*
|
||||||
|
* You can contact the author at :
|
||||||
Redistribution and use in source and binary forms, with or without
|
* - FSE+HUF source repository : https://github.com/Cyan4973/FiniteStateEntropy
|
||||||
modification, are permitted provided that the following conditions are
|
* - Public forum : https://groups.google.com/forum/#!forum/lz4c
|
||||||
met:
|
*
|
||||||
|
* This source code is licensed under both the BSD-style license (found in the
|
||||||
* Redistributions of source code must retain the above copyright
|
* LICENSE file in the root directory of this source tree) and the GPLv2 (found
|
||||||
notice, this list of conditions and the following disclaimer.
|
* in the COPYING file in the root directory of this source tree).
|
||||||
* Redistributions in binary form must reproduce the above
|
* You may select, at your option, one of the above-listed licenses.
|
||||||
copyright notice, this list of conditions and the following disclaimer
|
****************************************************************** */
|
||||||
in the documentation and/or other materials provided with the
|
|
||||||
distribution.
|
|
||||||
|
|
||||||
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
|
||||||
"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
|
||||||
LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
|
||||||
A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
|
|
||||||
OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
|
||||||
SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
|
||||||
LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
|
||||||
DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
|
||||||
THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
|
||||||
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
|
||||||
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
|
||||||
|
|
||||||
You can contact the author at :
|
|
||||||
- FSE+HUF source repository : https://github.com/Cyan4973/FiniteStateEntropy
|
|
||||||
- Public forum : https://groups.google.com/forum/#!forum/lz4c
|
|
||||||
*************************************************************************** */
|
|
||||||
|
|
||||||
/* *************************************
|
/* *************************************
|
||||||
* Dependencies
|
* Dependencies
|
||||||
@@ -39,8 +20,8 @@
|
|||||||
#include "error_private.h" /* ERR_*, ERROR */
|
#include "error_private.h" /* ERR_*, ERROR */
|
||||||
#define FSE_STATIC_LINKING_ONLY /* FSE_MIN_TABLELOG */
|
#define FSE_STATIC_LINKING_ONLY /* FSE_MIN_TABLELOG */
|
||||||
#include "fse.h"
|
#include "fse.h"
|
||||||
#define HUF_STATIC_LINKING_ONLY /* HUF_TABLELOG_ABSOLUTEMAX */
|
|
||||||
#include "huf.h"
|
#include "huf.h"
|
||||||
|
#include "bits.h" /* ZSDT_highbit32, ZSTD_countTrailingZeros32 */
|
||||||
|
|
||||||
|
|
||||||
/*=== Version ===*/
|
/*=== Version ===*/
|
||||||
@@ -58,7 +39,8 @@ const char* HUF_getErrorName(size_t code) { return ERR_getErrorName(code); }
|
|||||||
/*-**************************************************************
|
/*-**************************************************************
|
||||||
* FSE NCount encoding-decoding
|
* FSE NCount encoding-decoding
|
||||||
****************************************************************/
|
****************************************************************/
|
||||||
size_t FSE_readNCount (short* normalizedCounter, unsigned* maxSVPtr, unsigned* tableLogPtr,
|
FORCE_INLINE_TEMPLATE
|
||||||
|
size_t FSE_readNCount_body(short* normalizedCounter, unsigned* maxSVPtr, unsigned* tableLogPtr,
|
||||||
const void* headerBuffer, size_t hbSize)
|
const void* headerBuffer, size_t hbSize)
|
||||||
{
|
{
|
||||||
const BYTE* const istart = (const BYTE*) headerBuffer;
|
const BYTE* const istart = (const BYTE*) headerBuffer;
|
||||||
@@ -70,23 +52,23 @@ size_t FSE_readNCount (short* normalizedCounter, unsigned* maxSVPtr, unsigned* t
|
|||||||
U32 bitStream;
|
U32 bitStream;
|
||||||
int bitCount;
|
int bitCount;
|
||||||
unsigned charnum = 0;
|
unsigned charnum = 0;
|
||||||
|
unsigned const maxSV1 = *maxSVPtr + 1;
|
||||||
int previous0 = 0;
|
int previous0 = 0;
|
||||||
|
|
||||||
if (hbSize < 4) {
|
if (hbSize < 8) {
|
||||||
/* This function only works when hbSize >= 4 */
|
/* This function only works when hbSize >= 8 */
|
||||||
char buffer[4];
|
char buffer[8] = {0};
|
||||||
memset(buffer, 0, sizeof(buffer));
|
ZSTD_memcpy(buffer, headerBuffer, hbSize);
|
||||||
memcpy(buffer, headerBuffer, hbSize);
|
|
||||||
{ size_t const countSize = FSE_readNCount(normalizedCounter, maxSVPtr, tableLogPtr,
|
{ size_t const countSize = FSE_readNCount(normalizedCounter, maxSVPtr, tableLogPtr,
|
||||||
buffer, sizeof(buffer));
|
buffer, sizeof(buffer));
|
||||||
if (FSE_isError(countSize)) return countSize;
|
if (FSE_isError(countSize)) return countSize;
|
||||||
if (countSize > hbSize) return ERROR(corruption_detected);
|
if (countSize > hbSize) return ERROR(corruption_detected);
|
||||||
return countSize;
|
return countSize;
|
||||||
} }
|
} }
|
||||||
assert(hbSize >= 4);
|
assert(hbSize >= 8);
|
||||||
|
|
||||||
/* init */
|
/* init */
|
||||||
memset(normalizedCounter, 0, (*maxSVPtr+1) * sizeof(normalizedCounter[0])); /* all symbols not present in NCount have a frequency of 0 */
|
ZSTD_memset(normalizedCounter, 0, (*maxSVPtr+1) * sizeof(normalizedCounter[0])); /* all symbols not present in NCount have a frequency of 0 */
|
||||||
bitStream = MEM_readLE32(ip);
|
bitStream = MEM_readLE32(ip);
|
||||||
nbBits = (bitStream & 0xF) + FSE_MIN_TABLELOG; /* extract tableLog */
|
nbBits = (bitStream & 0xF) + FSE_MIN_TABLELOG; /* extract tableLog */
|
||||||
if (nbBits > FSE_TABLELOG_ABSOLUTE_MAX) return ERROR(tableLog_tooLarge);
|
if (nbBits > FSE_TABLELOG_ABSOLUTE_MAX) return ERROR(tableLog_tooLarge);
|
||||||
@@ -97,36 +79,58 @@ size_t FSE_readNCount (short* normalizedCounter, unsigned* maxSVPtr, unsigned* t
|
|||||||
threshold = 1<<nbBits;
|
threshold = 1<<nbBits;
|
||||||
nbBits++;
|
nbBits++;
|
||||||
|
|
||||||
while ((remaining>1) & (charnum<=*maxSVPtr)) {
|
for (;;) {
|
||||||
if (previous0) {
|
if (previous0) {
|
||||||
unsigned n0 = charnum;
|
/* Count the number of repeats. Each time the
|
||||||
while ((bitStream & 0xFFFF) == 0xFFFF) {
|
* 2-bit repeat code is 0b11 there is another
|
||||||
n0 += 24;
|
* repeat.
|
||||||
if (ip < iend-5) {
|
* Avoid UB by setting the high bit to 1.
|
||||||
ip += 2;
|
*/
|
||||||
bitStream = MEM_readLE32(ip) >> bitCount;
|
int repeats = ZSTD_countTrailingZeros32(~bitStream | 0x80000000) >> 1;
|
||||||
|
while (repeats >= 12) {
|
||||||
|
charnum += 3 * 12;
|
||||||
|
if (LIKELY(ip <= iend-7)) {
|
||||||
|
ip += 3;
|
||||||
} else {
|
} else {
|
||||||
bitStream >>= 16;
|
bitCount -= (int)(8 * (iend - 7 - ip));
|
||||||
bitCount += 16;
|
bitCount &= 31;
|
||||||
} }
|
ip = iend - 4;
|
||||||
while ((bitStream & 3) == 3) {
|
|
||||||
n0 += 3;
|
|
||||||
bitStream >>= 2;
|
|
||||||
bitCount += 2;
|
|
||||||
}
|
}
|
||||||
n0 += bitStream & 3;
|
bitStream = MEM_readLE32(ip) >> bitCount;
|
||||||
|
repeats = ZSTD_countTrailingZeros32(~bitStream | 0x80000000) >> 1;
|
||||||
|
}
|
||||||
|
charnum += 3 * repeats;
|
||||||
|
bitStream >>= 2 * repeats;
|
||||||
|
bitCount += 2 * repeats;
|
||||||
|
|
||||||
|
/* Add the final repeat which isn't 0b11. */
|
||||||
|
assert((bitStream & 3) < 3);
|
||||||
|
charnum += bitStream & 3;
|
||||||
bitCount += 2;
|
bitCount += 2;
|
||||||
if (n0 > *maxSVPtr) return ERROR(maxSymbolValue_tooSmall);
|
|
||||||
while (charnum < n0) normalizedCounter[charnum++] = 0;
|
/* This is an error, but break and return an error
|
||||||
if ((ip <= iend-7) || (ip + (bitCount>>3) <= iend-4)) {
|
* at the end, because returning out of a loop makes
|
||||||
|
* it harder for the compiler to optimize.
|
||||||
|
*/
|
||||||
|
if (charnum >= maxSV1) break;
|
||||||
|
|
||||||
|
/* We don't need to set the normalized count to 0
|
||||||
|
* because we already memset the whole buffer to 0.
|
||||||
|
*/
|
||||||
|
|
||||||
|
if (LIKELY(ip <= iend-7) || (ip + (bitCount>>3) <= iend-4)) {
|
||||||
assert((bitCount >> 3) <= 3); /* For first condition to work */
|
assert((bitCount >> 3) <= 3); /* For first condition to work */
|
||||||
ip += bitCount>>3;
|
ip += bitCount>>3;
|
||||||
bitCount &= 7;
|
bitCount &= 7;
|
||||||
bitStream = MEM_readLE32(ip) >> bitCount;
|
|
||||||
} else {
|
} else {
|
||||||
bitStream >>= 2;
|
bitCount -= (int)(8 * (iend - 4 - ip));
|
||||||
} }
|
bitCount &= 31;
|
||||||
{ int const max = (2*threshold-1) - remaining;
|
ip = iend - 4;
|
||||||
|
}
|
||||||
|
bitStream = MEM_readLE32(ip) >> bitCount;
|
||||||
|
}
|
||||||
|
{
|
||||||
|
int const max = (2*threshold-1) - remaining;
|
||||||
int count;
|
int count;
|
||||||
|
|
||||||
if ((bitStream & (threshold-1)) < (U32)max) {
|
if ((bitStream & (threshold-1)) < (U32)max) {
|
||||||
@@ -139,24 +143,43 @@ size_t FSE_readNCount (short* normalizedCounter, unsigned* maxSVPtr, unsigned* t
|
|||||||
}
|
}
|
||||||
|
|
||||||
count--; /* extra accuracy */
|
count--; /* extra accuracy */
|
||||||
remaining -= count < 0 ? -count : count; /* -1 means +1 */
|
/* When it matters (small blocks), this is a
|
||||||
|
* predictable branch, because we don't use -1.
|
||||||
|
*/
|
||||||
|
if (count >= 0) {
|
||||||
|
remaining -= count;
|
||||||
|
} else {
|
||||||
|
assert(count == -1);
|
||||||
|
remaining += count;
|
||||||
|
}
|
||||||
normalizedCounter[charnum++] = (short)count;
|
normalizedCounter[charnum++] = (short)count;
|
||||||
previous0 = !count;
|
previous0 = !count;
|
||||||
while (remaining < threshold) {
|
|
||||||
nbBits--;
|
|
||||||
threshold >>= 1;
|
|
||||||
}
|
|
||||||
|
|
||||||
if ((ip <= iend-7) || (ip + (bitCount>>3) <= iend-4)) {
|
assert(threshold > 1);
|
||||||
|
if (remaining < threshold) {
|
||||||
|
/* This branch can be folded into the
|
||||||
|
* threshold update condition because we
|
||||||
|
* know that threshold > 1.
|
||||||
|
*/
|
||||||
|
if (remaining <= 1) break;
|
||||||
|
nbBits = ZSTD_highbit32(remaining) + 1;
|
||||||
|
threshold = 1 << (nbBits - 1);
|
||||||
|
}
|
||||||
|
if (charnum >= maxSV1) break;
|
||||||
|
|
||||||
|
if (LIKELY(ip <= iend-7) || (ip + (bitCount>>3) <= iend-4)) {
|
||||||
ip += bitCount>>3;
|
ip += bitCount>>3;
|
||||||
bitCount &= 7;
|
bitCount &= 7;
|
||||||
} else {
|
} else {
|
||||||
bitCount -= (int)(8 * (iend - 4 - ip));
|
bitCount -= (int)(8 * (iend - 4 - ip));
|
||||||
|
bitCount &= 31;
|
||||||
ip = iend - 4;
|
ip = iend - 4;
|
||||||
}
|
}
|
||||||
bitStream = MEM_readLE32(ip) >> (bitCount & 31);
|
bitStream = MEM_readLE32(ip) >> bitCount;
|
||||||
} } /* while ((remaining>1) & (charnum<=*maxSVPtr)) */
|
} }
|
||||||
if (remaining != 1) return ERROR(corruption_detected);
|
if (remaining != 1) return ERROR(corruption_detected);
|
||||||
|
/* Only possible when there are too many zeros. */
|
||||||
|
if (charnum > maxSV1) return ERROR(maxSymbolValue_tooSmall);
|
||||||
if (bitCount > 32) return ERROR(corruption_detected);
|
if (bitCount > 32) return ERROR(corruption_detected);
|
||||||
*maxSVPtr = charnum-1;
|
*maxSVPtr = charnum-1;
|
||||||
|
|
||||||
@@ -164,6 +187,43 @@ size_t FSE_readNCount (short* normalizedCounter, unsigned* maxSVPtr, unsigned* t
|
|||||||
return ip-istart;
|
return ip-istart;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* Avoids the FORCE_INLINE of the _body() function. */
|
||||||
|
static size_t FSE_readNCount_body_default(
|
||||||
|
short* normalizedCounter, unsigned* maxSVPtr, unsigned* tableLogPtr,
|
||||||
|
const void* headerBuffer, size_t hbSize)
|
||||||
|
{
|
||||||
|
return FSE_readNCount_body(normalizedCounter, maxSVPtr, tableLogPtr, headerBuffer, hbSize);
|
||||||
|
}
|
||||||
|
|
||||||
|
#if DYNAMIC_BMI2
|
||||||
|
BMI2_TARGET_ATTRIBUTE static size_t FSE_readNCount_body_bmi2(
|
||||||
|
short* normalizedCounter, unsigned* maxSVPtr, unsigned* tableLogPtr,
|
||||||
|
const void* headerBuffer, size_t hbSize)
|
||||||
|
{
|
||||||
|
return FSE_readNCount_body(normalizedCounter, maxSVPtr, tableLogPtr, headerBuffer, hbSize);
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
|
size_t FSE_readNCount_bmi2(
|
||||||
|
short* normalizedCounter, unsigned* maxSVPtr, unsigned* tableLogPtr,
|
||||||
|
const void* headerBuffer, size_t hbSize, int bmi2)
|
||||||
|
{
|
||||||
|
#if DYNAMIC_BMI2
|
||||||
|
if (bmi2) {
|
||||||
|
return FSE_readNCount_body_bmi2(normalizedCounter, maxSVPtr, tableLogPtr, headerBuffer, hbSize);
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
(void)bmi2;
|
||||||
|
return FSE_readNCount_body_default(normalizedCounter, maxSVPtr, tableLogPtr, headerBuffer, hbSize);
|
||||||
|
}
|
||||||
|
|
||||||
|
size_t FSE_readNCount(
|
||||||
|
short* normalizedCounter, unsigned* maxSVPtr, unsigned* tableLogPtr,
|
||||||
|
const void* headerBuffer, size_t hbSize)
|
||||||
|
{
|
||||||
|
return FSE_readNCount_bmi2(normalizedCounter, maxSVPtr, tableLogPtr, headerBuffer, hbSize, /* bmi2 */ 0);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
/*! HUF_readStats() :
|
/*! HUF_readStats() :
|
||||||
Read compact Huffman tree, saved by HUF_writeCTable().
|
Read compact Huffman tree, saved by HUF_writeCTable().
|
||||||
@@ -175,6 +235,17 @@ size_t FSE_readNCount (short* normalizedCounter, unsigned* maxSVPtr, unsigned* t
|
|||||||
size_t HUF_readStats(BYTE* huffWeight, size_t hwSize, U32* rankStats,
|
size_t HUF_readStats(BYTE* huffWeight, size_t hwSize, U32* rankStats,
|
||||||
U32* nbSymbolsPtr, U32* tableLogPtr,
|
U32* nbSymbolsPtr, U32* tableLogPtr,
|
||||||
const void* src, size_t srcSize)
|
const void* src, size_t srcSize)
|
||||||
|
{
|
||||||
|
U32 wksp[HUF_READ_STATS_WORKSPACE_SIZE_U32];
|
||||||
|
return HUF_readStats_wksp(huffWeight, hwSize, rankStats, nbSymbolsPtr, tableLogPtr, src, srcSize, wksp, sizeof(wksp), /* flags */ 0);
|
||||||
|
}
|
||||||
|
|
||||||
|
FORCE_INLINE_TEMPLATE size_t
|
||||||
|
HUF_readStats_body(BYTE* huffWeight, size_t hwSize, U32* rankStats,
|
||||||
|
U32* nbSymbolsPtr, U32* tableLogPtr,
|
||||||
|
const void* src, size_t srcSize,
|
||||||
|
void* workSpace, size_t wkspSize,
|
||||||
|
int bmi2)
|
||||||
{
|
{
|
||||||
U32 weightTotal;
|
U32 weightTotal;
|
||||||
const BYTE* ip = (const BYTE*) src;
|
const BYTE* ip = (const BYTE*) src;
|
||||||
@@ -183,7 +254,7 @@ size_t HUF_readStats(BYTE* huffWeight, size_t hwSize, U32* rankStats,
|
|||||||
|
|
||||||
if (!srcSize) return ERROR(srcSize_wrong);
|
if (!srcSize) return ERROR(srcSize_wrong);
|
||||||
iSize = ip[0];
|
iSize = ip[0];
|
||||||
/* memset(huffWeight, 0, hwSize); *//* is not necessary, even though some analyzer complain ... */
|
/* ZSTD_memset(huffWeight, 0, hwSize); *//* is not necessary, even though some analyzer complain ... */
|
||||||
|
|
||||||
if (iSize >= 128) { /* special header */
|
if (iSize >= 128) { /* special header */
|
||||||
oSize = iSize - 127;
|
oSize = iSize - 127;
|
||||||
@@ -197,31 +268,31 @@ size_t HUF_readStats(BYTE* huffWeight, size_t hwSize, U32* rankStats,
|
|||||||
huffWeight[n+1] = ip[n/2] & 15;
|
huffWeight[n+1] = ip[n/2] & 15;
|
||||||
} } }
|
} } }
|
||||||
else { /* header compressed with FSE (normal case) */
|
else { /* header compressed with FSE (normal case) */
|
||||||
FSE_DTable fseWorkspace[FSE_DTABLE_SIZE_U32(6)]; /* 6 is max possible tableLog for HUF header (maybe even 5, to be tested) */
|
|
||||||
if (iSize+1 > srcSize) return ERROR(srcSize_wrong);
|
if (iSize+1 > srcSize) return ERROR(srcSize_wrong);
|
||||||
oSize = FSE_decompress_wksp(huffWeight, hwSize-1, ip+1, iSize, fseWorkspace, 6); /* max (hwSize-1) values decoded, as last one is implied */
|
/* max (hwSize-1) values decoded, as last one is implied */
|
||||||
|
oSize = FSE_decompress_wksp_bmi2(huffWeight, hwSize-1, ip+1, iSize, 6, workSpace, wkspSize, bmi2);
|
||||||
if (FSE_isError(oSize)) return oSize;
|
if (FSE_isError(oSize)) return oSize;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* collect weight stats */
|
/* collect weight stats */
|
||||||
memset(rankStats, 0, (HUF_TABLELOG_MAX + 1) * sizeof(U32));
|
ZSTD_memset(rankStats, 0, (HUF_TABLELOG_MAX + 1) * sizeof(U32));
|
||||||
weightTotal = 0;
|
weightTotal = 0;
|
||||||
{ U32 n; for (n=0; n<oSize; n++) {
|
{ U32 n; for (n=0; n<oSize; n++) {
|
||||||
if (huffWeight[n] >= HUF_TABLELOG_MAX) return ERROR(corruption_detected);
|
if (huffWeight[n] > HUF_TABLELOG_MAX) return ERROR(corruption_detected);
|
||||||
rankStats[huffWeight[n]]++;
|
rankStats[huffWeight[n]]++;
|
||||||
weightTotal += (1 << huffWeight[n]) >> 1;
|
weightTotal += (1 << huffWeight[n]) >> 1;
|
||||||
} }
|
} }
|
||||||
if (weightTotal == 0) return ERROR(corruption_detected);
|
if (weightTotal == 0) return ERROR(corruption_detected);
|
||||||
|
|
||||||
/* get last non-null symbol weight (implied, total must be 2^n) */
|
/* get last non-null symbol weight (implied, total must be 2^n) */
|
||||||
{ U32 const tableLog = BIT_highbit32(weightTotal) + 1;
|
{ U32 const tableLog = ZSTD_highbit32(weightTotal) + 1;
|
||||||
if (tableLog > HUF_TABLELOG_MAX) return ERROR(corruption_detected);
|
if (tableLog > HUF_TABLELOG_MAX) return ERROR(corruption_detected);
|
||||||
*tableLogPtr = tableLog;
|
*tableLogPtr = tableLog;
|
||||||
/* determine last weight */
|
/* determine last weight */
|
||||||
{ U32 const total = 1 << tableLog;
|
{ U32 const total = 1 << tableLog;
|
||||||
U32 const rest = total - weightTotal;
|
U32 const rest = total - weightTotal;
|
||||||
U32 const verif = 1 << BIT_highbit32(rest);
|
U32 const verif = 1 << ZSTD_highbit32(rest);
|
||||||
U32 const lastWeight = BIT_highbit32(rest) + 1;
|
U32 const lastWeight = ZSTD_highbit32(rest) + 1;
|
||||||
if (verif != rest) return ERROR(corruption_detected); /* last value must be a clean power of 2 */
|
if (verif != rest) return ERROR(corruption_detected); /* last value must be a clean power of 2 */
|
||||||
huffWeight[oSize] = (BYTE)lastWeight;
|
huffWeight[oSize] = (BYTE)lastWeight;
|
||||||
rankStats[lastWeight]++;
|
rankStats[lastWeight]++;
|
||||||
@@ -234,3 +305,39 @@ size_t HUF_readStats(BYTE* huffWeight, size_t hwSize, U32* rankStats,
|
|||||||
*nbSymbolsPtr = (U32)(oSize+1);
|
*nbSymbolsPtr = (U32)(oSize+1);
|
||||||
return iSize+1;
|
return iSize+1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* Avoids the FORCE_INLINE of the _body() function. */
|
||||||
|
static size_t HUF_readStats_body_default(BYTE* huffWeight, size_t hwSize, U32* rankStats,
|
||||||
|
U32* nbSymbolsPtr, U32* tableLogPtr,
|
||||||
|
const void* src, size_t srcSize,
|
||||||
|
void* workSpace, size_t wkspSize)
|
||||||
|
{
|
||||||
|
return HUF_readStats_body(huffWeight, hwSize, rankStats, nbSymbolsPtr, tableLogPtr, src, srcSize, workSpace, wkspSize, 0);
|
||||||
|
}
|
||||||
|
|
||||||
|
#if DYNAMIC_BMI2
|
||||||
|
static BMI2_TARGET_ATTRIBUTE size_t HUF_readStats_body_bmi2(BYTE* huffWeight, size_t hwSize, U32* rankStats,
|
||||||
|
U32* nbSymbolsPtr, U32* tableLogPtr,
|
||||||
|
const void* src, size_t srcSize,
|
||||||
|
void* workSpace, size_t wkspSize)
|
||||||
|
{
|
||||||
|
return HUF_readStats_body(huffWeight, hwSize, rankStats, nbSymbolsPtr, tableLogPtr, src, srcSize, workSpace, wkspSize, 1);
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
|
size_t HUF_readStats_wksp(BYTE* huffWeight, size_t hwSize, U32* rankStats,
|
||||||
|
U32* nbSymbolsPtr, U32* tableLogPtr,
|
||||||
|
const void* src, size_t srcSize,
|
||||||
|
void* workSpace, size_t wkspSize,
|
||||||
|
int flags)
|
||||||
|
{
|
||||||
|
#if DYNAMIC_BMI2
|
||||||
|
if (flags & HUF_flags_bmi2) {
|
||||||
|
return HUF_readStats_body_bmi2(huffWeight, hwSize, rankStats, nbSymbolsPtr, tableLogPtr, src, srcSize, workSpace, wkspSize);
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
(void)flags;
|
||||||
|
return HUF_readStats_body_default(huffWeight, hwSize, rankStats, nbSymbolsPtr, tableLogPtr, src, srcSize, workSpace, wkspSize);
|
||||||
|
}
|
||||||
|
|
||||||
|
#endif /* USE_EXTERNAL_ZSTD */
|
||||||
|
|||||||
16
vendor/github.com/DataDog/zstd/error_private.c
generated
vendored
16
vendor/github.com/DataDog/zstd/error_private.c
generated
vendored
@@ -1,5 +1,6 @@
|
|||||||
|
#ifndef USE_EXTERNAL_ZSTD
|
||||||
/*
|
/*
|
||||||
* Copyright (c) 2016-present, Yann Collet, Facebook, Inc.
|
* Copyright (c) Meta Platforms, Inc. and affiliates.
|
||||||
* All rights reserved.
|
* All rights reserved.
|
||||||
*
|
*
|
||||||
* This source code is licensed under both the BSD-style license (found in the
|
* This source code is licensed under both the BSD-style license (found in the
|
||||||
@@ -27,9 +28,11 @@ const char* ERR_getErrorString(ERR_enum code)
|
|||||||
case PREFIX(version_unsupported): return "Version not supported";
|
case PREFIX(version_unsupported): return "Version not supported";
|
||||||
case PREFIX(frameParameter_unsupported): return "Unsupported frame parameter";
|
case PREFIX(frameParameter_unsupported): return "Unsupported frame parameter";
|
||||||
case PREFIX(frameParameter_windowTooLarge): return "Frame requires too much memory for decoding";
|
case PREFIX(frameParameter_windowTooLarge): return "Frame requires too much memory for decoding";
|
||||||
case PREFIX(corruption_detected): return "Corrupted block detected";
|
case PREFIX(corruption_detected): return "Data corruption detected";
|
||||||
case PREFIX(checksum_wrong): return "Restored data doesn't match checksum";
|
case PREFIX(checksum_wrong): return "Restored data doesn't match checksum";
|
||||||
|
case PREFIX(literals_headerWrong): return "Header of Literals' block doesn't respect format specification";
|
||||||
case PREFIX(parameter_unsupported): return "Unsupported parameter";
|
case PREFIX(parameter_unsupported): return "Unsupported parameter";
|
||||||
|
case PREFIX(parameter_combination_unsupported): return "Unsupported combination of parameters";
|
||||||
case PREFIX(parameter_outOfBound): return "Parameter is out of bound";
|
case PREFIX(parameter_outOfBound): return "Parameter is out of bound";
|
||||||
case PREFIX(init_missing): return "Context should be init first";
|
case PREFIX(init_missing): return "Context should be init first";
|
||||||
case PREFIX(memory_allocation): return "Allocation error : not enough memory";
|
case PREFIX(memory_allocation): return "Allocation error : not enough memory";
|
||||||
@@ -38,17 +41,26 @@ const char* ERR_getErrorString(ERR_enum code)
|
|||||||
case PREFIX(tableLog_tooLarge): return "tableLog requires too much memory : unsupported";
|
case PREFIX(tableLog_tooLarge): return "tableLog requires too much memory : unsupported";
|
||||||
case PREFIX(maxSymbolValue_tooLarge): return "Unsupported max Symbol Value : too large";
|
case PREFIX(maxSymbolValue_tooLarge): return "Unsupported max Symbol Value : too large";
|
||||||
case PREFIX(maxSymbolValue_tooSmall): return "Specified maxSymbolValue is too small";
|
case PREFIX(maxSymbolValue_tooSmall): return "Specified maxSymbolValue is too small";
|
||||||
|
case PREFIX(stabilityCondition_notRespected): return "pledged buffer stability condition is not respected";
|
||||||
case PREFIX(dictionary_corrupted): return "Dictionary is corrupted";
|
case PREFIX(dictionary_corrupted): return "Dictionary is corrupted";
|
||||||
case PREFIX(dictionary_wrong): return "Dictionary mismatch";
|
case PREFIX(dictionary_wrong): return "Dictionary mismatch";
|
||||||
case PREFIX(dictionaryCreation_failed): return "Cannot create Dictionary from provided samples";
|
case PREFIX(dictionaryCreation_failed): return "Cannot create Dictionary from provided samples";
|
||||||
case PREFIX(dstSize_tooSmall): return "Destination buffer is too small";
|
case PREFIX(dstSize_tooSmall): return "Destination buffer is too small";
|
||||||
case PREFIX(srcSize_wrong): return "Src size is incorrect";
|
case PREFIX(srcSize_wrong): return "Src size is incorrect";
|
||||||
case PREFIX(dstBuffer_null): return "Operation on NULL destination buffer";
|
case PREFIX(dstBuffer_null): return "Operation on NULL destination buffer";
|
||||||
|
case PREFIX(noForwardProgress_destFull): return "Operation made no progress over multiple calls, due to output buffer being full";
|
||||||
|
case PREFIX(noForwardProgress_inputEmpty): return "Operation made no progress over multiple calls, due to input being empty";
|
||||||
/* following error codes are not stable and may be removed or changed in a future version */
|
/* following error codes are not stable and may be removed or changed in a future version */
|
||||||
case PREFIX(frameIndex_tooLarge): return "Frame index is too large";
|
case PREFIX(frameIndex_tooLarge): return "Frame index is too large";
|
||||||
case PREFIX(seekableIO): return "An I/O error occurred when reading/seeking";
|
case PREFIX(seekableIO): return "An I/O error occurred when reading/seeking";
|
||||||
|
case PREFIX(dstBuffer_wrong): return "Destination buffer is wrong";
|
||||||
|
case PREFIX(srcBuffer_wrong): return "Source buffer is wrong";
|
||||||
|
case PREFIX(sequenceProducer_failed): return "Block-level external sequence producer returned an error code";
|
||||||
|
case PREFIX(externalSequences_invalid): return "External sequences are not valid";
|
||||||
case PREFIX(maxCode):
|
case PREFIX(maxCode):
|
||||||
default: return notErrorCode;
|
default: return notErrorCode;
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#endif /* USE_EXTERNAL_ZSTD */
|
||||||
|
|||||||
92
vendor/github.com/DataDog/zstd/error_private.h
generated
vendored
92
vendor/github.com/DataDog/zstd/error_private.h
generated
vendored
@@ -1,5 +1,6 @@
|
|||||||
|
#ifndef USE_EXTERNAL_ZSTD
|
||||||
/*
|
/*
|
||||||
* Copyright (c) 2016-present, Yann Collet, Facebook, Inc.
|
* Copyright (c) Meta Platforms, Inc. and affiliates.
|
||||||
* All rights reserved.
|
* All rights reserved.
|
||||||
*
|
*
|
||||||
* This source code is licensed under both the BSD-style license (found in the
|
* This source code is licensed under both the BSD-style license (found in the
|
||||||
@@ -21,8 +22,10 @@ extern "C" {
|
|||||||
/* ****************************************
|
/* ****************************************
|
||||||
* Dependencies
|
* Dependencies
|
||||||
******************************************/
|
******************************************/
|
||||||
#include <stddef.h> /* size_t */
|
|
||||||
#include "zstd_errors.h" /* enum list */
|
#include "zstd_errors.h" /* enum list */
|
||||||
|
#include "compiler.h"
|
||||||
|
#include "debug.h"
|
||||||
|
#include "zstd_deps.h" /* size_t */
|
||||||
|
|
||||||
|
|
||||||
/* ****************************************
|
/* ****************************************
|
||||||
@@ -49,7 +52,7 @@ typedef ZSTD_ErrorCode ERR_enum;
|
|||||||
/*-****************************************
|
/*-****************************************
|
||||||
* Error codes handling
|
* Error codes handling
|
||||||
******************************************/
|
******************************************/
|
||||||
#undef ERROR /* reported already defined on VS 2015 (Rich Geldreich) */
|
#undef ERROR /* already defined on Visual Studio */
|
||||||
#define ERROR(name) ZSTD_ERROR(name)
|
#define ERROR(name) ZSTD_ERROR(name)
|
||||||
#define ZSTD_ERROR(name) ((size_t)-PREFIX(name))
|
#define ZSTD_ERROR(name) ((size_t)-PREFIX(name))
|
||||||
|
|
||||||
@@ -57,6 +60,10 @@ ERR_STATIC unsigned ERR_isError(size_t code) { return (code > ERROR(maxCode)); }
|
|||||||
|
|
||||||
ERR_STATIC ERR_enum ERR_getErrorCode(size_t code) { if (!ERR_isError(code)) return (ERR_enum)0; return (ERR_enum) (0-code); }
|
ERR_STATIC ERR_enum ERR_getErrorCode(size_t code) { if (!ERR_isError(code)) return (ERR_enum)0; return (ERR_enum) (0-code); }
|
||||||
|
|
||||||
|
/* check and forward error code */
|
||||||
|
#define CHECK_V_F(e, f) size_t const e = f; if (ERR_isError(e)) return e
|
||||||
|
#define CHECK_F(f) { CHECK_V_F(_var_err__, f); }
|
||||||
|
|
||||||
|
|
||||||
/*-****************************************
|
/*-****************************************
|
||||||
* Error Strings
|
* Error Strings
|
||||||
@@ -69,8 +76,87 @@ ERR_STATIC const char* ERR_getErrorName(size_t code)
|
|||||||
return ERR_getErrorString(ERR_getErrorCode(code));
|
return ERR_getErrorString(ERR_getErrorCode(code));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Ignore: this is an internal helper.
|
||||||
|
*
|
||||||
|
* This is a helper function to help force C99-correctness during compilation.
|
||||||
|
* Under strict compilation modes, variadic macro arguments can't be empty.
|
||||||
|
* However, variadic function arguments can be. Using a function therefore lets
|
||||||
|
* us statically check that at least one (string) argument was passed,
|
||||||
|
* independent of the compilation flags.
|
||||||
|
*/
|
||||||
|
static INLINE_KEYWORD UNUSED_ATTR
|
||||||
|
void _force_has_format_string(const char *format, ...) {
|
||||||
|
(void)format;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Ignore: this is an internal helper.
|
||||||
|
*
|
||||||
|
* We want to force this function invocation to be syntactically correct, but
|
||||||
|
* we don't want to force runtime evaluation of its arguments.
|
||||||
|
*/
|
||||||
|
#define _FORCE_HAS_FORMAT_STRING(...) \
|
||||||
|
if (0) { \
|
||||||
|
_force_has_format_string(__VA_ARGS__); \
|
||||||
|
}
|
||||||
|
|
||||||
|
#define ERR_QUOTE(str) #str
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Return the specified error if the condition evaluates to true.
|
||||||
|
*
|
||||||
|
* In debug modes, prints additional information.
|
||||||
|
* In order to do that (particularly, printing the conditional that failed),
|
||||||
|
* this can't just wrap RETURN_ERROR().
|
||||||
|
*/
|
||||||
|
#define RETURN_ERROR_IF(cond, err, ...) \
|
||||||
|
if (cond) { \
|
||||||
|
RAWLOG(3, "%s:%d: ERROR!: check %s failed, returning %s", \
|
||||||
|
__FILE__, __LINE__, ERR_QUOTE(cond), ERR_QUOTE(ERROR(err))); \
|
||||||
|
_FORCE_HAS_FORMAT_STRING(__VA_ARGS__); \
|
||||||
|
RAWLOG(3, ": " __VA_ARGS__); \
|
||||||
|
RAWLOG(3, "\n"); \
|
||||||
|
return ERROR(err); \
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Unconditionally return the specified error.
|
||||||
|
*
|
||||||
|
* In debug modes, prints additional information.
|
||||||
|
*/
|
||||||
|
#define RETURN_ERROR(err, ...) \
|
||||||
|
do { \
|
||||||
|
RAWLOG(3, "%s:%d: ERROR!: unconditional check failed, returning %s", \
|
||||||
|
__FILE__, __LINE__, ERR_QUOTE(ERROR(err))); \
|
||||||
|
_FORCE_HAS_FORMAT_STRING(__VA_ARGS__); \
|
||||||
|
RAWLOG(3, ": " __VA_ARGS__); \
|
||||||
|
RAWLOG(3, "\n"); \
|
||||||
|
return ERROR(err); \
|
||||||
|
} while(0);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* If the provided expression evaluates to an error code, returns that error code.
|
||||||
|
*
|
||||||
|
* In debug modes, prints additional information.
|
||||||
|
*/
|
||||||
|
#define FORWARD_IF_ERROR(err, ...) \
|
||||||
|
do { \
|
||||||
|
size_t const err_code = (err); \
|
||||||
|
if (ERR_isError(err_code)) { \
|
||||||
|
RAWLOG(3, "%s:%d: ERROR!: forwarding error in %s: %s", \
|
||||||
|
__FILE__, __LINE__, ERR_QUOTE(err), ERR_getErrorName(err_code)); \
|
||||||
|
_FORCE_HAS_FORMAT_STRING(__VA_ARGS__); \
|
||||||
|
RAWLOG(3, ": " __VA_ARGS__); \
|
||||||
|
RAWLOG(3, "\n"); \
|
||||||
|
return err_code; \
|
||||||
|
} \
|
||||||
|
} while(0);
|
||||||
|
|
||||||
#if defined (__cplusplus)
|
#if defined (__cplusplus)
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#endif /* ERROR_H_MODULE */
|
#endif /* ERROR_H_MODULE */
|
||||||
|
|
||||||
|
#endif /* USE_EXTERNAL_ZSTD */
|
||||||
|
|||||||
1
vendor/github.com/DataDog/zstd/errors.go
generated
vendored
1
vendor/github.com/DataDog/zstd/errors.go
generated
vendored
@@ -1,7 +1,6 @@
|
|||||||
package zstd
|
package zstd
|
||||||
|
|
||||||
/*
|
/*
|
||||||
#define ZSTD_STATIC_LINKING_ONLY
|
|
||||||
#include "zstd.h"
|
#include "zstd.h"
|
||||||
*/
|
*/
|
||||||
import "C"
|
import "C"
|
||||||
|
|||||||
14
vendor/github.com/DataDog/zstd/external_zstd.go
generated
vendored
Normal file
14
vendor/github.com/DataDog/zstd/external_zstd.go
generated
vendored
Normal file
@@ -0,0 +1,14 @@
|
|||||||
|
//go:build external_libzstd
|
||||||
|
// +build external_libzstd
|
||||||
|
|
||||||
|
package zstd
|
||||||
|
|
||||||
|
// #cgo CFLAGS: -DUSE_EXTERNAL_ZSTD
|
||||||
|
// #cgo pkg-config: libzstd
|
||||||
|
/*
|
||||||
|
#include<zstd.h>
|
||||||
|
#if ZSTD_VERSION_NUMBER < 10400
|
||||||
|
#error "ZSTD version >= 1.4 is required"
|
||||||
|
#endif
|
||||||
|
*/
|
||||||
|
import "C"
|
||||||
88
vendor/github.com/DataDog/zstd/fastcover.c
generated
vendored
88
vendor/github.com/DataDog/zstd/fastcover.c
generated
vendored
@@ -1,3 +1,14 @@
|
|||||||
|
#ifndef USE_EXTERNAL_ZSTD
|
||||||
|
/*
|
||||||
|
* Copyright (c) Meta Platforms, Inc. and affiliates.
|
||||||
|
* All rights reserved.
|
||||||
|
*
|
||||||
|
* This source code is licensed under both the BSD-style license (found in the
|
||||||
|
* LICENSE file in the root directory of this source tree) and the GPLv2 (found
|
||||||
|
* in the COPYING file in the root directory of this source tree).
|
||||||
|
* You may select, at your option, one of the above-listed licenses.
|
||||||
|
*/
|
||||||
|
|
||||||
/*-*************************************
|
/*-*************************************
|
||||||
* Dependencies
|
* Dependencies
|
||||||
***************************************/
|
***************************************/
|
||||||
@@ -6,24 +17,33 @@
|
|||||||
#include <string.h> /* memset */
|
#include <string.h> /* memset */
|
||||||
#include <time.h> /* clock */
|
#include <time.h> /* clock */
|
||||||
|
|
||||||
|
#ifndef ZDICT_STATIC_LINKING_ONLY
|
||||||
|
# define ZDICT_STATIC_LINKING_ONLY
|
||||||
|
#endif
|
||||||
|
|
||||||
#include "mem.h" /* read */
|
#include "mem.h" /* read */
|
||||||
#include "pool.h"
|
#include "pool.h"
|
||||||
#include "threading.h"
|
#include "threading.h"
|
||||||
#include "cover.h"
|
|
||||||
#include "zstd_internal.h" /* includes zstd.h */
|
#include "zstd_internal.h" /* includes zstd.h */
|
||||||
#ifndef ZDICT_STATIC_LINKING_ONLY
|
#include "zstd_compress_internal.h" /* ZSTD_hash*() */
|
||||||
#define ZDICT_STATIC_LINKING_ONLY
|
|
||||||
#endif
|
|
||||||
#include "zdict.h"
|
#include "zdict.h"
|
||||||
|
#include "cover.h"
|
||||||
|
|
||||||
|
|
||||||
/*-*************************************
|
/*-*************************************
|
||||||
* Constants
|
* Constants
|
||||||
***************************************/
|
***************************************/
|
||||||
|
/**
|
||||||
|
* There are 32bit indexes used to ref samples, so limit samples size to 4GB
|
||||||
|
* on 64bit builds.
|
||||||
|
* For 32bit builds we choose 1 GB.
|
||||||
|
* Most 32bit platforms have 2GB user-mode addressable space and we allocate a large
|
||||||
|
* contiguous buffer, so 1GB is already a high limit.
|
||||||
|
*/
|
||||||
#define FASTCOVER_MAX_SAMPLES_SIZE (sizeof(size_t) == 8 ? ((unsigned)-1) : ((unsigned)1 GB))
|
#define FASTCOVER_MAX_SAMPLES_SIZE (sizeof(size_t) == 8 ? ((unsigned)-1) : ((unsigned)1 GB))
|
||||||
#define FASTCOVER_MAX_F 31
|
#define FASTCOVER_MAX_F 31
|
||||||
#define FASTCOVER_MAX_ACCEL 10
|
#define FASTCOVER_MAX_ACCEL 10
|
||||||
#define DEFAULT_SPLITPOINT 0.75
|
#define FASTCOVER_DEFAULT_SPLITPOINT 0.75
|
||||||
#define DEFAULT_F 20
|
#define DEFAULT_F 20
|
||||||
#define DEFAULT_ACCEL 1
|
#define DEFAULT_ACCEL 1
|
||||||
|
|
||||||
@@ -31,50 +51,50 @@
|
|||||||
/*-*************************************
|
/*-*************************************
|
||||||
* Console display
|
* Console display
|
||||||
***************************************/
|
***************************************/
|
||||||
static int g_displayLevel = 2;
|
#ifndef LOCALDISPLAYLEVEL
|
||||||
|
static int g_displayLevel = 0;
|
||||||
|
#endif
|
||||||
|
#undef DISPLAY
|
||||||
#define DISPLAY(...) \
|
#define DISPLAY(...) \
|
||||||
{ \
|
{ \
|
||||||
fprintf(stderr, __VA_ARGS__); \
|
fprintf(stderr, __VA_ARGS__); \
|
||||||
fflush(stderr); \
|
fflush(stderr); \
|
||||||
}
|
}
|
||||||
|
#undef LOCALDISPLAYLEVEL
|
||||||
#define LOCALDISPLAYLEVEL(displayLevel, l, ...) \
|
#define LOCALDISPLAYLEVEL(displayLevel, l, ...) \
|
||||||
if (displayLevel >= l) { \
|
if (displayLevel >= l) { \
|
||||||
DISPLAY(__VA_ARGS__); \
|
DISPLAY(__VA_ARGS__); \
|
||||||
} /* 0 : no display; 1: errors; 2: default; 3: details; 4: debug */
|
} /* 0 : no display; 1: errors; 2: default; 3: details; 4: debug */
|
||||||
|
#undef DISPLAYLEVEL
|
||||||
#define DISPLAYLEVEL(l, ...) LOCALDISPLAYLEVEL(g_displayLevel, l, __VA_ARGS__)
|
#define DISPLAYLEVEL(l, ...) LOCALDISPLAYLEVEL(g_displayLevel, l, __VA_ARGS__)
|
||||||
|
|
||||||
|
#ifndef LOCALDISPLAYUPDATE
|
||||||
|
static const clock_t g_refreshRate = CLOCKS_PER_SEC * 15 / 100;
|
||||||
|
static clock_t g_time = 0;
|
||||||
|
#endif
|
||||||
|
#undef LOCALDISPLAYUPDATE
|
||||||
#define LOCALDISPLAYUPDATE(displayLevel, l, ...) \
|
#define LOCALDISPLAYUPDATE(displayLevel, l, ...) \
|
||||||
if (displayLevel >= l) { \
|
if (displayLevel >= l) { \
|
||||||
if ((clock() - g_time > refreshRate) || (displayLevel >= 4)) { \
|
if ((clock() - g_time > g_refreshRate) || (displayLevel >= 4)) { \
|
||||||
g_time = clock(); \
|
g_time = clock(); \
|
||||||
DISPLAY(__VA_ARGS__); \
|
DISPLAY(__VA_ARGS__); \
|
||||||
} \
|
} \
|
||||||
}
|
}
|
||||||
|
#undef DISPLAYUPDATE
|
||||||
#define DISPLAYUPDATE(l, ...) LOCALDISPLAYUPDATE(g_displayLevel, l, __VA_ARGS__)
|
#define DISPLAYUPDATE(l, ...) LOCALDISPLAYUPDATE(g_displayLevel, l, __VA_ARGS__)
|
||||||
static const clock_t refreshRate = CLOCKS_PER_SEC * 15 / 100;
|
|
||||||
static clock_t g_time = 0;
|
|
||||||
|
|
||||||
|
|
||||||
/*-*************************************
|
/*-*************************************
|
||||||
* Hash Functions
|
* Hash Functions
|
||||||
***************************************/
|
***************************************/
|
||||||
static const U64 prime6bytes = 227718039650203ULL;
|
|
||||||
static size_t ZSTD_hash6(U64 u, U32 h) { return (size_t)(((u << (64-48)) * prime6bytes) >> (64-h)) ; }
|
|
||||||
static size_t ZSTD_hash6Ptr(const void* p, U32 h) { return ZSTD_hash6(MEM_readLE64(p), h); }
|
|
||||||
|
|
||||||
static const U64 prime8bytes = 0xCF1BBCDCB7A56463ULL;
|
|
||||||
static size_t ZSTD_hash8(U64 u, U32 h) { return (size_t)(((u) * prime8bytes) >> (64-h)) ; }
|
|
||||||
static size_t ZSTD_hash8Ptr(const void* p, U32 h) { return ZSTD_hash8(MEM_readLE64(p), h); }
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Hash the d-byte value pointed to by p and mod 2^f
|
* Hash the d-byte value pointed to by p and mod 2^f into the frequency vector
|
||||||
*/
|
*/
|
||||||
static size_t FASTCOVER_hashPtrToIndex(const void* p, U32 h, unsigned d) {
|
static size_t FASTCOVER_hashPtrToIndex(const void* p, U32 f, unsigned d) {
|
||||||
if (d == 6) {
|
if (d == 6) {
|
||||||
return ZSTD_hash6Ptr(p, h) & ((1 << h) - 1);
|
return ZSTD_hash6Ptr(p, f);
|
||||||
}
|
}
|
||||||
return ZSTD_hash8Ptr(p, h) & ((1 << h) - 1);
|
return ZSTD_hash8Ptr(p, f);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -285,7 +305,7 @@ FASTCOVER_computeFrequency(U32* freqs, const FASTCOVER_ctx_t* ctx)
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Prepare a context for dictionary building.
|
* Prepare a context for dictionary building.
|
||||||
* The context is only dependent on the parameter `d` and can used multiple
|
* The context is only dependent on the parameter `d` and can be used multiple
|
||||||
* times.
|
* times.
|
||||||
* Returns 0 on success or error code on error.
|
* Returns 0 on success or error code on error.
|
||||||
* The context must be destroyed with `FASTCOVER_ctx_destroy()`.
|
* The context must be destroyed with `FASTCOVER_ctx_destroy()`.
|
||||||
@@ -451,20 +471,20 @@ typedef struct FASTCOVER_tryParameters_data_s {
|
|||||||
* This function is thread safe if zstd is compiled with multithreaded support.
|
* This function is thread safe if zstd is compiled with multithreaded support.
|
||||||
* It takes its parameters as an *OWNING* opaque pointer to support threading.
|
* It takes its parameters as an *OWNING* opaque pointer to support threading.
|
||||||
*/
|
*/
|
||||||
static void FASTCOVER_tryParameters(void *opaque)
|
static void FASTCOVER_tryParameters(void* opaque)
|
||||||
{
|
{
|
||||||
/* Save parameters as local variables */
|
/* Save parameters as local variables */
|
||||||
FASTCOVER_tryParameters_data_t *const data = (FASTCOVER_tryParameters_data_t *)opaque;
|
FASTCOVER_tryParameters_data_t *const data = (FASTCOVER_tryParameters_data_t*)opaque;
|
||||||
const FASTCOVER_ctx_t *const ctx = data->ctx;
|
const FASTCOVER_ctx_t *const ctx = data->ctx;
|
||||||
const ZDICT_cover_params_t parameters = data->parameters;
|
const ZDICT_cover_params_t parameters = data->parameters;
|
||||||
size_t dictBufferCapacity = data->dictBufferCapacity;
|
size_t dictBufferCapacity = data->dictBufferCapacity;
|
||||||
size_t totalCompressedSize = ERROR(GENERIC);
|
size_t totalCompressedSize = ERROR(GENERIC);
|
||||||
/* Initialize array to keep track of frequency of dmer within activeSegment */
|
/* Initialize array to keep track of frequency of dmer within activeSegment */
|
||||||
U16* segmentFreqs = (U16 *)calloc(((U64)1 << ctx->f), sizeof(U16));
|
U16* segmentFreqs = (U16*)calloc(((U64)1 << ctx->f), sizeof(U16));
|
||||||
/* Allocate space for hash table, dict, and freqs */
|
/* Allocate space for hash table, dict, and freqs */
|
||||||
BYTE *const dict = (BYTE * const)malloc(dictBufferCapacity);
|
BYTE *const dict = (BYTE*)malloc(dictBufferCapacity);
|
||||||
COVER_dictSelection_t selection = COVER_dictSelectionError(ERROR(GENERIC));
|
COVER_dictSelection_t selection = COVER_dictSelectionError(ERROR(GENERIC));
|
||||||
U32 *freqs = (U32*) malloc(((U64)1 << ctx->f) * sizeof(U32));
|
U32* freqs = (U32*) malloc(((U64)1 << ctx->f) * sizeof(U32));
|
||||||
if (!segmentFreqs || !dict || !freqs) {
|
if (!segmentFreqs || !dict || !freqs) {
|
||||||
DISPLAYLEVEL(1, "Failed to allocate buffers: out of memory\n");
|
DISPLAYLEVEL(1, "Failed to allocate buffers: out of memory\n");
|
||||||
goto _cleanup;
|
goto _cleanup;
|
||||||
@@ -476,7 +496,7 @@ static void FASTCOVER_tryParameters(void *opaque)
|
|||||||
parameters, segmentFreqs);
|
parameters, segmentFreqs);
|
||||||
|
|
||||||
const unsigned nbFinalizeSamples = (unsigned)(ctx->nbTrainSamples * ctx->accelParams.finalize / 100);
|
const unsigned nbFinalizeSamples = (unsigned)(ctx->nbTrainSamples * ctx->accelParams.finalize / 100);
|
||||||
selection = COVER_selectDict(dict + tail, dictBufferCapacity - tail,
|
selection = COVER_selectDict(dict + tail, dictBufferCapacity, dictBufferCapacity - tail,
|
||||||
ctx->samples, ctx->samplesSizes, nbFinalizeSamples, ctx->nbTrainSamples, ctx->nbSamples, parameters, ctx->offsets,
|
ctx->samples, ctx->samplesSizes, nbFinalizeSamples, ctx->nbTrainSamples, ctx->nbSamples, parameters, ctx->offsets,
|
||||||
totalCompressedSize);
|
totalCompressedSize);
|
||||||
|
|
||||||
@@ -537,7 +557,7 @@ ZDICT_trainFromBuffer_fastCover(void* dictBuffer, size_t dictBufferCapacity,
|
|||||||
ZDICT_cover_params_t coverParams;
|
ZDICT_cover_params_t coverParams;
|
||||||
FASTCOVER_accel_t accelParams;
|
FASTCOVER_accel_t accelParams;
|
||||||
/* Initialize global data */
|
/* Initialize global data */
|
||||||
g_displayLevel = parameters.zParams.notificationLevel;
|
g_displayLevel = (int)parameters.zParams.notificationLevel;
|
||||||
/* Assign splitPoint and f if not provided */
|
/* Assign splitPoint and f if not provided */
|
||||||
parameters.splitPoint = 1.0;
|
parameters.splitPoint = 1.0;
|
||||||
parameters.f = parameters.f == 0 ? DEFAULT_F : parameters.f;
|
parameters.f = parameters.f == 0 ? DEFAULT_F : parameters.f;
|
||||||
@@ -607,7 +627,7 @@ ZDICT_optimizeTrainFromBuffer_fastCover(
|
|||||||
/* constants */
|
/* constants */
|
||||||
const unsigned nbThreads = parameters->nbThreads;
|
const unsigned nbThreads = parameters->nbThreads;
|
||||||
const double splitPoint =
|
const double splitPoint =
|
||||||
parameters->splitPoint <= 0.0 ? DEFAULT_SPLITPOINT : parameters->splitPoint;
|
parameters->splitPoint <= 0.0 ? FASTCOVER_DEFAULT_SPLITPOINT : parameters->splitPoint;
|
||||||
const unsigned kMinD = parameters->d == 0 ? 6 : parameters->d;
|
const unsigned kMinD = parameters->d == 0 ? 6 : parameters->d;
|
||||||
const unsigned kMaxD = parameters->d == 0 ? 8 : parameters->d;
|
const unsigned kMaxD = parameters->d == 0 ? 8 : parameters->d;
|
||||||
const unsigned kMinK = parameters->k == 0 ? 50 : parameters->k;
|
const unsigned kMinK = parameters->k == 0 ? 50 : parameters->k;
|
||||||
@@ -620,7 +640,7 @@ ZDICT_optimizeTrainFromBuffer_fastCover(
|
|||||||
const unsigned accel = parameters->accel == 0 ? DEFAULT_ACCEL : parameters->accel;
|
const unsigned accel = parameters->accel == 0 ? DEFAULT_ACCEL : parameters->accel;
|
||||||
const unsigned shrinkDict = 0;
|
const unsigned shrinkDict = 0;
|
||||||
/* Local variables */
|
/* Local variables */
|
||||||
const int displayLevel = parameters->zParams.notificationLevel;
|
const int displayLevel = (int)parameters->zParams.notificationLevel;
|
||||||
unsigned iteration = 1;
|
unsigned iteration = 1;
|
||||||
unsigned d;
|
unsigned d;
|
||||||
unsigned k;
|
unsigned k;
|
||||||
@@ -704,7 +724,7 @@ ZDICT_optimizeTrainFromBuffer_fastCover(
|
|||||||
data->parameters.splitPoint = splitPoint;
|
data->parameters.splitPoint = splitPoint;
|
||||||
data->parameters.steps = kSteps;
|
data->parameters.steps = kSteps;
|
||||||
data->parameters.shrinkDict = shrinkDict;
|
data->parameters.shrinkDict = shrinkDict;
|
||||||
data->parameters.zParams.notificationLevel = g_displayLevel;
|
data->parameters.zParams.notificationLevel = (unsigned)g_displayLevel;
|
||||||
/* Check the parameters */
|
/* Check the parameters */
|
||||||
if (!FASTCOVER_checkParameters(data->parameters, dictBufferCapacity,
|
if (!FASTCOVER_checkParameters(data->parameters, dictBufferCapacity,
|
||||||
data->ctx->f, accel)) {
|
data->ctx->f, accel)) {
|
||||||
@@ -745,3 +765,5 @@ ZDICT_optimizeTrainFromBuffer_fastCover(
|
|||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#endif /* USE_EXTERNAL_ZSTD */
|
||||||
|
|||||||
166
vendor/github.com/DataDog/zstd/fse.h
generated
vendored
166
vendor/github.com/DataDog/zstd/fse.h
generated
vendored
@@ -1,35 +1,16 @@
|
|||||||
|
#ifndef USE_EXTERNAL_ZSTD
|
||||||
/* ******************************************************************
|
/* ******************************************************************
|
||||||
FSE : Finite State Entropy codec
|
* FSE : Finite State Entropy codec
|
||||||
Public Prototypes declaration
|
* Public Prototypes declaration
|
||||||
Copyright (C) 2013-2016, Yann Collet.
|
* Copyright (c) Meta Platforms, Inc. and affiliates.
|
||||||
|
*
|
||||||
BSD 2-Clause License (http://www.opensource.org/licenses/bsd-license.php)
|
* You can contact the author at :
|
||||||
|
* - Source repository : https://github.com/Cyan4973/FiniteStateEntropy
|
||||||
Redistribution and use in source and binary forms, with or without
|
*
|
||||||
modification, are permitted provided that the following conditions are
|
* This source code is licensed under both the BSD-style license (found in the
|
||||||
met:
|
* LICENSE file in the root directory of this source tree) and the GPLv2 (found
|
||||||
|
* in the COPYING file in the root directory of this source tree).
|
||||||
* Redistributions of source code must retain the above copyright
|
* You may select, at your option, one of the above-listed licenses.
|
||||||
notice, this list of conditions and the following disclaimer.
|
|
||||||
* Redistributions in binary form must reproduce the above
|
|
||||||
copyright notice, this list of conditions and the following disclaimer
|
|
||||||
in the documentation and/or other materials provided with the
|
|
||||||
distribution.
|
|
||||||
|
|
||||||
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
|
||||||
"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
|
||||||
LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
|
||||||
A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
|
|
||||||
OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
|
||||||
SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
|
||||||
LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
|
||||||
DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
|
||||||
THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
|
||||||
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
|
||||||
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
|
||||||
|
|
||||||
You can contact the author at :
|
|
||||||
- Source repository : https://github.com/Cyan4973/FiniteStateEntropy
|
|
||||||
****************************************************************** */
|
****************************************************************** */
|
||||||
|
|
||||||
#if defined (__cplusplus)
|
#if defined (__cplusplus)
|
||||||
@@ -43,7 +24,7 @@ extern "C" {
|
|||||||
/*-*****************************************
|
/*-*****************************************
|
||||||
* Dependencies
|
* Dependencies
|
||||||
******************************************/
|
******************************************/
|
||||||
#include <stddef.h> /* size_t, ptrdiff_t */
|
#include "zstd_deps.h" /* size_t, ptrdiff_t */
|
||||||
|
|
||||||
|
|
||||||
/*-*****************************************
|
/*-*****************************************
|
||||||
@@ -73,34 +54,6 @@ extern "C" {
|
|||||||
FSE_PUBLIC_API unsigned FSE_versionNumber(void); /**< library version number; to be used when checking dll version */
|
FSE_PUBLIC_API unsigned FSE_versionNumber(void); /**< library version number; to be used when checking dll version */
|
||||||
|
|
||||||
|
|
||||||
/*-****************************************
|
|
||||||
* FSE simple functions
|
|
||||||
******************************************/
|
|
||||||
/*! FSE_compress() :
|
|
||||||
Compress content of buffer 'src', of size 'srcSize', into destination buffer 'dst'.
|
|
||||||
'dst' buffer must be already allocated. Compression runs faster is dstCapacity >= FSE_compressBound(srcSize).
|
|
||||||
@return : size of compressed data (<= dstCapacity).
|
|
||||||
Special values : if return == 0, srcData is not compressible => Nothing is stored within dst !!!
|
|
||||||
if return == 1, srcData is a single byte symbol * srcSize times. Use RLE compression instead.
|
|
||||||
if FSE_isError(return), compression failed (more details using FSE_getErrorName())
|
|
||||||
*/
|
|
||||||
FSE_PUBLIC_API size_t FSE_compress(void* dst, size_t dstCapacity,
|
|
||||||
const void* src, size_t srcSize);
|
|
||||||
|
|
||||||
/*! FSE_decompress():
|
|
||||||
Decompress FSE data from buffer 'cSrc', of size 'cSrcSize',
|
|
||||||
into already allocated destination buffer 'dst', of size 'dstCapacity'.
|
|
||||||
@return : size of regenerated data (<= maxDstSize),
|
|
||||||
or an error code, which can be tested using FSE_isError() .
|
|
||||||
|
|
||||||
** Important ** : FSE_decompress() does not decompress non-compressible nor RLE data !!!
|
|
||||||
Why ? : making this distinction requires a header.
|
|
||||||
Header management is intentionally delegated to the user layer, which can better manage special cases.
|
|
||||||
*/
|
|
||||||
FSE_PUBLIC_API size_t FSE_decompress(void* dst, size_t dstCapacity,
|
|
||||||
const void* cSrc, size_t cSrcSize);
|
|
||||||
|
|
||||||
|
|
||||||
/*-*****************************************
|
/*-*****************************************
|
||||||
* Tool functions
|
* Tool functions
|
||||||
******************************************/
|
******************************************/
|
||||||
@@ -111,20 +64,6 @@ FSE_PUBLIC_API unsigned FSE_isError(size_t code); /* tells if a return
|
|||||||
FSE_PUBLIC_API const char* FSE_getErrorName(size_t code); /* provides error code string (useful for debugging) */
|
FSE_PUBLIC_API const char* FSE_getErrorName(size_t code); /* provides error code string (useful for debugging) */
|
||||||
|
|
||||||
|
|
||||||
/*-*****************************************
|
|
||||||
* FSE advanced functions
|
|
||||||
******************************************/
|
|
||||||
/*! FSE_compress2() :
|
|
||||||
Same as FSE_compress(), but allows the selection of 'maxSymbolValue' and 'tableLog'
|
|
||||||
Both parameters can be defined as '0' to mean : use default value
|
|
||||||
@return : size of compressed data
|
|
||||||
Special values : if return == 0, srcData is not compressible => Nothing is stored within cSrc !!!
|
|
||||||
if return == 1, srcData is a single byte symbol * srcSize times. Use RLE compression.
|
|
||||||
if FSE_isError(return), it's an error code.
|
|
||||||
*/
|
|
||||||
FSE_PUBLIC_API size_t FSE_compress2 (void* dst, size_t dstSize, const void* src, size_t srcSize, unsigned maxSymbolValue, unsigned tableLog);
|
|
||||||
|
|
||||||
|
|
||||||
/*-*****************************************
|
/*-*****************************************
|
||||||
* FSE detailed API
|
* FSE detailed API
|
||||||
******************************************/
|
******************************************/
|
||||||
@@ -157,10 +96,16 @@ FSE_PUBLIC_API unsigned FSE_optimalTableLog(unsigned maxTableLog, size_t srcSize
|
|||||||
/*! FSE_normalizeCount():
|
/*! FSE_normalizeCount():
|
||||||
normalize counts so that sum(count[]) == Power_of_2 (2^tableLog)
|
normalize counts so that sum(count[]) == Power_of_2 (2^tableLog)
|
||||||
'normalizedCounter' is a table of short, of minimum size (maxSymbolValue+1).
|
'normalizedCounter' is a table of short, of minimum size (maxSymbolValue+1).
|
||||||
|
useLowProbCount is a boolean parameter which trades off compressed size for
|
||||||
|
faster header decoding. When it is set to 1, the compressed data will be slightly
|
||||||
|
smaller. And when it is set to 0, FSE_readNCount() and FSE_buildDTable() will be
|
||||||
|
faster. If you are compressing a small amount of data (< 2 KB) then useLowProbCount=0
|
||||||
|
is a good default, since header deserialization makes a big speed difference.
|
||||||
|
Otherwise, useLowProbCount=1 is a good default, since the speed difference is small.
|
||||||
@return : tableLog,
|
@return : tableLog,
|
||||||
or an errorCode, which can be tested using FSE_isError() */
|
or an errorCode, which can be tested using FSE_isError() */
|
||||||
FSE_PUBLIC_API size_t FSE_normalizeCount(short* normalizedCounter, unsigned tableLog,
|
FSE_PUBLIC_API size_t FSE_normalizeCount(short* normalizedCounter, unsigned tableLog,
|
||||||
const unsigned* count, size_t srcSize, unsigned maxSymbolValue);
|
const unsigned* count, size_t srcSize, unsigned maxSymbolValue, unsigned useLowProbCount);
|
||||||
|
|
||||||
/*! FSE_NCountWriteBound():
|
/*! FSE_NCountWriteBound():
|
||||||
Provides the maximum possible size of an FSE normalized table, given 'maxSymbolValue' and 'tableLog'.
|
Provides the maximum possible size of an FSE normalized table, given 'maxSymbolValue' and 'tableLog'.
|
||||||
@@ -178,8 +123,6 @@ FSE_PUBLIC_API size_t FSE_writeNCount (void* buffer, size_t bufferSize,
|
|||||||
/*! Constructor and Destructor of FSE_CTable.
|
/*! Constructor and Destructor of FSE_CTable.
|
||||||
Note that FSE_CTable size depends on 'tableLog' and 'maxSymbolValue' */
|
Note that FSE_CTable size depends on 'tableLog' and 'maxSymbolValue' */
|
||||||
typedef unsigned FSE_CTable; /* don't allocate that. It's only meant to be more restrictive than void* */
|
typedef unsigned FSE_CTable; /* don't allocate that. It's only meant to be more restrictive than void* */
|
||||||
FSE_PUBLIC_API FSE_CTable* FSE_createCTable (unsigned maxSymbolValue, unsigned tableLog);
|
|
||||||
FSE_PUBLIC_API void FSE_freeCTable (FSE_CTable* ct);
|
|
||||||
|
|
||||||
/*! FSE_buildCTable():
|
/*! FSE_buildCTable():
|
||||||
Builds `ct`, which must be already allocated, using FSE_createCTable().
|
Builds `ct`, which must be already allocated, using FSE_createCTable().
|
||||||
@@ -248,23 +191,14 @@ FSE_PUBLIC_API size_t FSE_readNCount (short* normalizedCounter,
|
|||||||
unsigned* maxSymbolValuePtr, unsigned* tableLogPtr,
|
unsigned* maxSymbolValuePtr, unsigned* tableLogPtr,
|
||||||
const void* rBuffer, size_t rBuffSize);
|
const void* rBuffer, size_t rBuffSize);
|
||||||
|
|
||||||
/*! Constructor and Destructor of FSE_DTable.
|
/*! FSE_readNCount_bmi2():
|
||||||
Note that its size depends on 'tableLog' */
|
* Same as FSE_readNCount() but pass bmi2=1 when your CPU supports BMI2 and 0 otherwise.
|
||||||
|
*/
|
||||||
|
FSE_PUBLIC_API size_t FSE_readNCount_bmi2(short* normalizedCounter,
|
||||||
|
unsigned* maxSymbolValuePtr, unsigned* tableLogPtr,
|
||||||
|
const void* rBuffer, size_t rBuffSize, int bmi2);
|
||||||
|
|
||||||
typedef unsigned FSE_DTable; /* don't allocate that. It's just a way to be more restrictive than void* */
|
typedef unsigned FSE_DTable; /* don't allocate that. It's just a way to be more restrictive than void* */
|
||||||
FSE_PUBLIC_API FSE_DTable* FSE_createDTable(unsigned tableLog);
|
|
||||||
FSE_PUBLIC_API void FSE_freeDTable(FSE_DTable* dt);
|
|
||||||
|
|
||||||
/*! FSE_buildDTable():
|
|
||||||
Builds 'dt', which must be already allocated, using FSE_createDTable().
|
|
||||||
return : 0, or an errorCode, which can be tested using FSE_isError() */
|
|
||||||
FSE_PUBLIC_API size_t FSE_buildDTable (FSE_DTable* dt, const short* normalizedCounter, unsigned maxSymbolValue, unsigned tableLog);
|
|
||||||
|
|
||||||
/*! FSE_decompress_usingDTable():
|
|
||||||
Decompress compressed source `cSrc` of size `cSrcSize` using `dt`
|
|
||||||
into `dst` which must be already allocated.
|
|
||||||
@return : size of regenerated data (necessarily <= `dstCapacity`),
|
|
||||||
or an errorCode, which can be tested using FSE_isError() */
|
|
||||||
FSE_PUBLIC_API size_t FSE_decompress_usingDTable(void* dst, size_t dstCapacity, const void* cSrc, size_t cSrcSize, const FSE_DTable* dt);
|
|
||||||
|
|
||||||
/*!
|
/*!
|
||||||
Tutorial :
|
Tutorial :
|
||||||
@@ -308,12 +242,12 @@ If there is an error, the function will return an error code, which can be teste
|
|||||||
*******************************************/
|
*******************************************/
|
||||||
/* FSE buffer bounds */
|
/* FSE buffer bounds */
|
||||||
#define FSE_NCOUNTBOUND 512
|
#define FSE_NCOUNTBOUND 512
|
||||||
#define FSE_BLOCKBOUND(size) (size + (size>>7) + 4 /* fse states */ + sizeof(size_t) /* bitContainer */)
|
#define FSE_BLOCKBOUND(size) ((size) + ((size)>>7) + 4 /* fse states */ + sizeof(size_t) /* bitContainer */)
|
||||||
#define FSE_COMPRESSBOUND(size) (FSE_NCOUNTBOUND + FSE_BLOCKBOUND(size)) /* Macro version, useful for static allocation */
|
#define FSE_COMPRESSBOUND(size) (FSE_NCOUNTBOUND + FSE_BLOCKBOUND(size)) /* Macro version, useful for static allocation */
|
||||||
|
|
||||||
/* It is possible to statically allocate FSE CTable/DTable as a table of FSE_CTable/FSE_DTable using below macros */
|
/* It is possible to statically allocate FSE CTable/DTable as a table of FSE_CTable/FSE_DTable using below macros */
|
||||||
#define FSE_CTABLE_SIZE_U32(maxTableLog, maxSymbolValue) (1 + (1<<(maxTableLog-1)) + ((maxSymbolValue+1)*2))
|
#define FSE_CTABLE_SIZE_U32(maxTableLog, maxSymbolValue) (1 + (1<<((maxTableLog)-1)) + (((maxSymbolValue)+1)*2))
|
||||||
#define FSE_DTABLE_SIZE_U32(maxTableLog) (1 + (1<<maxTableLog))
|
#define FSE_DTABLE_SIZE_U32(maxTableLog) (1 + (1<<(maxTableLog)))
|
||||||
|
|
||||||
/* or use the size to malloc() space directly. Pay attention to alignment restrictions though */
|
/* or use the size to malloc() space directly. Pay attention to alignment restrictions though */
|
||||||
#define FSE_CTABLE_SIZE(maxTableLog, maxSymbolValue) (FSE_CTABLE_SIZE_U32(maxTableLog, maxSymbolValue) * sizeof(FSE_CTable))
|
#define FSE_CTABLE_SIZE(maxTableLog, maxSymbolValue) (FSE_CTABLE_SIZE_U32(maxTableLog, maxSymbolValue) * sizeof(FSE_CTable))
|
||||||
@@ -327,33 +261,28 @@ If there is an error, the function will return an error code, which can be teste
|
|||||||
unsigned FSE_optimalTableLog_internal(unsigned maxTableLog, size_t srcSize, unsigned maxSymbolValue, unsigned minus);
|
unsigned FSE_optimalTableLog_internal(unsigned maxTableLog, size_t srcSize, unsigned maxSymbolValue, unsigned minus);
|
||||||
/**< same as FSE_optimalTableLog(), which used `minus==2` */
|
/**< same as FSE_optimalTableLog(), which used `minus==2` */
|
||||||
|
|
||||||
/* FSE_compress_wksp() :
|
|
||||||
* Same as FSE_compress2(), but using an externally allocated scratch buffer (`workSpace`).
|
|
||||||
* FSE_WKSP_SIZE_U32() provides the minimum size required for `workSpace` as a table of FSE_CTable.
|
|
||||||
*/
|
|
||||||
#define FSE_WKSP_SIZE_U32(maxTableLog, maxSymbolValue) ( FSE_CTABLE_SIZE_U32(maxTableLog, maxSymbolValue) + ((maxTableLog > 12) ? (1 << (maxTableLog - 2)) : 1024) )
|
|
||||||
size_t FSE_compress_wksp (void* dst, size_t dstSize, const void* src, size_t srcSize, unsigned maxSymbolValue, unsigned tableLog, void* workSpace, size_t wkspSize);
|
|
||||||
|
|
||||||
size_t FSE_buildCTable_raw (FSE_CTable* ct, unsigned nbBits);
|
|
||||||
/**< build a fake FSE_CTable, designed for a flat distribution, where each symbol uses nbBits */
|
|
||||||
|
|
||||||
size_t FSE_buildCTable_rle (FSE_CTable* ct, unsigned char symbolValue);
|
size_t FSE_buildCTable_rle (FSE_CTable* ct, unsigned char symbolValue);
|
||||||
/**< build a fake FSE_CTable, designed to compress always the same symbolValue */
|
/**< build a fake FSE_CTable, designed to compress always the same symbolValue */
|
||||||
|
|
||||||
/* FSE_buildCTable_wksp() :
|
/* FSE_buildCTable_wksp() :
|
||||||
* Same as FSE_buildCTable(), but using an externally allocated scratch buffer (`workSpace`).
|
* Same as FSE_buildCTable(), but using an externally allocated scratch buffer (`workSpace`).
|
||||||
* `wkspSize` must be >= `(1<<tableLog)`.
|
* `wkspSize` must be >= `FSE_BUILD_CTABLE_WORKSPACE_SIZE_U32(maxSymbolValue, tableLog)` of `unsigned`.
|
||||||
|
* See FSE_buildCTable_wksp() for breakdown of workspace usage.
|
||||||
*/
|
*/
|
||||||
|
#define FSE_BUILD_CTABLE_WORKSPACE_SIZE_U32(maxSymbolValue, tableLog) (((maxSymbolValue + 2) + (1ull << (tableLog)))/2 + sizeof(U64)/sizeof(U32) /* additional 8 bytes for potential table overwrite */)
|
||||||
|
#define FSE_BUILD_CTABLE_WORKSPACE_SIZE(maxSymbolValue, tableLog) (sizeof(unsigned) * FSE_BUILD_CTABLE_WORKSPACE_SIZE_U32(maxSymbolValue, tableLog))
|
||||||
size_t FSE_buildCTable_wksp(FSE_CTable* ct, const short* normalizedCounter, unsigned maxSymbolValue, unsigned tableLog, void* workSpace, size_t wkspSize);
|
size_t FSE_buildCTable_wksp(FSE_CTable* ct, const short* normalizedCounter, unsigned maxSymbolValue, unsigned tableLog, void* workSpace, size_t wkspSize);
|
||||||
|
|
||||||
size_t FSE_buildDTable_raw (FSE_DTable* dt, unsigned nbBits);
|
#define FSE_BUILD_DTABLE_WKSP_SIZE(maxTableLog, maxSymbolValue) (sizeof(short) * (maxSymbolValue + 1) + (1ULL << maxTableLog) + 8)
|
||||||
/**< build a fake FSE_DTable, designed to read a flat distribution where each symbol uses nbBits */
|
#define FSE_BUILD_DTABLE_WKSP_SIZE_U32(maxTableLog, maxSymbolValue) ((FSE_BUILD_DTABLE_WKSP_SIZE(maxTableLog, maxSymbolValue) + sizeof(unsigned) - 1) / sizeof(unsigned))
|
||||||
|
FSE_PUBLIC_API size_t FSE_buildDTable_wksp(FSE_DTable* dt, const short* normalizedCounter, unsigned maxSymbolValue, unsigned tableLog, void* workSpace, size_t wkspSize);
|
||||||
|
/**< Same as FSE_buildDTable(), using an externally allocated `workspace` produced with `FSE_BUILD_DTABLE_WKSP_SIZE_U32(maxSymbolValue)` */
|
||||||
|
|
||||||
size_t FSE_buildDTable_rle (FSE_DTable* dt, unsigned char symbolValue);
|
#define FSE_DECOMPRESS_WKSP_SIZE_U32(maxTableLog, maxSymbolValue) (FSE_DTABLE_SIZE_U32(maxTableLog) + 1 + FSE_BUILD_DTABLE_WKSP_SIZE_U32(maxTableLog, maxSymbolValue) + (FSE_MAX_SYMBOL_VALUE + 1) / 2 + 1)
|
||||||
/**< build a fake FSE_DTable, designed to always generate the same symbolValue */
|
#define FSE_DECOMPRESS_WKSP_SIZE(maxTableLog, maxSymbolValue) (FSE_DECOMPRESS_WKSP_SIZE_U32(maxTableLog, maxSymbolValue) * sizeof(unsigned))
|
||||||
|
size_t FSE_decompress_wksp_bmi2(void* dst, size_t dstCapacity, const void* cSrc, size_t cSrcSize, unsigned maxLog, void* workSpace, size_t wkspSize, int bmi2);
|
||||||
size_t FSE_decompress_wksp(void* dst, size_t dstCapacity, const void* cSrc, size_t cSrcSize, FSE_DTable* workSpace, unsigned maxLog);
|
/**< same as FSE_decompress(), using an externally allocated `workSpace` produced with `FSE_DECOMPRESS_WKSP_SIZE_U32(maxLog, maxSymbolValue)`.
|
||||||
/**< same as FSE_decompress(), using an externally allocated `workSpace` produced with `FSE_DTABLE_SIZE_U32(maxLog)` */
|
* Set bmi2 to 1 if your CPU supports BMI2 or 0 if it doesn't */
|
||||||
|
|
||||||
typedef enum {
|
typedef enum {
|
||||||
FSE_repeat_none, /**< Cannot use the previous table */
|
FSE_repeat_none, /**< Cannot use the previous table */
|
||||||
@@ -549,7 +478,7 @@ MEM_STATIC void FSE_flushCState(BIT_CStream_t* bitC, const FSE_CState_t* statePt
|
|||||||
|
|
||||||
/* FSE_getMaxNbBits() :
|
/* FSE_getMaxNbBits() :
|
||||||
* Approximate maximum cost of a symbol, in bits.
|
* Approximate maximum cost of a symbol, in bits.
|
||||||
* Fractional get rounded up (i.e : a symbol with a normalized frequency of 3 gives the same result as a frequency of 2)
|
* Fractional get rounded up (i.e. a symbol with a normalized frequency of 3 gives the same result as a frequency of 2)
|
||||||
* note 1 : assume symbolValue is valid (<= maxSymbolValue)
|
* note 1 : assume symbolValue is valid (<= maxSymbolValue)
|
||||||
* note 2 : if freq[symbolValue]==0, @return a fake cost of tableLog+1 bits */
|
* note 2 : if freq[symbolValue]==0, @return a fake cost of tableLog+1 bits */
|
||||||
MEM_STATIC U32 FSE_getMaxNbBits(const void* symbolTTPtr, U32 symbolValue)
|
MEM_STATIC U32 FSE_getMaxNbBits(const void* symbolTTPtr, U32 symbolValue)
|
||||||
@@ -664,6 +593,9 @@ MEM_STATIC unsigned FSE_endOfDState(const FSE_DState_t* DStatePtr)
|
|||||||
#ifndef FSE_DEFAULT_MEMORY_USAGE
|
#ifndef FSE_DEFAULT_MEMORY_USAGE
|
||||||
# define FSE_DEFAULT_MEMORY_USAGE 13
|
# define FSE_DEFAULT_MEMORY_USAGE 13
|
||||||
#endif
|
#endif
|
||||||
|
#if (FSE_DEFAULT_MEMORY_USAGE > FSE_MAX_MEMORY_USAGE)
|
||||||
|
# error "FSE_DEFAULT_MEMORY_USAGE must be <= FSE_MAX_MEMORY_USAGE"
|
||||||
|
#endif
|
||||||
|
|
||||||
/*!FSE_MAX_SYMBOL_VALUE :
|
/*!FSE_MAX_SYMBOL_VALUE :
|
||||||
* Maximum symbol value authorized.
|
* Maximum symbol value authorized.
|
||||||
@@ -697,7 +629,7 @@ MEM_STATIC unsigned FSE_endOfDState(const FSE_DState_t* DStatePtr)
|
|||||||
# error "FSE_MAX_TABLELOG > FSE_TABLELOG_ABSOLUTE_MAX is not supported"
|
# error "FSE_MAX_TABLELOG > FSE_TABLELOG_ABSOLUTE_MAX is not supported"
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#define FSE_TABLESTEP(tableSize) ((tableSize>>1) + (tableSize>>3) + 3)
|
#define FSE_TABLESTEP(tableSize) (((tableSize)>>1) + ((tableSize)>>3) + 3)
|
||||||
|
|
||||||
|
|
||||||
#endif /* FSE_STATIC_LINKING_ONLY */
|
#endif /* FSE_STATIC_LINKING_ONLY */
|
||||||
@@ -706,3 +638,5 @@ MEM_STATIC unsigned FSE_endOfDState(const FSE_DState_t* DStatePtr)
|
|||||||
#if defined (__cplusplus)
|
#if defined (__cplusplus)
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
#endif /* USE_EXTERNAL_ZSTD */
|
||||||
|
|||||||
286
vendor/github.com/DataDog/zstd/fse_compress.c
generated
vendored
286
vendor/github.com/DataDog/zstd/fse_compress.c
generated
vendored
@@ -1,42 +1,21 @@
|
|||||||
|
#ifndef USE_EXTERNAL_ZSTD
|
||||||
/* ******************************************************************
|
/* ******************************************************************
|
||||||
FSE : Finite State Entropy encoder
|
* FSE : Finite State Entropy encoder
|
||||||
Copyright (C) 2013-present, Yann Collet.
|
* Copyright (c) Meta Platforms, Inc. and affiliates.
|
||||||
|
*
|
||||||
BSD 2-Clause License (http://www.opensource.org/licenses/bsd-license.php)
|
* You can contact the author at :
|
||||||
|
* - FSE source repository : https://github.com/Cyan4973/FiniteStateEntropy
|
||||||
Redistribution and use in source and binary forms, with or without
|
* - Public forum : https://groups.google.com/forum/#!forum/lz4c
|
||||||
modification, are permitted provided that the following conditions are
|
*
|
||||||
met:
|
* This source code is licensed under both the BSD-style license (found in the
|
||||||
|
* LICENSE file in the root directory of this source tree) and the GPLv2 (found
|
||||||
* Redistributions of source code must retain the above copyright
|
* in the COPYING file in the root directory of this source tree).
|
||||||
notice, this list of conditions and the following disclaimer.
|
* You may select, at your option, one of the above-listed licenses.
|
||||||
* Redistributions in binary form must reproduce the above
|
|
||||||
copyright notice, this list of conditions and the following disclaimer
|
|
||||||
in the documentation and/or other materials provided with the
|
|
||||||
distribution.
|
|
||||||
|
|
||||||
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
|
||||||
"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
|
||||||
LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
|
||||||
A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
|
|
||||||
OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
|
||||||
SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
|
||||||
LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
|
||||||
DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
|
||||||
THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
|
||||||
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
|
||||||
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
|
||||||
|
|
||||||
You can contact the author at :
|
|
||||||
- FSE source repository : https://github.com/Cyan4973/FiniteStateEntropy
|
|
||||||
- Public forum : https://groups.google.com/forum/#!forum/lz4c
|
|
||||||
****************************************************************** */
|
****************************************************************** */
|
||||||
|
|
||||||
/* **************************************************************
|
/* **************************************************************
|
||||||
* Includes
|
* Includes
|
||||||
****************************************************************/
|
****************************************************************/
|
||||||
#include <stdlib.h> /* malloc, free, qsort */
|
|
||||||
#include <string.h> /* memcpy, memset */
|
|
||||||
#include "compiler.h"
|
#include "compiler.h"
|
||||||
#include "mem.h" /* U32, U16, etc. */
|
#include "mem.h" /* U32, U16, etc. */
|
||||||
#include "debug.h" /* assert, DEBUGLOG */
|
#include "debug.h" /* assert, DEBUGLOG */
|
||||||
@@ -45,6 +24,10 @@
|
|||||||
#define FSE_STATIC_LINKING_ONLY
|
#define FSE_STATIC_LINKING_ONLY
|
||||||
#include "fse.h"
|
#include "fse.h"
|
||||||
#include "error_private.h"
|
#include "error_private.h"
|
||||||
|
#define ZSTD_DEPS_NEED_MALLOC
|
||||||
|
#define ZSTD_DEPS_NEED_MATH64
|
||||||
|
#include "zstd_deps.h" /* ZSTD_malloc, ZSTD_free, ZSTD_memcpy, ZSTD_memset */
|
||||||
|
#include "bits.h" /* ZSTD_highbit32 */
|
||||||
|
|
||||||
|
|
||||||
/* **************************************************************
|
/* **************************************************************
|
||||||
@@ -94,41 +77,85 @@ size_t FSE_buildCTable_wksp(FSE_CTable* ct,
|
|||||||
void* const FSCT = ((U32*)ptr) + 1 /* header */ + (tableLog ? tableSize>>1 : 1) ;
|
void* const FSCT = ((U32*)ptr) + 1 /* header */ + (tableLog ? tableSize>>1 : 1) ;
|
||||||
FSE_symbolCompressionTransform* const symbolTT = (FSE_symbolCompressionTransform*) (FSCT);
|
FSE_symbolCompressionTransform* const symbolTT = (FSE_symbolCompressionTransform*) (FSCT);
|
||||||
U32 const step = FSE_TABLESTEP(tableSize);
|
U32 const step = FSE_TABLESTEP(tableSize);
|
||||||
U32 cumul[FSE_MAX_SYMBOL_VALUE+2];
|
U32 const maxSV1 = maxSymbolValue+1;
|
||||||
|
|
||||||
|
U16* cumul = (U16*)workSpace; /* size = maxSV1 */
|
||||||
|
FSE_FUNCTION_TYPE* const tableSymbol = (FSE_FUNCTION_TYPE*)(cumul + (maxSV1+1)); /* size = tableSize */
|
||||||
|
|
||||||
FSE_FUNCTION_TYPE* const tableSymbol = (FSE_FUNCTION_TYPE*)workSpace;
|
|
||||||
U32 highThreshold = tableSize-1;
|
U32 highThreshold = tableSize-1;
|
||||||
|
|
||||||
|
assert(((size_t)workSpace & 1) == 0); /* Must be 2 bytes-aligned */
|
||||||
|
if (FSE_BUILD_CTABLE_WORKSPACE_SIZE(maxSymbolValue, tableLog) > wkspSize) return ERROR(tableLog_tooLarge);
|
||||||
/* CTable header */
|
/* CTable header */
|
||||||
if (((size_t)1 << tableLog) * sizeof(FSE_FUNCTION_TYPE) > wkspSize) return ERROR(tableLog_tooLarge);
|
|
||||||
tableU16[-2] = (U16) tableLog;
|
tableU16[-2] = (U16) tableLog;
|
||||||
tableU16[-1] = (U16) maxSymbolValue;
|
tableU16[-1] = (U16) maxSymbolValue;
|
||||||
assert(tableLog < 16); /* required for threshold strategy to work */
|
assert(tableLog < 16); /* required for threshold strategy to work */
|
||||||
|
|
||||||
/* For explanations on how to distribute symbol values over the table :
|
/* For explanations on how to distribute symbol values over the table :
|
||||||
* http://fastcompression.blogspot.fr/2014/02/fse-distributing-symbol-values.html */
|
* https://fastcompression.blogspot.fr/2014/02/fse-distributing-symbol-values.html */
|
||||||
|
|
||||||
#ifdef __clang_analyzer__
|
#ifdef __clang_analyzer__
|
||||||
memset(tableSymbol, 0, sizeof(*tableSymbol) * tableSize); /* useless initialization, just to keep scan-build happy */
|
ZSTD_memset(tableSymbol, 0, sizeof(*tableSymbol) * tableSize); /* useless initialization, just to keep scan-build happy */
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
/* symbol start positions */
|
/* symbol start positions */
|
||||||
{ U32 u;
|
{ U32 u;
|
||||||
cumul[0] = 0;
|
cumul[0] = 0;
|
||||||
for (u=1; u <= maxSymbolValue+1; u++) {
|
for (u=1; u <= maxSV1; u++) {
|
||||||
if (normalizedCounter[u-1]==-1) { /* Low proba symbol */
|
if (normalizedCounter[u-1]==-1) { /* Low proba symbol */
|
||||||
cumul[u] = cumul[u-1] + 1;
|
cumul[u] = cumul[u-1] + 1;
|
||||||
tableSymbol[highThreshold--] = (FSE_FUNCTION_TYPE)(u-1);
|
tableSymbol[highThreshold--] = (FSE_FUNCTION_TYPE)(u-1);
|
||||||
} else {
|
} else {
|
||||||
cumul[u] = cumul[u-1] + normalizedCounter[u-1];
|
assert(normalizedCounter[u-1] >= 0);
|
||||||
|
cumul[u] = cumul[u-1] + (U16)normalizedCounter[u-1];
|
||||||
|
assert(cumul[u] >= cumul[u-1]); /* no overflow */
|
||||||
} }
|
} }
|
||||||
cumul[maxSymbolValue+1] = tableSize+1;
|
cumul[maxSV1] = (U16)(tableSize+1);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Spread symbols */
|
/* Spread symbols */
|
||||||
{ U32 position = 0;
|
if (highThreshold == tableSize - 1) {
|
||||||
|
/* Case for no low prob count symbols. Lay down 8 bytes at a time
|
||||||
|
* to reduce branch misses since we are operating on a small block
|
||||||
|
*/
|
||||||
|
BYTE* const spread = tableSymbol + tableSize; /* size = tableSize + 8 (may write beyond tableSize) */
|
||||||
|
{ U64 const add = 0x0101010101010101ull;
|
||||||
|
size_t pos = 0;
|
||||||
|
U64 sv = 0;
|
||||||
|
U32 s;
|
||||||
|
for (s=0; s<maxSV1; ++s, sv += add) {
|
||||||
|
int i;
|
||||||
|
int const n = normalizedCounter[s];
|
||||||
|
MEM_write64(spread + pos, sv);
|
||||||
|
for (i = 8; i < n; i += 8) {
|
||||||
|
MEM_write64(spread + pos + i, sv);
|
||||||
|
}
|
||||||
|
assert(n>=0);
|
||||||
|
pos += (size_t)n;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
/* Spread symbols across the table. Lack of lowprob symbols means that
|
||||||
|
* we don't need variable sized inner loop, so we can unroll the loop and
|
||||||
|
* reduce branch misses.
|
||||||
|
*/
|
||||||
|
{ size_t position = 0;
|
||||||
|
size_t s;
|
||||||
|
size_t const unroll = 2; /* Experimentally determined optimal unroll */
|
||||||
|
assert(tableSize % unroll == 0); /* FSE_MIN_TABLELOG is 5 */
|
||||||
|
for (s = 0; s < (size_t)tableSize; s += unroll) {
|
||||||
|
size_t u;
|
||||||
|
for (u = 0; u < unroll; ++u) {
|
||||||
|
size_t const uPosition = (position + (u * step)) & tableMask;
|
||||||
|
tableSymbol[uPosition] = spread[s + u];
|
||||||
|
}
|
||||||
|
position = (position + (unroll * step)) & tableMask;
|
||||||
|
}
|
||||||
|
assert(position == 0); /* Must have initialized all positions */
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
U32 position = 0;
|
||||||
U32 symbol;
|
U32 symbol;
|
||||||
for (symbol=0; symbol<=maxSymbolValue; symbol++) {
|
for (symbol=0; symbol<maxSV1; symbol++) {
|
||||||
int nbOccurrences;
|
int nbOccurrences;
|
||||||
int const freq = normalizedCounter[symbol];
|
int const freq = normalizedCounter[symbol];
|
||||||
for (nbOccurrences=0; nbOccurrences<freq; nbOccurrences++) {
|
for (nbOccurrences=0; nbOccurrences<freq; nbOccurrences++) {
|
||||||
@@ -137,7 +164,6 @@ size_t FSE_buildCTable_wksp(FSE_CTable* ct,
|
|||||||
while (position > highThreshold)
|
while (position > highThreshold)
|
||||||
position = (position + step) & tableMask; /* Low proba area */
|
position = (position + step) & tableMask; /* Low proba area */
|
||||||
} }
|
} }
|
||||||
|
|
||||||
assert(position==0); /* Must have initialized all positions */
|
assert(position==0); /* Must have initialized all positions */
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -161,16 +187,17 @@ size_t FSE_buildCTable_wksp(FSE_CTable* ct,
|
|||||||
case -1:
|
case -1:
|
||||||
case 1:
|
case 1:
|
||||||
symbolTT[s].deltaNbBits = (tableLog << 16) - (1<<tableLog);
|
symbolTT[s].deltaNbBits = (tableLog << 16) - (1<<tableLog);
|
||||||
symbolTT[s].deltaFindState = total - 1;
|
assert(total <= INT_MAX);
|
||||||
|
symbolTT[s].deltaFindState = (int)(total - 1);
|
||||||
total ++;
|
total ++;
|
||||||
break;
|
break;
|
||||||
default :
|
default :
|
||||||
{
|
assert(normalizedCounter[s] > 1);
|
||||||
U32 const maxBitsOut = tableLog - BIT_highbit32 (normalizedCounter[s]-1);
|
{ U32 const maxBitsOut = tableLog - ZSTD_highbit32 ((U32)normalizedCounter[s]-1);
|
||||||
U32 const minStatePlus = normalizedCounter[s] << maxBitsOut;
|
U32 const minStatePlus = (U32)normalizedCounter[s] << maxBitsOut;
|
||||||
symbolTT[s].deltaNbBits = (maxBitsOut << 16) - minStatePlus;
|
symbolTT[s].deltaNbBits = (maxBitsOut << 16) - minStatePlus;
|
||||||
symbolTT[s].deltaFindState = total - normalizedCounter[s];
|
symbolTT[s].deltaFindState = (int)(total - (unsigned)normalizedCounter[s]);
|
||||||
total += normalizedCounter[s];
|
total += (unsigned)normalizedCounter[s];
|
||||||
} } } }
|
} } } }
|
||||||
|
|
||||||
#if 0 /* debug : symbol costs */
|
#if 0 /* debug : symbol costs */
|
||||||
@@ -181,31 +208,26 @@ size_t FSE_buildCTable_wksp(FSE_CTable* ct,
|
|||||||
symbol, normalizedCounter[symbol],
|
symbol, normalizedCounter[symbol],
|
||||||
FSE_getMaxNbBits(symbolTT, symbol),
|
FSE_getMaxNbBits(symbolTT, symbol),
|
||||||
(double)FSE_bitCost(symbolTT, tableLog, symbol, 8) / 256);
|
(double)FSE_bitCost(symbolTT, tableLog, symbol, 8) / 256);
|
||||||
}
|
} }
|
||||||
}
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
size_t FSE_buildCTable(FSE_CTable* ct, const short* normalizedCounter, unsigned maxSymbolValue, unsigned tableLog)
|
|
||||||
{
|
|
||||||
FSE_FUNCTION_TYPE tableSymbol[FSE_MAX_TABLESIZE]; /* memset() is not necessary, even if static analyzer complain about it */
|
|
||||||
return FSE_buildCTable_wksp(ct, normalizedCounter, maxSymbolValue, tableLog, tableSymbol, sizeof(tableSymbol));
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
#ifndef FSE_COMMONDEFS_ONLY
|
#ifndef FSE_COMMONDEFS_ONLY
|
||||||
|
|
||||||
|
|
||||||
/*-**************************************************************
|
/*-**************************************************************
|
||||||
* FSE NCount encoding
|
* FSE NCount encoding
|
||||||
****************************************************************/
|
****************************************************************/
|
||||||
size_t FSE_NCountWriteBound(unsigned maxSymbolValue, unsigned tableLog)
|
size_t FSE_NCountWriteBound(unsigned maxSymbolValue, unsigned tableLog)
|
||||||
{
|
{
|
||||||
size_t const maxHeaderSize = (((maxSymbolValue+1) * tableLog) >> 3) + 3;
|
size_t const maxHeaderSize = (((maxSymbolValue+1) * tableLog
|
||||||
|
+ 4 /* bitCount initialized at 4 */
|
||||||
|
+ 2 /* first two symbols may use one additional bit each */) / 8)
|
||||||
|
+ 1 /* round up to whole nb bytes */
|
||||||
|
+ 2 /* additional two bytes for bitstream flush */;
|
||||||
return maxSymbolValue ? maxHeaderSize : FSE_NCOUNTBOUND; /* maxSymbolValue==0 ? use default */
|
return maxSymbolValue ? maxHeaderSize : FSE_NCOUNTBOUND; /* maxSymbolValue==0 ? use default */
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -322,21 +344,11 @@ size_t FSE_writeNCount (void* buffer, size_t bufferSize,
|
|||||||
* FSE Compression Code
|
* FSE Compression Code
|
||||||
****************************************************************/
|
****************************************************************/
|
||||||
|
|
||||||
FSE_CTable* FSE_createCTable (unsigned maxSymbolValue, unsigned tableLog)
|
|
||||||
{
|
|
||||||
size_t size;
|
|
||||||
if (tableLog > FSE_TABLELOG_ABSOLUTE_MAX) tableLog = FSE_TABLELOG_ABSOLUTE_MAX;
|
|
||||||
size = FSE_CTABLE_SIZE_U32 (tableLog, maxSymbolValue) * sizeof(U32);
|
|
||||||
return (FSE_CTable*)malloc(size);
|
|
||||||
}
|
|
||||||
|
|
||||||
void FSE_freeCTable (FSE_CTable* ct) { free(ct); }
|
|
||||||
|
|
||||||
/* provides the minimum logSize to safely represent a distribution */
|
/* provides the minimum logSize to safely represent a distribution */
|
||||||
static unsigned FSE_minTableLog(size_t srcSize, unsigned maxSymbolValue)
|
static unsigned FSE_minTableLog(size_t srcSize, unsigned maxSymbolValue)
|
||||||
{
|
{
|
||||||
U32 minBitsSrc = BIT_highbit32((U32)(srcSize)) + 1;
|
U32 minBitsSrc = ZSTD_highbit32((U32)(srcSize)) + 1;
|
||||||
U32 minBitsSymbols = BIT_highbit32(maxSymbolValue) + 2;
|
U32 minBitsSymbols = ZSTD_highbit32(maxSymbolValue) + 2;
|
||||||
U32 minBits = minBitsSrc < minBitsSymbols ? minBitsSrc : minBitsSymbols;
|
U32 minBits = minBitsSrc < minBitsSymbols ? minBitsSrc : minBitsSymbols;
|
||||||
assert(srcSize > 1); /* Not supported, RLE should be used instead */
|
assert(srcSize > 1); /* Not supported, RLE should be used instead */
|
||||||
return minBits;
|
return minBits;
|
||||||
@@ -344,7 +356,7 @@ static unsigned FSE_minTableLog(size_t srcSize, unsigned maxSymbolValue)
|
|||||||
|
|
||||||
unsigned FSE_optimalTableLog_internal(unsigned maxTableLog, size_t srcSize, unsigned maxSymbolValue, unsigned minus)
|
unsigned FSE_optimalTableLog_internal(unsigned maxTableLog, size_t srcSize, unsigned maxSymbolValue, unsigned minus)
|
||||||
{
|
{
|
||||||
U32 maxBitsSrc = BIT_highbit32((U32)(srcSize - 1)) - minus;
|
U32 maxBitsSrc = ZSTD_highbit32((U32)(srcSize - 1)) - minus;
|
||||||
U32 tableLog = maxTableLog;
|
U32 tableLog = maxTableLog;
|
||||||
U32 minBits = FSE_minTableLog(srcSize, maxSymbolValue);
|
U32 minBits = FSE_minTableLog(srcSize, maxSymbolValue);
|
||||||
assert(srcSize > 1); /* Not supported, RLE should be used instead */
|
assert(srcSize > 1); /* Not supported, RLE should be used instead */
|
||||||
@@ -361,11 +373,10 @@ unsigned FSE_optimalTableLog(unsigned maxTableLog, size_t srcSize, unsigned maxS
|
|||||||
return FSE_optimalTableLog_internal(maxTableLog, srcSize, maxSymbolValue, 2);
|
return FSE_optimalTableLog_internal(maxTableLog, srcSize, maxSymbolValue, 2);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/* Secondary normalization method.
|
/* Secondary normalization method.
|
||||||
To be used when primary method fails. */
|
To be used when primary method fails. */
|
||||||
|
|
||||||
static size_t FSE_normalizeM2(short* norm, U32 tableLog, const unsigned* count, size_t total, U32 maxSymbolValue)
|
static size_t FSE_normalizeM2(short* norm, U32 tableLog, const unsigned* count, size_t total, U32 maxSymbolValue, short lowProbCount)
|
||||||
{
|
{
|
||||||
short const NOT_YET_ASSIGNED = -2;
|
short const NOT_YET_ASSIGNED = -2;
|
||||||
U32 s;
|
U32 s;
|
||||||
@@ -382,7 +393,7 @@ static size_t FSE_normalizeM2(short* norm, U32 tableLog, const unsigned* count,
|
|||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
if (count[s] <= lowThreshold) {
|
if (count[s] <= lowThreshold) {
|
||||||
norm[s] = -1;
|
norm[s] = lowProbCount;
|
||||||
distributed++;
|
distributed++;
|
||||||
total -= count[s];
|
total -= count[s];
|
||||||
continue;
|
continue;
|
||||||
@@ -434,7 +445,7 @@ static size_t FSE_normalizeM2(short* norm, U32 tableLog, const unsigned* count,
|
|||||||
|
|
||||||
{ U64 const vStepLog = 62 - tableLog;
|
{ U64 const vStepLog = 62 - tableLog;
|
||||||
U64 const mid = (1ULL << (vStepLog-1)) - 1;
|
U64 const mid = (1ULL << (vStepLog-1)) - 1;
|
||||||
U64 const rStep = ((((U64)1<<vStepLog) * ToDistribute) + mid) / total; /* scale on remaining */
|
U64 const rStep = ZSTD_div64((((U64)1<<vStepLog) * ToDistribute) + mid, (U32)total); /* scale on remaining */
|
||||||
U64 tmpTotal = mid;
|
U64 tmpTotal = mid;
|
||||||
for (s=0; s<=maxSymbolValue; s++) {
|
for (s=0; s<=maxSymbolValue; s++) {
|
||||||
if (norm[s]==NOT_YET_ASSIGNED) {
|
if (norm[s]==NOT_YET_ASSIGNED) {
|
||||||
@@ -451,10 +462,9 @@ static size_t FSE_normalizeM2(short* norm, U32 tableLog, const unsigned* count,
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
size_t FSE_normalizeCount (short* normalizedCounter, unsigned tableLog,
|
size_t FSE_normalizeCount (short* normalizedCounter, unsigned tableLog,
|
||||||
const unsigned* count, size_t total,
|
const unsigned* count, size_t total,
|
||||||
unsigned maxSymbolValue)
|
unsigned maxSymbolValue, unsigned useLowProbCount)
|
||||||
{
|
{
|
||||||
/* Sanity checks */
|
/* Sanity checks */
|
||||||
if (tableLog==0) tableLog = FSE_DEFAULT_TABLELOG;
|
if (tableLog==0) tableLog = FSE_DEFAULT_TABLELOG;
|
||||||
@@ -463,8 +473,9 @@ size_t FSE_normalizeCount (short* normalizedCounter, unsigned tableLog,
|
|||||||
if (tableLog < FSE_minTableLog(total, maxSymbolValue)) return ERROR(GENERIC); /* Too small tableLog, compression potentially impossible */
|
if (tableLog < FSE_minTableLog(total, maxSymbolValue)) return ERROR(GENERIC); /* Too small tableLog, compression potentially impossible */
|
||||||
|
|
||||||
{ static U32 const rtbTable[] = { 0, 473195, 504333, 520860, 550000, 700000, 750000, 830000 };
|
{ static U32 const rtbTable[] = { 0, 473195, 504333, 520860, 550000, 700000, 750000, 830000 };
|
||||||
|
short const lowProbCount = useLowProbCount ? -1 : 1;
|
||||||
U64 const scale = 62 - tableLog;
|
U64 const scale = 62 - tableLog;
|
||||||
U64 const step = ((U64)1<<62) / total; /* <== here, one division ! */
|
U64 const step = ZSTD_div64((U64)1<<62, (U32)total); /* <== here, one division ! */
|
||||||
U64 const vStep = 1ULL<<(scale-20);
|
U64 const vStep = 1ULL<<(scale-20);
|
||||||
int stillToDistribute = 1<<tableLog;
|
int stillToDistribute = 1<<tableLog;
|
||||||
unsigned s;
|
unsigned s;
|
||||||
@@ -476,7 +487,7 @@ size_t FSE_normalizeCount (short* normalizedCounter, unsigned tableLog,
|
|||||||
if (count[s] == total) return 0; /* rle special case */
|
if (count[s] == total) return 0; /* rle special case */
|
||||||
if (count[s] == 0) { normalizedCounter[s]=0; continue; }
|
if (count[s] == 0) { normalizedCounter[s]=0; continue; }
|
||||||
if (count[s] <= lowThreshold) {
|
if (count[s] <= lowThreshold) {
|
||||||
normalizedCounter[s] = -1;
|
normalizedCounter[s] = lowProbCount;
|
||||||
stillToDistribute--;
|
stillToDistribute--;
|
||||||
} else {
|
} else {
|
||||||
short proba = (short)((count[s]*step) >> scale);
|
short proba = (short)((count[s]*step) >> scale);
|
||||||
@@ -490,7 +501,7 @@ size_t FSE_normalizeCount (short* normalizedCounter, unsigned tableLog,
|
|||||||
} }
|
} }
|
||||||
if (-stillToDistribute >= (normalizedCounter[largest] >> 1)) {
|
if (-stillToDistribute >= (normalizedCounter[largest] >> 1)) {
|
||||||
/* corner case, need another normalization method */
|
/* corner case, need another normalization method */
|
||||||
size_t const errorCode = FSE_normalizeM2(normalizedCounter, tableLog, count, total, maxSymbolValue);
|
size_t const errorCode = FSE_normalizeM2(normalizedCounter, tableLog, count, total, maxSymbolValue, lowProbCount);
|
||||||
if (FSE_isError(errorCode)) return errorCode;
|
if (FSE_isError(errorCode)) return errorCode;
|
||||||
}
|
}
|
||||||
else normalizedCounter[largest] += (short)stillToDistribute;
|
else normalizedCounter[largest] += (short)stillToDistribute;
|
||||||
@@ -513,40 +524,6 @@ size_t FSE_normalizeCount (short* normalizedCounter, unsigned tableLog,
|
|||||||
return tableLog;
|
return tableLog;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/* fake FSE_CTable, for raw (uncompressed) input */
|
|
||||||
size_t FSE_buildCTable_raw (FSE_CTable* ct, unsigned nbBits)
|
|
||||||
{
|
|
||||||
const unsigned tableSize = 1 << nbBits;
|
|
||||||
const unsigned tableMask = tableSize - 1;
|
|
||||||
const unsigned maxSymbolValue = tableMask;
|
|
||||||
void* const ptr = ct;
|
|
||||||
U16* const tableU16 = ( (U16*) ptr) + 2;
|
|
||||||
void* const FSCT = ((U32*)ptr) + 1 /* header */ + (tableSize>>1); /* assumption : tableLog >= 1 */
|
|
||||||
FSE_symbolCompressionTransform* const symbolTT = (FSE_symbolCompressionTransform*) (FSCT);
|
|
||||||
unsigned s;
|
|
||||||
|
|
||||||
/* Sanity checks */
|
|
||||||
if (nbBits < 1) return ERROR(GENERIC); /* min size */
|
|
||||||
|
|
||||||
/* header */
|
|
||||||
tableU16[-2] = (U16) nbBits;
|
|
||||||
tableU16[-1] = (U16) maxSymbolValue;
|
|
||||||
|
|
||||||
/* Build table */
|
|
||||||
for (s=0; s<tableSize; s++)
|
|
||||||
tableU16[s] = (U16)(tableSize + s);
|
|
||||||
|
|
||||||
/* Build Symbol Transformation Table */
|
|
||||||
{ const U32 deltaNbBits = (nbBits << 16) - (1 << nbBits);
|
|
||||||
for (s=0; s<=maxSymbolValue; s++) {
|
|
||||||
symbolTT[s].deltaNbBits = deltaNbBits;
|
|
||||||
symbolTT[s].deltaFindState = s-1;
|
|
||||||
} }
|
|
||||||
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
/* fake FSE_CTable, for rle input (always same symbol) */
|
/* fake FSE_CTable, for rle input (always same symbol) */
|
||||||
size_t FSE_buildCTable_rle (FSE_CTable* ct, BYTE symbolValue)
|
size_t FSE_buildCTable_rle (FSE_CTable* ct, BYTE symbolValue)
|
||||||
{
|
{
|
||||||
@@ -645,77 +622,6 @@ size_t FSE_compress_usingCTable (void* dst, size_t dstSize,
|
|||||||
|
|
||||||
size_t FSE_compressBound(size_t size) { return FSE_COMPRESSBOUND(size); }
|
size_t FSE_compressBound(size_t size) { return FSE_COMPRESSBOUND(size); }
|
||||||
|
|
||||||
#define CHECK_V_F(e, f) size_t const e = f; if (ERR_isError(e)) return e
|
|
||||||
#define CHECK_F(f) { CHECK_V_F(_var_err__, f); }
|
|
||||||
|
|
||||||
/* FSE_compress_wksp() :
|
|
||||||
* Same as FSE_compress2(), but using an externally allocated scratch buffer (`workSpace`).
|
|
||||||
* `wkspSize` size must be `(1<<tableLog)`.
|
|
||||||
*/
|
|
||||||
size_t FSE_compress_wksp (void* dst, size_t dstSize, const void* src, size_t srcSize, unsigned maxSymbolValue, unsigned tableLog, void* workSpace, size_t wkspSize)
|
|
||||||
{
|
|
||||||
BYTE* const ostart = (BYTE*) dst;
|
|
||||||
BYTE* op = ostart;
|
|
||||||
BYTE* const oend = ostart + dstSize;
|
|
||||||
|
|
||||||
unsigned count[FSE_MAX_SYMBOL_VALUE+1];
|
|
||||||
S16 norm[FSE_MAX_SYMBOL_VALUE+1];
|
|
||||||
FSE_CTable* CTable = (FSE_CTable*)workSpace;
|
|
||||||
size_t const CTableSize = FSE_CTABLE_SIZE_U32(tableLog, maxSymbolValue);
|
|
||||||
void* scratchBuffer = (void*)(CTable + CTableSize);
|
|
||||||
size_t const scratchBufferSize = wkspSize - (CTableSize * sizeof(FSE_CTable));
|
|
||||||
|
|
||||||
/* init conditions */
|
|
||||||
if (wkspSize < FSE_WKSP_SIZE_U32(tableLog, maxSymbolValue)) return ERROR(tableLog_tooLarge);
|
|
||||||
if (srcSize <= 1) return 0; /* Not compressible */
|
|
||||||
if (!maxSymbolValue) maxSymbolValue = FSE_MAX_SYMBOL_VALUE;
|
|
||||||
if (!tableLog) tableLog = FSE_DEFAULT_TABLELOG;
|
|
||||||
|
|
||||||
/* Scan input and build symbol stats */
|
|
||||||
{ CHECK_V_F(maxCount, HIST_count_wksp(count, &maxSymbolValue, src, srcSize, scratchBuffer, scratchBufferSize) );
|
|
||||||
if (maxCount == srcSize) return 1; /* only a single symbol in src : rle */
|
|
||||||
if (maxCount == 1) return 0; /* each symbol present maximum once => not compressible */
|
|
||||||
if (maxCount < (srcSize >> 7)) return 0; /* Heuristic : not compressible enough */
|
|
||||||
}
|
|
||||||
|
|
||||||
tableLog = FSE_optimalTableLog(tableLog, srcSize, maxSymbolValue);
|
|
||||||
CHECK_F( FSE_normalizeCount(norm, tableLog, count, srcSize, maxSymbolValue) );
|
|
||||||
|
|
||||||
/* Write table description header */
|
|
||||||
{ CHECK_V_F(nc_err, FSE_writeNCount(op, oend-op, norm, maxSymbolValue, tableLog) );
|
|
||||||
op += nc_err;
|
|
||||||
}
|
|
||||||
|
|
||||||
/* Compress */
|
|
||||||
CHECK_F( FSE_buildCTable_wksp(CTable, norm, maxSymbolValue, tableLog, scratchBuffer, scratchBufferSize) );
|
|
||||||
{ CHECK_V_F(cSize, FSE_compress_usingCTable(op, oend - op, src, srcSize, CTable) );
|
|
||||||
if (cSize == 0) return 0; /* not enough space for compressed data */
|
|
||||||
op += cSize;
|
|
||||||
}
|
|
||||||
|
|
||||||
/* check compressibility */
|
|
||||||
if ( (size_t)(op-ostart) >= srcSize-1 ) return 0;
|
|
||||||
|
|
||||||
return op-ostart;
|
|
||||||
}
|
|
||||||
|
|
||||||
typedef struct {
|
|
||||||
FSE_CTable CTable_max[FSE_CTABLE_SIZE_U32(FSE_MAX_TABLELOG, FSE_MAX_SYMBOL_VALUE)];
|
|
||||||
BYTE scratchBuffer[1 << FSE_MAX_TABLELOG];
|
|
||||||
} fseWkspMax_t;
|
|
||||||
|
|
||||||
size_t FSE_compress2 (void* dst, size_t dstCapacity, const void* src, size_t srcSize, unsigned maxSymbolValue, unsigned tableLog)
|
|
||||||
{
|
|
||||||
fseWkspMax_t scratchBuffer;
|
|
||||||
DEBUG_STATIC_ASSERT(sizeof(scratchBuffer) >= FSE_WKSP_SIZE_U32(FSE_MAX_TABLELOG, FSE_MAX_SYMBOL_VALUE)); /* compilation failures here means scratchBuffer is not large enough */
|
|
||||||
if (tableLog > FSE_MAX_TABLELOG) return ERROR(tableLog_tooLarge);
|
|
||||||
return FSE_compress_wksp(dst, dstCapacity, src, srcSize, maxSymbolValue, tableLog, &scratchBuffer, sizeof(scratchBuffer));
|
|
||||||
}
|
|
||||||
|
|
||||||
size_t FSE_compress (void* dst, size_t dstCapacity, const void* src, size_t srcSize)
|
|
||||||
{
|
|
||||||
return FSE_compress2(dst, dstCapacity, src, srcSize, FSE_MAX_SYMBOL_VALUE, FSE_DEFAULT_TABLELOG);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
#endif /* FSE_COMMONDEFS_ONLY */
|
#endif /* FSE_COMMONDEFS_ONLY */
|
||||||
|
|
||||||
|
#endif /* USE_EXTERNAL_ZSTD */
|
||||||
|
|||||||
263
vendor/github.com/DataDog/zstd/fse_decompress.c
generated
vendored
263
vendor/github.com/DataDog/zstd/fse_decompress.c
generated
vendored
@@ -1,48 +1,31 @@
|
|||||||
|
#ifndef USE_EXTERNAL_ZSTD
|
||||||
/* ******************************************************************
|
/* ******************************************************************
|
||||||
FSE : Finite State Entropy decoder
|
* FSE : Finite State Entropy decoder
|
||||||
Copyright (C) 2013-2015, Yann Collet.
|
* Copyright (c) Meta Platforms, Inc. and affiliates.
|
||||||
|
*
|
||||||
BSD 2-Clause License (http://www.opensource.org/licenses/bsd-license.php)
|
* You can contact the author at :
|
||||||
|
* - FSE source repository : https://github.com/Cyan4973/FiniteStateEntropy
|
||||||
Redistribution and use in source and binary forms, with or without
|
* - Public forum : https://groups.google.com/forum/#!forum/lz4c
|
||||||
modification, are permitted provided that the following conditions are
|
*
|
||||||
met:
|
* This source code is licensed under both the BSD-style license (found in the
|
||||||
|
* LICENSE file in the root directory of this source tree) and the GPLv2 (found
|
||||||
* Redistributions of source code must retain the above copyright
|
* in the COPYING file in the root directory of this source tree).
|
||||||
notice, this list of conditions and the following disclaimer.
|
* You may select, at your option, one of the above-listed licenses.
|
||||||
* Redistributions in binary form must reproduce the above
|
|
||||||
copyright notice, this list of conditions and the following disclaimer
|
|
||||||
in the documentation and/or other materials provided with the
|
|
||||||
distribution.
|
|
||||||
|
|
||||||
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
|
||||||
"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
|
||||||
LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
|
||||||
A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
|
|
||||||
OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
|
||||||
SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
|
||||||
LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
|
||||||
DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
|
||||||
THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
|
||||||
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
|
||||||
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
|
||||||
|
|
||||||
You can contact the author at :
|
|
||||||
- FSE source repository : https://github.com/Cyan4973/FiniteStateEntropy
|
|
||||||
- Public forum : https://groups.google.com/forum/#!forum/lz4c
|
|
||||||
****************************************************************** */
|
****************************************************************** */
|
||||||
|
|
||||||
|
|
||||||
/* **************************************************************
|
/* **************************************************************
|
||||||
* Includes
|
* Includes
|
||||||
****************************************************************/
|
****************************************************************/
|
||||||
#include <stdlib.h> /* malloc, free, qsort */
|
#include "debug.h" /* assert */
|
||||||
#include <string.h> /* memcpy, memset */
|
|
||||||
#include "bitstream.h"
|
#include "bitstream.h"
|
||||||
#include "compiler.h"
|
#include "compiler.h"
|
||||||
#define FSE_STATIC_LINKING_ONLY
|
#define FSE_STATIC_LINKING_ONLY
|
||||||
#include "fse.h"
|
#include "fse.h"
|
||||||
#include "error_private.h"
|
#include "error_private.h"
|
||||||
|
#define ZSTD_DEPS_NEED_MALLOC
|
||||||
|
#include "zstd_deps.h"
|
||||||
|
#include "bits.h" /* ZSTD_highbit32 */
|
||||||
|
|
||||||
|
|
||||||
/* **************************************************************
|
/* **************************************************************
|
||||||
@@ -51,11 +34,6 @@
|
|||||||
#define FSE_isError ERR_isError
|
#define FSE_isError ERR_isError
|
||||||
#define FSE_STATIC_ASSERT(c) DEBUG_STATIC_ASSERT(c) /* use only *after* variable declarations */
|
#define FSE_STATIC_ASSERT(c) DEBUG_STATIC_ASSERT(c) /* use only *after* variable declarations */
|
||||||
|
|
||||||
/* check and forward error code */
|
|
||||||
#ifndef CHECK_F
|
|
||||||
#define CHECK_F(f) { size_t const e = f; if (FSE_isError(e)) return e; }
|
|
||||||
#endif
|
|
||||||
|
|
||||||
|
|
||||||
/* **************************************************************
|
/* **************************************************************
|
||||||
* Templates
|
* Templates
|
||||||
@@ -79,30 +57,19 @@
|
|||||||
#define FSE_FUNCTION_NAME(X,Y) FSE_CAT(X,Y)
|
#define FSE_FUNCTION_NAME(X,Y) FSE_CAT(X,Y)
|
||||||
#define FSE_TYPE_NAME(X,Y) FSE_CAT(X,Y)
|
#define FSE_TYPE_NAME(X,Y) FSE_CAT(X,Y)
|
||||||
|
|
||||||
|
static size_t FSE_buildDTable_internal(FSE_DTable* dt, const short* normalizedCounter, unsigned maxSymbolValue, unsigned tableLog, void* workSpace, size_t wkspSize)
|
||||||
/* Function templates */
|
|
||||||
FSE_DTable* FSE_createDTable (unsigned tableLog)
|
|
||||||
{
|
|
||||||
if (tableLog > FSE_TABLELOG_ABSOLUTE_MAX) tableLog = FSE_TABLELOG_ABSOLUTE_MAX;
|
|
||||||
return (FSE_DTable*)malloc( FSE_DTABLE_SIZE_U32(tableLog) * sizeof (U32) );
|
|
||||||
}
|
|
||||||
|
|
||||||
void FSE_freeDTable (FSE_DTable* dt)
|
|
||||||
{
|
|
||||||
free(dt);
|
|
||||||
}
|
|
||||||
|
|
||||||
size_t FSE_buildDTable(FSE_DTable* dt, const short* normalizedCounter, unsigned maxSymbolValue, unsigned tableLog)
|
|
||||||
{
|
{
|
||||||
void* const tdPtr = dt+1; /* because *dt is unsigned, 32-bits aligned on 32-bits */
|
void* const tdPtr = dt+1; /* because *dt is unsigned, 32-bits aligned on 32-bits */
|
||||||
FSE_DECODE_TYPE* const tableDecode = (FSE_DECODE_TYPE*) (tdPtr);
|
FSE_DECODE_TYPE* const tableDecode = (FSE_DECODE_TYPE*) (tdPtr);
|
||||||
U16 symbolNext[FSE_MAX_SYMBOL_VALUE+1];
|
U16* symbolNext = (U16*)workSpace;
|
||||||
|
BYTE* spread = (BYTE*)(symbolNext + maxSymbolValue + 1);
|
||||||
|
|
||||||
U32 const maxSV1 = maxSymbolValue + 1;
|
U32 const maxSV1 = maxSymbolValue + 1;
|
||||||
U32 const tableSize = 1 << tableLog;
|
U32 const tableSize = 1 << tableLog;
|
||||||
U32 highThreshold = tableSize-1;
|
U32 highThreshold = tableSize-1;
|
||||||
|
|
||||||
/* Sanity Checks */
|
/* Sanity Checks */
|
||||||
|
if (FSE_BUILD_DTABLE_WKSP_SIZE(tableLog, maxSymbolValue) > wkspSize) return ERROR(maxSymbolValue_tooLarge);
|
||||||
if (maxSymbolValue > FSE_MAX_SYMBOL_VALUE) return ERROR(maxSymbolValue_tooLarge);
|
if (maxSymbolValue > FSE_MAX_SYMBOL_VALUE) return ERROR(maxSymbolValue_tooLarge);
|
||||||
if (tableLog > FSE_MAX_TABLELOG) return ERROR(tableLog_tooLarge);
|
if (tableLog > FSE_MAX_TABLELOG) return ERROR(tableLog_tooLarge);
|
||||||
|
|
||||||
@@ -120,11 +87,57 @@ size_t FSE_buildDTable(FSE_DTable* dt, const short* normalizedCounter, unsigned
|
|||||||
if (normalizedCounter[s] >= largeLimit) DTableH.fastMode=0;
|
if (normalizedCounter[s] >= largeLimit) DTableH.fastMode=0;
|
||||||
symbolNext[s] = normalizedCounter[s];
|
symbolNext[s] = normalizedCounter[s];
|
||||||
} } }
|
} } }
|
||||||
memcpy(dt, &DTableH, sizeof(DTableH));
|
ZSTD_memcpy(dt, &DTableH, sizeof(DTableH));
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Spread symbols */
|
/* Spread symbols */
|
||||||
{ U32 const tableMask = tableSize-1;
|
if (highThreshold == tableSize - 1) {
|
||||||
|
size_t const tableMask = tableSize-1;
|
||||||
|
size_t const step = FSE_TABLESTEP(tableSize);
|
||||||
|
/* First lay down the symbols in order.
|
||||||
|
* We use a uint64_t to lay down 8 bytes at a time. This reduces branch
|
||||||
|
* misses since small blocks generally have small table logs, so nearly
|
||||||
|
* all symbols have counts <= 8. We ensure we have 8 bytes at the end of
|
||||||
|
* our buffer to handle the over-write.
|
||||||
|
*/
|
||||||
|
{
|
||||||
|
U64 const add = 0x0101010101010101ull;
|
||||||
|
size_t pos = 0;
|
||||||
|
U64 sv = 0;
|
||||||
|
U32 s;
|
||||||
|
for (s=0; s<maxSV1; ++s, sv += add) {
|
||||||
|
int i;
|
||||||
|
int const n = normalizedCounter[s];
|
||||||
|
MEM_write64(spread + pos, sv);
|
||||||
|
for (i = 8; i < n; i += 8) {
|
||||||
|
MEM_write64(spread + pos + i, sv);
|
||||||
|
}
|
||||||
|
pos += n;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
/* Now we spread those positions across the table.
|
||||||
|
* The benefit of doing it in two stages is that we avoid the
|
||||||
|
* variable size inner loop, which caused lots of branch misses.
|
||||||
|
* Now we can run through all the positions without any branch misses.
|
||||||
|
* We unroll the loop twice, since that is what empirically worked best.
|
||||||
|
*/
|
||||||
|
{
|
||||||
|
size_t position = 0;
|
||||||
|
size_t s;
|
||||||
|
size_t const unroll = 2;
|
||||||
|
assert(tableSize % unroll == 0); /* FSE_MIN_TABLELOG is 5 */
|
||||||
|
for (s = 0; s < (size_t)tableSize; s += unroll) {
|
||||||
|
size_t u;
|
||||||
|
for (u = 0; u < unroll; ++u) {
|
||||||
|
size_t const uPosition = (position + (u * step)) & tableMask;
|
||||||
|
tableDecode[uPosition].symbol = spread[s + u];
|
||||||
|
}
|
||||||
|
position = (position + (unroll * step)) & tableMask;
|
||||||
|
}
|
||||||
|
assert(position == 0);
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
U32 const tableMask = tableSize-1;
|
||||||
U32 const step = FSE_TABLESTEP(tableSize);
|
U32 const step = FSE_TABLESTEP(tableSize);
|
||||||
U32 s, position = 0;
|
U32 s, position = 0;
|
||||||
for (s=0; s<maxSV1; s++) {
|
for (s=0; s<maxSV1; s++) {
|
||||||
@@ -142,62 +155,24 @@ size_t FSE_buildDTable(FSE_DTable* dt, const short* normalizedCounter, unsigned
|
|||||||
for (u=0; u<tableSize; u++) {
|
for (u=0; u<tableSize; u++) {
|
||||||
FSE_FUNCTION_TYPE const symbol = (FSE_FUNCTION_TYPE)(tableDecode[u].symbol);
|
FSE_FUNCTION_TYPE const symbol = (FSE_FUNCTION_TYPE)(tableDecode[u].symbol);
|
||||||
U32 const nextState = symbolNext[symbol]++;
|
U32 const nextState = symbolNext[symbol]++;
|
||||||
tableDecode[u].nbBits = (BYTE) (tableLog - BIT_highbit32(nextState) );
|
tableDecode[u].nbBits = (BYTE) (tableLog - ZSTD_highbit32(nextState) );
|
||||||
tableDecode[u].newState = (U16) ( (nextState << tableDecode[u].nbBits) - tableSize);
|
tableDecode[u].newState = (U16) ( (nextState << tableDecode[u].nbBits) - tableSize);
|
||||||
} }
|
} }
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
size_t FSE_buildDTable_wksp(FSE_DTable* dt, const short* normalizedCounter, unsigned maxSymbolValue, unsigned tableLog, void* workSpace, size_t wkspSize)
|
||||||
|
{
|
||||||
|
return FSE_buildDTable_internal(dt, normalizedCounter, maxSymbolValue, tableLog, workSpace, wkspSize);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
#ifndef FSE_COMMONDEFS_ONLY
|
#ifndef FSE_COMMONDEFS_ONLY
|
||||||
|
|
||||||
/*-*******************************************************
|
/*-*******************************************************
|
||||||
* Decompression (Byte symbols)
|
* Decompression (Byte symbols)
|
||||||
*********************************************************/
|
*********************************************************/
|
||||||
size_t FSE_buildDTable_rle (FSE_DTable* dt, BYTE symbolValue)
|
|
||||||
{
|
|
||||||
void* ptr = dt;
|
|
||||||
FSE_DTableHeader* const DTableH = (FSE_DTableHeader*)ptr;
|
|
||||||
void* dPtr = dt + 1;
|
|
||||||
FSE_decode_t* const cell = (FSE_decode_t*)dPtr;
|
|
||||||
|
|
||||||
DTableH->tableLog = 0;
|
|
||||||
DTableH->fastMode = 0;
|
|
||||||
|
|
||||||
cell->newState = 0;
|
|
||||||
cell->symbol = symbolValue;
|
|
||||||
cell->nbBits = 0;
|
|
||||||
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
size_t FSE_buildDTable_raw (FSE_DTable* dt, unsigned nbBits)
|
|
||||||
{
|
|
||||||
void* ptr = dt;
|
|
||||||
FSE_DTableHeader* const DTableH = (FSE_DTableHeader*)ptr;
|
|
||||||
void* dPtr = dt + 1;
|
|
||||||
FSE_decode_t* const dinfo = (FSE_decode_t*)dPtr;
|
|
||||||
const unsigned tableSize = 1 << nbBits;
|
|
||||||
const unsigned tableMask = tableSize - 1;
|
|
||||||
const unsigned maxSV1 = tableMask+1;
|
|
||||||
unsigned s;
|
|
||||||
|
|
||||||
/* Sanity checks */
|
|
||||||
if (nbBits < 1) return ERROR(GENERIC); /* min size */
|
|
||||||
|
|
||||||
/* Build Decoding Table */
|
|
||||||
DTableH->tableLog = (U16)nbBits;
|
|
||||||
DTableH->fastMode = 1;
|
|
||||||
for (s=0; s<maxSV1; s++) {
|
|
||||||
dinfo[s].newState = 0;
|
|
||||||
dinfo[s].symbol = (BYTE)s;
|
|
||||||
dinfo[s].nbBits = (BYTE)nbBits;
|
|
||||||
}
|
|
||||||
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
FORCE_INLINE_TEMPLATE size_t FSE_decompress_usingDTable_generic(
|
FORCE_INLINE_TEMPLATE size_t FSE_decompress_usingDTable_generic(
|
||||||
void* dst, size_t maxDstSize,
|
void* dst, size_t maxDstSize,
|
||||||
@@ -261,51 +236,79 @@ FORCE_INLINE_TEMPLATE size_t FSE_decompress_usingDTable_generic(
|
|||||||
return op-ostart;
|
return op-ostart;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
typedef struct {
|
||||||
|
short ncount[FSE_MAX_SYMBOL_VALUE + 1];
|
||||||
|
FSE_DTable dtable[1]; /* Dynamically sized */
|
||||||
|
} FSE_DecompressWksp;
|
||||||
|
|
||||||
size_t FSE_decompress_usingDTable(void* dst, size_t originalSize,
|
|
||||||
|
FORCE_INLINE_TEMPLATE size_t FSE_decompress_wksp_body(
|
||||||
|
void* dst, size_t dstCapacity,
|
||||||
const void* cSrc, size_t cSrcSize,
|
const void* cSrc, size_t cSrcSize,
|
||||||
const FSE_DTable* dt)
|
unsigned maxLog, void* workSpace, size_t wkspSize,
|
||||||
|
int bmi2)
|
||||||
{
|
{
|
||||||
const void* ptr = dt;
|
const BYTE* const istart = (const BYTE*)cSrc;
|
||||||
|
const BYTE* ip = istart;
|
||||||
|
unsigned tableLog;
|
||||||
|
unsigned maxSymbolValue = FSE_MAX_SYMBOL_VALUE;
|
||||||
|
FSE_DecompressWksp* const wksp = (FSE_DecompressWksp*)workSpace;
|
||||||
|
|
||||||
|
DEBUG_STATIC_ASSERT((FSE_MAX_SYMBOL_VALUE + 1) % 2 == 0);
|
||||||
|
if (wkspSize < sizeof(*wksp)) return ERROR(GENERIC);
|
||||||
|
|
||||||
|
/* normal FSE decoding mode */
|
||||||
|
{
|
||||||
|
size_t const NCountLength = FSE_readNCount_bmi2(wksp->ncount, &maxSymbolValue, &tableLog, istart, cSrcSize, bmi2);
|
||||||
|
if (FSE_isError(NCountLength)) return NCountLength;
|
||||||
|
if (tableLog > maxLog) return ERROR(tableLog_tooLarge);
|
||||||
|
assert(NCountLength <= cSrcSize);
|
||||||
|
ip += NCountLength;
|
||||||
|
cSrcSize -= NCountLength;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (FSE_DECOMPRESS_WKSP_SIZE(tableLog, maxSymbolValue) > wkspSize) return ERROR(tableLog_tooLarge);
|
||||||
|
assert(sizeof(*wksp) + FSE_DTABLE_SIZE(tableLog) <= wkspSize);
|
||||||
|
workSpace = (BYTE*)workSpace + sizeof(*wksp) + FSE_DTABLE_SIZE(tableLog);
|
||||||
|
wkspSize -= sizeof(*wksp) + FSE_DTABLE_SIZE(tableLog);
|
||||||
|
|
||||||
|
CHECK_F( FSE_buildDTable_internal(wksp->dtable, wksp->ncount, maxSymbolValue, tableLog, workSpace, wkspSize) );
|
||||||
|
|
||||||
|
{
|
||||||
|
const void* ptr = wksp->dtable;
|
||||||
const FSE_DTableHeader* DTableH = (const FSE_DTableHeader*)ptr;
|
const FSE_DTableHeader* DTableH = (const FSE_DTableHeader*)ptr;
|
||||||
const U32 fastMode = DTableH->fastMode;
|
const U32 fastMode = DTableH->fastMode;
|
||||||
|
|
||||||
/* select fast mode (static) */
|
/* select fast mode (static) */
|
||||||
if (fastMode) return FSE_decompress_usingDTable_generic(dst, originalSize, cSrc, cSrcSize, dt, 1);
|
if (fastMode) return FSE_decompress_usingDTable_generic(dst, dstCapacity, ip, cSrcSize, wksp->dtable, 1);
|
||||||
return FSE_decompress_usingDTable_generic(dst, originalSize, cSrc, cSrcSize, dt, 0);
|
return FSE_decompress_usingDTable_generic(dst, dstCapacity, ip, cSrcSize, wksp->dtable, 0);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* Avoids the FORCE_INLINE of the _body() function. */
|
||||||
size_t FSE_decompress_wksp(void* dst, size_t dstCapacity, const void* cSrc, size_t cSrcSize, FSE_DTable* workSpace, unsigned maxLog)
|
static size_t FSE_decompress_wksp_body_default(void* dst, size_t dstCapacity, const void* cSrc, size_t cSrcSize, unsigned maxLog, void* workSpace, size_t wkspSize)
|
||||||
{
|
{
|
||||||
const BYTE* const istart = (const BYTE*)cSrc;
|
return FSE_decompress_wksp_body(dst, dstCapacity, cSrc, cSrcSize, maxLog, workSpace, wkspSize, 0);
|
||||||
const BYTE* ip = istart;
|
|
||||||
short counting[FSE_MAX_SYMBOL_VALUE+1];
|
|
||||||
unsigned tableLog;
|
|
||||||
unsigned maxSymbolValue = FSE_MAX_SYMBOL_VALUE;
|
|
||||||
|
|
||||||
/* normal FSE decoding mode */
|
|
||||||
size_t const NCountLength = FSE_readNCount (counting, &maxSymbolValue, &tableLog, istart, cSrcSize);
|
|
||||||
if (FSE_isError(NCountLength)) return NCountLength;
|
|
||||||
//if (NCountLength >= cSrcSize) return ERROR(srcSize_wrong); /* too small input size; supposed to be already checked in NCountLength, only remaining case : NCountLength==cSrcSize */
|
|
||||||
if (tableLog > maxLog) return ERROR(tableLog_tooLarge);
|
|
||||||
ip += NCountLength;
|
|
||||||
cSrcSize -= NCountLength;
|
|
||||||
|
|
||||||
CHECK_F( FSE_buildDTable (workSpace, counting, maxSymbolValue, tableLog) );
|
|
||||||
|
|
||||||
return FSE_decompress_usingDTable (dst, dstCapacity, ip, cSrcSize, workSpace); /* always return, even if it is an error code */
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#if DYNAMIC_BMI2
|
||||||
typedef FSE_DTable DTable_max_t[FSE_DTABLE_SIZE_U32(FSE_MAX_TABLELOG)];
|
BMI2_TARGET_ATTRIBUTE static size_t FSE_decompress_wksp_body_bmi2(void* dst, size_t dstCapacity, const void* cSrc, size_t cSrcSize, unsigned maxLog, void* workSpace, size_t wkspSize)
|
||||||
|
|
||||||
size_t FSE_decompress(void* dst, size_t dstCapacity, const void* cSrc, size_t cSrcSize)
|
|
||||||
{
|
{
|
||||||
DTable_max_t dt; /* Static analyzer seems unable to understand this table will be properly initialized later */
|
return FSE_decompress_wksp_body(dst, dstCapacity, cSrc, cSrcSize, maxLog, workSpace, wkspSize, 1);
|
||||||
return FSE_decompress_wksp(dst, dstCapacity, cSrc, cSrcSize, dt, FSE_MAX_TABLELOG);
|
|
||||||
}
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
|
size_t FSE_decompress_wksp_bmi2(void* dst, size_t dstCapacity, const void* cSrc, size_t cSrcSize, unsigned maxLog, void* workSpace, size_t wkspSize, int bmi2)
|
||||||
|
{
|
||||||
|
#if DYNAMIC_BMI2
|
||||||
|
if (bmi2) {
|
||||||
|
return FSE_decompress_wksp_body_bmi2(dst, dstCapacity, cSrc, cSrcSize, maxLog, workSpace, wkspSize);
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
(void)bmi2;
|
||||||
|
return FSE_decompress_wksp_body_default(dst, dstCapacity, cSrc, cSrcSize, maxLog, workSpace, wkspSize);
|
||||||
|
}
|
||||||
|
|
||||||
#endif /* FSE_COMMONDEFS_ONLY */
|
#endif /* FSE_COMMONDEFS_ONLY */
|
||||||
|
|
||||||
|
#endif /* USE_EXTERNAL_ZSTD */
|
||||||
|
|||||||
99
vendor/github.com/DataDog/zstd/hist.c
generated
vendored
99
vendor/github.com/DataDog/zstd/hist.c
generated
vendored
@@ -1,36 +1,17 @@
|
|||||||
|
#ifndef USE_EXTERNAL_ZSTD
|
||||||
/* ******************************************************************
|
/* ******************************************************************
|
||||||
hist : Histogram functions
|
* hist : Histogram functions
|
||||||
part of Finite State Entropy project
|
* part of Finite State Entropy project
|
||||||
Copyright (C) 2013-present, Yann Collet.
|
* Copyright (c) Meta Platforms, Inc. and affiliates.
|
||||||
|
*
|
||||||
BSD 2-Clause License (http://www.opensource.org/licenses/bsd-license.php)
|
* You can contact the author at :
|
||||||
|
* - FSE source repository : https://github.com/Cyan4973/FiniteStateEntropy
|
||||||
Redistribution and use in source and binary forms, with or without
|
* - Public forum : https://groups.google.com/forum/#!forum/lz4c
|
||||||
modification, are permitted provided that the following conditions are
|
*
|
||||||
met:
|
* This source code is licensed under both the BSD-style license (found in the
|
||||||
|
* LICENSE file in the root directory of this source tree) and the GPLv2 (found
|
||||||
* Redistributions of source code must retain the above copyright
|
* in the COPYING file in the root directory of this source tree).
|
||||||
notice, this list of conditions and the following disclaimer.
|
* You may select, at your option, one of the above-listed licenses.
|
||||||
* Redistributions in binary form must reproduce the above
|
|
||||||
copyright notice, this list of conditions and the following disclaimer
|
|
||||||
in the documentation and/or other materials provided with the
|
|
||||||
distribution.
|
|
||||||
|
|
||||||
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
|
||||||
"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
|
||||||
LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
|
||||||
A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
|
|
||||||
OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
|
||||||
SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
|
||||||
LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
|
||||||
DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
|
||||||
THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
|
||||||
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
|
||||||
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
|
||||||
|
|
||||||
You can contact the author at :
|
|
||||||
- FSE source repository : https://github.com/Cyan4973/FiniteStateEntropy
|
|
||||||
- Public forum : https://groups.google.com/forum/#!forum/lz4c
|
|
||||||
****************************************************************** */
|
****************************************************************** */
|
||||||
|
|
||||||
/* --- dependencies --- */
|
/* --- dependencies --- */
|
||||||
@@ -54,7 +35,7 @@ unsigned HIST_count_simple(unsigned* count, unsigned* maxSymbolValuePtr,
|
|||||||
unsigned maxSymbolValue = *maxSymbolValuePtr;
|
unsigned maxSymbolValue = *maxSymbolValuePtr;
|
||||||
unsigned largestCount=0;
|
unsigned largestCount=0;
|
||||||
|
|
||||||
memset(count, 0, (maxSymbolValue+1) * sizeof(*count));
|
ZSTD_memset(count, 0, (maxSymbolValue+1) * sizeof(*count));
|
||||||
if (srcSize==0) { *maxSymbolValuePtr = 0; return 0; }
|
if (srcSize==0) { *maxSymbolValuePtr = 0; return 0; }
|
||||||
|
|
||||||
while (ip<end) {
|
while (ip<end) {
|
||||||
@@ -80,9 +61,9 @@ typedef enum { trustInput, checkMaxSymbolValue } HIST_checkInput_e;
|
|||||||
* this design makes better use of OoO cpus,
|
* this design makes better use of OoO cpus,
|
||||||
* and is noticeably faster when some values are heavily repeated.
|
* and is noticeably faster when some values are heavily repeated.
|
||||||
* But it needs some additional workspace for intermediate tables.
|
* But it needs some additional workspace for intermediate tables.
|
||||||
* `workSpace` size must be a table of size >= HIST_WKSP_SIZE_U32.
|
* `workSpace` must be a U32 table of size >= HIST_WKSP_SIZE_U32.
|
||||||
* @return : largest histogram frequency,
|
* @return : largest histogram frequency,
|
||||||
* or an error code (notably when histogram would be larger than *maxSymbolValuePtr). */
|
* or an error code (notably when histogram's alphabet is larger than *maxSymbolValuePtr) */
|
||||||
static size_t HIST_count_parallel_wksp(
|
static size_t HIST_count_parallel_wksp(
|
||||||
unsigned* count, unsigned* maxSymbolValuePtr,
|
unsigned* count, unsigned* maxSymbolValuePtr,
|
||||||
const void* source, size_t sourceSize,
|
const void* source, size_t sourceSize,
|
||||||
@@ -91,22 +72,21 @@ static size_t HIST_count_parallel_wksp(
|
|||||||
{
|
{
|
||||||
const BYTE* ip = (const BYTE*)source;
|
const BYTE* ip = (const BYTE*)source;
|
||||||
const BYTE* const iend = ip+sourceSize;
|
const BYTE* const iend = ip+sourceSize;
|
||||||
unsigned maxSymbolValue = *maxSymbolValuePtr;
|
size_t const countSize = (*maxSymbolValuePtr + 1) * sizeof(*count);
|
||||||
unsigned max=0;
|
unsigned max=0;
|
||||||
U32* const Counting1 = workSpace;
|
U32* const Counting1 = workSpace;
|
||||||
U32* const Counting2 = Counting1 + 256;
|
U32* const Counting2 = Counting1 + 256;
|
||||||
U32* const Counting3 = Counting2 + 256;
|
U32* const Counting3 = Counting2 + 256;
|
||||||
U32* const Counting4 = Counting3 + 256;
|
U32* const Counting4 = Counting3 + 256;
|
||||||
|
|
||||||
memset(workSpace, 0, 4*256*sizeof(unsigned));
|
|
||||||
|
|
||||||
/* safety checks */
|
/* safety checks */
|
||||||
|
assert(*maxSymbolValuePtr <= 255);
|
||||||
if (!sourceSize) {
|
if (!sourceSize) {
|
||||||
memset(count, 0, maxSymbolValue + 1);
|
ZSTD_memset(count, 0, countSize);
|
||||||
*maxSymbolValuePtr = 0;
|
*maxSymbolValuePtr = 0;
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
if (!maxSymbolValue) maxSymbolValue = 255; /* 0 == default */
|
ZSTD_memset(workSpace, 0, 4*256*sizeof(unsigned));
|
||||||
|
|
||||||
/* by stripes of 16 bytes */
|
/* by stripes of 16 bytes */
|
||||||
{ U32 cached = MEM_read32(ip); ip += 4;
|
{ U32 cached = MEM_read32(ip); ip += 4;
|
||||||
@@ -138,21 +118,18 @@ static size_t HIST_count_parallel_wksp(
|
|||||||
/* finish last symbols */
|
/* finish last symbols */
|
||||||
while (ip<iend) Counting1[*ip++]++;
|
while (ip<iend) Counting1[*ip++]++;
|
||||||
|
|
||||||
if (check) { /* verify stats will fit into destination table */
|
|
||||||
U32 s; for (s=255; s>maxSymbolValue; s--) {
|
|
||||||
Counting1[s] += Counting2[s] + Counting3[s] + Counting4[s];
|
|
||||||
if (Counting1[s]) return ERROR(maxSymbolValue_tooSmall);
|
|
||||||
} }
|
|
||||||
|
|
||||||
{ U32 s;
|
{ U32 s;
|
||||||
if (maxSymbolValue > 255) maxSymbolValue = 255;
|
for (s=0; s<256; s++) {
|
||||||
for (s=0; s<=maxSymbolValue; s++) {
|
Counting1[s] += Counting2[s] + Counting3[s] + Counting4[s];
|
||||||
count[s] = Counting1[s] + Counting2[s] + Counting3[s] + Counting4[s];
|
if (Counting1[s] > max) max = Counting1[s];
|
||||||
if (count[s] > max) max = count[s];
|
|
||||||
} }
|
} }
|
||||||
|
|
||||||
while (!count[maxSymbolValue]) maxSymbolValue--;
|
{ unsigned maxSymbolValue = 255;
|
||||||
|
while (!Counting1[maxSymbolValue]) maxSymbolValue--;
|
||||||
|
if (check && maxSymbolValue > *maxSymbolValuePtr) return ERROR(maxSymbolValue_tooSmall);
|
||||||
*maxSymbolValuePtr = maxSymbolValue;
|
*maxSymbolValuePtr = maxSymbolValue;
|
||||||
|
ZSTD_memmove(count, Counting1, countSize); /* in case count & Counting1 are overlapping */
|
||||||
|
}
|
||||||
return (size_t)max;
|
return (size_t)max;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -172,14 +149,6 @@ size_t HIST_countFast_wksp(unsigned* count, unsigned* maxSymbolValuePtr,
|
|||||||
return HIST_count_parallel_wksp(count, maxSymbolValuePtr, source, sourceSize, trustInput, (U32*)workSpace);
|
return HIST_count_parallel_wksp(count, maxSymbolValuePtr, source, sourceSize, trustInput, (U32*)workSpace);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* fast variant (unsafe : won't check if src contains values beyond count[] limit) */
|
|
||||||
size_t HIST_countFast(unsigned* count, unsigned* maxSymbolValuePtr,
|
|
||||||
const void* source, size_t sourceSize)
|
|
||||||
{
|
|
||||||
unsigned tmpCounters[HIST_WKSP_SIZE_U32];
|
|
||||||
return HIST_countFast_wksp(count, maxSymbolValuePtr, source, sourceSize, tmpCounters, sizeof(tmpCounters));
|
|
||||||
}
|
|
||||||
|
|
||||||
/* HIST_count_wksp() :
|
/* HIST_count_wksp() :
|
||||||
* Same as HIST_count(), but using an externally provided scratch buffer.
|
* Same as HIST_count(), but using an externally provided scratch buffer.
|
||||||
* `workSpace` size must be table of >= HIST_WKSP_SIZE_U32 unsigned */
|
* `workSpace` size must be table of >= HIST_WKSP_SIZE_U32 unsigned */
|
||||||
@@ -195,9 +164,21 @@ size_t HIST_count_wksp(unsigned* count, unsigned* maxSymbolValuePtr,
|
|||||||
return HIST_countFast_wksp(count, maxSymbolValuePtr, source, sourceSize, workSpace, workSpaceSize);
|
return HIST_countFast_wksp(count, maxSymbolValuePtr, source, sourceSize, workSpace, workSpaceSize);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#ifndef ZSTD_NO_UNUSED_FUNCTIONS
|
||||||
|
/* fast variant (unsafe : won't check if src contains values beyond count[] limit) */
|
||||||
|
size_t HIST_countFast(unsigned* count, unsigned* maxSymbolValuePtr,
|
||||||
|
const void* source, size_t sourceSize)
|
||||||
|
{
|
||||||
|
unsigned tmpCounters[HIST_WKSP_SIZE_U32];
|
||||||
|
return HIST_countFast_wksp(count, maxSymbolValuePtr, source, sourceSize, tmpCounters, sizeof(tmpCounters));
|
||||||
|
}
|
||||||
|
|
||||||
size_t HIST_count(unsigned* count, unsigned* maxSymbolValuePtr,
|
size_t HIST_count(unsigned* count, unsigned* maxSymbolValuePtr,
|
||||||
const void* src, size_t srcSize)
|
const void* src, size_t srcSize)
|
||||||
{
|
{
|
||||||
unsigned tmpCounters[HIST_WKSP_SIZE_U32];
|
unsigned tmpCounters[HIST_WKSP_SIZE_U32];
|
||||||
return HIST_count_wksp(count, maxSymbolValuePtr, src, srcSize, tmpCounters, sizeof(tmpCounters));
|
return HIST_count_wksp(count, maxSymbolValuePtr, src, srcSize, tmpCounters, sizeof(tmpCounters));
|
||||||
}
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#endif /* USE_EXTERNAL_ZSTD */
|
||||||
|
|||||||
49
vendor/github.com/DataDog/zstd/hist.h
generated
vendored
49
vendor/github.com/DataDog/zstd/hist.h
generated
vendored
@@ -1,40 +1,21 @@
|
|||||||
|
#ifndef USE_EXTERNAL_ZSTD
|
||||||
/* ******************************************************************
|
/* ******************************************************************
|
||||||
hist : Histogram functions
|
* hist : Histogram functions
|
||||||
part of Finite State Entropy project
|
* part of Finite State Entropy project
|
||||||
Copyright (C) 2013-present, Yann Collet.
|
* Copyright (c) Meta Platforms, Inc. and affiliates.
|
||||||
|
*
|
||||||
BSD 2-Clause License (http://www.opensource.org/licenses/bsd-license.php)
|
* You can contact the author at :
|
||||||
|
* - FSE source repository : https://github.com/Cyan4973/FiniteStateEntropy
|
||||||
Redistribution and use in source and binary forms, with or without
|
* - Public forum : https://groups.google.com/forum/#!forum/lz4c
|
||||||
modification, are permitted provided that the following conditions are
|
*
|
||||||
met:
|
* This source code is licensed under both the BSD-style license (found in the
|
||||||
|
* LICENSE file in the root directory of this source tree) and the GPLv2 (found
|
||||||
* Redistributions of source code must retain the above copyright
|
* in the COPYING file in the root directory of this source tree).
|
||||||
notice, this list of conditions and the following disclaimer.
|
* You may select, at your option, one of the above-listed licenses.
|
||||||
* Redistributions in binary form must reproduce the above
|
|
||||||
copyright notice, this list of conditions and the following disclaimer
|
|
||||||
in the documentation and/or other materials provided with the
|
|
||||||
distribution.
|
|
||||||
|
|
||||||
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
|
||||||
"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
|
||||||
LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
|
||||||
A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
|
|
||||||
OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
|
||||||
SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
|
||||||
LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
|
||||||
DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
|
||||||
THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
|
||||||
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
|
||||||
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
|
||||||
|
|
||||||
You can contact the author at :
|
|
||||||
- FSE source repository : https://github.com/Cyan4973/FiniteStateEntropy
|
|
||||||
- Public forum : https://groups.google.com/forum/#!forum/lz4c
|
|
||||||
****************************************************************** */
|
****************************************************************** */
|
||||||
|
|
||||||
/* --- dependencies --- */
|
/* --- dependencies --- */
|
||||||
#include <stddef.h> /* size_t */
|
#include "zstd_deps.h" /* size_t */
|
||||||
|
|
||||||
|
|
||||||
/* --- simple histogram functions --- */
|
/* --- simple histogram functions --- */
|
||||||
@@ -93,3 +74,5 @@ size_t HIST_countFast_wksp(unsigned* count, unsigned* maxSymbolValuePtr,
|
|||||||
*/
|
*/
|
||||||
unsigned HIST_count_simple(unsigned* count, unsigned* maxSymbolValuePtr,
|
unsigned HIST_count_simple(unsigned* count, unsigned* maxSymbolValuePtr,
|
||||||
const void* src, size_t srcSize);
|
const void* src, size_t srcSize);
|
||||||
|
|
||||||
|
#endif /* USE_EXTERNAL_ZSTD */
|
||||||
|
|||||||
312
vendor/github.com/DataDog/zstd/huf.h
generated
vendored
312
vendor/github.com/DataDog/zstd/huf.h
generated
vendored
@@ -1,35 +1,16 @@
|
|||||||
|
#ifndef USE_EXTERNAL_ZSTD
|
||||||
/* ******************************************************************
|
/* ******************************************************************
|
||||||
huff0 huffman codec,
|
* huff0 huffman codec,
|
||||||
part of Finite State Entropy library
|
* part of Finite State Entropy library
|
||||||
Copyright (C) 2013-present, Yann Collet.
|
* Copyright (c) Meta Platforms, Inc. and affiliates.
|
||||||
|
*
|
||||||
BSD 2-Clause License (http://www.opensource.org/licenses/bsd-license.php)
|
* You can contact the author at :
|
||||||
|
* - Source repository : https://github.com/Cyan4973/FiniteStateEntropy
|
||||||
Redistribution and use in source and binary forms, with or without
|
*
|
||||||
modification, are permitted provided that the following conditions are
|
* This source code is licensed under both the BSD-style license (found in the
|
||||||
met:
|
* LICENSE file in the root directory of this source tree) and the GPLv2 (found
|
||||||
|
* in the COPYING file in the root directory of this source tree).
|
||||||
* Redistributions of source code must retain the above copyright
|
* You may select, at your option, one of the above-listed licenses.
|
||||||
notice, this list of conditions and the following disclaimer.
|
|
||||||
* Redistributions in binary form must reproduce the above
|
|
||||||
copyright notice, this list of conditions and the following disclaimer
|
|
||||||
in the documentation and/or other materials provided with the
|
|
||||||
distribution.
|
|
||||||
|
|
||||||
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
|
||||||
"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
|
||||||
LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
|
||||||
A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
|
|
||||||
OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
|
||||||
SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
|
||||||
LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
|
||||||
DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
|
||||||
THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
|
||||||
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
|
||||||
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
|
||||||
|
|
||||||
You can contact the author at :
|
|
||||||
- Source repository : https://github.com/Cyan4973/FiniteStateEntropy
|
|
||||||
****************************************************************** */
|
****************************************************************** */
|
||||||
|
|
||||||
#if defined (__cplusplus)
|
#if defined (__cplusplus)
|
||||||
@@ -40,105 +21,30 @@ extern "C" {
|
|||||||
#define HUF_H_298734234
|
#define HUF_H_298734234
|
||||||
|
|
||||||
/* *** Dependencies *** */
|
/* *** Dependencies *** */
|
||||||
#include <stddef.h> /* size_t */
|
#include "zstd_deps.h" /* size_t */
|
||||||
|
#include "mem.h" /* U32 */
|
||||||
|
#define FSE_STATIC_LINKING_ONLY
|
||||||
/* *** library symbols visibility *** */
|
#include "fse.h"
|
||||||
/* Note : when linking with -fvisibility=hidden on gcc, or by default on Visual,
|
|
||||||
* HUF symbols remain "private" (internal symbols for library only).
|
|
||||||
* Set macro FSE_DLL_EXPORT to 1 if you want HUF symbols visible on DLL interface */
|
|
||||||
#if defined(FSE_DLL_EXPORT) && (FSE_DLL_EXPORT==1) && defined(__GNUC__) && (__GNUC__ >= 4)
|
|
||||||
# define HUF_PUBLIC_API __attribute__ ((visibility ("default")))
|
|
||||||
#elif defined(FSE_DLL_EXPORT) && (FSE_DLL_EXPORT==1) /* Visual expected */
|
|
||||||
# define HUF_PUBLIC_API __declspec(dllexport)
|
|
||||||
#elif defined(FSE_DLL_IMPORT) && (FSE_DLL_IMPORT==1)
|
|
||||||
# define HUF_PUBLIC_API __declspec(dllimport) /* not required, just to generate faster code (saves a function pointer load from IAT and an indirect jump) */
|
|
||||||
#else
|
|
||||||
# define HUF_PUBLIC_API
|
|
||||||
#endif
|
|
||||||
|
|
||||||
|
|
||||||
/* ========================== */
|
|
||||||
/* *** simple functions *** */
|
|
||||||
/* ========================== */
|
|
||||||
|
|
||||||
/** HUF_compress() :
|
|
||||||
* Compress content from buffer 'src', of size 'srcSize', into buffer 'dst'.
|
|
||||||
* 'dst' buffer must be already allocated.
|
|
||||||
* Compression runs faster if `dstCapacity` >= HUF_compressBound(srcSize).
|
|
||||||
* `srcSize` must be <= `HUF_BLOCKSIZE_MAX` == 128 KB.
|
|
||||||
* @return : size of compressed data (<= `dstCapacity`).
|
|
||||||
* Special values : if return == 0, srcData is not compressible => Nothing is stored within dst !!!
|
|
||||||
* if HUF_isError(return), compression failed (more details using HUF_getErrorName())
|
|
||||||
*/
|
|
||||||
HUF_PUBLIC_API size_t HUF_compress(void* dst, size_t dstCapacity,
|
|
||||||
const void* src, size_t srcSize);
|
|
||||||
|
|
||||||
/** HUF_decompress() :
|
|
||||||
* Decompress HUF data from buffer 'cSrc', of size 'cSrcSize',
|
|
||||||
* into already allocated buffer 'dst', of minimum size 'dstSize'.
|
|
||||||
* `originalSize` : **must** be the ***exact*** size of original (uncompressed) data.
|
|
||||||
* Note : in contrast with FSE, HUF_decompress can regenerate
|
|
||||||
* RLE (cSrcSize==1) and uncompressed (cSrcSize==dstSize) data,
|
|
||||||
* because it knows size to regenerate (originalSize).
|
|
||||||
* @return : size of regenerated data (== originalSize),
|
|
||||||
* or an error code, which can be tested using HUF_isError()
|
|
||||||
*/
|
|
||||||
HUF_PUBLIC_API size_t HUF_decompress(void* dst, size_t originalSize,
|
|
||||||
const void* cSrc, size_t cSrcSize);
|
|
||||||
|
|
||||||
|
|
||||||
/* *** Tool functions *** */
|
/* *** Tool functions *** */
|
||||||
#define HUF_BLOCKSIZE_MAX (128 * 1024) /**< maximum input size for a single block compressed with HUF_compress */
|
#define HUF_BLOCKSIZE_MAX (128 * 1024) /**< maximum input size for a single block compressed with HUF_compress */
|
||||||
HUF_PUBLIC_API size_t HUF_compressBound(size_t size); /**< maximum compressed size (worst case) */
|
size_t HUF_compressBound(size_t size); /**< maximum compressed size (worst case) */
|
||||||
|
|
||||||
/* Error Management */
|
/* Error Management */
|
||||||
HUF_PUBLIC_API unsigned HUF_isError(size_t code); /**< tells if a return value is an error code */
|
unsigned HUF_isError(size_t code); /**< tells if a return value is an error code */
|
||||||
HUF_PUBLIC_API const char* HUF_getErrorName(size_t code); /**< provides error code string (useful for debugging) */
|
const char* HUF_getErrorName(size_t code); /**< provides error code string (useful for debugging) */
|
||||||
|
|
||||||
|
|
||||||
/* *** Advanced function *** */
|
#define HUF_WORKSPACE_SIZE ((8 << 10) + 512 /* sorting scratch space */)
|
||||||
|
#define HUF_WORKSPACE_SIZE_U64 (HUF_WORKSPACE_SIZE / sizeof(U64))
|
||||||
/** HUF_compress2() :
|
|
||||||
* Same as HUF_compress(), but offers control over `maxSymbolValue` and `tableLog`.
|
|
||||||
* `maxSymbolValue` must be <= HUF_SYMBOLVALUE_MAX .
|
|
||||||
* `tableLog` must be `<= HUF_TABLELOG_MAX` . */
|
|
||||||
HUF_PUBLIC_API size_t HUF_compress2 (void* dst, size_t dstCapacity,
|
|
||||||
const void* src, size_t srcSize,
|
|
||||||
unsigned maxSymbolValue, unsigned tableLog);
|
|
||||||
|
|
||||||
/** HUF_compress4X_wksp() :
|
|
||||||
* Same as HUF_compress2(), but uses externally allocated `workSpace`.
|
|
||||||
* `workspace` must have minimum alignment of 4, and be at least as large as HUF_WORKSPACE_SIZE */
|
|
||||||
#define HUF_WORKSPACE_SIZE (6 << 10)
|
|
||||||
#define HUF_WORKSPACE_SIZE_U32 (HUF_WORKSPACE_SIZE / sizeof(U32))
|
|
||||||
HUF_PUBLIC_API size_t HUF_compress4X_wksp (void* dst, size_t dstCapacity,
|
|
||||||
const void* src, size_t srcSize,
|
|
||||||
unsigned maxSymbolValue, unsigned tableLog,
|
|
||||||
void* workSpace, size_t wkspSize);
|
|
||||||
|
|
||||||
#endif /* HUF_H_298734234 */
|
|
||||||
|
|
||||||
/* ******************************************************************
|
|
||||||
* WARNING !!
|
|
||||||
* The following section contains advanced and experimental definitions
|
|
||||||
* which shall never be used in the context of a dynamic library,
|
|
||||||
* because they are not guaranteed to remain stable in the future.
|
|
||||||
* Only consider them in association with static linking.
|
|
||||||
* *****************************************************************/
|
|
||||||
#if defined(HUF_STATIC_LINKING_ONLY) && !defined(HUF_H_HUF_STATIC_LINKING_ONLY)
|
|
||||||
#define HUF_H_HUF_STATIC_LINKING_ONLY
|
|
||||||
|
|
||||||
/* *** Dependencies *** */
|
|
||||||
#include "mem.h" /* U32 */
|
|
||||||
|
|
||||||
|
|
||||||
/* *** Constants *** */
|
/* *** Constants *** */
|
||||||
#define HUF_TABLELOG_MAX 12 /* max runtime value of tableLog (due to static allocation); can be modified up to HUF_ABSOLUTEMAX_TABLELOG */
|
#define HUF_TABLELOG_MAX 12 /* max runtime value of tableLog (due to static allocation); can be modified up to HUF_TABLELOG_ABSOLUTEMAX */
|
||||||
#define HUF_TABLELOG_DEFAULT 11 /* default tableLog value when none specified */
|
#define HUF_TABLELOG_DEFAULT 11 /* default tableLog value when none specified */
|
||||||
#define HUF_SYMBOLVALUE_MAX 255
|
#define HUF_SYMBOLVALUE_MAX 255
|
||||||
|
|
||||||
#define HUF_TABLELOG_ABSOLUTEMAX 15 /* absolute limit of HUF_MAX_TABLELOG. Beyond that value, code does not work */
|
#define HUF_TABLELOG_ABSOLUTEMAX 12 /* absolute limit of HUF_MAX_TABLELOG. Beyond that value, code does not work */
|
||||||
#if (HUF_TABLELOG_MAX > HUF_TABLELOG_ABSOLUTEMAX)
|
#if (HUF_TABLELOG_MAX > HUF_TABLELOG_ABSOLUTEMAX)
|
||||||
# error "HUF_TABLELOG_MAX is too large !"
|
# error "HUF_TABLELOG_MAX is too large !"
|
||||||
#endif
|
#endif
|
||||||
@@ -153,12 +59,12 @@ HUF_PUBLIC_API size_t HUF_compress4X_wksp (void* dst, size_t dstCapacity,
|
|||||||
#define HUF_COMPRESSBOUND(size) (HUF_CTABLEBOUND + HUF_BLOCKBOUND(size)) /* Macro version, useful for static allocation */
|
#define HUF_COMPRESSBOUND(size) (HUF_CTABLEBOUND + HUF_BLOCKBOUND(size)) /* Macro version, useful for static allocation */
|
||||||
|
|
||||||
/* static allocation of HUF's Compression Table */
|
/* static allocation of HUF's Compression Table */
|
||||||
#define HUF_CTABLE_SIZE_U32(maxSymbolValue) ((maxSymbolValue)+1) /* Use tables of U32, for proper alignment */
|
/* this is a private definition, just exposed for allocation and strict aliasing purpose. never EVER access its members directly */
|
||||||
#define HUF_CTABLE_SIZE(maxSymbolValue) (HUF_CTABLE_SIZE_U32(maxSymbolValue) * sizeof(U32))
|
typedef size_t HUF_CElt; /* consider it an incomplete type */
|
||||||
|
#define HUF_CTABLE_SIZE_ST(maxSymbolValue) ((maxSymbolValue)+2) /* Use tables of size_t, for proper alignment */
|
||||||
|
#define HUF_CTABLE_SIZE(maxSymbolValue) (HUF_CTABLE_SIZE_ST(maxSymbolValue) * sizeof(size_t))
|
||||||
#define HUF_CREATE_STATIC_CTABLE(name, maxSymbolValue) \
|
#define HUF_CREATE_STATIC_CTABLE(name, maxSymbolValue) \
|
||||||
U32 name##hb[HUF_CTABLE_SIZE_U32(maxSymbolValue)]; \
|
HUF_CElt name[HUF_CTABLE_SIZE_ST(maxSymbolValue)] /* no final ; */
|
||||||
void* name##hv = &(name##hb); \
|
|
||||||
HUF_CElt* name = (HUF_CElt*)(name##hv) /* no final ; */
|
|
||||||
|
|
||||||
/* static allocation of HUF's DTable */
|
/* static allocation of HUF's DTable */
|
||||||
typedef U32 HUF_DTable;
|
typedef U32 HUF_DTable;
|
||||||
@@ -172,25 +78,49 @@ typedef U32 HUF_DTable;
|
|||||||
/* ****************************************
|
/* ****************************************
|
||||||
* Advanced decompression functions
|
* Advanced decompression functions
|
||||||
******************************************/
|
******************************************/
|
||||||
size_t HUF_decompress4X1 (void* dst, size_t dstSize, const void* cSrc, size_t cSrcSize); /**< single-symbol decoder */
|
|
||||||
#ifndef HUF_FORCE_DECOMPRESS_X1
|
|
||||||
size_t HUF_decompress4X2 (void* dst, size_t dstSize, const void* cSrc, size_t cSrcSize); /**< double-symbols decoder */
|
|
||||||
#endif
|
|
||||||
|
|
||||||
size_t HUF_decompress4X_DCtx (HUF_DTable* dctx, void* dst, size_t dstSize, const void* cSrc, size_t cSrcSize); /**< decodes RLE and uncompressed */
|
/**
|
||||||
size_t HUF_decompress4X_hufOnly(HUF_DTable* dctx, void* dst, size_t dstSize, const void* cSrc, size_t cSrcSize); /**< considers RLE and uncompressed as errors */
|
* Huffman flags bitset.
|
||||||
size_t HUF_decompress4X_hufOnly_wksp(HUF_DTable* dctx, void* dst, size_t dstSize, const void* cSrc, size_t cSrcSize, void* workSpace, size_t wkspSize); /**< considers RLE and uncompressed as errors */
|
* For all flags, 0 is the default value.
|
||||||
size_t HUF_decompress4X1_DCtx(HUF_DTable* dctx, void* dst, size_t dstSize, const void* cSrc, size_t cSrcSize); /**< single-symbol decoder */
|
*/
|
||||||
size_t HUF_decompress4X1_DCtx_wksp(HUF_DTable* dctx, void* dst, size_t dstSize, const void* cSrc, size_t cSrcSize, void* workSpace, size_t wkspSize); /**< single-symbol decoder */
|
typedef enum {
|
||||||
#ifndef HUF_FORCE_DECOMPRESS_X1
|
/**
|
||||||
size_t HUF_decompress4X2_DCtx(HUF_DTable* dctx, void* dst, size_t dstSize, const void* cSrc, size_t cSrcSize); /**< double-symbols decoder */
|
* If compiled with DYNAMIC_BMI2: Set flag only if the CPU supports BMI2 at runtime.
|
||||||
size_t HUF_decompress4X2_DCtx_wksp(HUF_DTable* dctx, void* dst, size_t dstSize, const void* cSrc, size_t cSrcSize, void* workSpace, size_t wkspSize); /**< double-symbols decoder */
|
* Otherwise: Ignored.
|
||||||
#endif
|
*/
|
||||||
|
HUF_flags_bmi2 = (1 << 0),
|
||||||
|
/**
|
||||||
|
* If set: Test possible table depths to find the one that produces the smallest header + encoded size.
|
||||||
|
* If unset: Use heuristic to find the table depth.
|
||||||
|
*/
|
||||||
|
HUF_flags_optimalDepth = (1 << 1),
|
||||||
|
/**
|
||||||
|
* If set: If the previous table can encode the input, always reuse the previous table.
|
||||||
|
* If unset: If the previous table can encode the input, reuse the previous table if it results in a smaller output.
|
||||||
|
*/
|
||||||
|
HUF_flags_preferRepeat = (1 << 2),
|
||||||
|
/**
|
||||||
|
* If set: Sample the input and check if the sample is uncompressible, if it is then don't attempt to compress.
|
||||||
|
* If unset: Always histogram the entire input.
|
||||||
|
*/
|
||||||
|
HUF_flags_suspectUncompressible = (1 << 3),
|
||||||
|
/**
|
||||||
|
* If set: Don't use assembly implementations
|
||||||
|
* If unset: Allow using assembly implementations
|
||||||
|
*/
|
||||||
|
HUF_flags_disableAsm = (1 << 4),
|
||||||
|
/**
|
||||||
|
* If set: Don't use the fast decoding loop, always use the fallback decoding loop.
|
||||||
|
* If unset: Use the fast decoding loop when possible.
|
||||||
|
*/
|
||||||
|
HUF_flags_disableFast = (1 << 5)
|
||||||
|
} HUF_flags_e;
|
||||||
|
|
||||||
|
|
||||||
/* ****************************************
|
/* ****************************************
|
||||||
* HUF detailed API
|
* HUF detailed API
|
||||||
* ****************************************/
|
* ****************************************/
|
||||||
|
#define HUF_OPTIMAL_DEPTH_THRESHOLD ZSTD_btultra
|
||||||
|
|
||||||
/*! HUF_compress() does the following:
|
/*! HUF_compress() does the following:
|
||||||
* 1. count symbol occurrence from source[] into table count[] using FSE_count() (exposed within "fse.h")
|
* 1. count symbol occurrence from source[] into table count[] using FSE_count() (exposed within "fse.h")
|
||||||
@@ -203,33 +133,38 @@ size_t HUF_decompress4X2_DCtx_wksp(HUF_DTable* dctx, void* dst, size_t dstSize,
|
|||||||
* For example, it's possible to compress several blocks using the same 'CTable',
|
* For example, it's possible to compress several blocks using the same 'CTable',
|
||||||
* or to save and regenerate 'CTable' using external methods.
|
* or to save and regenerate 'CTable' using external methods.
|
||||||
*/
|
*/
|
||||||
unsigned HUF_optimalTableLog(unsigned maxTableLog, size_t srcSize, unsigned maxSymbolValue);
|
unsigned HUF_minTableLog(unsigned symbolCardinality);
|
||||||
typedef struct HUF_CElt_s HUF_CElt; /* incomplete type */
|
unsigned HUF_cardinality(const unsigned* count, unsigned maxSymbolValue);
|
||||||
size_t HUF_buildCTable (HUF_CElt* CTable, const unsigned* count, unsigned maxSymbolValue, unsigned maxNbBits); /* @return : maxNbBits; CTable and count can overlap. In which case, CTable will overwrite count content */
|
unsigned HUF_optimalTableLog(unsigned maxTableLog, size_t srcSize, unsigned maxSymbolValue, void* workSpace,
|
||||||
size_t HUF_writeCTable (void* dst, size_t maxDstSize, const HUF_CElt* CTable, unsigned maxSymbolValue, unsigned huffLog);
|
size_t wkspSize, HUF_CElt* table, const unsigned* count, int flags); /* table is used as scratch space for building and testing tables, not a return value */
|
||||||
size_t HUF_compress4X_usingCTable(void* dst, size_t dstSize, const void* src, size_t srcSize, const HUF_CElt* CTable);
|
size_t HUF_writeCTable_wksp(void* dst, size_t maxDstSize, const HUF_CElt* CTable, unsigned maxSymbolValue, unsigned huffLog, void* workspace, size_t workspaceSize);
|
||||||
|
size_t HUF_compress4X_usingCTable(void* dst, size_t dstSize, const void* src, size_t srcSize, const HUF_CElt* CTable, int flags);
|
||||||
|
size_t HUF_estimateCompressedSize(const HUF_CElt* CTable, const unsigned* count, unsigned maxSymbolValue);
|
||||||
|
int HUF_validateCTable(const HUF_CElt* CTable, const unsigned* count, unsigned maxSymbolValue);
|
||||||
|
|
||||||
typedef enum {
|
typedef enum {
|
||||||
HUF_repeat_none, /**< Cannot use the previous table */
|
HUF_repeat_none, /**< Cannot use the previous table */
|
||||||
HUF_repeat_check, /**< Can use the previous table but it must be checked. Note : The previous table must have been constructed by HUF_compress{1, 4}X_repeat */
|
HUF_repeat_check, /**< Can use the previous table but it must be checked. Note : The previous table must have been constructed by HUF_compress{1, 4}X_repeat */
|
||||||
HUF_repeat_valid /**< Can use the previous table and it is assumed to be valid */
|
HUF_repeat_valid /**< Can use the previous table and it is assumed to be valid */
|
||||||
} HUF_repeat;
|
} HUF_repeat;
|
||||||
|
|
||||||
/** HUF_compress4X_repeat() :
|
/** HUF_compress4X_repeat() :
|
||||||
* Same as HUF_compress4X_wksp(), but considers using hufTable if *repeat != HUF_repeat_none.
|
* Same as HUF_compress4X_wksp(), but considers using hufTable if *repeat != HUF_repeat_none.
|
||||||
* If it uses hufTable it does not modify hufTable or repeat.
|
* If it uses hufTable it does not modify hufTable or repeat.
|
||||||
* If it doesn't, it sets *repeat = HUF_repeat_none, and it sets hufTable to the table used.
|
* If it doesn't, it sets *repeat = HUF_repeat_none, and it sets hufTable to the table used.
|
||||||
* If preferRepeat then the old table will always be used if valid. */
|
* If preferRepeat then the old table will always be used if valid.
|
||||||
|
* If suspectUncompressible then some sampling checks will be run to potentially skip huffman coding */
|
||||||
size_t HUF_compress4X_repeat(void* dst, size_t dstSize,
|
size_t HUF_compress4X_repeat(void* dst, size_t dstSize,
|
||||||
const void* src, size_t srcSize,
|
const void* src, size_t srcSize,
|
||||||
unsigned maxSymbolValue, unsigned tableLog,
|
unsigned maxSymbolValue, unsigned tableLog,
|
||||||
void* workSpace, size_t wkspSize, /**< `workSpace` must be aligned on 4-bytes boundaries, `wkspSize` must be >= HUF_WORKSPACE_SIZE */
|
void* workSpace, size_t wkspSize, /**< `workSpace` must be aligned on 4-bytes boundaries, `wkspSize` must be >= HUF_WORKSPACE_SIZE */
|
||||||
HUF_CElt* hufTable, HUF_repeat* repeat, int preferRepeat, int bmi2);
|
HUF_CElt* hufTable, HUF_repeat* repeat, int flags);
|
||||||
|
|
||||||
/** HUF_buildCTable_wksp() :
|
/** HUF_buildCTable_wksp() :
|
||||||
* Same as HUF_buildCTable(), but using externally allocated scratch buffer.
|
* Same as HUF_buildCTable(), but using externally allocated scratch buffer.
|
||||||
* `workSpace` must be aligned on 4-bytes boundaries, and its size must be >= HUF_CTABLE_WORKSPACE_SIZE.
|
* `workSpace` must be aligned on 4-bytes boundaries, and its size must be >= HUF_CTABLE_WORKSPACE_SIZE.
|
||||||
*/
|
*/
|
||||||
#define HUF_CTABLE_WORKSPACE_SIZE_U32 (2*HUF_SYMBOLVALUE_MAX +1 +1)
|
#define HUF_CTABLE_WORKSPACE_SIZE_U32 ((4 * (HUF_SYMBOLVALUE_MAX + 1)) + 192)
|
||||||
#define HUF_CTABLE_WORKSPACE_SIZE (HUF_CTABLE_WORKSPACE_SIZE_U32 * sizeof(unsigned))
|
#define HUF_CTABLE_WORKSPACE_SIZE (HUF_CTABLE_WORKSPACE_SIZE_U32 * sizeof(unsigned))
|
||||||
size_t HUF_buildCTable_wksp (HUF_CElt* tree,
|
size_t HUF_buildCTable_wksp (HUF_CElt* tree,
|
||||||
const unsigned* count, U32 maxSymbolValue, U32 maxNbBits,
|
const unsigned* count, U32 maxSymbolValue, U32 maxNbBits,
|
||||||
@@ -244,15 +179,27 @@ size_t HUF_readStats(BYTE* huffWeight, size_t hwSize,
|
|||||||
U32* rankStats, U32* nbSymbolsPtr, U32* tableLogPtr,
|
U32* rankStats, U32* nbSymbolsPtr, U32* tableLogPtr,
|
||||||
const void* src, size_t srcSize);
|
const void* src, size_t srcSize);
|
||||||
|
|
||||||
|
/*! HUF_readStats_wksp() :
|
||||||
|
* Same as HUF_readStats() but takes an external workspace which must be
|
||||||
|
* 4-byte aligned and its size must be >= HUF_READ_STATS_WORKSPACE_SIZE.
|
||||||
|
* If the CPU has BMI2 support, pass bmi2=1, otherwise pass bmi2=0.
|
||||||
|
*/
|
||||||
|
#define HUF_READ_STATS_WORKSPACE_SIZE_U32 FSE_DECOMPRESS_WKSP_SIZE_U32(6, HUF_TABLELOG_MAX-1)
|
||||||
|
#define HUF_READ_STATS_WORKSPACE_SIZE (HUF_READ_STATS_WORKSPACE_SIZE_U32 * sizeof(unsigned))
|
||||||
|
size_t HUF_readStats_wksp(BYTE* huffWeight, size_t hwSize,
|
||||||
|
U32* rankStats, U32* nbSymbolsPtr, U32* tableLogPtr,
|
||||||
|
const void* src, size_t srcSize,
|
||||||
|
void* workspace, size_t wkspSize,
|
||||||
|
int flags);
|
||||||
|
|
||||||
/** HUF_readCTable() :
|
/** HUF_readCTable() :
|
||||||
* Loading a CTable saved with HUF_writeCTable() */
|
* Loading a CTable saved with HUF_writeCTable() */
|
||||||
size_t HUF_readCTable (HUF_CElt* CTable, unsigned* maxSymbolValuePtr, const void* src, size_t srcSize);
|
size_t HUF_readCTable (HUF_CElt* CTable, unsigned* maxSymbolValuePtr, const void* src, size_t srcSize, unsigned *hasZeroWeights);
|
||||||
|
|
||||||
/** HUF_getNbBits() :
|
/** HUF_getNbBitsFromCTable() :
|
||||||
* Read nbBits from CTable symbolTable, for symbol `symbolValue` presumed <= HUF_SYMBOLVALUE_MAX
|
* Read nbBits from CTable symbolTable, for symbol `symbolValue` presumed <= HUF_SYMBOLVALUE_MAX
|
||||||
* Note 1 : is not inlined, as HUF_CElt definition is private
|
* Note 1 : is not inlined, as HUF_CElt definition is private */
|
||||||
* Note 2 : const void* used, so that it can provide a statically allocated table as argument (which uses type U32) */
|
U32 HUF_getNbBitsFromCTable(const HUF_CElt* symbolTable, U32 symbolValue);
|
||||||
U32 HUF_getNbBits(const void* symbolTable, U32 symbolValue);
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* HUF_decompress() does the following:
|
* HUF_decompress() does the following:
|
||||||
@@ -278,81 +225,52 @@ U32 HUF_selectDecoder (size_t dstSize, size_t cSrcSize);
|
|||||||
* a required workspace size greater than that specified in the following
|
* a required workspace size greater than that specified in the following
|
||||||
* macro.
|
* macro.
|
||||||
*/
|
*/
|
||||||
#define HUF_DECOMPRESS_WORKSPACE_SIZE (2 << 10)
|
#define HUF_DECOMPRESS_WORKSPACE_SIZE ((2 << 10) + (1 << 9))
|
||||||
#define HUF_DECOMPRESS_WORKSPACE_SIZE_U32 (HUF_DECOMPRESS_WORKSPACE_SIZE / sizeof(U32))
|
#define HUF_DECOMPRESS_WORKSPACE_SIZE_U32 (HUF_DECOMPRESS_WORKSPACE_SIZE / sizeof(U32))
|
||||||
|
|
||||||
#ifndef HUF_FORCE_DECOMPRESS_X2
|
|
||||||
size_t HUF_readDTableX1 (HUF_DTable* DTable, const void* src, size_t srcSize);
|
|
||||||
size_t HUF_readDTableX1_wksp (HUF_DTable* DTable, const void* src, size_t srcSize, void* workSpace, size_t wkspSize);
|
|
||||||
#endif
|
|
||||||
#ifndef HUF_FORCE_DECOMPRESS_X1
|
|
||||||
size_t HUF_readDTableX2 (HUF_DTable* DTable, const void* src, size_t srcSize);
|
|
||||||
size_t HUF_readDTableX2_wksp (HUF_DTable* DTable, const void* src, size_t srcSize, void* workSpace, size_t wkspSize);
|
|
||||||
#endif
|
|
||||||
|
|
||||||
size_t HUF_decompress4X_usingDTable(void* dst, size_t maxDstSize, const void* cSrc, size_t cSrcSize, const HUF_DTable* DTable);
|
|
||||||
#ifndef HUF_FORCE_DECOMPRESS_X2
|
|
||||||
size_t HUF_decompress4X1_usingDTable(void* dst, size_t maxDstSize, const void* cSrc, size_t cSrcSize, const HUF_DTable* DTable);
|
|
||||||
#endif
|
|
||||||
#ifndef HUF_FORCE_DECOMPRESS_X1
|
|
||||||
size_t HUF_decompress4X2_usingDTable(void* dst, size_t maxDstSize, const void* cSrc, size_t cSrcSize, const HUF_DTable* DTable);
|
|
||||||
#endif
|
|
||||||
|
|
||||||
|
|
||||||
/* ====================== */
|
/* ====================== */
|
||||||
/* single stream variants */
|
/* single stream variants */
|
||||||
/* ====================== */
|
/* ====================== */
|
||||||
|
|
||||||
size_t HUF_compress1X (void* dst, size_t dstSize, const void* src, size_t srcSize, unsigned maxSymbolValue, unsigned tableLog);
|
size_t HUF_compress1X_usingCTable(void* dst, size_t dstSize, const void* src, size_t srcSize, const HUF_CElt* CTable, int flags);
|
||||||
size_t HUF_compress1X_wksp (void* dst, size_t dstSize, const void* src, size_t srcSize, unsigned maxSymbolValue, unsigned tableLog, void* workSpace, size_t wkspSize); /**< `workSpace` must be a table of at least HUF_WORKSPACE_SIZE_U32 unsigned */
|
|
||||||
size_t HUF_compress1X_usingCTable(void* dst, size_t dstSize, const void* src, size_t srcSize, const HUF_CElt* CTable);
|
|
||||||
/** HUF_compress1X_repeat() :
|
/** HUF_compress1X_repeat() :
|
||||||
* Same as HUF_compress1X_wksp(), but considers using hufTable if *repeat != HUF_repeat_none.
|
* Same as HUF_compress1X_wksp(), but considers using hufTable if *repeat != HUF_repeat_none.
|
||||||
* If it uses hufTable it does not modify hufTable or repeat.
|
* If it uses hufTable it does not modify hufTable or repeat.
|
||||||
* If it doesn't, it sets *repeat = HUF_repeat_none, and it sets hufTable to the table used.
|
* If it doesn't, it sets *repeat = HUF_repeat_none, and it sets hufTable to the table used.
|
||||||
* If preferRepeat then the old table will always be used if valid. */
|
* If preferRepeat then the old table will always be used if valid.
|
||||||
|
* If suspectUncompressible then some sampling checks will be run to potentially skip huffman coding */
|
||||||
size_t HUF_compress1X_repeat(void* dst, size_t dstSize,
|
size_t HUF_compress1X_repeat(void* dst, size_t dstSize,
|
||||||
const void* src, size_t srcSize,
|
const void* src, size_t srcSize,
|
||||||
unsigned maxSymbolValue, unsigned tableLog,
|
unsigned maxSymbolValue, unsigned tableLog,
|
||||||
void* workSpace, size_t wkspSize, /**< `workSpace` must be aligned on 4-bytes boundaries, `wkspSize` must be >= HUF_WORKSPACE_SIZE */
|
void* workSpace, size_t wkspSize, /**< `workSpace` must be aligned on 4-bytes boundaries, `wkspSize` must be >= HUF_WORKSPACE_SIZE */
|
||||||
HUF_CElt* hufTable, HUF_repeat* repeat, int preferRepeat, int bmi2);
|
HUF_CElt* hufTable, HUF_repeat* repeat, int flags);
|
||||||
|
|
||||||
size_t HUF_decompress1X1 (void* dst, size_t dstSize, const void* cSrc, size_t cSrcSize); /* single-symbol decoder */
|
size_t HUF_decompress1X_DCtx_wksp(HUF_DTable* dctx, void* dst, size_t dstSize, const void* cSrc, size_t cSrcSize, void* workSpace, size_t wkspSize, int flags);
|
||||||
#ifndef HUF_FORCE_DECOMPRESS_X1
|
#ifndef HUF_FORCE_DECOMPRESS_X1
|
||||||
size_t HUF_decompress1X2 (void* dst, size_t dstSize, const void* cSrc, size_t cSrcSize); /* double-symbol decoder */
|
size_t HUF_decompress1X2_DCtx_wksp(HUF_DTable* dctx, void* dst, size_t dstSize, const void* cSrc, size_t cSrcSize, void* workSpace, size_t wkspSize, int flags); /**< double-symbols decoder */
|
||||||
#endif
|
|
||||||
|
|
||||||
size_t HUF_decompress1X_DCtx (HUF_DTable* dctx, void* dst, size_t dstSize, const void* cSrc, size_t cSrcSize);
|
|
||||||
size_t HUF_decompress1X_DCtx_wksp (HUF_DTable* dctx, void* dst, size_t dstSize, const void* cSrc, size_t cSrcSize, void* workSpace, size_t wkspSize);
|
|
||||||
#ifndef HUF_FORCE_DECOMPRESS_X2
|
|
||||||
size_t HUF_decompress1X1_DCtx(HUF_DTable* dctx, void* dst, size_t dstSize, const void* cSrc, size_t cSrcSize); /**< single-symbol decoder */
|
|
||||||
size_t HUF_decompress1X1_DCtx_wksp(HUF_DTable* dctx, void* dst, size_t dstSize, const void* cSrc, size_t cSrcSize, void* workSpace, size_t wkspSize); /**< single-symbol decoder */
|
|
||||||
#endif
|
|
||||||
#ifndef HUF_FORCE_DECOMPRESS_X1
|
|
||||||
size_t HUF_decompress1X2_DCtx(HUF_DTable* dctx, void* dst, size_t dstSize, const void* cSrc, size_t cSrcSize); /**< double-symbols decoder */
|
|
||||||
size_t HUF_decompress1X2_DCtx_wksp(HUF_DTable* dctx, void* dst, size_t dstSize, const void* cSrc, size_t cSrcSize, void* workSpace, size_t wkspSize); /**< double-symbols decoder */
|
|
||||||
#endif
|
|
||||||
|
|
||||||
size_t HUF_decompress1X_usingDTable(void* dst, size_t maxDstSize, const void* cSrc, size_t cSrcSize, const HUF_DTable* DTable); /**< automatic selection of sing or double symbol decoder, based on DTable */
|
|
||||||
#ifndef HUF_FORCE_DECOMPRESS_X2
|
|
||||||
size_t HUF_decompress1X1_usingDTable(void* dst, size_t maxDstSize, const void* cSrc, size_t cSrcSize, const HUF_DTable* DTable);
|
|
||||||
#endif
|
|
||||||
#ifndef HUF_FORCE_DECOMPRESS_X1
|
|
||||||
size_t HUF_decompress1X2_usingDTable(void* dst, size_t maxDstSize, const void* cSrc, size_t cSrcSize, const HUF_DTable* DTable);
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
/* BMI2 variants.
|
/* BMI2 variants.
|
||||||
* If the CPU has BMI2 support, pass bmi2=1, otherwise pass bmi2=0.
|
* If the CPU has BMI2 support, pass bmi2=1, otherwise pass bmi2=0.
|
||||||
*/
|
*/
|
||||||
size_t HUF_decompress1X_usingDTable_bmi2(void* dst, size_t maxDstSize, const void* cSrc, size_t cSrcSize, const HUF_DTable* DTable, int bmi2);
|
size_t HUF_decompress1X_usingDTable(void* dst, size_t maxDstSize, const void* cSrc, size_t cSrcSize, const HUF_DTable* DTable, int flags);
|
||||||
#ifndef HUF_FORCE_DECOMPRESS_X2
|
#ifndef HUF_FORCE_DECOMPRESS_X2
|
||||||
size_t HUF_decompress1X1_DCtx_wksp_bmi2(HUF_DTable* dctx, void* dst, size_t dstSize, const void* cSrc, size_t cSrcSize, void* workSpace, size_t wkspSize, int bmi2);
|
size_t HUF_decompress1X1_DCtx_wksp(HUF_DTable* dctx, void* dst, size_t dstSize, const void* cSrc, size_t cSrcSize, void* workSpace, size_t wkspSize, int flags);
|
||||||
|
#endif
|
||||||
|
size_t HUF_decompress4X_usingDTable(void* dst, size_t maxDstSize, const void* cSrc, size_t cSrcSize, const HUF_DTable* DTable, int flags);
|
||||||
|
size_t HUF_decompress4X_hufOnly_wksp(HUF_DTable* dctx, void* dst, size_t dstSize, const void* cSrc, size_t cSrcSize, void* workSpace, size_t wkspSize, int flags);
|
||||||
|
#ifndef HUF_FORCE_DECOMPRESS_X2
|
||||||
|
size_t HUF_readDTableX1_wksp(HUF_DTable* DTable, const void* src, size_t srcSize, void* workSpace, size_t wkspSize, int flags);
|
||||||
|
#endif
|
||||||
|
#ifndef HUF_FORCE_DECOMPRESS_X1
|
||||||
|
size_t HUF_readDTableX2_wksp(HUF_DTable* DTable, const void* src, size_t srcSize, void* workSpace, size_t wkspSize, int flags);
|
||||||
#endif
|
#endif
|
||||||
size_t HUF_decompress4X_usingDTable_bmi2(void* dst, size_t maxDstSize, const void* cSrc, size_t cSrcSize, const HUF_DTable* DTable, int bmi2);
|
|
||||||
size_t HUF_decompress4X_hufOnly_wksp_bmi2(HUF_DTable* dctx, void* dst, size_t dstSize, const void* cSrc, size_t cSrcSize, void* workSpace, size_t wkspSize, int bmi2);
|
|
||||||
|
|
||||||
#endif /* HUF_STATIC_LINKING_ONLY */
|
#endif /* HUF_H_298734234 */
|
||||||
|
|
||||||
#if defined (__cplusplus)
|
#if defined (__cplusplus)
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
#endif /* USE_EXTERNAL_ZSTD */
|
||||||
|
|||||||
1276
vendor/github.com/DataDog/zstd/huf_compress.c
generated
vendored
1276
vendor/github.com/DataDog/zstd/huf_compress.c
generated
vendored
File diff suppressed because it is too large
Load Diff
1713
vendor/github.com/DataDog/zstd/huf_decompress.c
generated
vendored
1713
vendor/github.com/DataDog/zstd/huf_decompress.c
generated
vendored
File diff suppressed because it is too large
Load Diff
576
vendor/github.com/DataDog/zstd/huf_decompress_amd64.S
generated
vendored
Normal file
576
vendor/github.com/DataDog/zstd/huf_decompress_amd64.S
generated
vendored
Normal file
@@ -0,0 +1,576 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (c) Meta Platforms, Inc. and affiliates.
|
||||||
|
* All rights reserved.
|
||||||
|
*
|
||||||
|
* This source code is licensed under both the BSD-style license (found in the
|
||||||
|
* LICENSE file in the root directory of this source tree) and the GPLv2 (found
|
||||||
|
* in the COPYING file in the root directory of this source tree).
|
||||||
|
* You may select, at your option, one of the above-listed licenses.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include "portability_macros.h"
|
||||||
|
|
||||||
|
/* Stack marking
|
||||||
|
* ref: https://wiki.gentoo.org/wiki/Hardened/GNU_stack_quickstart
|
||||||
|
*/
|
||||||
|
#if defined(__ELF__) && defined(__GNUC__)
|
||||||
|
.section .note.GNU-stack,"",%progbits
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#if ZSTD_ENABLE_ASM_X86_64_BMI2
|
||||||
|
|
||||||
|
/* Calling convention:
|
||||||
|
*
|
||||||
|
* %rdi contains the first argument: HUF_DecompressAsmArgs*.
|
||||||
|
* %rbp isn't maintained (no frame pointer).
|
||||||
|
* %rsp contains the stack pointer that grows down.
|
||||||
|
* No red-zone is assumed, only addresses >= %rsp are used.
|
||||||
|
* All register contents are preserved.
|
||||||
|
*
|
||||||
|
* TODO: Support Windows calling convention.
|
||||||
|
*/
|
||||||
|
|
||||||
|
ZSTD_HIDE_ASM_FUNCTION(HUF_decompress4X1_usingDTable_internal_fast_asm_loop)
|
||||||
|
ZSTD_HIDE_ASM_FUNCTION(HUF_decompress4X2_usingDTable_internal_fast_asm_loop)
|
||||||
|
ZSTD_HIDE_ASM_FUNCTION(_HUF_decompress4X2_usingDTable_internal_fast_asm_loop)
|
||||||
|
ZSTD_HIDE_ASM_FUNCTION(_HUF_decompress4X1_usingDTable_internal_fast_asm_loop)
|
||||||
|
.global HUF_decompress4X1_usingDTable_internal_fast_asm_loop
|
||||||
|
.global HUF_decompress4X2_usingDTable_internal_fast_asm_loop
|
||||||
|
.global _HUF_decompress4X1_usingDTable_internal_fast_asm_loop
|
||||||
|
.global _HUF_decompress4X2_usingDTable_internal_fast_asm_loop
|
||||||
|
.text
|
||||||
|
|
||||||
|
/* Sets up register mappings for clarity.
|
||||||
|
* op[], bits[], dtable & ip[0] each get their own register.
|
||||||
|
* ip[1,2,3] & olimit alias var[].
|
||||||
|
* %rax is a scratch register.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#define op0 rsi
|
||||||
|
#define op1 rbx
|
||||||
|
#define op2 rcx
|
||||||
|
#define op3 rdi
|
||||||
|
|
||||||
|
#define ip0 r8
|
||||||
|
#define ip1 r9
|
||||||
|
#define ip2 r10
|
||||||
|
#define ip3 r11
|
||||||
|
|
||||||
|
#define bits0 rbp
|
||||||
|
#define bits1 rdx
|
||||||
|
#define bits2 r12
|
||||||
|
#define bits3 r13
|
||||||
|
#define dtable r14
|
||||||
|
#define olimit r15
|
||||||
|
|
||||||
|
/* var[] aliases ip[1,2,3] & olimit
|
||||||
|
* ip[1,2,3] are saved every iteration.
|
||||||
|
* olimit is only used in compute_olimit.
|
||||||
|
*/
|
||||||
|
#define var0 r15
|
||||||
|
#define var1 r9
|
||||||
|
#define var2 r10
|
||||||
|
#define var3 r11
|
||||||
|
|
||||||
|
/* 32-bit var registers */
|
||||||
|
#define vard0 r15d
|
||||||
|
#define vard1 r9d
|
||||||
|
#define vard2 r10d
|
||||||
|
#define vard3 r11d
|
||||||
|
|
||||||
|
/* Calls X(N) for each stream 0, 1, 2, 3. */
|
||||||
|
#define FOR_EACH_STREAM(X) \
|
||||||
|
X(0); \
|
||||||
|
X(1); \
|
||||||
|
X(2); \
|
||||||
|
X(3)
|
||||||
|
|
||||||
|
/* Calls X(N, idx) for each stream 0, 1, 2, 3. */
|
||||||
|
#define FOR_EACH_STREAM_WITH_INDEX(X, idx) \
|
||||||
|
X(0, idx); \
|
||||||
|
X(1, idx); \
|
||||||
|
X(2, idx); \
|
||||||
|
X(3, idx)
|
||||||
|
|
||||||
|
/* Define both _HUF_* & HUF_* symbols because MacOS
|
||||||
|
* C symbols are prefixed with '_' & Linux symbols aren't.
|
||||||
|
*/
|
||||||
|
_HUF_decompress4X1_usingDTable_internal_fast_asm_loop:
|
||||||
|
HUF_decompress4X1_usingDTable_internal_fast_asm_loop:
|
||||||
|
ZSTD_CET_ENDBRANCH
|
||||||
|
/* Save all registers - even if they are callee saved for simplicity. */
|
||||||
|
push %rax
|
||||||
|
push %rbx
|
||||||
|
push %rcx
|
||||||
|
push %rdx
|
||||||
|
push %rbp
|
||||||
|
push %rsi
|
||||||
|
push %rdi
|
||||||
|
push %r8
|
||||||
|
push %r9
|
||||||
|
push %r10
|
||||||
|
push %r11
|
||||||
|
push %r12
|
||||||
|
push %r13
|
||||||
|
push %r14
|
||||||
|
push %r15
|
||||||
|
|
||||||
|
/* Read HUF_DecompressAsmArgs* args from %rax */
|
||||||
|
movq %rdi, %rax
|
||||||
|
movq 0(%rax), %ip0
|
||||||
|
movq 8(%rax), %ip1
|
||||||
|
movq 16(%rax), %ip2
|
||||||
|
movq 24(%rax), %ip3
|
||||||
|
movq 32(%rax), %op0
|
||||||
|
movq 40(%rax), %op1
|
||||||
|
movq 48(%rax), %op2
|
||||||
|
movq 56(%rax), %op3
|
||||||
|
movq 64(%rax), %bits0
|
||||||
|
movq 72(%rax), %bits1
|
||||||
|
movq 80(%rax), %bits2
|
||||||
|
movq 88(%rax), %bits3
|
||||||
|
movq 96(%rax), %dtable
|
||||||
|
push %rax /* argument */
|
||||||
|
push 104(%rax) /* ilimit */
|
||||||
|
push 112(%rax) /* oend */
|
||||||
|
push %olimit /* olimit space */
|
||||||
|
|
||||||
|
subq $24, %rsp
|
||||||
|
|
||||||
|
.L_4X1_compute_olimit:
|
||||||
|
/* Computes how many iterations we can do safely
|
||||||
|
* %r15, %rax may be clobbered
|
||||||
|
* rbx, rdx must be saved
|
||||||
|
* op3 & ip0 mustn't be clobbered
|
||||||
|
*/
|
||||||
|
movq %rbx, 0(%rsp)
|
||||||
|
movq %rdx, 8(%rsp)
|
||||||
|
|
||||||
|
movq 32(%rsp), %rax /* rax = oend */
|
||||||
|
subq %op3, %rax /* rax = oend - op3 */
|
||||||
|
|
||||||
|
/* r15 = (oend - op3) / 5 */
|
||||||
|
movabsq $-3689348814741910323, %rdx
|
||||||
|
mulq %rdx
|
||||||
|
movq %rdx, %r15
|
||||||
|
shrq $2, %r15
|
||||||
|
|
||||||
|
movq %ip0, %rax /* rax = ip0 */
|
||||||
|
movq 40(%rsp), %rdx /* rdx = ilimit */
|
||||||
|
subq %rdx, %rax /* rax = ip0 - ilimit */
|
||||||
|
movq %rax, %rbx /* rbx = ip0 - ilimit */
|
||||||
|
|
||||||
|
/* rdx = (ip0 - ilimit) / 7 */
|
||||||
|
movabsq $2635249153387078803, %rdx
|
||||||
|
mulq %rdx
|
||||||
|
subq %rdx, %rbx
|
||||||
|
shrq %rbx
|
||||||
|
addq %rbx, %rdx
|
||||||
|
shrq $2, %rdx
|
||||||
|
|
||||||
|
/* r15 = min(%rdx, %r15) */
|
||||||
|
cmpq %rdx, %r15
|
||||||
|
cmova %rdx, %r15
|
||||||
|
|
||||||
|
/* r15 = r15 * 5 */
|
||||||
|
leaq (%r15, %r15, 4), %r15
|
||||||
|
|
||||||
|
/* olimit = op3 + r15 */
|
||||||
|
addq %op3, %olimit
|
||||||
|
|
||||||
|
movq 8(%rsp), %rdx
|
||||||
|
movq 0(%rsp), %rbx
|
||||||
|
|
||||||
|
/* If (op3 + 20 > olimit) */
|
||||||
|
movq %op3, %rax /* rax = op3 */
|
||||||
|
addq $20, %rax /* rax = op3 + 20 */
|
||||||
|
cmpq %rax, %olimit /* op3 + 20 > olimit */
|
||||||
|
jb .L_4X1_exit
|
||||||
|
|
||||||
|
/* If (ip1 < ip0) go to exit */
|
||||||
|
cmpq %ip0, %ip1
|
||||||
|
jb .L_4X1_exit
|
||||||
|
|
||||||
|
/* If (ip2 < ip1) go to exit */
|
||||||
|
cmpq %ip1, %ip2
|
||||||
|
jb .L_4X1_exit
|
||||||
|
|
||||||
|
/* If (ip3 < ip2) go to exit */
|
||||||
|
cmpq %ip2, %ip3
|
||||||
|
jb .L_4X1_exit
|
||||||
|
|
||||||
|
/* Reads top 11 bits from bits[n]
|
||||||
|
* Loads dt[bits[n]] into var[n]
|
||||||
|
*/
|
||||||
|
#define GET_NEXT_DELT(n) \
|
||||||
|
movq $53, %var##n; \
|
||||||
|
shrxq %var##n, %bits##n, %var##n; \
|
||||||
|
movzwl (%dtable,%var##n,2),%vard##n
|
||||||
|
|
||||||
|
/* var[n] must contain the DTable entry computed with GET_NEXT_DELT
|
||||||
|
* Moves var[n] to %rax
|
||||||
|
* bits[n] <<= var[n] & 63
|
||||||
|
* op[n][idx] = %rax >> 8
|
||||||
|
* %ah is a way to access bits [8, 16) of %rax
|
||||||
|
*/
|
||||||
|
#define DECODE_FROM_DELT(n, idx) \
|
||||||
|
movq %var##n, %rax; \
|
||||||
|
shlxq %var##n, %bits##n, %bits##n; \
|
||||||
|
movb %ah, idx(%op##n)
|
||||||
|
|
||||||
|
/* Assumes GET_NEXT_DELT has been called.
|
||||||
|
* Calls DECODE_FROM_DELT then GET_NEXT_DELT
|
||||||
|
*/
|
||||||
|
#define DECODE_AND_GET_NEXT(n, idx) \
|
||||||
|
DECODE_FROM_DELT(n, idx); \
|
||||||
|
GET_NEXT_DELT(n) \
|
||||||
|
|
||||||
|
/* // ctz & nbBytes is stored in bits[n]
|
||||||
|
* // nbBits is stored in %rax
|
||||||
|
* ctz = CTZ[bits[n]]
|
||||||
|
* nbBits = ctz & 7
|
||||||
|
* nbBytes = ctz >> 3
|
||||||
|
* op[n] += 5
|
||||||
|
* ip[n] -= nbBytes
|
||||||
|
* // Note: x86-64 is little-endian ==> no bswap
|
||||||
|
* bits[n] = MEM_readST(ip[n]) | 1
|
||||||
|
* bits[n] <<= nbBits
|
||||||
|
*/
|
||||||
|
#define RELOAD_BITS(n) \
|
||||||
|
bsfq %bits##n, %bits##n; \
|
||||||
|
movq %bits##n, %rax; \
|
||||||
|
andq $7, %rax; \
|
||||||
|
shrq $3, %bits##n; \
|
||||||
|
leaq 5(%op##n), %op##n; \
|
||||||
|
subq %bits##n, %ip##n; \
|
||||||
|
movq (%ip##n), %bits##n; \
|
||||||
|
orq $1, %bits##n; \
|
||||||
|
shlx %rax, %bits##n, %bits##n
|
||||||
|
|
||||||
|
/* Store clobbered variables on the stack */
|
||||||
|
movq %olimit, 24(%rsp)
|
||||||
|
movq %ip1, 0(%rsp)
|
||||||
|
movq %ip2, 8(%rsp)
|
||||||
|
movq %ip3, 16(%rsp)
|
||||||
|
|
||||||
|
/* Call GET_NEXT_DELT for each stream */
|
||||||
|
FOR_EACH_STREAM(GET_NEXT_DELT)
|
||||||
|
|
||||||
|
.p2align 6
|
||||||
|
|
||||||
|
.L_4X1_loop_body:
|
||||||
|
/* Decode 5 symbols in each of the 4 streams (20 total)
|
||||||
|
* Must have called GET_NEXT_DELT for each stream
|
||||||
|
*/
|
||||||
|
FOR_EACH_STREAM_WITH_INDEX(DECODE_AND_GET_NEXT, 0)
|
||||||
|
FOR_EACH_STREAM_WITH_INDEX(DECODE_AND_GET_NEXT, 1)
|
||||||
|
FOR_EACH_STREAM_WITH_INDEX(DECODE_AND_GET_NEXT, 2)
|
||||||
|
FOR_EACH_STREAM_WITH_INDEX(DECODE_AND_GET_NEXT, 3)
|
||||||
|
FOR_EACH_STREAM_WITH_INDEX(DECODE_FROM_DELT, 4)
|
||||||
|
|
||||||
|
/* Load ip[1,2,3] from stack (var[] aliases them)
|
||||||
|
* ip[] is needed for RELOAD_BITS
|
||||||
|
* Each will be stored back to the stack after RELOAD
|
||||||
|
*/
|
||||||
|
movq 0(%rsp), %ip1
|
||||||
|
movq 8(%rsp), %ip2
|
||||||
|
movq 16(%rsp), %ip3
|
||||||
|
|
||||||
|
/* Reload each stream & fetch the next table entry
|
||||||
|
* to prepare for the next iteration
|
||||||
|
*/
|
||||||
|
RELOAD_BITS(0)
|
||||||
|
GET_NEXT_DELT(0)
|
||||||
|
|
||||||
|
RELOAD_BITS(1)
|
||||||
|
movq %ip1, 0(%rsp)
|
||||||
|
GET_NEXT_DELT(1)
|
||||||
|
|
||||||
|
RELOAD_BITS(2)
|
||||||
|
movq %ip2, 8(%rsp)
|
||||||
|
GET_NEXT_DELT(2)
|
||||||
|
|
||||||
|
RELOAD_BITS(3)
|
||||||
|
movq %ip3, 16(%rsp)
|
||||||
|
GET_NEXT_DELT(3)
|
||||||
|
|
||||||
|
/* If op3 < olimit: continue the loop */
|
||||||
|
cmp %op3, 24(%rsp)
|
||||||
|
ja .L_4X1_loop_body
|
||||||
|
|
||||||
|
/* Reload ip[1,2,3] from stack */
|
||||||
|
movq 0(%rsp), %ip1
|
||||||
|
movq 8(%rsp), %ip2
|
||||||
|
movq 16(%rsp), %ip3
|
||||||
|
|
||||||
|
/* Re-compute olimit */
|
||||||
|
jmp .L_4X1_compute_olimit
|
||||||
|
|
||||||
|
#undef GET_NEXT_DELT
|
||||||
|
#undef DECODE_FROM_DELT
|
||||||
|
#undef DECODE
|
||||||
|
#undef RELOAD_BITS
|
||||||
|
.L_4X1_exit:
|
||||||
|
addq $24, %rsp
|
||||||
|
|
||||||
|
/* Restore stack (oend & olimit) */
|
||||||
|
pop %rax /* olimit */
|
||||||
|
pop %rax /* oend */
|
||||||
|
pop %rax /* ilimit */
|
||||||
|
pop %rax /* arg */
|
||||||
|
|
||||||
|
/* Save ip / op / bits */
|
||||||
|
movq %ip0, 0(%rax)
|
||||||
|
movq %ip1, 8(%rax)
|
||||||
|
movq %ip2, 16(%rax)
|
||||||
|
movq %ip3, 24(%rax)
|
||||||
|
movq %op0, 32(%rax)
|
||||||
|
movq %op1, 40(%rax)
|
||||||
|
movq %op2, 48(%rax)
|
||||||
|
movq %op3, 56(%rax)
|
||||||
|
movq %bits0, 64(%rax)
|
||||||
|
movq %bits1, 72(%rax)
|
||||||
|
movq %bits2, 80(%rax)
|
||||||
|
movq %bits3, 88(%rax)
|
||||||
|
|
||||||
|
/* Restore registers */
|
||||||
|
pop %r15
|
||||||
|
pop %r14
|
||||||
|
pop %r13
|
||||||
|
pop %r12
|
||||||
|
pop %r11
|
||||||
|
pop %r10
|
||||||
|
pop %r9
|
||||||
|
pop %r8
|
||||||
|
pop %rdi
|
||||||
|
pop %rsi
|
||||||
|
pop %rbp
|
||||||
|
pop %rdx
|
||||||
|
pop %rcx
|
||||||
|
pop %rbx
|
||||||
|
pop %rax
|
||||||
|
ret
|
||||||
|
|
||||||
|
_HUF_decompress4X2_usingDTable_internal_fast_asm_loop:
|
||||||
|
HUF_decompress4X2_usingDTable_internal_fast_asm_loop:
|
||||||
|
ZSTD_CET_ENDBRANCH
|
||||||
|
/* Save all registers - even if they are callee saved for simplicity. */
|
||||||
|
push %rax
|
||||||
|
push %rbx
|
||||||
|
push %rcx
|
||||||
|
push %rdx
|
||||||
|
push %rbp
|
||||||
|
push %rsi
|
||||||
|
push %rdi
|
||||||
|
push %r8
|
||||||
|
push %r9
|
||||||
|
push %r10
|
||||||
|
push %r11
|
||||||
|
push %r12
|
||||||
|
push %r13
|
||||||
|
push %r14
|
||||||
|
push %r15
|
||||||
|
|
||||||
|
movq %rdi, %rax
|
||||||
|
movq 0(%rax), %ip0
|
||||||
|
movq 8(%rax), %ip1
|
||||||
|
movq 16(%rax), %ip2
|
||||||
|
movq 24(%rax), %ip3
|
||||||
|
movq 32(%rax), %op0
|
||||||
|
movq 40(%rax), %op1
|
||||||
|
movq 48(%rax), %op2
|
||||||
|
movq 56(%rax), %op3
|
||||||
|
movq 64(%rax), %bits0
|
||||||
|
movq 72(%rax), %bits1
|
||||||
|
movq 80(%rax), %bits2
|
||||||
|
movq 88(%rax), %bits3
|
||||||
|
movq 96(%rax), %dtable
|
||||||
|
push %rax /* argument */
|
||||||
|
push %rax /* olimit */
|
||||||
|
push 104(%rax) /* ilimit */
|
||||||
|
|
||||||
|
movq 112(%rax), %rax
|
||||||
|
push %rax /* oend3 */
|
||||||
|
|
||||||
|
movq %op3, %rax
|
||||||
|
push %rax /* oend2 */
|
||||||
|
|
||||||
|
movq %op2, %rax
|
||||||
|
push %rax /* oend1 */
|
||||||
|
|
||||||
|
movq %op1, %rax
|
||||||
|
push %rax /* oend0 */
|
||||||
|
|
||||||
|
/* Scratch space */
|
||||||
|
subq $8, %rsp
|
||||||
|
|
||||||
|
.L_4X2_compute_olimit:
|
||||||
|
/* Computes how many iterations we can do safely
|
||||||
|
* %r15, %rax may be clobbered
|
||||||
|
* rdx must be saved
|
||||||
|
* op[1,2,3,4] & ip0 mustn't be clobbered
|
||||||
|
*/
|
||||||
|
movq %rdx, 0(%rsp)
|
||||||
|
|
||||||
|
/* We can consume up to 7 input bytes each iteration. */
|
||||||
|
movq %ip0, %rax /* rax = ip0 */
|
||||||
|
movq 40(%rsp), %rdx /* rdx = ilimit */
|
||||||
|
subq %rdx, %rax /* rax = ip0 - ilimit */
|
||||||
|
movq %rax, %r15 /* r15 = ip0 - ilimit */
|
||||||
|
|
||||||
|
/* rdx = rax / 7 */
|
||||||
|
movabsq $2635249153387078803, %rdx
|
||||||
|
mulq %rdx
|
||||||
|
subq %rdx, %r15
|
||||||
|
shrq %r15
|
||||||
|
addq %r15, %rdx
|
||||||
|
shrq $2, %rdx
|
||||||
|
|
||||||
|
/* r15 = (ip0 - ilimit) / 7 */
|
||||||
|
movq %rdx, %r15
|
||||||
|
|
||||||
|
/* r15 = min(r15, min(oend0 - op0, oend1 - op1, oend2 - op2, oend3 - op3) / 10) */
|
||||||
|
movq 8(%rsp), %rax /* rax = oend0 */
|
||||||
|
subq %op0, %rax /* rax = oend0 - op0 */
|
||||||
|
movq 16(%rsp), %rdx /* rdx = oend1 */
|
||||||
|
subq %op1, %rdx /* rdx = oend1 - op1 */
|
||||||
|
|
||||||
|
cmpq %rax, %rdx
|
||||||
|
cmova %rax, %rdx /* rdx = min(%rdx, %rax) */
|
||||||
|
|
||||||
|
movq 24(%rsp), %rax /* rax = oend2 */
|
||||||
|
subq %op2, %rax /* rax = oend2 - op2 */
|
||||||
|
|
||||||
|
cmpq %rax, %rdx
|
||||||
|
cmova %rax, %rdx /* rdx = min(%rdx, %rax) */
|
||||||
|
|
||||||
|
movq 32(%rsp), %rax /* rax = oend3 */
|
||||||
|
subq %op3, %rax /* rax = oend3 - op3 */
|
||||||
|
|
||||||
|
cmpq %rax, %rdx
|
||||||
|
cmova %rax, %rdx /* rdx = min(%rdx, %rax) */
|
||||||
|
|
||||||
|
movabsq $-3689348814741910323, %rax
|
||||||
|
mulq %rdx
|
||||||
|
shrq $3, %rdx /* rdx = rdx / 10 */
|
||||||
|
|
||||||
|
/* r15 = min(%rdx, %r15) */
|
||||||
|
cmpq %rdx, %r15
|
||||||
|
cmova %rdx, %r15
|
||||||
|
|
||||||
|
/* olimit = op3 + 5 * r15 */
|
||||||
|
movq %r15, %rax
|
||||||
|
leaq (%op3, %rax, 4), %olimit
|
||||||
|
addq %rax, %olimit
|
||||||
|
|
||||||
|
movq 0(%rsp), %rdx
|
||||||
|
|
||||||
|
/* If (op3 + 10 > olimit) */
|
||||||
|
movq %op3, %rax /* rax = op3 */
|
||||||
|
addq $10, %rax /* rax = op3 + 10 */
|
||||||
|
cmpq %rax, %olimit /* op3 + 10 > olimit */
|
||||||
|
jb .L_4X2_exit
|
||||||
|
|
||||||
|
/* If (ip1 < ip0) go to exit */
|
||||||
|
cmpq %ip0, %ip1
|
||||||
|
jb .L_4X2_exit
|
||||||
|
|
||||||
|
/* If (ip2 < ip1) go to exit */
|
||||||
|
cmpq %ip1, %ip2
|
||||||
|
jb .L_4X2_exit
|
||||||
|
|
||||||
|
/* If (ip3 < ip2) go to exit */
|
||||||
|
cmpq %ip2, %ip3
|
||||||
|
jb .L_4X2_exit
|
||||||
|
|
||||||
|
#define DECODE(n, idx) \
|
||||||
|
movq %bits##n, %rax; \
|
||||||
|
shrq $53, %rax; \
|
||||||
|
movzwl 0(%dtable,%rax,4),%r8d; \
|
||||||
|
movzbl 2(%dtable,%rax,4),%r15d; \
|
||||||
|
movzbl 3(%dtable,%rax,4),%eax; \
|
||||||
|
movw %r8w, (%op##n); \
|
||||||
|
shlxq %r15, %bits##n, %bits##n; \
|
||||||
|
addq %rax, %op##n
|
||||||
|
|
||||||
|
#define RELOAD_BITS(n) \
|
||||||
|
bsfq %bits##n, %bits##n; \
|
||||||
|
movq %bits##n, %rax; \
|
||||||
|
shrq $3, %bits##n; \
|
||||||
|
andq $7, %rax; \
|
||||||
|
subq %bits##n, %ip##n; \
|
||||||
|
movq (%ip##n), %bits##n; \
|
||||||
|
orq $1, %bits##n; \
|
||||||
|
shlxq %rax, %bits##n, %bits##n
|
||||||
|
|
||||||
|
|
||||||
|
movq %olimit, 48(%rsp)
|
||||||
|
|
||||||
|
.p2align 6
|
||||||
|
|
||||||
|
.L_4X2_loop_body:
|
||||||
|
/* We clobber r8, so store it on the stack */
|
||||||
|
movq %r8, 0(%rsp)
|
||||||
|
|
||||||
|
/* Decode 5 symbols from each of the 4 streams (20 symbols total). */
|
||||||
|
FOR_EACH_STREAM_WITH_INDEX(DECODE, 0)
|
||||||
|
FOR_EACH_STREAM_WITH_INDEX(DECODE, 1)
|
||||||
|
FOR_EACH_STREAM_WITH_INDEX(DECODE, 2)
|
||||||
|
FOR_EACH_STREAM_WITH_INDEX(DECODE, 3)
|
||||||
|
FOR_EACH_STREAM_WITH_INDEX(DECODE, 4)
|
||||||
|
|
||||||
|
/* Reload r8 */
|
||||||
|
movq 0(%rsp), %r8
|
||||||
|
|
||||||
|
FOR_EACH_STREAM(RELOAD_BITS)
|
||||||
|
|
||||||
|
cmp %op3, 48(%rsp)
|
||||||
|
ja .L_4X2_loop_body
|
||||||
|
jmp .L_4X2_compute_olimit
|
||||||
|
|
||||||
|
#undef DECODE
|
||||||
|
#undef RELOAD_BITS
|
||||||
|
.L_4X2_exit:
|
||||||
|
addq $8, %rsp
|
||||||
|
/* Restore stack (oend & olimit) */
|
||||||
|
pop %rax /* oend0 */
|
||||||
|
pop %rax /* oend1 */
|
||||||
|
pop %rax /* oend2 */
|
||||||
|
pop %rax /* oend3 */
|
||||||
|
pop %rax /* ilimit */
|
||||||
|
pop %rax /* olimit */
|
||||||
|
pop %rax /* arg */
|
||||||
|
|
||||||
|
/* Save ip / op / bits */
|
||||||
|
movq %ip0, 0(%rax)
|
||||||
|
movq %ip1, 8(%rax)
|
||||||
|
movq %ip2, 16(%rax)
|
||||||
|
movq %ip3, 24(%rax)
|
||||||
|
movq %op0, 32(%rax)
|
||||||
|
movq %op1, 40(%rax)
|
||||||
|
movq %op2, 48(%rax)
|
||||||
|
movq %op3, 56(%rax)
|
||||||
|
movq %bits0, 64(%rax)
|
||||||
|
movq %bits1, 72(%rax)
|
||||||
|
movq %bits2, 80(%rax)
|
||||||
|
movq %bits3, 88(%rax)
|
||||||
|
|
||||||
|
/* Restore registers */
|
||||||
|
pop %r15
|
||||||
|
pop %r14
|
||||||
|
pop %r13
|
||||||
|
pop %r12
|
||||||
|
pop %r11
|
||||||
|
pop %r10
|
||||||
|
pop %r9
|
||||||
|
pop %r8
|
||||||
|
pop %rdi
|
||||||
|
pop %rsi
|
||||||
|
pop %rbp
|
||||||
|
pop %rdx
|
||||||
|
pop %rcx
|
||||||
|
pop %rbx
|
||||||
|
pop %rax
|
||||||
|
ret
|
||||||
|
|
||||||
|
#endif
|
||||||
267
vendor/github.com/DataDog/zstd/mem.h
generated
vendored
267
vendor/github.com/DataDog/zstd/mem.h
generated
vendored
@@ -1,5 +1,6 @@
|
|||||||
|
#ifndef USE_EXTERNAL_ZSTD
|
||||||
/*
|
/*
|
||||||
* Copyright (c) 2016-present, Yann Collet, Facebook, Inc.
|
* Copyright (c) Meta Platforms, Inc. and affiliates.
|
||||||
* All rights reserved.
|
* All rights reserved.
|
||||||
*
|
*
|
||||||
* This source code is licensed under both the BSD-style license (found in the
|
* This source code is licensed under both the BSD-style license (found in the
|
||||||
@@ -19,7 +20,9 @@ extern "C" {
|
|||||||
* Dependencies
|
* Dependencies
|
||||||
******************************************/
|
******************************************/
|
||||||
#include <stddef.h> /* size_t, ptrdiff_t */
|
#include <stddef.h> /* size_t, ptrdiff_t */
|
||||||
#include <string.h> /* memcpy */
|
#include "compiler.h" /* __has_builtin */
|
||||||
|
#include "debug.h" /* DEBUG_STATIC_ASSERT */
|
||||||
|
#include "zstd_deps.h" /* ZSTD_memcpy */
|
||||||
|
|
||||||
|
|
||||||
/*-****************************************
|
/*-****************************************
|
||||||
@@ -39,94 +42,18 @@ extern "C" {
|
|||||||
# define MEM_STATIC static /* this version may generate warnings for unused static functions; disable the relevant warning */
|
# define MEM_STATIC static /* this version may generate warnings for unused static functions; disable the relevant warning */
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#ifndef __has_builtin
|
|
||||||
# define __has_builtin(x) 0 /* compat. with non-clang compilers */
|
|
||||||
#endif
|
|
||||||
|
|
||||||
/* code only tested on 32 and 64 bits systems */
|
|
||||||
#define MEM_STATIC_ASSERT(c) { enum { MEM_static_assert = 1/(int)(!!(c)) }; }
|
|
||||||
MEM_STATIC void MEM_check(void) { MEM_STATIC_ASSERT((sizeof(size_t)==4) || (sizeof(size_t)==8)); }
|
|
||||||
|
|
||||||
/* detects whether we are being compiled under msan */
|
|
||||||
#if defined (__has_feature)
|
|
||||||
# if __has_feature(memory_sanitizer)
|
|
||||||
# define MEMORY_SANITIZER 1
|
|
||||||
# endif
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#if defined (MEMORY_SANITIZER)
|
|
||||||
/* Not all platforms that support msan provide sanitizers/msan_interface.h.
|
|
||||||
* We therefore declare the functions we need ourselves, rather than trying to
|
|
||||||
* include the header file... */
|
|
||||||
|
|
||||||
#include <stdint.h> /* intptr_t */
|
|
||||||
|
|
||||||
/* Make memory region fully initialized (without changing its contents). */
|
|
||||||
void __msan_unpoison(const volatile void *a, size_t size);
|
|
||||||
|
|
||||||
/* Make memory region fully uninitialized (without changing its contents).
|
|
||||||
This is a legacy interface that does not update origin information. Use
|
|
||||||
__msan_allocated_memory() instead. */
|
|
||||||
void __msan_poison(const volatile void *a, size_t size);
|
|
||||||
|
|
||||||
/* Returns the offset of the first (at least partially) poisoned byte in the
|
|
||||||
memory range, or -1 if the whole range is good. */
|
|
||||||
intptr_t __msan_test_shadow(const volatile void *x, size_t size);
|
|
||||||
#endif
|
|
||||||
|
|
||||||
/* detects whether we are being compiled under asan */
|
|
||||||
#if defined (__has_feature)
|
|
||||||
# if __has_feature(address_sanitizer)
|
|
||||||
# define ADDRESS_SANITIZER 1
|
|
||||||
# endif
|
|
||||||
#elif defined(__SANITIZE_ADDRESS__)
|
|
||||||
# define ADDRESS_SANITIZER 1
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#if defined (ADDRESS_SANITIZER)
|
|
||||||
/* Not all platforms that support asan provide sanitizers/asan_interface.h.
|
|
||||||
* We therefore declare the functions we need ourselves, rather than trying to
|
|
||||||
* include the header file... */
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Marks a memory region (<c>[addr, addr+size)</c>) as unaddressable.
|
|
||||||
*
|
|
||||||
* This memory must be previously allocated by your program. Instrumented
|
|
||||||
* code is forbidden from accessing addresses in this region until it is
|
|
||||||
* unpoisoned. This function is not guaranteed to poison the entire region -
|
|
||||||
* it could poison only a subregion of <c>[addr, addr+size)</c> due to ASan
|
|
||||||
* alignment restrictions.
|
|
||||||
*
|
|
||||||
* \note This function is not thread-safe because no two threads can poison or
|
|
||||||
* unpoison memory in the same memory region simultaneously.
|
|
||||||
*
|
|
||||||
* \param addr Start of memory region.
|
|
||||||
* \param size Size of memory region. */
|
|
||||||
void __asan_poison_memory_region(void const volatile *addr, size_t size);
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Marks a memory region (<c>[addr, addr+size)</c>) as addressable.
|
|
||||||
*
|
|
||||||
* This memory must be previously allocated by your program. Accessing
|
|
||||||
* addresses in this region is allowed until this region is poisoned again.
|
|
||||||
* This function could unpoison a super-region of <c>[addr, addr+size)</c> due
|
|
||||||
* to ASan alignment restrictions.
|
|
||||||
*
|
|
||||||
* \note This function is not thread-safe because no two threads can
|
|
||||||
* poison or unpoison memory in the same memory region simultaneously.
|
|
||||||
*
|
|
||||||
* \param addr Start of memory region.
|
|
||||||
* \param size Size of memory region. */
|
|
||||||
void __asan_unpoison_memory_region(void const volatile *addr, size_t size);
|
|
||||||
#endif
|
|
||||||
|
|
||||||
|
|
||||||
/*-**************************************************************
|
/*-**************************************************************
|
||||||
* Basic Types
|
* Basic Types
|
||||||
*****************************************************************/
|
*****************************************************************/
|
||||||
#if !defined (__VMS) && (defined (__cplusplus) || (defined (__STDC_VERSION__) && (__STDC_VERSION__ >= 199901L) /* C99 */) )
|
#if !defined (__VMS) && (defined (__cplusplus) || (defined (__STDC_VERSION__) && (__STDC_VERSION__ >= 199901L) /* C99 */) )
|
||||||
# include <stdint.h>
|
# if defined(_AIX)
|
||||||
|
# include <inttypes.h>
|
||||||
|
# else
|
||||||
|
# include <stdint.h> /* intptr_t */
|
||||||
|
# endif
|
||||||
typedef uint8_t BYTE;
|
typedef uint8_t BYTE;
|
||||||
|
typedef uint8_t U8;
|
||||||
|
typedef int8_t S8;
|
||||||
typedef uint16_t U16;
|
typedef uint16_t U16;
|
||||||
typedef int16_t S16;
|
typedef int16_t S16;
|
||||||
typedef uint32_t U32;
|
typedef uint32_t U32;
|
||||||
@@ -139,6 +66,8 @@ void __asan_unpoison_memory_region(void const volatile *addr, size_t size);
|
|||||||
# error "this implementation requires char to be exactly 8-bit type"
|
# error "this implementation requires char to be exactly 8-bit type"
|
||||||
#endif
|
#endif
|
||||||
typedef unsigned char BYTE;
|
typedef unsigned char BYTE;
|
||||||
|
typedef unsigned char U8;
|
||||||
|
typedef signed char S8;
|
||||||
#if USHRT_MAX != 65535
|
#if USHRT_MAX != 65535
|
||||||
# error "this implementation requires short to be exactly 16-bit type"
|
# error "this implementation requires short to be exactly 16-bit type"
|
||||||
#endif
|
#endif
|
||||||
@@ -157,25 +86,63 @@ void __asan_unpoison_memory_region(void const volatile *addr, size_t size);
|
|||||||
|
|
||||||
|
|
||||||
/*-**************************************************************
|
/*-**************************************************************
|
||||||
* Memory I/O
|
* Memory I/O API
|
||||||
*****************************************************************/
|
*****************************************************************/
|
||||||
/* MEM_FORCE_MEMORY_ACCESS :
|
/*=== Static platform detection ===*/
|
||||||
* By default, access to unaligned memory is controlled by `memcpy()`, which is safe and portable.
|
MEM_STATIC unsigned MEM_32bits(void);
|
||||||
* Unfortunately, on some target/compiler combinations, the generated assembly is sub-optimal.
|
MEM_STATIC unsigned MEM_64bits(void);
|
||||||
* The below switch allow to select different access method for improved performance.
|
MEM_STATIC unsigned MEM_isLittleEndian(void);
|
||||||
* Method 0 (default) : use `memcpy()`. Safe and portable.
|
|
||||||
* Method 1 : `__packed` statement. It depends on compiler extension (i.e., not portable).
|
/*=== Native unaligned read/write ===*/
|
||||||
* This method is safe if your compiler supports it, and *generally* as fast or faster than `memcpy`.
|
MEM_STATIC U16 MEM_read16(const void* memPtr);
|
||||||
|
MEM_STATIC U32 MEM_read32(const void* memPtr);
|
||||||
|
MEM_STATIC U64 MEM_read64(const void* memPtr);
|
||||||
|
MEM_STATIC size_t MEM_readST(const void* memPtr);
|
||||||
|
|
||||||
|
MEM_STATIC void MEM_write16(void* memPtr, U16 value);
|
||||||
|
MEM_STATIC void MEM_write32(void* memPtr, U32 value);
|
||||||
|
MEM_STATIC void MEM_write64(void* memPtr, U64 value);
|
||||||
|
|
||||||
|
/*=== Little endian unaligned read/write ===*/
|
||||||
|
MEM_STATIC U16 MEM_readLE16(const void* memPtr);
|
||||||
|
MEM_STATIC U32 MEM_readLE24(const void* memPtr);
|
||||||
|
MEM_STATIC U32 MEM_readLE32(const void* memPtr);
|
||||||
|
MEM_STATIC U64 MEM_readLE64(const void* memPtr);
|
||||||
|
MEM_STATIC size_t MEM_readLEST(const void* memPtr);
|
||||||
|
|
||||||
|
MEM_STATIC void MEM_writeLE16(void* memPtr, U16 val);
|
||||||
|
MEM_STATIC void MEM_writeLE24(void* memPtr, U32 val);
|
||||||
|
MEM_STATIC void MEM_writeLE32(void* memPtr, U32 val32);
|
||||||
|
MEM_STATIC void MEM_writeLE64(void* memPtr, U64 val64);
|
||||||
|
MEM_STATIC void MEM_writeLEST(void* memPtr, size_t val);
|
||||||
|
|
||||||
|
/*=== Big endian unaligned read/write ===*/
|
||||||
|
MEM_STATIC U32 MEM_readBE32(const void* memPtr);
|
||||||
|
MEM_STATIC U64 MEM_readBE64(const void* memPtr);
|
||||||
|
MEM_STATIC size_t MEM_readBEST(const void* memPtr);
|
||||||
|
|
||||||
|
MEM_STATIC void MEM_writeBE32(void* memPtr, U32 val32);
|
||||||
|
MEM_STATIC void MEM_writeBE64(void* memPtr, U64 val64);
|
||||||
|
MEM_STATIC void MEM_writeBEST(void* memPtr, size_t val);
|
||||||
|
|
||||||
|
/*=== Byteswap ===*/
|
||||||
|
MEM_STATIC U32 MEM_swap32(U32 in);
|
||||||
|
MEM_STATIC U64 MEM_swap64(U64 in);
|
||||||
|
MEM_STATIC size_t MEM_swapST(size_t in);
|
||||||
|
|
||||||
|
|
||||||
|
/*-**************************************************************
|
||||||
|
* Memory I/O Implementation
|
||||||
|
*****************************************************************/
|
||||||
|
/* MEM_FORCE_MEMORY_ACCESS : For accessing unaligned memory:
|
||||||
|
* Method 0 : always use `memcpy()`. Safe and portable.
|
||||||
|
* Method 1 : Use compiler extension to set unaligned access.
|
||||||
* Method 2 : direct access. This method is portable but violate C standard.
|
* Method 2 : direct access. This method is portable but violate C standard.
|
||||||
* It can generate buggy code on targets depending on alignment.
|
* It can generate buggy code on targets depending on alignment.
|
||||||
* In some circumstances, it's the only known way to get the most performance (i.e. GCC + ARMv6)
|
* Default : method 1 if supported, else method 0
|
||||||
* See http://fastcompression.blogspot.fr/2015/08/accessing-unaligned-memory.html for details.
|
|
||||||
* Prefer these methods in priority order (0 > 1 > 2)
|
|
||||||
*/
|
*/
|
||||||
#ifndef MEM_FORCE_MEMORY_ACCESS /* can be defined externally, on command line for example */
|
#ifndef MEM_FORCE_MEMORY_ACCESS /* can be defined externally, on command line for example */
|
||||||
# if defined(__GNUC__) && ( defined(__ARM_ARCH_6__) || defined(__ARM_ARCH_6J__) || defined(__ARM_ARCH_6K__) || defined(__ARM_ARCH_6Z__) || defined(__ARM_ARCH_6ZK__) || defined(__ARM_ARCH_6T2__) )
|
# ifdef __GNUC__
|
||||||
# define MEM_FORCE_MEMORY_ACCESS 2
|
|
||||||
# elif defined(__INTEL_COMPILER) || defined(__GNUC__) || defined(__ICCARM__)
|
|
||||||
# define MEM_FORCE_MEMORY_ACCESS 1
|
# define MEM_FORCE_MEMORY_ACCESS 1
|
||||||
# endif
|
# endif
|
||||||
#endif
|
#endif
|
||||||
@@ -185,8 +152,22 @@ MEM_STATIC unsigned MEM_64bits(void) { return sizeof(size_t)==8; }
|
|||||||
|
|
||||||
MEM_STATIC unsigned MEM_isLittleEndian(void)
|
MEM_STATIC unsigned MEM_isLittleEndian(void)
|
||||||
{
|
{
|
||||||
|
#if defined(__BYTE_ORDER__) && defined(__ORDER_LITTLE_ENDIAN__) && (__BYTE_ORDER__ == __ORDER_LITTLE_ENDIAN__)
|
||||||
|
return 1;
|
||||||
|
#elif defined(__BYTE_ORDER__) && defined(__ORDER_BIG_ENDIAN__) && (__BYTE_ORDER__ == __ORDER_BIG_ENDIAN__)
|
||||||
|
return 0;
|
||||||
|
#elif defined(__clang__) && __LITTLE_ENDIAN__
|
||||||
|
return 1;
|
||||||
|
#elif defined(__clang__) && __BIG_ENDIAN__
|
||||||
|
return 0;
|
||||||
|
#elif defined(_MSC_VER) && (_M_AMD64 || _M_IX86)
|
||||||
|
return 1;
|
||||||
|
#elif defined(__DMC__) && defined(_M_IX86)
|
||||||
|
return 1;
|
||||||
|
#else
|
||||||
const union { U32 u; BYTE c[4]; } one = { 1 }; /* don't use static : performance detrimental */
|
const union { U32 u; BYTE c[4]; } one = { 1 }; /* don't use static : performance detrimental */
|
||||||
return one.c[0];
|
return one.c[0];
|
||||||
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
#if defined(MEM_FORCE_MEMORY_ACCESS) && (MEM_FORCE_MEMORY_ACCESS==2)
|
#if defined(MEM_FORCE_MEMORY_ACCESS) && (MEM_FORCE_MEMORY_ACCESS==2)
|
||||||
@@ -204,30 +185,19 @@ MEM_STATIC void MEM_write64(void* memPtr, U64 value) { *(U64*)memPtr = value; }
|
|||||||
|
|
||||||
#elif defined(MEM_FORCE_MEMORY_ACCESS) && (MEM_FORCE_MEMORY_ACCESS==1)
|
#elif defined(MEM_FORCE_MEMORY_ACCESS) && (MEM_FORCE_MEMORY_ACCESS==1)
|
||||||
|
|
||||||
/* __pack instructions are safer, but compiler specific, hence potentially problematic for some compilers */
|
typedef __attribute__((aligned(1))) U16 unalign16;
|
||||||
/* currently only defined for gcc and icc */
|
typedef __attribute__((aligned(1))) U32 unalign32;
|
||||||
#if defined(_MSC_VER) || (defined(__INTEL_COMPILER) && defined(WIN32))
|
typedef __attribute__((aligned(1))) U64 unalign64;
|
||||||
__pragma( pack(push, 1) )
|
typedef __attribute__((aligned(1))) size_t unalignArch;
|
||||||
typedef struct { U16 v; } unalign16;
|
|
||||||
typedef struct { U32 v; } unalign32;
|
|
||||||
typedef struct { U64 v; } unalign64;
|
|
||||||
typedef struct { size_t v; } unalignArch;
|
|
||||||
__pragma( pack(pop) )
|
|
||||||
#else
|
|
||||||
typedef struct { U16 v; } __attribute__((packed)) unalign16;
|
|
||||||
typedef struct { U32 v; } __attribute__((packed)) unalign32;
|
|
||||||
typedef struct { U64 v; } __attribute__((packed)) unalign64;
|
|
||||||
typedef struct { size_t v; } __attribute__((packed)) unalignArch;
|
|
||||||
#endif
|
|
||||||
|
|
||||||
MEM_STATIC U16 MEM_read16(const void* ptr) { return ((const unalign16*)ptr)->v; }
|
MEM_STATIC U16 MEM_read16(const void* ptr) { return *(const unalign16*)ptr; }
|
||||||
MEM_STATIC U32 MEM_read32(const void* ptr) { return ((const unalign32*)ptr)->v; }
|
MEM_STATIC U32 MEM_read32(const void* ptr) { return *(const unalign32*)ptr; }
|
||||||
MEM_STATIC U64 MEM_read64(const void* ptr) { return ((const unalign64*)ptr)->v; }
|
MEM_STATIC U64 MEM_read64(const void* ptr) { return *(const unalign64*)ptr; }
|
||||||
MEM_STATIC size_t MEM_readST(const void* ptr) { return ((const unalignArch*)ptr)->v; }
|
MEM_STATIC size_t MEM_readST(const void* ptr) { return *(const unalignArch*)ptr; }
|
||||||
|
|
||||||
MEM_STATIC void MEM_write16(void* memPtr, U16 value) { ((unalign16*)memPtr)->v = value; }
|
MEM_STATIC void MEM_write16(void* memPtr, U16 value) { *(unalign16*)memPtr = value; }
|
||||||
MEM_STATIC void MEM_write32(void* memPtr, U32 value) { ((unalign32*)memPtr)->v = value; }
|
MEM_STATIC void MEM_write32(void* memPtr, U32 value) { *(unalign32*)memPtr = value; }
|
||||||
MEM_STATIC void MEM_write64(void* memPtr, U64 value) { ((unalign64*)memPtr)->v = value; }
|
MEM_STATIC void MEM_write64(void* memPtr, U64 value) { *(unalign64*)memPtr = value; }
|
||||||
|
|
||||||
#else
|
#else
|
||||||
|
|
||||||
@@ -236,41 +206,49 @@ MEM_STATIC void MEM_write64(void* memPtr, U64 value) { ((unalign64*)memPtr)->v =
|
|||||||
|
|
||||||
MEM_STATIC U16 MEM_read16(const void* memPtr)
|
MEM_STATIC U16 MEM_read16(const void* memPtr)
|
||||||
{
|
{
|
||||||
U16 val; memcpy(&val, memPtr, sizeof(val)); return val;
|
U16 val; ZSTD_memcpy(&val, memPtr, sizeof(val)); return val;
|
||||||
}
|
}
|
||||||
|
|
||||||
MEM_STATIC U32 MEM_read32(const void* memPtr)
|
MEM_STATIC U32 MEM_read32(const void* memPtr)
|
||||||
{
|
{
|
||||||
U32 val; memcpy(&val, memPtr, sizeof(val)); return val;
|
U32 val; ZSTD_memcpy(&val, memPtr, sizeof(val)); return val;
|
||||||
}
|
}
|
||||||
|
|
||||||
MEM_STATIC U64 MEM_read64(const void* memPtr)
|
MEM_STATIC U64 MEM_read64(const void* memPtr)
|
||||||
{
|
{
|
||||||
U64 val; memcpy(&val, memPtr, sizeof(val)); return val;
|
U64 val; ZSTD_memcpy(&val, memPtr, sizeof(val)); return val;
|
||||||
}
|
}
|
||||||
|
|
||||||
MEM_STATIC size_t MEM_readST(const void* memPtr)
|
MEM_STATIC size_t MEM_readST(const void* memPtr)
|
||||||
{
|
{
|
||||||
size_t val; memcpy(&val, memPtr, sizeof(val)); return val;
|
size_t val; ZSTD_memcpy(&val, memPtr, sizeof(val)); return val;
|
||||||
}
|
}
|
||||||
|
|
||||||
MEM_STATIC void MEM_write16(void* memPtr, U16 value)
|
MEM_STATIC void MEM_write16(void* memPtr, U16 value)
|
||||||
{
|
{
|
||||||
memcpy(memPtr, &value, sizeof(value));
|
ZSTD_memcpy(memPtr, &value, sizeof(value));
|
||||||
}
|
}
|
||||||
|
|
||||||
MEM_STATIC void MEM_write32(void* memPtr, U32 value)
|
MEM_STATIC void MEM_write32(void* memPtr, U32 value)
|
||||||
{
|
{
|
||||||
memcpy(memPtr, &value, sizeof(value));
|
ZSTD_memcpy(memPtr, &value, sizeof(value));
|
||||||
}
|
}
|
||||||
|
|
||||||
MEM_STATIC void MEM_write64(void* memPtr, U64 value)
|
MEM_STATIC void MEM_write64(void* memPtr, U64 value)
|
||||||
{
|
{
|
||||||
memcpy(memPtr, &value, sizeof(value));
|
ZSTD_memcpy(memPtr, &value, sizeof(value));
|
||||||
}
|
}
|
||||||
|
|
||||||
#endif /* MEM_FORCE_MEMORY_ACCESS */
|
#endif /* MEM_FORCE_MEMORY_ACCESS */
|
||||||
|
|
||||||
|
MEM_STATIC U32 MEM_swap32_fallback(U32 in)
|
||||||
|
{
|
||||||
|
return ((in << 24) & 0xff000000 ) |
|
||||||
|
((in << 8) & 0x00ff0000 ) |
|
||||||
|
((in >> 8) & 0x0000ff00 ) |
|
||||||
|
((in >> 24) & 0x000000ff );
|
||||||
|
}
|
||||||
|
|
||||||
MEM_STATIC U32 MEM_swap32(U32 in)
|
MEM_STATIC U32 MEM_swap32(U32 in)
|
||||||
{
|
{
|
||||||
#if defined(_MSC_VER) /* Visual Studio */
|
#if defined(_MSC_VER) /* Visual Studio */
|
||||||
@@ -279,13 +257,22 @@ MEM_STATIC U32 MEM_swap32(U32 in)
|
|||||||
|| (defined(__clang__) && __has_builtin(__builtin_bswap32))
|
|| (defined(__clang__) && __has_builtin(__builtin_bswap32))
|
||||||
return __builtin_bswap32(in);
|
return __builtin_bswap32(in);
|
||||||
#else
|
#else
|
||||||
return ((in << 24) & 0xff000000 ) |
|
return MEM_swap32_fallback(in);
|
||||||
((in << 8) & 0x00ff0000 ) |
|
|
||||||
((in >> 8) & 0x0000ff00 ) |
|
|
||||||
((in >> 24) & 0x000000ff );
|
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
|
MEM_STATIC U64 MEM_swap64_fallback(U64 in)
|
||||||
|
{
|
||||||
|
return ((in << 56) & 0xff00000000000000ULL) |
|
||||||
|
((in << 40) & 0x00ff000000000000ULL) |
|
||||||
|
((in << 24) & 0x0000ff0000000000ULL) |
|
||||||
|
((in << 8) & 0x000000ff00000000ULL) |
|
||||||
|
((in >> 8) & 0x00000000ff000000ULL) |
|
||||||
|
((in >> 24) & 0x0000000000ff0000ULL) |
|
||||||
|
((in >> 40) & 0x000000000000ff00ULL) |
|
||||||
|
((in >> 56) & 0x00000000000000ffULL);
|
||||||
|
}
|
||||||
|
|
||||||
MEM_STATIC U64 MEM_swap64(U64 in)
|
MEM_STATIC U64 MEM_swap64(U64 in)
|
||||||
{
|
{
|
||||||
#if defined(_MSC_VER) /* Visual Studio */
|
#if defined(_MSC_VER) /* Visual Studio */
|
||||||
@@ -294,14 +281,7 @@ MEM_STATIC U64 MEM_swap64(U64 in)
|
|||||||
|| (defined(__clang__) && __has_builtin(__builtin_bswap64))
|
|| (defined(__clang__) && __has_builtin(__builtin_bswap64))
|
||||||
return __builtin_bswap64(in);
|
return __builtin_bswap64(in);
|
||||||
#else
|
#else
|
||||||
return ((in << 56) & 0xff00000000000000ULL) |
|
return MEM_swap64_fallback(in);
|
||||||
((in << 40) & 0x00ff000000000000ULL) |
|
|
||||||
((in << 24) & 0x0000ff0000000000ULL) |
|
|
||||||
((in << 8) & 0x000000ff00000000ULL) |
|
|
||||||
((in >> 8) & 0x00000000ff000000ULL) |
|
|
||||||
((in >> 24) & 0x0000000000ff0000ULL) |
|
|
||||||
((in >> 40) & 0x000000000000ff00ULL) |
|
|
||||||
((in >> 56) & 0x00000000000000ffULL);
|
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -338,7 +318,7 @@ MEM_STATIC void MEM_writeLE16(void* memPtr, U16 val)
|
|||||||
|
|
||||||
MEM_STATIC U32 MEM_readLE24(const void* memPtr)
|
MEM_STATIC U32 MEM_readLE24(const void* memPtr)
|
||||||
{
|
{
|
||||||
return MEM_readLE16(memPtr) + (((const BYTE*)memPtr)[2] << 16);
|
return (U32)MEM_readLE16(memPtr) + ((U32)(((const BYTE*)memPtr)[2]) << 16);
|
||||||
}
|
}
|
||||||
|
|
||||||
MEM_STATIC void MEM_writeLE24(void* memPtr, U32 val)
|
MEM_STATIC void MEM_writeLE24(void* memPtr, U32 val)
|
||||||
@@ -445,9 +425,14 @@ MEM_STATIC void MEM_writeBEST(void* memPtr, size_t val)
|
|||||||
MEM_writeBE64(memPtr, (U64)val);
|
MEM_writeBE64(memPtr, (U64)val);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* code only tested on 32 and 64 bits systems */
|
||||||
|
MEM_STATIC void MEM_check(void) { DEBUG_STATIC_ASSERT((sizeof(size_t)==4) || (sizeof(size_t)==8)); }
|
||||||
|
|
||||||
|
|
||||||
#if defined (__cplusplus)
|
#if defined (__cplusplus)
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#endif /* MEM_H_MODULE */
|
#endif /* MEM_H_MODULE */
|
||||||
|
|
||||||
|
#endif /* USE_EXTERNAL_ZSTD */
|
||||||
|
|||||||
82
vendor/github.com/DataDog/zstd/pool.c
generated
vendored
82
vendor/github.com/DataDog/zstd/pool.c
generated
vendored
@@ -1,5 +1,6 @@
|
|||||||
|
#ifndef USE_EXTERNAL_ZSTD
|
||||||
/*
|
/*
|
||||||
* Copyright (c) 2016-present, Yann Collet, Facebook, Inc.
|
* Copyright (c) Meta Platforms, Inc. and affiliates.
|
||||||
* All rights reserved.
|
* All rights reserved.
|
||||||
*
|
*
|
||||||
* This source code is licensed under both the BSD-style license (found in the
|
* This source code is licensed under both the BSD-style license (found in the
|
||||||
@@ -10,9 +11,9 @@
|
|||||||
|
|
||||||
|
|
||||||
/* ====== Dependencies ======= */
|
/* ====== Dependencies ======= */
|
||||||
#include <stddef.h> /* size_t */
|
#include "allocations.h" /* ZSTD_customCalloc, ZSTD_customFree */
|
||||||
|
#include "zstd_deps.h" /* size_t */
|
||||||
#include "debug.h" /* assert */
|
#include "debug.h" /* assert */
|
||||||
#include "zstd_internal.h" /* ZSTD_malloc, ZSTD_free */
|
|
||||||
#include "pool.h"
|
#include "pool.h"
|
||||||
|
|
||||||
/* ====== Compiler specifics ====== */
|
/* ====== Compiler specifics ====== */
|
||||||
@@ -86,7 +87,7 @@ static void* POOL_thread(void* opaque) {
|
|||||||
{ POOL_job const job = ctx->queue[ctx->queueHead];
|
{ POOL_job const job = ctx->queue[ctx->queueHead];
|
||||||
ctx->queueHead = (ctx->queueHead + 1) % ctx->queueSize;
|
ctx->queueHead = (ctx->queueHead + 1) % ctx->queueSize;
|
||||||
ctx->numThreadsBusy++;
|
ctx->numThreadsBusy++;
|
||||||
ctx->queueEmpty = ctx->queueHead == ctx->queueTail;
|
ctx->queueEmpty = (ctx->queueHead == ctx->queueTail);
|
||||||
/* Unlock the mutex, signal a pusher, and run the job */
|
/* Unlock the mutex, signal a pusher, and run the job */
|
||||||
ZSTD_pthread_cond_signal(&ctx->queuePushCond);
|
ZSTD_pthread_cond_signal(&ctx->queuePushCond);
|
||||||
ZSTD_pthread_mutex_unlock(&ctx->queueMutex);
|
ZSTD_pthread_mutex_unlock(&ctx->queueMutex);
|
||||||
@@ -96,33 +97,37 @@ static void* POOL_thread(void* opaque) {
|
|||||||
/* If the intended queue size was 0, signal after finishing job */
|
/* If the intended queue size was 0, signal after finishing job */
|
||||||
ZSTD_pthread_mutex_lock(&ctx->queueMutex);
|
ZSTD_pthread_mutex_lock(&ctx->queueMutex);
|
||||||
ctx->numThreadsBusy--;
|
ctx->numThreadsBusy--;
|
||||||
if (ctx->queueSize == 1) {
|
|
||||||
ZSTD_pthread_cond_signal(&ctx->queuePushCond);
|
ZSTD_pthread_cond_signal(&ctx->queuePushCond);
|
||||||
}
|
|
||||||
ZSTD_pthread_mutex_unlock(&ctx->queueMutex);
|
ZSTD_pthread_mutex_unlock(&ctx->queueMutex);
|
||||||
}
|
}
|
||||||
} /* for (;;) */
|
} /* for (;;) */
|
||||||
assert(0); /* Unreachable */
|
assert(0); /* Unreachable */
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* ZSTD_createThreadPool() : public access point */
|
||||||
|
POOL_ctx* ZSTD_createThreadPool(size_t numThreads) {
|
||||||
|
return POOL_create (numThreads, 0);
|
||||||
|
}
|
||||||
|
|
||||||
POOL_ctx* POOL_create(size_t numThreads, size_t queueSize) {
|
POOL_ctx* POOL_create(size_t numThreads, size_t queueSize) {
|
||||||
return POOL_create_advanced(numThreads, queueSize, ZSTD_defaultCMem);
|
return POOL_create_advanced(numThreads, queueSize, ZSTD_defaultCMem);
|
||||||
}
|
}
|
||||||
|
|
||||||
POOL_ctx* POOL_create_advanced(size_t numThreads, size_t queueSize,
|
POOL_ctx* POOL_create_advanced(size_t numThreads, size_t queueSize,
|
||||||
ZSTD_customMem customMem) {
|
ZSTD_customMem customMem)
|
||||||
|
{
|
||||||
POOL_ctx* ctx;
|
POOL_ctx* ctx;
|
||||||
/* Check parameters */
|
/* Check parameters */
|
||||||
if (!numThreads) { return NULL; }
|
if (!numThreads) { return NULL; }
|
||||||
/* Allocate the context and zero initialize */
|
/* Allocate the context and zero initialize */
|
||||||
ctx = (POOL_ctx*)ZSTD_calloc(sizeof(POOL_ctx), customMem);
|
ctx = (POOL_ctx*)ZSTD_customCalloc(sizeof(POOL_ctx), customMem);
|
||||||
if (!ctx) { return NULL; }
|
if (!ctx) { return NULL; }
|
||||||
/* Initialize the job queue.
|
/* Initialize the job queue.
|
||||||
* It needs one extra space since one space is wasted to differentiate
|
* It needs one extra space since one space is wasted to differentiate
|
||||||
* empty and full queues.
|
* empty and full queues.
|
||||||
*/
|
*/
|
||||||
ctx->queueSize = queueSize + 1;
|
ctx->queueSize = queueSize + 1;
|
||||||
ctx->queue = (POOL_job*)ZSTD_malloc(ctx->queueSize * sizeof(POOL_job), customMem);
|
ctx->queue = (POOL_job*)ZSTD_customCalloc(ctx->queueSize * sizeof(POOL_job), customMem);
|
||||||
ctx->queueHead = 0;
|
ctx->queueHead = 0;
|
||||||
ctx->queueTail = 0;
|
ctx->queueTail = 0;
|
||||||
ctx->numThreadsBusy = 0;
|
ctx->numThreadsBusy = 0;
|
||||||
@@ -136,7 +141,7 @@ POOL_ctx* POOL_create_advanced(size_t numThreads, size_t queueSize,
|
|||||||
}
|
}
|
||||||
ctx->shutdown = 0;
|
ctx->shutdown = 0;
|
||||||
/* Allocate space for the thread handles */
|
/* Allocate space for the thread handles */
|
||||||
ctx->threads = (ZSTD_pthread_t*)ZSTD_malloc(numThreads * sizeof(ZSTD_pthread_t), customMem);
|
ctx->threads = (ZSTD_pthread_t*)ZSTD_customCalloc(numThreads * sizeof(ZSTD_pthread_t), customMem);
|
||||||
ctx->threadCapacity = 0;
|
ctx->threadCapacity = 0;
|
||||||
ctx->customMem = customMem;
|
ctx->customMem = customMem;
|
||||||
/* Check for errors */
|
/* Check for errors */
|
||||||
@@ -169,7 +174,7 @@ static void POOL_join(POOL_ctx* ctx) {
|
|||||||
/* Join all of the threads */
|
/* Join all of the threads */
|
||||||
{ size_t i;
|
{ size_t i;
|
||||||
for (i = 0; i < ctx->threadCapacity; ++i) {
|
for (i = 0; i < ctx->threadCapacity; ++i) {
|
||||||
ZSTD_pthread_join(ctx->threads[i], NULL); /* note : could fail */
|
ZSTD_pthread_join(ctx->threads[i]); /* note : could fail */
|
||||||
} }
|
} }
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -179,14 +184,27 @@ void POOL_free(POOL_ctx *ctx) {
|
|||||||
ZSTD_pthread_mutex_destroy(&ctx->queueMutex);
|
ZSTD_pthread_mutex_destroy(&ctx->queueMutex);
|
||||||
ZSTD_pthread_cond_destroy(&ctx->queuePushCond);
|
ZSTD_pthread_cond_destroy(&ctx->queuePushCond);
|
||||||
ZSTD_pthread_cond_destroy(&ctx->queuePopCond);
|
ZSTD_pthread_cond_destroy(&ctx->queuePopCond);
|
||||||
ZSTD_free(ctx->queue, ctx->customMem);
|
ZSTD_customFree(ctx->queue, ctx->customMem);
|
||||||
ZSTD_free(ctx->threads, ctx->customMem);
|
ZSTD_customFree(ctx->threads, ctx->customMem);
|
||||||
ZSTD_free(ctx, ctx->customMem);
|
ZSTD_customFree(ctx, ctx->customMem);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/*! POOL_joinJobs() :
|
||||||
|
* Waits for all queued jobs to finish executing.
|
||||||
|
*/
|
||||||
|
void POOL_joinJobs(POOL_ctx* ctx) {
|
||||||
|
ZSTD_pthread_mutex_lock(&ctx->queueMutex);
|
||||||
|
while(!ctx->queueEmpty || ctx->numThreadsBusy > 0) {
|
||||||
|
ZSTD_pthread_cond_wait(&ctx->queuePushCond, &ctx->queueMutex);
|
||||||
|
}
|
||||||
|
ZSTD_pthread_mutex_unlock(&ctx->queueMutex);
|
||||||
|
}
|
||||||
|
|
||||||
|
void ZSTD_freeThreadPool (ZSTD_threadPool* pool) {
|
||||||
|
POOL_free (pool);
|
||||||
|
}
|
||||||
|
|
||||||
size_t POOL_sizeof(POOL_ctx *ctx) {
|
size_t POOL_sizeof(const POOL_ctx* ctx) {
|
||||||
if (ctx==NULL) return 0; /* supports sizeof NULL */
|
if (ctx==NULL) return 0; /* supports sizeof NULL */
|
||||||
return sizeof(*ctx)
|
return sizeof(*ctx)
|
||||||
+ ctx->queueSize * sizeof(POOL_job)
|
+ ctx->queueSize * sizeof(POOL_job)
|
||||||
@@ -203,11 +221,11 @@ static int POOL_resize_internal(POOL_ctx* ctx, size_t numThreads)
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
/* numThreads > threadCapacity */
|
/* numThreads > threadCapacity */
|
||||||
{ ZSTD_pthread_t* const threadPool = (ZSTD_pthread_t*)ZSTD_malloc(numThreads * sizeof(ZSTD_pthread_t), ctx->customMem);
|
{ ZSTD_pthread_t* const threadPool = (ZSTD_pthread_t*)ZSTD_customCalloc(numThreads * sizeof(ZSTD_pthread_t), ctx->customMem);
|
||||||
if (!threadPool) return 1;
|
if (!threadPool) return 1;
|
||||||
/* replace existing thread pool */
|
/* replace existing thread pool */
|
||||||
memcpy(threadPool, ctx->threads, ctx->threadCapacity * sizeof(*threadPool));
|
ZSTD_memcpy(threadPool, ctx->threads, ctx->threadCapacity * sizeof(*threadPool));
|
||||||
ZSTD_free(ctx->threads, ctx->customMem);
|
ZSTD_customFree(ctx->threads, ctx->customMem);
|
||||||
ctx->threads = threadPool;
|
ctx->threads = threadPool;
|
||||||
/* Initialize additional threads */
|
/* Initialize additional threads */
|
||||||
{ size_t threadId;
|
{ size_t threadId;
|
||||||
@@ -251,9 +269,12 @@ static int isQueueFull(POOL_ctx const* ctx) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
static void POOL_add_internal(POOL_ctx* ctx, POOL_function function, void *opaque)
|
static void
|
||||||
|
POOL_add_internal(POOL_ctx* ctx, POOL_function function, void *opaque)
|
||||||
{
|
{
|
||||||
POOL_job const job = {function, opaque};
|
POOL_job job;
|
||||||
|
job.function = function;
|
||||||
|
job.opaque = opaque;
|
||||||
assert(ctx != NULL);
|
assert(ctx != NULL);
|
||||||
if (ctx->shutdown) return;
|
if (ctx->shutdown) return;
|
||||||
|
|
||||||
@@ -301,21 +322,28 @@ int POOL_tryAdd(POOL_ctx* ctx, POOL_function function, void* opaque)
|
|||||||
struct POOL_ctx_s {
|
struct POOL_ctx_s {
|
||||||
int dummy;
|
int dummy;
|
||||||
};
|
};
|
||||||
static POOL_ctx g_ctx;
|
static POOL_ctx g_poolCtx;
|
||||||
|
|
||||||
POOL_ctx* POOL_create(size_t numThreads, size_t queueSize) {
|
POOL_ctx* POOL_create(size_t numThreads, size_t queueSize) {
|
||||||
return POOL_create_advanced(numThreads, queueSize, ZSTD_defaultCMem);
|
return POOL_create_advanced(numThreads, queueSize, ZSTD_defaultCMem);
|
||||||
}
|
}
|
||||||
|
|
||||||
POOL_ctx* POOL_create_advanced(size_t numThreads, size_t queueSize, ZSTD_customMem customMem) {
|
POOL_ctx*
|
||||||
|
POOL_create_advanced(size_t numThreads, size_t queueSize, ZSTD_customMem customMem)
|
||||||
|
{
|
||||||
(void)numThreads;
|
(void)numThreads;
|
||||||
(void)queueSize;
|
(void)queueSize;
|
||||||
(void)customMem;
|
(void)customMem;
|
||||||
return &g_ctx;
|
return &g_poolCtx;
|
||||||
}
|
}
|
||||||
|
|
||||||
void POOL_free(POOL_ctx* ctx) {
|
void POOL_free(POOL_ctx* ctx) {
|
||||||
assert(!ctx || ctx == &g_ctx);
|
assert(!ctx || ctx == &g_poolCtx);
|
||||||
|
(void)ctx;
|
||||||
|
}
|
||||||
|
|
||||||
|
void POOL_joinJobs(POOL_ctx* ctx){
|
||||||
|
assert(!ctx || ctx == &g_poolCtx);
|
||||||
(void)ctx;
|
(void)ctx;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -335,10 +363,12 @@ int POOL_tryAdd(POOL_ctx* ctx, POOL_function function, void* opaque) {
|
|||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
size_t POOL_sizeof(POOL_ctx* ctx) {
|
size_t POOL_sizeof(const POOL_ctx* ctx) {
|
||||||
if (ctx==NULL) return 0; /* supports sizeof NULL */
|
if (ctx==NULL) return 0; /* supports sizeof NULL */
|
||||||
assert(ctx == &g_ctx);
|
assert(ctx == &g_poolCtx);
|
||||||
return sizeof(*ctx);
|
return sizeof(*ctx);
|
||||||
}
|
}
|
||||||
|
|
||||||
#endif /* ZSTD_MULTITHREAD */
|
#endif /* ZSTD_MULTITHREAD */
|
||||||
|
|
||||||
|
#endif /* USE_EXTERNAL_ZSTD */
|
||||||
|
|||||||
17
vendor/github.com/DataDog/zstd/pool.h
generated
vendored
17
vendor/github.com/DataDog/zstd/pool.h
generated
vendored
@@ -1,5 +1,6 @@
|
|||||||
|
#ifndef USE_EXTERNAL_ZSTD
|
||||||
/*
|
/*
|
||||||
* Copyright (c) 2016-present, Yann Collet, Facebook, Inc.
|
* Copyright (c) Meta Platforms, Inc. and affiliates.
|
||||||
* All rights reserved.
|
* All rights reserved.
|
||||||
*
|
*
|
||||||
* This source code is licensed under both the BSD-style license (found in the
|
* This source code is licensed under both the BSD-style license (found in the
|
||||||
@@ -16,7 +17,7 @@ extern "C" {
|
|||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
|
||||||
#include <stddef.h> /* size_t */
|
#include "zstd_deps.h"
|
||||||
#define ZSTD_STATIC_LINKING_ONLY /* ZSTD_customMem */
|
#define ZSTD_STATIC_LINKING_ONLY /* ZSTD_customMem */
|
||||||
#include "zstd.h"
|
#include "zstd.h"
|
||||||
|
|
||||||
@@ -38,6 +39,12 @@ POOL_ctx* POOL_create_advanced(size_t numThreads, size_t queueSize,
|
|||||||
*/
|
*/
|
||||||
void POOL_free(POOL_ctx* ctx);
|
void POOL_free(POOL_ctx* ctx);
|
||||||
|
|
||||||
|
|
||||||
|
/*! POOL_joinJobs() :
|
||||||
|
* Waits for all queued jobs to finish executing.
|
||||||
|
*/
|
||||||
|
void POOL_joinJobs(POOL_ctx* ctx);
|
||||||
|
|
||||||
/*! POOL_resize() :
|
/*! POOL_resize() :
|
||||||
* Expands or shrinks pool's number of threads.
|
* Expands or shrinks pool's number of threads.
|
||||||
* This is more efficient than releasing + creating a new context,
|
* This is more efficient than releasing + creating a new context,
|
||||||
@@ -53,7 +60,7 @@ int POOL_resize(POOL_ctx* ctx, size_t numThreads);
|
|||||||
* @return threadpool memory usage
|
* @return threadpool memory usage
|
||||||
* note : compatible with NULL (returns 0 in this case)
|
* note : compatible with NULL (returns 0 in this case)
|
||||||
*/
|
*/
|
||||||
size_t POOL_sizeof(POOL_ctx* ctx);
|
size_t POOL_sizeof(const POOL_ctx* ctx);
|
||||||
|
|
||||||
/*! POOL_function :
|
/*! POOL_function :
|
||||||
* The function type that can be added to a thread pool.
|
* The function type that can be added to a thread pool.
|
||||||
@@ -70,7 +77,7 @@ void POOL_add(POOL_ctx* ctx, POOL_function function, void* opaque);
|
|||||||
|
|
||||||
|
|
||||||
/*! POOL_tryAdd() :
|
/*! POOL_tryAdd() :
|
||||||
* Add the job `function(opaque)` to thread pool _if_ a worker is available.
|
* Add the job `function(opaque)` to thread pool _if_ a queue slot is available.
|
||||||
* Returns immediately even if not (does not block).
|
* Returns immediately even if not (does not block).
|
||||||
* @return : 1 if successful, 0 if not.
|
* @return : 1 if successful, 0 if not.
|
||||||
*/
|
*/
|
||||||
@@ -82,3 +89,5 @@ int POOL_tryAdd(POOL_ctx* ctx, POOL_function function, void* opaque);
|
|||||||
#endif
|
#endif
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
#endif /* USE_EXTERNAL_ZSTD */
|
||||||
|
|||||||
159
vendor/github.com/DataDog/zstd/portability_macros.h
generated
vendored
Normal file
159
vendor/github.com/DataDog/zstd/portability_macros.h
generated
vendored
Normal file
@@ -0,0 +1,159 @@
|
|||||||
|
#ifndef USE_EXTERNAL_ZSTD
|
||||||
|
/*
|
||||||
|
* Copyright (c) Meta Platforms, Inc. and affiliates.
|
||||||
|
* All rights reserved.
|
||||||
|
*
|
||||||
|
* This source code is licensed under both the BSD-style license (found in the
|
||||||
|
* LICENSE file in the root directory of this source tree) and the GPLv2 (found
|
||||||
|
* in the COPYING file in the root directory of this source tree).
|
||||||
|
* You may select, at your option, one of the above-listed licenses.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#ifndef ZSTD_PORTABILITY_MACROS_H
|
||||||
|
#define ZSTD_PORTABILITY_MACROS_H
|
||||||
|
|
||||||
|
/**
|
||||||
|
* This header file contains macro definitions to support portability.
|
||||||
|
* This header is shared between C and ASM code, so it MUST only
|
||||||
|
* contain macro definitions. It MUST not contain any C code.
|
||||||
|
*
|
||||||
|
* This header ONLY defines macros to detect platforms/feature support.
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
|
||||||
|
|
||||||
|
/* compat. with non-clang compilers */
|
||||||
|
#ifndef __has_attribute
|
||||||
|
#define __has_attribute(x) 0
|
||||||
|
#endif
|
||||||
|
|
||||||
|
/* compat. with non-clang compilers */
|
||||||
|
#ifndef __has_builtin
|
||||||
|
# define __has_builtin(x) 0
|
||||||
|
#endif
|
||||||
|
|
||||||
|
/* compat. with non-clang compilers */
|
||||||
|
#ifndef __has_feature
|
||||||
|
# define __has_feature(x) 0
|
||||||
|
#endif
|
||||||
|
|
||||||
|
/* detects whether we are being compiled under msan */
|
||||||
|
#ifndef ZSTD_MEMORY_SANITIZER
|
||||||
|
# if __has_feature(memory_sanitizer)
|
||||||
|
# define ZSTD_MEMORY_SANITIZER 1
|
||||||
|
# else
|
||||||
|
# define ZSTD_MEMORY_SANITIZER 0
|
||||||
|
# endif
|
||||||
|
#endif
|
||||||
|
|
||||||
|
/* detects whether we are being compiled under asan */
|
||||||
|
#ifndef ZSTD_ADDRESS_SANITIZER
|
||||||
|
# if __has_feature(address_sanitizer)
|
||||||
|
# define ZSTD_ADDRESS_SANITIZER 1
|
||||||
|
# elif defined(__SANITIZE_ADDRESS__)
|
||||||
|
# define ZSTD_ADDRESS_SANITIZER 1
|
||||||
|
# else
|
||||||
|
# define ZSTD_ADDRESS_SANITIZER 0
|
||||||
|
# endif
|
||||||
|
#endif
|
||||||
|
|
||||||
|
/* detects whether we are being compiled under dfsan */
|
||||||
|
#ifndef ZSTD_DATAFLOW_SANITIZER
|
||||||
|
# if __has_feature(dataflow_sanitizer)
|
||||||
|
# define ZSTD_DATAFLOW_SANITIZER 1
|
||||||
|
# else
|
||||||
|
# define ZSTD_DATAFLOW_SANITIZER 0
|
||||||
|
# endif
|
||||||
|
#endif
|
||||||
|
|
||||||
|
/* Mark the internal assembly functions as hidden */
|
||||||
|
#ifdef __ELF__
|
||||||
|
# define ZSTD_HIDE_ASM_FUNCTION(func) .hidden func
|
||||||
|
#else
|
||||||
|
# define ZSTD_HIDE_ASM_FUNCTION(func)
|
||||||
|
#endif
|
||||||
|
|
||||||
|
/* Enable runtime BMI2 dispatch based on the CPU.
|
||||||
|
* Enabled for clang & gcc >=4.8 on x86 when BMI2 isn't enabled by default.
|
||||||
|
*/
|
||||||
|
#ifndef DYNAMIC_BMI2
|
||||||
|
#if ((defined(__clang__) && __has_attribute(__target__)) \
|
||||||
|
|| (defined(__GNUC__) \
|
||||||
|
&& (__GNUC__ >= 5 || (__GNUC__ == 4 && __GNUC_MINOR__ >= 8)))) \
|
||||||
|
&& (defined(__x86_64__) || defined(_M_X64)) \
|
||||||
|
&& !defined(__BMI2__)
|
||||||
|
# define DYNAMIC_BMI2 1
|
||||||
|
#else
|
||||||
|
# define DYNAMIC_BMI2 0
|
||||||
|
#endif
|
||||||
|
#endif
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Only enable assembly for GNUC compatible compilers,
|
||||||
|
* because other platforms may not support GAS assembly syntax.
|
||||||
|
*
|
||||||
|
* Only enable assembly for Linux / MacOS, other platforms may
|
||||||
|
* work, but they haven't been tested. This could likely be
|
||||||
|
* extended to BSD systems.
|
||||||
|
*
|
||||||
|
* Disable assembly when MSAN is enabled, because MSAN requires
|
||||||
|
* 100% of code to be instrumented to work.
|
||||||
|
*/
|
||||||
|
#if defined(__GNUC__)
|
||||||
|
# if defined(__linux__) || defined(__linux) || defined(__APPLE__)
|
||||||
|
# if ZSTD_MEMORY_SANITIZER
|
||||||
|
# define ZSTD_ASM_SUPPORTED 0
|
||||||
|
# elif ZSTD_DATAFLOW_SANITIZER
|
||||||
|
# define ZSTD_ASM_SUPPORTED 0
|
||||||
|
# else
|
||||||
|
# define ZSTD_ASM_SUPPORTED 1
|
||||||
|
# endif
|
||||||
|
# else
|
||||||
|
# define ZSTD_ASM_SUPPORTED 0
|
||||||
|
# endif
|
||||||
|
#else
|
||||||
|
# define ZSTD_ASM_SUPPORTED 0
|
||||||
|
#endif
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Determines whether we should enable assembly for x86-64
|
||||||
|
* with BMI2.
|
||||||
|
*
|
||||||
|
* Enable if all of the following conditions hold:
|
||||||
|
* - ASM hasn't been explicitly disabled by defining ZSTD_DISABLE_ASM
|
||||||
|
* - Assembly is supported
|
||||||
|
* - We are compiling for x86-64 and either:
|
||||||
|
* - DYNAMIC_BMI2 is enabled
|
||||||
|
* - BMI2 is supported at compile time
|
||||||
|
*/
|
||||||
|
#if !defined(ZSTD_DISABLE_ASM) && \
|
||||||
|
ZSTD_ASM_SUPPORTED && \
|
||||||
|
defined(__x86_64__) && \
|
||||||
|
(DYNAMIC_BMI2 || defined(__BMI2__))
|
||||||
|
# define ZSTD_ENABLE_ASM_X86_64_BMI2 1
|
||||||
|
#else
|
||||||
|
# define ZSTD_ENABLE_ASM_X86_64_BMI2 0
|
||||||
|
#endif
|
||||||
|
|
||||||
|
/*
|
||||||
|
* For x86 ELF targets, add .note.gnu.property section for Intel CET in
|
||||||
|
* assembly sources when CET is enabled.
|
||||||
|
*
|
||||||
|
* Additionally, any function that may be called indirectly must begin
|
||||||
|
* with ZSTD_CET_ENDBRANCH.
|
||||||
|
*/
|
||||||
|
#if defined(__ELF__) && (defined(__x86_64__) || defined(__i386__)) \
|
||||||
|
&& defined(__has_include)
|
||||||
|
# if __has_include(<cet.h>)
|
||||||
|
# include <cet.h>
|
||||||
|
# define ZSTD_CET_ENDBRANCH _CET_ENDBR
|
||||||
|
# endif
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#ifndef ZSTD_CET_ENDBRANCH
|
||||||
|
# define ZSTD_CET_ENDBRANCH
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#endif /* ZSTD_PORTABILITY_MACROS_H */
|
||||||
|
|
||||||
|
#endif /* USE_EXTERNAL_ZSTD */
|
||||||
101
vendor/github.com/DataDog/zstd/threading.c
generated
vendored
101
vendor/github.com/DataDog/zstd/threading.c
generated
vendored
@@ -1,13 +1,15 @@
|
|||||||
|
#ifndef USE_EXTERNAL_ZSTD
|
||||||
/**
|
/**
|
||||||
* Copyright (c) 2016 Tino Reichardt
|
* Copyright (c) 2016 Tino Reichardt
|
||||||
* All rights reserved.
|
* All rights reserved.
|
||||||
*
|
*
|
||||||
|
* You can contact the author at:
|
||||||
|
* - zstdmt source repository: https://github.com/mcmilk/zstdmt
|
||||||
|
*
|
||||||
* This source code is licensed under both the BSD-style license (found in the
|
* This source code is licensed under both the BSD-style license (found in the
|
||||||
* LICENSE file in the root directory of this source tree) and the GPLv2 (found
|
* LICENSE file in the root directory of this source tree) and the GPLv2 (found
|
||||||
* in the COPYING file in the root directory of this source tree).
|
* in the COPYING file in the root directory of this source tree).
|
||||||
*
|
* You may select, at your option, one of the above-listed licenses.
|
||||||
* You can contact the author at:
|
|
||||||
* - zstdmt source repository: https://github.com/mcmilk/zstdmt
|
|
||||||
*/
|
*/
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -22,8 +24,7 @@ int g_ZSTD_threading_useless_symbol;
|
|||||||
#if defined(ZSTD_MULTITHREAD) && defined(_WIN32)
|
#if defined(ZSTD_MULTITHREAD) && defined(_WIN32)
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Windows minimalist Pthread Wrapper, based on :
|
* Windows minimalist Pthread Wrapper
|
||||||
* http://www.cse.wustl.edu/~schmidt/win32-cv-1.html
|
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
|
||||||
@@ -34,37 +35,92 @@ int g_ZSTD_threading_useless_symbol;
|
|||||||
|
|
||||||
/* === Implementation === */
|
/* === Implementation === */
|
||||||
|
|
||||||
|
typedef struct {
|
||||||
|
void* (*start_routine)(void*);
|
||||||
|
void* arg;
|
||||||
|
int initialized;
|
||||||
|
ZSTD_pthread_cond_t initialized_cond;
|
||||||
|
ZSTD_pthread_mutex_t initialized_mutex;
|
||||||
|
} ZSTD_thread_params_t;
|
||||||
|
|
||||||
static unsigned __stdcall worker(void *arg)
|
static unsigned __stdcall worker(void *arg)
|
||||||
{
|
{
|
||||||
ZSTD_pthread_t* const thread = (ZSTD_pthread_t*) arg;
|
void* (*start_routine)(void*);
|
||||||
thread->arg = thread->start_routine(thread->arg);
|
void* thread_arg;
|
||||||
|
|
||||||
|
/* Initialized thread_arg and start_routine and signal main thread that we don't need it
|
||||||
|
* to wait any longer.
|
||||||
|
*/
|
||||||
|
{
|
||||||
|
ZSTD_thread_params_t* thread_param = (ZSTD_thread_params_t*)arg;
|
||||||
|
thread_arg = thread_param->arg;
|
||||||
|
start_routine = thread_param->start_routine;
|
||||||
|
|
||||||
|
/* Signal main thread that we are running and do not depend on its memory anymore */
|
||||||
|
ZSTD_pthread_mutex_lock(&thread_param->initialized_mutex);
|
||||||
|
thread_param->initialized = 1;
|
||||||
|
ZSTD_pthread_cond_signal(&thread_param->initialized_cond);
|
||||||
|
ZSTD_pthread_mutex_unlock(&thread_param->initialized_mutex);
|
||||||
|
}
|
||||||
|
|
||||||
|
start_routine(thread_arg);
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
int ZSTD_pthread_create(ZSTD_pthread_t* thread, const void* unused,
|
int ZSTD_pthread_create(ZSTD_pthread_t* thread, const void* unused,
|
||||||
void* (*start_routine) (void*), void* arg)
|
void* (*start_routine) (void*), void* arg)
|
||||||
{
|
{
|
||||||
|
ZSTD_thread_params_t thread_param;
|
||||||
(void)unused;
|
(void)unused;
|
||||||
thread->arg = arg;
|
|
||||||
thread->start_routine = start_routine;
|
|
||||||
thread->handle = (HANDLE) _beginthreadex(NULL, 0, worker, thread, 0, NULL);
|
|
||||||
|
|
||||||
if (!thread->handle)
|
thread_param.start_routine = start_routine;
|
||||||
|
thread_param.arg = arg;
|
||||||
|
thread_param.initialized = 0;
|
||||||
|
*thread = NULL;
|
||||||
|
|
||||||
|
/* Setup thread initialization synchronization */
|
||||||
|
if(ZSTD_pthread_cond_init(&thread_param.initialized_cond, NULL)) {
|
||||||
|
/* Should never happen on Windows */
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
if(ZSTD_pthread_mutex_init(&thread_param.initialized_mutex, NULL)) {
|
||||||
|
/* Should never happen on Windows */
|
||||||
|
ZSTD_pthread_cond_destroy(&thread_param.initialized_cond);
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Spawn thread */
|
||||||
|
*thread = (HANDLE)_beginthreadex(NULL, 0, worker, &thread_param, 0, NULL);
|
||||||
|
if (!thread) {
|
||||||
|
ZSTD_pthread_mutex_destroy(&thread_param.initialized_mutex);
|
||||||
|
ZSTD_pthread_cond_destroy(&thread_param.initialized_cond);
|
||||||
return errno;
|
return errno;
|
||||||
else
|
}
|
||||||
|
|
||||||
|
/* Wait for thread to be initialized */
|
||||||
|
ZSTD_pthread_mutex_lock(&thread_param.initialized_mutex);
|
||||||
|
while(!thread_param.initialized) {
|
||||||
|
ZSTD_pthread_cond_wait(&thread_param.initialized_cond, &thread_param.initialized_mutex);
|
||||||
|
}
|
||||||
|
ZSTD_pthread_mutex_unlock(&thread_param.initialized_mutex);
|
||||||
|
ZSTD_pthread_mutex_destroy(&thread_param.initialized_mutex);
|
||||||
|
ZSTD_pthread_cond_destroy(&thread_param.initialized_cond);
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
int ZSTD_pthread_join(ZSTD_pthread_t thread, void **value_ptr)
|
int ZSTD_pthread_join(ZSTD_pthread_t thread)
|
||||||
{
|
{
|
||||||
DWORD result;
|
DWORD result;
|
||||||
|
|
||||||
if (!thread.handle) return 0;
|
if (!thread) return 0;
|
||||||
|
|
||||||
|
result = WaitForSingleObject(thread, INFINITE);
|
||||||
|
CloseHandle(thread);
|
||||||
|
|
||||||
result = WaitForSingleObject(thread.handle, INFINITE);
|
|
||||||
switch (result) {
|
switch (result) {
|
||||||
case WAIT_OBJECT_0:
|
case WAIT_OBJECT_0:
|
||||||
if (value_ptr) *value_ptr = thread.arg;
|
|
||||||
return 0;
|
return 0;
|
||||||
case WAIT_ABANDONED:
|
case WAIT_ABANDONED:
|
||||||
return EINVAL;
|
return EINVAL;
|
||||||
@@ -77,11 +133,12 @@ int ZSTD_pthread_join(ZSTD_pthread_t thread, void **value_ptr)
|
|||||||
|
|
||||||
#if defined(ZSTD_MULTITHREAD) && DEBUGLEVEL >= 1 && !defined(_WIN32)
|
#if defined(ZSTD_MULTITHREAD) && DEBUGLEVEL >= 1 && !defined(_WIN32)
|
||||||
|
|
||||||
#include <stdlib.h>
|
#define ZSTD_DEPS_NEED_MALLOC
|
||||||
|
#include "zstd_deps.h"
|
||||||
|
|
||||||
int ZSTD_pthread_mutex_init(ZSTD_pthread_mutex_t* mutex, pthread_mutexattr_t const* attr)
|
int ZSTD_pthread_mutex_init(ZSTD_pthread_mutex_t* mutex, pthread_mutexattr_t const* attr)
|
||||||
{
|
{
|
||||||
*mutex = (pthread_mutex_t*)malloc(sizeof(pthread_mutex_t));
|
*mutex = (pthread_mutex_t*)ZSTD_malloc(sizeof(pthread_mutex_t));
|
||||||
if (!*mutex)
|
if (!*mutex)
|
||||||
return 1;
|
return 1;
|
||||||
return pthread_mutex_init(*mutex, attr);
|
return pthread_mutex_init(*mutex, attr);
|
||||||
@@ -93,14 +150,14 @@ int ZSTD_pthread_mutex_destroy(ZSTD_pthread_mutex_t* mutex)
|
|||||||
return 0;
|
return 0;
|
||||||
{
|
{
|
||||||
int const ret = pthread_mutex_destroy(*mutex);
|
int const ret = pthread_mutex_destroy(*mutex);
|
||||||
free(*mutex);
|
ZSTD_free(*mutex);
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
int ZSTD_pthread_cond_init(ZSTD_pthread_cond_t* cond, pthread_condattr_t const* attr)
|
int ZSTD_pthread_cond_init(ZSTD_pthread_cond_t* cond, pthread_condattr_t const* attr)
|
||||||
{
|
{
|
||||||
*cond = (pthread_cond_t*)malloc(sizeof(pthread_cond_t));
|
*cond = (pthread_cond_t*)ZSTD_malloc(sizeof(pthread_cond_t));
|
||||||
if (!*cond)
|
if (!*cond)
|
||||||
return 1;
|
return 1;
|
||||||
return pthread_cond_init(*cond, attr);
|
return pthread_cond_init(*cond, attr);
|
||||||
@@ -112,9 +169,11 @@ int ZSTD_pthread_cond_destroy(ZSTD_pthread_cond_t* cond)
|
|||||||
return 0;
|
return 0;
|
||||||
{
|
{
|
||||||
int const ret = pthread_cond_destroy(*cond);
|
int const ret = pthread_cond_destroy(*cond);
|
||||||
free(*cond);
|
ZSTD_free(*cond);
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
#endif /* USE_EXTERNAL_ZSTD */
|
||||||
|
|||||||
25
vendor/github.com/DataDog/zstd/threading.h
generated
vendored
25
vendor/github.com/DataDog/zstd/threading.h
generated
vendored
@@ -1,13 +1,15 @@
|
|||||||
|
#ifndef USE_EXTERNAL_ZSTD
|
||||||
/**
|
/**
|
||||||
* Copyright (c) 2016 Tino Reichardt
|
* Copyright (c) 2016 Tino Reichardt
|
||||||
* All rights reserved.
|
* All rights reserved.
|
||||||
*
|
*
|
||||||
|
* You can contact the author at:
|
||||||
|
* - zstdmt source repository: https://github.com/mcmilk/zstdmt
|
||||||
|
*
|
||||||
* This source code is licensed under both the BSD-style license (found in the
|
* This source code is licensed under both the BSD-style license (found in the
|
||||||
* LICENSE file in the root directory of this source tree) and the GPLv2 (found
|
* LICENSE file in the root directory of this source tree) and the GPLv2 (found
|
||||||
* in the COPYING file in the root directory of this source tree).
|
* in the COPYING file in the root directory of this source tree).
|
||||||
*
|
* You may select, at your option, one of the above-listed licenses.
|
||||||
* You can contact the author at:
|
|
||||||
* - zstdmt source repository: https://github.com/mcmilk/zstdmt
|
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#ifndef THREADING_H_938743
|
#ifndef THREADING_H_938743
|
||||||
@@ -22,8 +24,7 @@ extern "C" {
|
|||||||
#if defined(ZSTD_MULTITHREAD) && defined(_WIN32)
|
#if defined(ZSTD_MULTITHREAD) && defined(_WIN32)
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Windows minimalist Pthread Wrapper, based on :
|
* Windows minimalist Pthread Wrapper
|
||||||
* http://www.cse.wustl.edu/~schmidt/win32-cv-1.html
|
|
||||||
*/
|
*/
|
||||||
#ifdef WINVER
|
#ifdef WINVER
|
||||||
# undef WINVER
|
# undef WINVER
|
||||||
@@ -61,16 +62,12 @@ extern "C" {
|
|||||||
#define ZSTD_pthread_cond_broadcast(a) WakeAllConditionVariable((a))
|
#define ZSTD_pthread_cond_broadcast(a) WakeAllConditionVariable((a))
|
||||||
|
|
||||||
/* ZSTD_pthread_create() and ZSTD_pthread_join() */
|
/* ZSTD_pthread_create() and ZSTD_pthread_join() */
|
||||||
typedef struct {
|
typedef HANDLE ZSTD_pthread_t;
|
||||||
HANDLE handle;
|
|
||||||
void* (*start_routine)(void*);
|
|
||||||
void* arg;
|
|
||||||
} ZSTD_pthread_t;
|
|
||||||
|
|
||||||
int ZSTD_pthread_create(ZSTD_pthread_t* thread, const void* unused,
|
int ZSTD_pthread_create(ZSTD_pthread_t* thread, const void* unused,
|
||||||
void* (*start_routine) (void*), void* arg);
|
void* (*start_routine) (void*), void* arg);
|
||||||
|
|
||||||
int ZSTD_pthread_join(ZSTD_pthread_t thread, void** value_ptr);
|
int ZSTD_pthread_join(ZSTD_pthread_t thread);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* add here more wrappers as required
|
* add here more wrappers as required
|
||||||
@@ -98,7 +95,7 @@ int ZSTD_pthread_join(ZSTD_pthread_t thread, void** value_ptr);
|
|||||||
|
|
||||||
#define ZSTD_pthread_t pthread_t
|
#define ZSTD_pthread_t pthread_t
|
||||||
#define ZSTD_pthread_create(a, b, c, d) pthread_create((a), (b), (c), (d))
|
#define ZSTD_pthread_create(a, b, c, d) pthread_create((a), (b), (c), (d))
|
||||||
#define ZSTD_pthread_join(a, b) pthread_join((a),(b))
|
#define ZSTD_pthread_join(a) pthread_join((a),NULL)
|
||||||
|
|
||||||
#else /* DEBUGLEVEL >= 1 */
|
#else /* DEBUGLEVEL >= 1 */
|
||||||
|
|
||||||
@@ -123,7 +120,7 @@ int ZSTD_pthread_cond_destroy(ZSTD_pthread_cond_t* cond);
|
|||||||
|
|
||||||
#define ZSTD_pthread_t pthread_t
|
#define ZSTD_pthread_t pthread_t
|
||||||
#define ZSTD_pthread_create(a, b, c, d) pthread_create((a), (b), (c), (d))
|
#define ZSTD_pthread_create(a, b, c, d) pthread_create((a), (b), (c), (d))
|
||||||
#define ZSTD_pthread_join(a, b) pthread_join((a),(b))
|
#define ZSTD_pthread_join(a) pthread_join((a),NULL)
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
@@ -152,3 +149,5 @@ typedef int ZSTD_pthread_cond_t;
|
|||||||
#endif
|
#endif
|
||||||
|
|
||||||
#endif /* THREADING_H_938743 */
|
#endif /* THREADING_H_938743 */
|
||||||
|
|
||||||
|
#endif /* USE_EXTERNAL_ZSTD */
|
||||||
|
|||||||
8
vendor/github.com/DataDog/zstd/travis_test_32.sh
generated
vendored
8
vendor/github.com/DataDog/zstd/travis_test_32.sh
generated
vendored
@@ -1,6 +1,8 @@
|
|||||||
#!/bin/bash
|
#!/bin/bash
|
||||||
# Get utilities
|
# Get utilities
|
||||||
yum -y -q -e 0 install wget tar unzip gcc
|
#yum -y -q -e 0 install wget tar unzip gcc
|
||||||
|
apt-get update
|
||||||
|
apt-get -y install wget tar unzip gcc
|
||||||
|
|
||||||
# Get Go
|
# Get Go
|
||||||
wget -q https://dl.google.com/go/go1.13.linux-386.tar.gz
|
wget -q https://dl.google.com/go/go1.13.linux-386.tar.gz
|
||||||
@@ -13,5 +15,5 @@ unzip mr.zip
|
|||||||
|
|
||||||
# Build and run tests
|
# Build and run tests
|
||||||
go build
|
go build
|
||||||
PAYLOAD=$(pwd)/mr go test -v
|
DISABLE_BIG_TESTS=1 PAYLOAD=$(pwd)/mr go test -v
|
||||||
PAYLOAD=$(pwd)/mr go test -bench .
|
DISABLE_BIG_TESTS=1 PAYLOAD=$(pwd)/mr go test -bench .
|
||||||
|
|||||||
891
vendor/github.com/DataDog/zstd/xxhash.c
generated
vendored
891
vendor/github.com/DataDog/zstd/xxhash.c
generated
vendored
@@ -1,882 +1,27 @@
|
|||||||
|
#ifndef USE_EXTERNAL_ZSTD
|
||||||
/*
|
/*
|
||||||
* xxHash - Fast Hash algorithm
|
* xxHash - Fast Hash algorithm
|
||||||
* Copyright (C) 2012-2016, Yann Collet
|
* Copyright (c) Meta Platforms, Inc. and affiliates.
|
||||||
*
|
*
|
||||||
* BSD 2-Clause License (http://www.opensource.org/licenses/bsd-license.php)
|
* You can contact the author at :
|
||||||
*
|
* - xxHash homepage: https://cyan4973.github.io/xxHash/
|
||||||
* Redistribution and use in source and binary forms, with or without
|
* - xxHash source repository : https://github.com/Cyan4973/xxHash
|
||||||
* modification, are permitted provided that the following conditions are
|
*
|
||||||
* met:
|
* This source code is licensed under both the BSD-style license (found in the
|
||||||
*
|
* LICENSE file in the root directory of this source tree) and the GPLv2 (found
|
||||||
* * Redistributions of source code must retain the above copyright
|
* in the COPYING file in the root directory of this source tree).
|
||||||
* notice, this list of conditions and the following disclaimer.
|
* You may select, at your option, one of the above-listed licenses.
|
||||||
* * Redistributions in binary form must reproduce the above
|
|
||||||
* copyright notice, this list of conditions and the following disclaimer
|
|
||||||
* in the documentation and/or other materials provided with the
|
|
||||||
* distribution.
|
|
||||||
*
|
|
||||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
|
||||||
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
|
||||||
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
|
||||||
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
|
|
||||||
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
|
||||||
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
|
||||||
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
|
||||||
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
|
||||||
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
|
||||||
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
|
||||||
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
|
||||||
*
|
|
||||||
* You can contact the author at :
|
|
||||||
* - xxHash homepage: http://www.xxhash.com
|
|
||||||
* - xxHash source repository : https://github.com/Cyan4973/xxHash
|
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
|
||||||
/* *************************************
|
|
||||||
* Tuning parameters
|
/*
|
||||||
***************************************/
|
* xxhash.c instantiates functions defined in xxhash.h
|
||||||
/*!XXH_FORCE_MEMORY_ACCESS :
|
|
||||||
* By default, access to unaligned memory is controlled by `memcpy()`, which is safe and portable.
|
|
||||||
* Unfortunately, on some target/compiler combinations, the generated assembly is sub-optimal.
|
|
||||||
* The below switch allow to select different access method for improved performance.
|
|
||||||
* Method 0 (default) : use `memcpy()`. Safe and portable.
|
|
||||||
* Method 1 : `__packed` statement. It depends on compiler extension (ie, not portable).
|
|
||||||
* This method is safe if your compiler supports it, and *generally* as fast or faster than `memcpy`.
|
|
||||||
* Method 2 : direct access. This method doesn't depend on compiler but violate C standard.
|
|
||||||
* It can generate buggy code on targets which do not support unaligned memory accesses.
|
|
||||||
* But in some circumstances, it's the only known way to get the most performance (ie GCC + ARMv6)
|
|
||||||
* See http://stackoverflow.com/a/32095106/646947 for details.
|
|
||||||
* Prefer these methods in priority order (0 > 1 > 2)
|
|
||||||
*/
|
*/
|
||||||
#ifndef XXH_FORCE_MEMORY_ACCESS /* can be defined externally, on command line for example */
|
|
||||||
# if defined(__GNUC__) && ( defined(__ARM_ARCH_6__) || defined(__ARM_ARCH_6J__) || defined(__ARM_ARCH_6K__) || defined(__ARM_ARCH_6Z__) || defined(__ARM_ARCH_6ZK__) || defined(__ARM_ARCH_6T2__) )
|
|
||||||
# define XXH_FORCE_MEMORY_ACCESS 2
|
|
||||||
# elif (defined(__INTEL_COMPILER) && !defined(WIN32)) || \
|
|
||||||
(defined(__GNUC__) && ( defined(__ARM_ARCH_7__) || defined(__ARM_ARCH_7A__) || defined(__ARM_ARCH_7R__) || defined(__ARM_ARCH_7M__) || defined(__ARM_ARCH_7S__) )) || \
|
|
||||||
defined(__ICCARM__)
|
|
||||||
# define XXH_FORCE_MEMORY_ACCESS 1
|
|
||||||
# endif
|
|
||||||
#endif
|
|
||||||
|
|
||||||
/*!XXH_ACCEPT_NULL_INPUT_POINTER :
|
#define XXH_STATIC_LINKING_ONLY /* access advanced declarations */
|
||||||
* If the input pointer is a null pointer, xxHash default behavior is to trigger a memory access error, since it is a bad pointer.
|
#define XXH_IMPLEMENTATION /* access definitions */
|
||||||
* When this option is enabled, xxHash output for null input pointers will be the same as a null-length input.
|
|
||||||
* By default, this option is disabled. To enable it, uncomment below define :
|
|
||||||
*/
|
|
||||||
/* #define XXH_ACCEPT_NULL_INPUT_POINTER 1 */
|
|
||||||
|
|
||||||
/*!XXH_FORCE_NATIVE_FORMAT :
|
|
||||||
* By default, xxHash library provides endian-independent Hash values, based on little-endian convention.
|
|
||||||
* Results are therefore identical for little-endian and big-endian CPU.
|
|
||||||
* This comes at a performance cost for big-endian CPU, since some swapping is required to emulate little-endian format.
|
|
||||||
* Should endian-independence be of no importance for your application, you may set the #define below to 1,
|
|
||||||
* to improve speed for Big-endian CPU.
|
|
||||||
* This option has no impact on Little_Endian CPU.
|
|
||||||
*/
|
|
||||||
#ifndef XXH_FORCE_NATIVE_FORMAT /* can be defined externally */
|
|
||||||
# define XXH_FORCE_NATIVE_FORMAT 0
|
|
||||||
#endif
|
|
||||||
|
|
||||||
/*!XXH_FORCE_ALIGN_CHECK :
|
|
||||||
* This is a minor performance trick, only useful with lots of very small keys.
|
|
||||||
* It means : check for aligned/unaligned input.
|
|
||||||
* The check costs one initial branch per hash; set to 0 when the input data
|
|
||||||
* is guaranteed to be aligned.
|
|
||||||
*/
|
|
||||||
#ifndef XXH_FORCE_ALIGN_CHECK /* can be defined externally */
|
|
||||||
# if defined(__i386) || defined(_M_IX86) || defined(__x86_64__) || defined(_M_X64)
|
|
||||||
# define XXH_FORCE_ALIGN_CHECK 0
|
|
||||||
# else
|
|
||||||
# define XXH_FORCE_ALIGN_CHECK 1
|
|
||||||
# endif
|
|
||||||
#endif
|
|
||||||
|
|
||||||
|
|
||||||
/* *************************************
|
|
||||||
* Includes & Memory related functions
|
|
||||||
***************************************/
|
|
||||||
/* Modify the local functions below should you wish to use some other memory routines */
|
|
||||||
/* for malloc(), free() */
|
|
||||||
#include <stdlib.h>
|
|
||||||
#include <stddef.h> /* size_t */
|
|
||||||
static void* XXH_malloc(size_t s) { return malloc(s); }
|
|
||||||
static void XXH_free (void* p) { free(p); }
|
|
||||||
/* for memcpy() */
|
|
||||||
#include <string.h>
|
|
||||||
static void* XXH_memcpy(void* dest, const void* src, size_t size) { return memcpy(dest,src,size); }
|
|
||||||
|
|
||||||
#ifndef XXH_STATIC_LINKING_ONLY
|
|
||||||
# define XXH_STATIC_LINKING_ONLY
|
|
||||||
#endif
|
|
||||||
#include "xxhash.h"
|
#include "xxhash.h"
|
||||||
|
|
||||||
|
#endif /* USE_EXTERNAL_ZSTD */
|
||||||
/* *************************************
|
|
||||||
* Compiler Specific Options
|
|
||||||
***************************************/
|
|
||||||
#if defined (__GNUC__) || defined(__cplusplus) || defined(__STDC_VERSION__) && __STDC_VERSION__ >= 199901L /* C99 */
|
|
||||||
# define INLINE_KEYWORD inline
|
|
||||||
#else
|
|
||||||
# define INLINE_KEYWORD
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#if defined(__GNUC__) || defined(__ICCARM__)
|
|
||||||
# define FORCE_INLINE_ATTR __attribute__((always_inline))
|
|
||||||
#elif defined(_MSC_VER)
|
|
||||||
# define FORCE_INLINE_ATTR __forceinline
|
|
||||||
#else
|
|
||||||
# define FORCE_INLINE_ATTR
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#define FORCE_INLINE_TEMPLATE static INLINE_KEYWORD FORCE_INLINE_ATTR
|
|
||||||
|
|
||||||
|
|
||||||
#ifdef _MSC_VER
|
|
||||||
# pragma warning(disable : 4127) /* disable: C4127: conditional expression is constant */
|
|
||||||
#endif
|
|
||||||
|
|
||||||
|
|
||||||
/* *************************************
|
|
||||||
* Basic Types
|
|
||||||
***************************************/
|
|
||||||
#ifndef MEM_MODULE
|
|
||||||
# define MEM_MODULE
|
|
||||||
# if !defined (__VMS) && (defined (__cplusplus) || (defined (__STDC_VERSION__) && (__STDC_VERSION__ >= 199901L) /* C99 */) )
|
|
||||||
# include <stdint.h>
|
|
||||||
typedef uint8_t BYTE;
|
|
||||||
typedef uint16_t U16;
|
|
||||||
typedef uint32_t U32;
|
|
||||||
typedef int32_t S32;
|
|
||||||
typedef uint64_t U64;
|
|
||||||
# else
|
|
||||||
typedef unsigned char BYTE;
|
|
||||||
typedef unsigned short U16;
|
|
||||||
typedef unsigned int U32;
|
|
||||||
typedef signed int S32;
|
|
||||||
typedef unsigned long long U64; /* if your compiler doesn't support unsigned long long, replace by another 64-bit type here. Note that xxhash.h will also need to be updated. */
|
|
||||||
# endif
|
|
||||||
#endif
|
|
||||||
|
|
||||||
|
|
||||||
#if (defined(XXH_FORCE_MEMORY_ACCESS) && (XXH_FORCE_MEMORY_ACCESS==2))
|
|
||||||
|
|
||||||
/* Force direct memory access. Only works on CPU which support unaligned memory access in hardware */
|
|
||||||
static U32 XXH_read32(const void* memPtr) { return *(const U32*) memPtr; }
|
|
||||||
static U64 XXH_read64(const void* memPtr) { return *(const U64*) memPtr; }
|
|
||||||
|
|
||||||
#elif (defined(XXH_FORCE_MEMORY_ACCESS) && (XXH_FORCE_MEMORY_ACCESS==1))
|
|
||||||
|
|
||||||
/* __pack instructions are safer, but compiler specific, hence potentially problematic for some compilers */
|
|
||||||
/* currently only defined for gcc and icc */
|
|
||||||
typedef union { U32 u32; U64 u64; } __attribute__((packed)) unalign;
|
|
||||||
|
|
||||||
static U32 XXH_read32(const void* ptr) { return ((const unalign*)ptr)->u32; }
|
|
||||||
static U64 XXH_read64(const void* ptr) { return ((const unalign*)ptr)->u64; }
|
|
||||||
|
|
||||||
#else
|
|
||||||
|
|
||||||
/* portable and safe solution. Generally efficient.
|
|
||||||
* see : http://stackoverflow.com/a/32095106/646947
|
|
||||||
*/
|
|
||||||
|
|
||||||
static U32 XXH_read32(const void* memPtr)
|
|
||||||
{
|
|
||||||
U32 val;
|
|
||||||
memcpy(&val, memPtr, sizeof(val));
|
|
||||||
return val;
|
|
||||||
}
|
|
||||||
|
|
||||||
static U64 XXH_read64(const void* memPtr)
|
|
||||||
{
|
|
||||||
U64 val;
|
|
||||||
memcpy(&val, memPtr, sizeof(val));
|
|
||||||
return val;
|
|
||||||
}
|
|
||||||
|
|
||||||
#endif /* XXH_FORCE_DIRECT_MEMORY_ACCESS */
|
|
||||||
|
|
||||||
|
|
||||||
/* ****************************************
|
|
||||||
* Compiler-specific Functions and Macros
|
|
||||||
******************************************/
|
|
||||||
#define GCC_VERSION (__GNUC__ * 100 + __GNUC_MINOR__)
|
|
||||||
|
|
||||||
/* Note : although _rotl exists for minGW (GCC under windows), performance seems poor */
|
|
||||||
#if defined(_MSC_VER)
|
|
||||||
# define XXH_rotl32(x,r) _rotl(x,r)
|
|
||||||
# define XXH_rotl64(x,r) _rotl64(x,r)
|
|
||||||
#else
|
|
||||||
#if defined(__ICCARM__)
|
|
||||||
# include <intrinsics.h>
|
|
||||||
# define XXH_rotl32(x,r) __ROR(x,(32 - r))
|
|
||||||
#else
|
|
||||||
# define XXH_rotl32(x,r) ((x << r) | (x >> (32 - r)))
|
|
||||||
#endif
|
|
||||||
# define XXH_rotl64(x,r) ((x << r) | (x >> (64 - r)))
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#if defined(_MSC_VER) /* Visual Studio */
|
|
||||||
# define XXH_swap32 _byteswap_ulong
|
|
||||||
# define XXH_swap64 _byteswap_uint64
|
|
||||||
#elif GCC_VERSION >= 403
|
|
||||||
# define XXH_swap32 __builtin_bswap32
|
|
||||||
# define XXH_swap64 __builtin_bswap64
|
|
||||||
#else
|
|
||||||
static U32 XXH_swap32 (U32 x)
|
|
||||||
{
|
|
||||||
return ((x << 24) & 0xff000000 ) |
|
|
||||||
((x << 8) & 0x00ff0000 ) |
|
|
||||||
((x >> 8) & 0x0000ff00 ) |
|
|
||||||
((x >> 24) & 0x000000ff );
|
|
||||||
}
|
|
||||||
static U64 XXH_swap64 (U64 x)
|
|
||||||
{
|
|
||||||
return ((x << 56) & 0xff00000000000000ULL) |
|
|
||||||
((x << 40) & 0x00ff000000000000ULL) |
|
|
||||||
((x << 24) & 0x0000ff0000000000ULL) |
|
|
||||||
((x << 8) & 0x000000ff00000000ULL) |
|
|
||||||
((x >> 8) & 0x00000000ff000000ULL) |
|
|
||||||
((x >> 24) & 0x0000000000ff0000ULL) |
|
|
||||||
((x >> 40) & 0x000000000000ff00ULL) |
|
|
||||||
((x >> 56) & 0x00000000000000ffULL);
|
|
||||||
}
|
|
||||||
#endif
|
|
||||||
|
|
||||||
|
|
||||||
/* *************************************
|
|
||||||
* Architecture Macros
|
|
||||||
***************************************/
|
|
||||||
typedef enum { XXH_bigEndian=0, XXH_littleEndian=1 } XXH_endianess;
|
|
||||||
|
|
||||||
/* XXH_CPU_LITTLE_ENDIAN can be defined externally, for example on the compiler command line */
|
|
||||||
#ifndef XXH_CPU_LITTLE_ENDIAN
|
|
||||||
static const int g_one = 1;
|
|
||||||
# define XXH_CPU_LITTLE_ENDIAN (*(const char*)(&g_one))
|
|
||||||
#endif
|
|
||||||
|
|
||||||
|
|
||||||
/* ***************************
|
|
||||||
* Memory reads
|
|
||||||
*****************************/
|
|
||||||
typedef enum { XXH_aligned, XXH_unaligned } XXH_alignment;
|
|
||||||
|
|
||||||
FORCE_INLINE_TEMPLATE U32 XXH_readLE32_align(const void* ptr, XXH_endianess endian, XXH_alignment align)
|
|
||||||
{
|
|
||||||
if (align==XXH_unaligned)
|
|
||||||
return endian==XXH_littleEndian ? XXH_read32(ptr) : XXH_swap32(XXH_read32(ptr));
|
|
||||||
else
|
|
||||||
return endian==XXH_littleEndian ? *(const U32*)ptr : XXH_swap32(*(const U32*)ptr);
|
|
||||||
}
|
|
||||||
|
|
||||||
FORCE_INLINE_TEMPLATE U32 XXH_readLE32(const void* ptr, XXH_endianess endian)
|
|
||||||
{
|
|
||||||
return XXH_readLE32_align(ptr, endian, XXH_unaligned);
|
|
||||||
}
|
|
||||||
|
|
||||||
static U32 XXH_readBE32(const void* ptr)
|
|
||||||
{
|
|
||||||
return XXH_CPU_LITTLE_ENDIAN ? XXH_swap32(XXH_read32(ptr)) : XXH_read32(ptr);
|
|
||||||
}
|
|
||||||
|
|
||||||
FORCE_INLINE_TEMPLATE U64 XXH_readLE64_align(const void* ptr, XXH_endianess endian, XXH_alignment align)
|
|
||||||
{
|
|
||||||
if (align==XXH_unaligned)
|
|
||||||
return endian==XXH_littleEndian ? XXH_read64(ptr) : XXH_swap64(XXH_read64(ptr));
|
|
||||||
else
|
|
||||||
return endian==XXH_littleEndian ? *(const U64*)ptr : XXH_swap64(*(const U64*)ptr);
|
|
||||||
}
|
|
||||||
|
|
||||||
FORCE_INLINE_TEMPLATE U64 XXH_readLE64(const void* ptr, XXH_endianess endian)
|
|
||||||
{
|
|
||||||
return XXH_readLE64_align(ptr, endian, XXH_unaligned);
|
|
||||||
}
|
|
||||||
|
|
||||||
static U64 XXH_readBE64(const void* ptr)
|
|
||||||
{
|
|
||||||
return XXH_CPU_LITTLE_ENDIAN ? XXH_swap64(XXH_read64(ptr)) : XXH_read64(ptr);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
/* *************************************
|
|
||||||
* Macros
|
|
||||||
***************************************/
|
|
||||||
#define XXH_STATIC_ASSERT(c) { enum { XXH_static_assert = 1/(int)(!!(c)) }; } /* use only *after* variable declarations */
|
|
||||||
|
|
||||||
|
|
||||||
/* *************************************
|
|
||||||
* Constants
|
|
||||||
***************************************/
|
|
||||||
static const U32 PRIME32_1 = 2654435761U;
|
|
||||||
static const U32 PRIME32_2 = 2246822519U;
|
|
||||||
static const U32 PRIME32_3 = 3266489917U;
|
|
||||||
static const U32 PRIME32_4 = 668265263U;
|
|
||||||
static const U32 PRIME32_5 = 374761393U;
|
|
||||||
|
|
||||||
static const U64 PRIME64_1 = 11400714785074694791ULL;
|
|
||||||
static const U64 PRIME64_2 = 14029467366897019727ULL;
|
|
||||||
static const U64 PRIME64_3 = 1609587929392839161ULL;
|
|
||||||
static const U64 PRIME64_4 = 9650029242287828579ULL;
|
|
||||||
static const U64 PRIME64_5 = 2870177450012600261ULL;
|
|
||||||
|
|
||||||
XXH_PUBLIC_API unsigned XXH_versionNumber (void) { return XXH_VERSION_NUMBER; }
|
|
||||||
|
|
||||||
|
|
||||||
/* **************************
|
|
||||||
* Utils
|
|
||||||
****************************/
|
|
||||||
XXH_PUBLIC_API void XXH32_copyState(XXH32_state_t* restrict dstState, const XXH32_state_t* restrict srcState)
|
|
||||||
{
|
|
||||||
memcpy(dstState, srcState, sizeof(*dstState));
|
|
||||||
}
|
|
||||||
|
|
||||||
XXH_PUBLIC_API void XXH64_copyState(XXH64_state_t* restrict dstState, const XXH64_state_t* restrict srcState)
|
|
||||||
{
|
|
||||||
memcpy(dstState, srcState, sizeof(*dstState));
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
/* ***************************
|
|
||||||
* Simple Hash Functions
|
|
||||||
*****************************/
|
|
||||||
|
|
||||||
static U32 XXH32_round(U32 seed, U32 input)
|
|
||||||
{
|
|
||||||
seed += input * PRIME32_2;
|
|
||||||
seed = XXH_rotl32(seed, 13);
|
|
||||||
seed *= PRIME32_1;
|
|
||||||
return seed;
|
|
||||||
}
|
|
||||||
|
|
||||||
FORCE_INLINE_TEMPLATE U32 XXH32_endian_align(const void* input, size_t len, U32 seed, XXH_endianess endian, XXH_alignment align)
|
|
||||||
{
|
|
||||||
const BYTE* p = (const BYTE*)input;
|
|
||||||
const BYTE* bEnd = p + len;
|
|
||||||
U32 h32;
|
|
||||||
#define XXH_get32bits(p) XXH_readLE32_align(p, endian, align)
|
|
||||||
|
|
||||||
#ifdef XXH_ACCEPT_NULL_INPUT_POINTER
|
|
||||||
if (p==NULL) {
|
|
||||||
len=0;
|
|
||||||
bEnd=p=(const BYTE*)(size_t)16;
|
|
||||||
}
|
|
||||||
#endif
|
|
||||||
|
|
||||||
if (len>=16) {
|
|
||||||
const BYTE* const limit = bEnd - 16;
|
|
||||||
U32 v1 = seed + PRIME32_1 + PRIME32_2;
|
|
||||||
U32 v2 = seed + PRIME32_2;
|
|
||||||
U32 v3 = seed + 0;
|
|
||||||
U32 v4 = seed - PRIME32_1;
|
|
||||||
|
|
||||||
do {
|
|
||||||
v1 = XXH32_round(v1, XXH_get32bits(p)); p+=4;
|
|
||||||
v2 = XXH32_round(v2, XXH_get32bits(p)); p+=4;
|
|
||||||
v3 = XXH32_round(v3, XXH_get32bits(p)); p+=4;
|
|
||||||
v4 = XXH32_round(v4, XXH_get32bits(p)); p+=4;
|
|
||||||
} while (p<=limit);
|
|
||||||
|
|
||||||
h32 = XXH_rotl32(v1, 1) + XXH_rotl32(v2, 7) + XXH_rotl32(v3, 12) + XXH_rotl32(v4, 18);
|
|
||||||
} else {
|
|
||||||
h32 = seed + PRIME32_5;
|
|
||||||
}
|
|
||||||
|
|
||||||
h32 += (U32) len;
|
|
||||||
|
|
||||||
while (p+4<=bEnd) {
|
|
||||||
h32 += XXH_get32bits(p) * PRIME32_3;
|
|
||||||
h32 = XXH_rotl32(h32, 17) * PRIME32_4 ;
|
|
||||||
p+=4;
|
|
||||||
}
|
|
||||||
|
|
||||||
while (p<bEnd) {
|
|
||||||
h32 += (*p) * PRIME32_5;
|
|
||||||
h32 = XXH_rotl32(h32, 11) * PRIME32_1 ;
|
|
||||||
p++;
|
|
||||||
}
|
|
||||||
|
|
||||||
h32 ^= h32 >> 15;
|
|
||||||
h32 *= PRIME32_2;
|
|
||||||
h32 ^= h32 >> 13;
|
|
||||||
h32 *= PRIME32_3;
|
|
||||||
h32 ^= h32 >> 16;
|
|
||||||
|
|
||||||
return h32;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
XXH_PUBLIC_API unsigned int XXH32 (const void* input, size_t len, unsigned int seed)
|
|
||||||
{
|
|
||||||
#if 0
|
|
||||||
/* Simple version, good for code maintenance, but unfortunately slow for small inputs */
|
|
||||||
XXH32_CREATESTATE_STATIC(state);
|
|
||||||
XXH32_reset(state, seed);
|
|
||||||
XXH32_update(state, input, len);
|
|
||||||
return XXH32_digest(state);
|
|
||||||
#else
|
|
||||||
XXH_endianess endian_detected = (XXH_endianess)XXH_CPU_LITTLE_ENDIAN;
|
|
||||||
|
|
||||||
if (XXH_FORCE_ALIGN_CHECK) {
|
|
||||||
if ((((size_t)input) & 3) == 0) { /* Input is 4-bytes aligned, leverage the speed benefit */
|
|
||||||
if ((endian_detected==XXH_littleEndian) || XXH_FORCE_NATIVE_FORMAT)
|
|
||||||
return XXH32_endian_align(input, len, seed, XXH_littleEndian, XXH_aligned);
|
|
||||||
else
|
|
||||||
return XXH32_endian_align(input, len, seed, XXH_bigEndian, XXH_aligned);
|
|
||||||
} }
|
|
||||||
|
|
||||||
if ((endian_detected==XXH_littleEndian) || XXH_FORCE_NATIVE_FORMAT)
|
|
||||||
return XXH32_endian_align(input, len, seed, XXH_littleEndian, XXH_unaligned);
|
|
||||||
else
|
|
||||||
return XXH32_endian_align(input, len, seed, XXH_bigEndian, XXH_unaligned);
|
|
||||||
#endif
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
static U64 XXH64_round(U64 acc, U64 input)
|
|
||||||
{
|
|
||||||
acc += input * PRIME64_2;
|
|
||||||
acc = XXH_rotl64(acc, 31);
|
|
||||||
acc *= PRIME64_1;
|
|
||||||
return acc;
|
|
||||||
}
|
|
||||||
|
|
||||||
static U64 XXH64_mergeRound(U64 acc, U64 val)
|
|
||||||
{
|
|
||||||
val = XXH64_round(0, val);
|
|
||||||
acc ^= val;
|
|
||||||
acc = acc * PRIME64_1 + PRIME64_4;
|
|
||||||
return acc;
|
|
||||||
}
|
|
||||||
|
|
||||||
FORCE_INLINE_TEMPLATE U64 XXH64_endian_align(const void* input, size_t len, U64 seed, XXH_endianess endian, XXH_alignment align)
|
|
||||||
{
|
|
||||||
const BYTE* p = (const BYTE*)input;
|
|
||||||
const BYTE* const bEnd = p + len;
|
|
||||||
U64 h64;
|
|
||||||
#define XXH_get64bits(p) XXH_readLE64_align(p, endian, align)
|
|
||||||
|
|
||||||
#ifdef XXH_ACCEPT_NULL_INPUT_POINTER
|
|
||||||
if (p==NULL) {
|
|
||||||
len=0;
|
|
||||||
bEnd=p=(const BYTE*)(size_t)32;
|
|
||||||
}
|
|
||||||
#endif
|
|
||||||
|
|
||||||
if (len>=32) {
|
|
||||||
const BYTE* const limit = bEnd - 32;
|
|
||||||
U64 v1 = seed + PRIME64_1 + PRIME64_2;
|
|
||||||
U64 v2 = seed + PRIME64_2;
|
|
||||||
U64 v3 = seed + 0;
|
|
||||||
U64 v4 = seed - PRIME64_1;
|
|
||||||
|
|
||||||
do {
|
|
||||||
v1 = XXH64_round(v1, XXH_get64bits(p)); p+=8;
|
|
||||||
v2 = XXH64_round(v2, XXH_get64bits(p)); p+=8;
|
|
||||||
v3 = XXH64_round(v3, XXH_get64bits(p)); p+=8;
|
|
||||||
v4 = XXH64_round(v4, XXH_get64bits(p)); p+=8;
|
|
||||||
} while (p<=limit);
|
|
||||||
|
|
||||||
h64 = XXH_rotl64(v1, 1) + XXH_rotl64(v2, 7) + XXH_rotl64(v3, 12) + XXH_rotl64(v4, 18);
|
|
||||||
h64 = XXH64_mergeRound(h64, v1);
|
|
||||||
h64 = XXH64_mergeRound(h64, v2);
|
|
||||||
h64 = XXH64_mergeRound(h64, v3);
|
|
||||||
h64 = XXH64_mergeRound(h64, v4);
|
|
||||||
|
|
||||||
} else {
|
|
||||||
h64 = seed + PRIME64_5;
|
|
||||||
}
|
|
||||||
|
|
||||||
h64 += (U64) len;
|
|
||||||
|
|
||||||
while (p+8<=bEnd) {
|
|
||||||
U64 const k1 = XXH64_round(0, XXH_get64bits(p));
|
|
||||||
h64 ^= k1;
|
|
||||||
h64 = XXH_rotl64(h64,27) * PRIME64_1 + PRIME64_4;
|
|
||||||
p+=8;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (p+4<=bEnd) {
|
|
||||||
h64 ^= (U64)(XXH_get32bits(p)) * PRIME64_1;
|
|
||||||
h64 = XXH_rotl64(h64, 23) * PRIME64_2 + PRIME64_3;
|
|
||||||
p+=4;
|
|
||||||
}
|
|
||||||
|
|
||||||
while (p<bEnd) {
|
|
||||||
h64 ^= (*p) * PRIME64_5;
|
|
||||||
h64 = XXH_rotl64(h64, 11) * PRIME64_1;
|
|
||||||
p++;
|
|
||||||
}
|
|
||||||
|
|
||||||
h64 ^= h64 >> 33;
|
|
||||||
h64 *= PRIME64_2;
|
|
||||||
h64 ^= h64 >> 29;
|
|
||||||
h64 *= PRIME64_3;
|
|
||||||
h64 ^= h64 >> 32;
|
|
||||||
|
|
||||||
return h64;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
XXH_PUBLIC_API unsigned long long XXH64 (const void* input, size_t len, unsigned long long seed)
|
|
||||||
{
|
|
||||||
#if 0
|
|
||||||
/* Simple version, good for code maintenance, but unfortunately slow for small inputs */
|
|
||||||
XXH64_CREATESTATE_STATIC(state);
|
|
||||||
XXH64_reset(state, seed);
|
|
||||||
XXH64_update(state, input, len);
|
|
||||||
return XXH64_digest(state);
|
|
||||||
#else
|
|
||||||
XXH_endianess endian_detected = (XXH_endianess)XXH_CPU_LITTLE_ENDIAN;
|
|
||||||
|
|
||||||
if (XXH_FORCE_ALIGN_CHECK) {
|
|
||||||
if ((((size_t)input) & 7)==0) { /* Input is aligned, let's leverage the speed advantage */
|
|
||||||
if ((endian_detected==XXH_littleEndian) || XXH_FORCE_NATIVE_FORMAT)
|
|
||||||
return XXH64_endian_align(input, len, seed, XXH_littleEndian, XXH_aligned);
|
|
||||||
else
|
|
||||||
return XXH64_endian_align(input, len, seed, XXH_bigEndian, XXH_aligned);
|
|
||||||
} }
|
|
||||||
|
|
||||||
if ((endian_detected==XXH_littleEndian) || XXH_FORCE_NATIVE_FORMAT)
|
|
||||||
return XXH64_endian_align(input, len, seed, XXH_littleEndian, XXH_unaligned);
|
|
||||||
else
|
|
||||||
return XXH64_endian_align(input, len, seed, XXH_bigEndian, XXH_unaligned);
|
|
||||||
#endif
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
/* **************************************************
|
|
||||||
* Advanced Hash Functions
|
|
||||||
****************************************************/
|
|
||||||
|
|
||||||
XXH_PUBLIC_API XXH32_state_t* XXH32_createState(void)
|
|
||||||
{
|
|
||||||
return (XXH32_state_t*)XXH_malloc(sizeof(XXH32_state_t));
|
|
||||||
}
|
|
||||||
XXH_PUBLIC_API XXH_errorcode XXH32_freeState(XXH32_state_t* statePtr)
|
|
||||||
{
|
|
||||||
XXH_free(statePtr);
|
|
||||||
return XXH_OK;
|
|
||||||
}
|
|
||||||
|
|
||||||
XXH_PUBLIC_API XXH64_state_t* XXH64_createState(void)
|
|
||||||
{
|
|
||||||
return (XXH64_state_t*)XXH_malloc(sizeof(XXH64_state_t));
|
|
||||||
}
|
|
||||||
XXH_PUBLIC_API XXH_errorcode XXH64_freeState(XXH64_state_t* statePtr)
|
|
||||||
{
|
|
||||||
XXH_free(statePtr);
|
|
||||||
return XXH_OK;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
/*** Hash feed ***/
|
|
||||||
|
|
||||||
XXH_PUBLIC_API XXH_errorcode XXH32_reset(XXH32_state_t* statePtr, unsigned int seed)
|
|
||||||
{
|
|
||||||
XXH32_state_t state; /* using a local state to memcpy() in order to avoid strict-aliasing warnings */
|
|
||||||
memset(&state, 0, sizeof(state)-4); /* do not write into reserved, for future removal */
|
|
||||||
state.v1 = seed + PRIME32_1 + PRIME32_2;
|
|
||||||
state.v2 = seed + PRIME32_2;
|
|
||||||
state.v3 = seed + 0;
|
|
||||||
state.v4 = seed - PRIME32_1;
|
|
||||||
memcpy(statePtr, &state, sizeof(state));
|
|
||||||
return XXH_OK;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
XXH_PUBLIC_API XXH_errorcode XXH64_reset(XXH64_state_t* statePtr, unsigned long long seed)
|
|
||||||
{
|
|
||||||
XXH64_state_t state; /* using a local state to memcpy() in order to avoid strict-aliasing warnings */
|
|
||||||
memset(&state, 0, sizeof(state)-8); /* do not write into reserved, for future removal */
|
|
||||||
state.v1 = seed + PRIME64_1 + PRIME64_2;
|
|
||||||
state.v2 = seed + PRIME64_2;
|
|
||||||
state.v3 = seed + 0;
|
|
||||||
state.v4 = seed - PRIME64_1;
|
|
||||||
memcpy(statePtr, &state, sizeof(state));
|
|
||||||
return XXH_OK;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
FORCE_INLINE_TEMPLATE XXH_errorcode XXH32_update_endian (XXH32_state_t* state, const void* input, size_t len, XXH_endianess endian)
|
|
||||||
{
|
|
||||||
const BYTE* p = (const BYTE*)input;
|
|
||||||
const BYTE* const bEnd = p + len;
|
|
||||||
|
|
||||||
#ifdef XXH_ACCEPT_NULL_INPUT_POINTER
|
|
||||||
if (input==NULL) return XXH_ERROR;
|
|
||||||
#endif
|
|
||||||
|
|
||||||
state->total_len_32 += (unsigned)len;
|
|
||||||
state->large_len |= (len>=16) | (state->total_len_32>=16);
|
|
||||||
|
|
||||||
if (state->memsize + len < 16) { /* fill in tmp buffer */
|
|
||||||
XXH_memcpy((BYTE*)(state->mem32) + state->memsize, input, len);
|
|
||||||
state->memsize += (unsigned)len;
|
|
||||||
return XXH_OK;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (state->memsize) { /* some data left from previous update */
|
|
||||||
XXH_memcpy((BYTE*)(state->mem32) + state->memsize, input, 16-state->memsize);
|
|
||||||
{ const U32* p32 = state->mem32;
|
|
||||||
state->v1 = XXH32_round(state->v1, XXH_readLE32(p32, endian)); p32++;
|
|
||||||
state->v2 = XXH32_round(state->v2, XXH_readLE32(p32, endian)); p32++;
|
|
||||||
state->v3 = XXH32_round(state->v3, XXH_readLE32(p32, endian)); p32++;
|
|
||||||
state->v4 = XXH32_round(state->v4, XXH_readLE32(p32, endian)); p32++;
|
|
||||||
}
|
|
||||||
p += 16-state->memsize;
|
|
||||||
state->memsize = 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (p <= bEnd-16) {
|
|
||||||
const BYTE* const limit = bEnd - 16;
|
|
||||||
U32 v1 = state->v1;
|
|
||||||
U32 v2 = state->v2;
|
|
||||||
U32 v3 = state->v3;
|
|
||||||
U32 v4 = state->v4;
|
|
||||||
|
|
||||||
do {
|
|
||||||
v1 = XXH32_round(v1, XXH_readLE32(p, endian)); p+=4;
|
|
||||||
v2 = XXH32_round(v2, XXH_readLE32(p, endian)); p+=4;
|
|
||||||
v3 = XXH32_round(v3, XXH_readLE32(p, endian)); p+=4;
|
|
||||||
v4 = XXH32_round(v4, XXH_readLE32(p, endian)); p+=4;
|
|
||||||
} while (p<=limit);
|
|
||||||
|
|
||||||
state->v1 = v1;
|
|
||||||
state->v2 = v2;
|
|
||||||
state->v3 = v3;
|
|
||||||
state->v4 = v4;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (p < bEnd) {
|
|
||||||
XXH_memcpy(state->mem32, p, (size_t)(bEnd-p));
|
|
||||||
state->memsize = (unsigned)(bEnd-p);
|
|
||||||
}
|
|
||||||
|
|
||||||
return XXH_OK;
|
|
||||||
}
|
|
||||||
|
|
||||||
XXH_PUBLIC_API XXH_errorcode XXH32_update (XXH32_state_t* state_in, const void* input, size_t len)
|
|
||||||
{
|
|
||||||
XXH_endianess endian_detected = (XXH_endianess)XXH_CPU_LITTLE_ENDIAN;
|
|
||||||
|
|
||||||
if ((endian_detected==XXH_littleEndian) || XXH_FORCE_NATIVE_FORMAT)
|
|
||||||
return XXH32_update_endian(state_in, input, len, XXH_littleEndian);
|
|
||||||
else
|
|
||||||
return XXH32_update_endian(state_in, input, len, XXH_bigEndian);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
FORCE_INLINE_TEMPLATE U32 XXH32_digest_endian (const XXH32_state_t* state, XXH_endianess endian)
|
|
||||||
{
|
|
||||||
const BYTE * p = (const BYTE*)state->mem32;
|
|
||||||
const BYTE* const bEnd = (const BYTE*)(state->mem32) + state->memsize;
|
|
||||||
U32 h32;
|
|
||||||
|
|
||||||
if (state->large_len) {
|
|
||||||
h32 = XXH_rotl32(state->v1, 1) + XXH_rotl32(state->v2, 7) + XXH_rotl32(state->v3, 12) + XXH_rotl32(state->v4, 18);
|
|
||||||
} else {
|
|
||||||
h32 = state->v3 /* == seed */ + PRIME32_5;
|
|
||||||
}
|
|
||||||
|
|
||||||
h32 += state->total_len_32;
|
|
||||||
|
|
||||||
while (p+4<=bEnd) {
|
|
||||||
h32 += XXH_readLE32(p, endian) * PRIME32_3;
|
|
||||||
h32 = XXH_rotl32(h32, 17) * PRIME32_4;
|
|
||||||
p+=4;
|
|
||||||
}
|
|
||||||
|
|
||||||
while (p<bEnd) {
|
|
||||||
h32 += (*p) * PRIME32_5;
|
|
||||||
h32 = XXH_rotl32(h32, 11) * PRIME32_1;
|
|
||||||
p++;
|
|
||||||
}
|
|
||||||
|
|
||||||
h32 ^= h32 >> 15;
|
|
||||||
h32 *= PRIME32_2;
|
|
||||||
h32 ^= h32 >> 13;
|
|
||||||
h32 *= PRIME32_3;
|
|
||||||
h32 ^= h32 >> 16;
|
|
||||||
|
|
||||||
return h32;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
XXH_PUBLIC_API unsigned int XXH32_digest (const XXH32_state_t* state_in)
|
|
||||||
{
|
|
||||||
XXH_endianess endian_detected = (XXH_endianess)XXH_CPU_LITTLE_ENDIAN;
|
|
||||||
|
|
||||||
if ((endian_detected==XXH_littleEndian) || XXH_FORCE_NATIVE_FORMAT)
|
|
||||||
return XXH32_digest_endian(state_in, XXH_littleEndian);
|
|
||||||
else
|
|
||||||
return XXH32_digest_endian(state_in, XXH_bigEndian);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/* **** XXH64 **** */
|
|
||||||
|
|
||||||
FORCE_INLINE_TEMPLATE XXH_errorcode XXH64_update_endian (XXH64_state_t* state, const void* input, size_t len, XXH_endianess endian)
|
|
||||||
{
|
|
||||||
const BYTE* p = (const BYTE*)input;
|
|
||||||
const BYTE* const bEnd = p + len;
|
|
||||||
|
|
||||||
#ifdef XXH_ACCEPT_NULL_INPUT_POINTER
|
|
||||||
if (input==NULL) return XXH_ERROR;
|
|
||||||
#endif
|
|
||||||
|
|
||||||
state->total_len += len;
|
|
||||||
|
|
||||||
if (state->memsize + len < 32) { /* fill in tmp buffer */
|
|
||||||
XXH_memcpy(((BYTE*)state->mem64) + state->memsize, input, len);
|
|
||||||
state->memsize += (U32)len;
|
|
||||||
return XXH_OK;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (state->memsize) { /* tmp buffer is full */
|
|
||||||
XXH_memcpy(((BYTE*)state->mem64) + state->memsize, input, 32-state->memsize);
|
|
||||||
state->v1 = XXH64_round(state->v1, XXH_readLE64(state->mem64+0, endian));
|
|
||||||
state->v2 = XXH64_round(state->v2, XXH_readLE64(state->mem64+1, endian));
|
|
||||||
state->v3 = XXH64_round(state->v3, XXH_readLE64(state->mem64+2, endian));
|
|
||||||
state->v4 = XXH64_round(state->v4, XXH_readLE64(state->mem64+3, endian));
|
|
||||||
p += 32-state->memsize;
|
|
||||||
state->memsize = 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (p+32 <= bEnd) {
|
|
||||||
const BYTE* const limit = bEnd - 32;
|
|
||||||
U64 v1 = state->v1;
|
|
||||||
U64 v2 = state->v2;
|
|
||||||
U64 v3 = state->v3;
|
|
||||||
U64 v4 = state->v4;
|
|
||||||
|
|
||||||
do {
|
|
||||||
v1 = XXH64_round(v1, XXH_readLE64(p, endian)); p+=8;
|
|
||||||
v2 = XXH64_round(v2, XXH_readLE64(p, endian)); p+=8;
|
|
||||||
v3 = XXH64_round(v3, XXH_readLE64(p, endian)); p+=8;
|
|
||||||
v4 = XXH64_round(v4, XXH_readLE64(p, endian)); p+=8;
|
|
||||||
} while (p<=limit);
|
|
||||||
|
|
||||||
state->v1 = v1;
|
|
||||||
state->v2 = v2;
|
|
||||||
state->v3 = v3;
|
|
||||||
state->v4 = v4;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (p < bEnd) {
|
|
||||||
XXH_memcpy(state->mem64, p, (size_t)(bEnd-p));
|
|
||||||
state->memsize = (unsigned)(bEnd-p);
|
|
||||||
}
|
|
||||||
|
|
||||||
return XXH_OK;
|
|
||||||
}
|
|
||||||
|
|
||||||
XXH_PUBLIC_API XXH_errorcode XXH64_update (XXH64_state_t* state_in, const void* input, size_t len)
|
|
||||||
{
|
|
||||||
XXH_endianess endian_detected = (XXH_endianess)XXH_CPU_LITTLE_ENDIAN;
|
|
||||||
|
|
||||||
if ((endian_detected==XXH_littleEndian) || XXH_FORCE_NATIVE_FORMAT)
|
|
||||||
return XXH64_update_endian(state_in, input, len, XXH_littleEndian);
|
|
||||||
else
|
|
||||||
return XXH64_update_endian(state_in, input, len, XXH_bigEndian);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
FORCE_INLINE_TEMPLATE U64 XXH64_digest_endian (const XXH64_state_t* state, XXH_endianess endian)
|
|
||||||
{
|
|
||||||
const BYTE * p = (const BYTE*)state->mem64;
|
|
||||||
const BYTE* const bEnd = (const BYTE*)state->mem64 + state->memsize;
|
|
||||||
U64 h64;
|
|
||||||
|
|
||||||
if (state->total_len >= 32) {
|
|
||||||
U64 const v1 = state->v1;
|
|
||||||
U64 const v2 = state->v2;
|
|
||||||
U64 const v3 = state->v3;
|
|
||||||
U64 const v4 = state->v4;
|
|
||||||
|
|
||||||
h64 = XXH_rotl64(v1, 1) + XXH_rotl64(v2, 7) + XXH_rotl64(v3, 12) + XXH_rotl64(v4, 18);
|
|
||||||
h64 = XXH64_mergeRound(h64, v1);
|
|
||||||
h64 = XXH64_mergeRound(h64, v2);
|
|
||||||
h64 = XXH64_mergeRound(h64, v3);
|
|
||||||
h64 = XXH64_mergeRound(h64, v4);
|
|
||||||
} else {
|
|
||||||
h64 = state->v3 + PRIME64_5;
|
|
||||||
}
|
|
||||||
|
|
||||||
h64 += (U64) state->total_len;
|
|
||||||
|
|
||||||
while (p+8<=bEnd) {
|
|
||||||
U64 const k1 = XXH64_round(0, XXH_readLE64(p, endian));
|
|
||||||
h64 ^= k1;
|
|
||||||
h64 = XXH_rotl64(h64,27) * PRIME64_1 + PRIME64_4;
|
|
||||||
p+=8;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (p+4<=bEnd) {
|
|
||||||
h64 ^= (U64)(XXH_readLE32(p, endian)) * PRIME64_1;
|
|
||||||
h64 = XXH_rotl64(h64, 23) * PRIME64_2 + PRIME64_3;
|
|
||||||
p+=4;
|
|
||||||
}
|
|
||||||
|
|
||||||
while (p<bEnd) {
|
|
||||||
h64 ^= (*p) * PRIME64_5;
|
|
||||||
h64 = XXH_rotl64(h64, 11) * PRIME64_1;
|
|
||||||
p++;
|
|
||||||
}
|
|
||||||
|
|
||||||
h64 ^= h64 >> 33;
|
|
||||||
h64 *= PRIME64_2;
|
|
||||||
h64 ^= h64 >> 29;
|
|
||||||
h64 *= PRIME64_3;
|
|
||||||
h64 ^= h64 >> 32;
|
|
||||||
|
|
||||||
return h64;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
XXH_PUBLIC_API unsigned long long XXH64_digest (const XXH64_state_t* state_in)
|
|
||||||
{
|
|
||||||
XXH_endianess endian_detected = (XXH_endianess)XXH_CPU_LITTLE_ENDIAN;
|
|
||||||
|
|
||||||
if ((endian_detected==XXH_littleEndian) || XXH_FORCE_NATIVE_FORMAT)
|
|
||||||
return XXH64_digest_endian(state_in, XXH_littleEndian);
|
|
||||||
else
|
|
||||||
return XXH64_digest_endian(state_in, XXH_bigEndian);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
/* **************************
|
|
||||||
* Canonical representation
|
|
||||||
****************************/
|
|
||||||
|
|
||||||
/*! Default XXH result types are basic unsigned 32 and 64 bits.
|
|
||||||
* The canonical representation follows human-readable write convention, aka big-endian (large digits first).
|
|
||||||
* These functions allow transformation of hash result into and from its canonical format.
|
|
||||||
* This way, hash values can be written into a file or buffer, and remain comparable across different systems and programs.
|
|
||||||
*/
|
|
||||||
|
|
||||||
XXH_PUBLIC_API void XXH32_canonicalFromHash(XXH32_canonical_t* dst, XXH32_hash_t hash)
|
|
||||||
{
|
|
||||||
XXH_STATIC_ASSERT(sizeof(XXH32_canonical_t) == sizeof(XXH32_hash_t));
|
|
||||||
if (XXH_CPU_LITTLE_ENDIAN) hash = XXH_swap32(hash);
|
|
||||||
memcpy(dst, &hash, sizeof(*dst));
|
|
||||||
}
|
|
||||||
|
|
||||||
XXH_PUBLIC_API void XXH64_canonicalFromHash(XXH64_canonical_t* dst, XXH64_hash_t hash)
|
|
||||||
{
|
|
||||||
XXH_STATIC_ASSERT(sizeof(XXH64_canonical_t) == sizeof(XXH64_hash_t));
|
|
||||||
if (XXH_CPU_LITTLE_ENDIAN) hash = XXH_swap64(hash);
|
|
||||||
memcpy(dst, &hash, sizeof(*dst));
|
|
||||||
}
|
|
||||||
|
|
||||||
XXH_PUBLIC_API XXH32_hash_t XXH32_hashFromCanonical(const XXH32_canonical_t* src)
|
|
||||||
{
|
|
||||||
return XXH_readBE32(src);
|
|
||||||
}
|
|
||||||
|
|
||||||
XXH_PUBLIC_API XXH64_hash_t XXH64_hashFromCanonical(const XXH64_canonical_t* src)
|
|
||||||
{
|
|
||||||
return XXH_readBE64(src);
|
|
||||||
}
|
|
||||||
|
|||||||
5778
vendor/github.com/DataDog/zstd/xxhash.h
generated
vendored
5778
vendor/github.com/DataDog/zstd/xxhash.h
generated
vendored
File diff suppressed because it is too large
Load Diff
5
vendor/github.com/DataDog/zstd/zbuff.h
generated
vendored
5
vendor/github.com/DataDog/zstd/zbuff.h
generated
vendored
@@ -1,5 +1,6 @@
|
|||||||
|
#ifndef USE_EXTERNAL_ZSTD
|
||||||
/*
|
/*
|
||||||
* Copyright (c) 2016-present, Yann Collet, Facebook, Inc.
|
* Copyright (c) Meta Platforms, Inc. and affiliates.
|
||||||
* All rights reserved.
|
* All rights reserved.
|
||||||
*
|
*
|
||||||
* This source code is licensed under both the BSD-style license (found in the
|
* This source code is licensed under both the BSD-style license (found in the
|
||||||
@@ -212,3 +213,5 @@ ZBUFF_DEPRECATED("use ZSTD_initDStream_usingDict") size_t ZBUFF_compressInit_adv
|
|||||||
#if defined (__cplusplus)
|
#if defined (__cplusplus)
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
#endif /* USE_EXTERNAL_ZSTD */
|
||||||
|
|||||||
5
vendor/github.com/DataDog/zstd/zbuff_common.c
generated
vendored
5
vendor/github.com/DataDog/zstd/zbuff_common.c
generated
vendored
@@ -1,5 +1,6 @@
|
|||||||
|
#ifndef USE_EXTERNAL_ZSTD
|
||||||
/*
|
/*
|
||||||
* Copyright (c) 2016-present, Yann Collet, Facebook, Inc.
|
* Copyright (c) Meta Platforms, Inc. and affiliates.
|
||||||
* All rights reserved.
|
* All rights reserved.
|
||||||
*
|
*
|
||||||
* This source code is licensed under both the BSD-style license (found in the
|
* This source code is licensed under both the BSD-style license (found in the
|
||||||
@@ -24,3 +25,5 @@ unsigned ZBUFF_isError(size_t errorCode) { return ERR_isError(errorCode); }
|
|||||||
/*! ZBUFF_getErrorName() :
|
/*! ZBUFF_getErrorName() :
|
||||||
* provides error code string from function result (useful for debugging) */
|
* provides error code string from function result (useful for debugging) */
|
||||||
const char* ZBUFF_getErrorName(size_t errorCode) { return ERR_getErrorName(errorCode); }
|
const char* ZBUFF_getErrorName(size_t errorCode) { return ERR_getErrorName(errorCode); }
|
||||||
|
|
||||||
|
#endif /* USE_EXTERNAL_ZSTD */
|
||||||
|
|||||||
31
vendor/github.com/DataDog/zstd/zbuff_compress.c
generated
vendored
31
vendor/github.com/DataDog/zstd/zbuff_compress.c
generated
vendored
@@ -1,5 +1,6 @@
|
|||||||
|
#ifndef USE_EXTERNAL_ZSTD
|
||||||
/*
|
/*
|
||||||
* Copyright (c) 2016-present, Yann Collet, Facebook, Inc.
|
* Copyright (c) Meta Platforms, Inc. and affiliates.
|
||||||
* All rights reserved.
|
* All rights reserved.
|
||||||
*
|
*
|
||||||
* This source code is licensed under both the BSD-style license (found in the
|
* This source code is licensed under both the BSD-style license (found in the
|
||||||
@@ -15,6 +16,7 @@
|
|||||||
***************************************/
|
***************************************/
|
||||||
#define ZBUFF_STATIC_LINKING_ONLY
|
#define ZBUFF_STATIC_LINKING_ONLY
|
||||||
#include "zbuff.h"
|
#include "zbuff.h"
|
||||||
|
#include "error_private.h"
|
||||||
|
|
||||||
|
|
||||||
/*-***********************************************************
|
/*-***********************************************************
|
||||||
@@ -73,13 +75,32 @@ size_t ZBUFF_compressInit_advanced(ZBUFF_CCtx* zbc,
|
|||||||
ZSTD_parameters params, unsigned long long pledgedSrcSize)
|
ZSTD_parameters params, unsigned long long pledgedSrcSize)
|
||||||
{
|
{
|
||||||
if (pledgedSrcSize==0) pledgedSrcSize = ZSTD_CONTENTSIZE_UNKNOWN; /* preserve "0 == unknown" behavior */
|
if (pledgedSrcSize==0) pledgedSrcSize = ZSTD_CONTENTSIZE_UNKNOWN; /* preserve "0 == unknown" behavior */
|
||||||
return ZSTD_initCStream_advanced(zbc, dict, dictSize, params, pledgedSrcSize);
|
FORWARD_IF_ERROR(ZSTD_CCtx_reset(zbc, ZSTD_reset_session_only), "");
|
||||||
}
|
FORWARD_IF_ERROR(ZSTD_CCtx_setPledgedSrcSize(zbc, pledgedSrcSize), "");
|
||||||
|
|
||||||
|
FORWARD_IF_ERROR(ZSTD_checkCParams(params.cParams), "");
|
||||||
|
FORWARD_IF_ERROR(ZSTD_CCtx_setParameter(zbc, ZSTD_c_windowLog, params.cParams.windowLog), "");
|
||||||
|
FORWARD_IF_ERROR(ZSTD_CCtx_setParameter(zbc, ZSTD_c_hashLog, params.cParams.hashLog), "");
|
||||||
|
FORWARD_IF_ERROR(ZSTD_CCtx_setParameter(zbc, ZSTD_c_chainLog, params.cParams.chainLog), "");
|
||||||
|
FORWARD_IF_ERROR(ZSTD_CCtx_setParameter(zbc, ZSTD_c_searchLog, params.cParams.searchLog), "");
|
||||||
|
FORWARD_IF_ERROR(ZSTD_CCtx_setParameter(zbc, ZSTD_c_minMatch, params.cParams.minMatch), "");
|
||||||
|
FORWARD_IF_ERROR(ZSTD_CCtx_setParameter(zbc, ZSTD_c_targetLength, params.cParams.targetLength), "");
|
||||||
|
FORWARD_IF_ERROR(ZSTD_CCtx_setParameter(zbc, ZSTD_c_strategy, params.cParams.strategy), "");
|
||||||
|
|
||||||
|
FORWARD_IF_ERROR(ZSTD_CCtx_setParameter(zbc, ZSTD_c_contentSizeFlag, params.fParams.contentSizeFlag), "");
|
||||||
|
FORWARD_IF_ERROR(ZSTD_CCtx_setParameter(zbc, ZSTD_c_checksumFlag, params.fParams.checksumFlag), "");
|
||||||
|
FORWARD_IF_ERROR(ZSTD_CCtx_setParameter(zbc, ZSTD_c_dictIDFlag, params.fParams.noDictIDFlag), "");
|
||||||
|
|
||||||
|
FORWARD_IF_ERROR(ZSTD_CCtx_loadDictionary(zbc, dict, dictSize), "");
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
size_t ZBUFF_compressInitDictionary(ZBUFF_CCtx* zbc, const void* dict, size_t dictSize, int compressionLevel)
|
size_t ZBUFF_compressInitDictionary(ZBUFF_CCtx* zbc, const void* dict, size_t dictSize, int compressionLevel)
|
||||||
{
|
{
|
||||||
return ZSTD_initCStream_usingDict(zbc, dict, dictSize, compressionLevel);
|
FORWARD_IF_ERROR(ZSTD_CCtx_reset(zbc, ZSTD_reset_session_only), "");
|
||||||
|
FORWARD_IF_ERROR(ZSTD_CCtx_setParameter(zbc, ZSTD_c_compressionLevel, compressionLevel), "");
|
||||||
|
FORWARD_IF_ERROR(ZSTD_CCtx_loadDictionary(zbc, dict, dictSize), "");
|
||||||
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
size_t ZBUFF_compressInit(ZBUFF_CCtx* zbc, int compressionLevel)
|
size_t ZBUFF_compressInit(ZBUFF_CCtx* zbc, int compressionLevel)
|
||||||
@@ -145,3 +166,5 @@ size_t ZBUFF_compressEnd(ZBUFF_CCtx* zbc, void* dst, size_t* dstCapacityPtr)
|
|||||||
***************************************/
|
***************************************/
|
||||||
size_t ZBUFF_recommendedCInSize(void) { return ZSTD_CStreamInSize(); }
|
size_t ZBUFF_recommendedCInSize(void) { return ZSTD_CStreamInSize(); }
|
||||||
size_t ZBUFF_recommendedCOutSize(void) { return ZSTD_CStreamOutSize(); }
|
size_t ZBUFF_recommendedCOutSize(void) { return ZSTD_CStreamOutSize(); }
|
||||||
|
|
||||||
|
#endif /* USE_EXTERNAL_ZSTD */
|
||||||
|
|||||||
7
vendor/github.com/DataDog/zstd/zbuff_decompress.c
generated
vendored
7
vendor/github.com/DataDog/zstd/zbuff_decompress.c
generated
vendored
@@ -1,5 +1,6 @@
|
|||||||
|
#ifndef USE_EXTERNAL_ZSTD
|
||||||
/*
|
/*
|
||||||
* Copyright (c) 2016-present, Yann Collet, Facebook, Inc.
|
* Copyright (c) Meta Platforms, Inc. and affiliates.
|
||||||
* All rights reserved.
|
* All rights reserved.
|
||||||
*
|
*
|
||||||
* This source code is licensed under both the BSD-style license (found in the
|
* This source code is licensed under both the BSD-style license (found in the
|
||||||
@@ -13,6 +14,8 @@
|
|||||||
/* *************************************
|
/* *************************************
|
||||||
* Dependencies
|
* Dependencies
|
||||||
***************************************/
|
***************************************/
|
||||||
|
#define ZSTD_DISABLE_DEPRECATE_WARNINGS /* suppress warning on ZSTD_initDStream_usingDict */
|
||||||
|
#include "zstd.h" /* ZSTD_CStream, ZSTD_DStream, ZSTDLIB_API */
|
||||||
#define ZBUFF_STATIC_LINKING_ONLY
|
#define ZBUFF_STATIC_LINKING_ONLY
|
||||||
#include "zbuff.h"
|
#include "zbuff.h"
|
||||||
|
|
||||||
@@ -73,3 +76,5 @@ size_t ZBUFF_decompressContinue(ZBUFF_DCtx* zbd,
|
|||||||
***************************************/
|
***************************************/
|
||||||
size_t ZBUFF_recommendedDInSize(void) { return ZSTD_DStreamInSize(); }
|
size_t ZBUFF_recommendedDInSize(void) { return ZSTD_DStreamInSize(); }
|
||||||
size_t ZBUFF_recommendedDOutSize(void) { return ZSTD_DStreamOutSize(); }
|
size_t ZBUFF_recommendedDOutSize(void) { return ZSTD_DStreamOutSize(); }
|
||||||
|
|
||||||
|
#endif /* USE_EXTERNAL_ZSTD */
|
||||||
|
|||||||
235
vendor/github.com/DataDog/zstd/zdict.c
generated
vendored
235
vendor/github.com/DataDog/zstd/zdict.c
generated
vendored
@@ -1,5 +1,6 @@
|
|||||||
|
#ifndef USE_EXTERNAL_ZSTD
|
||||||
/*
|
/*
|
||||||
* Copyright (c) 2016-present, Yann Collet, Facebook, Inc.
|
* Copyright (c) Meta Platforms, Inc. and affiliates.
|
||||||
* All rights reserved.
|
* All rights reserved.
|
||||||
*
|
*
|
||||||
* This source code is licensed under both the BSD-style license (found in the
|
* This source code is licensed under both the BSD-style license (found in the
|
||||||
@@ -23,9 +24,13 @@
|
|||||||
/* Unix Large Files support (>4GB) */
|
/* Unix Large Files support (>4GB) */
|
||||||
#define _FILE_OFFSET_BITS 64
|
#define _FILE_OFFSET_BITS 64
|
||||||
#if (defined(__sun__) && (!defined(__LP64__))) /* Sun Solaris 32-bits requires specific definitions */
|
#if (defined(__sun__) && (!defined(__LP64__))) /* Sun Solaris 32-bits requires specific definitions */
|
||||||
|
# ifndef _LARGEFILE_SOURCE
|
||||||
# define _LARGEFILE_SOURCE
|
# define _LARGEFILE_SOURCE
|
||||||
|
# endif
|
||||||
#elif ! defined(__LP64__) /* No point defining Large file for 64 bit */
|
#elif ! defined(__LP64__) /* No point defining Large file for 64 bit */
|
||||||
|
# ifndef _LARGEFILE64_SOURCE
|
||||||
# define _LARGEFILE64_SOURCE
|
# define _LARGEFILE64_SOURCE
|
||||||
|
# endif
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
|
||||||
@@ -37,17 +42,19 @@
|
|||||||
#include <stdio.h> /* fprintf, fopen, ftello64 */
|
#include <stdio.h> /* fprintf, fopen, ftello64 */
|
||||||
#include <time.h> /* clock */
|
#include <time.h> /* clock */
|
||||||
|
|
||||||
#include "mem.h" /* read */
|
|
||||||
#include "fse.h" /* FSE_normalizeCount, FSE_writeNCount */
|
|
||||||
#define HUF_STATIC_LINKING_ONLY
|
|
||||||
#include "huf.h" /* HUF_buildCTable, HUF_writeCTable */
|
|
||||||
#include "zstd_internal.h" /* includes zstd.h */
|
|
||||||
#include "xxhash.h" /* XXH64 */
|
|
||||||
#include "divsufsort.h"
|
|
||||||
#ifndef ZDICT_STATIC_LINKING_ONLY
|
#ifndef ZDICT_STATIC_LINKING_ONLY
|
||||||
# define ZDICT_STATIC_LINKING_ONLY
|
# define ZDICT_STATIC_LINKING_ONLY
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
#include "mem.h" /* read */
|
||||||
|
#include "fse.h" /* FSE_normalizeCount, FSE_writeNCount */
|
||||||
|
#include "huf.h" /* HUF_buildCTable, HUF_writeCTable */
|
||||||
|
#include "zstd_internal.h" /* includes zstd.h */
|
||||||
|
#include "xxhash.h" /* XXH64 */
|
||||||
|
#include "zstd_compress_internal.h" /* ZSTD_loadCEntropy() */
|
||||||
#include "zdict.h"
|
#include "zdict.h"
|
||||||
|
#include "divsufsort.h"
|
||||||
|
#include "bits.h" /* ZSTD_NbCommonBytes */
|
||||||
|
|
||||||
|
|
||||||
/*-*************************************
|
/*-*************************************
|
||||||
@@ -61,14 +68,15 @@
|
|||||||
|
|
||||||
#define NOISELENGTH 32
|
#define NOISELENGTH 32
|
||||||
|
|
||||||
static const int g_compressionLevel_default = 3;
|
|
||||||
static const U32 g_selectivity_default = 9;
|
static const U32 g_selectivity_default = 9;
|
||||||
|
|
||||||
|
|
||||||
/*-*************************************
|
/*-*************************************
|
||||||
* Console display
|
* Console display
|
||||||
***************************************/
|
***************************************/
|
||||||
|
#undef DISPLAY
|
||||||
#define DISPLAY(...) { fprintf(stderr, __VA_ARGS__); fflush( stderr ); }
|
#define DISPLAY(...) { fprintf(stderr, __VA_ARGS__); fflush( stderr ); }
|
||||||
|
#undef DISPLAYLEVEL
|
||||||
#define DISPLAYLEVEL(l, ...) if (notificationLevel>=l) { DISPLAY(__VA_ARGS__); } /* 0 : no display; 1: errors; 2: default; 3: details; 4: debug */
|
#define DISPLAYLEVEL(l, ...) if (notificationLevel>=l) { DISPLAY(__VA_ARGS__); } /* 0 : no display; 1: errors; 2: default; 3: details; 4: debug */
|
||||||
|
|
||||||
static clock_t ZDICT_clockSpan(clock_t nPrevious) { return clock() - nPrevious; }
|
static clock_t ZDICT_clockSpan(clock_t nPrevious) { return clock() - nPrevious; }
|
||||||
@@ -99,69 +107,30 @@ unsigned ZDICT_getDictID(const void* dictBuffer, size_t dictSize)
|
|||||||
return MEM_readLE32((const char*)dictBuffer + 4);
|
return MEM_readLE32((const char*)dictBuffer + 4);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
size_t ZDICT_getDictHeaderSize(const void* dictBuffer, size_t dictSize)
|
||||||
|
{
|
||||||
|
size_t headerSize;
|
||||||
|
if (dictSize <= 8 || MEM_readLE32(dictBuffer) != ZSTD_MAGIC_DICTIONARY) return ERROR(dictionary_corrupted);
|
||||||
|
|
||||||
|
{ ZSTD_compressedBlockState_t* bs = (ZSTD_compressedBlockState_t*)malloc(sizeof(ZSTD_compressedBlockState_t));
|
||||||
|
U32* wksp = (U32*)malloc(HUF_WORKSPACE_SIZE);
|
||||||
|
if (!bs || !wksp) {
|
||||||
|
headerSize = ERROR(memory_allocation);
|
||||||
|
} else {
|
||||||
|
ZSTD_reset_compressedBlockState(bs);
|
||||||
|
headerSize = ZSTD_loadCEntropy(bs, wksp, dictBuffer, dictSize);
|
||||||
|
}
|
||||||
|
|
||||||
|
free(bs);
|
||||||
|
free(wksp);
|
||||||
|
}
|
||||||
|
|
||||||
|
return headerSize;
|
||||||
|
}
|
||||||
|
|
||||||
/*-********************************************************
|
/*-********************************************************
|
||||||
* Dictionary training functions
|
* Dictionary training functions
|
||||||
**********************************************************/
|
**********************************************************/
|
||||||
static unsigned ZDICT_NbCommonBytes (size_t val)
|
|
||||||
{
|
|
||||||
if (MEM_isLittleEndian()) {
|
|
||||||
if (MEM_64bits()) {
|
|
||||||
# if defined(_MSC_VER) && defined(_WIN64)
|
|
||||||
unsigned long r = 0;
|
|
||||||
_BitScanForward64( &r, (U64)val );
|
|
||||||
return (unsigned)(r>>3);
|
|
||||||
# elif defined(__GNUC__) && (__GNUC__ >= 3)
|
|
||||||
return (__builtin_ctzll((U64)val) >> 3);
|
|
||||||
# else
|
|
||||||
static const int DeBruijnBytePos[64] = { 0, 0, 0, 0, 0, 1, 1, 2, 0, 3, 1, 3, 1, 4, 2, 7, 0, 2, 3, 6, 1, 5, 3, 5, 1, 3, 4, 4, 2, 5, 6, 7, 7, 0, 1, 2, 3, 3, 4, 6, 2, 6, 5, 5, 3, 4, 5, 6, 7, 1, 2, 4, 6, 4, 4, 5, 7, 2, 6, 5, 7, 6, 7, 7 };
|
|
||||||
return DeBruijnBytePos[((U64)((val & -(long long)val) * 0x0218A392CDABBD3FULL)) >> 58];
|
|
||||||
# endif
|
|
||||||
} else { /* 32 bits */
|
|
||||||
# if defined(_MSC_VER)
|
|
||||||
unsigned long r=0;
|
|
||||||
_BitScanForward( &r, (U32)val );
|
|
||||||
return (unsigned)(r>>3);
|
|
||||||
# elif defined(__GNUC__) && (__GNUC__ >= 3)
|
|
||||||
return (__builtin_ctz((U32)val) >> 3);
|
|
||||||
# else
|
|
||||||
static const int DeBruijnBytePos[32] = { 0, 0, 3, 0, 3, 1, 3, 0, 3, 2, 2, 1, 3, 2, 0, 1, 3, 3, 1, 2, 2, 2, 2, 0, 3, 1, 2, 0, 1, 0, 1, 1 };
|
|
||||||
return DeBruijnBytePos[((U32)((val & -(S32)val) * 0x077CB531U)) >> 27];
|
|
||||||
# endif
|
|
||||||
}
|
|
||||||
} else { /* Big Endian CPU */
|
|
||||||
if (MEM_64bits()) {
|
|
||||||
# if defined(_MSC_VER) && defined(_WIN64)
|
|
||||||
unsigned long r = 0;
|
|
||||||
_BitScanReverse64( &r, val );
|
|
||||||
return (unsigned)(r>>3);
|
|
||||||
# elif defined(__GNUC__) && (__GNUC__ >= 3)
|
|
||||||
return (__builtin_clzll(val) >> 3);
|
|
||||||
# else
|
|
||||||
unsigned r;
|
|
||||||
const unsigned n32 = sizeof(size_t)*4; /* calculate this way due to compiler complaining in 32-bits mode */
|
|
||||||
if (!(val>>n32)) { r=4; } else { r=0; val>>=n32; }
|
|
||||||
if (!(val>>16)) { r+=2; val>>=8; } else { val>>=24; }
|
|
||||||
r += (!val);
|
|
||||||
return r;
|
|
||||||
# endif
|
|
||||||
} else { /* 32 bits */
|
|
||||||
# if defined(_MSC_VER)
|
|
||||||
unsigned long r = 0;
|
|
||||||
_BitScanReverse( &r, (unsigned long)val );
|
|
||||||
return (unsigned)(r>>3);
|
|
||||||
# elif defined(__GNUC__) && (__GNUC__ >= 3)
|
|
||||||
return (__builtin_clz((U32)val) >> 3);
|
|
||||||
# else
|
|
||||||
unsigned r;
|
|
||||||
if (!(val>>16)) { r=2; val>>=8; } else { r=0; val>>=24; }
|
|
||||||
r += (!val);
|
|
||||||
return r;
|
|
||||||
# endif
|
|
||||||
} }
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
/*! ZDICT_count() :
|
/*! ZDICT_count() :
|
||||||
Count the nb of common bytes between 2 pointers.
|
Count the nb of common bytes between 2 pointers.
|
||||||
Note : this function presumes end of buffer followed by noisy guard band.
|
Note : this function presumes end of buffer followed by noisy guard band.
|
||||||
@@ -176,7 +145,7 @@ static size_t ZDICT_count(const void* pIn, const void* pMatch)
|
|||||||
pMatch = (const char*)pMatch+sizeof(size_t);
|
pMatch = (const char*)pMatch+sizeof(size_t);
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
pIn = (const char*)pIn+ZDICT_NbCommonBytes(diff);
|
pIn = (const char*)pIn+ZSTD_NbCommonBytes(diff);
|
||||||
return (size_t)((const char*)pIn - pStart);
|
return (size_t)((const char*)pIn - pStart);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -208,7 +177,7 @@ static dictItem ZDICT_analyzePos(
|
|||||||
U32 savings[LLIMIT] = {0};
|
U32 savings[LLIMIT] = {0};
|
||||||
const BYTE* b = (const BYTE*)buffer;
|
const BYTE* b = (const BYTE*)buffer;
|
||||||
size_t maxLength = LLIMIT;
|
size_t maxLength = LLIMIT;
|
||||||
size_t pos = suffix[start];
|
size_t pos = (size_t)suffix[start];
|
||||||
U32 end = start;
|
U32 end = start;
|
||||||
dictItem solution;
|
dictItem solution;
|
||||||
|
|
||||||
@@ -342,7 +311,7 @@ static dictItem ZDICT_analyzePos(
|
|||||||
savings[i] = savings[i-1] + (lengthList[i] * (i-3));
|
savings[i] = savings[i-1] + (lengthList[i] * (i-3));
|
||||||
|
|
||||||
DISPLAYLEVEL(4, "Selected dict at position %u, of length %u : saves %u (ratio: %.2f) \n",
|
DISPLAYLEVEL(4, "Selected dict at position %u, of length %u : saves %u (ratio: %.2f) \n",
|
||||||
(unsigned)pos, (unsigned)maxLength, (unsigned)savings[maxLength], (double)savings[maxLength] / maxLength);
|
(unsigned)pos, (unsigned)maxLength, (unsigned)savings[maxLength], (double)savings[maxLength] / (double)maxLength);
|
||||||
|
|
||||||
solution.pos = (U32)pos;
|
solution.pos = (U32)pos;
|
||||||
solution.length = (U32)maxLength;
|
solution.length = (U32)maxLength;
|
||||||
@@ -352,7 +321,7 @@ static dictItem ZDICT_analyzePos(
|
|||||||
{ U32 id;
|
{ U32 id;
|
||||||
for (id=start; id<end; id++) {
|
for (id=start; id<end; id++) {
|
||||||
U32 p, pEnd, length;
|
U32 p, pEnd, length;
|
||||||
U32 const testedPos = suffix[id];
|
U32 const testedPos = (U32)suffix[id];
|
||||||
if (testedPos == pos)
|
if (testedPos == pos)
|
||||||
length = solution.length;
|
length = solution.length;
|
||||||
else {
|
else {
|
||||||
@@ -415,7 +384,7 @@ static U32 ZDICT_tryMerge(dictItem* table, dictItem elt, U32 eltNbToSkip, const
|
|||||||
|
|
||||||
if ((table[u].pos + table[u].length >= elt.pos) && (table[u].pos < elt.pos)) { /* overlap, existing < new */
|
if ((table[u].pos + table[u].length >= elt.pos) && (table[u].pos < elt.pos)) { /* overlap, existing < new */
|
||||||
/* append */
|
/* append */
|
||||||
int const addedLength = (int)eltEnd - (table[u].pos + table[u].length);
|
int const addedLength = (int)eltEnd - (int)(table[u].pos + table[u].length);
|
||||||
table[u].savings += elt.length / 8; /* rough approx bonus */
|
table[u].savings += elt.length / 8; /* rough approx bonus */
|
||||||
if (addedLength > 0) { /* otherwise, elt fully included into existing */
|
if (addedLength > 0) { /* otherwise, elt fully included into existing */
|
||||||
table[u].length += addedLength;
|
table[u].length += addedLength;
|
||||||
@@ -508,6 +477,7 @@ static size_t ZDICT_trainBuffer_legacy(dictItem* dictList, U32 dictListSize,
|
|||||||
clock_t displayClock = 0;
|
clock_t displayClock = 0;
|
||||||
clock_t const refreshRate = CLOCKS_PER_SEC * 3 / 10;
|
clock_t const refreshRate = CLOCKS_PER_SEC * 3 / 10;
|
||||||
|
|
||||||
|
# undef DISPLAYUPDATE
|
||||||
# define DISPLAYUPDATE(l, ...) if (notificationLevel>=l) { \
|
# define DISPLAYUPDATE(l, ...) if (notificationLevel>=l) { \
|
||||||
if (ZDICT_clockSpan(displayClock) > refreshRate) \
|
if (ZDICT_clockSpan(displayClock) > refreshRate) \
|
||||||
{ displayClock = clock(); DISPLAY(__VA_ARGS__); \
|
{ displayClock = clock(); DISPLAY(__VA_ARGS__); \
|
||||||
@@ -554,7 +524,7 @@ static size_t ZDICT_trainBuffer_legacy(dictItem* dictList, U32 dictListSize,
|
|||||||
if (solution.length==0) { cursor++; continue; }
|
if (solution.length==0) { cursor++; continue; }
|
||||||
ZDICT_insertDictItem(dictList, dictListSize, solution, buffer);
|
ZDICT_insertDictItem(dictList, dictListSize, solution, buffer);
|
||||||
cursor += solution.length;
|
cursor += solution.length;
|
||||||
DISPLAYUPDATE(2, "\r%4.2f %% \r", (double)cursor / bufferSize * 100);
|
DISPLAYUPDATE(2, "\r%4.2f %% \r", (double)cursor / (double)bufferSize * 100.0);
|
||||||
} }
|
} }
|
||||||
|
|
||||||
_cleanup:
|
_cleanup:
|
||||||
@@ -588,20 +558,20 @@ typedef struct
|
|||||||
|
|
||||||
#define MAXREPOFFSET 1024
|
#define MAXREPOFFSET 1024
|
||||||
|
|
||||||
static void ZDICT_countEStats(EStats_ress_t esr, ZSTD_parameters params,
|
static void ZDICT_countEStats(EStats_ress_t esr, const ZSTD_parameters* params,
|
||||||
unsigned* countLit, unsigned* offsetcodeCount, unsigned* matchlengthCount, unsigned* litlengthCount, U32* repOffsets,
|
unsigned* countLit, unsigned* offsetcodeCount, unsigned* matchlengthCount, unsigned* litlengthCount, U32* repOffsets,
|
||||||
const void* src, size_t srcSize,
|
const void* src, size_t srcSize,
|
||||||
U32 notificationLevel)
|
U32 notificationLevel)
|
||||||
{
|
{
|
||||||
size_t const blockSizeMax = MIN (ZSTD_BLOCKSIZE_MAX, 1 << params.cParams.windowLog);
|
size_t const blockSizeMax = MIN (ZSTD_BLOCKSIZE_MAX, 1 << params->cParams.windowLog);
|
||||||
size_t cSize;
|
size_t cSize;
|
||||||
|
|
||||||
if (srcSize > blockSizeMax) srcSize = blockSizeMax; /* protection vs large samples */
|
if (srcSize > blockSizeMax) srcSize = blockSizeMax; /* protection vs large samples */
|
||||||
{ size_t const errorCode = ZSTD_compressBegin_usingCDict(esr.zc, esr.dict);
|
{ size_t const errorCode = ZSTD_compressBegin_usingCDict_deprecated(esr.zc, esr.dict);
|
||||||
if (ZSTD_isError(errorCode)) { DISPLAYLEVEL(1, "warning : ZSTD_compressBegin_usingCDict failed \n"); return; }
|
if (ZSTD_isError(errorCode)) { DISPLAYLEVEL(1, "warning : ZSTD_compressBegin_usingCDict failed \n"); return; }
|
||||||
|
|
||||||
}
|
}
|
||||||
cSize = ZSTD_compressBlock(esr.zc, esr.workPlace, ZSTD_BLOCKSIZE_MAX, src, srcSize);
|
cSize = ZSTD_compressBlock_deprecated(esr.zc, esr.workPlace, ZSTD_BLOCKSIZE_MAX, src, srcSize);
|
||||||
if (ZSTD_isError(cSize)) { DISPLAYLEVEL(3, "warning : could not compress sample size %u \n", (unsigned)srcSize); return; }
|
if (ZSTD_isError(cSize)) { DISPLAYLEVEL(3, "warning : could not compress sample size %u \n", (unsigned)srcSize); return; }
|
||||||
|
|
||||||
if (cSize) { /* if == 0; block is not compressible */
|
if (cSize) { /* if == 0; block is not compressible */
|
||||||
@@ -634,8 +604,8 @@ static void ZDICT_countEStats(EStats_ress_t esr, ZSTD_parameters params,
|
|||||||
|
|
||||||
if (nbSeq >= 2) { /* rep offsets */
|
if (nbSeq >= 2) { /* rep offsets */
|
||||||
const seqDef* const seq = seqStorePtr->sequencesStart;
|
const seqDef* const seq = seqStorePtr->sequencesStart;
|
||||||
U32 offset1 = seq[0].offset - 3;
|
U32 offset1 = seq[0].offBase - ZSTD_REP_NUM;
|
||||||
U32 offset2 = seq[1].offset - 3;
|
U32 offset2 = seq[1].offBase - ZSTD_REP_NUM;
|
||||||
if (offset1 >= MAXREPOFFSET) offset1 = 0;
|
if (offset1 >= MAXREPOFFSET) offset1 = 0;
|
||||||
if (offset2 >= MAXREPOFFSET) offset2 = 0;
|
if (offset2 >= MAXREPOFFSET) offset2 = 0;
|
||||||
repOffsets[offset1] += 3;
|
repOffsets[offset1] += 3;
|
||||||
@@ -682,7 +652,7 @@ static void ZDICT_flatLit(unsigned* countLit)
|
|||||||
|
|
||||||
#define OFFCODE_MAX 30 /* only applicable to first block */
|
#define OFFCODE_MAX 30 /* only applicable to first block */
|
||||||
static size_t ZDICT_analyzeEntropy(void* dstBuffer, size_t maxDstSize,
|
static size_t ZDICT_analyzeEntropy(void* dstBuffer, size_t maxDstSize,
|
||||||
unsigned compressionLevel,
|
int compressionLevel,
|
||||||
const void* srcBuffer, const size_t* fileSizes, unsigned nbFiles,
|
const void* srcBuffer, const size_t* fileSizes, unsigned nbFiles,
|
||||||
const void* dictBuffer, size_t dictBufferSize,
|
const void* dictBuffer, size_t dictBufferSize,
|
||||||
unsigned notificationLevel)
|
unsigned notificationLevel)
|
||||||
@@ -706,6 +676,7 @@ static size_t ZDICT_analyzeEntropy(void* dstBuffer, size_t maxDstSize,
|
|||||||
size_t const totalSrcSize = ZDICT_totalSampleSize(fileSizes, nbFiles);
|
size_t const totalSrcSize = ZDICT_totalSampleSize(fileSizes, nbFiles);
|
||||||
size_t const averageSampleSize = totalSrcSize / (nbFiles + !nbFiles);
|
size_t const averageSampleSize = totalSrcSize / (nbFiles + !nbFiles);
|
||||||
BYTE* dstPtr = (BYTE*)dstBuffer;
|
BYTE* dstPtr = (BYTE*)dstBuffer;
|
||||||
|
U32 wksp[HUF_CTABLE_WORKSPACE_SIZE_U32];
|
||||||
|
|
||||||
/* init */
|
/* init */
|
||||||
DEBUGLOG(4, "ZDICT_analyzeEntropy");
|
DEBUGLOG(4, "ZDICT_analyzeEntropy");
|
||||||
@@ -717,7 +688,7 @@ static size_t ZDICT_analyzeEntropy(void* dstBuffer, size_t maxDstSize,
|
|||||||
memset(repOffset, 0, sizeof(repOffset));
|
memset(repOffset, 0, sizeof(repOffset));
|
||||||
repOffset[1] = repOffset[4] = repOffset[8] = 1;
|
repOffset[1] = repOffset[4] = repOffset[8] = 1;
|
||||||
memset(bestRepOffset, 0, sizeof(bestRepOffset));
|
memset(bestRepOffset, 0, sizeof(bestRepOffset));
|
||||||
if (compressionLevel==0) compressionLevel = g_compressionLevel_default;
|
if (compressionLevel==0) compressionLevel = ZSTD_CLEVEL_DEFAULT;
|
||||||
params = ZSTD_getParams(compressionLevel, averageSampleSize, dictBufferSize);
|
params = ZSTD_getParams(compressionLevel, averageSampleSize, dictBufferSize);
|
||||||
|
|
||||||
esr.dict = ZSTD_createCDict_advanced(dictBuffer, dictBufferSize, ZSTD_dlm_byRef, ZSTD_dct_rawContent, params.cParams, ZSTD_defaultCMem);
|
esr.dict = ZSTD_createCDict_advanced(dictBuffer, dictBufferSize, ZSTD_dlm_byRef, ZSTD_dct_rawContent, params.cParams, ZSTD_defaultCMem);
|
||||||
@@ -731,15 +702,22 @@ static size_t ZDICT_analyzeEntropy(void* dstBuffer, size_t maxDstSize,
|
|||||||
|
|
||||||
/* collect stats on all samples */
|
/* collect stats on all samples */
|
||||||
for (u=0; u<nbFiles; u++) {
|
for (u=0; u<nbFiles; u++) {
|
||||||
ZDICT_countEStats(esr, params,
|
ZDICT_countEStats(esr, ¶ms,
|
||||||
countLit, offcodeCount, matchLengthCount, litLengthCount, repOffset,
|
countLit, offcodeCount, matchLengthCount, litLengthCount, repOffset,
|
||||||
(const char*)srcBuffer + pos, fileSizes[u],
|
(const char*)srcBuffer + pos, fileSizes[u],
|
||||||
notificationLevel);
|
notificationLevel);
|
||||||
pos += fileSizes[u];
|
pos += fileSizes[u];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (notificationLevel >= 4) {
|
||||||
|
/* writeStats */
|
||||||
|
DISPLAYLEVEL(4, "Offset Code Frequencies : \n");
|
||||||
|
for (u=0; u<=offcodeMax; u++) {
|
||||||
|
DISPLAYLEVEL(4, "%2u :%7u \n", u, offcodeCount[u]);
|
||||||
|
} }
|
||||||
|
|
||||||
/* analyze, build stats, starting with literals */
|
/* analyze, build stats, starting with literals */
|
||||||
{ size_t maxNbBits = HUF_buildCTable (hufTable, countLit, 255, huffLog);
|
{ size_t maxNbBits = HUF_buildCTable_wksp(hufTable, countLit, 255, huffLog, wksp, sizeof(wksp));
|
||||||
if (HUF_isError(maxNbBits)) {
|
if (HUF_isError(maxNbBits)) {
|
||||||
eSize = maxNbBits;
|
eSize = maxNbBits;
|
||||||
DISPLAYLEVEL(1, " HUF_buildCTable error \n");
|
DISPLAYLEVEL(1, " HUF_buildCTable error \n");
|
||||||
@@ -748,7 +726,7 @@ static size_t ZDICT_analyzeEntropy(void* dstBuffer, size_t maxDstSize,
|
|||||||
if (maxNbBits==8) { /* not compressible : will fail on HUF_writeCTable() */
|
if (maxNbBits==8) { /* not compressible : will fail on HUF_writeCTable() */
|
||||||
DISPLAYLEVEL(2, "warning : pathological dataset : literals are not compressible : samples are noisy or too regular \n");
|
DISPLAYLEVEL(2, "warning : pathological dataset : literals are not compressible : samples are noisy or too regular \n");
|
||||||
ZDICT_flatLit(countLit); /* replace distribution by a fake "mostly flat but still compressible" distribution, that HUF_writeCTable() can encode */
|
ZDICT_flatLit(countLit); /* replace distribution by a fake "mostly flat but still compressible" distribution, that HUF_writeCTable() can encode */
|
||||||
maxNbBits = HUF_buildCTable (hufTable, countLit, 255, huffLog);
|
maxNbBits = HUF_buildCTable_wksp(hufTable, countLit, 255, huffLog, wksp, sizeof(wksp));
|
||||||
assert(maxNbBits==9);
|
assert(maxNbBits==9);
|
||||||
}
|
}
|
||||||
huffLog = (U32)maxNbBits;
|
huffLog = (U32)maxNbBits;
|
||||||
@@ -762,7 +740,7 @@ static size_t ZDICT_analyzeEntropy(void* dstBuffer, size_t maxDstSize,
|
|||||||
/* note : the result of this phase should be used to better appreciate the impact on statistics */
|
/* note : the result of this phase should be used to better appreciate the impact on statistics */
|
||||||
|
|
||||||
total=0; for (u=0; u<=offcodeMax; u++) total+=offcodeCount[u];
|
total=0; for (u=0; u<=offcodeMax; u++) total+=offcodeCount[u];
|
||||||
errorCode = FSE_normalizeCount(offcodeNCount, Offlog, offcodeCount, total, offcodeMax);
|
errorCode = FSE_normalizeCount(offcodeNCount, Offlog, offcodeCount, total, offcodeMax, /* useLowProbCount */ 1);
|
||||||
if (FSE_isError(errorCode)) {
|
if (FSE_isError(errorCode)) {
|
||||||
eSize = errorCode;
|
eSize = errorCode;
|
||||||
DISPLAYLEVEL(1, "FSE_normalizeCount error with offcodeCount \n");
|
DISPLAYLEVEL(1, "FSE_normalizeCount error with offcodeCount \n");
|
||||||
@@ -771,7 +749,7 @@ static size_t ZDICT_analyzeEntropy(void* dstBuffer, size_t maxDstSize,
|
|||||||
Offlog = (U32)errorCode;
|
Offlog = (U32)errorCode;
|
||||||
|
|
||||||
total=0; for (u=0; u<=MaxML; u++) total+=matchLengthCount[u];
|
total=0; for (u=0; u<=MaxML; u++) total+=matchLengthCount[u];
|
||||||
errorCode = FSE_normalizeCount(matchLengthNCount, mlLog, matchLengthCount, total, MaxML);
|
errorCode = FSE_normalizeCount(matchLengthNCount, mlLog, matchLengthCount, total, MaxML, /* useLowProbCount */ 1);
|
||||||
if (FSE_isError(errorCode)) {
|
if (FSE_isError(errorCode)) {
|
||||||
eSize = errorCode;
|
eSize = errorCode;
|
||||||
DISPLAYLEVEL(1, "FSE_normalizeCount error with matchLengthCount \n");
|
DISPLAYLEVEL(1, "FSE_normalizeCount error with matchLengthCount \n");
|
||||||
@@ -780,7 +758,7 @@ static size_t ZDICT_analyzeEntropy(void* dstBuffer, size_t maxDstSize,
|
|||||||
mlLog = (U32)errorCode;
|
mlLog = (U32)errorCode;
|
||||||
|
|
||||||
total=0; for (u=0; u<=MaxLL; u++) total+=litLengthCount[u];
|
total=0; for (u=0; u<=MaxLL; u++) total+=litLengthCount[u];
|
||||||
errorCode = FSE_normalizeCount(litLengthNCount, llLog, litLengthCount, total, MaxLL);
|
errorCode = FSE_normalizeCount(litLengthNCount, llLog, litLengthCount, total, MaxLL, /* useLowProbCount */ 1);
|
||||||
if (FSE_isError(errorCode)) {
|
if (FSE_isError(errorCode)) {
|
||||||
eSize = errorCode;
|
eSize = errorCode;
|
||||||
DISPLAYLEVEL(1, "FSE_normalizeCount error with litLengthCount \n");
|
DISPLAYLEVEL(1, "FSE_normalizeCount error with litLengthCount \n");
|
||||||
@@ -789,7 +767,7 @@ static size_t ZDICT_analyzeEntropy(void* dstBuffer, size_t maxDstSize,
|
|||||||
llLog = (U32)errorCode;
|
llLog = (U32)errorCode;
|
||||||
|
|
||||||
/* write result to buffer */
|
/* write result to buffer */
|
||||||
{ size_t const hhSize = HUF_writeCTable(dstPtr, maxDstSize, hufTable, 255, huffLog);
|
{ size_t const hhSize = HUF_writeCTable_wksp(dstPtr, maxDstSize, hufTable, 255, huffLog, wksp, sizeof(wksp));
|
||||||
if (HUF_isError(hhSize)) {
|
if (HUF_isError(hhSize)) {
|
||||||
eSize = hhSize;
|
eSize = hhSize;
|
||||||
DISPLAYLEVEL(1, "HUF_writeCTable error \n");
|
DISPLAYLEVEL(1, "HUF_writeCTable error \n");
|
||||||
@@ -844,7 +822,7 @@ static size_t ZDICT_analyzeEntropy(void* dstBuffer, size_t maxDstSize,
|
|||||||
MEM_writeLE32(dstPtr+8, bestRepOffset[2].offset);
|
MEM_writeLE32(dstPtr+8, bestRepOffset[2].offset);
|
||||||
#else
|
#else
|
||||||
/* at this stage, we don't use the result of "most common first offset",
|
/* at this stage, we don't use the result of "most common first offset",
|
||||||
as the impact of statistics is not properly evaluated */
|
* as the impact of statistics is not properly evaluated */
|
||||||
MEM_writeLE32(dstPtr+0, repStartValue[0]);
|
MEM_writeLE32(dstPtr+0, repStartValue[0]);
|
||||||
MEM_writeLE32(dstPtr+4, repStartValue[1]);
|
MEM_writeLE32(dstPtr+4, repStartValue[1]);
|
||||||
MEM_writeLE32(dstPtr+8, repStartValue[2]);
|
MEM_writeLE32(dstPtr+8, repStartValue[2]);
|
||||||
@@ -860,6 +838,17 @@ _cleanup:
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @returns the maximum repcode value
|
||||||
|
*/
|
||||||
|
static U32 ZDICT_maxRep(U32 const reps[ZSTD_REP_NUM])
|
||||||
|
{
|
||||||
|
U32 maxRep = reps[0];
|
||||||
|
int r;
|
||||||
|
for (r = 1; r < ZSTD_REP_NUM; ++r)
|
||||||
|
maxRep = MAX(maxRep, reps[r]);
|
||||||
|
return maxRep;
|
||||||
|
}
|
||||||
|
|
||||||
size_t ZDICT_finalizeDictionary(void* dictBuffer, size_t dictBufferCapacity,
|
size_t ZDICT_finalizeDictionary(void* dictBuffer, size_t dictBufferCapacity,
|
||||||
const void* customDictContent, size_t dictContentSize,
|
const void* customDictContent, size_t dictContentSize,
|
||||||
@@ -869,13 +858,15 @@ size_t ZDICT_finalizeDictionary(void* dictBuffer, size_t dictBufferCapacity,
|
|||||||
size_t hSize;
|
size_t hSize;
|
||||||
#define HBUFFSIZE 256 /* should prove large enough for all entropy headers */
|
#define HBUFFSIZE 256 /* should prove large enough for all entropy headers */
|
||||||
BYTE header[HBUFFSIZE];
|
BYTE header[HBUFFSIZE];
|
||||||
int const compressionLevel = (params.compressionLevel == 0) ? g_compressionLevel_default : params.compressionLevel;
|
int const compressionLevel = (params.compressionLevel == 0) ? ZSTD_CLEVEL_DEFAULT : params.compressionLevel;
|
||||||
U32 const notificationLevel = params.notificationLevel;
|
U32 const notificationLevel = params.notificationLevel;
|
||||||
|
/* The final dictionary content must be at least as large as the largest repcode */
|
||||||
|
size_t const minContentSize = (size_t)ZDICT_maxRep(repStartValue);
|
||||||
|
size_t paddingSize;
|
||||||
|
|
||||||
/* check conditions */
|
/* check conditions */
|
||||||
DEBUGLOG(4, "ZDICT_finalizeDictionary");
|
DEBUGLOG(4, "ZDICT_finalizeDictionary");
|
||||||
if (dictBufferCapacity < dictContentSize) return ERROR(dstSize_tooSmall);
|
if (dictBufferCapacity < dictContentSize) return ERROR(dstSize_tooSmall);
|
||||||
if (dictContentSize < ZDICT_CONTENTSIZE_MIN) return ERROR(srcSize_wrong);
|
|
||||||
if (dictBufferCapacity < ZDICT_DICTSIZE_MIN) return ERROR(dstSize_tooSmall);
|
if (dictBufferCapacity < ZDICT_DICTSIZE_MIN) return ERROR(dstSize_tooSmall);
|
||||||
|
|
||||||
/* dictionary header */
|
/* dictionary header */
|
||||||
@@ -899,12 +890,43 @@ size_t ZDICT_finalizeDictionary(void* dictBuffer, size_t dictBufferCapacity,
|
|||||||
hSize += eSize;
|
hSize += eSize;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* copy elements in final buffer ; note : src and dst buffer can overlap */
|
/* Shrink the content size if it doesn't fit in the buffer */
|
||||||
if (hSize + dictContentSize > dictBufferCapacity) dictContentSize = dictBufferCapacity - hSize;
|
if (hSize + dictContentSize > dictBufferCapacity) {
|
||||||
{ size_t const dictSize = hSize + dictContentSize;
|
dictContentSize = dictBufferCapacity - hSize;
|
||||||
char* dictEnd = (char*)dictBuffer + dictSize;
|
}
|
||||||
memmove(dictEnd - dictContentSize, customDictContent, dictContentSize);
|
|
||||||
memcpy(dictBuffer, header, hSize);
|
/* Pad the dictionary content with zeros if it is too small */
|
||||||
|
if (dictContentSize < minContentSize) {
|
||||||
|
RETURN_ERROR_IF(hSize + minContentSize > dictBufferCapacity, dstSize_tooSmall,
|
||||||
|
"dictBufferCapacity too small to fit max repcode");
|
||||||
|
paddingSize = minContentSize - dictContentSize;
|
||||||
|
} else {
|
||||||
|
paddingSize = 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
{
|
||||||
|
size_t const dictSize = hSize + paddingSize + dictContentSize;
|
||||||
|
|
||||||
|
/* The dictionary consists of the header, optional padding, and the content.
|
||||||
|
* The padding comes before the content because the "best" position in the
|
||||||
|
* dictionary is the last byte.
|
||||||
|
*/
|
||||||
|
BYTE* const outDictHeader = (BYTE*)dictBuffer;
|
||||||
|
BYTE* const outDictPadding = outDictHeader + hSize;
|
||||||
|
BYTE* const outDictContent = outDictPadding + paddingSize;
|
||||||
|
|
||||||
|
assert(dictSize <= dictBufferCapacity);
|
||||||
|
assert(outDictContent + dictContentSize == (BYTE*)dictBuffer + dictSize);
|
||||||
|
|
||||||
|
/* First copy the customDictContent into its final location.
|
||||||
|
* `customDictContent` and `dictBuffer` may overlap, so we must
|
||||||
|
* do this before any other writes into the output buffer.
|
||||||
|
* Then copy the header & padding into the output buffer.
|
||||||
|
*/
|
||||||
|
memmove(outDictContent, customDictContent, dictContentSize);
|
||||||
|
memcpy(outDictHeader, header, hSize);
|
||||||
|
memset(outDictPadding, 0, paddingSize);
|
||||||
|
|
||||||
return dictSize;
|
return dictSize;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -915,7 +937,7 @@ static size_t ZDICT_addEntropyTablesFromBuffer_advanced(
|
|||||||
const void* samplesBuffer, const size_t* samplesSizes, unsigned nbSamples,
|
const void* samplesBuffer, const size_t* samplesSizes, unsigned nbSamples,
|
||||||
ZDICT_params_t params)
|
ZDICT_params_t params)
|
||||||
{
|
{
|
||||||
int const compressionLevel = (params.compressionLevel == 0) ? g_compressionLevel_default : params.compressionLevel;
|
int const compressionLevel = (params.compressionLevel == 0) ? ZSTD_CLEVEL_DEFAULT : params.compressionLevel;
|
||||||
U32 const notificationLevel = params.notificationLevel;
|
U32 const notificationLevel = params.notificationLevel;
|
||||||
size_t hSize = 8;
|
size_t hSize = 8;
|
||||||
|
|
||||||
@@ -944,16 +966,11 @@ static size_t ZDICT_addEntropyTablesFromBuffer_advanced(
|
|||||||
return MIN(dictBufferCapacity, hSize+dictContentSize);
|
return MIN(dictBufferCapacity, hSize+dictContentSize);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Hidden declaration for dbio.c */
|
|
||||||
size_t ZDICT_trainFromBuffer_unsafe_legacy(
|
|
||||||
void* dictBuffer, size_t maxDictSize,
|
|
||||||
const void* samplesBuffer, const size_t* samplesSizes, unsigned nbSamples,
|
|
||||||
ZDICT_legacy_params_t params);
|
|
||||||
/*! ZDICT_trainFromBuffer_unsafe_legacy() :
|
/*! ZDICT_trainFromBuffer_unsafe_legacy() :
|
||||||
* Warning : `samplesBuffer` must be followed by noisy guard band.
|
* Warning : `samplesBuffer` must be followed by noisy guard band !!!
|
||||||
* @return : size of dictionary, or an error code which can be tested with ZDICT_isError()
|
* @return : size of dictionary, or an error code which can be tested with ZDICT_isError()
|
||||||
*/
|
*/
|
||||||
size_t ZDICT_trainFromBuffer_unsafe_legacy(
|
static size_t ZDICT_trainFromBuffer_unsafe_legacy(
|
||||||
void* dictBuffer, size_t maxDictSize,
|
void* dictBuffer, size_t maxDictSize,
|
||||||
const void* samplesBuffer, const size_t* samplesSizes, unsigned nbSamples,
|
const void* samplesBuffer, const size_t* samplesSizes, unsigned nbSamples,
|
||||||
ZDICT_legacy_params_t params)
|
ZDICT_legacy_params_t params)
|
||||||
@@ -1090,8 +1107,8 @@ size_t ZDICT_trainFromBuffer(void* dictBuffer, size_t dictBufferCapacity,
|
|||||||
memset(¶ms, 0, sizeof(params));
|
memset(¶ms, 0, sizeof(params));
|
||||||
params.d = 8;
|
params.d = 8;
|
||||||
params.steps = 4;
|
params.steps = 4;
|
||||||
/* Default to level 6 since no compression level information is available */
|
/* Use default level since no compression level information is available */
|
||||||
params.zParams.compressionLevel = 3;
|
params.zParams.compressionLevel = ZSTD_CLEVEL_DEFAULT;
|
||||||
#if defined(DEBUGLEVEL) && (DEBUGLEVEL>=1)
|
#if defined(DEBUGLEVEL) && (DEBUGLEVEL>=1)
|
||||||
params.zParams.notificationLevel = DEBUGLEVEL;
|
params.zParams.notificationLevel = DEBUGLEVEL;
|
||||||
#endif
|
#endif
|
||||||
@@ -1109,3 +1126,5 @@ size_t ZDICT_addEntropyTablesFromBuffer(void* dictBuffer, size_t dictContentSize
|
|||||||
samplesBuffer, samplesSizes, nbSamples,
|
samplesBuffer, samplesSizes, nbSamples,
|
||||||
params);
|
params);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#endif /* USE_EXTERNAL_ZSTD */
|
||||||
|
|||||||
311
vendor/github.com/DataDog/zstd/zdict.h
generated
vendored
311
vendor/github.com/DataDog/zstd/zdict.h
generated
vendored
@@ -1,5 +1,6 @@
|
|||||||
|
#ifndef USE_EXTERNAL_ZSTD
|
||||||
/*
|
/*
|
||||||
* Copyright (c) 2016-present, Yann Collet, Facebook, Inc.
|
* Copyright (c) Meta Platforms, Inc. and affiliates.
|
||||||
* All rights reserved.
|
* All rights reserved.
|
||||||
*
|
*
|
||||||
* This source code is licensed under both the BSD-style license (found in the
|
* This source code is licensed under both the BSD-style license (found in the
|
||||||
@@ -8,34 +9,184 @@
|
|||||||
* You may select, at your option, one of the above-listed licenses.
|
* You may select, at your option, one of the above-listed licenses.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#ifndef DICTBUILDER_H_001
|
|
||||||
#define DICTBUILDER_H_001
|
|
||||||
|
|
||||||
#if defined (__cplusplus)
|
#if defined (__cplusplus)
|
||||||
extern "C" {
|
extern "C" {
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
#ifndef ZSTD_ZDICT_H
|
||||||
|
#define ZSTD_ZDICT_H
|
||||||
|
|
||||||
/*====== Dependencies ======*/
|
/*====== Dependencies ======*/
|
||||||
#include <stddef.h> /* size_t */
|
#include <stddef.h> /* size_t */
|
||||||
|
|
||||||
|
|
||||||
/* ===== ZDICTLIB_API : control library symbols visibility ===== */
|
/* ===== ZDICTLIB_API : control library symbols visibility ===== */
|
||||||
#ifndef ZDICTLIB_VISIBILITY
|
#ifndef ZDICTLIB_VISIBLE
|
||||||
# if defined(__GNUC__) && (__GNUC__ >= 4)
|
/* Backwards compatibility with old macro name */
|
||||||
# define ZDICTLIB_VISIBILITY __attribute__ ((visibility ("default")))
|
# ifdef ZDICTLIB_VISIBILITY
|
||||||
|
# define ZDICTLIB_VISIBLE ZDICTLIB_VISIBILITY
|
||||||
|
# elif defined(__GNUC__) && (__GNUC__ >= 4) && !defined(__MINGW32__)
|
||||||
|
# define ZDICTLIB_VISIBLE __attribute__ ((visibility ("default")))
|
||||||
# else
|
# else
|
||||||
# define ZDICTLIB_VISIBILITY
|
# define ZDICTLIB_VISIBLE
|
||||||
# endif
|
# endif
|
||||||
#endif
|
#endif
|
||||||
#if defined(ZSTD_DLL_EXPORT) && (ZSTD_DLL_EXPORT==1)
|
|
||||||
# define ZDICTLIB_API __declspec(dllexport) ZDICTLIB_VISIBILITY
|
#ifndef ZDICTLIB_HIDDEN
|
||||||
#elif defined(ZSTD_DLL_IMPORT) && (ZSTD_DLL_IMPORT==1)
|
# if defined(__GNUC__) && (__GNUC__ >= 4) && !defined(__MINGW32__)
|
||||||
# define ZDICTLIB_API __declspec(dllimport) ZDICTLIB_VISIBILITY /* It isn't required but allows to generate better code, saving a function pointer load from the IAT and an indirect jump.*/
|
# define ZDICTLIB_HIDDEN __attribute__ ((visibility ("hidden")))
|
||||||
#else
|
# else
|
||||||
# define ZDICTLIB_API ZDICTLIB_VISIBILITY
|
# define ZDICTLIB_HIDDEN
|
||||||
|
# endif
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
#if defined(ZSTD_DLL_EXPORT) && (ZSTD_DLL_EXPORT==1)
|
||||||
|
# define ZDICTLIB_API __declspec(dllexport) ZDICTLIB_VISIBLE
|
||||||
|
#elif defined(ZSTD_DLL_IMPORT) && (ZSTD_DLL_IMPORT==1)
|
||||||
|
# define ZDICTLIB_API __declspec(dllimport) ZDICTLIB_VISIBLE /* It isn't required but allows to generate better code, saving a function pointer load from the IAT and an indirect jump.*/
|
||||||
|
#else
|
||||||
|
# define ZDICTLIB_API ZDICTLIB_VISIBLE
|
||||||
|
#endif
|
||||||
|
|
||||||
|
/*******************************************************************************
|
||||||
|
* Zstd dictionary builder
|
||||||
|
*
|
||||||
|
* FAQ
|
||||||
|
* ===
|
||||||
|
* Why should I use a dictionary?
|
||||||
|
* ------------------------------
|
||||||
|
*
|
||||||
|
* Zstd can use dictionaries to improve compression ratio of small data.
|
||||||
|
* Traditionally small files don't compress well because there is very little
|
||||||
|
* repetition in a single sample, since it is small. But, if you are compressing
|
||||||
|
* many similar files, like a bunch of JSON records that share the same
|
||||||
|
* structure, you can train a dictionary on ahead of time on some samples of
|
||||||
|
* these files. Then, zstd can use the dictionary to find repetitions that are
|
||||||
|
* present across samples. This can vastly improve compression ratio.
|
||||||
|
*
|
||||||
|
* When is a dictionary useful?
|
||||||
|
* ----------------------------
|
||||||
|
*
|
||||||
|
* Dictionaries are useful when compressing many small files that are similar.
|
||||||
|
* The larger a file is, the less benefit a dictionary will have. Generally,
|
||||||
|
* we don't expect dictionary compression to be effective past 100KB. And the
|
||||||
|
* smaller a file is, the more we would expect the dictionary to help.
|
||||||
|
*
|
||||||
|
* How do I use a dictionary?
|
||||||
|
* --------------------------
|
||||||
|
*
|
||||||
|
* Simply pass the dictionary to the zstd compressor with
|
||||||
|
* `ZSTD_CCtx_loadDictionary()`. The same dictionary must then be passed to
|
||||||
|
* the decompressor, using `ZSTD_DCtx_loadDictionary()`. There are other
|
||||||
|
* more advanced functions that allow selecting some options, see zstd.h for
|
||||||
|
* complete documentation.
|
||||||
|
*
|
||||||
|
* What is a zstd dictionary?
|
||||||
|
* --------------------------
|
||||||
|
*
|
||||||
|
* A zstd dictionary has two pieces: Its header, and its content. The header
|
||||||
|
* contains a magic number, the dictionary ID, and entropy tables. These
|
||||||
|
* entropy tables allow zstd to save on header costs in the compressed file,
|
||||||
|
* which really matters for small data. The content is just bytes, which are
|
||||||
|
* repeated content that is common across many samples.
|
||||||
|
*
|
||||||
|
* What is a raw content dictionary?
|
||||||
|
* ---------------------------------
|
||||||
|
*
|
||||||
|
* A raw content dictionary is just bytes. It doesn't have a zstd dictionary
|
||||||
|
* header, a dictionary ID, or entropy tables. Any buffer is a valid raw
|
||||||
|
* content dictionary.
|
||||||
|
*
|
||||||
|
* How do I train a dictionary?
|
||||||
|
* ----------------------------
|
||||||
|
*
|
||||||
|
* Gather samples from your use case. These samples should be similar to each
|
||||||
|
* other. If you have several use cases, you could try to train one dictionary
|
||||||
|
* per use case.
|
||||||
|
*
|
||||||
|
* Pass those samples to `ZDICT_trainFromBuffer()` and that will train your
|
||||||
|
* dictionary. There are a few advanced versions of this function, but this
|
||||||
|
* is a great starting point. If you want to further tune your dictionary
|
||||||
|
* you could try `ZDICT_optimizeTrainFromBuffer_cover()`. If that is too slow
|
||||||
|
* you can try `ZDICT_optimizeTrainFromBuffer_fastCover()`.
|
||||||
|
*
|
||||||
|
* If the dictionary training function fails, that is likely because you
|
||||||
|
* either passed too few samples, or a dictionary would not be effective
|
||||||
|
* for your data. Look at the messages that the dictionary trainer printed,
|
||||||
|
* if it doesn't say too few samples, then a dictionary would not be effective.
|
||||||
|
*
|
||||||
|
* How large should my dictionary be?
|
||||||
|
* ----------------------------------
|
||||||
|
*
|
||||||
|
* A reasonable dictionary size, the `dictBufferCapacity`, is about 100KB.
|
||||||
|
* The zstd CLI defaults to a 110KB dictionary. You likely don't need a
|
||||||
|
* dictionary larger than that. But, most use cases can get away with a
|
||||||
|
* smaller dictionary. The advanced dictionary builders can automatically
|
||||||
|
* shrink the dictionary for you, and select the smallest size that doesn't
|
||||||
|
* hurt compression ratio too much. See the `shrinkDict` parameter.
|
||||||
|
* A smaller dictionary can save memory, and potentially speed up
|
||||||
|
* compression.
|
||||||
|
*
|
||||||
|
* How many samples should I provide to the dictionary builder?
|
||||||
|
* ------------------------------------------------------------
|
||||||
|
*
|
||||||
|
* We generally recommend passing ~100x the size of the dictionary
|
||||||
|
* in samples. A few thousand should suffice. Having too few samples
|
||||||
|
* can hurt the dictionaries effectiveness. Having more samples will
|
||||||
|
* only improve the dictionaries effectiveness. But having too many
|
||||||
|
* samples can slow down the dictionary builder.
|
||||||
|
*
|
||||||
|
* How do I determine if a dictionary will be effective?
|
||||||
|
* -----------------------------------------------------
|
||||||
|
*
|
||||||
|
* Simply train a dictionary and try it out. You can use zstd's built in
|
||||||
|
* benchmarking tool to test the dictionary effectiveness.
|
||||||
|
*
|
||||||
|
* # Benchmark levels 1-3 without a dictionary
|
||||||
|
* zstd -b1e3 -r /path/to/my/files
|
||||||
|
* # Benchmark levels 1-3 with a dictionary
|
||||||
|
* zstd -b1e3 -r /path/to/my/files -D /path/to/my/dictionary
|
||||||
|
*
|
||||||
|
* When should I retrain a dictionary?
|
||||||
|
* -----------------------------------
|
||||||
|
*
|
||||||
|
* You should retrain a dictionary when its effectiveness drops. Dictionary
|
||||||
|
* effectiveness drops as the data you are compressing changes. Generally, we do
|
||||||
|
* expect dictionaries to "decay" over time, as your data changes, but the rate
|
||||||
|
* at which they decay depends on your use case. Internally, we regularly
|
||||||
|
* retrain dictionaries, and if the new dictionary performs significantly
|
||||||
|
* better than the old dictionary, we will ship the new dictionary.
|
||||||
|
*
|
||||||
|
* I have a raw content dictionary, how do I turn it into a zstd dictionary?
|
||||||
|
* -------------------------------------------------------------------------
|
||||||
|
*
|
||||||
|
* If you have a raw content dictionary, e.g. by manually constructing it, or
|
||||||
|
* using a third-party dictionary builder, you can turn it into a zstd
|
||||||
|
* dictionary by using `ZDICT_finalizeDictionary()`. You'll also have to
|
||||||
|
* provide some samples of the data. It will add the zstd header to the
|
||||||
|
* raw content, which contains a dictionary ID and entropy tables, which
|
||||||
|
* will improve compression ratio, and allow zstd to write the dictionary ID
|
||||||
|
* into the frame, if you so choose.
|
||||||
|
*
|
||||||
|
* Do I have to use zstd's dictionary builder?
|
||||||
|
* -------------------------------------------
|
||||||
|
*
|
||||||
|
* No! You can construct dictionary content however you please, it is just
|
||||||
|
* bytes. It will always be valid as a raw content dictionary. If you want
|
||||||
|
* a zstd dictionary, which can improve compression ratio, use
|
||||||
|
* `ZDICT_finalizeDictionary()`.
|
||||||
|
*
|
||||||
|
* What is the attack surface of a zstd dictionary?
|
||||||
|
* ------------------------------------------------
|
||||||
|
*
|
||||||
|
* Zstd is heavily fuzz tested, including loading fuzzed dictionaries, so
|
||||||
|
* zstd should never crash, or access out-of-bounds memory no matter what
|
||||||
|
* the dictionary is. However, if an attacker can control the dictionary
|
||||||
|
* during decompression, they can cause zstd to generate arbitrary bytes,
|
||||||
|
* just like if they controlled the compressed data.
|
||||||
|
*
|
||||||
|
******************************************************************************/
|
||||||
|
|
||||||
|
|
||||||
/*! ZDICT_trainFromBuffer():
|
/*! ZDICT_trainFromBuffer():
|
||||||
* Train a dictionary from an array of samples.
|
* Train a dictionary from an array of samples.
|
||||||
@@ -61,15 +212,81 @@ ZDICTLIB_API size_t ZDICT_trainFromBuffer(void* dictBuffer, size_t dictBufferCap
|
|||||||
const void* samplesBuffer,
|
const void* samplesBuffer,
|
||||||
const size_t* samplesSizes, unsigned nbSamples);
|
const size_t* samplesSizes, unsigned nbSamples);
|
||||||
|
|
||||||
|
typedef struct {
|
||||||
|
int compressionLevel; /**< optimize for a specific zstd compression level; 0 means default */
|
||||||
|
unsigned notificationLevel; /**< Write log to stderr; 0 = none (default); 1 = errors; 2 = progression; 3 = details; 4 = debug; */
|
||||||
|
unsigned dictID; /**< force dictID value; 0 means auto mode (32-bits random value)
|
||||||
|
* NOTE: The zstd format reserves some dictionary IDs for future use.
|
||||||
|
* You may use them in private settings, but be warned that they
|
||||||
|
* may be used by zstd in a public dictionary registry in the future.
|
||||||
|
* These dictionary IDs are:
|
||||||
|
* - low range : <= 32767
|
||||||
|
* - high range : >= (2^31)
|
||||||
|
*/
|
||||||
|
} ZDICT_params_t;
|
||||||
|
|
||||||
|
/*! ZDICT_finalizeDictionary():
|
||||||
|
* Given a custom content as a basis for dictionary, and a set of samples,
|
||||||
|
* finalize dictionary by adding headers and statistics according to the zstd
|
||||||
|
* dictionary format.
|
||||||
|
*
|
||||||
|
* Samples must be stored concatenated in a flat buffer `samplesBuffer`,
|
||||||
|
* supplied with an array of sizes `samplesSizes`, providing the size of each
|
||||||
|
* sample in order. The samples are used to construct the statistics, so they
|
||||||
|
* should be representative of what you will compress with this dictionary.
|
||||||
|
*
|
||||||
|
* The compression level can be set in `parameters`. You should pass the
|
||||||
|
* compression level you expect to use in production. The statistics for each
|
||||||
|
* compression level differ, so tuning the dictionary for the compression level
|
||||||
|
* can help quite a bit.
|
||||||
|
*
|
||||||
|
* You can set an explicit dictionary ID in `parameters`, or allow us to pick
|
||||||
|
* a random dictionary ID for you, but we can't guarantee no collisions.
|
||||||
|
*
|
||||||
|
* The dstDictBuffer and the dictContent may overlap, and the content will be
|
||||||
|
* appended to the end of the header. If the header + the content doesn't fit in
|
||||||
|
* maxDictSize the beginning of the content is truncated to make room, since it
|
||||||
|
* is presumed that the most profitable content is at the end of the dictionary,
|
||||||
|
* since that is the cheapest to reference.
|
||||||
|
*
|
||||||
|
* `maxDictSize` must be >= max(dictContentSize, ZSTD_DICTSIZE_MIN).
|
||||||
|
*
|
||||||
|
* @return: size of dictionary stored into `dstDictBuffer` (<= `maxDictSize`),
|
||||||
|
* or an error code, which can be tested by ZDICT_isError().
|
||||||
|
* Note: ZDICT_finalizeDictionary() will push notifications into stderr if
|
||||||
|
* instructed to, using notificationLevel>0.
|
||||||
|
* NOTE: This function currently may fail in several edge cases including:
|
||||||
|
* * Not enough samples
|
||||||
|
* * Samples are uncompressible
|
||||||
|
* * Samples are all exactly the same
|
||||||
|
*/
|
||||||
|
ZDICTLIB_API size_t ZDICT_finalizeDictionary(void* dstDictBuffer, size_t maxDictSize,
|
||||||
|
const void* dictContent, size_t dictContentSize,
|
||||||
|
const void* samplesBuffer, const size_t* samplesSizes, unsigned nbSamples,
|
||||||
|
ZDICT_params_t parameters);
|
||||||
|
|
||||||
|
|
||||||
/*====== Helper functions ======*/
|
/*====== Helper functions ======*/
|
||||||
ZDICTLIB_API unsigned ZDICT_getDictID(const void* dictBuffer, size_t dictSize); /**< extracts dictID; @return zero if error (not a valid dictionary) */
|
ZDICTLIB_API unsigned ZDICT_getDictID(const void* dictBuffer, size_t dictSize); /**< extracts dictID; @return zero if error (not a valid dictionary) */
|
||||||
|
ZDICTLIB_API size_t ZDICT_getDictHeaderSize(const void* dictBuffer, size_t dictSize); /* returns dict header size; returns a ZSTD error code on failure */
|
||||||
ZDICTLIB_API unsigned ZDICT_isError(size_t errorCode);
|
ZDICTLIB_API unsigned ZDICT_isError(size_t errorCode);
|
||||||
ZDICTLIB_API const char* ZDICT_getErrorName(size_t errorCode);
|
ZDICTLIB_API const char* ZDICT_getErrorName(size_t errorCode);
|
||||||
|
|
||||||
|
#endif /* ZSTD_ZDICT_H */
|
||||||
|
|
||||||
|
#if defined(ZDICT_STATIC_LINKING_ONLY) && !defined(ZSTD_ZDICT_H_STATIC)
|
||||||
|
#define ZSTD_ZDICT_H_STATIC
|
||||||
|
|
||||||
#ifdef ZDICT_STATIC_LINKING_ONLY
|
/* This can be overridden externally to hide static symbols. */
|
||||||
|
#ifndef ZDICTLIB_STATIC_API
|
||||||
|
# if defined(ZSTD_DLL_EXPORT) && (ZSTD_DLL_EXPORT==1)
|
||||||
|
# define ZDICTLIB_STATIC_API __declspec(dllexport) ZDICTLIB_VISIBLE
|
||||||
|
# elif defined(ZSTD_DLL_IMPORT) && (ZSTD_DLL_IMPORT==1)
|
||||||
|
# define ZDICTLIB_STATIC_API __declspec(dllimport) ZDICTLIB_VISIBLE
|
||||||
|
# else
|
||||||
|
# define ZDICTLIB_STATIC_API ZDICTLIB_VISIBLE
|
||||||
|
# endif
|
||||||
|
#endif
|
||||||
|
|
||||||
/* ====================================================================================
|
/* ====================================================================================
|
||||||
* The definitions in this section are considered experimental.
|
* The definitions in this section are considered experimental.
|
||||||
@@ -78,11 +295,9 @@ ZDICTLIB_API const char* ZDICT_getErrorName(size_t errorCode);
|
|||||||
* Use them only in association with static linking.
|
* Use them only in association with static linking.
|
||||||
* ==================================================================================== */
|
* ==================================================================================== */
|
||||||
|
|
||||||
typedef struct {
|
#define ZDICT_DICTSIZE_MIN 256
|
||||||
int compressionLevel; /* optimize for a specific zstd compression level; 0 means default */
|
/* Deprecated: Remove in v1.6.0 */
|
||||||
unsigned notificationLevel; /* Write log to stderr; 0 = none (default); 1 = errors; 2 = progression; 3 = details; 4 = debug; */
|
#define ZDICT_CONTENTSIZE_MIN 128
|
||||||
unsigned dictID; /* force dictID value; 0 means auto mode (32-bits random value) */
|
|
||||||
} ZDICT_params_t;
|
|
||||||
|
|
||||||
/*! ZDICT_cover_params_t:
|
/*! ZDICT_cover_params_t:
|
||||||
* k and d are the only required parameters.
|
* k and d are the only required parameters.
|
||||||
@@ -127,7 +342,7 @@ typedef struct {
|
|||||||
* In general, it's recommended to provide a few thousands samples, though this can vary a lot.
|
* In general, it's recommended to provide a few thousands samples, though this can vary a lot.
|
||||||
* It's recommended that total size of all samples be about ~x100 times the target size of dictionary.
|
* It's recommended that total size of all samples be about ~x100 times the target size of dictionary.
|
||||||
*/
|
*/
|
||||||
ZDICTLIB_API size_t ZDICT_trainFromBuffer_cover(
|
ZDICTLIB_STATIC_API size_t ZDICT_trainFromBuffer_cover(
|
||||||
void *dictBuffer, size_t dictBufferCapacity,
|
void *dictBuffer, size_t dictBufferCapacity,
|
||||||
const void *samplesBuffer, const size_t *samplesSizes, unsigned nbSamples,
|
const void *samplesBuffer, const size_t *samplesSizes, unsigned nbSamples,
|
||||||
ZDICT_cover_params_t parameters);
|
ZDICT_cover_params_t parameters);
|
||||||
@@ -149,7 +364,7 @@ ZDICTLIB_API size_t ZDICT_trainFromBuffer_cover(
|
|||||||
* See ZDICT_trainFromBuffer() for details on failure modes.
|
* See ZDICT_trainFromBuffer() for details on failure modes.
|
||||||
* Note: ZDICT_optimizeTrainFromBuffer_cover() requires about 8 bytes of memory for each input byte and additionally another 5 bytes of memory for each byte of memory for each thread.
|
* Note: ZDICT_optimizeTrainFromBuffer_cover() requires about 8 bytes of memory for each input byte and additionally another 5 bytes of memory for each byte of memory for each thread.
|
||||||
*/
|
*/
|
||||||
ZDICTLIB_API size_t ZDICT_optimizeTrainFromBuffer_cover(
|
ZDICTLIB_STATIC_API size_t ZDICT_optimizeTrainFromBuffer_cover(
|
||||||
void* dictBuffer, size_t dictBufferCapacity,
|
void* dictBuffer, size_t dictBufferCapacity,
|
||||||
const void* samplesBuffer, const size_t* samplesSizes, unsigned nbSamples,
|
const void* samplesBuffer, const size_t* samplesSizes, unsigned nbSamples,
|
||||||
ZDICT_cover_params_t* parameters);
|
ZDICT_cover_params_t* parameters);
|
||||||
@@ -170,7 +385,7 @@ ZDICTLIB_API size_t ZDICT_optimizeTrainFromBuffer_cover(
|
|||||||
* In general, it's recommended to provide a few thousands samples, though this can vary a lot.
|
* In general, it's recommended to provide a few thousands samples, though this can vary a lot.
|
||||||
* It's recommended that total size of all samples be about ~x100 times the target size of dictionary.
|
* It's recommended that total size of all samples be about ~x100 times the target size of dictionary.
|
||||||
*/
|
*/
|
||||||
ZDICTLIB_API size_t ZDICT_trainFromBuffer_fastCover(void *dictBuffer,
|
ZDICTLIB_STATIC_API size_t ZDICT_trainFromBuffer_fastCover(void *dictBuffer,
|
||||||
size_t dictBufferCapacity, const void *samplesBuffer,
|
size_t dictBufferCapacity, const void *samplesBuffer,
|
||||||
const size_t *samplesSizes, unsigned nbSamples,
|
const size_t *samplesSizes, unsigned nbSamples,
|
||||||
ZDICT_fastCover_params_t parameters);
|
ZDICT_fastCover_params_t parameters);
|
||||||
@@ -193,33 +408,11 @@ ZDICTLIB_API size_t ZDICT_trainFromBuffer_fastCover(void *dictBuffer,
|
|||||||
* See ZDICT_trainFromBuffer() for details on failure modes.
|
* See ZDICT_trainFromBuffer() for details on failure modes.
|
||||||
* Note: ZDICT_optimizeTrainFromBuffer_fastCover() requires about 6 * 2^f bytes of memory for each thread.
|
* Note: ZDICT_optimizeTrainFromBuffer_fastCover() requires about 6 * 2^f bytes of memory for each thread.
|
||||||
*/
|
*/
|
||||||
ZDICTLIB_API size_t ZDICT_optimizeTrainFromBuffer_fastCover(void* dictBuffer,
|
ZDICTLIB_STATIC_API size_t ZDICT_optimizeTrainFromBuffer_fastCover(void* dictBuffer,
|
||||||
size_t dictBufferCapacity, const void* samplesBuffer,
|
size_t dictBufferCapacity, const void* samplesBuffer,
|
||||||
const size_t* samplesSizes, unsigned nbSamples,
|
const size_t* samplesSizes, unsigned nbSamples,
|
||||||
ZDICT_fastCover_params_t* parameters);
|
ZDICT_fastCover_params_t* parameters);
|
||||||
|
|
||||||
/*! ZDICT_finalizeDictionary():
|
|
||||||
* Given a custom content as a basis for dictionary, and a set of samples,
|
|
||||||
* finalize dictionary by adding headers and statistics.
|
|
||||||
*
|
|
||||||
* Samples must be stored concatenated in a flat buffer `samplesBuffer`,
|
|
||||||
* supplied with an array of sizes `samplesSizes`, providing the size of each sample in order.
|
|
||||||
*
|
|
||||||
* dictContentSize must be >= ZDICT_CONTENTSIZE_MIN bytes.
|
|
||||||
* maxDictSize must be >= dictContentSize, and must be >= ZDICT_DICTSIZE_MIN bytes.
|
|
||||||
*
|
|
||||||
* @return: size of dictionary stored into `dictBuffer` (<= `dictBufferCapacity`),
|
|
||||||
* or an error code, which can be tested by ZDICT_isError().
|
|
||||||
* Note: ZDICT_finalizeDictionary() will push notifications into stderr if instructed to, using notificationLevel>0.
|
|
||||||
* Note 2: dictBuffer and dictContent can overlap
|
|
||||||
*/
|
|
||||||
#define ZDICT_CONTENTSIZE_MIN 128
|
|
||||||
#define ZDICT_DICTSIZE_MIN 256
|
|
||||||
ZDICTLIB_API size_t ZDICT_finalizeDictionary(void* dictBuffer, size_t dictBufferCapacity,
|
|
||||||
const void* dictContent, size_t dictContentSize,
|
|
||||||
const void* samplesBuffer, const size_t* samplesSizes, unsigned nbSamples,
|
|
||||||
ZDICT_params_t parameters);
|
|
||||||
|
|
||||||
typedef struct {
|
typedef struct {
|
||||||
unsigned selectivityLevel; /* 0 means default; larger => select more => larger dictionary */
|
unsigned selectivityLevel; /* 0 means default; larger => select more => larger dictionary */
|
||||||
ZDICT_params_t zParams;
|
ZDICT_params_t zParams;
|
||||||
@@ -240,43 +433,45 @@ typedef struct {
|
|||||||
* It's recommended that total size of all samples be about ~x100 times the target size of dictionary.
|
* It's recommended that total size of all samples be about ~x100 times the target size of dictionary.
|
||||||
* Note: ZDICT_trainFromBuffer_legacy() will send notifications into stderr if instructed to, using notificationLevel>0.
|
* Note: ZDICT_trainFromBuffer_legacy() will send notifications into stderr if instructed to, using notificationLevel>0.
|
||||||
*/
|
*/
|
||||||
ZDICTLIB_API size_t ZDICT_trainFromBuffer_legacy(
|
ZDICTLIB_STATIC_API size_t ZDICT_trainFromBuffer_legacy(
|
||||||
void *dictBuffer, size_t dictBufferCapacity,
|
void* dictBuffer, size_t dictBufferCapacity,
|
||||||
const void *samplesBuffer, const size_t *samplesSizes, unsigned nbSamples,
|
const void* samplesBuffer, const size_t* samplesSizes, unsigned nbSamples,
|
||||||
ZDICT_legacy_params_t parameters);
|
ZDICT_legacy_params_t parameters);
|
||||||
|
|
||||||
|
|
||||||
/* Deprecation warnings */
|
/* Deprecation warnings */
|
||||||
/* It is generally possible to disable deprecation warnings from compiler,
|
/* It is generally possible to disable deprecation warnings from compiler,
|
||||||
for example with -Wno-deprecated-declarations for gcc
|
for example with -Wno-deprecated-declarations for gcc
|
||||||
or _CRT_SECURE_NO_WARNINGS in Visual.
|
or _CRT_SECURE_NO_WARNINGS in Visual.
|
||||||
Otherwise, it's also possible to manually define ZDICT_DISABLE_DEPRECATE_WARNINGS */
|
Otherwise, it's also possible to manually define ZDICT_DISABLE_DEPRECATE_WARNINGS */
|
||||||
#ifdef ZDICT_DISABLE_DEPRECATE_WARNINGS
|
#ifdef ZDICT_DISABLE_DEPRECATE_WARNINGS
|
||||||
# define ZDICT_DEPRECATED(message) ZDICTLIB_API /* disable deprecation warnings */
|
# define ZDICT_DEPRECATED(message) /* disable deprecation warnings */
|
||||||
#else
|
#else
|
||||||
# define ZDICT_GCC_VERSION (__GNUC__ * 100 + __GNUC_MINOR__)
|
# define ZDICT_GCC_VERSION (__GNUC__ * 100 + __GNUC_MINOR__)
|
||||||
# if defined (__cplusplus) && (__cplusplus >= 201402) /* C++14 or greater */
|
# if defined (__cplusplus) && (__cplusplus >= 201402) /* C++14 or greater */
|
||||||
# define ZDICT_DEPRECATED(message) [[deprecated(message)]] ZDICTLIB_API
|
# define ZDICT_DEPRECATED(message) [[deprecated(message)]]
|
||||||
# elif (ZDICT_GCC_VERSION >= 405) || defined(__clang__)
|
# elif defined(__clang__) || (ZDICT_GCC_VERSION >= 405)
|
||||||
# define ZDICT_DEPRECATED(message) ZDICTLIB_API __attribute__((deprecated(message)))
|
# define ZDICT_DEPRECATED(message) __attribute__((deprecated(message)))
|
||||||
# elif (ZDICT_GCC_VERSION >= 301)
|
# elif (ZDICT_GCC_VERSION >= 301)
|
||||||
# define ZDICT_DEPRECATED(message) ZDICTLIB_API __attribute__((deprecated))
|
# define ZDICT_DEPRECATED(message) __attribute__((deprecated))
|
||||||
# elif defined(_MSC_VER)
|
# elif defined(_MSC_VER)
|
||||||
# define ZDICT_DEPRECATED(message) ZDICTLIB_API __declspec(deprecated(message))
|
# define ZDICT_DEPRECATED(message) __declspec(deprecated(message))
|
||||||
# else
|
# else
|
||||||
# pragma message("WARNING: You need to implement ZDICT_DEPRECATED for this compiler")
|
# pragma message("WARNING: You need to implement ZDICT_DEPRECATED for this compiler")
|
||||||
# define ZDICT_DEPRECATED(message) ZDICTLIB_API
|
# define ZDICT_DEPRECATED(message)
|
||||||
# endif
|
# endif
|
||||||
#endif /* ZDICT_DISABLE_DEPRECATE_WARNINGS */
|
#endif /* ZDICT_DISABLE_DEPRECATE_WARNINGS */
|
||||||
|
|
||||||
ZDICT_DEPRECATED("use ZDICT_finalizeDictionary() instead")
|
ZDICT_DEPRECATED("use ZDICT_finalizeDictionary() instead")
|
||||||
|
ZDICTLIB_STATIC_API
|
||||||
size_t ZDICT_addEntropyTablesFromBuffer(void* dictBuffer, size_t dictContentSize, size_t dictBufferCapacity,
|
size_t ZDICT_addEntropyTablesFromBuffer(void* dictBuffer, size_t dictContentSize, size_t dictBufferCapacity,
|
||||||
const void* samplesBuffer, const size_t* samplesSizes, unsigned nbSamples);
|
const void* samplesBuffer, const size_t* samplesSizes, unsigned nbSamples);
|
||||||
|
|
||||||
|
|
||||||
#endif /* ZDICT_STATIC_LINKING_ONLY */
|
#endif /* ZSTD_ZDICT_H_STATIC */
|
||||||
|
|
||||||
#if defined (__cplusplus)
|
#if defined (__cplusplus)
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#endif /* DICTBUILDER_H_001 */
|
#endif /* USE_EXTERNAL_ZSTD */
|
||||||
|
|||||||
130
vendor/github.com/DataDog/zstd/zstd.go
generated
vendored
130
vendor/github.com/DataDog/zstd/zstd.go
generated
vendored
@@ -1,29 +1,18 @@
|
|||||||
package zstd
|
package zstd
|
||||||
|
|
||||||
/*
|
/*
|
||||||
#define ZSTD_STATIC_LINKING_ONLY
|
// support decoding of "legacy" zstd payloads from versions [0.4, 0.8], matching the
|
||||||
|
// default configuration of the zstd command line tool:
|
||||||
|
// https://github.com/facebook/zstd/blob/dev/programs/README.md
|
||||||
|
#cgo CFLAGS: -DZSTD_LEGACY_SUPPORT=4 -DZSTD_MULTITHREAD=1
|
||||||
|
|
||||||
#include "zstd.h"
|
#include "zstd.h"
|
||||||
#include "stdint.h" // for uintptr_t
|
|
||||||
|
|
||||||
// The following *_wrapper function are used for removing superflouos
|
|
||||||
// memory allocations when calling the wrapped functions from Go code.
|
|
||||||
// See https://github.com/golang/go/issues/24450 for details.
|
|
||||||
|
|
||||||
static size_t ZSTD_compress_wrapper(uintptr_t dst, size_t maxDstSize, const uintptr_t src, size_t srcSize, int compressionLevel) {
|
|
||||||
return ZSTD_compress((void*)dst, maxDstSize, (const void*)src, srcSize, compressionLevel);
|
|
||||||
}
|
|
||||||
|
|
||||||
static size_t ZSTD_decompress_wrapper(uintptr_t dst, size_t maxDstSize, uintptr_t src, size_t srcSize) {
|
|
||||||
return ZSTD_decompress((void*)dst, maxDstSize, (const void *)src, srcSize);
|
|
||||||
}
|
|
||||||
|
|
||||||
*/
|
*/
|
||||||
import "C"
|
import "C"
|
||||||
import (
|
import (
|
||||||
"bytes"
|
"bytes"
|
||||||
"errors"
|
"errors"
|
||||||
"io/ioutil"
|
"io/ioutil"
|
||||||
"runtime"
|
|
||||||
"unsafe"
|
"unsafe"
|
||||||
)
|
)
|
||||||
|
|
||||||
@@ -39,6 +28,17 @@ var (
|
|||||||
ErrEmptySlice = errors.New("Bytes slice is empty")
|
ErrEmptySlice = errors.New("Bytes slice is empty")
|
||||||
)
|
)
|
||||||
|
|
||||||
|
const (
|
||||||
|
// decompressSizeBufferLimit is the limit we set on creating a decompression buffer for the Decompress API
|
||||||
|
// This is made to prevent DOS from maliciously-created payloads (aka zipbomb).
|
||||||
|
// For large payloads with a compression ratio > 10, you can do your own allocation and pass it to the method:
|
||||||
|
// dst := make([]byte, 1GB)
|
||||||
|
// decompressed, err := zstd.Decompress(dst, src)
|
||||||
|
decompressSizeBufferLimit = 1000 * 1000
|
||||||
|
|
||||||
|
zstdFrameHeaderSizeMin = 2 // From zstd.h. Since it's experimental API, hardcoding it
|
||||||
|
)
|
||||||
|
|
||||||
// CompressBound returns the worst case size needed for a destination buffer,
|
// CompressBound returns the worst case size needed for a destination buffer,
|
||||||
// which can be used to preallocate a destination buffer or select a previously
|
// which can be used to preallocate a destination buffer or select a previously
|
||||||
// allocated buffer from a pool.
|
// allocated buffer from a pool.
|
||||||
@@ -57,6 +57,33 @@ func cCompressBound(srcSize int) int {
|
|||||||
return int(C.ZSTD_compressBound(C.size_t(srcSize)))
|
return int(C.ZSTD_compressBound(C.size_t(srcSize)))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// decompressSizeHint tries to give a hint on how much of the output buffer size we should have
|
||||||
|
// based on zstd frame descriptors. To prevent DOS from maliciously-created payloads, limit the size
|
||||||
|
func decompressSizeHint(src []byte) int {
|
||||||
|
// 1 MB or 10x input size
|
||||||
|
upperBound := 10 * len(src)
|
||||||
|
if upperBound < decompressSizeBufferLimit {
|
||||||
|
upperBound = decompressSizeBufferLimit
|
||||||
|
}
|
||||||
|
|
||||||
|
hint := upperBound
|
||||||
|
if len(src) >= zstdFrameHeaderSizeMin {
|
||||||
|
hint = int(C.ZSTD_getFrameContentSize(unsafe.Pointer(&src[0]), C.size_t(len(src))))
|
||||||
|
if hint < 0 { // On error, just use upperBound
|
||||||
|
hint = upperBound
|
||||||
|
}
|
||||||
|
if hint == 0 { // When compressing the empty slice, we need an output of at least 1 to pass down to the C lib
|
||||||
|
hint = 1
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Take the minimum of both
|
||||||
|
if hint > upperBound {
|
||||||
|
return upperBound
|
||||||
|
}
|
||||||
|
return hint
|
||||||
|
}
|
||||||
|
|
||||||
// Compress src into dst. If you have a buffer to use, you can pass it to
|
// Compress src into dst. If you have a buffer to use, you can pass it to
|
||||||
// prevent allocation. If it is too small, or if nil is passed, a new buffer
|
// prevent allocation. If it is too small, or if nil is passed, a new buffer
|
||||||
// will be allocated and returned.
|
// will be allocated and returned.
|
||||||
@@ -73,19 +100,26 @@ func CompressLevel(dst, src []byte, level int) ([]byte, error) {
|
|||||||
dst = make([]byte, bound)
|
dst = make([]byte, bound)
|
||||||
}
|
}
|
||||||
|
|
||||||
srcPtr := C.uintptr_t(uintptr(0)) // Do not point anywhere, if src is empty
|
// We need unsafe.Pointer(&src[0]) in the Cgo call to avoid "Go pointer to Go pointer" panics.
|
||||||
if len(src) > 0 {
|
// This means we need to special case empty input. See:
|
||||||
srcPtr = C.uintptr_t(uintptr(unsafe.Pointer(&src[0])))
|
// https://github.com/golang/go/issues/14210#issuecomment-346402945
|
||||||
}
|
var cWritten C.size_t
|
||||||
|
if len(src) == 0 {
|
||||||
cWritten := C.ZSTD_compress_wrapper(
|
cWritten = C.ZSTD_compress(
|
||||||
C.uintptr_t(uintptr(unsafe.Pointer(&dst[0]))),
|
unsafe.Pointer(&dst[0]),
|
||||||
C.size_t(len(dst)),
|
C.size_t(len(dst)),
|
||||||
srcPtr,
|
unsafe.Pointer(nil),
|
||||||
|
C.size_t(0),
|
||||||
|
C.int(level))
|
||||||
|
} else {
|
||||||
|
cWritten = C.ZSTD_compress(
|
||||||
|
unsafe.Pointer(&dst[0]),
|
||||||
|
C.size_t(len(dst)),
|
||||||
|
unsafe.Pointer(&src[0]),
|
||||||
C.size_t(len(src)),
|
C.size_t(len(src)),
|
||||||
C.int(level))
|
C.int(level))
|
||||||
|
}
|
||||||
|
|
||||||
runtime.KeepAlive(src)
|
|
||||||
written := int(cWritten)
|
written := int(cWritten)
|
||||||
// Check if the return is an Error code
|
// Check if the return is an Error code
|
||||||
if err := getError(written); err != nil {
|
if err := getError(written); err != nil {
|
||||||
@@ -101,43 +135,25 @@ func Decompress(dst, src []byte) ([]byte, error) {
|
|||||||
if len(src) == 0 {
|
if len(src) == 0 {
|
||||||
return []byte{}, ErrEmptySlice
|
return []byte{}, ErrEmptySlice
|
||||||
}
|
}
|
||||||
decompress := func(dst, src []byte) ([]byte, error) {
|
|
||||||
|
|
||||||
cWritten := C.ZSTD_decompress_wrapper(
|
bound := decompressSizeHint(src)
|
||||||
C.uintptr_t(uintptr(unsafe.Pointer(&dst[0]))),
|
if cap(dst) >= bound {
|
||||||
C.size_t(len(dst)),
|
dst = dst[0:cap(dst)]
|
||||||
C.uintptr_t(uintptr(unsafe.Pointer(&src[0]))),
|
} else {
|
||||||
C.size_t(len(src)))
|
dst = make([]byte, bound)
|
||||||
|
|
||||||
runtime.KeepAlive(src)
|
|
||||||
written := int(cWritten)
|
|
||||||
// Check error
|
|
||||||
if err := getError(written); err != nil {
|
|
||||||
return nil, err
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
written := int(C.ZSTD_decompress(
|
||||||
|
unsafe.Pointer(&dst[0]),
|
||||||
|
C.size_t(len(dst)),
|
||||||
|
unsafe.Pointer(&src[0]),
|
||||||
|
C.size_t(len(src))))
|
||||||
|
err := getError(written)
|
||||||
|
if err == nil {
|
||||||
return dst[:written], nil
|
return dst[:written], nil
|
||||||
}
|
}
|
||||||
|
|
||||||
if len(dst) == 0 {
|
|
||||||
// Attempt to use zStd to determine decompressed size (may result in error or 0)
|
|
||||||
size := int(C.size_t(C.ZSTD_getDecompressedSize(unsafe.Pointer(&src[0]), C.size_t(len(src)))))
|
|
||||||
|
|
||||||
if err := getError(size); err != nil {
|
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
|
|
||||||
if size > 0 {
|
|
||||||
dst = make([]byte, size)
|
|
||||||
} else {
|
|
||||||
dst = make([]byte, len(src)*3) // starting guess
|
|
||||||
}
|
|
||||||
}
|
|
||||||
for i := 0; i < 3; i++ { // 3 tries to allocate a bigger buffer
|
|
||||||
result, err := decompress(dst, src)
|
|
||||||
if !IsDstSizeTooSmallError(err) {
|
if !IsDstSizeTooSmallError(err) {
|
||||||
return result, err
|
return nil, err
|
||||||
}
|
|
||||||
dst = make([]byte, len(dst)*2) // Grow buffer by 2
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// We failed getting a dst buffer of correct size, use stream API
|
// We failed getting a dst buffer of correct size, use stream API
|
||||||
|
|||||||
1566
vendor/github.com/DataDog/zstd/zstd.h
generated
vendored
1566
vendor/github.com/DataDog/zstd/zstd.h
generated
vendored
File diff suppressed because it is too large
Load Diff
151
vendor/github.com/DataDog/zstd/zstd_bulk.go
generated
vendored
Normal file
151
vendor/github.com/DataDog/zstd/zstd_bulk.go
generated
vendored
Normal file
@@ -0,0 +1,151 @@
|
|||||||
|
package zstd
|
||||||
|
|
||||||
|
/*
|
||||||
|
#include "zstd.h"
|
||||||
|
*/
|
||||||
|
import "C"
|
||||||
|
import (
|
||||||
|
"errors"
|
||||||
|
"runtime"
|
||||||
|
"unsafe"
|
||||||
|
)
|
||||||
|
|
||||||
|
var (
|
||||||
|
// ErrEmptyDictionary is returned when the given dictionary is empty
|
||||||
|
ErrEmptyDictionary = errors.New("Dictionary is empty")
|
||||||
|
// ErrBadDictionary is returned when cannot load the given dictionary
|
||||||
|
ErrBadDictionary = errors.New("Cannot load dictionary")
|
||||||
|
)
|
||||||
|
|
||||||
|
// BulkProcessor implements Bulk processing dictionary API.
|
||||||
|
// When compressing multiple messages or blocks using the same dictionary,
|
||||||
|
// it's recommended to digest the dictionary only once, since it's a costly operation.
|
||||||
|
// NewBulkProcessor() will create a state from digesting a dictionary.
|
||||||
|
// The resulting state can be used for future compression/decompression operations with very limited startup cost.
|
||||||
|
// BulkProcessor can be created once and shared by multiple threads concurrently, since its usage is read-only.
|
||||||
|
// The state will be freed when gc cleans up BulkProcessor.
|
||||||
|
type BulkProcessor struct {
|
||||||
|
cDict *C.struct_ZSTD_CDict_s
|
||||||
|
dDict *C.struct_ZSTD_DDict_s
|
||||||
|
}
|
||||||
|
|
||||||
|
// NewBulkProcessor creates a new BulkProcessor with a pre-trained dictionary and compression level
|
||||||
|
func NewBulkProcessor(dictionary []byte, compressionLevel int) (*BulkProcessor, error) {
|
||||||
|
if len(dictionary) < 1 {
|
||||||
|
return nil, ErrEmptyDictionary
|
||||||
|
}
|
||||||
|
|
||||||
|
p := &BulkProcessor{}
|
||||||
|
runtime.SetFinalizer(p, finalizeBulkProcessor)
|
||||||
|
|
||||||
|
p.cDict = C.ZSTD_createCDict(
|
||||||
|
unsafe.Pointer(&dictionary[0]),
|
||||||
|
C.size_t(len(dictionary)),
|
||||||
|
C.int(compressionLevel),
|
||||||
|
)
|
||||||
|
if p.cDict == nil {
|
||||||
|
return nil, ErrBadDictionary
|
||||||
|
}
|
||||||
|
p.dDict = C.ZSTD_createDDict(
|
||||||
|
unsafe.Pointer(&dictionary[0]),
|
||||||
|
C.size_t(len(dictionary)),
|
||||||
|
)
|
||||||
|
if p.dDict == nil {
|
||||||
|
return nil, ErrBadDictionary
|
||||||
|
}
|
||||||
|
|
||||||
|
return p, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
// Compress compresses `src` into `dst` with the dictionary given when creating the BulkProcessor.
|
||||||
|
// If you have a buffer to use, you can pass it to prevent allocation.
|
||||||
|
// If it is too small, or if nil is passed, a new buffer will be allocated and returned.
|
||||||
|
func (p *BulkProcessor) Compress(dst, src []byte) ([]byte, error) {
|
||||||
|
bound := CompressBound(len(src))
|
||||||
|
if cap(dst) >= bound {
|
||||||
|
dst = dst[0:bound]
|
||||||
|
} else {
|
||||||
|
dst = make([]byte, bound)
|
||||||
|
}
|
||||||
|
|
||||||
|
cctx := C.ZSTD_createCCtx()
|
||||||
|
// We need unsafe.Pointer(&src[0]) in the Cgo call to avoid "Go pointer to Go pointer" panics.
|
||||||
|
// This means we need to special case empty input. See:
|
||||||
|
// https://github.com/golang/go/issues/14210#issuecomment-346402945
|
||||||
|
var cWritten C.size_t
|
||||||
|
if len(src) == 0 {
|
||||||
|
cWritten = C.ZSTD_compress_usingCDict(
|
||||||
|
cctx,
|
||||||
|
unsafe.Pointer(&dst[0]),
|
||||||
|
C.size_t(len(dst)),
|
||||||
|
unsafe.Pointer(nil),
|
||||||
|
C.size_t(len(src)),
|
||||||
|
p.cDict,
|
||||||
|
)
|
||||||
|
} else {
|
||||||
|
cWritten = C.ZSTD_compress_usingCDict(
|
||||||
|
cctx,
|
||||||
|
unsafe.Pointer(&dst[0]),
|
||||||
|
C.size_t(len(dst)),
|
||||||
|
unsafe.Pointer(&src[0]),
|
||||||
|
C.size_t(len(src)),
|
||||||
|
p.cDict,
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
C.ZSTD_freeCCtx(cctx)
|
||||||
|
|
||||||
|
written := int(cWritten)
|
||||||
|
if err := getError(written); err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
return dst[:written], nil
|
||||||
|
}
|
||||||
|
|
||||||
|
// Decompress decompresses `src` into `dst` with the dictionary given when creating the BulkProcessor.
|
||||||
|
// If you have a buffer to use, you can pass it to prevent allocation.
|
||||||
|
// If it is too small, or if nil is passed, a new buffer will be allocated and returned.
|
||||||
|
func (p *BulkProcessor) Decompress(dst, src []byte) ([]byte, error) {
|
||||||
|
if len(src) == 0 {
|
||||||
|
return nil, ErrEmptySlice
|
||||||
|
}
|
||||||
|
|
||||||
|
contentSize := decompressSizeHint(src)
|
||||||
|
if cap(dst) >= contentSize {
|
||||||
|
dst = dst[0:contentSize]
|
||||||
|
} else {
|
||||||
|
dst = make([]byte, contentSize)
|
||||||
|
}
|
||||||
|
|
||||||
|
if contentSize == 0 {
|
||||||
|
return dst, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
dctx := C.ZSTD_createDCtx()
|
||||||
|
cWritten := C.ZSTD_decompress_usingDDict(
|
||||||
|
dctx,
|
||||||
|
unsafe.Pointer(&dst[0]),
|
||||||
|
C.size_t(contentSize),
|
||||||
|
unsafe.Pointer(&src[0]),
|
||||||
|
C.size_t(len(src)),
|
||||||
|
p.dDict,
|
||||||
|
)
|
||||||
|
C.ZSTD_freeDCtx(dctx)
|
||||||
|
|
||||||
|
written := int(cWritten)
|
||||||
|
if err := getError(written); err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
|
||||||
|
return dst[:written], nil
|
||||||
|
}
|
||||||
|
|
||||||
|
// finalizeBulkProcessor frees compression and decompression dictionaries from memory
|
||||||
|
func finalizeBulkProcessor(p *BulkProcessor) {
|
||||||
|
if p.cDict != nil {
|
||||||
|
C.ZSTD_freeCDict(p.cDict)
|
||||||
|
}
|
||||||
|
if p.dDict != nil {
|
||||||
|
C.ZSTD_freeDDict(p.dDict)
|
||||||
|
}
|
||||||
|
}
|
||||||
40
vendor/github.com/DataDog/zstd/zstd_common.c
generated
vendored
40
vendor/github.com/DataDog/zstd/zstd_common.c
generated
vendored
@@ -1,5 +1,6 @@
|
|||||||
|
#ifndef USE_EXTERNAL_ZSTD
|
||||||
/*
|
/*
|
||||||
* Copyright (c) 2016-present, Yann Collet, Facebook, Inc.
|
* Copyright (c) Meta Platforms, Inc. and affiliates.
|
||||||
* All rights reserved.
|
* All rights reserved.
|
||||||
*
|
*
|
||||||
* This source code is licensed under both the BSD-style license (found in the
|
* This source code is licensed under both the BSD-style license (found in the
|
||||||
@@ -13,8 +14,7 @@
|
|||||||
/*-*************************************
|
/*-*************************************
|
||||||
* Dependencies
|
* Dependencies
|
||||||
***************************************/
|
***************************************/
|
||||||
#include <stdlib.h> /* malloc, calloc, free */
|
#define ZSTD_DEPS_NEED_MALLOC
|
||||||
#include <string.h> /* memset */
|
|
||||||
#include "error_private.h"
|
#include "error_private.h"
|
||||||
#include "zstd_internal.h"
|
#include "zstd_internal.h"
|
||||||
|
|
||||||
@@ -48,36 +48,4 @@ ZSTD_ErrorCode ZSTD_getErrorCode(size_t code) { return ERR_getErrorCode(code); }
|
|||||||
* provides error code string from enum */
|
* provides error code string from enum */
|
||||||
const char* ZSTD_getErrorString(ZSTD_ErrorCode code) { return ERR_getErrorString(code); }
|
const char* ZSTD_getErrorString(ZSTD_ErrorCode code) { return ERR_getErrorString(code); }
|
||||||
|
|
||||||
|
#endif /* USE_EXTERNAL_ZSTD */
|
||||||
|
|
||||||
/*=**************************************************************
|
|
||||||
* Custom allocator
|
|
||||||
****************************************************************/
|
|
||||||
void* ZSTD_malloc(size_t size, ZSTD_customMem customMem)
|
|
||||||
{
|
|
||||||
if (customMem.customAlloc)
|
|
||||||
return customMem.customAlloc(customMem.opaque, size);
|
|
||||||
return malloc(size);
|
|
||||||
}
|
|
||||||
|
|
||||||
void* ZSTD_calloc(size_t size, ZSTD_customMem customMem)
|
|
||||||
{
|
|
||||||
if (customMem.customAlloc) {
|
|
||||||
/* calloc implemented as malloc+memset;
|
|
||||||
* not as efficient as calloc, but next best guess for custom malloc */
|
|
||||||
void* const ptr = customMem.customAlloc(customMem.opaque, size);
|
|
||||||
memset(ptr, 0, size);
|
|
||||||
return ptr;
|
|
||||||
}
|
|
||||||
return calloc(1, size);
|
|
||||||
}
|
|
||||||
|
|
||||||
void ZSTD_free(void* ptr, ZSTD_customMem customMem)
|
|
||||||
{
|
|
||||||
if (ptr!=NULL) {
|
|
||||||
if (customMem.customFree)
|
|
||||||
customMem.customFree(customMem.opaque, ptr);
|
|
||||||
else
|
|
||||||
free(ptr);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|||||||
5038
vendor/github.com/DataDog/zstd/zstd_compress.c
generated
vendored
5038
vendor/github.com/DataDog/zstd/zstd_compress.c
generated
vendored
File diff suppressed because it is too large
Load Diff
816
vendor/github.com/DataDog/zstd/zstd_compress_internal.h
generated
vendored
816
vendor/github.com/DataDog/zstd/zstd_compress_internal.h
generated
vendored
File diff suppressed because it is too large
Load Diff
154
vendor/github.com/DataDog/zstd/zstd_compress_literals.c
generated
vendored
154
vendor/github.com/DataDog/zstd/zstd_compress_literals.c
generated
vendored
@@ -1,5 +1,6 @@
|
|||||||
|
#ifndef USE_EXTERNAL_ZSTD
|
||||||
/*
|
/*
|
||||||
* Copyright (c) 2016-present, Yann Collet, Facebook, Inc.
|
* Copyright (c) Meta Platforms, Inc. and affiliates.
|
||||||
* All rights reserved.
|
* All rights reserved.
|
||||||
*
|
*
|
||||||
* This source code is licensed under both the BSD-style license (found in the
|
* This source code is licensed under both the BSD-style license (found in the
|
||||||
@@ -13,12 +14,37 @@
|
|||||||
***************************************/
|
***************************************/
|
||||||
#include "zstd_compress_literals.h"
|
#include "zstd_compress_literals.h"
|
||||||
|
|
||||||
|
|
||||||
|
/* **************************************************************
|
||||||
|
* Debug Traces
|
||||||
|
****************************************************************/
|
||||||
|
#if DEBUGLEVEL >= 2
|
||||||
|
|
||||||
|
static size_t showHexa(const void* src, size_t srcSize)
|
||||||
|
{
|
||||||
|
const BYTE* const ip = (const BYTE*)src;
|
||||||
|
size_t u;
|
||||||
|
for (u=0; u<srcSize; u++) {
|
||||||
|
RAWLOG(5, " %02X", ip[u]); (void)ip;
|
||||||
|
}
|
||||||
|
RAWLOG(5, " \n");
|
||||||
|
return srcSize;
|
||||||
|
}
|
||||||
|
|
||||||
|
#endif
|
||||||
|
|
||||||
|
|
||||||
|
/* **************************************************************
|
||||||
|
* Literals compression - special cases
|
||||||
|
****************************************************************/
|
||||||
size_t ZSTD_noCompressLiterals (void* dst, size_t dstCapacity, const void* src, size_t srcSize)
|
size_t ZSTD_noCompressLiterals (void* dst, size_t dstCapacity, const void* src, size_t srcSize)
|
||||||
{
|
{
|
||||||
BYTE* const ostart = (BYTE* const)dst;
|
BYTE* const ostart = (BYTE*)dst;
|
||||||
U32 const flSize = 1 + (srcSize>31) + (srcSize>4095);
|
U32 const flSize = 1 + (srcSize>31) + (srcSize>4095);
|
||||||
|
|
||||||
RETURN_ERROR_IF(srcSize + flSize > dstCapacity, dstSize_tooSmall);
|
DEBUGLOG(5, "ZSTD_noCompressLiterals: srcSize=%zu, dstCapacity=%zu", srcSize, dstCapacity);
|
||||||
|
|
||||||
|
RETURN_ERROR_IF(srcSize + flSize > dstCapacity, dstSize_tooSmall, "");
|
||||||
|
|
||||||
switch(flSize)
|
switch(flSize)
|
||||||
{
|
{
|
||||||
@@ -35,16 +61,31 @@ size_t ZSTD_noCompressLiterals (void* dst, size_t dstCapacity, const void* src,
|
|||||||
assert(0);
|
assert(0);
|
||||||
}
|
}
|
||||||
|
|
||||||
memcpy(ostart + flSize, src, srcSize);
|
ZSTD_memcpy(ostart + flSize, src, srcSize);
|
||||||
|
DEBUGLOG(5, "Raw (uncompressed) literals: %u -> %u", (U32)srcSize, (U32)(srcSize + flSize));
|
||||||
return srcSize + flSize;
|
return srcSize + flSize;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static int allBytesIdentical(const void* src, size_t srcSize)
|
||||||
|
{
|
||||||
|
assert(srcSize >= 1);
|
||||||
|
assert(src != NULL);
|
||||||
|
{ const BYTE b = ((const BYTE*)src)[0];
|
||||||
|
size_t p;
|
||||||
|
for (p=1; p<srcSize; p++) {
|
||||||
|
if (((const BYTE*)src)[p] != b) return 0;
|
||||||
|
}
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
size_t ZSTD_compressRleLiteralsBlock (void* dst, size_t dstCapacity, const void* src, size_t srcSize)
|
size_t ZSTD_compressRleLiteralsBlock (void* dst, size_t dstCapacity, const void* src, size_t srcSize)
|
||||||
{
|
{
|
||||||
BYTE* const ostart = (BYTE* const)dst;
|
BYTE* const ostart = (BYTE*)dst;
|
||||||
U32 const flSize = 1 + (srcSize>31) + (srcSize>4095);
|
U32 const flSize = 1 + (srcSize>31) + (srcSize>4095);
|
||||||
|
|
||||||
(void)dstCapacity; /* dstCapacity already guaranteed to be >=4, hence large enough */
|
assert(dstCapacity >= 4); (void)dstCapacity;
|
||||||
|
assert(allBytesIdentical(src, srcSize));
|
||||||
|
|
||||||
switch(flSize)
|
switch(flSize)
|
||||||
{
|
{
|
||||||
@@ -62,66 +103,103 @@ size_t ZSTD_compressRleLiteralsBlock (void* dst, size_t dstCapacity, const void*
|
|||||||
}
|
}
|
||||||
|
|
||||||
ostart[flSize] = *(const BYTE*)src;
|
ostart[flSize] = *(const BYTE*)src;
|
||||||
|
DEBUGLOG(5, "RLE : Repeated Literal (%02X: %u times) -> %u bytes encoded", ((const BYTE*)src)[0], (U32)srcSize, (U32)flSize + 1);
|
||||||
return flSize+1;
|
return flSize+1;
|
||||||
}
|
}
|
||||||
|
|
||||||
size_t ZSTD_compressLiterals (ZSTD_hufCTables_t const* prevHuf,
|
/* ZSTD_minLiteralsToCompress() :
|
||||||
ZSTD_hufCTables_t* nextHuf,
|
* returns minimal amount of literals
|
||||||
ZSTD_strategy strategy, int disableLiteralCompression,
|
* for literal compression to even be attempted.
|
||||||
|
* Minimum is made tighter as compression strategy increases.
|
||||||
|
*/
|
||||||
|
static size_t
|
||||||
|
ZSTD_minLiteralsToCompress(ZSTD_strategy strategy, HUF_repeat huf_repeat)
|
||||||
|
{
|
||||||
|
assert((int)strategy >= 0);
|
||||||
|
assert((int)strategy <= 9);
|
||||||
|
/* btultra2 : min 8 bytes;
|
||||||
|
* then 2x larger for each successive compression strategy
|
||||||
|
* max threshold 64 bytes */
|
||||||
|
{ int const shift = MIN(9-(int)strategy, 3);
|
||||||
|
size_t const mintc = (huf_repeat == HUF_repeat_valid) ? 6 : (size_t)8 << shift;
|
||||||
|
DEBUGLOG(7, "minLiteralsToCompress = %zu", mintc);
|
||||||
|
return mintc;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
size_t ZSTD_compressLiterals (
|
||||||
void* dst, size_t dstCapacity,
|
void* dst, size_t dstCapacity,
|
||||||
const void* src, size_t srcSize,
|
const void* src, size_t srcSize,
|
||||||
void* entropyWorkspace, size_t entropyWorkspaceSize,
|
void* entropyWorkspace, size_t entropyWorkspaceSize,
|
||||||
const int bmi2)
|
const ZSTD_hufCTables_t* prevHuf,
|
||||||
|
ZSTD_hufCTables_t* nextHuf,
|
||||||
|
ZSTD_strategy strategy,
|
||||||
|
int disableLiteralCompression,
|
||||||
|
int suspectUncompressible,
|
||||||
|
int bmi2)
|
||||||
{
|
{
|
||||||
size_t const minGain = ZSTD_minGain(srcSize, strategy);
|
|
||||||
size_t const lhSize = 3 + (srcSize >= 1 KB) + (srcSize >= 16 KB);
|
size_t const lhSize = 3 + (srcSize >= 1 KB) + (srcSize >= 16 KB);
|
||||||
BYTE* const ostart = (BYTE*)dst;
|
BYTE* const ostart = (BYTE*)dst;
|
||||||
U32 singleStream = srcSize < 256;
|
U32 singleStream = srcSize < 256;
|
||||||
symbolEncodingType_e hType = set_compressed;
|
symbolEncodingType_e hType = set_compressed;
|
||||||
size_t cLitSize;
|
size_t cLitSize;
|
||||||
|
|
||||||
DEBUGLOG(5,"ZSTD_compressLiterals (disableLiteralCompression=%i)",
|
DEBUGLOG(5,"ZSTD_compressLiterals (disableLiteralCompression=%i, srcSize=%u, dstCapacity=%zu)",
|
||||||
disableLiteralCompression);
|
disableLiteralCompression, (U32)srcSize, dstCapacity);
|
||||||
|
|
||||||
|
DEBUGLOG(6, "Completed literals listing (%zu bytes)", showHexa(src, srcSize));
|
||||||
|
|
||||||
/* Prepare nextEntropy assuming reusing the existing table */
|
/* Prepare nextEntropy assuming reusing the existing table */
|
||||||
memcpy(nextHuf, prevHuf, sizeof(*prevHuf));
|
ZSTD_memcpy(nextHuf, prevHuf, sizeof(*prevHuf));
|
||||||
|
|
||||||
if (disableLiteralCompression)
|
if (disableLiteralCompression)
|
||||||
return ZSTD_noCompressLiterals(dst, dstCapacity, src, srcSize);
|
return ZSTD_noCompressLiterals(dst, dstCapacity, src, srcSize);
|
||||||
|
|
||||||
/* small ? don't even attempt compression (speed opt) */
|
/* if too small, don't even attempt compression (speed opt) */
|
||||||
# define COMPRESS_LITERALS_SIZE_MIN 63
|
if (srcSize < ZSTD_minLiteralsToCompress(strategy, prevHuf->repeatMode))
|
||||||
{ size_t const minLitSize = (prevHuf->repeatMode == HUF_repeat_valid) ? 6 : COMPRESS_LITERALS_SIZE_MIN;
|
return ZSTD_noCompressLiterals(dst, dstCapacity, src, srcSize);
|
||||||
if (srcSize <= minLitSize) return ZSTD_noCompressLiterals(dst, dstCapacity, src, srcSize);
|
|
||||||
}
|
|
||||||
|
|
||||||
RETURN_ERROR_IF(dstCapacity < lhSize+1, dstSize_tooSmall, "not enough space for compression");
|
RETURN_ERROR_IF(dstCapacity < lhSize+1, dstSize_tooSmall, "not enough space for compression");
|
||||||
{ HUF_repeat repeat = prevHuf->repeatMode;
|
{ HUF_repeat repeat = prevHuf->repeatMode;
|
||||||
int const preferRepeat = strategy < ZSTD_lazy ? srcSize <= 1024 : 0;
|
int const flags = 0
|
||||||
|
| (bmi2 ? HUF_flags_bmi2 : 0)
|
||||||
|
| (strategy < ZSTD_lazy && srcSize <= 1024 ? HUF_flags_preferRepeat : 0)
|
||||||
|
| (strategy >= HUF_OPTIMAL_DEPTH_THRESHOLD ? HUF_flags_optimalDepth : 0)
|
||||||
|
| (suspectUncompressible ? HUF_flags_suspectUncompressible : 0);
|
||||||
|
|
||||||
|
typedef size_t (*huf_compress_f)(void*, size_t, const void*, size_t, unsigned, unsigned, void*, size_t, HUF_CElt*, HUF_repeat*, int);
|
||||||
|
huf_compress_f huf_compress;
|
||||||
if (repeat == HUF_repeat_valid && lhSize == 3) singleStream = 1;
|
if (repeat == HUF_repeat_valid && lhSize == 3) singleStream = 1;
|
||||||
cLitSize = singleStream ?
|
huf_compress = singleStream ? HUF_compress1X_repeat : HUF_compress4X_repeat;
|
||||||
HUF_compress1X_repeat(
|
cLitSize = huf_compress(ostart+lhSize, dstCapacity-lhSize,
|
||||||
ostart+lhSize, dstCapacity-lhSize, src, srcSize,
|
src, srcSize,
|
||||||
255, 11, entropyWorkspace, entropyWorkspaceSize,
|
HUF_SYMBOLVALUE_MAX, LitHufLog,
|
||||||
(HUF_CElt*)nextHuf->CTable, &repeat, preferRepeat, bmi2) :
|
entropyWorkspace, entropyWorkspaceSize,
|
||||||
HUF_compress4X_repeat(
|
(HUF_CElt*)nextHuf->CTable,
|
||||||
ostart+lhSize, dstCapacity-lhSize, src, srcSize,
|
&repeat, flags);
|
||||||
255, 11, entropyWorkspace, entropyWorkspaceSize,
|
DEBUGLOG(5, "%zu literals compressed into %zu bytes (before header)", srcSize, cLitSize);
|
||||||
(HUF_CElt*)nextHuf->CTable, &repeat, preferRepeat, bmi2);
|
|
||||||
if (repeat != HUF_repeat_none) {
|
if (repeat != HUF_repeat_none) {
|
||||||
/* reused the existing table */
|
/* reused the existing table */
|
||||||
|
DEBUGLOG(5, "reusing statistics from previous huffman block");
|
||||||
hType = set_repeat;
|
hType = set_repeat;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if ((cLitSize==0) | (cLitSize >= srcSize - minGain) | ERR_isError(cLitSize)) {
|
{ size_t const minGain = ZSTD_minGain(srcSize, strategy);
|
||||||
memcpy(nextHuf, prevHuf, sizeof(*prevHuf));
|
if ((cLitSize==0) || (cLitSize >= srcSize - minGain) || ERR_isError(cLitSize)) {
|
||||||
|
ZSTD_memcpy(nextHuf, prevHuf, sizeof(*prevHuf));
|
||||||
return ZSTD_noCompressLiterals(dst, dstCapacity, src, srcSize);
|
return ZSTD_noCompressLiterals(dst, dstCapacity, src, srcSize);
|
||||||
}
|
} }
|
||||||
if (cLitSize==1) {
|
if (cLitSize==1) {
|
||||||
memcpy(nextHuf, prevHuf, sizeof(*prevHuf));
|
/* A return value of 1 signals that the alphabet consists of a single symbol.
|
||||||
|
* However, in some rare circumstances, it could be the compressed size (a single byte).
|
||||||
|
* For that outcome to have a chance to happen, it's necessary that `srcSize < 8`.
|
||||||
|
* (it's also necessary to not generate statistics).
|
||||||
|
* Therefore, in such a case, actively check that all bytes are identical. */
|
||||||
|
if ((srcSize >= 8) || allBytesIdentical(src, srcSize)) {
|
||||||
|
ZSTD_memcpy(nextHuf, prevHuf, sizeof(*prevHuf));
|
||||||
return ZSTD_compressRleLiteralsBlock(dst, dstCapacity, src, srcSize);
|
return ZSTD_compressRleLiteralsBlock(dst, dstCapacity, src, srcSize);
|
||||||
}
|
} }
|
||||||
|
|
||||||
if (hType == set_compressed) {
|
if (hType == set_compressed) {
|
||||||
/* using a newly constructed table */
|
/* using a newly constructed table */
|
||||||
@@ -132,16 +210,19 @@ size_t ZSTD_compressLiterals (ZSTD_hufCTables_t const* prevHuf,
|
|||||||
switch(lhSize)
|
switch(lhSize)
|
||||||
{
|
{
|
||||||
case 3: /* 2 - 2 - 10 - 10 */
|
case 3: /* 2 - 2 - 10 - 10 */
|
||||||
{ U32 const lhc = hType + ((!singleStream) << 2) + ((U32)srcSize<<4) + ((U32)cLitSize<<14);
|
if (!singleStream) assert(srcSize >= MIN_LITERALS_FOR_4_STREAMS);
|
||||||
|
{ U32 const lhc = hType + ((U32)(!singleStream) << 2) + ((U32)srcSize<<4) + ((U32)cLitSize<<14);
|
||||||
MEM_writeLE24(ostart, lhc);
|
MEM_writeLE24(ostart, lhc);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
case 4: /* 2 - 2 - 14 - 14 */
|
case 4: /* 2 - 2 - 14 - 14 */
|
||||||
|
assert(srcSize >= MIN_LITERALS_FOR_4_STREAMS);
|
||||||
{ U32 const lhc = hType + (2 << 2) + ((U32)srcSize<<4) + ((U32)cLitSize<<18);
|
{ U32 const lhc = hType + (2 << 2) + ((U32)srcSize<<4) + ((U32)cLitSize<<18);
|
||||||
MEM_writeLE32(ostart, lhc);
|
MEM_writeLE32(ostart, lhc);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
case 5: /* 2 - 2 - 18 - 18 */
|
case 5: /* 2 - 2 - 18 - 18 */
|
||||||
|
assert(srcSize >= MIN_LITERALS_FOR_4_STREAMS);
|
||||||
{ U32 const lhc = hType + (3 << 2) + ((U32)srcSize<<4) + ((U32)cLitSize<<22);
|
{ U32 const lhc = hType + (3 << 2) + ((U32)srcSize<<4) + ((U32)cLitSize<<22);
|
||||||
MEM_writeLE32(ostart, lhc);
|
MEM_writeLE32(ostart, lhc);
|
||||||
ostart[4] = (BYTE)(cLitSize >> 10);
|
ostart[4] = (BYTE)(cLitSize >> 10);
|
||||||
@@ -150,5 +231,8 @@ size_t ZSTD_compressLiterals (ZSTD_hufCTables_t const* prevHuf,
|
|||||||
default: /* not possible : lhSize is {3,4,5} */
|
default: /* not possible : lhSize is {3,4,5} */
|
||||||
assert(0);
|
assert(0);
|
||||||
}
|
}
|
||||||
|
DEBUGLOG(5, "Compressed literals: %u -> %u", (U32)srcSize, (U32)(lhSize+cLitSize));
|
||||||
return lhSize+cLitSize;
|
return lhSize+cLitSize;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#endif /* USE_EXTERNAL_ZSTD */
|
||||||
|
|||||||
25
vendor/github.com/DataDog/zstd/zstd_compress_literals.h
generated
vendored
25
vendor/github.com/DataDog/zstd/zstd_compress_literals.h
generated
vendored
@@ -1,5 +1,6 @@
|
|||||||
|
#ifndef USE_EXTERNAL_ZSTD
|
||||||
/*
|
/*
|
||||||
* Copyright (c) 2016-present, Yann Collet, Facebook, Inc.
|
* Copyright (c) Meta Platforms, Inc. and affiliates.
|
||||||
* All rights reserved.
|
* All rights reserved.
|
||||||
*
|
*
|
||||||
* This source code is licensed under both the BSD-style license (found in the
|
* This source code is licensed under both the BSD-style license (found in the
|
||||||
@@ -16,14 +17,26 @@
|
|||||||
|
|
||||||
size_t ZSTD_noCompressLiterals (void* dst, size_t dstCapacity, const void* src, size_t srcSize);
|
size_t ZSTD_noCompressLiterals (void* dst, size_t dstCapacity, const void* src, size_t srcSize);
|
||||||
|
|
||||||
|
/* ZSTD_compressRleLiteralsBlock() :
|
||||||
|
* Conditions :
|
||||||
|
* - All bytes in @src are identical
|
||||||
|
* - dstCapacity >= 4 */
|
||||||
size_t ZSTD_compressRleLiteralsBlock (void* dst, size_t dstCapacity, const void* src, size_t srcSize);
|
size_t ZSTD_compressRleLiteralsBlock (void* dst, size_t dstCapacity, const void* src, size_t srcSize);
|
||||||
|
|
||||||
size_t ZSTD_compressLiterals (ZSTD_hufCTables_t const* prevHuf,
|
/* ZSTD_compressLiterals():
|
||||||
ZSTD_hufCTables_t* nextHuf,
|
* @entropyWorkspace: must be aligned on 4-bytes boundaries
|
||||||
ZSTD_strategy strategy, int disableLiteralCompression,
|
* @entropyWorkspaceSize : must be >= HUF_WORKSPACE_SIZE
|
||||||
void* dst, size_t dstCapacity,
|
* @suspectUncompressible: sampling checks, to potentially skip huffman coding
|
||||||
|
*/
|
||||||
|
size_t ZSTD_compressLiterals (void* dst, size_t dstCapacity,
|
||||||
const void* src, size_t srcSize,
|
const void* src, size_t srcSize,
|
||||||
void* entropyWorkspace, size_t entropyWorkspaceSize,
|
void* entropyWorkspace, size_t entropyWorkspaceSize,
|
||||||
const int bmi2);
|
const ZSTD_hufCTables_t* prevHuf,
|
||||||
|
ZSTD_hufCTables_t* nextHuf,
|
||||||
|
ZSTD_strategy strategy, int disableLiteralCompression,
|
||||||
|
int suspectUncompressible,
|
||||||
|
int bmi2);
|
||||||
|
|
||||||
#endif /* ZSTD_COMPRESS_LITERALS_H */
|
#endif /* ZSTD_COMPRESS_LITERALS_H */
|
||||||
|
|
||||||
|
#endif /* USE_EXTERNAL_ZSTD */
|
||||||
|
|||||||
98
vendor/github.com/DataDog/zstd/zstd_compress_sequences.c
generated
vendored
98
vendor/github.com/DataDog/zstd/zstd_compress_sequences.c
generated
vendored
@@ -1,5 +1,6 @@
|
|||||||
|
#ifndef USE_EXTERNAL_ZSTD
|
||||||
/*
|
/*
|
||||||
* Copyright (c) 2016-present, Yann Collet, Facebook, Inc.
|
* Copyright (c) Meta Platforms, Inc. and affiliates.
|
||||||
* All rights reserved.
|
* All rights reserved.
|
||||||
*
|
*
|
||||||
* This source code is licensed under both the BSD-style license (found in the
|
* This source code is licensed under both the BSD-style license (found in the
|
||||||
@@ -50,6 +51,19 @@ static unsigned ZSTD_getFSEMaxSymbolValue(FSE_CTable const* ctable) {
|
|||||||
return maxSymbolValue;
|
return maxSymbolValue;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns true if we should use ncount=-1 else we should
|
||||||
|
* use ncount=1 for low probability symbols instead.
|
||||||
|
*/
|
||||||
|
static unsigned ZSTD_useLowProbCount(size_t const nbSeq)
|
||||||
|
{
|
||||||
|
/* Heuristic: This should cover most blocks <= 16K and
|
||||||
|
* start to fade out after 16K to about 32K depending on
|
||||||
|
* compressibility.
|
||||||
|
*/
|
||||||
|
return nbSeq >= 2048;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns the cost in bytes of encoding the normalized count header.
|
* Returns the cost in bytes of encoding the normalized count header.
|
||||||
* Returns an error if any of the helper functions return an error.
|
* Returns an error if any of the helper functions return an error.
|
||||||
@@ -60,7 +74,7 @@ static size_t ZSTD_NCountCost(unsigned const* count, unsigned const max,
|
|||||||
BYTE wksp[FSE_NCOUNTBOUND];
|
BYTE wksp[FSE_NCOUNTBOUND];
|
||||||
S16 norm[MaxSeq + 1];
|
S16 norm[MaxSeq + 1];
|
||||||
const U32 tableLog = FSE_optimalTableLog(FSELog, nbSeq, max);
|
const U32 tableLog = FSE_optimalTableLog(FSELog, nbSeq, max);
|
||||||
FORWARD_IF_ERROR(FSE_normalizeCount(norm, tableLog, count, nbSeq, max));
|
FORWARD_IF_ERROR(FSE_normalizeCount(norm, tableLog, count, nbSeq, max, ZSTD_useLowProbCount(nbSeq)), "");
|
||||||
return FSE_writeNCount(wksp, sizeof(wksp), norm, max, tableLog);
|
return FSE_writeNCount(wksp, sizeof(wksp), norm, max, tableLog);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -72,6 +86,8 @@ static size_t ZSTD_entropyCost(unsigned const* count, unsigned const max, size_t
|
|||||||
{
|
{
|
||||||
unsigned cost = 0;
|
unsigned cost = 0;
|
||||||
unsigned s;
|
unsigned s;
|
||||||
|
|
||||||
|
assert(total > 0);
|
||||||
for (s = 0; s <= max; ++s) {
|
for (s = 0; s <= max; ++s) {
|
||||||
unsigned norm = (unsigned)((256 * count[s]) / total);
|
unsigned norm = (unsigned)((256 * count[s]) / total);
|
||||||
if (count[s] != 0 && norm == 0)
|
if (count[s] != 0 && norm == 0)
|
||||||
@@ -86,7 +102,7 @@ static size_t ZSTD_entropyCost(unsigned const* count, unsigned const max, size_t
|
|||||||
* Returns the cost in bits of encoding the distribution in count using ctable.
|
* Returns the cost in bits of encoding the distribution in count using ctable.
|
||||||
* Returns an error if ctable cannot represent all the symbols in count.
|
* Returns an error if ctable cannot represent all the symbols in count.
|
||||||
*/
|
*/
|
||||||
static size_t ZSTD_fseBitCost(
|
size_t ZSTD_fseBitCost(
|
||||||
FSE_CTable const* ctable,
|
FSE_CTable const* ctable,
|
||||||
unsigned const* count,
|
unsigned const* count,
|
||||||
unsigned const max)
|
unsigned const max)
|
||||||
@@ -96,18 +112,22 @@ static size_t ZSTD_fseBitCost(
|
|||||||
unsigned s;
|
unsigned s;
|
||||||
FSE_CState_t cstate;
|
FSE_CState_t cstate;
|
||||||
FSE_initCState(&cstate, ctable);
|
FSE_initCState(&cstate, ctable);
|
||||||
RETURN_ERROR_IF(ZSTD_getFSEMaxSymbolValue(ctable) < max, GENERIC,
|
if (ZSTD_getFSEMaxSymbolValue(ctable) < max) {
|
||||||
"Repeat FSE_CTable has maxSymbolValue %u < %u",
|
DEBUGLOG(5, "Repeat FSE_CTable has maxSymbolValue %u < %u",
|
||||||
ZSTD_getFSEMaxSymbolValue(ctable), max);
|
ZSTD_getFSEMaxSymbolValue(ctable), max);
|
||||||
|
return ERROR(GENERIC);
|
||||||
|
}
|
||||||
for (s = 0; s <= max; ++s) {
|
for (s = 0; s <= max; ++s) {
|
||||||
unsigned const tableLog = cstate.stateLog;
|
unsigned const tableLog = cstate.stateLog;
|
||||||
unsigned const badCost = (tableLog + 1) << kAccuracyLog;
|
unsigned const badCost = (tableLog + 1) << kAccuracyLog;
|
||||||
unsigned const bitCost = FSE_bitCost(cstate.symbolTT, tableLog, s, kAccuracyLog);
|
unsigned const bitCost = FSE_bitCost(cstate.symbolTT, tableLog, s, kAccuracyLog);
|
||||||
if (count[s] == 0)
|
if (count[s] == 0)
|
||||||
continue;
|
continue;
|
||||||
RETURN_ERROR_IF(bitCost >= badCost, GENERIC,
|
if (bitCost >= badCost) {
|
||||||
"Repeat FSE_CTable has Prob[%u] == 0", s);
|
DEBUGLOG(5, "Repeat FSE_CTable has Prob[%u] == 0", s);
|
||||||
cost += count[s] * bitCost;
|
return ERROR(GENERIC);
|
||||||
|
}
|
||||||
|
cost += (size_t)count[s] * bitCost;
|
||||||
}
|
}
|
||||||
return cost >> kAccuracyLog;
|
return cost >> kAccuracyLog;
|
||||||
}
|
}
|
||||||
@@ -117,7 +137,7 @@ static size_t ZSTD_fseBitCost(
|
|||||||
* table described by norm. The max symbol support by norm is assumed >= max.
|
* table described by norm. The max symbol support by norm is assumed >= max.
|
||||||
* norm must be valid for every symbol with non-zero probability in count.
|
* norm must be valid for every symbol with non-zero probability in count.
|
||||||
*/
|
*/
|
||||||
static size_t ZSTD_crossEntropyCost(short const* norm, unsigned accuracyLog,
|
size_t ZSTD_crossEntropyCost(short const* norm, unsigned accuracyLog,
|
||||||
unsigned const* count, unsigned const max)
|
unsigned const* count, unsigned const max)
|
||||||
{
|
{
|
||||||
unsigned const shift = 8 - accuracyLog;
|
unsigned const shift = 8 - accuracyLog;
|
||||||
@@ -125,7 +145,7 @@ static size_t ZSTD_crossEntropyCost(short const* norm, unsigned accuracyLog,
|
|||||||
unsigned s;
|
unsigned s;
|
||||||
assert(accuracyLog <= 8);
|
assert(accuracyLog <= 8);
|
||||||
for (s = 0; s <= max; ++s) {
|
for (s = 0; s <= max; ++s) {
|
||||||
unsigned const normAcc = norm[s] != -1 ? norm[s] : 1;
|
unsigned const normAcc = (norm[s] != -1) ? (unsigned)norm[s] : 1;
|
||||||
unsigned const norm256 = normAcc << shift;
|
unsigned const norm256 = normAcc << shift;
|
||||||
assert(norm256 > 0);
|
assert(norm256 > 0);
|
||||||
assert(norm256 < 256);
|
assert(norm256 < 256);
|
||||||
@@ -147,7 +167,7 @@ ZSTD_selectEncodingType(
|
|||||||
if (mostFrequent == nbSeq) {
|
if (mostFrequent == nbSeq) {
|
||||||
*repeatMode = FSE_repeat_none;
|
*repeatMode = FSE_repeat_none;
|
||||||
if (isDefaultAllowed && nbSeq <= 2) {
|
if (isDefaultAllowed && nbSeq <= 2) {
|
||||||
/* Prefer set_basic over set_rle when there are 2 or less symbols,
|
/* Prefer set_basic over set_rle when there are 2 or fewer symbols,
|
||||||
* since RLE uses 1 byte, but set_basic uses 5-6 bits per symbol.
|
* since RLE uses 1 byte, but set_basic uses 5-6 bits per symbol.
|
||||||
* If basic encoding isn't possible, always choose RLE.
|
* If basic encoding isn't possible, always choose RLE.
|
||||||
*/
|
*/
|
||||||
@@ -215,6 +235,11 @@ ZSTD_selectEncodingType(
|
|||||||
return set_compressed;
|
return set_compressed;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
typedef struct {
|
||||||
|
S16 norm[MaxSeq + 1];
|
||||||
|
U32 wksp[FSE_BUILD_CTABLE_WORKSPACE_SIZE_U32(MaxSeq, MaxFSELog)];
|
||||||
|
} ZSTD_BuildCTableWksp;
|
||||||
|
|
||||||
size_t
|
size_t
|
||||||
ZSTD_buildCTable(void* dst, size_t dstCapacity,
|
ZSTD_buildCTable(void* dst, size_t dstCapacity,
|
||||||
FSE_CTable* nextCTable, U32 FSELog, symbolEncodingType_e type,
|
FSE_CTable* nextCTable, U32 FSELog, symbolEncodingType_e type,
|
||||||
@@ -230,18 +255,18 @@ ZSTD_buildCTable(void* dst, size_t dstCapacity,
|
|||||||
|
|
||||||
switch (type) {
|
switch (type) {
|
||||||
case set_rle:
|
case set_rle:
|
||||||
FORWARD_IF_ERROR(FSE_buildCTable_rle(nextCTable, (BYTE)max));
|
FORWARD_IF_ERROR(FSE_buildCTable_rle(nextCTable, (BYTE)max), "");
|
||||||
RETURN_ERROR_IF(dstCapacity==0, dstSize_tooSmall);
|
RETURN_ERROR_IF(dstCapacity==0, dstSize_tooSmall, "not enough space");
|
||||||
*op = codeTable[0];
|
*op = codeTable[0];
|
||||||
return 1;
|
return 1;
|
||||||
case set_repeat:
|
case set_repeat:
|
||||||
memcpy(nextCTable, prevCTable, prevCTableSize);
|
ZSTD_memcpy(nextCTable, prevCTable, prevCTableSize);
|
||||||
return 0;
|
return 0;
|
||||||
case set_basic:
|
case set_basic:
|
||||||
FORWARD_IF_ERROR(FSE_buildCTable_wksp(nextCTable, defaultNorm, defaultMax, defaultNormLog, entropyWorkspace, entropyWorkspaceSize)); /* note : could be pre-calculated */
|
FORWARD_IF_ERROR(FSE_buildCTable_wksp(nextCTable, defaultNorm, defaultMax, defaultNormLog, entropyWorkspace, entropyWorkspaceSize), ""); /* note : could be pre-calculated */
|
||||||
return 0;
|
return 0;
|
||||||
case set_compressed: {
|
case set_compressed: {
|
||||||
S16 norm[MaxSeq + 1];
|
ZSTD_BuildCTableWksp* wksp = (ZSTD_BuildCTableWksp*)entropyWorkspace;
|
||||||
size_t nbSeq_1 = nbSeq;
|
size_t nbSeq_1 = nbSeq;
|
||||||
const U32 tableLog = FSE_optimalTableLog(FSELog, nbSeq, max);
|
const U32 tableLog = FSE_optimalTableLog(FSELog, nbSeq, max);
|
||||||
if (count[codeTable[nbSeq-1]] > 1) {
|
if (count[codeTable[nbSeq-1]] > 1) {
|
||||||
@@ -249,14 +274,17 @@ ZSTD_buildCTable(void* dst, size_t dstCapacity,
|
|||||||
nbSeq_1--;
|
nbSeq_1--;
|
||||||
}
|
}
|
||||||
assert(nbSeq_1 > 1);
|
assert(nbSeq_1 > 1);
|
||||||
FORWARD_IF_ERROR(FSE_normalizeCount(norm, tableLog, count, nbSeq_1, max));
|
assert(entropyWorkspaceSize >= sizeof(ZSTD_BuildCTableWksp));
|
||||||
{ size_t const NCountSize = FSE_writeNCount(op, oend - op, norm, max, tableLog); /* overflow protected */
|
(void)entropyWorkspaceSize;
|
||||||
FORWARD_IF_ERROR(NCountSize);
|
FORWARD_IF_ERROR(FSE_normalizeCount(wksp->norm, tableLog, count, nbSeq_1, max, ZSTD_useLowProbCount(nbSeq_1)), "FSE_normalizeCount failed");
|
||||||
FORWARD_IF_ERROR(FSE_buildCTable_wksp(nextCTable, norm, max, tableLog, entropyWorkspace, entropyWorkspaceSize));
|
assert(oend >= op);
|
||||||
|
{ size_t const NCountSize = FSE_writeNCount(op, (size_t)(oend - op), wksp->norm, max, tableLog); /* overflow protected */
|
||||||
|
FORWARD_IF_ERROR(NCountSize, "FSE_writeNCount failed");
|
||||||
|
FORWARD_IF_ERROR(FSE_buildCTable_wksp(nextCTable, wksp->norm, max, tableLog, wksp->wksp, sizeof(wksp->wksp)), "FSE_buildCTable_wksp failed");
|
||||||
return NCountSize;
|
return NCountSize;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
default: assert(0); RETURN_ERROR(GENERIC);
|
default: assert(0); RETURN_ERROR(GENERIC, "impossible to reach");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -286,19 +314,19 @@ ZSTD_encodeSequences_body(
|
|||||||
FSE_initCState2(&stateLitLength, CTable_LitLength, llCodeTable[nbSeq-1]);
|
FSE_initCState2(&stateLitLength, CTable_LitLength, llCodeTable[nbSeq-1]);
|
||||||
BIT_addBits(&blockStream, sequences[nbSeq-1].litLength, LL_bits[llCodeTable[nbSeq-1]]);
|
BIT_addBits(&blockStream, sequences[nbSeq-1].litLength, LL_bits[llCodeTable[nbSeq-1]]);
|
||||||
if (MEM_32bits()) BIT_flushBits(&blockStream);
|
if (MEM_32bits()) BIT_flushBits(&blockStream);
|
||||||
BIT_addBits(&blockStream, sequences[nbSeq-1].matchLength, ML_bits[mlCodeTable[nbSeq-1]]);
|
BIT_addBits(&blockStream, sequences[nbSeq-1].mlBase, ML_bits[mlCodeTable[nbSeq-1]]);
|
||||||
if (MEM_32bits()) BIT_flushBits(&blockStream);
|
if (MEM_32bits()) BIT_flushBits(&blockStream);
|
||||||
if (longOffsets) {
|
if (longOffsets) {
|
||||||
U32 const ofBits = ofCodeTable[nbSeq-1];
|
U32 const ofBits = ofCodeTable[nbSeq-1];
|
||||||
int const extraBits = ofBits - MIN(ofBits, STREAM_ACCUMULATOR_MIN-1);
|
unsigned const extraBits = ofBits - MIN(ofBits, STREAM_ACCUMULATOR_MIN-1);
|
||||||
if (extraBits) {
|
if (extraBits) {
|
||||||
BIT_addBits(&blockStream, sequences[nbSeq-1].offset, extraBits);
|
BIT_addBits(&blockStream, sequences[nbSeq-1].offBase, extraBits);
|
||||||
BIT_flushBits(&blockStream);
|
BIT_flushBits(&blockStream);
|
||||||
}
|
}
|
||||||
BIT_addBits(&blockStream, sequences[nbSeq-1].offset >> extraBits,
|
BIT_addBits(&blockStream, sequences[nbSeq-1].offBase >> extraBits,
|
||||||
ofBits - extraBits);
|
ofBits - extraBits);
|
||||||
} else {
|
} else {
|
||||||
BIT_addBits(&blockStream, sequences[nbSeq-1].offset, ofCodeTable[nbSeq-1]);
|
BIT_addBits(&blockStream, sequences[nbSeq-1].offBase, ofCodeTable[nbSeq-1]);
|
||||||
}
|
}
|
||||||
BIT_flushBits(&blockStream);
|
BIT_flushBits(&blockStream);
|
||||||
|
|
||||||
@@ -312,8 +340,8 @@ ZSTD_encodeSequences_body(
|
|||||||
U32 const mlBits = ML_bits[mlCode];
|
U32 const mlBits = ML_bits[mlCode];
|
||||||
DEBUGLOG(6, "encoding: litlen:%2u - matchlen:%2u - offCode:%7u",
|
DEBUGLOG(6, "encoding: litlen:%2u - matchlen:%2u - offCode:%7u",
|
||||||
(unsigned)sequences[n].litLength,
|
(unsigned)sequences[n].litLength,
|
||||||
(unsigned)sequences[n].matchLength + MINMATCH,
|
(unsigned)sequences[n].mlBase + MINMATCH,
|
||||||
(unsigned)sequences[n].offset);
|
(unsigned)sequences[n].offBase);
|
||||||
/* 32b*/ /* 64b*/
|
/* 32b*/ /* 64b*/
|
||||||
/* (7)*/ /* (7)*/
|
/* (7)*/ /* (7)*/
|
||||||
FSE_encodeSymbol(&blockStream, &stateOffsetBits, ofCode); /* 15 */ /* 15 */
|
FSE_encodeSymbol(&blockStream, &stateOffsetBits, ofCode); /* 15 */ /* 15 */
|
||||||
@@ -324,18 +352,18 @@ ZSTD_encodeSequences_body(
|
|||||||
BIT_flushBits(&blockStream); /* (7)*/
|
BIT_flushBits(&blockStream); /* (7)*/
|
||||||
BIT_addBits(&blockStream, sequences[n].litLength, llBits);
|
BIT_addBits(&blockStream, sequences[n].litLength, llBits);
|
||||||
if (MEM_32bits() && ((llBits+mlBits)>24)) BIT_flushBits(&blockStream);
|
if (MEM_32bits() && ((llBits+mlBits)>24)) BIT_flushBits(&blockStream);
|
||||||
BIT_addBits(&blockStream, sequences[n].matchLength, mlBits);
|
BIT_addBits(&blockStream, sequences[n].mlBase, mlBits);
|
||||||
if (MEM_32bits() || (ofBits+mlBits+llBits > 56)) BIT_flushBits(&blockStream);
|
if (MEM_32bits() || (ofBits+mlBits+llBits > 56)) BIT_flushBits(&blockStream);
|
||||||
if (longOffsets) {
|
if (longOffsets) {
|
||||||
int const extraBits = ofBits - MIN(ofBits, STREAM_ACCUMULATOR_MIN-1);
|
unsigned const extraBits = ofBits - MIN(ofBits, STREAM_ACCUMULATOR_MIN-1);
|
||||||
if (extraBits) {
|
if (extraBits) {
|
||||||
BIT_addBits(&blockStream, sequences[n].offset, extraBits);
|
BIT_addBits(&blockStream, sequences[n].offBase, extraBits);
|
||||||
BIT_flushBits(&blockStream); /* (7)*/
|
BIT_flushBits(&blockStream); /* (7)*/
|
||||||
}
|
}
|
||||||
BIT_addBits(&blockStream, sequences[n].offset >> extraBits,
|
BIT_addBits(&blockStream, sequences[n].offBase >> extraBits,
|
||||||
ofBits - extraBits); /* 31 */
|
ofBits - extraBits); /* 31 */
|
||||||
} else {
|
} else {
|
||||||
BIT_addBits(&blockStream, sequences[n].offset, ofBits); /* 31 */
|
BIT_addBits(&blockStream, sequences[n].offBase, ofBits); /* 31 */
|
||||||
}
|
}
|
||||||
BIT_flushBits(&blockStream); /* (7)*/
|
BIT_flushBits(&blockStream); /* (7)*/
|
||||||
DEBUGLOG(7, "remaining space : %i", (int)(blockStream.endPtr - blockStream.ptr));
|
DEBUGLOG(7, "remaining space : %i", (int)(blockStream.endPtr - blockStream.ptr));
|
||||||
@@ -372,7 +400,7 @@ ZSTD_encodeSequences_default(
|
|||||||
|
|
||||||
#if DYNAMIC_BMI2
|
#if DYNAMIC_BMI2
|
||||||
|
|
||||||
static TARGET_ATTRIBUTE("bmi2") size_t
|
static BMI2_TARGET_ATTRIBUTE size_t
|
||||||
ZSTD_encodeSequences_bmi2(
|
ZSTD_encodeSequences_bmi2(
|
||||||
void* dst, size_t dstCapacity,
|
void* dst, size_t dstCapacity,
|
||||||
FSE_CTable const* CTable_MatchLength, BYTE const* mlCodeTable,
|
FSE_CTable const* CTable_MatchLength, BYTE const* mlCodeTable,
|
||||||
@@ -413,3 +441,5 @@ size_t ZSTD_encodeSequences(
|
|||||||
CTable_LitLength, llCodeTable,
|
CTable_LitLength, llCodeTable,
|
||||||
sequences, nbSeq, longOffsets);
|
sequences, nbSeq, longOffsets);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#endif /* USE_EXTERNAL_ZSTD */
|
||||||
|
|||||||
12
vendor/github.com/DataDog/zstd/zstd_compress_sequences.h
generated
vendored
12
vendor/github.com/DataDog/zstd/zstd_compress_sequences.h
generated
vendored
@@ -1,5 +1,6 @@
|
|||||||
|
#ifndef USE_EXTERNAL_ZSTD
|
||||||
/*
|
/*
|
||||||
* Copyright (c) 2016-present, Yann Collet, Facebook, Inc.
|
* Copyright (c) Meta Platforms, Inc. and affiliates.
|
||||||
* All rights reserved.
|
* All rights reserved.
|
||||||
*
|
*
|
||||||
* This source code is licensed under both the BSD-style license (found in the
|
* This source code is licensed under both the BSD-style license (found in the
|
||||||
@@ -44,4 +45,13 @@ size_t ZSTD_encodeSequences(
|
|||||||
FSE_CTable const* CTable_LitLength, BYTE const* llCodeTable,
|
FSE_CTable const* CTable_LitLength, BYTE const* llCodeTable,
|
||||||
seqDef const* sequences, size_t nbSeq, int longOffsets, int bmi2);
|
seqDef const* sequences, size_t nbSeq, int longOffsets, int bmi2);
|
||||||
|
|
||||||
|
size_t ZSTD_fseBitCost(
|
||||||
|
FSE_CTable const* ctable,
|
||||||
|
unsigned const* count,
|
||||||
|
unsigned const max);
|
||||||
|
|
||||||
|
size_t ZSTD_crossEntropyCost(short const* norm, unsigned accuracyLog,
|
||||||
|
unsigned const* count, unsigned const max);
|
||||||
#endif /* ZSTD_COMPRESS_SEQUENCES_H */
|
#endif /* ZSTD_COMPRESS_SEQUENCES_H */
|
||||||
|
|
||||||
|
#endif /* USE_EXTERNAL_ZSTD */
|
||||||
|
|||||||
580
vendor/github.com/DataDog/zstd/zstd_compress_superblock.c
generated
vendored
Normal file
580
vendor/github.com/DataDog/zstd/zstd_compress_superblock.c
generated
vendored
Normal file
@@ -0,0 +1,580 @@
|
|||||||
|
#ifndef USE_EXTERNAL_ZSTD
|
||||||
|
/*
|
||||||
|
* Copyright (c) Meta Platforms, Inc. and affiliates.
|
||||||
|
* All rights reserved.
|
||||||
|
*
|
||||||
|
* This source code is licensed under both the BSD-style license (found in the
|
||||||
|
* LICENSE file in the root directory of this source tree) and the GPLv2 (found
|
||||||
|
* in the COPYING file in the root directory of this source tree).
|
||||||
|
* You may select, at your option, one of the above-listed licenses.
|
||||||
|
*/
|
||||||
|
|
||||||
|
/*-*************************************
|
||||||
|
* Dependencies
|
||||||
|
***************************************/
|
||||||
|
#include "zstd_compress_superblock.h"
|
||||||
|
|
||||||
|
#include "zstd_internal.h" /* ZSTD_getSequenceLength */
|
||||||
|
#include "hist.h" /* HIST_countFast_wksp */
|
||||||
|
#include "zstd_compress_internal.h" /* ZSTD_[huf|fse|entropy]CTablesMetadata_t */
|
||||||
|
#include "zstd_compress_sequences.h"
|
||||||
|
#include "zstd_compress_literals.h"
|
||||||
|
|
||||||
|
/** ZSTD_compressSubBlock_literal() :
|
||||||
|
* Compresses literals section for a sub-block.
|
||||||
|
* When we have to write the Huffman table we will sometimes choose a header
|
||||||
|
* size larger than necessary. This is because we have to pick the header size
|
||||||
|
* before we know the table size + compressed size, so we have a bound on the
|
||||||
|
* table size. If we guessed incorrectly, we fall back to uncompressed literals.
|
||||||
|
*
|
||||||
|
* We write the header when writeEntropy=1 and set entropyWritten=1 when we succeeded
|
||||||
|
* in writing the header, otherwise it is set to 0.
|
||||||
|
*
|
||||||
|
* hufMetadata->hType has literals block type info.
|
||||||
|
* If it is set_basic, all sub-blocks literals section will be Raw_Literals_Block.
|
||||||
|
* If it is set_rle, all sub-blocks literals section will be RLE_Literals_Block.
|
||||||
|
* If it is set_compressed, first sub-block's literals section will be Compressed_Literals_Block
|
||||||
|
* If it is set_compressed, first sub-block's literals section will be Treeless_Literals_Block
|
||||||
|
* and the following sub-blocks' literals sections will be Treeless_Literals_Block.
|
||||||
|
* @return : compressed size of literals section of a sub-block
|
||||||
|
* Or 0 if unable to compress.
|
||||||
|
* Or error code */
|
||||||
|
static size_t
|
||||||
|
ZSTD_compressSubBlock_literal(const HUF_CElt* hufTable,
|
||||||
|
const ZSTD_hufCTablesMetadata_t* hufMetadata,
|
||||||
|
const BYTE* literals, size_t litSize,
|
||||||
|
void* dst, size_t dstSize,
|
||||||
|
const int bmi2, int writeEntropy, int* entropyWritten)
|
||||||
|
{
|
||||||
|
size_t const header = writeEntropy ? 200 : 0;
|
||||||
|
size_t const lhSize = 3 + (litSize >= (1 KB - header)) + (litSize >= (16 KB - header));
|
||||||
|
BYTE* const ostart = (BYTE*)dst;
|
||||||
|
BYTE* const oend = ostart + dstSize;
|
||||||
|
BYTE* op = ostart + lhSize;
|
||||||
|
U32 const singleStream = lhSize == 3;
|
||||||
|
symbolEncodingType_e hType = writeEntropy ? hufMetadata->hType : set_repeat;
|
||||||
|
size_t cLitSize = 0;
|
||||||
|
|
||||||
|
DEBUGLOG(5, "ZSTD_compressSubBlock_literal (litSize=%zu, lhSize=%zu, writeEntropy=%d)", litSize, lhSize, writeEntropy);
|
||||||
|
|
||||||
|
*entropyWritten = 0;
|
||||||
|
if (litSize == 0 || hufMetadata->hType == set_basic) {
|
||||||
|
DEBUGLOG(5, "ZSTD_compressSubBlock_literal using raw literal");
|
||||||
|
return ZSTD_noCompressLiterals(dst, dstSize, literals, litSize);
|
||||||
|
} else if (hufMetadata->hType == set_rle) {
|
||||||
|
DEBUGLOG(5, "ZSTD_compressSubBlock_literal using rle literal");
|
||||||
|
return ZSTD_compressRleLiteralsBlock(dst, dstSize, literals, litSize);
|
||||||
|
}
|
||||||
|
|
||||||
|
assert(litSize > 0);
|
||||||
|
assert(hufMetadata->hType == set_compressed || hufMetadata->hType == set_repeat);
|
||||||
|
|
||||||
|
if (writeEntropy && hufMetadata->hType == set_compressed) {
|
||||||
|
ZSTD_memcpy(op, hufMetadata->hufDesBuffer, hufMetadata->hufDesSize);
|
||||||
|
op += hufMetadata->hufDesSize;
|
||||||
|
cLitSize += hufMetadata->hufDesSize;
|
||||||
|
DEBUGLOG(5, "ZSTD_compressSubBlock_literal (hSize=%zu)", hufMetadata->hufDesSize);
|
||||||
|
}
|
||||||
|
|
||||||
|
{ int const flags = bmi2 ? HUF_flags_bmi2 : 0;
|
||||||
|
const size_t cSize = singleStream ? HUF_compress1X_usingCTable(op, oend-op, literals, litSize, hufTable, flags)
|
||||||
|
: HUF_compress4X_usingCTable(op, oend-op, literals, litSize, hufTable, flags);
|
||||||
|
op += cSize;
|
||||||
|
cLitSize += cSize;
|
||||||
|
if (cSize == 0 || ERR_isError(cSize)) {
|
||||||
|
DEBUGLOG(5, "Failed to write entropy tables %s", ZSTD_getErrorName(cSize));
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
/* If we expand and we aren't writing a header then emit uncompressed */
|
||||||
|
if (!writeEntropy && cLitSize >= litSize) {
|
||||||
|
DEBUGLOG(5, "ZSTD_compressSubBlock_literal using raw literal because uncompressible");
|
||||||
|
return ZSTD_noCompressLiterals(dst, dstSize, literals, litSize);
|
||||||
|
}
|
||||||
|
/* If we are writing headers then allow expansion that doesn't change our header size. */
|
||||||
|
if (lhSize < (size_t)(3 + (cLitSize >= 1 KB) + (cLitSize >= 16 KB))) {
|
||||||
|
assert(cLitSize > litSize);
|
||||||
|
DEBUGLOG(5, "Literals expanded beyond allowed header size");
|
||||||
|
return ZSTD_noCompressLiterals(dst, dstSize, literals, litSize);
|
||||||
|
}
|
||||||
|
DEBUGLOG(5, "ZSTD_compressSubBlock_literal (cSize=%zu)", cSize);
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Build header */
|
||||||
|
switch(lhSize)
|
||||||
|
{
|
||||||
|
case 3: /* 2 - 2 - 10 - 10 */
|
||||||
|
{ U32 const lhc = hType + ((!singleStream) << 2) + ((U32)litSize<<4) + ((U32)cLitSize<<14);
|
||||||
|
MEM_writeLE24(ostart, lhc);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
case 4: /* 2 - 2 - 14 - 14 */
|
||||||
|
{ U32 const lhc = hType + (2 << 2) + ((U32)litSize<<4) + ((U32)cLitSize<<18);
|
||||||
|
MEM_writeLE32(ostart, lhc);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
case 5: /* 2 - 2 - 18 - 18 */
|
||||||
|
{ U32 const lhc = hType + (3 << 2) + ((U32)litSize<<4) + ((U32)cLitSize<<22);
|
||||||
|
MEM_writeLE32(ostart, lhc);
|
||||||
|
ostart[4] = (BYTE)(cLitSize >> 10);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
default: /* not possible : lhSize is {3,4,5} */
|
||||||
|
assert(0);
|
||||||
|
}
|
||||||
|
*entropyWritten = 1;
|
||||||
|
DEBUGLOG(5, "Compressed literals: %u -> %u", (U32)litSize, (U32)(op-ostart));
|
||||||
|
return op-ostart;
|
||||||
|
}
|
||||||
|
|
||||||
|
static size_t
|
||||||
|
ZSTD_seqDecompressedSize(seqStore_t const* seqStore,
|
||||||
|
const seqDef* sequences, size_t nbSeq,
|
||||||
|
size_t litSize, int lastSequence)
|
||||||
|
{
|
||||||
|
const seqDef* const sstart = sequences;
|
||||||
|
const seqDef* const send = sequences + nbSeq;
|
||||||
|
const seqDef* sp = sstart;
|
||||||
|
size_t matchLengthSum = 0;
|
||||||
|
size_t litLengthSum = 0;
|
||||||
|
(void)(litLengthSum); /* suppress unused variable warning on some environments */
|
||||||
|
while (send-sp > 0) {
|
||||||
|
ZSTD_sequenceLength const seqLen = ZSTD_getSequenceLength(seqStore, sp);
|
||||||
|
litLengthSum += seqLen.litLength;
|
||||||
|
matchLengthSum += seqLen.matchLength;
|
||||||
|
sp++;
|
||||||
|
}
|
||||||
|
assert(litLengthSum <= litSize);
|
||||||
|
if (!lastSequence) {
|
||||||
|
assert(litLengthSum == litSize);
|
||||||
|
}
|
||||||
|
return matchLengthSum + litSize;
|
||||||
|
}
|
||||||
|
|
||||||
|
/** ZSTD_compressSubBlock_sequences() :
|
||||||
|
* Compresses sequences section for a sub-block.
|
||||||
|
* fseMetadata->llType, fseMetadata->ofType, and fseMetadata->mlType have
|
||||||
|
* symbol compression modes for the super-block.
|
||||||
|
* The first successfully compressed block will have these in its header.
|
||||||
|
* We set entropyWritten=1 when we succeed in compressing the sequences.
|
||||||
|
* The following sub-blocks will always have repeat mode.
|
||||||
|
* @return : compressed size of sequences section of a sub-block
|
||||||
|
* Or 0 if it is unable to compress
|
||||||
|
* Or error code. */
|
||||||
|
static size_t
|
||||||
|
ZSTD_compressSubBlock_sequences(const ZSTD_fseCTables_t* fseTables,
|
||||||
|
const ZSTD_fseCTablesMetadata_t* fseMetadata,
|
||||||
|
const seqDef* sequences, size_t nbSeq,
|
||||||
|
const BYTE* llCode, const BYTE* mlCode, const BYTE* ofCode,
|
||||||
|
const ZSTD_CCtx_params* cctxParams,
|
||||||
|
void* dst, size_t dstCapacity,
|
||||||
|
const int bmi2, int writeEntropy, int* entropyWritten)
|
||||||
|
{
|
||||||
|
const int longOffsets = cctxParams->cParams.windowLog > STREAM_ACCUMULATOR_MIN;
|
||||||
|
BYTE* const ostart = (BYTE*)dst;
|
||||||
|
BYTE* const oend = ostart + dstCapacity;
|
||||||
|
BYTE* op = ostart;
|
||||||
|
BYTE* seqHead;
|
||||||
|
|
||||||
|
DEBUGLOG(5, "ZSTD_compressSubBlock_sequences (nbSeq=%zu, writeEntropy=%d, longOffsets=%d)", nbSeq, writeEntropy, longOffsets);
|
||||||
|
|
||||||
|
*entropyWritten = 0;
|
||||||
|
/* Sequences Header */
|
||||||
|
RETURN_ERROR_IF((oend-op) < 3 /*max nbSeq Size*/ + 1 /*seqHead*/,
|
||||||
|
dstSize_tooSmall, "");
|
||||||
|
if (nbSeq < 0x7F)
|
||||||
|
*op++ = (BYTE)nbSeq;
|
||||||
|
else if (nbSeq < LONGNBSEQ)
|
||||||
|
op[0] = (BYTE)((nbSeq>>8) + 0x80), op[1] = (BYTE)nbSeq, op+=2;
|
||||||
|
else
|
||||||
|
op[0]=0xFF, MEM_writeLE16(op+1, (U16)(nbSeq - LONGNBSEQ)), op+=3;
|
||||||
|
if (nbSeq==0) {
|
||||||
|
return op - ostart;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* seqHead : flags for FSE encoding type */
|
||||||
|
seqHead = op++;
|
||||||
|
|
||||||
|
DEBUGLOG(5, "ZSTD_compressSubBlock_sequences (seqHeadSize=%u)", (unsigned)(op-ostart));
|
||||||
|
|
||||||
|
if (writeEntropy) {
|
||||||
|
const U32 LLtype = fseMetadata->llType;
|
||||||
|
const U32 Offtype = fseMetadata->ofType;
|
||||||
|
const U32 MLtype = fseMetadata->mlType;
|
||||||
|
DEBUGLOG(5, "ZSTD_compressSubBlock_sequences (fseTablesSize=%zu)", fseMetadata->fseTablesSize);
|
||||||
|
*seqHead = (BYTE)((LLtype<<6) + (Offtype<<4) + (MLtype<<2));
|
||||||
|
ZSTD_memcpy(op, fseMetadata->fseTablesBuffer, fseMetadata->fseTablesSize);
|
||||||
|
op += fseMetadata->fseTablesSize;
|
||||||
|
} else {
|
||||||
|
const U32 repeat = set_repeat;
|
||||||
|
*seqHead = (BYTE)((repeat<<6) + (repeat<<4) + (repeat<<2));
|
||||||
|
}
|
||||||
|
|
||||||
|
{ size_t const bitstreamSize = ZSTD_encodeSequences(
|
||||||
|
op, oend - op,
|
||||||
|
fseTables->matchlengthCTable, mlCode,
|
||||||
|
fseTables->offcodeCTable, ofCode,
|
||||||
|
fseTables->litlengthCTable, llCode,
|
||||||
|
sequences, nbSeq,
|
||||||
|
longOffsets, bmi2);
|
||||||
|
FORWARD_IF_ERROR(bitstreamSize, "ZSTD_encodeSequences failed");
|
||||||
|
op += bitstreamSize;
|
||||||
|
/* zstd versions <= 1.3.4 mistakenly report corruption when
|
||||||
|
* FSE_readNCount() receives a buffer < 4 bytes.
|
||||||
|
* Fixed by https://github.com/facebook/zstd/pull/1146.
|
||||||
|
* This can happen when the last set_compressed table present is 2
|
||||||
|
* bytes and the bitstream is only one byte.
|
||||||
|
* In this exceedingly rare case, we will simply emit an uncompressed
|
||||||
|
* block, since it isn't worth optimizing.
|
||||||
|
*/
|
||||||
|
#ifndef FUZZING_BUILD_MODE_UNSAFE_FOR_PRODUCTION
|
||||||
|
if (writeEntropy && fseMetadata->lastCountSize && fseMetadata->lastCountSize + bitstreamSize < 4) {
|
||||||
|
/* NCountSize >= 2 && bitstreamSize > 0 ==> lastCountSize == 3 */
|
||||||
|
assert(fseMetadata->lastCountSize + bitstreamSize == 3);
|
||||||
|
DEBUGLOG(5, "Avoiding bug in zstd decoder in versions <= 1.3.4 by "
|
||||||
|
"emitting an uncompressed block.");
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
DEBUGLOG(5, "ZSTD_compressSubBlock_sequences (bitstreamSize=%zu)", bitstreamSize);
|
||||||
|
}
|
||||||
|
|
||||||
|
/* zstd versions <= 1.4.0 mistakenly report error when
|
||||||
|
* sequences section body size is less than 3 bytes.
|
||||||
|
* Fixed by https://github.com/facebook/zstd/pull/1664.
|
||||||
|
* This can happen when the previous sequences section block is compressed
|
||||||
|
* with rle mode and the current block's sequences section is compressed
|
||||||
|
* with repeat mode where sequences section body size can be 1 byte.
|
||||||
|
*/
|
||||||
|
#ifndef FUZZING_BUILD_MODE_UNSAFE_FOR_PRODUCTION
|
||||||
|
if (op-seqHead < 4) {
|
||||||
|
DEBUGLOG(5, "Avoiding bug in zstd decoder in versions <= 1.4.0 by emitting "
|
||||||
|
"an uncompressed block when sequences are < 4 bytes");
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
|
*entropyWritten = 1;
|
||||||
|
return op - ostart;
|
||||||
|
}
|
||||||
|
|
||||||
|
/** ZSTD_compressSubBlock() :
|
||||||
|
* Compresses a single sub-block.
|
||||||
|
* @return : compressed size of the sub-block
|
||||||
|
* Or 0 if it failed to compress. */
|
||||||
|
static size_t ZSTD_compressSubBlock(const ZSTD_entropyCTables_t* entropy,
|
||||||
|
const ZSTD_entropyCTablesMetadata_t* entropyMetadata,
|
||||||
|
const seqDef* sequences, size_t nbSeq,
|
||||||
|
const BYTE* literals, size_t litSize,
|
||||||
|
const BYTE* llCode, const BYTE* mlCode, const BYTE* ofCode,
|
||||||
|
const ZSTD_CCtx_params* cctxParams,
|
||||||
|
void* dst, size_t dstCapacity,
|
||||||
|
const int bmi2,
|
||||||
|
int writeLitEntropy, int writeSeqEntropy,
|
||||||
|
int* litEntropyWritten, int* seqEntropyWritten,
|
||||||
|
U32 lastBlock)
|
||||||
|
{
|
||||||
|
BYTE* const ostart = (BYTE*)dst;
|
||||||
|
BYTE* const oend = ostart + dstCapacity;
|
||||||
|
BYTE* op = ostart + ZSTD_blockHeaderSize;
|
||||||
|
DEBUGLOG(5, "ZSTD_compressSubBlock (litSize=%zu, nbSeq=%zu, writeLitEntropy=%d, writeSeqEntropy=%d, lastBlock=%d)",
|
||||||
|
litSize, nbSeq, writeLitEntropy, writeSeqEntropy, lastBlock);
|
||||||
|
{ size_t cLitSize = ZSTD_compressSubBlock_literal((const HUF_CElt*)entropy->huf.CTable,
|
||||||
|
&entropyMetadata->hufMetadata, literals, litSize,
|
||||||
|
op, oend-op, bmi2, writeLitEntropy, litEntropyWritten);
|
||||||
|
FORWARD_IF_ERROR(cLitSize, "ZSTD_compressSubBlock_literal failed");
|
||||||
|
if (cLitSize == 0) return 0;
|
||||||
|
op += cLitSize;
|
||||||
|
}
|
||||||
|
{ size_t cSeqSize = ZSTD_compressSubBlock_sequences(&entropy->fse,
|
||||||
|
&entropyMetadata->fseMetadata,
|
||||||
|
sequences, nbSeq,
|
||||||
|
llCode, mlCode, ofCode,
|
||||||
|
cctxParams,
|
||||||
|
op, oend-op,
|
||||||
|
bmi2, writeSeqEntropy, seqEntropyWritten);
|
||||||
|
FORWARD_IF_ERROR(cSeqSize, "ZSTD_compressSubBlock_sequences failed");
|
||||||
|
if (cSeqSize == 0) return 0;
|
||||||
|
op += cSeqSize;
|
||||||
|
}
|
||||||
|
/* Write block header */
|
||||||
|
{ size_t cSize = (op-ostart)-ZSTD_blockHeaderSize;
|
||||||
|
U32 const cBlockHeader24 = lastBlock + (((U32)bt_compressed)<<1) + (U32)(cSize << 3);
|
||||||
|
MEM_writeLE24(ostart, cBlockHeader24);
|
||||||
|
}
|
||||||
|
return op-ostart;
|
||||||
|
}
|
||||||
|
|
||||||
|
static size_t ZSTD_estimateSubBlockSize_literal(const BYTE* literals, size_t litSize,
|
||||||
|
const ZSTD_hufCTables_t* huf,
|
||||||
|
const ZSTD_hufCTablesMetadata_t* hufMetadata,
|
||||||
|
void* workspace, size_t wkspSize,
|
||||||
|
int writeEntropy)
|
||||||
|
{
|
||||||
|
unsigned* const countWksp = (unsigned*)workspace;
|
||||||
|
unsigned maxSymbolValue = 255;
|
||||||
|
size_t literalSectionHeaderSize = 3; /* Use hard coded size of 3 bytes */
|
||||||
|
|
||||||
|
if (hufMetadata->hType == set_basic) return litSize;
|
||||||
|
else if (hufMetadata->hType == set_rle) return 1;
|
||||||
|
else if (hufMetadata->hType == set_compressed || hufMetadata->hType == set_repeat) {
|
||||||
|
size_t const largest = HIST_count_wksp (countWksp, &maxSymbolValue, (const BYTE*)literals, litSize, workspace, wkspSize);
|
||||||
|
if (ZSTD_isError(largest)) return litSize;
|
||||||
|
{ size_t cLitSizeEstimate = HUF_estimateCompressedSize((const HUF_CElt*)huf->CTable, countWksp, maxSymbolValue);
|
||||||
|
if (writeEntropy) cLitSizeEstimate += hufMetadata->hufDesSize;
|
||||||
|
return cLitSizeEstimate + literalSectionHeaderSize;
|
||||||
|
} }
|
||||||
|
assert(0); /* impossible */
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
static size_t ZSTD_estimateSubBlockSize_symbolType(symbolEncodingType_e type,
|
||||||
|
const BYTE* codeTable, unsigned maxCode,
|
||||||
|
size_t nbSeq, const FSE_CTable* fseCTable,
|
||||||
|
const U8* additionalBits,
|
||||||
|
short const* defaultNorm, U32 defaultNormLog, U32 defaultMax,
|
||||||
|
void* workspace, size_t wkspSize)
|
||||||
|
{
|
||||||
|
unsigned* const countWksp = (unsigned*)workspace;
|
||||||
|
const BYTE* ctp = codeTable;
|
||||||
|
const BYTE* const ctStart = ctp;
|
||||||
|
const BYTE* const ctEnd = ctStart + nbSeq;
|
||||||
|
size_t cSymbolTypeSizeEstimateInBits = 0;
|
||||||
|
unsigned max = maxCode;
|
||||||
|
|
||||||
|
HIST_countFast_wksp(countWksp, &max, codeTable, nbSeq, workspace, wkspSize); /* can't fail */
|
||||||
|
if (type == set_basic) {
|
||||||
|
/* We selected this encoding type, so it must be valid. */
|
||||||
|
assert(max <= defaultMax);
|
||||||
|
cSymbolTypeSizeEstimateInBits = max <= defaultMax
|
||||||
|
? ZSTD_crossEntropyCost(defaultNorm, defaultNormLog, countWksp, max)
|
||||||
|
: ERROR(GENERIC);
|
||||||
|
} else if (type == set_rle) {
|
||||||
|
cSymbolTypeSizeEstimateInBits = 0;
|
||||||
|
} else if (type == set_compressed || type == set_repeat) {
|
||||||
|
cSymbolTypeSizeEstimateInBits = ZSTD_fseBitCost(fseCTable, countWksp, max);
|
||||||
|
}
|
||||||
|
if (ZSTD_isError(cSymbolTypeSizeEstimateInBits)) return nbSeq * 10;
|
||||||
|
while (ctp < ctEnd) {
|
||||||
|
if (additionalBits) cSymbolTypeSizeEstimateInBits += additionalBits[*ctp];
|
||||||
|
else cSymbolTypeSizeEstimateInBits += *ctp; /* for offset, offset code is also the number of additional bits */
|
||||||
|
ctp++;
|
||||||
|
}
|
||||||
|
return cSymbolTypeSizeEstimateInBits / 8;
|
||||||
|
}
|
||||||
|
|
||||||
|
static size_t ZSTD_estimateSubBlockSize_sequences(const BYTE* ofCodeTable,
|
||||||
|
const BYTE* llCodeTable,
|
||||||
|
const BYTE* mlCodeTable,
|
||||||
|
size_t nbSeq,
|
||||||
|
const ZSTD_fseCTables_t* fseTables,
|
||||||
|
const ZSTD_fseCTablesMetadata_t* fseMetadata,
|
||||||
|
void* workspace, size_t wkspSize,
|
||||||
|
int writeEntropy)
|
||||||
|
{
|
||||||
|
size_t const sequencesSectionHeaderSize = 3; /* Use hard coded size of 3 bytes */
|
||||||
|
size_t cSeqSizeEstimate = 0;
|
||||||
|
if (nbSeq == 0) return sequencesSectionHeaderSize;
|
||||||
|
cSeqSizeEstimate += ZSTD_estimateSubBlockSize_symbolType(fseMetadata->ofType, ofCodeTable, MaxOff,
|
||||||
|
nbSeq, fseTables->offcodeCTable, NULL,
|
||||||
|
OF_defaultNorm, OF_defaultNormLog, DefaultMaxOff,
|
||||||
|
workspace, wkspSize);
|
||||||
|
cSeqSizeEstimate += ZSTD_estimateSubBlockSize_symbolType(fseMetadata->llType, llCodeTable, MaxLL,
|
||||||
|
nbSeq, fseTables->litlengthCTable, LL_bits,
|
||||||
|
LL_defaultNorm, LL_defaultNormLog, MaxLL,
|
||||||
|
workspace, wkspSize);
|
||||||
|
cSeqSizeEstimate += ZSTD_estimateSubBlockSize_symbolType(fseMetadata->mlType, mlCodeTable, MaxML,
|
||||||
|
nbSeq, fseTables->matchlengthCTable, ML_bits,
|
||||||
|
ML_defaultNorm, ML_defaultNormLog, MaxML,
|
||||||
|
workspace, wkspSize);
|
||||||
|
if (writeEntropy) cSeqSizeEstimate += fseMetadata->fseTablesSize;
|
||||||
|
return cSeqSizeEstimate + sequencesSectionHeaderSize;
|
||||||
|
}
|
||||||
|
|
||||||
|
static size_t ZSTD_estimateSubBlockSize(const BYTE* literals, size_t litSize,
|
||||||
|
const BYTE* ofCodeTable,
|
||||||
|
const BYTE* llCodeTable,
|
||||||
|
const BYTE* mlCodeTable,
|
||||||
|
size_t nbSeq,
|
||||||
|
const ZSTD_entropyCTables_t* entropy,
|
||||||
|
const ZSTD_entropyCTablesMetadata_t* entropyMetadata,
|
||||||
|
void* workspace, size_t wkspSize,
|
||||||
|
int writeLitEntropy, int writeSeqEntropy) {
|
||||||
|
size_t cSizeEstimate = 0;
|
||||||
|
cSizeEstimate += ZSTD_estimateSubBlockSize_literal(literals, litSize,
|
||||||
|
&entropy->huf, &entropyMetadata->hufMetadata,
|
||||||
|
workspace, wkspSize, writeLitEntropy);
|
||||||
|
cSizeEstimate += ZSTD_estimateSubBlockSize_sequences(ofCodeTable, llCodeTable, mlCodeTable,
|
||||||
|
nbSeq, &entropy->fse, &entropyMetadata->fseMetadata,
|
||||||
|
workspace, wkspSize, writeSeqEntropy);
|
||||||
|
return cSizeEstimate + ZSTD_blockHeaderSize;
|
||||||
|
}
|
||||||
|
|
||||||
|
static int ZSTD_needSequenceEntropyTables(ZSTD_fseCTablesMetadata_t const* fseMetadata)
|
||||||
|
{
|
||||||
|
if (fseMetadata->llType == set_compressed || fseMetadata->llType == set_rle)
|
||||||
|
return 1;
|
||||||
|
if (fseMetadata->mlType == set_compressed || fseMetadata->mlType == set_rle)
|
||||||
|
return 1;
|
||||||
|
if (fseMetadata->ofType == set_compressed || fseMetadata->ofType == set_rle)
|
||||||
|
return 1;
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
/** ZSTD_compressSubBlock_multi() :
|
||||||
|
* Breaks super-block into multiple sub-blocks and compresses them.
|
||||||
|
* Entropy will be written to the first block.
|
||||||
|
* The following blocks will use repeat mode to compress.
|
||||||
|
* All sub-blocks are compressed blocks (no raw or rle blocks).
|
||||||
|
* @return : compressed size of the super block (which is multiple ZSTD blocks)
|
||||||
|
* Or 0 if it failed to compress. */
|
||||||
|
static size_t ZSTD_compressSubBlock_multi(const seqStore_t* seqStorePtr,
|
||||||
|
const ZSTD_compressedBlockState_t* prevCBlock,
|
||||||
|
ZSTD_compressedBlockState_t* nextCBlock,
|
||||||
|
const ZSTD_entropyCTablesMetadata_t* entropyMetadata,
|
||||||
|
const ZSTD_CCtx_params* cctxParams,
|
||||||
|
void* dst, size_t dstCapacity,
|
||||||
|
const void* src, size_t srcSize,
|
||||||
|
const int bmi2, U32 lastBlock,
|
||||||
|
void* workspace, size_t wkspSize)
|
||||||
|
{
|
||||||
|
const seqDef* const sstart = seqStorePtr->sequencesStart;
|
||||||
|
const seqDef* const send = seqStorePtr->sequences;
|
||||||
|
const seqDef* sp = sstart;
|
||||||
|
const BYTE* const lstart = seqStorePtr->litStart;
|
||||||
|
const BYTE* const lend = seqStorePtr->lit;
|
||||||
|
const BYTE* lp = lstart;
|
||||||
|
BYTE const* ip = (BYTE const*)src;
|
||||||
|
BYTE const* const iend = ip + srcSize;
|
||||||
|
BYTE* const ostart = (BYTE*)dst;
|
||||||
|
BYTE* const oend = ostart + dstCapacity;
|
||||||
|
BYTE* op = ostart;
|
||||||
|
const BYTE* llCodePtr = seqStorePtr->llCode;
|
||||||
|
const BYTE* mlCodePtr = seqStorePtr->mlCode;
|
||||||
|
const BYTE* ofCodePtr = seqStorePtr->ofCode;
|
||||||
|
size_t targetCBlockSize = cctxParams->targetCBlockSize;
|
||||||
|
size_t litSize, seqCount;
|
||||||
|
int writeLitEntropy = entropyMetadata->hufMetadata.hType == set_compressed;
|
||||||
|
int writeSeqEntropy = 1;
|
||||||
|
int lastSequence = 0;
|
||||||
|
|
||||||
|
DEBUGLOG(5, "ZSTD_compressSubBlock_multi (litSize=%u, nbSeq=%u)",
|
||||||
|
(unsigned)(lend-lp), (unsigned)(send-sstart));
|
||||||
|
|
||||||
|
litSize = 0;
|
||||||
|
seqCount = 0;
|
||||||
|
do {
|
||||||
|
size_t cBlockSizeEstimate = 0;
|
||||||
|
if (sstart == send) {
|
||||||
|
lastSequence = 1;
|
||||||
|
} else {
|
||||||
|
const seqDef* const sequence = sp + seqCount;
|
||||||
|
lastSequence = sequence == send - 1;
|
||||||
|
litSize += ZSTD_getSequenceLength(seqStorePtr, sequence).litLength;
|
||||||
|
seqCount++;
|
||||||
|
}
|
||||||
|
if (lastSequence) {
|
||||||
|
assert(lp <= lend);
|
||||||
|
assert(litSize <= (size_t)(lend - lp));
|
||||||
|
litSize = (size_t)(lend - lp);
|
||||||
|
}
|
||||||
|
/* I think there is an optimization opportunity here.
|
||||||
|
* Calling ZSTD_estimateSubBlockSize for every sequence can be wasteful
|
||||||
|
* since it recalculates estimate from scratch.
|
||||||
|
* For example, it would recount literal distribution and symbol codes every time.
|
||||||
|
*/
|
||||||
|
cBlockSizeEstimate = ZSTD_estimateSubBlockSize(lp, litSize, ofCodePtr, llCodePtr, mlCodePtr, seqCount,
|
||||||
|
&nextCBlock->entropy, entropyMetadata,
|
||||||
|
workspace, wkspSize, writeLitEntropy, writeSeqEntropy);
|
||||||
|
if (cBlockSizeEstimate > targetCBlockSize || lastSequence) {
|
||||||
|
int litEntropyWritten = 0;
|
||||||
|
int seqEntropyWritten = 0;
|
||||||
|
const size_t decompressedSize = ZSTD_seqDecompressedSize(seqStorePtr, sp, seqCount, litSize, lastSequence);
|
||||||
|
const size_t cSize = ZSTD_compressSubBlock(&nextCBlock->entropy, entropyMetadata,
|
||||||
|
sp, seqCount,
|
||||||
|
lp, litSize,
|
||||||
|
llCodePtr, mlCodePtr, ofCodePtr,
|
||||||
|
cctxParams,
|
||||||
|
op, oend-op,
|
||||||
|
bmi2, writeLitEntropy, writeSeqEntropy,
|
||||||
|
&litEntropyWritten, &seqEntropyWritten,
|
||||||
|
lastBlock && lastSequence);
|
||||||
|
FORWARD_IF_ERROR(cSize, "ZSTD_compressSubBlock failed");
|
||||||
|
if (cSize > 0 && cSize < decompressedSize) {
|
||||||
|
DEBUGLOG(5, "Committed the sub-block");
|
||||||
|
assert(ip + decompressedSize <= iend);
|
||||||
|
ip += decompressedSize;
|
||||||
|
sp += seqCount;
|
||||||
|
lp += litSize;
|
||||||
|
op += cSize;
|
||||||
|
llCodePtr += seqCount;
|
||||||
|
mlCodePtr += seqCount;
|
||||||
|
ofCodePtr += seqCount;
|
||||||
|
litSize = 0;
|
||||||
|
seqCount = 0;
|
||||||
|
/* Entropy only needs to be written once */
|
||||||
|
if (litEntropyWritten) {
|
||||||
|
writeLitEntropy = 0;
|
||||||
|
}
|
||||||
|
if (seqEntropyWritten) {
|
||||||
|
writeSeqEntropy = 0;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} while (!lastSequence);
|
||||||
|
if (writeLitEntropy) {
|
||||||
|
DEBUGLOG(5, "ZSTD_compressSubBlock_multi has literal entropy tables unwritten");
|
||||||
|
ZSTD_memcpy(&nextCBlock->entropy.huf, &prevCBlock->entropy.huf, sizeof(prevCBlock->entropy.huf));
|
||||||
|
}
|
||||||
|
if (writeSeqEntropy && ZSTD_needSequenceEntropyTables(&entropyMetadata->fseMetadata)) {
|
||||||
|
/* If we haven't written our entropy tables, then we've violated our contract and
|
||||||
|
* must emit an uncompressed block.
|
||||||
|
*/
|
||||||
|
DEBUGLOG(5, "ZSTD_compressSubBlock_multi has sequence entropy tables unwritten");
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
if (ip < iend) {
|
||||||
|
size_t const cSize = ZSTD_noCompressBlock(op, oend - op, ip, iend - ip, lastBlock);
|
||||||
|
DEBUGLOG(5, "ZSTD_compressSubBlock_multi last sub-block uncompressed, %zu bytes", (size_t)(iend - ip));
|
||||||
|
FORWARD_IF_ERROR(cSize, "ZSTD_noCompressBlock failed");
|
||||||
|
assert(cSize != 0);
|
||||||
|
op += cSize;
|
||||||
|
/* We have to regenerate the repcodes because we've skipped some sequences */
|
||||||
|
if (sp < send) {
|
||||||
|
seqDef const* seq;
|
||||||
|
repcodes_t rep;
|
||||||
|
ZSTD_memcpy(&rep, prevCBlock->rep, sizeof(rep));
|
||||||
|
for (seq = sstart; seq < sp; ++seq) {
|
||||||
|
ZSTD_updateRep(rep.rep, seq->offBase, ZSTD_getSequenceLength(seqStorePtr, seq).litLength == 0);
|
||||||
|
}
|
||||||
|
ZSTD_memcpy(nextCBlock->rep, &rep, sizeof(rep));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
DEBUGLOG(5, "ZSTD_compressSubBlock_multi compressed");
|
||||||
|
return op-ostart;
|
||||||
|
}
|
||||||
|
|
||||||
|
size_t ZSTD_compressSuperBlock(ZSTD_CCtx* zc,
|
||||||
|
void* dst, size_t dstCapacity,
|
||||||
|
void const* src, size_t srcSize,
|
||||||
|
unsigned lastBlock) {
|
||||||
|
ZSTD_entropyCTablesMetadata_t entropyMetadata;
|
||||||
|
|
||||||
|
FORWARD_IF_ERROR(ZSTD_buildBlockEntropyStats(&zc->seqStore,
|
||||||
|
&zc->blockState.prevCBlock->entropy,
|
||||||
|
&zc->blockState.nextCBlock->entropy,
|
||||||
|
&zc->appliedParams,
|
||||||
|
&entropyMetadata,
|
||||||
|
zc->entropyWorkspace, ENTROPY_WORKSPACE_SIZE /* statically allocated in resetCCtx */), "");
|
||||||
|
|
||||||
|
return ZSTD_compressSubBlock_multi(&zc->seqStore,
|
||||||
|
zc->blockState.prevCBlock,
|
||||||
|
zc->blockState.nextCBlock,
|
||||||
|
&entropyMetadata,
|
||||||
|
&zc->appliedParams,
|
||||||
|
dst, dstCapacity,
|
||||||
|
src, srcSize,
|
||||||
|
zc->bmi2, lastBlock,
|
||||||
|
zc->entropyWorkspace, ENTROPY_WORKSPACE_SIZE /* statically allocated in resetCCtx */);
|
||||||
|
}
|
||||||
|
|
||||||
|
#endif /* USE_EXTERNAL_ZSTD */
|
||||||
35
vendor/github.com/DataDog/zstd/zstd_compress_superblock.h
generated
vendored
Normal file
35
vendor/github.com/DataDog/zstd/zstd_compress_superblock.h
generated
vendored
Normal file
@@ -0,0 +1,35 @@
|
|||||||
|
#ifndef USE_EXTERNAL_ZSTD
|
||||||
|
/*
|
||||||
|
* Copyright (c) Meta Platforms, Inc. and affiliates.
|
||||||
|
* All rights reserved.
|
||||||
|
*
|
||||||
|
* This source code is licensed under both the BSD-style license (found in the
|
||||||
|
* LICENSE file in the root directory of this source tree) and the GPLv2 (found
|
||||||
|
* in the COPYING file in the root directory of this source tree).
|
||||||
|
* You may select, at your option, one of the above-listed licenses.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#ifndef ZSTD_COMPRESS_ADVANCED_H
|
||||||
|
#define ZSTD_COMPRESS_ADVANCED_H
|
||||||
|
|
||||||
|
/*-*************************************
|
||||||
|
* Dependencies
|
||||||
|
***************************************/
|
||||||
|
|
||||||
|
#include "zstd.h" /* ZSTD_CCtx */
|
||||||
|
|
||||||
|
/*-*************************************
|
||||||
|
* Target Compressed Block Size
|
||||||
|
***************************************/
|
||||||
|
|
||||||
|
/* ZSTD_compressSuperBlock() :
|
||||||
|
* Used to compress a super block when targetCBlockSize is being used.
|
||||||
|
* The given block will be compressed into multiple sub blocks that are around targetCBlockSize. */
|
||||||
|
size_t ZSTD_compressSuperBlock(ZSTD_CCtx* zc,
|
||||||
|
void* dst, size_t dstCapacity,
|
||||||
|
void const* src, size_t srcSize,
|
||||||
|
unsigned lastBlock);
|
||||||
|
|
||||||
|
#endif /* ZSTD_COMPRESS_ADVANCED_H */
|
||||||
|
|
||||||
|
#endif /* USE_EXTERNAL_ZSTD */
|
||||||
131
vendor/github.com/DataDog/zstd/zstd_ctx.go
generated
vendored
Normal file
131
vendor/github.com/DataDog/zstd/zstd_ctx.go
generated
vendored
Normal file
@@ -0,0 +1,131 @@
|
|||||||
|
package zstd
|
||||||
|
|
||||||
|
/*
|
||||||
|
#include "zstd.h"
|
||||||
|
*/
|
||||||
|
import "C"
|
||||||
|
import (
|
||||||
|
"bytes"
|
||||||
|
"io/ioutil"
|
||||||
|
"runtime"
|
||||||
|
"unsafe"
|
||||||
|
)
|
||||||
|
|
||||||
|
type Ctx interface {
|
||||||
|
// Compress src into dst. If you have a buffer to use, you can pass it to
|
||||||
|
// prevent allocation. If it is too small, or if nil is passed, a new buffer
|
||||||
|
// will be allocated and returned.
|
||||||
|
Compress(dst, src []byte) ([]byte, error)
|
||||||
|
|
||||||
|
// CompressLevel is the same as Compress but you can pass a compression level
|
||||||
|
CompressLevel(dst, src []byte, level int) ([]byte, error)
|
||||||
|
|
||||||
|
// Decompress src into dst. If you have a buffer to use, you can pass it to
|
||||||
|
// prevent allocation. If it is too small, or if nil is passed, a new buffer
|
||||||
|
// will be allocated and returned.
|
||||||
|
Decompress(dst, src []byte) ([]byte, error)
|
||||||
|
}
|
||||||
|
|
||||||
|
type ctx struct {
|
||||||
|
cctx *C.ZSTD_CCtx
|
||||||
|
dctx *C.ZSTD_DCtx
|
||||||
|
}
|
||||||
|
|
||||||
|
// Create a new ZStd Context.
|
||||||
|
// When compressing/decompressing many times, it is recommended to allocate a
|
||||||
|
// context just once, and re-use it for each successive compression operation.
|
||||||
|
// This will make workload friendlier for system's memory.
|
||||||
|
// Note : re-using context is just a speed / resource optimization.
|
||||||
|
// It doesn't change the compression ratio, which remains identical.
|
||||||
|
// Note 2 : In multi-threaded environments,
|
||||||
|
// use one different context per thread for parallel execution.
|
||||||
|
//
|
||||||
|
func NewCtx() Ctx {
|
||||||
|
c := &ctx{
|
||||||
|
cctx: C.ZSTD_createCCtx(),
|
||||||
|
dctx: C.ZSTD_createDCtx(),
|
||||||
|
}
|
||||||
|
|
||||||
|
runtime.SetFinalizer(c, finalizeCtx)
|
||||||
|
return c
|
||||||
|
}
|
||||||
|
|
||||||
|
func (c *ctx) Compress(dst, src []byte) ([]byte, error) {
|
||||||
|
return c.CompressLevel(dst, src, DefaultCompression)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (c *ctx) CompressLevel(dst, src []byte, level int) ([]byte, error) {
|
||||||
|
bound := CompressBound(len(src))
|
||||||
|
if cap(dst) >= bound {
|
||||||
|
dst = dst[0:bound] // Reuse dst buffer
|
||||||
|
} else {
|
||||||
|
dst = make([]byte, bound)
|
||||||
|
}
|
||||||
|
|
||||||
|
// We need unsafe.Pointer(&src[0]) in the Cgo call to avoid "Go pointer to Go pointer" panics.
|
||||||
|
// This means we need to special case empty input. See:
|
||||||
|
// https://github.com/golang/go/issues/14210#issuecomment-346402945
|
||||||
|
var cWritten C.size_t
|
||||||
|
if len(src) == 0 {
|
||||||
|
cWritten = C.ZSTD_compressCCtx(
|
||||||
|
c.cctx,
|
||||||
|
unsafe.Pointer(&dst[0]),
|
||||||
|
C.size_t(len(dst)),
|
||||||
|
unsafe.Pointer(nil),
|
||||||
|
C.size_t(0),
|
||||||
|
C.int(level))
|
||||||
|
} else {
|
||||||
|
cWritten = C.ZSTD_compressCCtx(
|
||||||
|
c.cctx,
|
||||||
|
unsafe.Pointer(&dst[0]),
|
||||||
|
C.size_t(len(dst)),
|
||||||
|
unsafe.Pointer(&src[0]),
|
||||||
|
C.size_t(len(src)),
|
||||||
|
C.int(level))
|
||||||
|
}
|
||||||
|
|
||||||
|
written := int(cWritten)
|
||||||
|
// Check if the return is an Error code
|
||||||
|
if err := getError(written); err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
return dst[:written], nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func (c *ctx) Decompress(dst, src []byte) ([]byte, error) {
|
||||||
|
if len(src) == 0 {
|
||||||
|
return []byte{}, ErrEmptySlice
|
||||||
|
}
|
||||||
|
|
||||||
|
bound := decompressSizeHint(src)
|
||||||
|
if cap(dst) >= bound {
|
||||||
|
dst = dst[0:cap(dst)]
|
||||||
|
} else {
|
||||||
|
dst = make([]byte, bound)
|
||||||
|
}
|
||||||
|
|
||||||
|
written := int(C.ZSTD_decompressDCtx(
|
||||||
|
c.dctx,
|
||||||
|
unsafe.Pointer(&dst[0]),
|
||||||
|
C.size_t(len(dst)),
|
||||||
|
unsafe.Pointer(&src[0]),
|
||||||
|
C.size_t(len(src))))
|
||||||
|
|
||||||
|
err := getError(written)
|
||||||
|
if err == nil {
|
||||||
|
return dst[:written], nil
|
||||||
|
}
|
||||||
|
if !IsDstSizeTooSmallError(err) {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
|
||||||
|
// We failed getting a dst buffer of correct size, use stream API
|
||||||
|
r := NewReader(bytes.NewReader(src))
|
||||||
|
defer r.Close()
|
||||||
|
return ioutil.ReadAll(r)
|
||||||
|
}
|
||||||
|
|
||||||
|
func finalizeCtx(c *ctx) {
|
||||||
|
C.ZSTD_freeCCtx(c.cctx)
|
||||||
|
C.ZSTD_freeDCtx(c.dctx)
|
||||||
|
}
|
||||||
428
vendor/github.com/DataDog/zstd/zstd_cwksp.h
generated
vendored
428
vendor/github.com/DataDog/zstd/zstd_cwksp.h
generated
vendored
@@ -1,5 +1,6 @@
|
|||||||
|
#ifndef USE_EXTERNAL_ZSTD
|
||||||
/*
|
/*
|
||||||
* Copyright (c) 2016-present, Yann Collet, Facebook, Inc.
|
* Copyright (c) Meta Platforms, Inc. and affiliates.
|
||||||
* All rights reserved.
|
* All rights reserved.
|
||||||
*
|
*
|
||||||
* This source code is licensed under both the BSD-style license (found in the
|
* This source code is licensed under both the BSD-style license (found in the
|
||||||
@@ -14,7 +15,9 @@
|
|||||||
/*-*************************************
|
/*-*************************************
|
||||||
* Dependencies
|
* Dependencies
|
||||||
***************************************/
|
***************************************/
|
||||||
|
#include "allocations.h" /* ZSTD_customMalloc, ZSTD_customFree */
|
||||||
#include "zstd_internal.h"
|
#include "zstd_internal.h"
|
||||||
|
#include "portability_macros.h"
|
||||||
|
|
||||||
#if defined (__cplusplus)
|
#if defined (__cplusplus)
|
||||||
extern "C" {
|
extern "C" {
|
||||||
@@ -24,16 +27,6 @@ extern "C" {
|
|||||||
* Constants
|
* Constants
|
||||||
***************************************/
|
***************************************/
|
||||||
|
|
||||||
/* define "workspace is too large" as this number of times larger than needed */
|
|
||||||
#define ZSTD_WORKSPACETOOLARGE_FACTOR 3
|
|
||||||
|
|
||||||
/* when workspace is continuously too large
|
|
||||||
* during at least this number of times,
|
|
||||||
* context's memory usage is considered wasteful,
|
|
||||||
* because it's sized to handle a worst case scenario which rarely happens.
|
|
||||||
* In which case, resize it down to free some memory */
|
|
||||||
#define ZSTD_WORKSPACETOOLARGE_MAXDURATION 128
|
|
||||||
|
|
||||||
/* Since the workspace is effectively its own little malloc implementation /
|
/* Since the workspace is effectively its own little malloc implementation /
|
||||||
* arena, when we run under ASAN, we should similarly insert redzones between
|
* arena, when we run under ASAN, we should similarly insert redzones between
|
||||||
* each internal element of the workspace, so ASAN will catch overruns that
|
* each internal element of the workspace, so ASAN will catch overruns that
|
||||||
@@ -45,15 +38,30 @@ extern "C" {
|
|||||||
#define ZSTD_CWKSP_ASAN_REDZONE_SIZE 128
|
#define ZSTD_CWKSP_ASAN_REDZONE_SIZE 128
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
|
||||||
|
/* Set our tables and aligneds to align by 64 bytes */
|
||||||
|
#define ZSTD_CWKSP_ALIGNMENT_BYTES 64
|
||||||
|
|
||||||
/*-*************************************
|
/*-*************************************
|
||||||
* Structures
|
* Structures
|
||||||
***************************************/
|
***************************************/
|
||||||
typedef enum {
|
typedef enum {
|
||||||
ZSTD_cwksp_alloc_objects,
|
ZSTD_cwksp_alloc_objects,
|
||||||
ZSTD_cwksp_alloc_buffers,
|
ZSTD_cwksp_alloc_aligned_init_once,
|
||||||
ZSTD_cwksp_alloc_aligned
|
ZSTD_cwksp_alloc_aligned,
|
||||||
|
ZSTD_cwksp_alloc_buffers
|
||||||
} ZSTD_cwksp_alloc_phase_e;
|
} ZSTD_cwksp_alloc_phase_e;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Used to describe whether the workspace is statically allocated (and will not
|
||||||
|
* necessarily ever be freed), or if it's dynamically allocated and we can
|
||||||
|
* expect a well-formed caller to free this.
|
||||||
|
*/
|
||||||
|
typedef enum {
|
||||||
|
ZSTD_cwksp_dynamic_alloc,
|
||||||
|
ZSTD_cwksp_static_alloc
|
||||||
|
} ZSTD_cwksp_static_alloc_e;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Zstd fits all its internal datastructures into a single continuous buffer,
|
* Zstd fits all its internal datastructures into a single continuous buffer,
|
||||||
* so that it only needs to perform a single OS allocation (or so that a buffer
|
* so that it only needs to perform a single OS allocation (or so that a buffer
|
||||||
@@ -95,14 +103,14 @@ typedef enum {
|
|||||||
* Workspace Layout:
|
* Workspace Layout:
|
||||||
*
|
*
|
||||||
* [ ... workspace ... ]
|
* [ ... workspace ... ]
|
||||||
* [objects][tables ... ->] free space [<- ... aligned][<- ... buffers]
|
* [objects][tables ->] free space [<- buffers][<- aligned][<- init once]
|
||||||
*
|
*
|
||||||
* The various objects that live in the workspace are divided into the
|
* The various objects that live in the workspace are divided into the
|
||||||
* following categories, and are allocated separately:
|
* following categories, and are allocated separately:
|
||||||
*
|
*
|
||||||
* - Static objects: this is optionally the enclosing ZSTD_CCtx or ZSTD_CDict,
|
* - Static objects: this is optionally the enclosing ZSTD_CCtx or ZSTD_CDict,
|
||||||
* so that literally everything fits in a single buffer. Note: if present,
|
* so that literally everything fits in a single buffer. Note: if present,
|
||||||
* this must be the first object in the workspace, since ZSTD_free{CCtx,
|
* this must be the first object in the workspace, since ZSTD_customFree{CCtx,
|
||||||
* CDict}() rely on a pointer comparison to see whether one or two frees are
|
* CDict}() rely on a pointer comparison to see whether one or two frees are
|
||||||
* required.
|
* required.
|
||||||
*
|
*
|
||||||
@@ -117,10 +125,20 @@ typedef enum {
|
|||||||
* - Tables: these are any of several different datastructures (hash tables,
|
* - Tables: these are any of several different datastructures (hash tables,
|
||||||
* chain tables, binary trees) that all respect a common format: they are
|
* chain tables, binary trees) that all respect a common format: they are
|
||||||
* uint32_t arrays, all of whose values are between 0 and (nextSrc - base).
|
* uint32_t arrays, all of whose values are between 0 and (nextSrc - base).
|
||||||
* Their sizes depend on the cparams.
|
* Their sizes depend on the cparams. These tables are 64-byte aligned.
|
||||||
*
|
*
|
||||||
* - Aligned: these buffers are used for various purposes that require 4 byte
|
* - Init once: these buffers require to be initialized at least once before
|
||||||
* alignment, but don't require any initialization before they're used.
|
* use. They should be used when we want to skip memory initialization
|
||||||
|
* while not triggering memory checkers (like Valgrind) when reading from
|
||||||
|
* from this memory without writing to it first.
|
||||||
|
* These buffers should be used carefully as they might contain data
|
||||||
|
* from previous compressions.
|
||||||
|
* Buffers are aligned to 64 bytes.
|
||||||
|
*
|
||||||
|
* - Aligned: these buffers don't require any initialization before they're
|
||||||
|
* used. The user of the buffer should make sure they write into a buffer
|
||||||
|
* location before reading from it.
|
||||||
|
* Buffers are aligned to 64 bytes.
|
||||||
*
|
*
|
||||||
* - Buffers: these buffers are used for various purposes that don't require
|
* - Buffers: these buffers are used for various purposes that don't require
|
||||||
* any alignment or initialization before they're used. This means they can
|
* any alignment or initialization before they're used. This means they can
|
||||||
@@ -132,9 +150,9 @@ typedef enum {
|
|||||||
* correctly packed into the workspace buffer. That order is:
|
* correctly packed into the workspace buffer. That order is:
|
||||||
*
|
*
|
||||||
* 1. Objects
|
* 1. Objects
|
||||||
* 2. Buffers
|
* 2. Init once / Tables
|
||||||
* 3. Aligned
|
* 3. Aligned / Tables
|
||||||
* 4. Tables
|
* 4. Buffers / Tables
|
||||||
*
|
*
|
||||||
* Attempts to reserve objects of different types out of order will fail.
|
* Attempts to reserve objects of different types out of order will fail.
|
||||||
*/
|
*/
|
||||||
@@ -146,10 +164,12 @@ typedef struct {
|
|||||||
void* tableEnd;
|
void* tableEnd;
|
||||||
void* tableValidEnd;
|
void* tableValidEnd;
|
||||||
void* allocStart;
|
void* allocStart;
|
||||||
|
void* initOnceStart;
|
||||||
|
|
||||||
int allocFailed;
|
BYTE allocFailed;
|
||||||
int workspaceOversizedDuration;
|
int workspaceOversizedDuration;
|
||||||
ZSTD_cwksp_alloc_phase_e phase;
|
ZSTD_cwksp_alloc_phase_e phase;
|
||||||
|
ZSTD_cwksp_static_alloc_e isStatic;
|
||||||
} ZSTD_cwksp;
|
} ZSTD_cwksp;
|
||||||
|
|
||||||
/*-*************************************
|
/*-*************************************
|
||||||
@@ -157,6 +177,7 @@ typedef struct {
|
|||||||
***************************************/
|
***************************************/
|
||||||
|
|
||||||
MEM_STATIC size_t ZSTD_cwksp_available_space(ZSTD_cwksp* ws);
|
MEM_STATIC size_t ZSTD_cwksp_available_space(ZSTD_cwksp* ws);
|
||||||
|
MEM_STATIC void* ZSTD_cwksp_initialAllocStart(ZSTD_cwksp* ws);
|
||||||
|
|
||||||
MEM_STATIC void ZSTD_cwksp_assert_internal_consistency(ZSTD_cwksp* ws) {
|
MEM_STATIC void ZSTD_cwksp_assert_internal_consistency(ZSTD_cwksp* ws) {
|
||||||
(void)ws;
|
(void)ws;
|
||||||
@@ -166,6 +187,20 @@ MEM_STATIC void ZSTD_cwksp_assert_internal_consistency(ZSTD_cwksp* ws) {
|
|||||||
assert(ws->tableEnd <= ws->allocStart);
|
assert(ws->tableEnd <= ws->allocStart);
|
||||||
assert(ws->tableValidEnd <= ws->allocStart);
|
assert(ws->tableValidEnd <= ws->allocStart);
|
||||||
assert(ws->allocStart <= ws->workspaceEnd);
|
assert(ws->allocStart <= ws->workspaceEnd);
|
||||||
|
assert(ws->initOnceStart <= ZSTD_cwksp_initialAllocStart(ws));
|
||||||
|
assert(ws->workspace <= ws->initOnceStart);
|
||||||
|
#if ZSTD_MEMORY_SANITIZER
|
||||||
|
{
|
||||||
|
intptr_t const offset = __msan_test_shadow(ws->initOnceStart,
|
||||||
|
(U8*)ZSTD_cwksp_initialAllocStart(ws) - (U8*)ws->initOnceStart);
|
||||||
|
#if defined(ZSTD_MSAN_PRINT)
|
||||||
|
if(offset!=-1) {
|
||||||
|
__msan_print_shadow((U8*)ws->initOnceStart + offset - 8, 32);
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
assert(offset==-1);
|
||||||
|
};
|
||||||
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -186,63 +221,72 @@ MEM_STATIC size_t ZSTD_cwksp_align(size_t size, size_t const align) {
|
|||||||
* Since tables aren't currently redzoned, you don't need to call through this
|
* Since tables aren't currently redzoned, you don't need to call through this
|
||||||
* to figure out how much space you need for the matchState tables. Everything
|
* to figure out how much space you need for the matchState tables. Everything
|
||||||
* else is though.
|
* else is though.
|
||||||
|
*
|
||||||
|
* Do not use for sizing aligned buffers. Instead, use ZSTD_cwksp_aligned_alloc_size().
|
||||||
*/
|
*/
|
||||||
MEM_STATIC size_t ZSTD_cwksp_alloc_size(size_t size) {
|
MEM_STATIC size_t ZSTD_cwksp_alloc_size(size_t size) {
|
||||||
#if defined (ADDRESS_SANITIZER) && !defined (ZSTD_ASAN_DONT_POISON_WORKSPACE)
|
if (size == 0)
|
||||||
|
return 0;
|
||||||
|
#if ZSTD_ADDRESS_SANITIZER && !defined (ZSTD_ASAN_DONT_POISON_WORKSPACE)
|
||||||
return size + 2 * ZSTD_CWKSP_ASAN_REDZONE_SIZE;
|
return size + 2 * ZSTD_CWKSP_ASAN_REDZONE_SIZE;
|
||||||
#else
|
#else
|
||||||
return size;
|
return size;
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
MEM_STATIC void ZSTD_cwksp_internal_advance_phase(
|
/**
|
||||||
ZSTD_cwksp* ws, ZSTD_cwksp_alloc_phase_e phase) {
|
* Returns an adjusted alloc size that is the nearest larger multiple of 64 bytes.
|
||||||
assert(phase >= ws->phase);
|
* Used to determine the number of bytes required for a given "aligned".
|
||||||
if (phase > ws->phase) {
|
*/
|
||||||
if (ws->phase < ZSTD_cwksp_alloc_buffers &&
|
MEM_STATIC size_t ZSTD_cwksp_aligned_alloc_size(size_t size) {
|
||||||
phase >= ZSTD_cwksp_alloc_buffers) {
|
return ZSTD_cwksp_alloc_size(ZSTD_cwksp_align(size, ZSTD_CWKSP_ALIGNMENT_BYTES));
|
||||||
ws->tableValidEnd = ws->objectEnd;
|
|
||||||
}
|
|
||||||
if (ws->phase < ZSTD_cwksp_alloc_aligned &&
|
|
||||||
phase >= ZSTD_cwksp_alloc_aligned) {
|
|
||||||
/* If unaligned allocations down from a too-large top have left us
|
|
||||||
* unaligned, we need to realign our alloc ptr. Technically, this
|
|
||||||
* can consume space that is unaccounted for in the neededSpace
|
|
||||||
* calculation. However, I believe this can only happen when the
|
|
||||||
* workspace is too large, and specifically when it is too large
|
|
||||||
* by a larger margin than the space that will be consumed. */
|
|
||||||
/* TODO: cleaner, compiler warning friendly way to do this??? */
|
|
||||||
ws->allocStart = (BYTE*)ws->allocStart - ((size_t)ws->allocStart & (sizeof(U32)-1));
|
|
||||||
if (ws->allocStart < ws->tableValidEnd) {
|
|
||||||
ws->tableValidEnd = ws->allocStart;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
ws->phase = phase;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns whether this object/buffer/etc was allocated in this workspace.
|
* Returns the amount of additional space the cwksp must allocate
|
||||||
|
* for internal purposes (currently only alignment).
|
||||||
*/
|
*/
|
||||||
MEM_STATIC int ZSTD_cwksp_owns_buffer(const ZSTD_cwksp* ws, const void* ptr) {
|
MEM_STATIC size_t ZSTD_cwksp_slack_space_required(void) {
|
||||||
return (ptr != NULL) && (ws->workspace <= ptr) && (ptr <= ws->workspaceEnd);
|
/* For alignment, the wksp will always allocate an additional 2*ZSTD_CWKSP_ALIGNMENT_BYTES
|
||||||
|
* bytes to align the beginning of tables section and end of buffers;
|
||||||
|
*/
|
||||||
|
size_t const slackSpace = ZSTD_CWKSP_ALIGNMENT_BYTES * 2;
|
||||||
|
return slackSpace;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Return the number of additional bytes required to align a pointer to the given number of bytes.
|
||||||
|
* alignBytes must be a power of two.
|
||||||
|
*/
|
||||||
|
MEM_STATIC size_t ZSTD_cwksp_bytes_to_align_ptr(void* ptr, const size_t alignBytes) {
|
||||||
|
size_t const alignBytesMask = alignBytes - 1;
|
||||||
|
size_t const bytes = (alignBytes - ((size_t)ptr & (alignBytesMask))) & alignBytesMask;
|
||||||
|
assert((alignBytes & alignBytesMask) == 0);
|
||||||
|
assert(bytes < alignBytes);
|
||||||
|
return bytes;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns the initial value for allocStart which is used to determine the position from
|
||||||
|
* which we can allocate from the end of the workspace.
|
||||||
|
*/
|
||||||
|
MEM_STATIC void* ZSTD_cwksp_initialAllocStart(ZSTD_cwksp* ws) {
|
||||||
|
return (void*)((size_t)ws->workspaceEnd & ~(ZSTD_CWKSP_ALIGNMENT_BYTES-1));
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Internal function. Do not use directly.
|
* Internal function. Do not use directly.
|
||||||
|
* Reserves the given number of bytes within the aligned/buffer segment of the wksp,
|
||||||
|
* which counts from the end of the wksp (as opposed to the object/table segment).
|
||||||
|
*
|
||||||
|
* Returns a pointer to the beginning of that space.
|
||||||
*/
|
*/
|
||||||
MEM_STATIC void* ZSTD_cwksp_reserve_internal(
|
MEM_STATIC void*
|
||||||
ZSTD_cwksp* ws, size_t bytes, ZSTD_cwksp_alloc_phase_e phase) {
|
ZSTD_cwksp_reserve_internal_buffer_space(ZSTD_cwksp* ws, size_t const bytes)
|
||||||
void* alloc;
|
{
|
||||||
void* bottom = ws->tableEnd;
|
void* const alloc = (BYTE*)ws->allocStart - bytes;
|
||||||
ZSTD_cwksp_internal_advance_phase(ws, phase);
|
void* const bottom = ws->tableEnd;
|
||||||
alloc = (BYTE *)ws->allocStart - bytes;
|
|
||||||
|
|
||||||
#if defined (ADDRESS_SANITIZER) && !defined (ZSTD_ASAN_DONT_POISON_WORKSPACE)
|
|
||||||
/* over-reserve space */
|
|
||||||
alloc = (BYTE *)alloc - 2 * ZSTD_CWKSP_ASAN_REDZONE_SIZE;
|
|
||||||
#endif
|
|
||||||
|
|
||||||
DEBUGLOG(5, "cwksp: reserving %p %zd bytes, %zd bytes remaining",
|
DEBUGLOG(5, "cwksp: reserving %p %zd bytes, %zd bytes remaining",
|
||||||
alloc, bytes, ZSTD_cwksp_available_space(ws) - bytes);
|
alloc, bytes, ZSTD_cwksp_available_space(ws) - bytes);
|
||||||
ZSTD_cwksp_assert_internal_consistency(ws);
|
ZSTD_cwksp_assert_internal_consistency(ws);
|
||||||
@@ -252,16 +296,88 @@ MEM_STATIC void* ZSTD_cwksp_reserve_internal(
|
|||||||
ws->allocFailed = 1;
|
ws->allocFailed = 1;
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
/* the area is reserved from the end of wksp.
|
||||||
|
* If it overlaps with tableValidEnd, it voids guarantees on values' range */
|
||||||
if (alloc < ws->tableValidEnd) {
|
if (alloc < ws->tableValidEnd) {
|
||||||
ws->tableValidEnd = alloc;
|
ws->tableValidEnd = alloc;
|
||||||
}
|
}
|
||||||
ws->allocStart = alloc;
|
ws->allocStart = alloc;
|
||||||
|
return alloc;
|
||||||
|
}
|
||||||
|
|
||||||
#if defined (ADDRESS_SANITIZER) && !defined (ZSTD_ASAN_DONT_POISON_WORKSPACE)
|
/**
|
||||||
|
* Moves the cwksp to the next phase, and does any necessary allocations.
|
||||||
|
* cwksp initialization must necessarily go through each phase in order.
|
||||||
|
* Returns a 0 on success, or zstd error
|
||||||
|
*/
|
||||||
|
MEM_STATIC size_t
|
||||||
|
ZSTD_cwksp_internal_advance_phase(ZSTD_cwksp* ws, ZSTD_cwksp_alloc_phase_e phase)
|
||||||
|
{
|
||||||
|
assert(phase >= ws->phase);
|
||||||
|
if (phase > ws->phase) {
|
||||||
|
/* Going from allocating objects to allocating initOnce / tables */
|
||||||
|
if (ws->phase < ZSTD_cwksp_alloc_aligned_init_once &&
|
||||||
|
phase >= ZSTD_cwksp_alloc_aligned_init_once) {
|
||||||
|
ws->tableValidEnd = ws->objectEnd;
|
||||||
|
ws->initOnceStart = ZSTD_cwksp_initialAllocStart(ws);
|
||||||
|
|
||||||
|
{ /* Align the start of the tables to 64 bytes. Use [0, 63] bytes */
|
||||||
|
void *const alloc = ws->objectEnd;
|
||||||
|
size_t const bytesToAlign = ZSTD_cwksp_bytes_to_align_ptr(alloc, ZSTD_CWKSP_ALIGNMENT_BYTES);
|
||||||
|
void *const objectEnd = (BYTE *) alloc + bytesToAlign;
|
||||||
|
DEBUGLOG(5, "reserving table alignment addtl space: %zu", bytesToAlign);
|
||||||
|
RETURN_ERROR_IF(objectEnd > ws->workspaceEnd, memory_allocation,
|
||||||
|
"table phase - alignment initial allocation failed!");
|
||||||
|
ws->objectEnd = objectEnd;
|
||||||
|
ws->tableEnd = objectEnd; /* table area starts being empty */
|
||||||
|
if (ws->tableValidEnd < ws->tableEnd) {
|
||||||
|
ws->tableValidEnd = ws->tableEnd;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
ws->phase = phase;
|
||||||
|
ZSTD_cwksp_assert_internal_consistency(ws);
|
||||||
|
}
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns whether this object/buffer/etc was allocated in this workspace.
|
||||||
|
*/
|
||||||
|
MEM_STATIC int ZSTD_cwksp_owns_buffer(const ZSTD_cwksp* ws, const void* ptr)
|
||||||
|
{
|
||||||
|
return (ptr != NULL) && (ws->workspace <= ptr) && (ptr < ws->workspaceEnd);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Internal function. Do not use directly.
|
||||||
|
*/
|
||||||
|
MEM_STATIC void*
|
||||||
|
ZSTD_cwksp_reserve_internal(ZSTD_cwksp* ws, size_t bytes, ZSTD_cwksp_alloc_phase_e phase)
|
||||||
|
{
|
||||||
|
void* alloc;
|
||||||
|
if (ZSTD_isError(ZSTD_cwksp_internal_advance_phase(ws, phase)) || bytes == 0) {
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
|
||||||
|
#if ZSTD_ADDRESS_SANITIZER && !defined (ZSTD_ASAN_DONT_POISON_WORKSPACE)
|
||||||
|
/* over-reserve space */
|
||||||
|
bytes += 2 * ZSTD_CWKSP_ASAN_REDZONE_SIZE;
|
||||||
|
#endif
|
||||||
|
|
||||||
|
alloc = ZSTD_cwksp_reserve_internal_buffer_space(ws, bytes);
|
||||||
|
|
||||||
|
#if ZSTD_ADDRESS_SANITIZER && !defined (ZSTD_ASAN_DONT_POISON_WORKSPACE)
|
||||||
/* Move alloc so there's ZSTD_CWKSP_ASAN_REDZONE_SIZE unused space on
|
/* Move alloc so there's ZSTD_CWKSP_ASAN_REDZONE_SIZE unused space on
|
||||||
* either size. */
|
* either size. */
|
||||||
|
if (alloc) {
|
||||||
alloc = (BYTE *)alloc + ZSTD_CWKSP_ASAN_REDZONE_SIZE;
|
alloc = (BYTE *)alloc + ZSTD_CWKSP_ASAN_REDZONE_SIZE;
|
||||||
__asan_unpoison_memory_region(alloc, bytes);
|
if (ws->isStatic == ZSTD_cwksp_dynamic_alloc) {
|
||||||
|
/* We need to keep the redzone poisoned while unpoisoning the bytes that
|
||||||
|
* are actually allocated. */
|
||||||
|
__asan_unpoison_memory_region(alloc, bytes - 2 * ZSTD_CWKSP_ASAN_REDZONE_SIZE);
|
||||||
|
}
|
||||||
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
return alloc;
|
return alloc;
|
||||||
@@ -270,33 +386,78 @@ MEM_STATIC void* ZSTD_cwksp_reserve_internal(
|
|||||||
/**
|
/**
|
||||||
* Reserves and returns unaligned memory.
|
* Reserves and returns unaligned memory.
|
||||||
*/
|
*/
|
||||||
MEM_STATIC BYTE* ZSTD_cwksp_reserve_buffer(ZSTD_cwksp* ws, size_t bytes) {
|
MEM_STATIC BYTE* ZSTD_cwksp_reserve_buffer(ZSTD_cwksp* ws, size_t bytes)
|
||||||
|
{
|
||||||
return (BYTE*)ZSTD_cwksp_reserve_internal(ws, bytes, ZSTD_cwksp_alloc_buffers);
|
return (BYTE*)ZSTD_cwksp_reserve_internal(ws, bytes, ZSTD_cwksp_alloc_buffers);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Reserves and returns memory sized on and aligned on sizeof(unsigned).
|
* Reserves and returns memory sized on and aligned on ZSTD_CWKSP_ALIGNMENT_BYTES (64 bytes).
|
||||||
|
* This memory has been initialized at least once in the past.
|
||||||
|
* This doesn't mean it has been initialized this time, and it might contain data from previous
|
||||||
|
* operations.
|
||||||
|
* The main usage is for algorithms that might need read access into uninitialized memory.
|
||||||
|
* The algorithm must maintain safety under these conditions and must make sure it doesn't
|
||||||
|
* leak any of the past data (directly or in side channels).
|
||||||
*/
|
*/
|
||||||
MEM_STATIC void* ZSTD_cwksp_reserve_aligned(ZSTD_cwksp* ws, size_t bytes) {
|
MEM_STATIC void* ZSTD_cwksp_reserve_aligned_init_once(ZSTD_cwksp* ws, size_t bytes)
|
||||||
assert((bytes & (sizeof(U32)-1)) == 0);
|
{
|
||||||
return ZSTD_cwksp_reserve_internal(ws, ZSTD_cwksp_align(bytes, sizeof(U32)), ZSTD_cwksp_alloc_aligned);
|
size_t const alignedBytes = ZSTD_cwksp_align(bytes, ZSTD_CWKSP_ALIGNMENT_BYTES);
|
||||||
|
void* ptr = ZSTD_cwksp_reserve_internal(ws, alignedBytes, ZSTD_cwksp_alloc_aligned_init_once);
|
||||||
|
assert(((size_t)ptr & (ZSTD_CWKSP_ALIGNMENT_BYTES-1))== 0);
|
||||||
|
if(ptr && ptr < ws->initOnceStart) {
|
||||||
|
/* We assume the memory following the current allocation is either:
|
||||||
|
* 1. Not usable as initOnce memory (end of workspace)
|
||||||
|
* 2. Another initOnce buffer that has been allocated before (and so was previously memset)
|
||||||
|
* 3. An ASAN redzone, in which case we don't want to write on it
|
||||||
|
* For these reasons it should be fine to not explicitly zero every byte up to ws->initOnceStart.
|
||||||
|
* Note that we assume here that MSAN and ASAN cannot run in the same time. */
|
||||||
|
ZSTD_memset(ptr, 0, MIN((size_t)((U8*)ws->initOnceStart - (U8*)ptr), alignedBytes));
|
||||||
|
ws->initOnceStart = ptr;
|
||||||
|
}
|
||||||
|
#if ZSTD_MEMORY_SANITIZER
|
||||||
|
assert(__msan_test_shadow(ptr, bytes) == -1);
|
||||||
|
#endif
|
||||||
|
return ptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Aligned on sizeof(unsigned). These buffers have the special property that
|
* Reserves and returns memory sized on and aligned on ZSTD_CWKSP_ALIGNMENT_BYTES (64 bytes).
|
||||||
|
*/
|
||||||
|
MEM_STATIC void* ZSTD_cwksp_reserve_aligned(ZSTD_cwksp* ws, size_t bytes)
|
||||||
|
{
|
||||||
|
void* ptr = ZSTD_cwksp_reserve_internal(ws, ZSTD_cwksp_align(bytes, ZSTD_CWKSP_ALIGNMENT_BYTES),
|
||||||
|
ZSTD_cwksp_alloc_aligned);
|
||||||
|
assert(((size_t)ptr & (ZSTD_CWKSP_ALIGNMENT_BYTES-1))== 0);
|
||||||
|
return ptr;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Aligned on 64 bytes. These buffers have the special property that
|
||||||
* their values remain constrained, allowing us to re-use them without
|
* their values remain constrained, allowing us to re-use them without
|
||||||
* memset()-ing them.
|
* memset()-ing them.
|
||||||
*/
|
*/
|
||||||
MEM_STATIC void* ZSTD_cwksp_reserve_table(ZSTD_cwksp* ws, size_t bytes) {
|
MEM_STATIC void* ZSTD_cwksp_reserve_table(ZSTD_cwksp* ws, size_t bytes)
|
||||||
const ZSTD_cwksp_alloc_phase_e phase = ZSTD_cwksp_alloc_aligned;
|
{
|
||||||
void* alloc = ws->tableEnd;
|
const ZSTD_cwksp_alloc_phase_e phase = ZSTD_cwksp_alloc_aligned_init_once;
|
||||||
void* end = (BYTE *)alloc + bytes;
|
void* alloc;
|
||||||
void* top = ws->allocStart;
|
void* end;
|
||||||
|
void* top;
|
||||||
|
|
||||||
|
/* We can only start allocating tables after we are done reserving space for objects at the
|
||||||
|
* start of the workspace */
|
||||||
|
if(ws->phase < phase) {
|
||||||
|
if (ZSTD_isError(ZSTD_cwksp_internal_advance_phase(ws, phase))) {
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
alloc = ws->tableEnd;
|
||||||
|
end = (BYTE *)alloc + bytes;
|
||||||
|
top = ws->allocStart;
|
||||||
|
|
||||||
DEBUGLOG(5, "cwksp: reserving %p table %zd bytes, %zd bytes remaining",
|
DEBUGLOG(5, "cwksp: reserving %p table %zd bytes, %zd bytes remaining",
|
||||||
alloc, bytes, ZSTD_cwksp_available_space(ws) - bytes);
|
alloc, bytes, ZSTD_cwksp_available_space(ws) - bytes);
|
||||||
assert((bytes & (sizeof(U32)-1)) == 0);
|
assert((bytes & (sizeof(U32)-1)) == 0);
|
||||||
ZSTD_cwksp_internal_advance_phase(ws, phase);
|
|
||||||
ZSTD_cwksp_assert_internal_consistency(ws);
|
ZSTD_cwksp_assert_internal_consistency(ws);
|
||||||
assert(end <= top);
|
assert(end <= top);
|
||||||
if (end > top) {
|
if (end > top) {
|
||||||
@@ -306,35 +467,41 @@ MEM_STATIC void* ZSTD_cwksp_reserve_table(ZSTD_cwksp* ws, size_t bytes) {
|
|||||||
}
|
}
|
||||||
ws->tableEnd = end;
|
ws->tableEnd = end;
|
||||||
|
|
||||||
#if defined (ADDRESS_SANITIZER) && !defined (ZSTD_ASAN_DONT_POISON_WORKSPACE)
|
#if ZSTD_ADDRESS_SANITIZER && !defined (ZSTD_ASAN_DONT_POISON_WORKSPACE)
|
||||||
|
if (ws->isStatic == ZSTD_cwksp_dynamic_alloc) {
|
||||||
__asan_unpoison_memory_region(alloc, bytes);
|
__asan_unpoison_memory_region(alloc, bytes);
|
||||||
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
assert((bytes & (ZSTD_CWKSP_ALIGNMENT_BYTES-1)) == 0);
|
||||||
|
assert(((size_t)alloc & (ZSTD_CWKSP_ALIGNMENT_BYTES-1))== 0);
|
||||||
return alloc;
|
return alloc;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Aligned on sizeof(void*).
|
* Aligned on sizeof(void*).
|
||||||
|
* Note : should happen only once, at workspace first initialization
|
||||||
*/
|
*/
|
||||||
MEM_STATIC void* ZSTD_cwksp_reserve_object(ZSTD_cwksp* ws, size_t bytes) {
|
MEM_STATIC void* ZSTD_cwksp_reserve_object(ZSTD_cwksp* ws, size_t bytes)
|
||||||
size_t roundedBytes = ZSTD_cwksp_align(bytes, sizeof(void*));
|
{
|
||||||
|
size_t const roundedBytes = ZSTD_cwksp_align(bytes, sizeof(void*));
|
||||||
void* alloc = ws->objectEnd;
|
void* alloc = ws->objectEnd;
|
||||||
void* end = (BYTE*)alloc + roundedBytes;
|
void* end = (BYTE*)alloc + roundedBytes;
|
||||||
|
|
||||||
#if defined (ADDRESS_SANITIZER) && !defined (ZSTD_ASAN_DONT_POISON_WORKSPACE)
|
#if ZSTD_ADDRESS_SANITIZER && !defined (ZSTD_ASAN_DONT_POISON_WORKSPACE)
|
||||||
/* over-reserve space */
|
/* over-reserve space */
|
||||||
end = (BYTE *)end + 2 * ZSTD_CWKSP_ASAN_REDZONE_SIZE;
|
end = (BYTE *)end + 2 * ZSTD_CWKSP_ASAN_REDZONE_SIZE;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
DEBUGLOG(5,
|
DEBUGLOG(4,
|
||||||
"cwksp: reserving %p object %zd bytes (rounded to %zd), %zd bytes remaining",
|
"cwksp: reserving %p object %zd bytes (rounded to %zd), %zd bytes remaining",
|
||||||
alloc, bytes, roundedBytes, ZSTD_cwksp_available_space(ws) - roundedBytes);
|
alloc, bytes, roundedBytes, ZSTD_cwksp_available_space(ws) - roundedBytes);
|
||||||
assert(((size_t)alloc & (sizeof(void*)-1)) == 0);
|
assert((size_t)alloc % ZSTD_ALIGNOF(void*) == 0);
|
||||||
assert((bytes & (sizeof(void*)-1)) == 0);
|
assert(bytes % ZSTD_ALIGNOF(void*) == 0);
|
||||||
ZSTD_cwksp_assert_internal_consistency(ws);
|
ZSTD_cwksp_assert_internal_consistency(ws);
|
||||||
/* we must be in the first phase, no advance is possible */
|
/* we must be in the first phase, no advance is possible */
|
||||||
if (ws->phase != ZSTD_cwksp_alloc_objects || end > ws->workspaceEnd) {
|
if (ws->phase != ZSTD_cwksp_alloc_objects || end > ws->workspaceEnd) {
|
||||||
DEBUGLOG(4, "cwksp: object alloc failed!");
|
DEBUGLOG(3, "cwksp: object alloc failed!");
|
||||||
ws->allocFailed = 1;
|
ws->allocFailed = 1;
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
@@ -342,27 +509,38 @@ MEM_STATIC void* ZSTD_cwksp_reserve_object(ZSTD_cwksp* ws, size_t bytes) {
|
|||||||
ws->tableEnd = end;
|
ws->tableEnd = end;
|
||||||
ws->tableValidEnd = end;
|
ws->tableValidEnd = end;
|
||||||
|
|
||||||
#if defined (ADDRESS_SANITIZER) && !defined (ZSTD_ASAN_DONT_POISON_WORKSPACE)
|
#if ZSTD_ADDRESS_SANITIZER && !defined (ZSTD_ASAN_DONT_POISON_WORKSPACE)
|
||||||
/* Move alloc so there's ZSTD_CWKSP_ASAN_REDZONE_SIZE unused space on
|
/* Move alloc so there's ZSTD_CWKSP_ASAN_REDZONE_SIZE unused space on
|
||||||
* either size. */
|
* either size. */
|
||||||
alloc = (BYTE *)alloc + ZSTD_CWKSP_ASAN_REDZONE_SIZE;
|
alloc = (BYTE*)alloc + ZSTD_CWKSP_ASAN_REDZONE_SIZE;
|
||||||
|
if (ws->isStatic == ZSTD_cwksp_dynamic_alloc) {
|
||||||
__asan_unpoison_memory_region(alloc, bytes);
|
__asan_unpoison_memory_region(alloc, bytes);
|
||||||
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
return alloc;
|
return alloc;
|
||||||
}
|
}
|
||||||
|
|
||||||
MEM_STATIC void ZSTD_cwksp_mark_tables_dirty(ZSTD_cwksp* ws) {
|
MEM_STATIC void ZSTD_cwksp_mark_tables_dirty(ZSTD_cwksp* ws)
|
||||||
|
{
|
||||||
DEBUGLOG(4, "cwksp: ZSTD_cwksp_mark_tables_dirty");
|
DEBUGLOG(4, "cwksp: ZSTD_cwksp_mark_tables_dirty");
|
||||||
|
|
||||||
#if defined (MEMORY_SANITIZER) && !defined (ZSTD_MSAN_DONT_POISON_WORKSPACE)
|
#if ZSTD_MEMORY_SANITIZER && !defined (ZSTD_MSAN_DONT_POISON_WORKSPACE)
|
||||||
/* To validate that the table re-use logic is sound, and that we don't
|
/* To validate that the table re-use logic is sound, and that we don't
|
||||||
* access table space that we haven't cleaned, we re-"poison" the table
|
* access table space that we haven't cleaned, we re-"poison" the table
|
||||||
* space every time we mark it dirty. */
|
* space every time we mark it dirty.
|
||||||
|
* Since tableValidEnd space and initOnce space may overlap we don't poison
|
||||||
|
* the initOnce portion as it break its promise. This means that this poisoning
|
||||||
|
* check isn't always applied fully. */
|
||||||
{
|
{
|
||||||
size_t size = (BYTE*)ws->tableValidEnd - (BYTE*)ws->objectEnd;
|
size_t size = (BYTE*)ws->tableValidEnd - (BYTE*)ws->objectEnd;
|
||||||
assert(__msan_test_shadow(ws->objectEnd, size) == -1);
|
assert(__msan_test_shadow(ws->objectEnd, size) == -1);
|
||||||
|
if((BYTE*)ws->tableValidEnd < (BYTE*)ws->initOnceStart) {
|
||||||
__msan_poison(ws->objectEnd, size);
|
__msan_poison(ws->objectEnd, size);
|
||||||
|
} else {
|
||||||
|
assert(ws->initOnceStart >= ws->objectEnd);
|
||||||
|
__msan_poison(ws->objectEnd, (BYTE*)ws->initOnceStart - (BYTE*)ws->objectEnd);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
@@ -390,7 +568,7 @@ MEM_STATIC void ZSTD_cwksp_clean_tables(ZSTD_cwksp* ws) {
|
|||||||
assert(ws->tableValidEnd >= ws->objectEnd);
|
assert(ws->tableValidEnd >= ws->objectEnd);
|
||||||
assert(ws->tableValidEnd <= ws->allocStart);
|
assert(ws->tableValidEnd <= ws->allocStart);
|
||||||
if (ws->tableValidEnd < ws->tableEnd) {
|
if (ws->tableValidEnd < ws->tableEnd) {
|
||||||
memset(ws->tableValidEnd, 0, (BYTE*)ws->tableEnd - (BYTE*)ws->tableValidEnd);
|
ZSTD_memset(ws->tableValidEnd, 0, (size_t)((BYTE*)ws->tableEnd - (BYTE*)ws->tableValidEnd));
|
||||||
}
|
}
|
||||||
ZSTD_cwksp_mark_tables_clean(ws);
|
ZSTD_cwksp_mark_tables_clean(ws);
|
||||||
}
|
}
|
||||||
@@ -402,8 +580,12 @@ MEM_STATIC void ZSTD_cwksp_clean_tables(ZSTD_cwksp* ws) {
|
|||||||
MEM_STATIC void ZSTD_cwksp_clear_tables(ZSTD_cwksp* ws) {
|
MEM_STATIC void ZSTD_cwksp_clear_tables(ZSTD_cwksp* ws) {
|
||||||
DEBUGLOG(4, "cwksp: clearing tables!");
|
DEBUGLOG(4, "cwksp: clearing tables!");
|
||||||
|
|
||||||
#if defined (ADDRESS_SANITIZER) && !defined (ZSTD_ASAN_DONT_POISON_WORKSPACE)
|
#if ZSTD_ADDRESS_SANITIZER && !defined (ZSTD_ASAN_DONT_POISON_WORKSPACE)
|
||||||
{
|
/* We don't do this when the workspace is statically allocated, because
|
||||||
|
* when that is the case, we have no capability to hook into the end of the
|
||||||
|
* workspace's lifecycle to unpoison the memory.
|
||||||
|
*/
|
||||||
|
if (ws->isStatic == ZSTD_cwksp_dynamic_alloc) {
|
||||||
size_t size = (BYTE*)ws->tableValidEnd - (BYTE*)ws->objectEnd;
|
size_t size = (BYTE*)ws->tableValidEnd - (BYTE*)ws->objectEnd;
|
||||||
__asan_poison_memory_region(ws->objectEnd, size);
|
__asan_poison_memory_region(ws->objectEnd, size);
|
||||||
}
|
}
|
||||||
@@ -420,29 +602,36 @@ MEM_STATIC void ZSTD_cwksp_clear_tables(ZSTD_cwksp* ws) {
|
|||||||
MEM_STATIC void ZSTD_cwksp_clear(ZSTD_cwksp* ws) {
|
MEM_STATIC void ZSTD_cwksp_clear(ZSTD_cwksp* ws) {
|
||||||
DEBUGLOG(4, "cwksp: clearing!");
|
DEBUGLOG(4, "cwksp: clearing!");
|
||||||
|
|
||||||
#if defined (MEMORY_SANITIZER) && !defined (ZSTD_MSAN_DONT_POISON_WORKSPACE)
|
#if ZSTD_MEMORY_SANITIZER && !defined (ZSTD_MSAN_DONT_POISON_WORKSPACE)
|
||||||
/* To validate that the context re-use logic is sound, and that we don't
|
/* To validate that the context re-use logic is sound, and that we don't
|
||||||
* access stuff that this compression hasn't initialized, we re-"poison"
|
* access stuff that this compression hasn't initialized, we re-"poison"
|
||||||
* the workspace (or at least the non-static, non-table parts of it)
|
* the workspace except for the areas in which we expect memory re-use
|
||||||
* every time we start a new compression. */
|
* without initialization (objects, valid tables area and init once
|
||||||
|
* memory). */
|
||||||
{
|
{
|
||||||
size_t size = (BYTE*)ws->workspaceEnd - (BYTE*)ws->tableValidEnd;
|
if((BYTE*)ws->tableValidEnd < (BYTE*)ws->initOnceStart) {
|
||||||
|
size_t size = (BYTE*)ws->initOnceStart - (BYTE*)ws->tableValidEnd;
|
||||||
__msan_poison(ws->tableValidEnd, size);
|
__msan_poison(ws->tableValidEnd, size);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#if defined (ADDRESS_SANITIZER) && !defined (ZSTD_ASAN_DONT_POISON_WORKSPACE)
|
#if ZSTD_ADDRESS_SANITIZER && !defined (ZSTD_ASAN_DONT_POISON_WORKSPACE)
|
||||||
{
|
/* We don't do this when the workspace is statically allocated, because
|
||||||
|
* when that is the case, we have no capability to hook into the end of the
|
||||||
|
* workspace's lifecycle to unpoison the memory.
|
||||||
|
*/
|
||||||
|
if (ws->isStatic == ZSTD_cwksp_dynamic_alloc) {
|
||||||
size_t size = (BYTE*)ws->workspaceEnd - (BYTE*)ws->objectEnd;
|
size_t size = (BYTE*)ws->workspaceEnd - (BYTE*)ws->objectEnd;
|
||||||
__asan_poison_memory_region(ws->objectEnd, size);
|
__asan_poison_memory_region(ws->objectEnd, size);
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
ws->tableEnd = ws->objectEnd;
|
ws->tableEnd = ws->objectEnd;
|
||||||
ws->allocStart = ws->workspaceEnd;
|
ws->allocStart = ZSTD_cwksp_initialAllocStart(ws);
|
||||||
ws->allocFailed = 0;
|
ws->allocFailed = 0;
|
||||||
if (ws->phase > ZSTD_cwksp_alloc_buffers) {
|
if (ws->phase > ZSTD_cwksp_alloc_aligned_init_once) {
|
||||||
ws->phase = ZSTD_cwksp_alloc_buffers;
|
ws->phase = ZSTD_cwksp_alloc_aligned_init_once;
|
||||||
}
|
}
|
||||||
ZSTD_cwksp_assert_internal_consistency(ws);
|
ZSTD_cwksp_assert_internal_consistency(ws);
|
||||||
}
|
}
|
||||||
@@ -452,47 +641,54 @@ MEM_STATIC void ZSTD_cwksp_clear(ZSTD_cwksp* ws) {
|
|||||||
* Any existing values in the workspace are ignored (the previously managed
|
* Any existing values in the workspace are ignored (the previously managed
|
||||||
* buffer, if present, must be separately freed).
|
* buffer, if present, must be separately freed).
|
||||||
*/
|
*/
|
||||||
MEM_STATIC void ZSTD_cwksp_init(ZSTD_cwksp* ws, void* start, size_t size) {
|
MEM_STATIC void ZSTD_cwksp_init(ZSTD_cwksp* ws, void* start, size_t size, ZSTD_cwksp_static_alloc_e isStatic) {
|
||||||
DEBUGLOG(4, "cwksp: init'ing workspace with %zd bytes", size);
|
DEBUGLOG(4, "cwksp: init'ing workspace with %zd bytes", size);
|
||||||
assert(((size_t)start & (sizeof(void*)-1)) == 0); /* ensure correct alignment */
|
assert(((size_t)start & (sizeof(void*)-1)) == 0); /* ensure correct alignment */
|
||||||
ws->workspace = start;
|
ws->workspace = start;
|
||||||
ws->workspaceEnd = (BYTE*)start + size;
|
ws->workspaceEnd = (BYTE*)start + size;
|
||||||
ws->objectEnd = ws->workspace;
|
ws->objectEnd = ws->workspace;
|
||||||
ws->tableValidEnd = ws->objectEnd;
|
ws->tableValidEnd = ws->objectEnd;
|
||||||
|
ws->initOnceStart = ZSTD_cwksp_initialAllocStart(ws);
|
||||||
ws->phase = ZSTD_cwksp_alloc_objects;
|
ws->phase = ZSTD_cwksp_alloc_objects;
|
||||||
|
ws->isStatic = isStatic;
|
||||||
ZSTD_cwksp_clear(ws);
|
ZSTD_cwksp_clear(ws);
|
||||||
ws->workspaceOversizedDuration = 0;
|
ws->workspaceOversizedDuration = 0;
|
||||||
ZSTD_cwksp_assert_internal_consistency(ws);
|
ZSTD_cwksp_assert_internal_consistency(ws);
|
||||||
}
|
}
|
||||||
|
|
||||||
MEM_STATIC size_t ZSTD_cwksp_create(ZSTD_cwksp* ws, size_t size, ZSTD_customMem customMem) {
|
MEM_STATIC size_t ZSTD_cwksp_create(ZSTD_cwksp* ws, size_t size, ZSTD_customMem customMem) {
|
||||||
void* workspace = ZSTD_malloc(size, customMem);
|
void* workspace = ZSTD_customMalloc(size, customMem);
|
||||||
DEBUGLOG(4, "cwksp: creating new workspace with %zd bytes", size);
|
DEBUGLOG(4, "cwksp: creating new workspace with %zd bytes", size);
|
||||||
RETURN_ERROR_IF(workspace == NULL, memory_allocation);
|
RETURN_ERROR_IF(workspace == NULL, memory_allocation, "NULL pointer!");
|
||||||
ZSTD_cwksp_init(ws, workspace, size);
|
ZSTD_cwksp_init(ws, workspace, size, ZSTD_cwksp_dynamic_alloc);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
MEM_STATIC void ZSTD_cwksp_free(ZSTD_cwksp* ws, ZSTD_customMem customMem) {
|
MEM_STATIC void ZSTD_cwksp_free(ZSTD_cwksp* ws, ZSTD_customMem customMem) {
|
||||||
void *ptr = ws->workspace;
|
void *ptr = ws->workspace;
|
||||||
DEBUGLOG(4, "cwksp: freeing workspace");
|
DEBUGLOG(4, "cwksp: freeing workspace");
|
||||||
memset(ws, 0, sizeof(ZSTD_cwksp));
|
ZSTD_memset(ws, 0, sizeof(ZSTD_cwksp));
|
||||||
ZSTD_free(ptr, customMem);
|
ZSTD_customFree(ptr, customMem);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Moves the management of a workspace from one cwksp to another. The src cwksp
|
* Moves the management of a workspace from one cwksp to another. The src cwksp
|
||||||
* is left in an invalid state (src must be re-init()'ed before its used again).
|
* is left in an invalid state (src must be re-init()'ed before it's used again).
|
||||||
*/
|
*/
|
||||||
MEM_STATIC void ZSTD_cwksp_move(ZSTD_cwksp* dst, ZSTD_cwksp* src) {
|
MEM_STATIC void ZSTD_cwksp_move(ZSTD_cwksp* dst, ZSTD_cwksp* src) {
|
||||||
*dst = *src;
|
*dst = *src;
|
||||||
memset(src, 0, sizeof(ZSTD_cwksp));
|
ZSTD_memset(src, 0, sizeof(ZSTD_cwksp));
|
||||||
}
|
}
|
||||||
|
|
||||||
MEM_STATIC size_t ZSTD_cwksp_sizeof(const ZSTD_cwksp* ws) {
|
MEM_STATIC size_t ZSTD_cwksp_sizeof(const ZSTD_cwksp* ws) {
|
||||||
return (size_t)((BYTE*)ws->workspaceEnd - (BYTE*)ws->workspace);
|
return (size_t)((BYTE*)ws->workspaceEnd - (BYTE*)ws->workspace);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
MEM_STATIC size_t ZSTD_cwksp_used(const ZSTD_cwksp* ws) {
|
||||||
|
return (size_t)((BYTE*)ws->tableEnd - (BYTE*)ws->workspace)
|
||||||
|
+ (size_t)((BYTE*)ws->workspaceEnd - (BYTE*)ws->allocStart);
|
||||||
|
}
|
||||||
|
|
||||||
MEM_STATIC int ZSTD_cwksp_reserve_failed(const ZSTD_cwksp* ws) {
|
MEM_STATIC int ZSTD_cwksp_reserve_failed(const ZSTD_cwksp* ws) {
|
||||||
return ws->allocFailed;
|
return ws->allocFailed;
|
||||||
}
|
}
|
||||||
@@ -501,6 +697,18 @@ MEM_STATIC int ZSTD_cwksp_reserve_failed(const ZSTD_cwksp* ws) {
|
|||||||
* Functions Checking Free Space
|
* Functions Checking Free Space
|
||||||
***************************************/
|
***************************************/
|
||||||
|
|
||||||
|
/* ZSTD_alignmentSpaceWithinBounds() :
|
||||||
|
* Returns if the estimated space needed for a wksp is within an acceptable limit of the
|
||||||
|
* actual amount of space used.
|
||||||
|
*/
|
||||||
|
MEM_STATIC int ZSTD_cwksp_estimated_space_within_bounds(const ZSTD_cwksp *const ws, size_t const estimatedSpace) {
|
||||||
|
/* We have an alignment space between objects and tables between tables and buffers, so we can have up to twice
|
||||||
|
* the alignment bytes difference between estimation and actual usage */
|
||||||
|
return (estimatedSpace - ZSTD_cwksp_slack_space_required()) <= ZSTD_cwksp_used(ws) &&
|
||||||
|
ZSTD_cwksp_used(ws) <= estimatedSpace;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
MEM_STATIC size_t ZSTD_cwksp_available_space(ZSTD_cwksp* ws) {
|
MEM_STATIC size_t ZSTD_cwksp_available_space(ZSTD_cwksp* ws) {
|
||||||
return (size_t)((BYTE*)ws->allocStart - (BYTE*)ws->tableEnd);
|
return (size_t)((BYTE*)ws->allocStart - (BYTE*)ws->tableEnd);
|
||||||
}
|
}
|
||||||
@@ -533,3 +741,5 @@ MEM_STATIC void ZSTD_cwksp_bump_oversized_duration(
|
|||||||
#endif
|
#endif
|
||||||
|
|
||||||
#endif /* ZSTD_CWKSP_H */
|
#endif /* ZSTD_CWKSP_H */
|
||||||
|
|
||||||
|
#endif /* USE_EXTERNAL_ZSTD */
|
||||||
|
|||||||
37
vendor/github.com/DataDog/zstd/zstd_ddict.c
generated
vendored
37
vendor/github.com/DataDog/zstd/zstd_ddict.c
generated
vendored
@@ -1,5 +1,6 @@
|
|||||||
|
#ifndef USE_EXTERNAL_ZSTD
|
||||||
/*
|
/*
|
||||||
* Copyright (c) 2016-present, Yann Collet, Facebook, Inc.
|
* Copyright (c) Meta Platforms, Inc. and affiliates.
|
||||||
* All rights reserved.
|
* All rights reserved.
|
||||||
*
|
*
|
||||||
* This source code is licensed under both the BSD-style license (found in the
|
* This source code is licensed under both the BSD-style license (found in the
|
||||||
@@ -14,18 +15,18 @@
|
|||||||
/*-*******************************************************
|
/*-*******************************************************
|
||||||
* Dependencies
|
* Dependencies
|
||||||
*********************************************************/
|
*********************************************************/
|
||||||
#include <string.h> /* memcpy, memmove, memset */
|
#include "allocations.h" /* ZSTD_customMalloc, ZSTD_customFree */
|
||||||
|
#include "zstd_deps.h" /* ZSTD_memcpy, ZSTD_memmove, ZSTD_memset */
|
||||||
#include "cpu.h" /* bmi2 */
|
#include "cpu.h" /* bmi2 */
|
||||||
#include "mem.h" /* low level memory routines */
|
#include "mem.h" /* low level memory routines */
|
||||||
#define FSE_STATIC_LINKING_ONLY
|
#define FSE_STATIC_LINKING_ONLY
|
||||||
#include "fse.h"
|
#include "fse.h"
|
||||||
#define HUF_STATIC_LINKING_ONLY
|
|
||||||
#include "huf.h"
|
#include "huf.h"
|
||||||
#include "zstd_decompress_internal.h"
|
#include "zstd_decompress_internal.h"
|
||||||
#include "zstd_ddict.h"
|
#include "zstd_ddict.h"
|
||||||
|
|
||||||
#if defined(ZSTD_LEGACY_SUPPORT) && (ZSTD_LEGACY_SUPPORT>=1)
|
#if defined(ZSTD_LEGACY_SUPPORT) && (ZSTD_LEGACY_SUPPORT>=1)
|
||||||
# include "zstd_legacy.h"
|
#include "zstd_legacy.h"
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
|
||||||
@@ -65,6 +66,10 @@ void ZSTD_copyDDictParameters(ZSTD_DCtx* dctx, const ZSTD_DDict* ddict)
|
|||||||
dctx->virtualStart = ddict->dictContent;
|
dctx->virtualStart = ddict->dictContent;
|
||||||
dctx->dictEnd = (const BYTE*)ddict->dictContent + ddict->dictSize;
|
dctx->dictEnd = (const BYTE*)ddict->dictContent + ddict->dictSize;
|
||||||
dctx->previousDstEnd = dctx->dictEnd;
|
dctx->previousDstEnd = dctx->dictEnd;
|
||||||
|
#ifdef FUZZING_BUILD_MODE_UNSAFE_FOR_PRODUCTION
|
||||||
|
dctx->dictContentBeginForFuzzing = dctx->prefixStart;
|
||||||
|
dctx->dictContentEndForFuzzing = dctx->previousDstEnd;
|
||||||
|
#endif
|
||||||
if (ddict->entropyPresent) {
|
if (ddict->entropyPresent) {
|
||||||
dctx->litEntropy = 1;
|
dctx->litEntropy = 1;
|
||||||
dctx->fseEntropy = 1;
|
dctx->fseEntropy = 1;
|
||||||
@@ -107,7 +112,7 @@ ZSTD_loadEntropy_intoDDict(ZSTD_DDict* ddict,
|
|||||||
/* load entropy tables */
|
/* load entropy tables */
|
||||||
RETURN_ERROR_IF(ZSTD_isError(ZSTD_loadDEntropy(
|
RETURN_ERROR_IF(ZSTD_isError(ZSTD_loadDEntropy(
|
||||||
&ddict->entropy, ddict->dictContent, ddict->dictSize)),
|
&ddict->entropy, ddict->dictContent, ddict->dictSize)),
|
||||||
dictionary_corrupted);
|
dictionary_corrupted, "");
|
||||||
ddict->entropyPresent = 1;
|
ddict->entropyPresent = 1;
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
@@ -123,17 +128,17 @@ static size_t ZSTD_initDDict_internal(ZSTD_DDict* ddict,
|
|||||||
ddict->dictContent = dict;
|
ddict->dictContent = dict;
|
||||||
if (!dict) dictSize = 0;
|
if (!dict) dictSize = 0;
|
||||||
} else {
|
} else {
|
||||||
void* const internalBuffer = ZSTD_malloc(dictSize, ddict->cMem);
|
void* const internalBuffer = ZSTD_customMalloc(dictSize, ddict->cMem);
|
||||||
ddict->dictBuffer = internalBuffer;
|
ddict->dictBuffer = internalBuffer;
|
||||||
ddict->dictContent = internalBuffer;
|
ddict->dictContent = internalBuffer;
|
||||||
if (!internalBuffer) return ERROR(memory_allocation);
|
if (!internalBuffer) return ERROR(memory_allocation);
|
||||||
memcpy(internalBuffer, dict, dictSize);
|
ZSTD_memcpy(internalBuffer, dict, dictSize);
|
||||||
}
|
}
|
||||||
ddict->dictSize = dictSize;
|
ddict->dictSize = dictSize;
|
||||||
ddict->entropy.hufTable[0] = (HUF_DTable)((HufLog)*0x1000001); /* cover both little and big endian */
|
ddict->entropy.hufTable[0] = (HUF_DTable)((ZSTD_HUFFDTABLE_CAPACITY_LOG)*0x1000001); /* cover both little and big endian */
|
||||||
|
|
||||||
/* parse dictionary content */
|
/* parse dictionary content */
|
||||||
FORWARD_IF_ERROR( ZSTD_loadEntropy_intoDDict(ddict, dictContentType) );
|
FORWARD_IF_ERROR( ZSTD_loadEntropy_intoDDict(ddict, dictContentType) , "");
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
@@ -143,9 +148,9 @@ ZSTD_DDict* ZSTD_createDDict_advanced(const void* dict, size_t dictSize,
|
|||||||
ZSTD_dictContentType_e dictContentType,
|
ZSTD_dictContentType_e dictContentType,
|
||||||
ZSTD_customMem customMem)
|
ZSTD_customMem customMem)
|
||||||
{
|
{
|
||||||
if (!customMem.customAlloc ^ !customMem.customFree) return NULL;
|
if ((!customMem.customAlloc) ^ (!customMem.customFree)) return NULL;
|
||||||
|
|
||||||
{ ZSTD_DDict* const ddict = (ZSTD_DDict*) ZSTD_malloc(sizeof(ZSTD_DDict), customMem);
|
{ ZSTD_DDict* const ddict = (ZSTD_DDict*) ZSTD_customMalloc(sizeof(ZSTD_DDict), customMem);
|
||||||
if (ddict == NULL) return NULL;
|
if (ddict == NULL) return NULL;
|
||||||
ddict->cMem = customMem;
|
ddict->cMem = customMem;
|
||||||
{ size_t const initResult = ZSTD_initDDict_internal(ddict,
|
{ size_t const initResult = ZSTD_initDDict_internal(ddict,
|
||||||
@@ -194,7 +199,7 @@ const ZSTD_DDict* ZSTD_initStaticDDict(
|
|||||||
if ((size_t)sBuffer & 7) return NULL; /* 8-aligned */
|
if ((size_t)sBuffer & 7) return NULL; /* 8-aligned */
|
||||||
if (sBufferSize < neededSpace) return NULL;
|
if (sBufferSize < neededSpace) return NULL;
|
||||||
if (dictLoadMethod == ZSTD_dlm_byCopy) {
|
if (dictLoadMethod == ZSTD_dlm_byCopy) {
|
||||||
memcpy(ddict+1, dict, dictSize); /* local copy */
|
ZSTD_memcpy(ddict+1, dict, dictSize); /* local copy */
|
||||||
dict = ddict+1;
|
dict = ddict+1;
|
||||||
}
|
}
|
||||||
if (ZSTD_isError( ZSTD_initDDict_internal(ddict,
|
if (ZSTD_isError( ZSTD_initDDict_internal(ddict,
|
||||||
@@ -209,8 +214,8 @@ size_t ZSTD_freeDDict(ZSTD_DDict* ddict)
|
|||||||
{
|
{
|
||||||
if (ddict==NULL) return 0; /* support free on NULL */
|
if (ddict==NULL) return 0; /* support free on NULL */
|
||||||
{ ZSTD_customMem const cMem = ddict->cMem;
|
{ ZSTD_customMem const cMem = ddict->cMem;
|
||||||
ZSTD_free(ddict->dictBuffer, cMem);
|
ZSTD_customFree(ddict->dictBuffer, cMem);
|
||||||
ZSTD_free(ddict, cMem);
|
ZSTD_customFree(ddict, cMem);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -236,5 +241,7 @@ size_t ZSTD_sizeof_DDict(const ZSTD_DDict* ddict)
|
|||||||
unsigned ZSTD_getDictID_fromDDict(const ZSTD_DDict* ddict)
|
unsigned ZSTD_getDictID_fromDDict(const ZSTD_DDict* ddict)
|
||||||
{
|
{
|
||||||
if (ddict==NULL) return 0;
|
if (ddict==NULL) return 0;
|
||||||
return ZSTD_getDictID_fromDict(ddict->dictContent, ddict->dictSize);
|
return ddict->dictID;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#endif /* USE_EXTERNAL_ZSTD */
|
||||||
|
|||||||
7
vendor/github.com/DataDog/zstd/zstd_ddict.h
generated
vendored
7
vendor/github.com/DataDog/zstd/zstd_ddict.h
generated
vendored
@@ -1,5 +1,6 @@
|
|||||||
|
#ifndef USE_EXTERNAL_ZSTD
|
||||||
/*
|
/*
|
||||||
* Copyright (c) 2016-present, Yann Collet, Facebook, Inc.
|
* Copyright (c) Meta Platforms, Inc. and affiliates.
|
||||||
* All rights reserved.
|
* All rights reserved.
|
||||||
*
|
*
|
||||||
* This source code is licensed under both the BSD-style license (found in the
|
* This source code is licensed under both the BSD-style license (found in the
|
||||||
@@ -15,7 +16,7 @@
|
|||||||
/*-*******************************************************
|
/*-*******************************************************
|
||||||
* Dependencies
|
* Dependencies
|
||||||
*********************************************************/
|
*********************************************************/
|
||||||
#include <stddef.h> /* size_t */
|
#include "zstd_deps.h" /* size_t */
|
||||||
#include "zstd.h" /* ZSTD_DDict, and several public functions */
|
#include "zstd.h" /* ZSTD_DDict, and several public functions */
|
||||||
|
|
||||||
|
|
||||||
@@ -42,3 +43,5 @@ void ZSTD_copyDDictParameters(ZSTD_DCtx* dctx, const ZSTD_DDict* ddict);
|
|||||||
|
|
||||||
|
|
||||||
#endif /* ZSTD_DDICT_H */
|
#endif /* ZSTD_DDICT_H */
|
||||||
|
|
||||||
|
#endif /* USE_EXTERNAL_ZSTD */
|
||||||
|
|||||||
1065
vendor/github.com/DataDog/zstd/zstd_decompress.c
generated
vendored
1065
vendor/github.com/DataDog/zstd/zstd_decompress.c
generated
vendored
File diff suppressed because it is too large
Load Diff
1496
vendor/github.com/DataDog/zstd/zstd_decompress_block.c
generated
vendored
1496
vendor/github.com/DataDog/zstd/zstd_decompress_block.c
generated
vendored
File diff suppressed because it is too large
Load Diff
27
vendor/github.com/DataDog/zstd/zstd_decompress_block.h
generated
vendored
27
vendor/github.com/DataDog/zstd/zstd_decompress_block.h
generated
vendored
@@ -1,5 +1,6 @@
|
|||||||
|
#ifndef USE_EXTERNAL_ZSTD
|
||||||
/*
|
/*
|
||||||
* Copyright (c) 2016-present, Yann Collet, Facebook, Inc.
|
* Copyright (c) Meta Platforms, Inc. and affiliates.
|
||||||
* All rights reserved.
|
* All rights reserved.
|
||||||
*
|
*
|
||||||
* This source code is licensed under both the BSD-style license (found in the
|
* This source code is licensed under both the BSD-style license (found in the
|
||||||
@@ -15,7 +16,7 @@
|
|||||||
/*-*******************************************************
|
/*-*******************************************************
|
||||||
* Dependencies
|
* Dependencies
|
||||||
*********************************************************/
|
*********************************************************/
|
||||||
#include <stddef.h> /* size_t */
|
#include "zstd_deps.h" /* size_t */
|
||||||
#include "zstd.h" /* DCtx, and some public functions */
|
#include "zstd.h" /* DCtx, and some public functions */
|
||||||
#include "zstd_internal.h" /* blockProperties_t, and some public functions */
|
#include "zstd_internal.h" /* blockProperties_t, and some public functions */
|
||||||
#include "zstd_decompress_internal.h" /* ZSTD_seqSymbol */
|
#include "zstd_decompress_internal.h" /* ZSTD_seqSymbol */
|
||||||
@@ -33,6 +34,12 @@
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
|
|
||||||
|
/* Streaming state is used to inform allocation of the literal buffer */
|
||||||
|
typedef enum {
|
||||||
|
not_streaming = 0,
|
||||||
|
is_streaming = 1
|
||||||
|
} streaming_operation;
|
||||||
|
|
||||||
/* ZSTD_decompressBlock_internal() :
|
/* ZSTD_decompressBlock_internal() :
|
||||||
* decompress block, starting at `src`,
|
* decompress block, starting at `src`,
|
||||||
* into destination buffer `dst`.
|
* into destination buffer `dst`.
|
||||||
@@ -41,19 +48,29 @@
|
|||||||
*/
|
*/
|
||||||
size_t ZSTD_decompressBlock_internal(ZSTD_DCtx* dctx,
|
size_t ZSTD_decompressBlock_internal(ZSTD_DCtx* dctx,
|
||||||
void* dst, size_t dstCapacity,
|
void* dst, size_t dstCapacity,
|
||||||
const void* src, size_t srcSize, const int frame);
|
const void* src, size_t srcSize, const int frame, const streaming_operation streaming);
|
||||||
|
|
||||||
/* ZSTD_buildFSETable() :
|
/* ZSTD_buildFSETable() :
|
||||||
* generate FSE decoding table for one symbol (ll, ml or off)
|
* generate FSE decoding table for one symbol (ll, ml or off)
|
||||||
* this function must be called with valid parameters only
|
* this function must be called with valid parameters only
|
||||||
* (dt is large enough, normalizedCounter distribution total is a power of 2, max is within range, etc.)
|
* (dt is large enough, normalizedCounter distribution total is a power of 2, max is within range, etc.)
|
||||||
* in which case it cannot fail.
|
* in which case it cannot fail.
|
||||||
|
* The workspace must be 4-byte aligned and at least ZSTD_BUILD_FSE_TABLE_WKSP_SIZE bytes, which is
|
||||||
|
* defined in zstd_decompress_internal.h.
|
||||||
* Internal use only.
|
* Internal use only.
|
||||||
*/
|
*/
|
||||||
void ZSTD_buildFSETable(ZSTD_seqSymbol* dt,
|
void ZSTD_buildFSETable(ZSTD_seqSymbol* dt,
|
||||||
const short* normalizedCounter, unsigned maxSymbolValue,
|
const short* normalizedCounter, unsigned maxSymbolValue,
|
||||||
const U32* baseValue, const U32* nbAdditionalBits,
|
const U32* baseValue, const U8* nbAdditionalBits,
|
||||||
unsigned tableLog);
|
unsigned tableLog, void* wksp, size_t wkspSize,
|
||||||
|
int bmi2);
|
||||||
|
|
||||||
|
/* Internal definition of ZSTD_decompressBlock() to avoid deprecation warnings. */
|
||||||
|
size_t ZSTD_decompressBlock_deprecated(ZSTD_DCtx* dctx,
|
||||||
|
void* dst, size_t dstCapacity,
|
||||||
|
const void* src, size_t srcSize);
|
||||||
|
|
||||||
|
|
||||||
#endif /* ZSTD_DEC_BLOCK_H */
|
#endif /* ZSTD_DEC_BLOCK_H */
|
||||||
|
|
||||||
|
#endif /* USE_EXTERNAL_ZSTD */
|
||||||
|
|||||||
86
vendor/github.com/DataDog/zstd/zstd_decompress_internal.h
generated
vendored
86
vendor/github.com/DataDog/zstd/zstd_decompress_internal.h
generated
vendored
@@ -1,5 +1,6 @@
|
|||||||
|
#ifndef USE_EXTERNAL_ZSTD
|
||||||
/*
|
/*
|
||||||
* Copyright (c) 2016-present, Yann Collet, Facebook, Inc.
|
* Copyright (c) Meta Platforms, Inc. and affiliates.
|
||||||
* All rights reserved.
|
* All rights reserved.
|
||||||
*
|
*
|
||||||
* This source code is licensed under both the BSD-style license (found in the
|
* This source code is licensed under both the BSD-style license (found in the
|
||||||
@@ -20,33 +21,33 @@
|
|||||||
* Dependencies
|
* Dependencies
|
||||||
*********************************************************/
|
*********************************************************/
|
||||||
#include "mem.h" /* BYTE, U16, U32 */
|
#include "mem.h" /* BYTE, U16, U32 */
|
||||||
#include "zstd_internal.h" /* ZSTD_seqSymbol */
|
#include "zstd_internal.h" /* constants : MaxLL, MaxML, MaxOff, LLFSELog, etc. */
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/*-*******************************************************
|
/*-*******************************************************
|
||||||
* Constants
|
* Constants
|
||||||
*********************************************************/
|
*********************************************************/
|
||||||
static const U32 LL_base[MaxLL+1] = {
|
static UNUSED_ATTR const U32 LL_base[MaxLL+1] = {
|
||||||
0, 1, 2, 3, 4, 5, 6, 7,
|
0, 1, 2, 3, 4, 5, 6, 7,
|
||||||
8, 9, 10, 11, 12, 13, 14, 15,
|
8, 9, 10, 11, 12, 13, 14, 15,
|
||||||
16, 18, 20, 22, 24, 28, 32, 40,
|
16, 18, 20, 22, 24, 28, 32, 40,
|
||||||
48, 64, 0x80, 0x100, 0x200, 0x400, 0x800, 0x1000,
|
48, 64, 0x80, 0x100, 0x200, 0x400, 0x800, 0x1000,
|
||||||
0x2000, 0x4000, 0x8000, 0x10000 };
|
0x2000, 0x4000, 0x8000, 0x10000 };
|
||||||
|
|
||||||
static const U32 OF_base[MaxOff+1] = {
|
static UNUSED_ATTR const U32 OF_base[MaxOff+1] = {
|
||||||
0, 1, 1, 5, 0xD, 0x1D, 0x3D, 0x7D,
|
0, 1, 1, 5, 0xD, 0x1D, 0x3D, 0x7D,
|
||||||
0xFD, 0x1FD, 0x3FD, 0x7FD, 0xFFD, 0x1FFD, 0x3FFD, 0x7FFD,
|
0xFD, 0x1FD, 0x3FD, 0x7FD, 0xFFD, 0x1FFD, 0x3FFD, 0x7FFD,
|
||||||
0xFFFD, 0x1FFFD, 0x3FFFD, 0x7FFFD, 0xFFFFD, 0x1FFFFD, 0x3FFFFD, 0x7FFFFD,
|
0xFFFD, 0x1FFFD, 0x3FFFD, 0x7FFFD, 0xFFFFD, 0x1FFFFD, 0x3FFFFD, 0x7FFFFD,
|
||||||
0xFFFFFD, 0x1FFFFFD, 0x3FFFFFD, 0x7FFFFFD, 0xFFFFFFD, 0x1FFFFFFD, 0x3FFFFFFD, 0x7FFFFFFD };
|
0xFFFFFD, 0x1FFFFFD, 0x3FFFFFD, 0x7FFFFFD, 0xFFFFFFD, 0x1FFFFFFD, 0x3FFFFFFD, 0x7FFFFFFD };
|
||||||
|
|
||||||
static const U32 OF_bits[MaxOff+1] = {
|
static UNUSED_ATTR const U8 OF_bits[MaxOff+1] = {
|
||||||
0, 1, 2, 3, 4, 5, 6, 7,
|
0, 1, 2, 3, 4, 5, 6, 7,
|
||||||
8, 9, 10, 11, 12, 13, 14, 15,
|
8, 9, 10, 11, 12, 13, 14, 15,
|
||||||
16, 17, 18, 19, 20, 21, 22, 23,
|
16, 17, 18, 19, 20, 21, 22, 23,
|
||||||
24, 25, 26, 27, 28, 29, 30, 31 };
|
24, 25, 26, 27, 28, 29, 30, 31 };
|
||||||
|
|
||||||
static const U32 ML_base[MaxML+1] = {
|
static UNUSED_ATTR const U32 ML_base[MaxML+1] = {
|
||||||
3, 4, 5, 6, 7, 8, 9, 10,
|
3, 4, 5, 6, 7, 8, 9, 10,
|
||||||
11, 12, 13, 14, 15, 16, 17, 18,
|
11, 12, 13, 14, 15, 16, 17, 18,
|
||||||
19, 20, 21, 22, 23, 24, 25, 26,
|
19, 20, 21, 22, 23, 24, 25, 26,
|
||||||
@@ -73,12 +74,17 @@ static const U32 ML_base[MaxML+1] = {
|
|||||||
|
|
||||||
#define SEQSYMBOL_TABLE_SIZE(log) (1 + (1 << (log)))
|
#define SEQSYMBOL_TABLE_SIZE(log) (1 + (1 << (log)))
|
||||||
|
|
||||||
|
#define ZSTD_BUILD_FSE_TABLE_WKSP_SIZE (sizeof(S16) * (MaxSeq + 1) + (1u << MaxFSELog) + sizeof(U64))
|
||||||
|
#define ZSTD_BUILD_FSE_TABLE_WKSP_SIZE_U32 ((ZSTD_BUILD_FSE_TABLE_WKSP_SIZE + sizeof(U32) - 1) / sizeof(U32))
|
||||||
|
#define ZSTD_HUFFDTABLE_CAPACITY_LOG 12
|
||||||
|
|
||||||
typedef struct {
|
typedef struct {
|
||||||
ZSTD_seqSymbol LLTable[SEQSYMBOL_TABLE_SIZE(LLFSELog)]; /* Note : Space reserved for FSE Tables */
|
ZSTD_seqSymbol LLTable[SEQSYMBOL_TABLE_SIZE(LLFSELog)]; /* Note : Space reserved for FSE Tables */
|
||||||
ZSTD_seqSymbol OFTable[SEQSYMBOL_TABLE_SIZE(OffFSELog)]; /* is also used as temporary workspace while building hufTable during DDict creation */
|
ZSTD_seqSymbol OFTable[SEQSYMBOL_TABLE_SIZE(OffFSELog)]; /* is also used as temporary workspace while building hufTable during DDict creation */
|
||||||
ZSTD_seqSymbol MLTable[SEQSYMBOL_TABLE_SIZE(MLFSELog)]; /* and therefore must be at least HUF_DECOMPRESS_WORKSPACE_SIZE large */
|
ZSTD_seqSymbol MLTable[SEQSYMBOL_TABLE_SIZE(MLFSELog)]; /* and therefore must be at least HUF_DECOMPRESS_WORKSPACE_SIZE large */
|
||||||
HUF_DTable hufTable[HUF_DTABLE_SIZE(HufLog)]; /* can accommodate HUF_decompress4X */
|
HUF_DTable hufTable[HUF_DTABLE_SIZE(ZSTD_HUFFDTABLE_CAPACITY_LOG)]; /* can accommodate HUF_decompress4X */
|
||||||
U32 rep[ZSTD_REP_NUM];
|
U32 rep[ZSTD_REP_NUM];
|
||||||
|
U32 workspace[ZSTD_BUILD_FSE_TABLE_WKSP_SIZE_U32];
|
||||||
} ZSTD_entropyDTables_t;
|
} ZSTD_entropyDTables_t;
|
||||||
|
|
||||||
typedef enum { ZSTDds_getFrameHeaderSize, ZSTDds_decodeFrameHeader,
|
typedef enum { ZSTDds_getFrameHeaderSize, ZSTDds_decodeFrameHeader,
|
||||||
@@ -95,6 +101,29 @@ typedef enum {
|
|||||||
ZSTD_use_once = 1 /* Use the dictionary once and set to ZSTD_dont_use */
|
ZSTD_use_once = 1 /* Use the dictionary once and set to ZSTD_dont_use */
|
||||||
} ZSTD_dictUses_e;
|
} ZSTD_dictUses_e;
|
||||||
|
|
||||||
|
/* Hashset for storing references to multiple ZSTD_DDict within ZSTD_DCtx */
|
||||||
|
typedef struct {
|
||||||
|
const ZSTD_DDict** ddictPtrTable;
|
||||||
|
size_t ddictPtrTableSize;
|
||||||
|
size_t ddictPtrCount;
|
||||||
|
} ZSTD_DDictHashSet;
|
||||||
|
|
||||||
|
#ifndef ZSTD_DECODER_INTERNAL_BUFFER
|
||||||
|
# define ZSTD_DECODER_INTERNAL_BUFFER (1 << 16)
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#define ZSTD_LBMIN 64
|
||||||
|
#define ZSTD_LBMAX (128 << 10)
|
||||||
|
|
||||||
|
/* extra buffer, compensates when dst is not large enough to store litBuffer */
|
||||||
|
#define ZSTD_LITBUFFEREXTRASIZE BOUNDED(ZSTD_LBMIN, ZSTD_DECODER_INTERNAL_BUFFER, ZSTD_LBMAX)
|
||||||
|
|
||||||
|
typedef enum {
|
||||||
|
ZSTD_not_in_dst = 0, /* Stored entirely within litExtraBuffer */
|
||||||
|
ZSTD_in_dst = 1, /* Stored entirely within dst (in memory after current output write) */
|
||||||
|
ZSTD_split = 2 /* Split between litExtraBuffer and dst */
|
||||||
|
} ZSTD_litLocation_e;
|
||||||
|
|
||||||
struct ZSTD_DCtx_s
|
struct ZSTD_DCtx_s
|
||||||
{
|
{
|
||||||
const ZSTD_seqSymbol* LLTptr;
|
const ZSTD_seqSymbol* LLTptr;
|
||||||
@@ -109,6 +138,7 @@ struct ZSTD_DCtx_s
|
|||||||
const void* dictEnd; /* end of previous segment */
|
const void* dictEnd; /* end of previous segment */
|
||||||
size_t expected;
|
size_t expected;
|
||||||
ZSTD_frameHeader fParams;
|
ZSTD_frameHeader fParams;
|
||||||
|
U64 processedCSize;
|
||||||
U64 decodedSize;
|
U64 decodedSize;
|
||||||
blockType_e bType; /* used in ZSTD_decompressContinue(), store blockType between block header decoding and block decompression stages */
|
blockType_e bType; /* used in ZSTD_decompressContinue(), store blockType between block header decoding and block decompression stages */
|
||||||
ZSTD_dStage stage;
|
ZSTD_dStage stage;
|
||||||
@@ -117,12 +147,16 @@ struct ZSTD_DCtx_s
|
|||||||
XXH64_state_t xxhState;
|
XXH64_state_t xxhState;
|
||||||
size_t headerSize;
|
size_t headerSize;
|
||||||
ZSTD_format_e format;
|
ZSTD_format_e format;
|
||||||
|
ZSTD_forceIgnoreChecksum_e forceIgnoreChecksum; /* User specified: if == 1, will ignore checksums in compressed frame. Default == 0 */
|
||||||
|
U32 validateChecksum; /* if == 1, will validate checksum. Is == 1 if (fParams.checksumFlag == 1) and (forceIgnoreChecksum == 0). */
|
||||||
const BYTE* litPtr;
|
const BYTE* litPtr;
|
||||||
ZSTD_customMem customMem;
|
ZSTD_customMem customMem;
|
||||||
size_t litSize;
|
size_t litSize;
|
||||||
size_t rleSize;
|
size_t rleSize;
|
||||||
size_t staticSize;
|
size_t staticSize;
|
||||||
|
#if DYNAMIC_BMI2 != 0
|
||||||
int bmi2; /* == 1 if the CPU supports BMI2 and 0 otherwise. CPU support is determined dynamically once per context lifetime. */
|
int bmi2; /* == 1 if the CPU supports BMI2 and 0 otherwise. CPU support is determined dynamically once per context lifetime. */
|
||||||
|
#endif
|
||||||
|
|
||||||
/* dictionary */
|
/* dictionary */
|
||||||
ZSTD_DDict* ddictLocal;
|
ZSTD_DDict* ddictLocal;
|
||||||
@@ -130,6 +164,9 @@ struct ZSTD_DCtx_s
|
|||||||
U32 dictID;
|
U32 dictID;
|
||||||
int ddictIsCold; /* if == 1 : dictionary is "new" for working context, and presumed "cold" (not in cpu cache) */
|
int ddictIsCold; /* if == 1 : dictionary is "new" for working context, and presumed "cold" (not in cpu cache) */
|
||||||
ZSTD_dictUses_e dictUses;
|
ZSTD_dictUses_e dictUses;
|
||||||
|
ZSTD_DDictHashSet* ddictSet; /* Hash set for multiple ddicts */
|
||||||
|
ZSTD_refMultipleDDicts_e refMultipleDDicts; /* User specified: if == 1, will allow references to multiple DDicts. Default == 0 (disabled) */
|
||||||
|
int disableHufAsm;
|
||||||
|
|
||||||
/* streaming */
|
/* streaming */
|
||||||
ZSTD_dStreamStage streamStage;
|
ZSTD_dStreamStage streamStage;
|
||||||
@@ -142,17 +179,44 @@ struct ZSTD_DCtx_s
|
|||||||
size_t outStart;
|
size_t outStart;
|
||||||
size_t outEnd;
|
size_t outEnd;
|
||||||
size_t lhSize;
|
size_t lhSize;
|
||||||
|
#if defined(ZSTD_LEGACY_SUPPORT) && (ZSTD_LEGACY_SUPPORT>=1)
|
||||||
void* legacyContext;
|
void* legacyContext;
|
||||||
U32 previousLegacyVersion;
|
U32 previousLegacyVersion;
|
||||||
U32 legacyVersion;
|
U32 legacyVersion;
|
||||||
|
#endif
|
||||||
U32 hostageByte;
|
U32 hostageByte;
|
||||||
int noForwardProgress;
|
int noForwardProgress;
|
||||||
|
ZSTD_bufferMode_e outBufferMode;
|
||||||
|
ZSTD_outBuffer expectedOutBuffer;
|
||||||
|
|
||||||
/* workspace */
|
/* workspace */
|
||||||
BYTE litBuffer[ZSTD_BLOCKSIZE_MAX + WILDCOPY_OVERLENGTH];
|
BYTE* litBuffer;
|
||||||
|
const BYTE* litBufferEnd;
|
||||||
|
ZSTD_litLocation_e litBufferLocation;
|
||||||
|
BYTE litExtraBuffer[ZSTD_LITBUFFEREXTRASIZE + WILDCOPY_OVERLENGTH]; /* literal buffer can be split between storage within dst and within this scratch buffer */
|
||||||
BYTE headerBuffer[ZSTD_FRAMEHEADERSIZE_MAX];
|
BYTE headerBuffer[ZSTD_FRAMEHEADERSIZE_MAX];
|
||||||
|
|
||||||
|
size_t oversizedDuration;
|
||||||
|
|
||||||
|
#ifdef FUZZING_BUILD_MODE_UNSAFE_FOR_PRODUCTION
|
||||||
|
void const* dictContentBeginForFuzzing;
|
||||||
|
void const* dictContentEndForFuzzing;
|
||||||
|
#endif
|
||||||
|
|
||||||
|
/* Tracing */
|
||||||
|
#if ZSTD_TRACE
|
||||||
|
ZSTD_TraceCtx traceCtx;
|
||||||
|
#endif
|
||||||
}; /* typedef'd to ZSTD_DCtx within "zstd.h" */
|
}; /* typedef'd to ZSTD_DCtx within "zstd.h" */
|
||||||
|
|
||||||
|
MEM_STATIC int ZSTD_DCtx_get_bmi2(const struct ZSTD_DCtx_s *dctx) {
|
||||||
|
#if DYNAMIC_BMI2 != 0
|
||||||
|
return dctx->bmi2;
|
||||||
|
#else
|
||||||
|
(void)dctx;
|
||||||
|
return 0;
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
|
||||||
/*-*******************************************************
|
/*-*******************************************************
|
||||||
* Shared internal functions
|
* Shared internal functions
|
||||||
@@ -160,7 +224,7 @@ struct ZSTD_DCtx_s
|
|||||||
|
|
||||||
/*! ZSTD_loadDEntropy() :
|
/*! ZSTD_loadDEntropy() :
|
||||||
* dict : must point at beginning of a valid zstd dictionary.
|
* dict : must point at beginning of a valid zstd dictionary.
|
||||||
* @return : size of entropy tables read */
|
* @return : size of dictionary header (size of magic number + dict ID + entropy tables) */
|
||||||
size_t ZSTD_loadDEntropy(ZSTD_entropyDTables_t* entropy,
|
size_t ZSTD_loadDEntropy(ZSTD_entropyDTables_t* entropy,
|
||||||
const void* const dict, size_t const dictSize);
|
const void* const dict, size_t const dictSize);
|
||||||
|
|
||||||
@@ -169,7 +233,9 @@ size_t ZSTD_loadDEntropy(ZSTD_entropyDTables_t* entropy,
|
|||||||
* If yes, do nothing (continue on current segment).
|
* If yes, do nothing (continue on current segment).
|
||||||
* If not, classify previous segment as "external dictionary", and start a new segment.
|
* If not, classify previous segment as "external dictionary", and start a new segment.
|
||||||
* This function cannot fail. */
|
* This function cannot fail. */
|
||||||
void ZSTD_checkContinuity(ZSTD_DCtx* dctx, const void* dst);
|
void ZSTD_checkContinuity(ZSTD_DCtx* dctx, const void* dst, size_t dstSize);
|
||||||
|
|
||||||
|
|
||||||
#endif /* ZSTD_DECOMPRESS_INTERNAL_H */
|
#endif /* ZSTD_DECOMPRESS_INTERNAL_H */
|
||||||
|
|
||||||
|
#endif /* USE_EXTERNAL_ZSTD */
|
||||||
|
|||||||
114
vendor/github.com/DataDog/zstd/zstd_deps.h
generated
vendored
Normal file
114
vendor/github.com/DataDog/zstd/zstd_deps.h
generated
vendored
Normal file
@@ -0,0 +1,114 @@
|
|||||||
|
#ifndef USE_EXTERNAL_ZSTD
|
||||||
|
/*
|
||||||
|
* Copyright (c) Meta Platforms, Inc. and affiliates.
|
||||||
|
* All rights reserved.
|
||||||
|
*
|
||||||
|
* This source code is licensed under both the BSD-style license (found in the
|
||||||
|
* LICENSE file in the root directory of this source tree) and the GPLv2 (found
|
||||||
|
* in the COPYING file in the root directory of this source tree).
|
||||||
|
* You may select, at your option, one of the above-listed licenses.
|
||||||
|
*/
|
||||||
|
|
||||||
|
/* This file provides common libc dependencies that zstd requires.
|
||||||
|
* The purpose is to allow replacing this file with a custom implementation
|
||||||
|
* to compile zstd without libc support.
|
||||||
|
*/
|
||||||
|
|
||||||
|
/* Need:
|
||||||
|
* NULL
|
||||||
|
* INT_MAX
|
||||||
|
* UINT_MAX
|
||||||
|
* ZSTD_memcpy()
|
||||||
|
* ZSTD_memset()
|
||||||
|
* ZSTD_memmove()
|
||||||
|
*/
|
||||||
|
#ifndef ZSTD_DEPS_COMMON
|
||||||
|
#define ZSTD_DEPS_COMMON
|
||||||
|
|
||||||
|
#include <limits.h>
|
||||||
|
#include <stddef.h>
|
||||||
|
#include <string.h>
|
||||||
|
|
||||||
|
#if defined(__GNUC__) && __GNUC__ >= 4
|
||||||
|
# define ZSTD_memcpy(d,s,l) __builtin_memcpy((d),(s),(l))
|
||||||
|
# define ZSTD_memmove(d,s,l) __builtin_memmove((d),(s),(l))
|
||||||
|
# define ZSTD_memset(p,v,l) __builtin_memset((p),(v),(l))
|
||||||
|
#else
|
||||||
|
# define ZSTD_memcpy(d,s,l) memcpy((d),(s),(l))
|
||||||
|
# define ZSTD_memmove(d,s,l) memmove((d),(s),(l))
|
||||||
|
# define ZSTD_memset(p,v,l) memset((p),(v),(l))
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#endif /* ZSTD_DEPS_COMMON */
|
||||||
|
|
||||||
|
/* Need:
|
||||||
|
* ZSTD_malloc()
|
||||||
|
* ZSTD_free()
|
||||||
|
* ZSTD_calloc()
|
||||||
|
*/
|
||||||
|
#ifdef ZSTD_DEPS_NEED_MALLOC
|
||||||
|
#ifndef ZSTD_DEPS_MALLOC
|
||||||
|
#define ZSTD_DEPS_MALLOC
|
||||||
|
|
||||||
|
#include <stdlib.h>
|
||||||
|
|
||||||
|
#define ZSTD_malloc(s) malloc(s)
|
||||||
|
#define ZSTD_calloc(n,s) calloc((n), (s))
|
||||||
|
#define ZSTD_free(p) free((p))
|
||||||
|
|
||||||
|
#endif /* ZSTD_DEPS_MALLOC */
|
||||||
|
#endif /* ZSTD_DEPS_NEED_MALLOC */
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Provides 64-bit math support.
|
||||||
|
* Need:
|
||||||
|
* U64 ZSTD_div64(U64 dividend, U32 divisor)
|
||||||
|
*/
|
||||||
|
#ifdef ZSTD_DEPS_NEED_MATH64
|
||||||
|
#ifndef ZSTD_DEPS_MATH64
|
||||||
|
#define ZSTD_DEPS_MATH64
|
||||||
|
|
||||||
|
#define ZSTD_div64(dividend, divisor) ((dividend) / (divisor))
|
||||||
|
|
||||||
|
#endif /* ZSTD_DEPS_MATH64 */
|
||||||
|
#endif /* ZSTD_DEPS_NEED_MATH64 */
|
||||||
|
|
||||||
|
/* Need:
|
||||||
|
* assert()
|
||||||
|
*/
|
||||||
|
#ifdef ZSTD_DEPS_NEED_ASSERT
|
||||||
|
#ifndef ZSTD_DEPS_ASSERT
|
||||||
|
#define ZSTD_DEPS_ASSERT
|
||||||
|
|
||||||
|
#include <assert.h>
|
||||||
|
|
||||||
|
#endif /* ZSTD_DEPS_ASSERT */
|
||||||
|
#endif /* ZSTD_DEPS_NEED_ASSERT */
|
||||||
|
|
||||||
|
/* Need:
|
||||||
|
* ZSTD_DEBUG_PRINT()
|
||||||
|
*/
|
||||||
|
#ifdef ZSTD_DEPS_NEED_IO
|
||||||
|
#ifndef ZSTD_DEPS_IO
|
||||||
|
#define ZSTD_DEPS_IO
|
||||||
|
|
||||||
|
#include <stdio.h>
|
||||||
|
#define ZSTD_DEBUG_PRINT(...) fprintf(stderr, __VA_ARGS__)
|
||||||
|
|
||||||
|
#endif /* ZSTD_DEPS_IO */
|
||||||
|
#endif /* ZSTD_DEPS_NEED_IO */
|
||||||
|
|
||||||
|
/* Only requested when <stdint.h> is known to be present.
|
||||||
|
* Need:
|
||||||
|
* intptr_t
|
||||||
|
*/
|
||||||
|
#ifdef ZSTD_DEPS_NEED_STDINT
|
||||||
|
#ifndef ZSTD_DEPS_STDINT
|
||||||
|
#define ZSTD_DEPS_STDINT
|
||||||
|
|
||||||
|
#include <stdint.h>
|
||||||
|
|
||||||
|
#endif /* ZSTD_DEPS_STDINT */
|
||||||
|
#endif /* ZSTD_DEPS_NEED_STDINT */
|
||||||
|
|
||||||
|
#endif /* USE_EXTERNAL_ZSTD */
|
||||||
509
vendor/github.com/DataDog/zstd/zstd_double_fast.c
generated
vendored
509
vendor/github.com/DataDog/zstd/zstd_double_fast.c
generated
vendored
@@ -1,5 +1,6 @@
|
|||||||
|
#ifndef USE_EXTERNAL_ZSTD
|
||||||
/*
|
/*
|
||||||
* Copyright (c) 2016-present, Yann Collet, Facebook, Inc.
|
* Copyright (c) Meta Platforms, Inc. and affiliates.
|
||||||
* All rights reserved.
|
* All rights reserved.
|
||||||
*
|
*
|
||||||
* This source code is licensed under both the BSD-style license (found in the
|
* This source code is licensed under both the BSD-style license (found in the
|
||||||
@@ -11,8 +12,43 @@
|
|||||||
#include "zstd_compress_internal.h"
|
#include "zstd_compress_internal.h"
|
||||||
#include "zstd_double_fast.h"
|
#include "zstd_double_fast.h"
|
||||||
|
|
||||||
|
static void ZSTD_fillDoubleHashTableForCDict(ZSTD_matchState_t* ms,
|
||||||
|
void const* end, ZSTD_dictTableLoadMethod_e dtlm)
|
||||||
|
{
|
||||||
|
const ZSTD_compressionParameters* const cParams = &ms->cParams;
|
||||||
|
U32* const hashLarge = ms->hashTable;
|
||||||
|
U32 const hBitsL = cParams->hashLog + ZSTD_SHORT_CACHE_TAG_BITS;
|
||||||
|
U32 const mls = cParams->minMatch;
|
||||||
|
U32* const hashSmall = ms->chainTable;
|
||||||
|
U32 const hBitsS = cParams->chainLog + ZSTD_SHORT_CACHE_TAG_BITS;
|
||||||
|
const BYTE* const base = ms->window.base;
|
||||||
|
const BYTE* ip = base + ms->nextToUpdate;
|
||||||
|
const BYTE* const iend = ((const BYTE*)end) - HASH_READ_SIZE;
|
||||||
|
const U32 fastHashFillStep = 3;
|
||||||
|
|
||||||
void ZSTD_fillDoubleHashTable(ZSTD_matchState_t* ms,
|
/* Always insert every fastHashFillStep position into the hash tables.
|
||||||
|
* Insert the other positions into the large hash table if their entry
|
||||||
|
* is empty.
|
||||||
|
*/
|
||||||
|
for (; ip + fastHashFillStep - 1 <= iend; ip += fastHashFillStep) {
|
||||||
|
U32 const curr = (U32)(ip - base);
|
||||||
|
U32 i;
|
||||||
|
for (i = 0; i < fastHashFillStep; ++i) {
|
||||||
|
size_t const smHashAndTag = ZSTD_hashPtr(ip + i, hBitsS, mls);
|
||||||
|
size_t const lgHashAndTag = ZSTD_hashPtr(ip + i, hBitsL, 8);
|
||||||
|
if (i == 0) {
|
||||||
|
ZSTD_writeTaggedIndex(hashSmall, smHashAndTag, curr + i);
|
||||||
|
}
|
||||||
|
if (i == 0 || hashLarge[lgHashAndTag >> ZSTD_SHORT_CACHE_TAG_BITS] == 0) {
|
||||||
|
ZSTD_writeTaggedIndex(hashLarge, lgHashAndTag, curr + i);
|
||||||
|
}
|
||||||
|
/* Only load extra positions for ZSTD_dtlm_full */
|
||||||
|
if (dtlm == ZSTD_dtlm_fast)
|
||||||
|
break;
|
||||||
|
} }
|
||||||
|
}
|
||||||
|
|
||||||
|
static void ZSTD_fillDoubleHashTableForCCtx(ZSTD_matchState_t* ms,
|
||||||
void const* end, ZSTD_dictTableLoadMethod_e dtlm)
|
void const* end, ZSTD_dictTableLoadMethod_e dtlm)
|
||||||
{
|
{
|
||||||
const ZSTD_compressionParameters* const cParams = &ms->cParams;
|
const ZSTD_compressionParameters* const cParams = &ms->cParams;
|
||||||
@@ -31,27 +67,249 @@ void ZSTD_fillDoubleHashTable(ZSTD_matchState_t* ms,
|
|||||||
* is empty.
|
* is empty.
|
||||||
*/
|
*/
|
||||||
for (; ip + fastHashFillStep - 1 <= iend; ip += fastHashFillStep) {
|
for (; ip + fastHashFillStep - 1 <= iend; ip += fastHashFillStep) {
|
||||||
U32 const current = (U32)(ip - base);
|
U32 const curr = (U32)(ip - base);
|
||||||
U32 i;
|
U32 i;
|
||||||
for (i = 0; i < fastHashFillStep; ++i) {
|
for (i = 0; i < fastHashFillStep; ++i) {
|
||||||
size_t const smHash = ZSTD_hashPtr(ip + i, hBitsS, mls);
|
size_t const smHash = ZSTD_hashPtr(ip + i, hBitsS, mls);
|
||||||
size_t const lgHash = ZSTD_hashPtr(ip + i, hBitsL, 8);
|
size_t const lgHash = ZSTD_hashPtr(ip + i, hBitsL, 8);
|
||||||
if (i == 0)
|
if (i == 0)
|
||||||
hashSmall[smHash] = current + i;
|
hashSmall[smHash] = curr + i;
|
||||||
if (i == 0 || hashLarge[lgHash] == 0)
|
if (i == 0 || hashLarge[lgHash] == 0)
|
||||||
hashLarge[lgHash] = current + i;
|
hashLarge[lgHash] = curr + i;
|
||||||
/* Only load extra positions for ZSTD_dtlm_full */
|
/* Only load extra positions for ZSTD_dtlm_full */
|
||||||
if (dtlm == ZSTD_dtlm_fast)
|
if (dtlm == ZSTD_dtlm_fast)
|
||||||
break;
|
break;
|
||||||
} }
|
} }
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void ZSTD_fillDoubleHashTable(ZSTD_matchState_t* ms,
|
||||||
|
const void* const end,
|
||||||
|
ZSTD_dictTableLoadMethod_e dtlm,
|
||||||
|
ZSTD_tableFillPurpose_e tfp)
|
||||||
|
{
|
||||||
|
if (tfp == ZSTD_tfp_forCDict) {
|
||||||
|
ZSTD_fillDoubleHashTableForCDict(ms, end, dtlm);
|
||||||
|
} else {
|
||||||
|
ZSTD_fillDoubleHashTableForCCtx(ms, end, dtlm);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
FORCE_INLINE_TEMPLATE
|
FORCE_INLINE_TEMPLATE
|
||||||
size_t ZSTD_compressBlock_doubleFast_generic(
|
size_t ZSTD_compressBlock_doubleFast_noDict_generic(
|
||||||
|
ZSTD_matchState_t* ms, seqStore_t* seqStore, U32 rep[ZSTD_REP_NUM],
|
||||||
|
void const* src, size_t srcSize, U32 const mls /* template */)
|
||||||
|
{
|
||||||
|
ZSTD_compressionParameters const* cParams = &ms->cParams;
|
||||||
|
U32* const hashLong = ms->hashTable;
|
||||||
|
const U32 hBitsL = cParams->hashLog;
|
||||||
|
U32* const hashSmall = ms->chainTable;
|
||||||
|
const U32 hBitsS = cParams->chainLog;
|
||||||
|
const BYTE* const base = ms->window.base;
|
||||||
|
const BYTE* const istart = (const BYTE*)src;
|
||||||
|
const BYTE* anchor = istart;
|
||||||
|
const U32 endIndex = (U32)((size_t)(istart - base) + srcSize);
|
||||||
|
/* presumes that, if there is a dictionary, it must be using Attach mode */
|
||||||
|
const U32 prefixLowestIndex = ZSTD_getLowestPrefixIndex(ms, endIndex, cParams->windowLog);
|
||||||
|
const BYTE* const prefixLowest = base + prefixLowestIndex;
|
||||||
|
const BYTE* const iend = istart + srcSize;
|
||||||
|
const BYTE* const ilimit = iend - HASH_READ_SIZE;
|
||||||
|
U32 offset_1=rep[0], offset_2=rep[1];
|
||||||
|
U32 offsetSaved1 = 0, offsetSaved2 = 0;
|
||||||
|
|
||||||
|
size_t mLength;
|
||||||
|
U32 offset;
|
||||||
|
U32 curr;
|
||||||
|
|
||||||
|
/* how many positions to search before increasing step size */
|
||||||
|
const size_t kStepIncr = 1 << kSearchStrength;
|
||||||
|
/* the position at which to increment the step size if no match is found */
|
||||||
|
const BYTE* nextStep;
|
||||||
|
size_t step; /* the current step size */
|
||||||
|
|
||||||
|
size_t hl0; /* the long hash at ip */
|
||||||
|
size_t hl1; /* the long hash at ip1 */
|
||||||
|
|
||||||
|
U32 idxl0; /* the long match index for ip */
|
||||||
|
U32 idxl1; /* the long match index for ip1 */
|
||||||
|
|
||||||
|
const BYTE* matchl0; /* the long match for ip */
|
||||||
|
const BYTE* matchs0; /* the short match for ip */
|
||||||
|
const BYTE* matchl1; /* the long match for ip1 */
|
||||||
|
|
||||||
|
const BYTE* ip = istart; /* the current position */
|
||||||
|
const BYTE* ip1; /* the next position */
|
||||||
|
|
||||||
|
DEBUGLOG(5, "ZSTD_compressBlock_doubleFast_noDict_generic");
|
||||||
|
|
||||||
|
/* init */
|
||||||
|
ip += ((ip - prefixLowest) == 0);
|
||||||
|
{
|
||||||
|
U32 const current = (U32)(ip - base);
|
||||||
|
U32 const windowLow = ZSTD_getLowestPrefixIndex(ms, current, cParams->windowLog);
|
||||||
|
U32 const maxRep = current - windowLow;
|
||||||
|
if (offset_2 > maxRep) offsetSaved2 = offset_2, offset_2 = 0;
|
||||||
|
if (offset_1 > maxRep) offsetSaved1 = offset_1, offset_1 = 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Outer Loop: one iteration per match found and stored */
|
||||||
|
while (1) {
|
||||||
|
step = 1;
|
||||||
|
nextStep = ip + kStepIncr;
|
||||||
|
ip1 = ip + step;
|
||||||
|
|
||||||
|
if (ip1 > ilimit) {
|
||||||
|
goto _cleanup;
|
||||||
|
}
|
||||||
|
|
||||||
|
hl0 = ZSTD_hashPtr(ip, hBitsL, 8);
|
||||||
|
idxl0 = hashLong[hl0];
|
||||||
|
matchl0 = base + idxl0;
|
||||||
|
|
||||||
|
/* Inner Loop: one iteration per search / position */
|
||||||
|
do {
|
||||||
|
const size_t hs0 = ZSTD_hashPtr(ip, hBitsS, mls);
|
||||||
|
const U32 idxs0 = hashSmall[hs0];
|
||||||
|
curr = (U32)(ip-base);
|
||||||
|
matchs0 = base + idxs0;
|
||||||
|
|
||||||
|
hashLong[hl0] = hashSmall[hs0] = curr; /* update hash tables */
|
||||||
|
|
||||||
|
/* check noDict repcode */
|
||||||
|
if ((offset_1 > 0) & (MEM_read32(ip+1-offset_1) == MEM_read32(ip+1))) {
|
||||||
|
mLength = ZSTD_count(ip+1+4, ip+1+4-offset_1, iend) + 4;
|
||||||
|
ip++;
|
||||||
|
ZSTD_storeSeq(seqStore, (size_t)(ip-anchor), anchor, iend, REPCODE1_TO_OFFBASE, mLength);
|
||||||
|
goto _match_stored;
|
||||||
|
}
|
||||||
|
|
||||||
|
hl1 = ZSTD_hashPtr(ip1, hBitsL, 8);
|
||||||
|
|
||||||
|
if (idxl0 > prefixLowestIndex) {
|
||||||
|
/* check prefix long match */
|
||||||
|
if (MEM_read64(matchl0) == MEM_read64(ip)) {
|
||||||
|
mLength = ZSTD_count(ip+8, matchl0+8, iend) + 8;
|
||||||
|
offset = (U32)(ip-matchl0);
|
||||||
|
while (((ip>anchor) & (matchl0>prefixLowest)) && (ip[-1] == matchl0[-1])) { ip--; matchl0--; mLength++; } /* catch up */
|
||||||
|
goto _match_found;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
idxl1 = hashLong[hl1];
|
||||||
|
matchl1 = base + idxl1;
|
||||||
|
|
||||||
|
if (idxs0 > prefixLowestIndex) {
|
||||||
|
/* check prefix short match */
|
||||||
|
if (MEM_read32(matchs0) == MEM_read32(ip)) {
|
||||||
|
goto _search_next_long;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (ip1 >= nextStep) {
|
||||||
|
PREFETCH_L1(ip1 + 64);
|
||||||
|
PREFETCH_L1(ip1 + 128);
|
||||||
|
step++;
|
||||||
|
nextStep += kStepIncr;
|
||||||
|
}
|
||||||
|
ip = ip1;
|
||||||
|
ip1 += step;
|
||||||
|
|
||||||
|
hl0 = hl1;
|
||||||
|
idxl0 = idxl1;
|
||||||
|
matchl0 = matchl1;
|
||||||
|
#if defined(__aarch64__)
|
||||||
|
PREFETCH_L1(ip+256);
|
||||||
|
#endif
|
||||||
|
} while (ip1 <= ilimit);
|
||||||
|
|
||||||
|
_cleanup:
|
||||||
|
/* If offset_1 started invalid (offsetSaved1 != 0) and became valid (offset_1 != 0),
|
||||||
|
* rotate saved offsets. See comment in ZSTD_compressBlock_fast_noDict for more context. */
|
||||||
|
offsetSaved2 = ((offsetSaved1 != 0) && (offset_1 != 0)) ? offsetSaved1 : offsetSaved2;
|
||||||
|
|
||||||
|
/* save reps for next block */
|
||||||
|
rep[0] = offset_1 ? offset_1 : offsetSaved1;
|
||||||
|
rep[1] = offset_2 ? offset_2 : offsetSaved2;
|
||||||
|
|
||||||
|
/* Return the last literals size */
|
||||||
|
return (size_t)(iend - anchor);
|
||||||
|
|
||||||
|
_search_next_long:
|
||||||
|
|
||||||
|
/* check prefix long +1 match */
|
||||||
|
if (idxl1 > prefixLowestIndex) {
|
||||||
|
if (MEM_read64(matchl1) == MEM_read64(ip1)) {
|
||||||
|
ip = ip1;
|
||||||
|
mLength = ZSTD_count(ip+8, matchl1+8, iend) + 8;
|
||||||
|
offset = (U32)(ip-matchl1);
|
||||||
|
while (((ip>anchor) & (matchl1>prefixLowest)) && (ip[-1] == matchl1[-1])) { ip--; matchl1--; mLength++; } /* catch up */
|
||||||
|
goto _match_found;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/* if no long +1 match, explore the short match we found */
|
||||||
|
mLength = ZSTD_count(ip+4, matchs0+4, iend) + 4;
|
||||||
|
offset = (U32)(ip - matchs0);
|
||||||
|
while (((ip>anchor) & (matchs0>prefixLowest)) && (ip[-1] == matchs0[-1])) { ip--; matchs0--; mLength++; } /* catch up */
|
||||||
|
|
||||||
|
/* fall-through */
|
||||||
|
|
||||||
|
_match_found: /* requires ip, offset, mLength */
|
||||||
|
offset_2 = offset_1;
|
||||||
|
offset_1 = offset;
|
||||||
|
|
||||||
|
if (step < 4) {
|
||||||
|
/* It is unsafe to write this value back to the hashtable when ip1 is
|
||||||
|
* greater than or equal to the new ip we will have after we're done
|
||||||
|
* processing this match. Rather than perform that test directly
|
||||||
|
* (ip1 >= ip + mLength), which costs speed in practice, we do a simpler
|
||||||
|
* more predictable test. The minmatch even if we take a short match is
|
||||||
|
* 4 bytes, so as long as step, the distance between ip and ip1
|
||||||
|
* (initially) is less than 4, we know ip1 < new ip. */
|
||||||
|
hashLong[hl1] = (U32)(ip1 - base);
|
||||||
|
}
|
||||||
|
|
||||||
|
ZSTD_storeSeq(seqStore, (size_t)(ip-anchor), anchor, iend, OFFSET_TO_OFFBASE(offset), mLength);
|
||||||
|
|
||||||
|
_match_stored:
|
||||||
|
/* match found */
|
||||||
|
ip += mLength;
|
||||||
|
anchor = ip;
|
||||||
|
|
||||||
|
if (ip <= ilimit) {
|
||||||
|
/* Complementary insertion */
|
||||||
|
/* done after iLimit test, as candidates could be > iend-8 */
|
||||||
|
{ U32 const indexToInsert = curr+2;
|
||||||
|
hashLong[ZSTD_hashPtr(base+indexToInsert, hBitsL, 8)] = indexToInsert;
|
||||||
|
hashLong[ZSTD_hashPtr(ip-2, hBitsL, 8)] = (U32)(ip-2-base);
|
||||||
|
hashSmall[ZSTD_hashPtr(base+indexToInsert, hBitsS, mls)] = indexToInsert;
|
||||||
|
hashSmall[ZSTD_hashPtr(ip-1, hBitsS, mls)] = (U32)(ip-1-base);
|
||||||
|
}
|
||||||
|
|
||||||
|
/* check immediate repcode */
|
||||||
|
while ( (ip <= ilimit)
|
||||||
|
&& ( (offset_2>0)
|
||||||
|
& (MEM_read32(ip) == MEM_read32(ip - offset_2)) )) {
|
||||||
|
/* store sequence */
|
||||||
|
size_t const rLength = ZSTD_count(ip+4, ip+4-offset_2, iend) + 4;
|
||||||
|
U32 const tmpOff = offset_2; offset_2 = offset_1; offset_1 = tmpOff; /* swap offset_2 <=> offset_1 */
|
||||||
|
hashSmall[ZSTD_hashPtr(ip, hBitsS, mls)] = (U32)(ip-base);
|
||||||
|
hashLong[ZSTD_hashPtr(ip, hBitsL, 8)] = (U32)(ip-base);
|
||||||
|
ZSTD_storeSeq(seqStore, 0, anchor, iend, REPCODE1_TO_OFFBASE, rLength);
|
||||||
|
ip += rLength;
|
||||||
|
anchor = ip;
|
||||||
|
continue; /* faster when present ... (?) */
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
FORCE_INLINE_TEMPLATE
|
||||||
|
size_t ZSTD_compressBlock_doubleFast_dictMatchState_generic(
|
||||||
ZSTD_matchState_t* ms, seqStore_t* seqStore, U32 rep[ZSTD_REP_NUM],
|
ZSTD_matchState_t* ms, seqStore_t* seqStore, U32 rep[ZSTD_REP_NUM],
|
||||||
void const* src, size_t srcSize,
|
void const* src, size_t srcSize,
|
||||||
U32 const mls /* template */, ZSTD_dictMode_e const dictMode)
|
U32 const mls /* template */)
|
||||||
{
|
{
|
||||||
ZSTD_compressionParameters const* cParams = &ms->cParams;
|
ZSTD_compressionParameters const* cParams = &ms->cParams;
|
||||||
U32* const hashLong = ms->hashTable;
|
U32* const hashLong = ms->hashTable;
|
||||||
@@ -63,63 +321,45 @@ size_t ZSTD_compressBlock_doubleFast_generic(
|
|||||||
const BYTE* ip = istart;
|
const BYTE* ip = istart;
|
||||||
const BYTE* anchor = istart;
|
const BYTE* anchor = istart;
|
||||||
const U32 endIndex = (U32)((size_t)(istart - base) + srcSize);
|
const U32 endIndex = (U32)((size_t)(istart - base) + srcSize);
|
||||||
const U32 lowestValid = ms->window.dictLimit;
|
|
||||||
const U32 maxDistance = 1U << cParams->windowLog;
|
|
||||||
/* presumes that, if there is a dictionary, it must be using Attach mode */
|
/* presumes that, if there is a dictionary, it must be using Attach mode */
|
||||||
const U32 prefixLowestIndex = (endIndex - lowestValid > maxDistance) ? endIndex - maxDistance : lowestValid;
|
const U32 prefixLowestIndex = ZSTD_getLowestPrefixIndex(ms, endIndex, cParams->windowLog);
|
||||||
const BYTE* const prefixLowest = base + prefixLowestIndex;
|
const BYTE* const prefixLowest = base + prefixLowestIndex;
|
||||||
const BYTE* const iend = istart + srcSize;
|
const BYTE* const iend = istart + srcSize;
|
||||||
const BYTE* const ilimit = iend - HASH_READ_SIZE;
|
const BYTE* const ilimit = iend - HASH_READ_SIZE;
|
||||||
U32 offset_1=rep[0], offset_2=rep[1];
|
U32 offset_1=rep[0], offset_2=rep[1];
|
||||||
U32 offsetSaved = 0;
|
|
||||||
|
|
||||||
const ZSTD_matchState_t* const dms = ms->dictMatchState;
|
const ZSTD_matchState_t* const dms = ms->dictMatchState;
|
||||||
const ZSTD_compressionParameters* const dictCParams =
|
const ZSTD_compressionParameters* const dictCParams = &dms->cParams;
|
||||||
dictMode == ZSTD_dictMatchState ?
|
const U32* const dictHashLong = dms->hashTable;
|
||||||
&dms->cParams : NULL;
|
const U32* const dictHashSmall = dms->chainTable;
|
||||||
const U32* const dictHashLong = dictMode == ZSTD_dictMatchState ?
|
const U32 dictStartIndex = dms->window.dictLimit;
|
||||||
dms->hashTable : NULL;
|
const BYTE* const dictBase = dms->window.base;
|
||||||
const U32* const dictHashSmall = dictMode == ZSTD_dictMatchState ?
|
const BYTE* const dictStart = dictBase + dictStartIndex;
|
||||||
dms->chainTable : NULL;
|
const BYTE* const dictEnd = dms->window.nextSrc;
|
||||||
const U32 dictStartIndex = dictMode == ZSTD_dictMatchState ?
|
const U32 dictIndexDelta = prefixLowestIndex - (U32)(dictEnd - dictBase);
|
||||||
dms->window.dictLimit : 0;
|
const U32 dictHBitsL = dictCParams->hashLog + ZSTD_SHORT_CACHE_TAG_BITS;
|
||||||
const BYTE* const dictBase = dictMode == ZSTD_dictMatchState ?
|
const U32 dictHBitsS = dictCParams->chainLog + ZSTD_SHORT_CACHE_TAG_BITS;
|
||||||
dms->window.base : NULL;
|
const U32 dictAndPrefixLength = (U32)((ip - prefixLowest) + (dictEnd - dictStart));
|
||||||
const BYTE* const dictStart = dictMode == ZSTD_dictMatchState ?
|
|
||||||
dictBase + dictStartIndex : NULL;
|
|
||||||
const BYTE* const dictEnd = dictMode == ZSTD_dictMatchState ?
|
|
||||||
dms->window.nextSrc : NULL;
|
|
||||||
const U32 dictIndexDelta = dictMode == ZSTD_dictMatchState ?
|
|
||||||
prefixLowestIndex - (U32)(dictEnd - dictBase) :
|
|
||||||
0;
|
|
||||||
const U32 dictHBitsL = dictMode == ZSTD_dictMatchState ?
|
|
||||||
dictCParams->hashLog : hBitsL;
|
|
||||||
const U32 dictHBitsS = dictMode == ZSTD_dictMatchState ?
|
|
||||||
dictCParams->chainLog : hBitsS;
|
|
||||||
const U32 dictAndPrefixLength = (U32)(ip - prefixLowest + dictEnd - dictStart);
|
|
||||||
|
|
||||||
DEBUGLOG(5, "ZSTD_compressBlock_doubleFast_generic");
|
DEBUGLOG(5, "ZSTD_compressBlock_doubleFast_dictMatchState_generic");
|
||||||
|
|
||||||
assert(dictMode == ZSTD_noDict || dictMode == ZSTD_dictMatchState);
|
|
||||||
|
|
||||||
/* if a dictionary is attached, it must be within window range */
|
/* if a dictionary is attached, it must be within window range */
|
||||||
if (dictMode == ZSTD_dictMatchState) {
|
assert(ms->window.dictLimit + (1U << cParams->windowLog) >= endIndex);
|
||||||
assert(lowestValid + maxDistance >= endIndex);
|
|
||||||
|
if (ms->prefetchCDictTables) {
|
||||||
|
size_t const hashTableBytes = (((size_t)1) << dictCParams->hashLog) * sizeof(U32);
|
||||||
|
size_t const chainTableBytes = (((size_t)1) << dictCParams->chainLog) * sizeof(U32);
|
||||||
|
PREFETCH_AREA(dictHashLong, hashTableBytes)
|
||||||
|
PREFETCH_AREA(dictHashSmall, chainTableBytes)
|
||||||
}
|
}
|
||||||
|
|
||||||
/* init */
|
/* init */
|
||||||
ip += (dictAndPrefixLength == 0);
|
ip += (dictAndPrefixLength == 0);
|
||||||
if (dictMode == ZSTD_noDict) {
|
|
||||||
U32 const maxRep = (U32)(ip - prefixLowest);
|
|
||||||
if (offset_2 > maxRep) offsetSaved = offset_2, offset_2 = 0;
|
|
||||||
if (offset_1 > maxRep) offsetSaved = offset_1, offset_1 = 0;
|
|
||||||
}
|
|
||||||
if (dictMode == ZSTD_dictMatchState) {
|
|
||||||
/* dictMatchState repCode checks don't currently handle repCode == 0
|
/* dictMatchState repCode checks don't currently handle repCode == 0
|
||||||
* disabling. */
|
* disabling. */
|
||||||
assert(offset_1 <= dictAndPrefixLength);
|
assert(offset_1 <= dictAndPrefixLength);
|
||||||
assert(offset_2 <= dictAndPrefixLength);
|
assert(offset_2 <= dictAndPrefixLength);
|
||||||
}
|
|
||||||
|
|
||||||
/* Main Search Loop */
|
/* Main Search Loop */
|
||||||
while (ip < ilimit) { /* < instead of <=, because repcode check at (ip+1) */
|
while (ip < ilimit) { /* < instead of <=, because repcode check at (ip+1) */
|
||||||
@@ -127,37 +367,30 @@ size_t ZSTD_compressBlock_doubleFast_generic(
|
|||||||
U32 offset;
|
U32 offset;
|
||||||
size_t const h2 = ZSTD_hashPtr(ip, hBitsL, 8);
|
size_t const h2 = ZSTD_hashPtr(ip, hBitsL, 8);
|
||||||
size_t const h = ZSTD_hashPtr(ip, hBitsS, mls);
|
size_t const h = ZSTD_hashPtr(ip, hBitsS, mls);
|
||||||
size_t const dictHL = ZSTD_hashPtr(ip, dictHBitsL, 8);
|
size_t const dictHashAndTagL = ZSTD_hashPtr(ip, dictHBitsL, 8);
|
||||||
size_t const dictHS = ZSTD_hashPtr(ip, dictHBitsS, mls);
|
size_t const dictHashAndTagS = ZSTD_hashPtr(ip, dictHBitsS, mls);
|
||||||
U32 const current = (U32)(ip-base);
|
U32 const dictMatchIndexAndTagL = dictHashLong[dictHashAndTagL >> ZSTD_SHORT_CACHE_TAG_BITS];
|
||||||
|
U32 const dictMatchIndexAndTagS = dictHashSmall[dictHashAndTagS >> ZSTD_SHORT_CACHE_TAG_BITS];
|
||||||
|
int const dictTagsMatchL = ZSTD_comparePackedTags(dictMatchIndexAndTagL, dictHashAndTagL);
|
||||||
|
int const dictTagsMatchS = ZSTD_comparePackedTags(dictMatchIndexAndTagS, dictHashAndTagS);
|
||||||
|
U32 const curr = (U32)(ip-base);
|
||||||
U32 const matchIndexL = hashLong[h2];
|
U32 const matchIndexL = hashLong[h2];
|
||||||
U32 matchIndexS = hashSmall[h];
|
U32 matchIndexS = hashSmall[h];
|
||||||
const BYTE* matchLong = base + matchIndexL;
|
const BYTE* matchLong = base + matchIndexL;
|
||||||
const BYTE* match = base + matchIndexS;
|
const BYTE* match = base + matchIndexS;
|
||||||
const U32 repIndex = current + 1 - offset_1;
|
const U32 repIndex = curr + 1 - offset_1;
|
||||||
const BYTE* repMatch = (dictMode == ZSTD_dictMatchState
|
const BYTE* repMatch = (repIndex < prefixLowestIndex) ?
|
||||||
&& repIndex < prefixLowestIndex) ?
|
|
||||||
dictBase + (repIndex - dictIndexDelta) :
|
dictBase + (repIndex - dictIndexDelta) :
|
||||||
base + repIndex;
|
base + repIndex;
|
||||||
hashLong[h2] = hashSmall[h] = current; /* update hash tables */
|
hashLong[h2] = hashSmall[h] = curr; /* update hash tables */
|
||||||
|
|
||||||
/* check dictMatchState repcode */
|
/* check repcode */
|
||||||
if (dictMode == ZSTD_dictMatchState
|
if (((U32)((prefixLowestIndex-1) - repIndex) >= 3 /* intentional underflow */)
|
||||||
&& ((U32)((prefixLowestIndex-1) - repIndex) >= 3 /* intentional underflow */)
|
|
||||||
&& (MEM_read32(repMatch) == MEM_read32(ip+1)) ) {
|
&& (MEM_read32(repMatch) == MEM_read32(ip+1)) ) {
|
||||||
const BYTE* repMatchEnd = repIndex < prefixLowestIndex ? dictEnd : iend;
|
const BYTE* repMatchEnd = repIndex < prefixLowestIndex ? dictEnd : iend;
|
||||||
mLength = ZSTD_count_2segments(ip+1+4, repMatch+4, iend, repMatchEnd, prefixLowest) + 4;
|
mLength = ZSTD_count_2segments(ip+1+4, repMatch+4, iend, repMatchEnd, prefixLowest) + 4;
|
||||||
ip++;
|
ip++;
|
||||||
ZSTD_storeSeq(seqStore, (size_t)(ip-anchor), anchor, iend, 0, mLength-MINMATCH);
|
ZSTD_storeSeq(seqStore, (size_t)(ip-anchor), anchor, iend, REPCODE1_TO_OFFBASE, mLength);
|
||||||
goto _match_stored;
|
|
||||||
}
|
|
||||||
|
|
||||||
/* check noDict repcode */
|
|
||||||
if ( dictMode == ZSTD_noDict
|
|
||||||
&& ((offset_1 > 0) & (MEM_read32(ip+1-offset_1) == MEM_read32(ip+1)))) {
|
|
||||||
mLength = ZSTD_count(ip+1+4, ip+1+4-offset_1, iend) + 4;
|
|
||||||
ip++;
|
|
||||||
ZSTD_storeSeq(seqStore, (size_t)(ip-anchor), anchor, iend, 0, mLength-MINMATCH);
|
|
||||||
goto _match_stored;
|
goto _match_stored;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -169,15 +402,15 @@ size_t ZSTD_compressBlock_doubleFast_generic(
|
|||||||
while (((ip>anchor) & (matchLong>prefixLowest)) && (ip[-1] == matchLong[-1])) { ip--; matchLong--; mLength++; } /* catch up */
|
while (((ip>anchor) & (matchLong>prefixLowest)) && (ip[-1] == matchLong[-1])) { ip--; matchLong--; mLength++; } /* catch up */
|
||||||
goto _match_found;
|
goto _match_found;
|
||||||
}
|
}
|
||||||
} else if (dictMode == ZSTD_dictMatchState) {
|
} else if (dictTagsMatchL) {
|
||||||
/* check dictMatchState long match */
|
/* check dictMatchState long match */
|
||||||
U32 const dictMatchIndexL = dictHashLong[dictHL];
|
U32 const dictMatchIndexL = dictMatchIndexAndTagL >> ZSTD_SHORT_CACHE_TAG_BITS;
|
||||||
const BYTE* dictMatchL = dictBase + dictMatchIndexL;
|
const BYTE* dictMatchL = dictBase + dictMatchIndexL;
|
||||||
assert(dictMatchL < dictEnd);
|
assert(dictMatchL < dictEnd);
|
||||||
|
|
||||||
if (dictMatchL > dictStart && MEM_read64(dictMatchL) == MEM_read64(ip)) {
|
if (dictMatchL > dictStart && MEM_read64(dictMatchL) == MEM_read64(ip)) {
|
||||||
mLength = ZSTD_count_2segments(ip+8, dictMatchL+8, iend, dictEnd, prefixLowest) + 8;
|
mLength = ZSTD_count_2segments(ip+8, dictMatchL+8, iend, dictEnd, prefixLowest) + 8;
|
||||||
offset = (U32)(current - dictMatchIndexL - dictIndexDelta);
|
offset = (U32)(curr - dictMatchIndexL - dictIndexDelta);
|
||||||
while (((ip>anchor) & (dictMatchL>dictStart)) && (ip[-1] == dictMatchL[-1])) { ip--; dictMatchL--; mLength++; } /* catch up */
|
while (((ip>anchor) & (dictMatchL>dictStart)) && (ip[-1] == dictMatchL[-1])) { ip--; dictMatchL--; mLength++; } /* catch up */
|
||||||
goto _match_found;
|
goto _match_found;
|
||||||
} }
|
} }
|
||||||
@@ -187,9 +420,9 @@ size_t ZSTD_compressBlock_doubleFast_generic(
|
|||||||
if (MEM_read32(match) == MEM_read32(ip)) {
|
if (MEM_read32(match) == MEM_read32(ip)) {
|
||||||
goto _search_next_long;
|
goto _search_next_long;
|
||||||
}
|
}
|
||||||
} else if (dictMode == ZSTD_dictMatchState) {
|
} else if (dictTagsMatchS) {
|
||||||
/* check dictMatchState short match */
|
/* check dictMatchState short match */
|
||||||
U32 const dictMatchIndexS = dictHashSmall[dictHS];
|
U32 const dictMatchIndexS = dictMatchIndexAndTagS >> ZSTD_SHORT_CACHE_TAG_BITS;
|
||||||
match = dictBase + dictMatchIndexS;
|
match = dictBase + dictMatchIndexS;
|
||||||
matchIndexS = dictMatchIndexS + dictIndexDelta;
|
matchIndexS = dictMatchIndexS + dictIndexDelta;
|
||||||
|
|
||||||
@@ -198,15 +431,19 @@ size_t ZSTD_compressBlock_doubleFast_generic(
|
|||||||
} }
|
} }
|
||||||
|
|
||||||
ip += ((ip-anchor) >> kSearchStrength) + 1;
|
ip += ((ip-anchor) >> kSearchStrength) + 1;
|
||||||
|
#if defined(__aarch64__)
|
||||||
|
PREFETCH_L1(ip+256);
|
||||||
|
#endif
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
_search_next_long:
|
_search_next_long:
|
||||||
|
|
||||||
{ size_t const hl3 = ZSTD_hashPtr(ip+1, hBitsL, 8);
|
{ size_t const hl3 = ZSTD_hashPtr(ip+1, hBitsL, 8);
|
||||||
size_t const dictHLNext = ZSTD_hashPtr(ip+1, dictHBitsL, 8);
|
size_t const dictHashAndTagL3 = ZSTD_hashPtr(ip+1, dictHBitsL, 8);
|
||||||
U32 const matchIndexL3 = hashLong[hl3];
|
U32 const matchIndexL3 = hashLong[hl3];
|
||||||
|
U32 const dictMatchIndexAndTagL3 = dictHashLong[dictHashAndTagL3 >> ZSTD_SHORT_CACHE_TAG_BITS];
|
||||||
|
int const dictTagsMatchL3 = ZSTD_comparePackedTags(dictMatchIndexAndTagL3, dictHashAndTagL3);
|
||||||
const BYTE* matchL3 = base + matchIndexL3;
|
const BYTE* matchL3 = base + matchIndexL3;
|
||||||
hashLong[hl3] = current + 1;
|
hashLong[hl3] = curr + 1;
|
||||||
|
|
||||||
/* check prefix long +1 match */
|
/* check prefix long +1 match */
|
||||||
if (matchIndexL3 > prefixLowestIndex) {
|
if (matchIndexL3 > prefixLowestIndex) {
|
||||||
@@ -217,23 +454,23 @@ _search_next_long:
|
|||||||
while (((ip>anchor) & (matchL3>prefixLowest)) && (ip[-1] == matchL3[-1])) { ip--; matchL3--; mLength++; } /* catch up */
|
while (((ip>anchor) & (matchL3>prefixLowest)) && (ip[-1] == matchL3[-1])) { ip--; matchL3--; mLength++; } /* catch up */
|
||||||
goto _match_found;
|
goto _match_found;
|
||||||
}
|
}
|
||||||
} else if (dictMode == ZSTD_dictMatchState) {
|
} else if (dictTagsMatchL3) {
|
||||||
/* check dict long +1 match */
|
/* check dict long +1 match */
|
||||||
U32 const dictMatchIndexL3 = dictHashLong[dictHLNext];
|
U32 const dictMatchIndexL3 = dictMatchIndexAndTagL3 >> ZSTD_SHORT_CACHE_TAG_BITS;
|
||||||
const BYTE* dictMatchL3 = dictBase + dictMatchIndexL3;
|
const BYTE* dictMatchL3 = dictBase + dictMatchIndexL3;
|
||||||
assert(dictMatchL3 < dictEnd);
|
assert(dictMatchL3 < dictEnd);
|
||||||
if (dictMatchL3 > dictStart && MEM_read64(dictMatchL3) == MEM_read64(ip+1)) {
|
if (dictMatchL3 > dictStart && MEM_read64(dictMatchL3) == MEM_read64(ip+1)) {
|
||||||
mLength = ZSTD_count_2segments(ip+1+8, dictMatchL3+8, iend, dictEnd, prefixLowest) + 8;
|
mLength = ZSTD_count_2segments(ip+1+8, dictMatchL3+8, iend, dictEnd, prefixLowest) + 8;
|
||||||
ip++;
|
ip++;
|
||||||
offset = (U32)(current + 1 - dictMatchIndexL3 - dictIndexDelta);
|
offset = (U32)(curr + 1 - dictMatchIndexL3 - dictIndexDelta);
|
||||||
while (((ip>anchor) & (dictMatchL3>dictStart)) && (ip[-1] == dictMatchL3[-1])) { ip--; dictMatchL3--; mLength++; } /* catch up */
|
while (((ip>anchor) & (dictMatchL3>dictStart)) && (ip[-1] == dictMatchL3[-1])) { ip--; dictMatchL3--; mLength++; } /* catch up */
|
||||||
goto _match_found;
|
goto _match_found;
|
||||||
} } }
|
} } }
|
||||||
|
|
||||||
/* if no long +1 match, explore the short match we found */
|
/* if no long +1 match, explore the short match we found */
|
||||||
if (dictMode == ZSTD_dictMatchState && matchIndexS < prefixLowestIndex) {
|
if (matchIndexS < prefixLowestIndex) {
|
||||||
mLength = ZSTD_count_2segments(ip+4, match+4, iend, dictEnd, prefixLowest) + 4;
|
mLength = ZSTD_count_2segments(ip+4, match+4, iend, dictEnd, prefixLowest) + 4;
|
||||||
offset = (U32)(current - matchIndexS);
|
offset = (U32)(curr - matchIndexS);
|
||||||
while (((ip>anchor) & (match>dictStart)) && (ip[-1] == match[-1])) { ip--; match--; mLength++; } /* catch up */
|
while (((ip>anchor) & (match>dictStart)) && (ip[-1] == match[-1])) { ip--; match--; mLength++; } /* catch up */
|
||||||
} else {
|
} else {
|
||||||
mLength = ZSTD_count(ip+4, match+4, iend) + 4;
|
mLength = ZSTD_count(ip+4, match+4, iend) + 4;
|
||||||
@@ -241,13 +478,11 @@ _search_next_long:
|
|||||||
while (((ip>anchor) & (match>prefixLowest)) && (ip[-1] == match[-1])) { ip--; match--; mLength++; } /* catch up */
|
while (((ip>anchor) & (match>prefixLowest)) && (ip[-1] == match[-1])) { ip--; match--; mLength++; } /* catch up */
|
||||||
}
|
}
|
||||||
|
|
||||||
/* fall-through */
|
|
||||||
|
|
||||||
_match_found:
|
_match_found:
|
||||||
offset_2 = offset_1;
|
offset_2 = offset_1;
|
||||||
offset_1 = offset;
|
offset_1 = offset;
|
||||||
|
|
||||||
ZSTD_storeSeq(seqStore, (size_t)(ip-anchor), anchor, iend, offset + ZSTD_REP_MOVE, mLength-MINMATCH);
|
ZSTD_storeSeq(seqStore, (size_t)(ip-anchor), anchor, iend, OFFSET_TO_OFFBASE(offset), mLength);
|
||||||
|
|
||||||
_match_stored:
|
_match_stored:
|
||||||
/* match found */
|
/* match found */
|
||||||
@@ -257,7 +492,7 @@ _match_stored:
|
|||||||
if (ip <= ilimit) {
|
if (ip <= ilimit) {
|
||||||
/* Complementary insertion */
|
/* Complementary insertion */
|
||||||
/* done after iLimit test, as candidates could be > iend-8 */
|
/* done after iLimit test, as candidates could be > iend-8 */
|
||||||
{ U32 const indexToInsert = current+2;
|
{ U32 const indexToInsert = curr+2;
|
||||||
hashLong[ZSTD_hashPtr(base+indexToInsert, hBitsL, 8)] = indexToInsert;
|
hashLong[ZSTD_hashPtr(base+indexToInsert, hBitsL, 8)] = indexToInsert;
|
||||||
hashLong[ZSTD_hashPtr(ip-2, hBitsL, 8)] = (U32)(ip-2-base);
|
hashLong[ZSTD_hashPtr(ip-2, hBitsL, 8)] = (U32)(ip-2-base);
|
||||||
hashSmall[ZSTD_hashPtr(base+indexToInsert, hBitsS, mls)] = indexToInsert;
|
hashSmall[ZSTD_hashPtr(base+indexToInsert, hBitsS, mls)] = indexToInsert;
|
||||||
@@ -265,20 +500,18 @@ _match_stored:
|
|||||||
}
|
}
|
||||||
|
|
||||||
/* check immediate repcode */
|
/* check immediate repcode */
|
||||||
if (dictMode == ZSTD_dictMatchState) {
|
|
||||||
while (ip <= ilimit) {
|
while (ip <= ilimit) {
|
||||||
U32 const current2 = (U32)(ip-base);
|
U32 const current2 = (U32)(ip-base);
|
||||||
U32 const repIndex2 = current2 - offset_2;
|
U32 const repIndex2 = current2 - offset_2;
|
||||||
const BYTE* repMatch2 = dictMode == ZSTD_dictMatchState
|
const BYTE* repMatch2 = repIndex2 < prefixLowestIndex ?
|
||||||
&& repIndex2 < prefixLowestIndex ?
|
dictBase + repIndex2 - dictIndexDelta :
|
||||||
dictBase - dictIndexDelta + repIndex2 :
|
|
||||||
base + repIndex2;
|
base + repIndex2;
|
||||||
if ( ((U32)((prefixLowestIndex-1) - (U32)repIndex2) >= 3 /* intentional overflow */)
|
if ( ((U32)((prefixLowestIndex-1) - (U32)repIndex2) >= 3 /* intentional overflow */)
|
||||||
&& (MEM_read32(repMatch2) == MEM_read32(ip)) ) {
|
&& (MEM_read32(repMatch2) == MEM_read32(ip)) ) {
|
||||||
const BYTE* const repEnd2 = repIndex2 < prefixLowestIndex ? dictEnd : iend;
|
const BYTE* const repEnd2 = repIndex2 < prefixLowestIndex ? dictEnd : iend;
|
||||||
size_t const repLength2 = ZSTD_count_2segments(ip+4, repMatch2+4, iend, repEnd2, prefixLowest) + 4;
|
size_t const repLength2 = ZSTD_count_2segments(ip+4, repMatch2+4, iend, repEnd2, prefixLowest) + 4;
|
||||||
U32 tmpOffset = offset_2; offset_2 = offset_1; offset_1 = tmpOffset; /* swap offset_2 <=> offset_1 */
|
U32 tmpOffset = offset_2; offset_2 = offset_1; offset_1 = tmpOffset; /* swap offset_2 <=> offset_1 */
|
||||||
ZSTD_storeSeq(seqStore, 0, anchor, iend, 0, repLength2-MINMATCH);
|
ZSTD_storeSeq(seqStore, 0, anchor, iend, REPCODE1_TO_OFFBASE, repLength2);
|
||||||
hashSmall[ZSTD_hashPtr(ip, hBitsS, mls)] = current2;
|
hashSmall[ZSTD_hashPtr(ip, hBitsS, mls)] = current2;
|
||||||
hashLong[ZSTD_hashPtr(ip, hBitsL, 8)] = current2;
|
hashLong[ZSTD_hashPtr(ip, hBitsL, 8)] = current2;
|
||||||
ip += repLength2;
|
ip += repLength2;
|
||||||
@@ -286,32 +519,36 @@ _match_stored:
|
|||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
} }
|
}
|
||||||
|
}
|
||||||
if (dictMode == ZSTD_noDict) {
|
|
||||||
while ( (ip <= ilimit)
|
|
||||||
&& ( (offset_2>0)
|
|
||||||
& (MEM_read32(ip) == MEM_read32(ip - offset_2)) )) {
|
|
||||||
/* store sequence */
|
|
||||||
size_t const rLength = ZSTD_count(ip+4, ip+4-offset_2, iend) + 4;
|
|
||||||
U32 const tmpOff = offset_2; offset_2 = offset_1; offset_1 = tmpOff; /* swap offset_2 <=> offset_1 */
|
|
||||||
hashSmall[ZSTD_hashPtr(ip, hBitsS, mls)] = (U32)(ip-base);
|
|
||||||
hashLong[ZSTD_hashPtr(ip, hBitsL, 8)] = (U32)(ip-base);
|
|
||||||
ZSTD_storeSeq(seqStore, 0, anchor, iend, 0, rLength-MINMATCH);
|
|
||||||
ip += rLength;
|
|
||||||
anchor = ip;
|
|
||||||
continue; /* faster when present ... (?) */
|
|
||||||
} } }
|
|
||||||
} /* while (ip < ilimit) */
|
} /* while (ip < ilimit) */
|
||||||
|
|
||||||
/* save reps for next block */
|
/* save reps for next block */
|
||||||
rep[0] = offset_1 ? offset_1 : offsetSaved;
|
rep[0] = offset_1;
|
||||||
rep[1] = offset_2 ? offset_2 : offsetSaved;
|
rep[1] = offset_2;
|
||||||
|
|
||||||
/* Return the last literals size */
|
/* Return the last literals size */
|
||||||
return (size_t)(iend - anchor);
|
return (size_t)(iend - anchor);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#define ZSTD_GEN_DFAST_FN(dictMode, mls) \
|
||||||
|
static size_t ZSTD_compressBlock_doubleFast_##dictMode##_##mls( \
|
||||||
|
ZSTD_matchState_t* ms, seqStore_t* seqStore, U32 rep[ZSTD_REP_NUM], \
|
||||||
|
void const* src, size_t srcSize) \
|
||||||
|
{ \
|
||||||
|
return ZSTD_compressBlock_doubleFast_##dictMode##_generic(ms, seqStore, rep, src, srcSize, mls); \
|
||||||
|
}
|
||||||
|
|
||||||
|
ZSTD_GEN_DFAST_FN(noDict, 4)
|
||||||
|
ZSTD_GEN_DFAST_FN(noDict, 5)
|
||||||
|
ZSTD_GEN_DFAST_FN(noDict, 6)
|
||||||
|
ZSTD_GEN_DFAST_FN(noDict, 7)
|
||||||
|
|
||||||
|
ZSTD_GEN_DFAST_FN(dictMatchState, 4)
|
||||||
|
ZSTD_GEN_DFAST_FN(dictMatchState, 5)
|
||||||
|
ZSTD_GEN_DFAST_FN(dictMatchState, 6)
|
||||||
|
ZSTD_GEN_DFAST_FN(dictMatchState, 7)
|
||||||
|
|
||||||
|
|
||||||
size_t ZSTD_compressBlock_doubleFast(
|
size_t ZSTD_compressBlock_doubleFast(
|
||||||
ZSTD_matchState_t* ms, seqStore_t* seqStore, U32 rep[ZSTD_REP_NUM],
|
ZSTD_matchState_t* ms, seqStore_t* seqStore, U32 rep[ZSTD_REP_NUM],
|
||||||
@@ -322,13 +559,13 @@ size_t ZSTD_compressBlock_doubleFast(
|
|||||||
{
|
{
|
||||||
default: /* includes case 3 */
|
default: /* includes case 3 */
|
||||||
case 4 :
|
case 4 :
|
||||||
return ZSTD_compressBlock_doubleFast_generic(ms, seqStore, rep, src, srcSize, 4, ZSTD_noDict);
|
return ZSTD_compressBlock_doubleFast_noDict_4(ms, seqStore, rep, src, srcSize);
|
||||||
case 5 :
|
case 5 :
|
||||||
return ZSTD_compressBlock_doubleFast_generic(ms, seqStore, rep, src, srcSize, 5, ZSTD_noDict);
|
return ZSTD_compressBlock_doubleFast_noDict_5(ms, seqStore, rep, src, srcSize);
|
||||||
case 6 :
|
case 6 :
|
||||||
return ZSTD_compressBlock_doubleFast_generic(ms, seqStore, rep, src, srcSize, 6, ZSTD_noDict);
|
return ZSTD_compressBlock_doubleFast_noDict_6(ms, seqStore, rep, src, srcSize);
|
||||||
case 7 :
|
case 7 :
|
||||||
return ZSTD_compressBlock_doubleFast_generic(ms, seqStore, rep, src, srcSize, 7, ZSTD_noDict);
|
return ZSTD_compressBlock_doubleFast_noDict_7(ms, seqStore, rep, src, srcSize);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -342,13 +579,13 @@ size_t ZSTD_compressBlock_doubleFast_dictMatchState(
|
|||||||
{
|
{
|
||||||
default: /* includes case 3 */
|
default: /* includes case 3 */
|
||||||
case 4 :
|
case 4 :
|
||||||
return ZSTD_compressBlock_doubleFast_generic(ms, seqStore, rep, src, srcSize, 4, ZSTD_dictMatchState);
|
return ZSTD_compressBlock_doubleFast_dictMatchState_4(ms, seqStore, rep, src, srcSize);
|
||||||
case 5 :
|
case 5 :
|
||||||
return ZSTD_compressBlock_doubleFast_generic(ms, seqStore, rep, src, srcSize, 5, ZSTD_dictMatchState);
|
return ZSTD_compressBlock_doubleFast_dictMatchState_5(ms, seqStore, rep, src, srcSize);
|
||||||
case 6 :
|
case 6 :
|
||||||
return ZSTD_compressBlock_doubleFast_generic(ms, seqStore, rep, src, srcSize, 6, ZSTD_dictMatchState);
|
return ZSTD_compressBlock_doubleFast_dictMatchState_6(ms, seqStore, rep, src, srcSize);
|
||||||
case 7 :
|
case 7 :
|
||||||
return ZSTD_compressBlock_doubleFast_generic(ms, seqStore, rep, src, srcSize, 7, ZSTD_dictMatchState);
|
return ZSTD_compressBlock_doubleFast_dictMatchState_7(ms, seqStore, rep, src, srcSize);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -384,7 +621,7 @@ static size_t ZSTD_compressBlock_doubleFast_extDict_generic(
|
|||||||
|
|
||||||
/* if extDict is invalidated due to maxDistance, switch to "regular" variant */
|
/* if extDict is invalidated due to maxDistance, switch to "regular" variant */
|
||||||
if (prefixStartIndex == dictStartIndex)
|
if (prefixStartIndex == dictStartIndex)
|
||||||
return ZSTD_compressBlock_doubleFast_generic(ms, seqStore, rep, src, srcSize, mls, ZSTD_noDict);
|
return ZSTD_compressBlock_doubleFast(ms, seqStore, rep, src, srcSize);
|
||||||
|
|
||||||
/* Search Loop */
|
/* Search Loop */
|
||||||
while (ip < ilimit) { /* < instead of <=, because (ip+1) */
|
while (ip < ilimit) { /* < instead of <=, because (ip+1) */
|
||||||
@@ -398,31 +635,31 @@ static size_t ZSTD_compressBlock_doubleFast_extDict_generic(
|
|||||||
const BYTE* const matchLongBase = matchLongIndex < prefixStartIndex ? dictBase : base;
|
const BYTE* const matchLongBase = matchLongIndex < prefixStartIndex ? dictBase : base;
|
||||||
const BYTE* matchLong = matchLongBase + matchLongIndex;
|
const BYTE* matchLong = matchLongBase + matchLongIndex;
|
||||||
|
|
||||||
const U32 current = (U32)(ip-base);
|
const U32 curr = (U32)(ip-base);
|
||||||
const U32 repIndex = current + 1 - offset_1; /* offset_1 expected <= current +1 */
|
const U32 repIndex = curr + 1 - offset_1; /* offset_1 expected <= curr +1 */
|
||||||
const BYTE* const repBase = repIndex < prefixStartIndex ? dictBase : base;
|
const BYTE* const repBase = repIndex < prefixStartIndex ? dictBase : base;
|
||||||
const BYTE* const repMatch = repBase + repIndex;
|
const BYTE* const repMatch = repBase + repIndex;
|
||||||
size_t mLength;
|
size_t mLength;
|
||||||
hashSmall[hSmall] = hashLong[hLong] = current; /* update hash table */
|
hashSmall[hSmall] = hashLong[hLong] = curr; /* update hash table */
|
||||||
|
|
||||||
if ((((U32)((prefixStartIndex-1) - repIndex) >= 3) /* intentional underflow : ensure repIndex doesn't overlap dict + prefix */
|
if ((((U32)((prefixStartIndex-1) - repIndex) >= 3) /* intentional underflow : ensure repIndex doesn't overlap dict + prefix */
|
||||||
& (repIndex > dictStartIndex))
|
& (offset_1 <= curr+1 - dictStartIndex)) /* note: we are searching at curr+1 */
|
||||||
&& (MEM_read32(repMatch) == MEM_read32(ip+1)) ) {
|
&& (MEM_read32(repMatch) == MEM_read32(ip+1)) ) {
|
||||||
const BYTE* repMatchEnd = repIndex < prefixStartIndex ? dictEnd : iend;
|
const BYTE* repMatchEnd = repIndex < prefixStartIndex ? dictEnd : iend;
|
||||||
mLength = ZSTD_count_2segments(ip+1+4, repMatch+4, iend, repMatchEnd, prefixStart) + 4;
|
mLength = ZSTD_count_2segments(ip+1+4, repMatch+4, iend, repMatchEnd, prefixStart) + 4;
|
||||||
ip++;
|
ip++;
|
||||||
ZSTD_storeSeq(seqStore, (size_t)(ip-anchor), anchor, iend, 0, mLength-MINMATCH);
|
ZSTD_storeSeq(seqStore, (size_t)(ip-anchor), anchor, iend, REPCODE1_TO_OFFBASE, mLength);
|
||||||
} else {
|
} else {
|
||||||
if ((matchLongIndex > dictStartIndex) && (MEM_read64(matchLong) == MEM_read64(ip))) {
|
if ((matchLongIndex > dictStartIndex) && (MEM_read64(matchLong) == MEM_read64(ip))) {
|
||||||
const BYTE* const matchEnd = matchLongIndex < prefixStartIndex ? dictEnd : iend;
|
const BYTE* const matchEnd = matchLongIndex < prefixStartIndex ? dictEnd : iend;
|
||||||
const BYTE* const lowMatchPtr = matchLongIndex < prefixStartIndex ? dictStart : prefixStart;
|
const BYTE* const lowMatchPtr = matchLongIndex < prefixStartIndex ? dictStart : prefixStart;
|
||||||
U32 offset;
|
U32 offset;
|
||||||
mLength = ZSTD_count_2segments(ip+8, matchLong+8, iend, matchEnd, prefixStart) + 8;
|
mLength = ZSTD_count_2segments(ip+8, matchLong+8, iend, matchEnd, prefixStart) + 8;
|
||||||
offset = current - matchLongIndex;
|
offset = curr - matchLongIndex;
|
||||||
while (((ip>anchor) & (matchLong>lowMatchPtr)) && (ip[-1] == matchLong[-1])) { ip--; matchLong--; mLength++; } /* catch up */
|
while (((ip>anchor) & (matchLong>lowMatchPtr)) && (ip[-1] == matchLong[-1])) { ip--; matchLong--; mLength++; } /* catch up */
|
||||||
offset_2 = offset_1;
|
offset_2 = offset_1;
|
||||||
offset_1 = offset;
|
offset_1 = offset;
|
||||||
ZSTD_storeSeq(seqStore, (size_t)(ip-anchor), anchor, iend, offset + ZSTD_REP_MOVE, mLength-MINMATCH);
|
ZSTD_storeSeq(seqStore, (size_t)(ip-anchor), anchor, iend, OFFSET_TO_OFFBASE(offset), mLength);
|
||||||
|
|
||||||
} else if ((matchIndex > dictStartIndex) && (MEM_read32(match) == MEM_read32(ip))) {
|
} else if ((matchIndex > dictStartIndex) && (MEM_read32(match) == MEM_read32(ip))) {
|
||||||
size_t const h3 = ZSTD_hashPtr(ip+1, hBitsL, 8);
|
size_t const h3 = ZSTD_hashPtr(ip+1, hBitsL, 8);
|
||||||
@@ -430,24 +667,24 @@ static size_t ZSTD_compressBlock_doubleFast_extDict_generic(
|
|||||||
const BYTE* const match3Base = matchIndex3 < prefixStartIndex ? dictBase : base;
|
const BYTE* const match3Base = matchIndex3 < prefixStartIndex ? dictBase : base;
|
||||||
const BYTE* match3 = match3Base + matchIndex3;
|
const BYTE* match3 = match3Base + matchIndex3;
|
||||||
U32 offset;
|
U32 offset;
|
||||||
hashLong[h3] = current + 1;
|
hashLong[h3] = curr + 1;
|
||||||
if ( (matchIndex3 > dictStartIndex) && (MEM_read64(match3) == MEM_read64(ip+1)) ) {
|
if ( (matchIndex3 > dictStartIndex) && (MEM_read64(match3) == MEM_read64(ip+1)) ) {
|
||||||
const BYTE* const matchEnd = matchIndex3 < prefixStartIndex ? dictEnd : iend;
|
const BYTE* const matchEnd = matchIndex3 < prefixStartIndex ? dictEnd : iend;
|
||||||
const BYTE* const lowMatchPtr = matchIndex3 < prefixStartIndex ? dictStart : prefixStart;
|
const BYTE* const lowMatchPtr = matchIndex3 < prefixStartIndex ? dictStart : prefixStart;
|
||||||
mLength = ZSTD_count_2segments(ip+9, match3+8, iend, matchEnd, prefixStart) + 8;
|
mLength = ZSTD_count_2segments(ip+9, match3+8, iend, matchEnd, prefixStart) + 8;
|
||||||
ip++;
|
ip++;
|
||||||
offset = current+1 - matchIndex3;
|
offset = curr+1 - matchIndex3;
|
||||||
while (((ip>anchor) & (match3>lowMatchPtr)) && (ip[-1] == match3[-1])) { ip--; match3--; mLength++; } /* catch up */
|
while (((ip>anchor) & (match3>lowMatchPtr)) && (ip[-1] == match3[-1])) { ip--; match3--; mLength++; } /* catch up */
|
||||||
} else {
|
} else {
|
||||||
const BYTE* const matchEnd = matchIndex < prefixStartIndex ? dictEnd : iend;
|
const BYTE* const matchEnd = matchIndex < prefixStartIndex ? dictEnd : iend;
|
||||||
const BYTE* const lowMatchPtr = matchIndex < prefixStartIndex ? dictStart : prefixStart;
|
const BYTE* const lowMatchPtr = matchIndex < prefixStartIndex ? dictStart : prefixStart;
|
||||||
mLength = ZSTD_count_2segments(ip+4, match+4, iend, matchEnd, prefixStart) + 4;
|
mLength = ZSTD_count_2segments(ip+4, match+4, iend, matchEnd, prefixStart) + 4;
|
||||||
offset = current - matchIndex;
|
offset = curr - matchIndex;
|
||||||
while (((ip>anchor) & (match>lowMatchPtr)) && (ip[-1] == match[-1])) { ip--; match--; mLength++; } /* catch up */
|
while (((ip>anchor) & (match>lowMatchPtr)) && (ip[-1] == match[-1])) { ip--; match--; mLength++; } /* catch up */
|
||||||
}
|
}
|
||||||
offset_2 = offset_1;
|
offset_2 = offset_1;
|
||||||
offset_1 = offset;
|
offset_1 = offset;
|
||||||
ZSTD_storeSeq(seqStore, (size_t)(ip-anchor), anchor, iend, offset + ZSTD_REP_MOVE, mLength-MINMATCH);
|
ZSTD_storeSeq(seqStore, (size_t)(ip-anchor), anchor, iend, OFFSET_TO_OFFBASE(offset), mLength);
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
ip += ((ip-anchor) >> kSearchStrength) + 1;
|
ip += ((ip-anchor) >> kSearchStrength) + 1;
|
||||||
@@ -461,7 +698,7 @@ static size_t ZSTD_compressBlock_doubleFast_extDict_generic(
|
|||||||
if (ip <= ilimit) {
|
if (ip <= ilimit) {
|
||||||
/* Complementary insertion */
|
/* Complementary insertion */
|
||||||
/* done after iLimit test, as candidates could be > iend-8 */
|
/* done after iLimit test, as candidates could be > iend-8 */
|
||||||
{ U32 const indexToInsert = current+2;
|
{ U32 const indexToInsert = curr+2;
|
||||||
hashLong[ZSTD_hashPtr(base+indexToInsert, hBitsL, 8)] = indexToInsert;
|
hashLong[ZSTD_hashPtr(base+indexToInsert, hBitsL, 8)] = indexToInsert;
|
||||||
hashLong[ZSTD_hashPtr(ip-2, hBitsL, 8)] = (U32)(ip-2-base);
|
hashLong[ZSTD_hashPtr(ip-2, hBitsL, 8)] = (U32)(ip-2-base);
|
||||||
hashSmall[ZSTD_hashPtr(base+indexToInsert, hBitsS, mls)] = indexToInsert;
|
hashSmall[ZSTD_hashPtr(base+indexToInsert, hBitsS, mls)] = indexToInsert;
|
||||||
@@ -474,12 +711,12 @@ static size_t ZSTD_compressBlock_doubleFast_extDict_generic(
|
|||||||
U32 const repIndex2 = current2 - offset_2;
|
U32 const repIndex2 = current2 - offset_2;
|
||||||
const BYTE* repMatch2 = repIndex2 < prefixStartIndex ? dictBase + repIndex2 : base + repIndex2;
|
const BYTE* repMatch2 = repIndex2 < prefixStartIndex ? dictBase + repIndex2 : base + repIndex2;
|
||||||
if ( (((U32)((prefixStartIndex-1) - repIndex2) >= 3) /* intentional overflow : ensure repIndex2 doesn't overlap dict + prefix */
|
if ( (((U32)((prefixStartIndex-1) - repIndex2) >= 3) /* intentional overflow : ensure repIndex2 doesn't overlap dict + prefix */
|
||||||
& (repIndex2 > dictStartIndex))
|
& (offset_2 <= current2 - dictStartIndex))
|
||||||
&& (MEM_read32(repMatch2) == MEM_read32(ip)) ) {
|
&& (MEM_read32(repMatch2) == MEM_read32(ip)) ) {
|
||||||
const BYTE* const repEnd2 = repIndex2 < prefixStartIndex ? dictEnd : iend;
|
const BYTE* const repEnd2 = repIndex2 < prefixStartIndex ? dictEnd : iend;
|
||||||
size_t const repLength2 = ZSTD_count_2segments(ip+4, repMatch2+4, iend, repEnd2, prefixStart) + 4;
|
size_t const repLength2 = ZSTD_count_2segments(ip+4, repMatch2+4, iend, repEnd2, prefixStart) + 4;
|
||||||
U32 const tmpOffset = offset_2; offset_2 = offset_1; offset_1 = tmpOffset; /* swap offset_2 <=> offset_1 */
|
U32 const tmpOffset = offset_2; offset_2 = offset_1; offset_1 = tmpOffset; /* swap offset_2 <=> offset_1 */
|
||||||
ZSTD_storeSeq(seqStore, 0, anchor, iend, 0, repLength2-MINMATCH);
|
ZSTD_storeSeq(seqStore, 0, anchor, iend, REPCODE1_TO_OFFBASE, repLength2);
|
||||||
hashSmall[ZSTD_hashPtr(ip, hBitsS, mls)] = current2;
|
hashSmall[ZSTD_hashPtr(ip, hBitsS, mls)] = current2;
|
||||||
hashLong[ZSTD_hashPtr(ip, hBitsL, 8)] = current2;
|
hashLong[ZSTD_hashPtr(ip, hBitsL, 8)] = current2;
|
||||||
ip += repLength2;
|
ip += repLength2;
|
||||||
@@ -497,6 +734,10 @@ static size_t ZSTD_compressBlock_doubleFast_extDict_generic(
|
|||||||
return (size_t)(iend - anchor);
|
return (size_t)(iend - anchor);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
ZSTD_GEN_DFAST_FN(extDict, 4)
|
||||||
|
ZSTD_GEN_DFAST_FN(extDict, 5)
|
||||||
|
ZSTD_GEN_DFAST_FN(extDict, 6)
|
||||||
|
ZSTD_GEN_DFAST_FN(extDict, 7)
|
||||||
|
|
||||||
size_t ZSTD_compressBlock_doubleFast_extDict(
|
size_t ZSTD_compressBlock_doubleFast_extDict(
|
||||||
ZSTD_matchState_t* ms, seqStore_t* seqStore, U32 rep[ZSTD_REP_NUM],
|
ZSTD_matchState_t* ms, seqStore_t* seqStore, U32 rep[ZSTD_REP_NUM],
|
||||||
@@ -507,12 +748,14 @@ size_t ZSTD_compressBlock_doubleFast_extDict(
|
|||||||
{
|
{
|
||||||
default: /* includes case 3 */
|
default: /* includes case 3 */
|
||||||
case 4 :
|
case 4 :
|
||||||
return ZSTD_compressBlock_doubleFast_extDict_generic(ms, seqStore, rep, src, srcSize, 4);
|
return ZSTD_compressBlock_doubleFast_extDict_4(ms, seqStore, rep, src, srcSize);
|
||||||
case 5 :
|
case 5 :
|
||||||
return ZSTD_compressBlock_doubleFast_extDict_generic(ms, seqStore, rep, src, srcSize, 5);
|
return ZSTD_compressBlock_doubleFast_extDict_5(ms, seqStore, rep, src, srcSize);
|
||||||
case 6 :
|
case 6 :
|
||||||
return ZSTD_compressBlock_doubleFast_extDict_generic(ms, seqStore, rep, src, srcSize, 6);
|
return ZSTD_compressBlock_doubleFast_extDict_6(ms, seqStore, rep, src, srcSize);
|
||||||
case 7 :
|
case 7 :
|
||||||
return ZSTD_compressBlock_doubleFast_extDict_generic(ms, seqStore, rep, src, srcSize, 7);
|
return ZSTD_compressBlock_doubleFast_extDict_7(ms, seqStore, rep, src, srcSize);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#endif /* USE_EXTERNAL_ZSTD */
|
||||||
|
|||||||
8
vendor/github.com/DataDog/zstd/zstd_double_fast.h
generated
vendored
8
vendor/github.com/DataDog/zstd/zstd_double_fast.h
generated
vendored
@@ -1,5 +1,6 @@
|
|||||||
|
#ifndef USE_EXTERNAL_ZSTD
|
||||||
/*
|
/*
|
||||||
* Copyright (c) 2016-present, Yann Collet, Facebook, Inc.
|
* Copyright (c) Meta Platforms, Inc. and affiliates.
|
||||||
* All rights reserved.
|
* All rights reserved.
|
||||||
*
|
*
|
||||||
* This source code is licensed under both the BSD-style license (found in the
|
* This source code is licensed under both the BSD-style license (found in the
|
||||||
@@ -19,7 +20,8 @@ extern "C" {
|
|||||||
#include "zstd_compress_internal.h" /* ZSTD_CCtx, size_t */
|
#include "zstd_compress_internal.h" /* ZSTD_CCtx, size_t */
|
||||||
|
|
||||||
void ZSTD_fillDoubleHashTable(ZSTD_matchState_t* ms,
|
void ZSTD_fillDoubleHashTable(ZSTD_matchState_t* ms,
|
||||||
void const* end, ZSTD_dictTableLoadMethod_e dtlm);
|
void const* end, ZSTD_dictTableLoadMethod_e dtlm,
|
||||||
|
ZSTD_tableFillPurpose_e tfp);
|
||||||
size_t ZSTD_compressBlock_doubleFast(
|
size_t ZSTD_compressBlock_doubleFast(
|
||||||
ZSTD_matchState_t* ms, seqStore_t* seqStore, U32 rep[ZSTD_REP_NUM],
|
ZSTD_matchState_t* ms, seqStore_t* seqStore, U32 rep[ZSTD_REP_NUM],
|
||||||
void const* src, size_t srcSize);
|
void const* src, size_t srcSize);
|
||||||
@@ -36,3 +38,5 @@ size_t ZSTD_compressBlock_doubleFast_extDict(
|
|||||||
#endif
|
#endif
|
||||||
|
|
||||||
#endif /* ZSTD_DOUBLE_FAST_H */
|
#endif /* ZSTD_DOUBLE_FAST_H */
|
||||||
|
|
||||||
|
#endif /* USE_EXTERNAL_ZSTD */
|
||||||
|
|||||||
40
vendor/github.com/DataDog/zstd/zstd_errors.h
generated
vendored
40
vendor/github.com/DataDog/zstd/zstd_errors.h
generated
vendored
@@ -1,5 +1,6 @@
|
|||||||
|
#ifndef USE_EXTERNAL_ZSTD
|
||||||
/*
|
/*
|
||||||
* Copyright (c) 2016-present, Yann Collet, Facebook, Inc.
|
* Copyright (c) Meta Platforms, Inc. and affiliates.
|
||||||
* All rights reserved.
|
* All rights reserved.
|
||||||
*
|
*
|
||||||
* This source code is licensed under both the BSD-style license (found in the
|
* This source code is licensed under both the BSD-style license (found in the
|
||||||
@@ -20,19 +21,31 @@ extern "C" {
|
|||||||
|
|
||||||
|
|
||||||
/* ===== ZSTDERRORLIB_API : control library symbols visibility ===== */
|
/* ===== ZSTDERRORLIB_API : control library symbols visibility ===== */
|
||||||
#ifndef ZSTDERRORLIB_VISIBILITY
|
#ifndef ZSTDERRORLIB_VISIBLE
|
||||||
# if defined(__GNUC__) && (__GNUC__ >= 4)
|
/* Backwards compatibility with old macro name */
|
||||||
# define ZSTDERRORLIB_VISIBILITY __attribute__ ((visibility ("default")))
|
# ifdef ZSTDERRORLIB_VISIBILITY
|
||||||
|
# define ZSTDERRORLIB_VISIBLE ZSTDERRORLIB_VISIBILITY
|
||||||
|
# elif defined(__GNUC__) && (__GNUC__ >= 4) && !defined(__MINGW32__)
|
||||||
|
# define ZSTDERRORLIB_VISIBLE __attribute__ ((visibility ("default")))
|
||||||
# else
|
# else
|
||||||
# define ZSTDERRORLIB_VISIBILITY
|
# define ZSTDERRORLIB_VISIBLE
|
||||||
# endif
|
# endif
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
#ifndef ZSTDERRORLIB_HIDDEN
|
||||||
|
# if defined(__GNUC__) && (__GNUC__ >= 4) && !defined(__MINGW32__)
|
||||||
|
# define ZSTDERRORLIB_HIDDEN __attribute__ ((visibility ("hidden")))
|
||||||
|
# else
|
||||||
|
# define ZSTDERRORLIB_HIDDEN
|
||||||
|
# endif
|
||||||
|
#endif
|
||||||
|
|
||||||
#if defined(ZSTD_DLL_EXPORT) && (ZSTD_DLL_EXPORT==1)
|
#if defined(ZSTD_DLL_EXPORT) && (ZSTD_DLL_EXPORT==1)
|
||||||
# define ZSTDERRORLIB_API __declspec(dllexport) ZSTDERRORLIB_VISIBILITY
|
# define ZSTDERRORLIB_API __declspec(dllexport) ZSTDERRORLIB_VISIBLE
|
||||||
#elif defined(ZSTD_DLL_IMPORT) && (ZSTD_DLL_IMPORT==1)
|
#elif defined(ZSTD_DLL_IMPORT) && (ZSTD_DLL_IMPORT==1)
|
||||||
# define ZSTDERRORLIB_API __declspec(dllimport) ZSTDERRORLIB_VISIBILITY /* It isn't required but allows to generate better code, saving a function pointer load from the IAT and an indirect jump.*/
|
# define ZSTDERRORLIB_API __declspec(dllimport) ZSTDERRORLIB_VISIBLE /* It isn't required but allows to generate better code, saving a function pointer load from the IAT and an indirect jump.*/
|
||||||
#else
|
#else
|
||||||
# define ZSTDERRORLIB_API ZSTDERRORLIB_VISIBILITY
|
# define ZSTDERRORLIB_API ZSTDERRORLIB_VISIBLE
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
/*-*********************************************
|
/*-*********************************************
|
||||||
@@ -58,14 +71,17 @@ typedef enum {
|
|||||||
ZSTD_error_frameParameter_windowTooLarge = 16,
|
ZSTD_error_frameParameter_windowTooLarge = 16,
|
||||||
ZSTD_error_corruption_detected = 20,
|
ZSTD_error_corruption_detected = 20,
|
||||||
ZSTD_error_checksum_wrong = 22,
|
ZSTD_error_checksum_wrong = 22,
|
||||||
|
ZSTD_error_literals_headerWrong = 24,
|
||||||
ZSTD_error_dictionary_corrupted = 30,
|
ZSTD_error_dictionary_corrupted = 30,
|
||||||
ZSTD_error_dictionary_wrong = 32,
|
ZSTD_error_dictionary_wrong = 32,
|
||||||
ZSTD_error_dictionaryCreation_failed = 34,
|
ZSTD_error_dictionaryCreation_failed = 34,
|
||||||
ZSTD_error_parameter_unsupported = 40,
|
ZSTD_error_parameter_unsupported = 40,
|
||||||
|
ZSTD_error_parameter_combination_unsupported = 41,
|
||||||
ZSTD_error_parameter_outOfBound = 42,
|
ZSTD_error_parameter_outOfBound = 42,
|
||||||
ZSTD_error_tableLog_tooLarge = 44,
|
ZSTD_error_tableLog_tooLarge = 44,
|
||||||
ZSTD_error_maxSymbolValue_tooLarge = 46,
|
ZSTD_error_maxSymbolValue_tooLarge = 46,
|
||||||
ZSTD_error_maxSymbolValue_tooSmall = 48,
|
ZSTD_error_maxSymbolValue_tooSmall = 48,
|
||||||
|
ZSTD_error_stabilityCondition_notRespected = 50,
|
||||||
ZSTD_error_stage_wrong = 60,
|
ZSTD_error_stage_wrong = 60,
|
||||||
ZSTD_error_init_missing = 62,
|
ZSTD_error_init_missing = 62,
|
||||||
ZSTD_error_memory_allocation = 64,
|
ZSTD_error_memory_allocation = 64,
|
||||||
@@ -73,9 +89,15 @@ typedef enum {
|
|||||||
ZSTD_error_dstSize_tooSmall = 70,
|
ZSTD_error_dstSize_tooSmall = 70,
|
||||||
ZSTD_error_srcSize_wrong = 72,
|
ZSTD_error_srcSize_wrong = 72,
|
||||||
ZSTD_error_dstBuffer_null = 74,
|
ZSTD_error_dstBuffer_null = 74,
|
||||||
|
ZSTD_error_noForwardProgress_destFull = 80,
|
||||||
|
ZSTD_error_noForwardProgress_inputEmpty = 82,
|
||||||
/* following error codes are __NOT STABLE__, they can be removed or changed in future versions */
|
/* following error codes are __NOT STABLE__, they can be removed or changed in future versions */
|
||||||
ZSTD_error_frameIndex_tooLarge = 100,
|
ZSTD_error_frameIndex_tooLarge = 100,
|
||||||
ZSTD_error_seekableIO = 102,
|
ZSTD_error_seekableIO = 102,
|
||||||
|
ZSTD_error_dstBuffer_wrong = 104,
|
||||||
|
ZSTD_error_srcBuffer_wrong = 105,
|
||||||
|
ZSTD_error_sequenceProducer_failed = 106,
|
||||||
|
ZSTD_error_externalSequences_invalid = 107,
|
||||||
ZSTD_error_maxCode = 120 /* never EVER use this value directly, it can change in future versions! Use ZSTD_isError() instead */
|
ZSTD_error_maxCode = 120 /* never EVER use this value directly, it can change in future versions! Use ZSTD_isError() instead */
|
||||||
} ZSTD_ErrorCode;
|
} ZSTD_ErrorCode;
|
||||||
|
|
||||||
@@ -91,3 +113,5 @@ ZSTDERRORLIB_API const char* ZSTD_getErrorString(ZSTD_ErrorCode code); /**< Sa
|
|||||||
#endif
|
#endif
|
||||||
|
|
||||||
#endif /* ZSTD_ERRORS_H_398273423 */
|
#endif /* ZSTD_ERRORS_H_398273423 */
|
||||||
|
|
||||||
|
#endif /* USE_EXTERNAL_ZSTD */
|
||||||
|
|||||||
967
vendor/github.com/DataDog/zstd/zstd_fast.c
generated
vendored
967
vendor/github.com/DataDog/zstd/zstd_fast.c
generated
vendored
File diff suppressed because it is too large
Load Diff
8
vendor/github.com/DataDog/zstd/zstd_fast.h
generated
vendored
8
vendor/github.com/DataDog/zstd/zstd_fast.h
generated
vendored
@@ -1,5 +1,6 @@
|
|||||||
|
#ifndef USE_EXTERNAL_ZSTD
|
||||||
/*
|
/*
|
||||||
* Copyright (c) 2016-present, Yann Collet, Facebook, Inc.
|
* Copyright (c) Meta Platforms, Inc. and affiliates.
|
||||||
* All rights reserved.
|
* All rights reserved.
|
||||||
*
|
*
|
||||||
* This source code is licensed under both the BSD-style license (found in the
|
* This source code is licensed under both the BSD-style license (found in the
|
||||||
@@ -19,7 +20,8 @@ extern "C" {
|
|||||||
#include "zstd_compress_internal.h"
|
#include "zstd_compress_internal.h"
|
||||||
|
|
||||||
void ZSTD_fillHashTable(ZSTD_matchState_t* ms,
|
void ZSTD_fillHashTable(ZSTD_matchState_t* ms,
|
||||||
void const* end, ZSTD_dictTableLoadMethod_e dtlm);
|
void const* end, ZSTD_dictTableLoadMethod_e dtlm,
|
||||||
|
ZSTD_tableFillPurpose_e tfp);
|
||||||
size_t ZSTD_compressBlock_fast(
|
size_t ZSTD_compressBlock_fast(
|
||||||
ZSTD_matchState_t* ms, seqStore_t* seqStore, U32 rep[ZSTD_REP_NUM],
|
ZSTD_matchState_t* ms, seqStore_t* seqStore, U32 rep[ZSTD_REP_NUM],
|
||||||
void const* src, size_t srcSize);
|
void const* src, size_t srcSize);
|
||||||
@@ -35,3 +37,5 @@ size_t ZSTD_compressBlock_fast_extDict(
|
|||||||
#endif
|
#endif
|
||||||
|
|
||||||
#endif /* ZSTD_FAST_H */
|
#endif /* ZSTD_FAST_H */
|
||||||
|
|
||||||
|
#endif /* USE_EXTERNAL_ZSTD */
|
||||||
|
|||||||
283
vendor/github.com/DataDog/zstd/zstd_internal.h
generated
vendored
283
vendor/github.com/DataDog/zstd/zstd_internal.h
generated
vendored
@@ -1,5 +1,6 @@
|
|||||||
|
#ifndef USE_EXTERNAL_ZSTD
|
||||||
/*
|
/*
|
||||||
* Copyright (c) 2016-present, Yann Collet, Facebook, Inc.
|
* Copyright (c) Meta Platforms, Inc. and affiliates.
|
||||||
* All rights reserved.
|
* All rights reserved.
|
||||||
*
|
*
|
||||||
* This source code is licensed under both the BSD-style license (found in the
|
* This source code is licensed under both the BSD-style license (found in the
|
||||||
@@ -20,6 +21,7 @@
|
|||||||
* Dependencies
|
* Dependencies
|
||||||
***************************************/
|
***************************************/
|
||||||
#include "compiler.h"
|
#include "compiler.h"
|
||||||
|
#include "cpu.h"
|
||||||
#include "mem.h"
|
#include "mem.h"
|
||||||
#include "debug.h" /* assert, DEBUGLOG, RAWLOG, g_debuglevel */
|
#include "debug.h" /* assert, DEBUGLOG, RAWLOG, g_debuglevel */
|
||||||
#include "error_private.h"
|
#include "error_private.h"
|
||||||
@@ -27,12 +29,16 @@
|
|||||||
#include "zstd.h"
|
#include "zstd.h"
|
||||||
#define FSE_STATIC_LINKING_ONLY
|
#define FSE_STATIC_LINKING_ONLY
|
||||||
#include "fse.h"
|
#include "fse.h"
|
||||||
#define HUF_STATIC_LINKING_ONLY
|
|
||||||
#include "huf.h"
|
#include "huf.h"
|
||||||
#ifndef XXH_STATIC_LINKING_ONLY
|
#ifndef XXH_STATIC_LINKING_ONLY
|
||||||
# define XXH_STATIC_LINKING_ONLY /* XXH64_state_t */
|
# define XXH_STATIC_LINKING_ONLY /* XXH64_state_t */
|
||||||
#endif
|
#endif
|
||||||
#include "xxhash.h" /* XXH_reset, update, digest */
|
#include "xxhash.h" /* XXH_reset, update, digest */
|
||||||
|
#ifndef ZSTD_NO_TRACE
|
||||||
|
# include "zstd_trace.h"
|
||||||
|
#else
|
||||||
|
# define ZSTD_TRACE 0
|
||||||
|
#endif
|
||||||
|
|
||||||
#if defined (__cplusplus)
|
#if defined (__cplusplus)
|
||||||
extern "C" {
|
extern "C" {
|
||||||
@@ -52,50 +58,7 @@ extern "C" {
|
|||||||
#undef MAX
|
#undef MAX
|
||||||
#define MIN(a,b) ((a)<(b) ? (a) : (b))
|
#define MIN(a,b) ((a)<(b) ? (a) : (b))
|
||||||
#define MAX(a,b) ((a)>(b) ? (a) : (b))
|
#define MAX(a,b) ((a)>(b) ? (a) : (b))
|
||||||
|
#define BOUNDED(min,val,max) (MAX(min,MIN(val,max)))
|
||||||
/**
|
|
||||||
* Return the specified error if the condition evaluates to true.
|
|
||||||
*
|
|
||||||
* In debug modes, prints additional information.
|
|
||||||
* In order to do that (particularly, printing the conditional that failed),
|
|
||||||
* this can't just wrap RETURN_ERROR().
|
|
||||||
*/
|
|
||||||
#define RETURN_ERROR_IF(cond, err, ...) \
|
|
||||||
if (cond) { \
|
|
||||||
RAWLOG(3, "%s:%d: ERROR!: check %s failed, returning %s", __FILE__, __LINE__, ZSTD_QUOTE(cond), ZSTD_QUOTE(ERROR(err))); \
|
|
||||||
RAWLOG(3, ": " __VA_ARGS__); \
|
|
||||||
RAWLOG(3, "\n"); \
|
|
||||||
return ERROR(err); \
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Unconditionally return the specified error.
|
|
||||||
*
|
|
||||||
* In debug modes, prints additional information.
|
|
||||||
*/
|
|
||||||
#define RETURN_ERROR(err, ...) \
|
|
||||||
do { \
|
|
||||||
RAWLOG(3, "%s:%d: ERROR!: unconditional check failed, returning %s", __FILE__, __LINE__, ZSTD_QUOTE(ERROR(err))); \
|
|
||||||
RAWLOG(3, ": " __VA_ARGS__); \
|
|
||||||
RAWLOG(3, "\n"); \
|
|
||||||
return ERROR(err); \
|
|
||||||
} while(0);
|
|
||||||
|
|
||||||
/**
|
|
||||||
* If the provided expression evaluates to an error code, returns that error code.
|
|
||||||
*
|
|
||||||
* In debug modes, prints additional information.
|
|
||||||
*/
|
|
||||||
#define FORWARD_IF_ERROR(err, ...) \
|
|
||||||
do { \
|
|
||||||
size_t const err_code = (err); \
|
|
||||||
if (ERR_isError(err_code)) { \
|
|
||||||
RAWLOG(3, "%s:%d: ERROR!: forwarding error in %s: %s", __FILE__, __LINE__, ZSTD_QUOTE(err), ERR_getErrorName(err_code)); \
|
|
||||||
RAWLOG(3, ": " __VA_ARGS__); \
|
|
||||||
RAWLOG(3, "\n"); \
|
|
||||||
return err_code; \
|
|
||||||
} \
|
|
||||||
} while(0);
|
|
||||||
|
|
||||||
|
|
||||||
/*-*************************************
|
/*-*************************************
|
||||||
@@ -104,8 +67,7 @@ extern "C" {
|
|||||||
#define ZSTD_OPT_NUM (1<<12)
|
#define ZSTD_OPT_NUM (1<<12)
|
||||||
|
|
||||||
#define ZSTD_REP_NUM 3 /* number of repcodes */
|
#define ZSTD_REP_NUM 3 /* number of repcodes */
|
||||||
#define ZSTD_REP_MOVE (ZSTD_REP_NUM-1)
|
static UNUSED_ATTR const U32 repStartValue[ZSTD_REP_NUM] = { 1, 4, 8 };
|
||||||
static const U32 repStartValue[ZSTD_REP_NUM] = { 1, 4, 8 };
|
|
||||||
|
|
||||||
#define KB *(1 <<10)
|
#define KB *(1 <<10)
|
||||||
#define MB *(1 <<20)
|
#define MB *(1 <<20)
|
||||||
@@ -119,19 +81,21 @@ static const U32 repStartValue[ZSTD_REP_NUM] = { 1, 4, 8 };
|
|||||||
#define BIT0 1
|
#define BIT0 1
|
||||||
|
|
||||||
#define ZSTD_WINDOWLOG_ABSOLUTEMIN 10
|
#define ZSTD_WINDOWLOG_ABSOLUTEMIN 10
|
||||||
static const size_t ZSTD_fcs_fieldSize[4] = { 0, 2, 4, 8 };
|
static UNUSED_ATTR const size_t ZSTD_fcs_fieldSize[4] = { 0, 2, 4, 8 };
|
||||||
static const size_t ZSTD_did_fieldSize[4] = { 0, 1, 2, 4 };
|
static UNUSED_ATTR const size_t ZSTD_did_fieldSize[4] = { 0, 1, 2, 4 };
|
||||||
|
|
||||||
#define ZSTD_FRAMEIDSIZE 4 /* magic number size */
|
#define ZSTD_FRAMEIDSIZE 4 /* magic number size */
|
||||||
|
|
||||||
#define ZSTD_BLOCKHEADERSIZE 3 /* C standard doesn't allow `static const` variable to be init using another `static const` variable */
|
#define ZSTD_BLOCKHEADERSIZE 3 /* C standard doesn't allow `static const` variable to be init using another `static const` variable */
|
||||||
static const size_t ZSTD_blockHeaderSize = ZSTD_BLOCKHEADERSIZE;
|
static UNUSED_ATTR const size_t ZSTD_blockHeaderSize = ZSTD_BLOCKHEADERSIZE;
|
||||||
typedef enum { bt_raw, bt_rle, bt_compressed, bt_reserved } blockType_e;
|
typedef enum { bt_raw, bt_rle, bt_compressed, bt_reserved } blockType_e;
|
||||||
|
|
||||||
#define MIN_SEQUENCES_SIZE 1 /* nbSeq==0 */
|
#define ZSTD_FRAMECHECKSUMSIZE 4
|
||||||
#define MIN_CBLOCK_SIZE (1 /*litCSize*/ + 1 /* RLE or RAW */ + MIN_SEQUENCES_SIZE /* nbSeq==0 */) /* for a non-null block */
|
|
||||||
|
#define MIN_SEQUENCES_SIZE 1 /* nbSeq==0 */
|
||||||
|
#define MIN_CBLOCK_SIZE (1 /*litCSize*/ + 1 /* RLE or RAW */) /* for a non-null block */
|
||||||
|
#define MIN_LITERALS_FOR_4_STREAMS 6
|
||||||
|
|
||||||
#define HufLog 12
|
|
||||||
typedef enum { set_basic, set_rle, set_compressed, set_repeat } symbolEncodingType_e;
|
typedef enum { set_basic, set_rle, set_compressed, set_repeat } symbolEncodingType_e;
|
||||||
|
|
||||||
#define LONGNBSEQ 0x7F00
|
#define LONGNBSEQ 0x7F00
|
||||||
@@ -139,6 +103,7 @@ typedef enum { set_basic, set_rle, set_compressed, set_repeat } symbolEncodingTy
|
|||||||
#define MINMATCH 3
|
#define MINMATCH 3
|
||||||
|
|
||||||
#define Litbits 8
|
#define Litbits 8
|
||||||
|
#define LitHufLog 11
|
||||||
#define MaxLit ((1<<Litbits) - 1)
|
#define MaxLit ((1<<Litbits) - 1)
|
||||||
#define MaxML 52
|
#define MaxML 52
|
||||||
#define MaxLL 35
|
#define MaxLL 35
|
||||||
@@ -149,52 +114,91 @@ typedef enum { set_basic, set_rle, set_compressed, set_repeat } symbolEncodingTy
|
|||||||
#define LLFSELog 9
|
#define LLFSELog 9
|
||||||
#define OffFSELog 8
|
#define OffFSELog 8
|
||||||
#define MaxFSELog MAX(MAX(MLFSELog, LLFSELog), OffFSELog)
|
#define MaxFSELog MAX(MAX(MLFSELog, LLFSELog), OffFSELog)
|
||||||
|
#define MaxMLBits 16
|
||||||
|
#define MaxLLBits 16
|
||||||
|
|
||||||
static const U32 LL_bits[MaxLL+1] = { 0, 0, 0, 0, 0, 0, 0, 0,
|
#define ZSTD_MAX_HUF_HEADER_SIZE 128 /* header + <= 127 byte tree description */
|
||||||
|
/* Each table cannot take more than #symbols * FSELog bits */
|
||||||
|
#define ZSTD_MAX_FSE_HEADERS_SIZE (((MaxML + 1) * MLFSELog + (MaxLL + 1) * LLFSELog + (MaxOff + 1) * OffFSELog + 7) / 8)
|
||||||
|
|
||||||
|
static UNUSED_ATTR const U8 LL_bits[MaxLL+1] = {
|
||||||
|
0, 0, 0, 0, 0, 0, 0, 0,
|
||||||
0, 0, 0, 0, 0, 0, 0, 0,
|
0, 0, 0, 0, 0, 0, 0, 0,
|
||||||
1, 1, 1, 1, 2, 2, 3, 3,
|
1, 1, 1, 1, 2, 2, 3, 3,
|
||||||
4, 6, 7, 8, 9,10,11,12,
|
4, 6, 7, 8, 9,10,11,12,
|
||||||
13,14,15,16 };
|
13,14,15,16
|
||||||
static const S16 LL_defaultNorm[MaxLL+1] = { 4, 3, 2, 2, 2, 2, 2, 2,
|
};
|
||||||
|
static UNUSED_ATTR const S16 LL_defaultNorm[MaxLL+1] = {
|
||||||
|
4, 3, 2, 2, 2, 2, 2, 2,
|
||||||
2, 2, 2, 2, 2, 1, 1, 1,
|
2, 2, 2, 2, 2, 1, 1, 1,
|
||||||
2, 2, 2, 2, 2, 2, 2, 2,
|
2, 2, 2, 2, 2, 2, 2, 2,
|
||||||
2, 3, 2, 1, 1, 1, 1, 1,
|
2, 3, 2, 1, 1, 1, 1, 1,
|
||||||
-1,-1,-1,-1 };
|
-1,-1,-1,-1
|
||||||
|
};
|
||||||
#define LL_DEFAULTNORMLOG 6 /* for static allocation */
|
#define LL_DEFAULTNORMLOG 6 /* for static allocation */
|
||||||
static const U32 LL_defaultNormLog = LL_DEFAULTNORMLOG;
|
static UNUSED_ATTR const U32 LL_defaultNormLog = LL_DEFAULTNORMLOG;
|
||||||
|
|
||||||
static const U32 ML_bits[MaxML+1] = { 0, 0, 0, 0, 0, 0, 0, 0,
|
static UNUSED_ATTR const U8 ML_bits[MaxML+1] = {
|
||||||
|
0, 0, 0, 0, 0, 0, 0, 0,
|
||||||
0, 0, 0, 0, 0, 0, 0, 0,
|
0, 0, 0, 0, 0, 0, 0, 0,
|
||||||
0, 0, 0, 0, 0, 0, 0, 0,
|
0, 0, 0, 0, 0, 0, 0, 0,
|
||||||
0, 0, 0, 0, 0, 0, 0, 0,
|
0, 0, 0, 0, 0, 0, 0, 0,
|
||||||
1, 1, 1, 1, 2, 2, 3, 3,
|
1, 1, 1, 1, 2, 2, 3, 3,
|
||||||
4, 4, 5, 7, 8, 9,10,11,
|
4, 4, 5, 7, 8, 9,10,11,
|
||||||
12,13,14,15,16 };
|
12,13,14,15,16
|
||||||
static const S16 ML_defaultNorm[MaxML+1] = { 1, 4, 3, 2, 2, 2, 2, 2,
|
};
|
||||||
|
static UNUSED_ATTR const S16 ML_defaultNorm[MaxML+1] = {
|
||||||
|
1, 4, 3, 2, 2, 2, 2, 2,
|
||||||
2, 1, 1, 1, 1, 1, 1, 1,
|
2, 1, 1, 1, 1, 1, 1, 1,
|
||||||
1, 1, 1, 1, 1, 1, 1, 1,
|
1, 1, 1, 1, 1, 1, 1, 1,
|
||||||
1, 1, 1, 1, 1, 1, 1, 1,
|
1, 1, 1, 1, 1, 1, 1, 1,
|
||||||
1, 1, 1, 1, 1, 1, 1, 1,
|
1, 1, 1, 1, 1, 1, 1, 1,
|
||||||
1, 1, 1, 1, 1, 1,-1,-1,
|
1, 1, 1, 1, 1, 1,-1,-1,
|
||||||
-1,-1,-1,-1,-1 };
|
-1,-1,-1,-1,-1
|
||||||
|
};
|
||||||
#define ML_DEFAULTNORMLOG 6 /* for static allocation */
|
#define ML_DEFAULTNORMLOG 6 /* for static allocation */
|
||||||
static const U32 ML_defaultNormLog = ML_DEFAULTNORMLOG;
|
static UNUSED_ATTR const U32 ML_defaultNormLog = ML_DEFAULTNORMLOG;
|
||||||
|
|
||||||
static const S16 OF_defaultNorm[DefaultMaxOff+1] = { 1, 1, 1, 1, 1, 1, 2, 2,
|
static UNUSED_ATTR const S16 OF_defaultNorm[DefaultMaxOff+1] = {
|
||||||
|
1, 1, 1, 1, 1, 1, 2, 2,
|
||||||
2, 1, 1, 1, 1, 1, 1, 1,
|
2, 1, 1, 1, 1, 1, 1, 1,
|
||||||
1, 1, 1, 1, 1, 1, 1, 1,
|
1, 1, 1, 1, 1, 1, 1, 1,
|
||||||
-1,-1,-1,-1,-1 };
|
-1,-1,-1,-1,-1
|
||||||
|
};
|
||||||
#define OF_DEFAULTNORMLOG 5 /* for static allocation */
|
#define OF_DEFAULTNORMLOG 5 /* for static allocation */
|
||||||
static const U32 OF_defaultNormLog = OF_DEFAULTNORMLOG;
|
static UNUSED_ATTR const U32 OF_defaultNormLog = OF_DEFAULTNORMLOG;
|
||||||
|
|
||||||
|
|
||||||
/*-*******************************************
|
/*-*******************************************
|
||||||
* Shared functions to include for inlining
|
* Shared functions to include for inlining
|
||||||
*********************************************/
|
*********************************************/
|
||||||
static void ZSTD_copy8(void* dst, const void* src) { memcpy(dst, src, 8); }
|
static void ZSTD_copy8(void* dst, const void* src) {
|
||||||
|
#if defined(ZSTD_ARCH_ARM_NEON)
|
||||||
|
vst1_u8((uint8_t*)dst, vld1_u8((const uint8_t*)src));
|
||||||
|
#else
|
||||||
|
ZSTD_memcpy(dst, src, 8);
|
||||||
|
#endif
|
||||||
|
}
|
||||||
#define COPY8(d,s) { ZSTD_copy8(d,s); d+=8; s+=8; }
|
#define COPY8(d,s) { ZSTD_copy8(d,s); d+=8; s+=8; }
|
||||||
static void ZSTD_copy16(void* dst, const void* src) { memcpy(dst, src, 16); }
|
|
||||||
|
/* Need to use memmove here since the literal buffer can now be located within
|
||||||
|
the dst buffer. In circumstances where the op "catches up" to where the
|
||||||
|
literal buffer is, there can be partial overlaps in this call on the final
|
||||||
|
copy if the literal is being shifted by less than 16 bytes. */
|
||||||
|
static void ZSTD_copy16(void* dst, const void* src) {
|
||||||
|
#if defined(ZSTD_ARCH_ARM_NEON)
|
||||||
|
vst1q_u8((uint8_t*)dst, vld1q_u8((const uint8_t*)src));
|
||||||
|
#elif defined(ZSTD_ARCH_X86_SSE2)
|
||||||
|
_mm_storeu_si128((__m128i*)dst, _mm_loadu_si128((const __m128i*)src));
|
||||||
|
#elif defined(__clang__)
|
||||||
|
ZSTD_memmove(dst, src, 16);
|
||||||
|
#else
|
||||||
|
/* ZSTD_memmove is not inlined properly by gcc */
|
||||||
|
BYTE copy16_buf[16];
|
||||||
|
ZSTD_memcpy(copy16_buf, src, 16);
|
||||||
|
ZSTD_memcpy(dst, copy16_buf, 16);
|
||||||
|
#endif
|
||||||
|
}
|
||||||
#define COPY16(d,s) { ZSTD_copy16(d,s); d+=16; s+=16; }
|
#define COPY16(d,s) { ZSTD_copy16(d,s); d+=16; s+=16; }
|
||||||
|
|
||||||
#define WILDCOPY_OVERLENGTH 32
|
#define WILDCOPY_OVERLENGTH 32
|
||||||
@@ -207,13 +211,13 @@ typedef enum {
|
|||||||
} ZSTD_overlap_e;
|
} ZSTD_overlap_e;
|
||||||
|
|
||||||
/*! ZSTD_wildcopy() :
|
/*! ZSTD_wildcopy() :
|
||||||
* Custom version of memcpy(), can over read/write up to WILDCOPY_OVERLENGTH bytes (if length==0)
|
* Custom version of ZSTD_memcpy(), can over read/write up to WILDCOPY_OVERLENGTH bytes (if length==0)
|
||||||
* @param ovtype controls the overlap detection
|
* @param ovtype controls the overlap detection
|
||||||
* - ZSTD_no_overlap: The source and destination are guaranteed to be at least WILDCOPY_VECLEN bytes apart.
|
* - ZSTD_no_overlap: The source and destination are guaranteed to be at least WILDCOPY_VECLEN bytes apart.
|
||||||
* - ZSTD_overlap_src_before_dst: The src and dst may overlap, but they MUST be at least 8 bytes apart.
|
* - ZSTD_overlap_src_before_dst: The src and dst may overlap, but they MUST be at least 8 bytes apart.
|
||||||
* The src buffer must be before the dst buffer.
|
* The src buffer must be before the dst buffer.
|
||||||
*/
|
*/
|
||||||
MEM_STATIC FORCE_INLINE_ATTR DONT_VECTORIZE
|
MEM_STATIC FORCE_INLINE_ATTR
|
||||||
void ZSTD_wildcopy(void* dst, const void* src, ptrdiff_t length, ZSTD_overlap_e const ovtype)
|
void ZSTD_wildcopy(void* dst, const void* src, ptrdiff_t length, ZSTD_overlap_e const ovtype)
|
||||||
{
|
{
|
||||||
ptrdiff_t diff = (BYTE*)dst - (const BYTE*)src;
|
ptrdiff_t diff = (BYTE*)dst - (const BYTE*)src;
|
||||||
@@ -221,8 +225,6 @@ void ZSTD_wildcopy(void* dst, const void* src, ptrdiff_t length, ZSTD_overlap_e
|
|||||||
BYTE* op = (BYTE*)dst;
|
BYTE* op = (BYTE*)dst;
|
||||||
BYTE* const oend = op + length;
|
BYTE* const oend = op + length;
|
||||||
|
|
||||||
assert(diff >= 8 || (ovtype == ZSTD_no_overlap && diff <= -WILDCOPY_VECLEN));
|
|
||||||
|
|
||||||
if (ovtype == ZSTD_overlap_src_before_dst && diff < WILDCOPY_VECLEN) {
|
if (ovtype == ZSTD_overlap_src_before_dst && diff < WILDCOPY_VECLEN) {
|
||||||
/* Handle short offset copies. */
|
/* Handle short offset copies. */
|
||||||
do {
|
do {
|
||||||
@@ -230,15 +232,16 @@ void ZSTD_wildcopy(void* dst, const void* src, ptrdiff_t length, ZSTD_overlap_e
|
|||||||
} while (op < oend);
|
} while (op < oend);
|
||||||
} else {
|
} else {
|
||||||
assert(diff >= WILDCOPY_VECLEN || diff <= -WILDCOPY_VECLEN);
|
assert(diff >= WILDCOPY_VECLEN || diff <= -WILDCOPY_VECLEN);
|
||||||
/* Separate out the first two COPY16() calls because the copy length is
|
/* Separate out the first COPY16() call because the copy length is
|
||||||
* almost certain to be short, so the branches have different
|
* almost certain to be short, so the branches have different
|
||||||
* probabilities.
|
* probabilities. Since it is almost certain to be short, only do
|
||||||
* On gcc-9 unrolling once is +1.6%, twice is +2%, thrice is +1.8%.
|
* one COPY16() in the first call. Then, do two calls per loop since
|
||||||
* On clang-8 unrolling once is +1.4%, twice is +3.3%, thrice is +3%.
|
* at that point it is more likely to have a high trip count.
|
||||||
*/
|
*/
|
||||||
COPY16(op, ip);
|
ZSTD_copy16(op, ip);
|
||||||
COPY16(op, ip);
|
if (16 >= length) return;
|
||||||
if (op >= oend) return;
|
op += 16;
|
||||||
|
ip += 16;
|
||||||
do {
|
do {
|
||||||
COPY16(op, ip);
|
COPY16(op, ip);
|
||||||
COPY16(op, ip);
|
COPY16(op, ip);
|
||||||
@@ -247,30 +250,92 @@ void ZSTD_wildcopy(void* dst, const void* src, ptrdiff_t length, ZSTD_overlap_e
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
MEM_STATIC size_t ZSTD_limitCopy(void* dst, size_t dstCapacity, const void* src, size_t srcSize)
|
||||||
|
{
|
||||||
|
size_t const length = MIN(dstCapacity, srcSize);
|
||||||
|
if (length > 0) {
|
||||||
|
ZSTD_memcpy(dst, src, length);
|
||||||
|
}
|
||||||
|
return length;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* define "workspace is too large" as this number of times larger than needed */
|
||||||
|
#define ZSTD_WORKSPACETOOLARGE_FACTOR 3
|
||||||
|
|
||||||
|
/* when workspace is continuously too large
|
||||||
|
* during at least this number of times,
|
||||||
|
* context's memory usage is considered wasteful,
|
||||||
|
* because it's sized to handle a worst case scenario which rarely happens.
|
||||||
|
* In which case, resize it down to free some memory */
|
||||||
|
#define ZSTD_WORKSPACETOOLARGE_MAXDURATION 128
|
||||||
|
|
||||||
|
/* Controls whether the input/output buffer is buffered or stable. */
|
||||||
|
typedef enum {
|
||||||
|
ZSTD_bm_buffered = 0, /* Buffer the input/output */
|
||||||
|
ZSTD_bm_stable = 1 /* ZSTD_inBuffer/ZSTD_outBuffer is stable */
|
||||||
|
} ZSTD_bufferMode_e;
|
||||||
|
|
||||||
|
|
||||||
/*-*******************************************
|
/*-*******************************************
|
||||||
* Private declarations
|
* Private declarations
|
||||||
*********************************************/
|
*********************************************/
|
||||||
typedef struct seqDef_s {
|
typedef struct seqDef_s {
|
||||||
U32 offset;
|
U32 offBase; /* offBase == Offset + ZSTD_REP_NUM, or repcode 1,2,3 */
|
||||||
U16 litLength;
|
U16 litLength;
|
||||||
U16 matchLength;
|
U16 mlBase; /* mlBase == matchLength - MINMATCH */
|
||||||
} seqDef;
|
} seqDef;
|
||||||
|
|
||||||
|
/* Controls whether seqStore has a single "long" litLength or matchLength. See seqStore_t. */
|
||||||
|
typedef enum {
|
||||||
|
ZSTD_llt_none = 0, /* no longLengthType */
|
||||||
|
ZSTD_llt_literalLength = 1, /* represents a long literal */
|
||||||
|
ZSTD_llt_matchLength = 2 /* represents a long match */
|
||||||
|
} ZSTD_longLengthType_e;
|
||||||
|
|
||||||
typedef struct {
|
typedef struct {
|
||||||
seqDef* sequencesStart;
|
seqDef* sequencesStart;
|
||||||
seqDef* sequences;
|
seqDef* sequences; /* ptr to end of sequences */
|
||||||
BYTE* litStart;
|
BYTE* litStart;
|
||||||
BYTE* lit;
|
BYTE* lit; /* ptr to end of literals */
|
||||||
BYTE* llCode;
|
BYTE* llCode;
|
||||||
BYTE* mlCode;
|
BYTE* mlCode;
|
||||||
BYTE* ofCode;
|
BYTE* ofCode;
|
||||||
size_t maxNbSeq;
|
size_t maxNbSeq;
|
||||||
size_t maxNbLit;
|
size_t maxNbLit;
|
||||||
U32 longLengthID; /* 0 == no longLength; 1 == Lit.longLength; 2 == Match.longLength; */
|
|
||||||
U32 longLengthPos;
|
/* longLengthPos and longLengthType to allow us to represent either a single litLength or matchLength
|
||||||
|
* in the seqStore that has a value larger than U16 (if it exists). To do so, we increment
|
||||||
|
* the existing value of the litLength or matchLength by 0x10000.
|
||||||
|
*/
|
||||||
|
ZSTD_longLengthType_e longLengthType;
|
||||||
|
U32 longLengthPos; /* Index of the sequence to apply long length modification to */
|
||||||
} seqStore_t;
|
} seqStore_t;
|
||||||
|
|
||||||
|
typedef struct {
|
||||||
|
U32 litLength;
|
||||||
|
U32 matchLength;
|
||||||
|
} ZSTD_sequenceLength;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns the ZSTD_sequenceLength for the given sequences. It handles the decoding of long sequences
|
||||||
|
* indicated by longLengthPos and longLengthType, and adds MINMATCH back to matchLength.
|
||||||
|
*/
|
||||||
|
MEM_STATIC ZSTD_sequenceLength ZSTD_getSequenceLength(seqStore_t const* seqStore, seqDef const* seq)
|
||||||
|
{
|
||||||
|
ZSTD_sequenceLength seqLen;
|
||||||
|
seqLen.litLength = seq->litLength;
|
||||||
|
seqLen.matchLength = seq->mlBase + MINMATCH;
|
||||||
|
if (seqStore->longLengthPos == (U32)(seq - seqStore->sequencesStart)) {
|
||||||
|
if (seqStore->longLengthType == ZSTD_llt_literalLength) {
|
||||||
|
seqLen.litLength += 0x10000;
|
||||||
|
}
|
||||||
|
if (seqStore->longLengthType == ZSTD_llt_matchLength) {
|
||||||
|
seqLen.matchLength += 0x10000;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return seqLen;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Contains the compressed frame size and an upper-bound for the decompressed frame size.
|
* Contains the compressed frame size and an upper-bound for the decompressed frame size.
|
||||||
* Note: before using `compressedSize`, check for errors using ZSTD_isError().
|
* Note: before using `compressedSize`, check for errors using ZSTD_isError().
|
||||||
@@ -278,43 +343,13 @@ typedef struct {
|
|||||||
* `decompressedBound != ZSTD_CONTENTSIZE_ERROR`
|
* `decompressedBound != ZSTD_CONTENTSIZE_ERROR`
|
||||||
*/
|
*/
|
||||||
typedef struct {
|
typedef struct {
|
||||||
|
size_t nbBlocks;
|
||||||
size_t compressedSize;
|
size_t compressedSize;
|
||||||
unsigned long long decompressedBound;
|
unsigned long long decompressedBound;
|
||||||
} ZSTD_frameSizeInfo; /* decompress & legacy */
|
} ZSTD_frameSizeInfo; /* decompress & legacy */
|
||||||
|
|
||||||
const seqStore_t* ZSTD_getSeqStore(const ZSTD_CCtx* ctx); /* compress & dictBuilder */
|
const seqStore_t* ZSTD_getSeqStore(const ZSTD_CCtx* ctx); /* compress & dictBuilder */
|
||||||
void ZSTD_seqToCodes(const seqStore_t* seqStorePtr); /* compress, dictBuilder, decodeCorpus (shouldn't get its definition from here) */
|
int ZSTD_seqToCodes(const seqStore_t* seqStorePtr); /* compress, dictBuilder, decodeCorpus (shouldn't get its definition from here) */
|
||||||
|
|
||||||
/* custom memory allocation functions */
|
|
||||||
void* ZSTD_malloc(size_t size, ZSTD_customMem customMem);
|
|
||||||
void* ZSTD_calloc(size_t size, ZSTD_customMem customMem);
|
|
||||||
void ZSTD_free(void* ptr, ZSTD_customMem customMem);
|
|
||||||
|
|
||||||
|
|
||||||
MEM_STATIC U32 ZSTD_highbit32(U32 val) /* compress, dictBuilder, decodeCorpus */
|
|
||||||
{
|
|
||||||
assert(val != 0);
|
|
||||||
{
|
|
||||||
# if defined(_MSC_VER) /* Visual */
|
|
||||||
unsigned long r=0;
|
|
||||||
_BitScanReverse(&r, val);
|
|
||||||
return (unsigned)r;
|
|
||||||
# elif defined(__GNUC__) && (__GNUC__ >= 3) /* GCC Intrinsic */
|
|
||||||
return __builtin_clz (val) ^ 31;
|
|
||||||
# elif defined(__ICCARM__) /* IAR Intrinsic */
|
|
||||||
return 31 - __CLZ(val);
|
|
||||||
# else /* Software version */
|
|
||||||
static const U32 DeBruijnClz[32] = { 0, 9, 1, 10, 13, 21, 2, 29, 11, 14, 16, 18, 22, 25, 3, 30, 8, 12, 20, 28, 15, 17, 24, 7, 19, 27, 23, 6, 26, 5, 4, 31 };
|
|
||||||
U32 v = val;
|
|
||||||
v |= v >> 1;
|
|
||||||
v |= v >> 2;
|
|
||||||
v |= v >> 4;
|
|
||||||
v |= v >> 8;
|
|
||||||
v |= v >> 16;
|
|
||||||
return DeBruijnClz[(v * 0x07C4ACDDU) >> 27];
|
|
||||||
# endif
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
/* ZSTD_invalidateRepCodes() :
|
/* ZSTD_invalidateRepCodes() :
|
||||||
@@ -342,9 +377,19 @@ size_t ZSTD_getcBlockSize(const void* src, size_t srcSize,
|
|||||||
size_t ZSTD_decodeSeqHeaders(ZSTD_DCtx* dctx, int* nbSeqPtr,
|
size_t ZSTD_decodeSeqHeaders(ZSTD_DCtx* dctx, int* nbSeqPtr,
|
||||||
const void* src, size_t srcSize);
|
const void* src, size_t srcSize);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @returns true iff the CPU supports dynamic BMI2 dispatch.
|
||||||
|
*/
|
||||||
|
MEM_STATIC int ZSTD_cpuSupportsBmi2(void)
|
||||||
|
{
|
||||||
|
ZSTD_cpuid_t cpuid = ZSTD_cpuid();
|
||||||
|
return ZSTD_cpuid_bmi1(cpuid) && ZSTD_cpuid_bmi2(cpuid);
|
||||||
|
}
|
||||||
|
|
||||||
#if defined (__cplusplus)
|
#if defined (__cplusplus)
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#endif /* ZSTD_CCOMMON_H_MODULE */
|
#endif /* ZSTD_CCOMMON_H_MODULE */
|
||||||
|
|
||||||
|
#endif /* USE_EXTERNAL_ZSTD */
|
||||||
|
|||||||
1553
vendor/github.com/DataDog/zstd/zstd_lazy.c
generated
vendored
1553
vendor/github.com/DataDog/zstd/zstd_lazy.c
generated
vendored
File diff suppressed because it is too large
Load Diff
65
vendor/github.com/DataDog/zstd/zstd_lazy.h
generated
vendored
65
vendor/github.com/DataDog/zstd/zstd_lazy.h
generated
vendored
@@ -1,5 +1,6 @@
|
|||||||
|
#ifndef USE_EXTERNAL_ZSTD
|
||||||
/*
|
/*
|
||||||
* Copyright (c) 2016-present, Yann Collet, Facebook, Inc.
|
* Copyright (c) Meta Platforms, Inc. and affiliates.
|
||||||
* All rights reserved.
|
* All rights reserved.
|
||||||
*
|
*
|
||||||
* This source code is licensed under both the BSD-style license (found in the
|
* This source code is licensed under both the BSD-style license (found in the
|
||||||
@@ -17,7 +18,20 @@ extern "C" {
|
|||||||
|
|
||||||
#include "zstd_compress_internal.h"
|
#include "zstd_compress_internal.h"
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Dedicated Dictionary Search Structure bucket log. In the
|
||||||
|
* ZSTD_dedicatedDictSearch mode, the hashTable has
|
||||||
|
* 2 ** ZSTD_LAZY_DDSS_BUCKET_LOG entries in each bucket, rather than just
|
||||||
|
* one.
|
||||||
|
*/
|
||||||
|
#define ZSTD_LAZY_DDSS_BUCKET_LOG 2
|
||||||
|
|
||||||
|
#define ZSTD_ROW_HASH_TAG_BITS 8 /* nb bits to use for the tag */
|
||||||
|
|
||||||
U32 ZSTD_insertAndFindFirstIndex(ZSTD_matchState_t* ms, const BYTE* ip);
|
U32 ZSTD_insertAndFindFirstIndex(ZSTD_matchState_t* ms, const BYTE* ip);
|
||||||
|
void ZSTD_row_update(ZSTD_matchState_t* const ms, const BYTE* ip);
|
||||||
|
|
||||||
|
void ZSTD_dedicatedDictSearch_lazy_loadDictionary(ZSTD_matchState_t* ms, const BYTE* const ip);
|
||||||
|
|
||||||
void ZSTD_preserveUnsortedMark (U32* const table, U32 const size, U32 const reducerValue); /*! used in ZSTD_reduceIndex(). preemptively increase value of ZSTD_DUBT_UNSORTED_MARK */
|
void ZSTD_preserveUnsortedMark (U32* const table, U32 const size, U32 const reducerValue); /*! used in ZSTD_reduceIndex(). preemptively increase value of ZSTD_DUBT_UNSORTED_MARK */
|
||||||
|
|
||||||
@@ -33,6 +47,15 @@ size_t ZSTD_compressBlock_lazy(
|
|||||||
size_t ZSTD_compressBlock_greedy(
|
size_t ZSTD_compressBlock_greedy(
|
||||||
ZSTD_matchState_t* ms, seqStore_t* seqStore, U32 rep[ZSTD_REP_NUM],
|
ZSTD_matchState_t* ms, seqStore_t* seqStore, U32 rep[ZSTD_REP_NUM],
|
||||||
void const* src, size_t srcSize);
|
void const* src, size_t srcSize);
|
||||||
|
size_t ZSTD_compressBlock_lazy2_row(
|
||||||
|
ZSTD_matchState_t* ms, seqStore_t* seqStore, U32 rep[ZSTD_REP_NUM],
|
||||||
|
void const* src, size_t srcSize);
|
||||||
|
size_t ZSTD_compressBlock_lazy_row(
|
||||||
|
ZSTD_matchState_t* ms, seqStore_t* seqStore, U32 rep[ZSTD_REP_NUM],
|
||||||
|
void const* src, size_t srcSize);
|
||||||
|
size_t ZSTD_compressBlock_greedy_row(
|
||||||
|
ZSTD_matchState_t* ms, seqStore_t* seqStore, U32 rep[ZSTD_REP_NUM],
|
||||||
|
void const* src, size_t srcSize);
|
||||||
|
|
||||||
size_t ZSTD_compressBlock_btlazy2_dictMatchState(
|
size_t ZSTD_compressBlock_btlazy2_dictMatchState(
|
||||||
ZSTD_matchState_t* ms, seqStore_t* seqStore, U32 rep[ZSTD_REP_NUM],
|
ZSTD_matchState_t* ms, seqStore_t* seqStore, U32 rep[ZSTD_REP_NUM],
|
||||||
@@ -46,6 +69,34 @@ size_t ZSTD_compressBlock_lazy_dictMatchState(
|
|||||||
size_t ZSTD_compressBlock_greedy_dictMatchState(
|
size_t ZSTD_compressBlock_greedy_dictMatchState(
|
||||||
ZSTD_matchState_t* ms, seqStore_t* seqStore, U32 rep[ZSTD_REP_NUM],
|
ZSTD_matchState_t* ms, seqStore_t* seqStore, U32 rep[ZSTD_REP_NUM],
|
||||||
void const* src, size_t srcSize);
|
void const* src, size_t srcSize);
|
||||||
|
size_t ZSTD_compressBlock_lazy2_dictMatchState_row(
|
||||||
|
ZSTD_matchState_t* ms, seqStore_t* seqStore, U32 rep[ZSTD_REP_NUM],
|
||||||
|
void const* src, size_t srcSize);
|
||||||
|
size_t ZSTD_compressBlock_lazy_dictMatchState_row(
|
||||||
|
ZSTD_matchState_t* ms, seqStore_t* seqStore, U32 rep[ZSTD_REP_NUM],
|
||||||
|
void const* src, size_t srcSize);
|
||||||
|
size_t ZSTD_compressBlock_greedy_dictMatchState_row(
|
||||||
|
ZSTD_matchState_t* ms, seqStore_t* seqStore, U32 rep[ZSTD_REP_NUM],
|
||||||
|
void const* src, size_t srcSize);
|
||||||
|
|
||||||
|
size_t ZSTD_compressBlock_lazy2_dedicatedDictSearch(
|
||||||
|
ZSTD_matchState_t* ms, seqStore_t* seqStore, U32 rep[ZSTD_REP_NUM],
|
||||||
|
void const* src, size_t srcSize);
|
||||||
|
size_t ZSTD_compressBlock_lazy_dedicatedDictSearch(
|
||||||
|
ZSTD_matchState_t* ms, seqStore_t* seqStore, U32 rep[ZSTD_REP_NUM],
|
||||||
|
void const* src, size_t srcSize);
|
||||||
|
size_t ZSTD_compressBlock_greedy_dedicatedDictSearch(
|
||||||
|
ZSTD_matchState_t* ms, seqStore_t* seqStore, U32 rep[ZSTD_REP_NUM],
|
||||||
|
void const* src, size_t srcSize);
|
||||||
|
size_t ZSTD_compressBlock_lazy2_dedicatedDictSearch_row(
|
||||||
|
ZSTD_matchState_t* ms, seqStore_t* seqStore, U32 rep[ZSTD_REP_NUM],
|
||||||
|
void const* src, size_t srcSize);
|
||||||
|
size_t ZSTD_compressBlock_lazy_dedicatedDictSearch_row(
|
||||||
|
ZSTD_matchState_t* ms, seqStore_t* seqStore, U32 rep[ZSTD_REP_NUM],
|
||||||
|
void const* src, size_t srcSize);
|
||||||
|
size_t ZSTD_compressBlock_greedy_dedicatedDictSearch_row(
|
||||||
|
ZSTD_matchState_t* ms, seqStore_t* seqStore, U32 rep[ZSTD_REP_NUM],
|
||||||
|
void const* src, size_t srcSize);
|
||||||
|
|
||||||
size_t ZSTD_compressBlock_greedy_extDict(
|
size_t ZSTD_compressBlock_greedy_extDict(
|
||||||
ZSTD_matchState_t* ms, seqStore_t* seqStore, U32 rep[ZSTD_REP_NUM],
|
ZSTD_matchState_t* ms, seqStore_t* seqStore, U32 rep[ZSTD_REP_NUM],
|
||||||
@@ -56,12 +107,24 @@ size_t ZSTD_compressBlock_lazy_extDict(
|
|||||||
size_t ZSTD_compressBlock_lazy2_extDict(
|
size_t ZSTD_compressBlock_lazy2_extDict(
|
||||||
ZSTD_matchState_t* ms, seqStore_t* seqStore, U32 rep[ZSTD_REP_NUM],
|
ZSTD_matchState_t* ms, seqStore_t* seqStore, U32 rep[ZSTD_REP_NUM],
|
||||||
void const* src, size_t srcSize);
|
void const* src, size_t srcSize);
|
||||||
|
size_t ZSTD_compressBlock_greedy_extDict_row(
|
||||||
|
ZSTD_matchState_t* ms, seqStore_t* seqStore, U32 rep[ZSTD_REP_NUM],
|
||||||
|
void const* src, size_t srcSize);
|
||||||
|
size_t ZSTD_compressBlock_lazy_extDict_row(
|
||||||
|
ZSTD_matchState_t* ms, seqStore_t* seqStore, U32 rep[ZSTD_REP_NUM],
|
||||||
|
void const* src, size_t srcSize);
|
||||||
|
size_t ZSTD_compressBlock_lazy2_extDict_row(
|
||||||
|
ZSTD_matchState_t* ms, seqStore_t* seqStore, U32 rep[ZSTD_REP_NUM],
|
||||||
|
void const* src, size_t srcSize);
|
||||||
size_t ZSTD_compressBlock_btlazy2_extDict(
|
size_t ZSTD_compressBlock_btlazy2_extDict(
|
||||||
ZSTD_matchState_t* ms, seqStore_t* seqStore, U32 rep[ZSTD_REP_NUM],
|
ZSTD_matchState_t* ms, seqStore_t* seqStore, U32 rep[ZSTD_REP_NUM],
|
||||||
void const* src, size_t srcSize);
|
void const* src, size_t srcSize);
|
||||||
|
|
||||||
|
|
||||||
#if defined (__cplusplus)
|
#if defined (__cplusplus)
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#endif /* ZSTD_LAZY_H */
|
#endif /* ZSTD_LAZY_H */
|
||||||
|
|
||||||
|
#endif /* USE_EXTERNAL_ZSTD */
|
||||||
|
|||||||
514
vendor/github.com/DataDog/zstd/zstd_ldm.c
generated
vendored
514
vendor/github.com/DataDog/zstd/zstd_ldm.c
generated
vendored
@@ -1,22 +1,137 @@
|
|||||||
|
#ifndef USE_EXTERNAL_ZSTD
|
||||||
/*
|
/*
|
||||||
* Copyright (c) 2016-present, Yann Collet, Facebook, Inc.
|
* Copyright (c) Meta Platforms, Inc. and affiliates.
|
||||||
* All rights reserved.
|
* All rights reserved.
|
||||||
*
|
*
|
||||||
* This source code is licensed under both the BSD-style license (found in the
|
* This source code is licensed under both the BSD-style license (found in the
|
||||||
* LICENSE file in the root directory of this source tree) and the GPLv2 (found
|
* LICENSE file in the root directory of this source tree) and the GPLv2 (found
|
||||||
* in the COPYING file in the root directory of this source tree).
|
* in the COPYING file in the root directory of this source tree).
|
||||||
|
* You may select, at your option, one of the above-listed licenses.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include "zstd_ldm.h"
|
#include "zstd_ldm.h"
|
||||||
|
|
||||||
#include "debug.h"
|
#include "debug.h"
|
||||||
|
#include "xxhash.h"
|
||||||
#include "zstd_fast.h" /* ZSTD_fillHashTable() */
|
#include "zstd_fast.h" /* ZSTD_fillHashTable() */
|
||||||
#include "zstd_double_fast.h" /* ZSTD_fillDoubleHashTable() */
|
#include "zstd_double_fast.h" /* ZSTD_fillDoubleHashTable() */
|
||||||
|
#include "zstd_ldm_geartab.h"
|
||||||
|
|
||||||
#define LDM_BUCKET_SIZE_LOG 3
|
#define LDM_BUCKET_SIZE_LOG 3
|
||||||
#define LDM_MIN_MATCH_LENGTH 64
|
#define LDM_MIN_MATCH_LENGTH 64
|
||||||
#define LDM_HASH_RLOG 7
|
#define LDM_HASH_RLOG 7
|
||||||
#define LDM_HASH_CHAR_OFFSET 10
|
|
||||||
|
typedef struct {
|
||||||
|
U64 rolling;
|
||||||
|
U64 stopMask;
|
||||||
|
} ldmRollingHashState_t;
|
||||||
|
|
||||||
|
/** ZSTD_ldm_gear_init():
|
||||||
|
*
|
||||||
|
* Initializes the rolling hash state such that it will honor the
|
||||||
|
* settings in params. */
|
||||||
|
static void ZSTD_ldm_gear_init(ldmRollingHashState_t* state, ldmParams_t const* params)
|
||||||
|
{
|
||||||
|
unsigned maxBitsInMask = MIN(params->minMatchLength, 64);
|
||||||
|
unsigned hashRateLog = params->hashRateLog;
|
||||||
|
|
||||||
|
state->rolling = ~(U32)0;
|
||||||
|
|
||||||
|
/* The choice of the splitting criterion is subject to two conditions:
|
||||||
|
* 1. it has to trigger on average every 2^(hashRateLog) bytes;
|
||||||
|
* 2. ideally, it has to depend on a window of minMatchLength bytes.
|
||||||
|
*
|
||||||
|
* In the gear hash algorithm, bit n depends on the last n bytes;
|
||||||
|
* so in order to obtain a good quality splitting criterion it is
|
||||||
|
* preferable to use bits with high weight.
|
||||||
|
*
|
||||||
|
* To match condition 1 we use a mask with hashRateLog bits set
|
||||||
|
* and, because of the previous remark, we make sure these bits
|
||||||
|
* have the highest possible weight while still respecting
|
||||||
|
* condition 2.
|
||||||
|
*/
|
||||||
|
if (hashRateLog > 0 && hashRateLog <= maxBitsInMask) {
|
||||||
|
state->stopMask = (((U64)1 << hashRateLog) - 1) << (maxBitsInMask - hashRateLog);
|
||||||
|
} else {
|
||||||
|
/* In this degenerate case we simply honor the hash rate. */
|
||||||
|
state->stopMask = ((U64)1 << hashRateLog) - 1;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/** ZSTD_ldm_gear_reset()
|
||||||
|
* Feeds [data, data + minMatchLength) into the hash without registering any
|
||||||
|
* splits. This effectively resets the hash state. This is used when skipping
|
||||||
|
* over data, either at the beginning of a block, or skipping sections.
|
||||||
|
*/
|
||||||
|
static void ZSTD_ldm_gear_reset(ldmRollingHashState_t* state,
|
||||||
|
BYTE const* data, size_t minMatchLength)
|
||||||
|
{
|
||||||
|
U64 hash = state->rolling;
|
||||||
|
size_t n = 0;
|
||||||
|
|
||||||
|
#define GEAR_ITER_ONCE() do { \
|
||||||
|
hash = (hash << 1) + ZSTD_ldm_gearTab[data[n] & 0xff]; \
|
||||||
|
n += 1; \
|
||||||
|
} while (0)
|
||||||
|
while (n + 3 < minMatchLength) {
|
||||||
|
GEAR_ITER_ONCE();
|
||||||
|
GEAR_ITER_ONCE();
|
||||||
|
GEAR_ITER_ONCE();
|
||||||
|
GEAR_ITER_ONCE();
|
||||||
|
}
|
||||||
|
while (n < minMatchLength) {
|
||||||
|
GEAR_ITER_ONCE();
|
||||||
|
}
|
||||||
|
#undef GEAR_ITER_ONCE
|
||||||
|
}
|
||||||
|
|
||||||
|
/** ZSTD_ldm_gear_feed():
|
||||||
|
*
|
||||||
|
* Registers in the splits array all the split points found in the first
|
||||||
|
* size bytes following the data pointer. This function terminates when
|
||||||
|
* either all the data has been processed or LDM_BATCH_SIZE splits are
|
||||||
|
* present in the splits array.
|
||||||
|
*
|
||||||
|
* Precondition: The splits array must not be full.
|
||||||
|
* Returns: The number of bytes processed. */
|
||||||
|
static size_t ZSTD_ldm_gear_feed(ldmRollingHashState_t* state,
|
||||||
|
BYTE const* data, size_t size,
|
||||||
|
size_t* splits, unsigned* numSplits)
|
||||||
|
{
|
||||||
|
size_t n;
|
||||||
|
U64 hash, mask;
|
||||||
|
|
||||||
|
hash = state->rolling;
|
||||||
|
mask = state->stopMask;
|
||||||
|
n = 0;
|
||||||
|
|
||||||
|
#define GEAR_ITER_ONCE() do { \
|
||||||
|
hash = (hash << 1) + ZSTD_ldm_gearTab[data[n] & 0xff]; \
|
||||||
|
n += 1; \
|
||||||
|
if (UNLIKELY((hash & mask) == 0)) { \
|
||||||
|
splits[*numSplits] = n; \
|
||||||
|
*numSplits += 1; \
|
||||||
|
if (*numSplits == LDM_BATCH_SIZE) \
|
||||||
|
goto done; \
|
||||||
|
} \
|
||||||
|
} while (0)
|
||||||
|
|
||||||
|
while (n + 3 < size) {
|
||||||
|
GEAR_ITER_ONCE();
|
||||||
|
GEAR_ITER_ONCE();
|
||||||
|
GEAR_ITER_ONCE();
|
||||||
|
GEAR_ITER_ONCE();
|
||||||
|
}
|
||||||
|
while (n < size) {
|
||||||
|
GEAR_ITER_ONCE();
|
||||||
|
}
|
||||||
|
|
||||||
|
#undef GEAR_ITER_ONCE
|
||||||
|
|
||||||
|
done:
|
||||||
|
state->rolling = hash;
|
||||||
|
return n;
|
||||||
|
}
|
||||||
|
|
||||||
void ZSTD_ldm_adjustParameters(ldmParams_t* params,
|
void ZSTD_ldm_adjustParameters(ldmParams_t* params,
|
||||||
ZSTD_compressionParameters const* cParams)
|
ZSTD_compressionParameters const* cParams)
|
||||||
@@ -26,13 +141,6 @@ void ZSTD_ldm_adjustParameters(ldmParams_t* params,
|
|||||||
DEBUGLOG(4, "ZSTD_ldm_adjustParameters");
|
DEBUGLOG(4, "ZSTD_ldm_adjustParameters");
|
||||||
if (!params->bucketSizeLog) params->bucketSizeLog = LDM_BUCKET_SIZE_LOG;
|
if (!params->bucketSizeLog) params->bucketSizeLog = LDM_BUCKET_SIZE_LOG;
|
||||||
if (!params->minMatchLength) params->minMatchLength = LDM_MIN_MATCH_LENGTH;
|
if (!params->minMatchLength) params->minMatchLength = LDM_MIN_MATCH_LENGTH;
|
||||||
if (cParams->strategy >= ZSTD_btopt) {
|
|
||||||
/* Get out of the way of the optimal parser */
|
|
||||||
U32 const minMatch = MAX(cParams->targetLength, params->minMatchLength);
|
|
||||||
assert(minMatch >= ZSTD_LDM_MINMATCH_MIN);
|
|
||||||
assert(minMatch <= ZSTD_LDM_MINMATCH_MAX);
|
|
||||||
params->minMatchLength = minMatch;
|
|
||||||
}
|
|
||||||
if (params->hashLog == 0) {
|
if (params->hashLog == 0) {
|
||||||
params->hashLog = MAX(ZSTD_HASHLOG_MIN, params->windowLog - LDM_HASH_RLOG);
|
params->hashLog = MAX(ZSTD_HASHLOG_MIN, params->windowLog - LDM_HASH_RLOG);
|
||||||
assert(params->hashLog <= ZSTD_HASHLOG_MAX);
|
assert(params->hashLog <= ZSTD_HASHLOG_MAX);
|
||||||
@@ -52,47 +160,12 @@ size_t ZSTD_ldm_getTableSize(ldmParams_t params)
|
|||||||
size_t const ldmBucketSize = ((size_t)1) << (params.hashLog - ldmBucketSizeLog);
|
size_t const ldmBucketSize = ((size_t)1) << (params.hashLog - ldmBucketSizeLog);
|
||||||
size_t const totalSize = ZSTD_cwksp_alloc_size(ldmBucketSize)
|
size_t const totalSize = ZSTD_cwksp_alloc_size(ldmBucketSize)
|
||||||
+ ZSTD_cwksp_alloc_size(ldmHSize * sizeof(ldmEntry_t));
|
+ ZSTD_cwksp_alloc_size(ldmHSize * sizeof(ldmEntry_t));
|
||||||
return params.enableLdm ? totalSize : 0;
|
return params.enableLdm == ZSTD_ps_enable ? totalSize : 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
size_t ZSTD_ldm_getMaxNbSeq(ldmParams_t params, size_t maxChunkSize)
|
size_t ZSTD_ldm_getMaxNbSeq(ldmParams_t params, size_t maxChunkSize)
|
||||||
{
|
{
|
||||||
return params.enableLdm ? (maxChunkSize / params.minMatchLength) : 0;
|
return params.enableLdm == ZSTD_ps_enable ? (maxChunkSize / params.minMatchLength) : 0;
|
||||||
}
|
|
||||||
|
|
||||||
/** ZSTD_ldm_getSmallHash() :
|
|
||||||
* numBits should be <= 32
|
|
||||||
* If numBits==0, returns 0.
|
|
||||||
* @return : the most significant numBits of value. */
|
|
||||||
static U32 ZSTD_ldm_getSmallHash(U64 value, U32 numBits)
|
|
||||||
{
|
|
||||||
assert(numBits <= 32);
|
|
||||||
return numBits == 0 ? 0 : (U32)(value >> (64 - numBits));
|
|
||||||
}
|
|
||||||
|
|
||||||
/** ZSTD_ldm_getChecksum() :
|
|
||||||
* numBitsToDiscard should be <= 32
|
|
||||||
* @return : the next most significant 32 bits after numBitsToDiscard */
|
|
||||||
static U32 ZSTD_ldm_getChecksum(U64 hash, U32 numBitsToDiscard)
|
|
||||||
{
|
|
||||||
assert(numBitsToDiscard <= 32);
|
|
||||||
return (hash >> (64 - 32 - numBitsToDiscard)) & 0xFFFFFFFF;
|
|
||||||
}
|
|
||||||
|
|
||||||
/** ZSTD_ldm_getTag() ;
|
|
||||||
* Given the hash, returns the most significant numTagBits bits
|
|
||||||
* after (32 + hbits) bits.
|
|
||||||
*
|
|
||||||
* If there are not enough bits remaining, return the last
|
|
||||||
* numTagBits bits. */
|
|
||||||
static U32 ZSTD_ldm_getTag(U64 hash, U32 hbits, U32 numTagBits)
|
|
||||||
{
|
|
||||||
assert(numTagBits < 32 && hbits <= 32);
|
|
||||||
if (32 - hbits < numTagBits) {
|
|
||||||
return hash & (((U32)1 << numTagBits) - 1);
|
|
||||||
} else {
|
|
||||||
return (hash >> (32 - hbits - numTagBits)) & (((U32)1 << numTagBits) - 1);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/** ZSTD_ldm_getBucket() :
|
/** ZSTD_ldm_getBucket() :
|
||||||
@@ -109,38 +182,12 @@ static void ZSTD_ldm_insertEntry(ldmState_t* ldmState,
|
|||||||
size_t const hash, const ldmEntry_t entry,
|
size_t const hash, const ldmEntry_t entry,
|
||||||
ldmParams_t const ldmParams)
|
ldmParams_t const ldmParams)
|
||||||
{
|
{
|
||||||
BYTE* const bucketOffsets = ldmState->bucketOffsets;
|
BYTE* const pOffset = ldmState->bucketOffsets + hash;
|
||||||
*(ZSTD_ldm_getBucket(ldmState, hash, ldmParams) + bucketOffsets[hash]) = entry;
|
unsigned const offset = *pOffset;
|
||||||
bucketOffsets[hash]++;
|
|
||||||
bucketOffsets[hash] &= ((U32)1 << ldmParams.bucketSizeLog) - 1;
|
*(ZSTD_ldm_getBucket(ldmState, hash, ldmParams) + offset) = entry;
|
||||||
}
|
*pOffset = (BYTE)((offset + 1) & ((1u << ldmParams.bucketSizeLog) - 1));
|
||||||
|
|
||||||
/** ZSTD_ldm_makeEntryAndInsertByTag() :
|
|
||||||
*
|
|
||||||
* Gets the small hash, checksum, and tag from the rollingHash.
|
|
||||||
*
|
|
||||||
* If the tag matches (1 << ldmParams.hashRateLog)-1, then
|
|
||||||
* creates an ldmEntry from the offset, and inserts it into the hash table.
|
|
||||||
*
|
|
||||||
* hBits is the length of the small hash, which is the most significant hBits
|
|
||||||
* of rollingHash. The checksum is the next 32 most significant bits, followed
|
|
||||||
* by ldmParams.hashRateLog bits that make up the tag. */
|
|
||||||
static void ZSTD_ldm_makeEntryAndInsertByTag(ldmState_t* ldmState,
|
|
||||||
U64 const rollingHash,
|
|
||||||
U32 const hBits,
|
|
||||||
U32 const offset,
|
|
||||||
ldmParams_t const ldmParams)
|
|
||||||
{
|
|
||||||
U32 const tag = ZSTD_ldm_getTag(rollingHash, hBits, ldmParams.hashRateLog);
|
|
||||||
U32 const tagMask = ((U32)1 << ldmParams.hashRateLog) - 1;
|
|
||||||
if (tag == tagMask) {
|
|
||||||
U32 const hash = ZSTD_ldm_getSmallHash(rollingHash, hBits);
|
|
||||||
U32 const checksum = ZSTD_ldm_getChecksum(rollingHash, hBits);
|
|
||||||
ldmEntry_t entry;
|
|
||||||
entry.offset = offset;
|
|
||||||
entry.checksum = checksum;
|
|
||||||
ZSTD_ldm_insertEntry(ldmState, hash, entry, ldmParams);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/** ZSTD_ldm_countBackwardsMatch() :
|
/** ZSTD_ldm_countBackwardsMatch() :
|
||||||
@@ -149,10 +196,10 @@ static void ZSTD_ldm_makeEntryAndInsertByTag(ldmState_t* ldmState,
|
|||||||
* We count only bytes where pMatch >= pBase and pIn >= pAnchor. */
|
* We count only bytes where pMatch >= pBase and pIn >= pAnchor. */
|
||||||
static size_t ZSTD_ldm_countBackwardsMatch(
|
static size_t ZSTD_ldm_countBackwardsMatch(
|
||||||
const BYTE* pIn, const BYTE* pAnchor,
|
const BYTE* pIn, const BYTE* pAnchor,
|
||||||
const BYTE* pMatch, const BYTE* pBase)
|
const BYTE* pMatch, const BYTE* pMatchBase)
|
||||||
{
|
{
|
||||||
size_t matchLength = 0;
|
size_t matchLength = 0;
|
||||||
while (pIn > pAnchor && pMatch > pBase && pIn[-1] == pMatch[-1]) {
|
while (pIn > pAnchor && pMatch > pMatchBase && pIn[-1] == pMatch[-1]) {
|
||||||
pIn--;
|
pIn--;
|
||||||
pMatch--;
|
pMatch--;
|
||||||
matchLength++;
|
matchLength++;
|
||||||
@@ -160,6 +207,27 @@ static size_t ZSTD_ldm_countBackwardsMatch(
|
|||||||
return matchLength;
|
return matchLength;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/** ZSTD_ldm_countBackwardsMatch_2segments() :
|
||||||
|
* Returns the number of bytes that match backwards from pMatch,
|
||||||
|
* even with the backwards match spanning 2 different segments.
|
||||||
|
*
|
||||||
|
* On reaching `pMatchBase`, start counting from mEnd */
|
||||||
|
static size_t ZSTD_ldm_countBackwardsMatch_2segments(
|
||||||
|
const BYTE* pIn, const BYTE* pAnchor,
|
||||||
|
const BYTE* pMatch, const BYTE* pMatchBase,
|
||||||
|
const BYTE* pExtDictStart, const BYTE* pExtDictEnd)
|
||||||
|
{
|
||||||
|
size_t matchLength = ZSTD_ldm_countBackwardsMatch(pIn, pAnchor, pMatch, pMatchBase);
|
||||||
|
if (pMatch - matchLength != pMatchBase || pMatchBase == pExtDictStart) {
|
||||||
|
/* If backwards match is entirely in the extDict or prefix, immediately return */
|
||||||
|
return matchLength;
|
||||||
|
}
|
||||||
|
DEBUGLOG(7, "ZSTD_ldm_countBackwardsMatch_2segments: found 2-parts backwards match (length in prefix==%zu)", matchLength);
|
||||||
|
matchLength += ZSTD_ldm_countBackwardsMatch(pIn - matchLength, pAnchor, pExtDictEnd, pExtDictStart);
|
||||||
|
DEBUGLOG(7, "final backwards match length = %zu", matchLength);
|
||||||
|
return matchLength;
|
||||||
|
}
|
||||||
|
|
||||||
/** ZSTD_ldm_fillFastTables() :
|
/** ZSTD_ldm_fillFastTables() :
|
||||||
*
|
*
|
||||||
* Fills the relevant tables for the ZSTD_fast and ZSTD_dfast strategies.
|
* Fills the relevant tables for the ZSTD_fast and ZSTD_dfast strategies.
|
||||||
@@ -175,11 +243,11 @@ static size_t ZSTD_ldm_fillFastTables(ZSTD_matchState_t* ms,
|
|||||||
switch(ms->cParams.strategy)
|
switch(ms->cParams.strategy)
|
||||||
{
|
{
|
||||||
case ZSTD_fast:
|
case ZSTD_fast:
|
||||||
ZSTD_fillHashTable(ms, iend, ZSTD_dtlm_fast);
|
ZSTD_fillHashTable(ms, iend, ZSTD_dtlm_fast, ZSTD_tfp_forCCtx);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case ZSTD_dfast:
|
case ZSTD_dfast:
|
||||||
ZSTD_fillDoubleHashTable(ms, iend, ZSTD_dtlm_fast);
|
ZSTD_fillDoubleHashTable(ms, iend, ZSTD_dtlm_fast, ZSTD_tfp_forCCtx);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case ZSTD_greedy:
|
case ZSTD_greedy:
|
||||||
@@ -197,30 +265,43 @@ static size_t ZSTD_ldm_fillFastTables(ZSTD_matchState_t* ms,
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
/** ZSTD_ldm_fillLdmHashTable() :
|
void ZSTD_ldm_fillHashTable(
|
||||||
*
|
ldmState_t* ldmState, const BYTE* ip,
|
||||||
* Fills hashTable from (lastHashed + 1) to iend (non-inclusive).
|
const BYTE* iend, ldmParams_t const* params)
|
||||||
* lastHash is the rolling hash that corresponds to lastHashed.
|
|
||||||
*
|
|
||||||
* Returns the rolling hash corresponding to position iend-1. */
|
|
||||||
static U64 ZSTD_ldm_fillLdmHashTable(ldmState_t* state,
|
|
||||||
U64 lastHash, const BYTE* lastHashed,
|
|
||||||
const BYTE* iend, const BYTE* base,
|
|
||||||
U32 hBits, ldmParams_t const ldmParams)
|
|
||||||
{
|
{
|
||||||
U64 rollingHash = lastHash;
|
U32 const minMatchLength = params->minMatchLength;
|
||||||
const BYTE* cur = lastHashed + 1;
|
U32 const hBits = params->hashLog - params->bucketSizeLog;
|
||||||
|
BYTE const* const base = ldmState->window.base;
|
||||||
|
BYTE const* const istart = ip;
|
||||||
|
ldmRollingHashState_t hashState;
|
||||||
|
size_t* const splits = ldmState->splitIndices;
|
||||||
|
unsigned numSplits;
|
||||||
|
|
||||||
while (cur < iend) {
|
DEBUGLOG(5, "ZSTD_ldm_fillHashTable");
|
||||||
rollingHash = ZSTD_rollingHash_rotate(rollingHash, cur[-1],
|
|
||||||
cur[ldmParams.minMatchLength-1],
|
ZSTD_ldm_gear_init(&hashState, params);
|
||||||
state->hashPower);
|
while (ip < iend) {
|
||||||
ZSTD_ldm_makeEntryAndInsertByTag(state,
|
size_t hashed;
|
||||||
rollingHash, hBits,
|
unsigned n;
|
||||||
(U32)(cur - base), ldmParams);
|
|
||||||
++cur;
|
numSplits = 0;
|
||||||
|
hashed = ZSTD_ldm_gear_feed(&hashState, ip, iend - ip, splits, &numSplits);
|
||||||
|
|
||||||
|
for (n = 0; n < numSplits; n++) {
|
||||||
|
if (ip + splits[n] >= istart + minMatchLength) {
|
||||||
|
BYTE const* const split = ip + splits[n] - minMatchLength;
|
||||||
|
U64 const xxhash = XXH64(split, minMatchLength, 0);
|
||||||
|
U32 const hash = (U32)(xxhash & (((U32)1 << hBits) - 1));
|
||||||
|
ldmEntry_t entry;
|
||||||
|
|
||||||
|
entry.offset = (U32)(split - base);
|
||||||
|
entry.checksum = (U32)(xxhash >> 32);
|
||||||
|
ZSTD_ldm_insertEntry(ldmState, hash, entry, *params);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
ip += hashed;
|
||||||
}
|
}
|
||||||
return rollingHash;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -231,10 +312,10 @@ static U64 ZSTD_ldm_fillLdmHashTable(ldmState_t* state,
|
|||||||
* (after a long match, only update tables a limited amount). */
|
* (after a long match, only update tables a limited amount). */
|
||||||
static void ZSTD_ldm_limitTableUpdate(ZSTD_matchState_t* ms, const BYTE* anchor)
|
static void ZSTD_ldm_limitTableUpdate(ZSTD_matchState_t* ms, const BYTE* anchor)
|
||||||
{
|
{
|
||||||
U32 const current = (U32)(anchor - ms->window.base);
|
U32 const curr = (U32)(anchor - ms->window.base);
|
||||||
if (current > ms->nextToUpdate + 1024) {
|
if (curr > ms->nextToUpdate + 1024) {
|
||||||
ms->nextToUpdate =
|
ms->nextToUpdate =
|
||||||
current - MIN(512, current - ms->nextToUpdate - 1024);
|
curr - MIN(512, curr - ms->nextToUpdate - 1024);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -245,11 +326,8 @@ static size_t ZSTD_ldm_generateSequences_internal(
|
|||||||
/* LDM parameters */
|
/* LDM parameters */
|
||||||
int const extDict = ZSTD_window_hasExtDict(ldmState->window);
|
int const extDict = ZSTD_window_hasExtDict(ldmState->window);
|
||||||
U32 const minMatchLength = params->minMatchLength;
|
U32 const minMatchLength = params->minMatchLength;
|
||||||
U64 const hashPower = ldmState->hashPower;
|
U32 const entsPerBucket = 1U << params->bucketSizeLog;
|
||||||
U32 const hBits = params->hashLog - params->bucketSizeLog;
|
U32 const hBits = params->hashLog - params->bucketSizeLog;
|
||||||
U32 const ldmBucketSize = 1U << params->bucketSizeLog;
|
|
||||||
U32 const hashRateLog = params->hashRateLog;
|
|
||||||
U32 const ldmTagMask = (1U << params->hashRateLog) - 1;
|
|
||||||
/* Prefix and extDict parameters */
|
/* Prefix and extDict parameters */
|
||||||
U32 const dictLimit = ldmState->window.dictLimit;
|
U32 const dictLimit = ldmState->window.dictLimit;
|
||||||
U32 const lowestIndex = extDict ? ldmState->window.lowLimit : dictLimit;
|
U32 const lowestIndex = extDict ? ldmState->window.lowLimit : dictLimit;
|
||||||
@@ -261,45 +339,69 @@ static size_t ZSTD_ldm_generateSequences_internal(
|
|||||||
/* Input bounds */
|
/* Input bounds */
|
||||||
BYTE const* const istart = (BYTE const*)src;
|
BYTE const* const istart = (BYTE const*)src;
|
||||||
BYTE const* const iend = istart + srcSize;
|
BYTE const* const iend = istart + srcSize;
|
||||||
BYTE const* const ilimit = iend - MAX(minMatchLength, HASH_READ_SIZE);
|
BYTE const* const ilimit = iend - HASH_READ_SIZE;
|
||||||
/* Input positions */
|
/* Input positions */
|
||||||
BYTE const* anchor = istart;
|
BYTE const* anchor = istart;
|
||||||
BYTE const* ip = istart;
|
BYTE const* ip = istart;
|
||||||
/* Rolling hash */
|
/* Rolling hash state */
|
||||||
BYTE const* lastHashed = NULL;
|
ldmRollingHashState_t hashState;
|
||||||
U64 rollingHash = 0;
|
/* Arrays for staged-processing */
|
||||||
|
size_t* const splits = ldmState->splitIndices;
|
||||||
|
ldmMatchCandidate_t* const candidates = ldmState->matchCandidates;
|
||||||
|
unsigned numSplits;
|
||||||
|
|
||||||
while (ip <= ilimit) {
|
if (srcSize < minMatchLength)
|
||||||
size_t mLength;
|
return iend - anchor;
|
||||||
U32 const current = (U32)(ip - base);
|
|
||||||
size_t forwardMatchLength = 0, backwardMatchLength = 0;
|
/* Initialize the rolling hash state with the first minMatchLength bytes */
|
||||||
ldmEntry_t* bestEntry = NULL;
|
ZSTD_ldm_gear_init(&hashState, params);
|
||||||
if (ip != istart) {
|
ZSTD_ldm_gear_reset(&hashState, ip, minMatchLength);
|
||||||
rollingHash = ZSTD_rollingHash_rotate(rollingHash, lastHashed[0],
|
ip += minMatchLength;
|
||||||
lastHashed[minMatchLength],
|
|
||||||
hashPower);
|
while (ip < ilimit) {
|
||||||
} else {
|
size_t hashed;
|
||||||
rollingHash = ZSTD_rollingHash_compute(ip, minMatchLength);
|
unsigned n;
|
||||||
|
|
||||||
|
numSplits = 0;
|
||||||
|
hashed = ZSTD_ldm_gear_feed(&hashState, ip, ilimit - ip,
|
||||||
|
splits, &numSplits);
|
||||||
|
|
||||||
|
for (n = 0; n < numSplits; n++) {
|
||||||
|
BYTE const* const split = ip + splits[n] - minMatchLength;
|
||||||
|
U64 const xxhash = XXH64(split, minMatchLength, 0);
|
||||||
|
U32 const hash = (U32)(xxhash & (((U32)1 << hBits) - 1));
|
||||||
|
|
||||||
|
candidates[n].split = split;
|
||||||
|
candidates[n].hash = hash;
|
||||||
|
candidates[n].checksum = (U32)(xxhash >> 32);
|
||||||
|
candidates[n].bucket = ZSTD_ldm_getBucket(ldmState, hash, *params);
|
||||||
|
PREFETCH_L1(candidates[n].bucket);
|
||||||
}
|
}
|
||||||
lastHashed = ip;
|
|
||||||
|
|
||||||
/* Do not insert and do not look for a match */
|
for (n = 0; n < numSplits; n++) {
|
||||||
if (ZSTD_ldm_getTag(rollingHash, hBits, hashRateLog) != ldmTagMask) {
|
size_t forwardMatchLength = 0, backwardMatchLength = 0,
|
||||||
ip++;
|
bestMatchLength = 0, mLength;
|
||||||
|
U32 offset;
|
||||||
|
BYTE const* const split = candidates[n].split;
|
||||||
|
U32 const checksum = candidates[n].checksum;
|
||||||
|
U32 const hash = candidates[n].hash;
|
||||||
|
ldmEntry_t* const bucket = candidates[n].bucket;
|
||||||
|
ldmEntry_t const* cur;
|
||||||
|
ldmEntry_t const* bestEntry = NULL;
|
||||||
|
ldmEntry_t newEntry;
|
||||||
|
|
||||||
|
newEntry.offset = (U32)(split - base);
|
||||||
|
newEntry.checksum = checksum;
|
||||||
|
|
||||||
|
/* If a split point would generate a sequence overlapping with
|
||||||
|
* the previous one, we merely register it in the hash table and
|
||||||
|
* move on */
|
||||||
|
if (split < anchor) {
|
||||||
|
ZSTD_ldm_insertEntry(ldmState, hash, newEntry, *params);
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Get the best entry and compute the match lengths */
|
for (cur = bucket; cur < bucket + entsPerBucket; cur++) {
|
||||||
{
|
|
||||||
ldmEntry_t* const bucket =
|
|
||||||
ZSTD_ldm_getBucket(ldmState,
|
|
||||||
ZSTD_ldm_getSmallHash(rollingHash, hBits),
|
|
||||||
*params);
|
|
||||||
ldmEntry_t* cur;
|
|
||||||
size_t bestMatchLength = 0;
|
|
||||||
U32 const checksum = ZSTD_ldm_getChecksum(rollingHash, hBits);
|
|
||||||
|
|
||||||
for (cur = bucket; cur < bucket + ldmBucketSize; ++cur) {
|
|
||||||
size_t curForwardMatchLength, curBackwardMatchLength,
|
size_t curForwardMatchLength, curBackwardMatchLength,
|
||||||
curTotalMatchLength;
|
curTotalMatchLength;
|
||||||
if (cur->checksum != checksum || cur->offset <= lowestIndex) {
|
if (cur->checksum != checksum || cur->offset <= lowestIndex) {
|
||||||
@@ -313,30 +415,23 @@ static size_t ZSTD_ldm_generateSequences_internal(
|
|||||||
cur->offset < dictLimit ? dictEnd : iend;
|
cur->offset < dictLimit ? dictEnd : iend;
|
||||||
BYTE const* const lowMatchPtr =
|
BYTE const* const lowMatchPtr =
|
||||||
cur->offset < dictLimit ? dictStart : lowPrefixPtr;
|
cur->offset < dictLimit ? dictStart : lowPrefixPtr;
|
||||||
|
curForwardMatchLength =
|
||||||
curForwardMatchLength = ZSTD_count_2segments(
|
ZSTD_count_2segments(split, pMatch, iend, matchEnd, lowPrefixPtr);
|
||||||
ip, pMatch, iend,
|
|
||||||
matchEnd, lowPrefixPtr);
|
|
||||||
if (curForwardMatchLength < minMatchLength) {
|
if (curForwardMatchLength < minMatchLength) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
curBackwardMatchLength =
|
curBackwardMatchLength = ZSTD_ldm_countBackwardsMatch_2segments(
|
||||||
ZSTD_ldm_countBackwardsMatch(ip, anchor, pMatch,
|
split, anchor, pMatch, lowMatchPtr, dictStart, dictEnd);
|
||||||
lowMatchPtr);
|
|
||||||
curTotalMatchLength = curForwardMatchLength +
|
|
||||||
curBackwardMatchLength;
|
|
||||||
} else { /* !extDict */
|
} else { /* !extDict */
|
||||||
BYTE const* const pMatch = base + cur->offset;
|
BYTE const* const pMatch = base + cur->offset;
|
||||||
curForwardMatchLength = ZSTD_count(ip, pMatch, iend);
|
curForwardMatchLength = ZSTD_count(split, pMatch, iend);
|
||||||
if (curForwardMatchLength < minMatchLength) {
|
if (curForwardMatchLength < minMatchLength) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
curBackwardMatchLength =
|
curBackwardMatchLength =
|
||||||
ZSTD_ldm_countBackwardsMatch(ip, anchor, pMatch,
|
ZSTD_ldm_countBackwardsMatch(split, anchor, pMatch, lowPrefixPtr);
|
||||||
lowPrefixPtr);
|
|
||||||
curTotalMatchLength = curForwardMatchLength +
|
|
||||||
curBackwardMatchLength;
|
|
||||||
}
|
}
|
||||||
|
curTotalMatchLength = curForwardMatchLength + curBackwardMatchLength;
|
||||||
|
|
||||||
if (curTotalMatchLength > bestMatchLength) {
|
if (curTotalMatchLength > bestMatchLength) {
|
||||||
bestMatchLength = curTotalMatchLength;
|
bestMatchLength = curTotalMatchLength;
|
||||||
@@ -345,57 +440,54 @@ static size_t ZSTD_ldm_generateSequences_internal(
|
|||||||
bestEntry = cur;
|
bestEntry = cur;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
/* No match found -- continue searching */
|
/* No match found -- insert an entry into the hash table
|
||||||
|
* and process the next candidate match */
|
||||||
if (bestEntry == NULL) {
|
if (bestEntry == NULL) {
|
||||||
ZSTD_ldm_makeEntryAndInsertByTag(ldmState, rollingHash,
|
ZSTD_ldm_insertEntry(ldmState, hash, newEntry, *params);
|
||||||
hBits, current,
|
|
||||||
*params);
|
|
||||||
ip++;
|
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Match found */
|
/* Match found */
|
||||||
|
offset = (U32)(split - base) - bestEntry->offset;
|
||||||
mLength = forwardMatchLength + backwardMatchLength;
|
mLength = forwardMatchLength + backwardMatchLength;
|
||||||
ip -= backwardMatchLength;
|
|
||||||
|
|
||||||
{
|
{
|
||||||
/* Store the sequence:
|
|
||||||
* ip = current - backwardMatchLength
|
|
||||||
* The match is at (bestEntry->offset - backwardMatchLength)
|
|
||||||
*/
|
|
||||||
U32 const matchIndex = bestEntry->offset;
|
|
||||||
U32 const offset = current - matchIndex;
|
|
||||||
rawSeq* const seq = rawSeqStore->seq + rawSeqStore->size;
|
rawSeq* const seq = rawSeqStore->seq + rawSeqStore->size;
|
||||||
|
|
||||||
/* Out of sequence storage */
|
/* Out of sequence storage */
|
||||||
if (rawSeqStore->size == rawSeqStore->capacity)
|
if (rawSeqStore->size == rawSeqStore->capacity)
|
||||||
return ERROR(dstSize_tooSmall);
|
return ERROR(dstSize_tooSmall);
|
||||||
seq->litLength = (U32)(ip - anchor);
|
seq->litLength = (U32)(split - backwardMatchLength - anchor);
|
||||||
seq->matchLength = (U32)mLength;
|
seq->matchLength = (U32)mLength;
|
||||||
seq->offset = offset;
|
seq->offset = offset;
|
||||||
rawSeqStore->size++;
|
rawSeqStore->size++;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Insert the current entry into the hash table */
|
/* Insert the current entry into the hash table --- it must be
|
||||||
ZSTD_ldm_makeEntryAndInsertByTag(ldmState, rollingHash, hBits,
|
* done after the previous block to avoid clobbering bestEntry */
|
||||||
(U32)(lastHashed - base),
|
ZSTD_ldm_insertEntry(ldmState, hash, newEntry, *params);
|
||||||
*params);
|
|
||||||
|
|
||||||
assert(ip + backwardMatchLength == lastHashed);
|
anchor = split + forwardMatchLength;
|
||||||
|
|
||||||
/* Fill the hash table from lastHashed+1 to ip+mLength*/
|
/* If we find a match that ends after the data that we've hashed
|
||||||
/* Heuristic: don't need to fill the entire table at end of block */
|
* then we have a repeating, overlapping, pattern. E.g. all zeros.
|
||||||
if (ip + mLength <= ilimit) {
|
* If one repetition of the pattern matches our `stopMask` then all
|
||||||
rollingHash = ZSTD_ldm_fillLdmHashTable(
|
* repetitions will. We don't need to insert them all into out table,
|
||||||
ldmState, rollingHash, lastHashed,
|
* only the first one. So skip over overlapping matches.
|
||||||
ip + mLength, base, hBits, *params);
|
* This is a major speed boost (20x) for compressing a single byte
|
||||||
lastHashed = ip + mLength - 1;
|
* repeated, when that byte ends up in the table.
|
||||||
|
*/
|
||||||
|
if (anchor > ip + hashed) {
|
||||||
|
ZSTD_ldm_gear_reset(&hashState, anchor - minMatchLength, minMatchLength);
|
||||||
|
/* Continue the outer loop at anchor (ip + hashed == anchor). */
|
||||||
|
ip = anchor - hashed;
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
ip += mLength;
|
|
||||||
anchor = ip;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
ip += hashed;
|
||||||
|
}
|
||||||
|
|
||||||
return iend - anchor;
|
return iend - anchor;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -444,11 +536,13 @@ size_t ZSTD_ldm_generateSequences(
|
|||||||
|
|
||||||
assert(chunkStart < iend);
|
assert(chunkStart < iend);
|
||||||
/* 1. Perform overflow correction if necessary. */
|
/* 1. Perform overflow correction if necessary. */
|
||||||
if (ZSTD_window_needOverflowCorrection(ldmState->window, chunkEnd)) {
|
if (ZSTD_window_needOverflowCorrection(ldmState->window, 0, maxDist, ldmState->loadedDictEnd, chunkStart, chunkEnd)) {
|
||||||
U32 const ldmHSize = 1U << params->hashLog;
|
U32 const ldmHSize = 1U << params->hashLog;
|
||||||
U32 const correction = ZSTD_window_correctOverflow(
|
U32 const correction = ZSTD_window_correctOverflow(
|
||||||
&ldmState->window, /* cycleLog */ 0, maxDist, chunkStart);
|
&ldmState->window, /* cycleLog */ 0, maxDist, chunkStart);
|
||||||
ZSTD_ldm_reduceTable(ldmState->hashTable, ldmHSize, correction);
|
ZSTD_ldm_reduceTable(ldmState->hashTable, ldmHSize, correction);
|
||||||
|
/* invalidate dictionaries on overflow correction */
|
||||||
|
ldmState->loadedDictEnd = 0;
|
||||||
}
|
}
|
||||||
/* 2. We enforce the maximum offset allowed.
|
/* 2. We enforce the maximum offset allowed.
|
||||||
*
|
*
|
||||||
@@ -456,9 +550,15 @@ size_t ZSTD_ldm_generateSequences(
|
|||||||
* the window through early invalidation.
|
* the window through early invalidation.
|
||||||
* TODO: * Test the chunk size.
|
* TODO: * Test the chunk size.
|
||||||
* * Try invalidation after the sequence generation and test the
|
* * Try invalidation after the sequence generation and test the
|
||||||
* the offset against maxDist directly.
|
* offset against maxDist directly.
|
||||||
|
*
|
||||||
|
* NOTE: Because of dictionaries + sequence splitting we MUST make sure
|
||||||
|
* that any offset used is valid at the END of the sequence, since it may
|
||||||
|
* be split into two sequences. This condition holds when using
|
||||||
|
* ZSTD_window_enforceMaxDist(), but if we move to checking offsets
|
||||||
|
* against maxDist directly, we'll have to carefully handle that case.
|
||||||
*/
|
*/
|
||||||
ZSTD_window_enforceMaxDist(&ldmState->window, chunkEnd, maxDist, NULL, NULL);
|
ZSTD_window_enforceMaxDist(&ldmState->window, chunkEnd, maxDist, &ldmState->loadedDictEnd, NULL);
|
||||||
/* 3. Generate the sequences for the chunk, and get newLeftoverSize. */
|
/* 3. Generate the sequences for the chunk, and get newLeftoverSize. */
|
||||||
newLeftoverSize = ZSTD_ldm_generateSequences_internal(
|
newLeftoverSize = ZSTD_ldm_generateSequences_internal(
|
||||||
ldmState, sequences, params, chunkStart, chunkSize);
|
ldmState, sequences, params, chunkStart, chunkSize);
|
||||||
@@ -480,7 +580,9 @@ size_t ZSTD_ldm_generateSequences(
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
void ZSTD_ldm_skipSequences(rawSeqStore_t* rawSeqStore, size_t srcSize, U32 const minMatch) {
|
void
|
||||||
|
ZSTD_ldm_skipSequences(rawSeqStore_t* rawSeqStore, size_t srcSize, U32 const minMatch)
|
||||||
|
{
|
||||||
while (srcSize > 0 && rawSeqStore->pos < rawSeqStore->size) {
|
while (srcSize > 0 && rawSeqStore->pos < rawSeqStore->size) {
|
||||||
rawSeq* seq = rawSeqStore->seq + rawSeqStore->pos;
|
rawSeq* seq = rawSeqStore->seq + rawSeqStore->pos;
|
||||||
if (srcSize <= seq->litLength) {
|
if (srcSize <= seq->litLength) {
|
||||||
@@ -539,14 +641,32 @@ static rawSeq maybeSplitSequence(rawSeqStore_t* rawSeqStore,
|
|||||||
return sequence;
|
return sequence;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void ZSTD_ldm_skipRawSeqStoreBytes(rawSeqStore_t* rawSeqStore, size_t nbBytes) {
|
||||||
|
U32 currPos = (U32)(rawSeqStore->posInSequence + nbBytes);
|
||||||
|
while (currPos && rawSeqStore->pos < rawSeqStore->size) {
|
||||||
|
rawSeq currSeq = rawSeqStore->seq[rawSeqStore->pos];
|
||||||
|
if (currPos >= currSeq.litLength + currSeq.matchLength) {
|
||||||
|
currPos -= currSeq.litLength + currSeq.matchLength;
|
||||||
|
rawSeqStore->pos++;
|
||||||
|
} else {
|
||||||
|
rawSeqStore->posInSequence = currPos;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (currPos == 0 || rawSeqStore->pos == rawSeqStore->size) {
|
||||||
|
rawSeqStore->posInSequence = 0;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
size_t ZSTD_ldm_blockCompress(rawSeqStore_t* rawSeqStore,
|
size_t ZSTD_ldm_blockCompress(rawSeqStore_t* rawSeqStore,
|
||||||
ZSTD_matchState_t* ms, seqStore_t* seqStore, U32 rep[ZSTD_REP_NUM],
|
ZSTD_matchState_t* ms, seqStore_t* seqStore, U32 rep[ZSTD_REP_NUM],
|
||||||
|
ZSTD_paramSwitch_e useRowMatchFinder,
|
||||||
void const* src, size_t srcSize)
|
void const* src, size_t srcSize)
|
||||||
{
|
{
|
||||||
const ZSTD_compressionParameters* const cParams = &ms->cParams;
|
const ZSTD_compressionParameters* const cParams = &ms->cParams;
|
||||||
unsigned const minMatch = cParams->minMatch;
|
unsigned const minMatch = cParams->minMatch;
|
||||||
ZSTD_blockCompressor const blockCompressor =
|
ZSTD_blockCompressor const blockCompressor =
|
||||||
ZSTD_selectBlockCompressor(cParams->strategy, ZSTD_matchState_dictMode(ms));
|
ZSTD_selectBlockCompressor(cParams->strategy, useRowMatchFinder, ZSTD_matchState_dictMode(ms));
|
||||||
/* Input bounds */
|
/* Input bounds */
|
||||||
BYTE const* const istart = (BYTE const*)src;
|
BYTE const* const istart = (BYTE const*)src;
|
||||||
BYTE const* const iend = istart + srcSize;
|
BYTE const* const iend = istart + srcSize;
|
||||||
@@ -554,9 +674,18 @@ size_t ZSTD_ldm_blockCompress(rawSeqStore_t* rawSeqStore,
|
|||||||
BYTE const* ip = istart;
|
BYTE const* ip = istart;
|
||||||
|
|
||||||
DEBUGLOG(5, "ZSTD_ldm_blockCompress: srcSize=%zu", srcSize);
|
DEBUGLOG(5, "ZSTD_ldm_blockCompress: srcSize=%zu", srcSize);
|
||||||
|
/* If using opt parser, use LDMs only as candidates rather than always accepting them */
|
||||||
|
if (cParams->strategy >= ZSTD_btopt) {
|
||||||
|
size_t lastLLSize;
|
||||||
|
ms->ldmSeqStore = rawSeqStore;
|
||||||
|
lastLLSize = blockCompressor(ms, seqStore, rep, src, srcSize);
|
||||||
|
ZSTD_ldm_skipRawSeqStoreBytes(rawSeqStore, srcSize);
|
||||||
|
return lastLLSize;
|
||||||
|
}
|
||||||
|
|
||||||
assert(rawSeqStore->pos <= rawSeqStore->size);
|
assert(rawSeqStore->pos <= rawSeqStore->size);
|
||||||
assert(rawSeqStore->size <= rawSeqStore->capacity);
|
assert(rawSeqStore->size <= rawSeqStore->capacity);
|
||||||
/* Loop through each sequence and apply the block compressor to the lits */
|
/* Loop through each sequence and apply the block compressor to the literals */
|
||||||
while (rawSeqStore->pos < rawSeqStore->size && ip < iend) {
|
while (rawSeqStore->pos < rawSeqStore->size && ip < iend) {
|
||||||
/* maybeSplitSequence updates rawSeqStore->pos */
|
/* maybeSplitSequence updates rawSeqStore->pos */
|
||||||
rawSeq const sequence = maybeSplitSequence(rawSeqStore,
|
rawSeq const sequence = maybeSplitSequence(rawSeqStore,
|
||||||
@@ -566,14 +695,13 @@ size_t ZSTD_ldm_blockCompress(rawSeqStore_t* rawSeqStore,
|
|||||||
if (sequence.offset == 0)
|
if (sequence.offset == 0)
|
||||||
break;
|
break;
|
||||||
|
|
||||||
assert(sequence.offset <= (1U << cParams->windowLog));
|
|
||||||
assert(ip + sequence.litLength + sequence.matchLength <= iend);
|
assert(ip + sequence.litLength + sequence.matchLength <= iend);
|
||||||
|
|
||||||
/* Fill tables for block compressor */
|
/* Fill tables for block compressor */
|
||||||
ZSTD_ldm_limitTableUpdate(ms, ip);
|
ZSTD_ldm_limitTableUpdate(ms, ip);
|
||||||
ZSTD_ldm_fillFastTables(ms, ip);
|
ZSTD_ldm_fillFastTables(ms, ip);
|
||||||
/* Run the block compressor */
|
/* Run the block compressor */
|
||||||
DEBUGLOG(5, "calling block compressor on segment of size %u", sequence.litLength);
|
DEBUGLOG(5, "pos %u : calling block compressor on segment of size %u", (unsigned)(ip-istart), sequence.litLength);
|
||||||
{
|
{
|
||||||
size_t const newLitLength =
|
size_t const newLitLength =
|
||||||
blockCompressor(ms, seqStore, rep, ip, sequence.litLength);
|
blockCompressor(ms, seqStore, rep, ip, sequence.litLength);
|
||||||
@@ -584,8 +712,8 @@ size_t ZSTD_ldm_blockCompress(rawSeqStore_t* rawSeqStore,
|
|||||||
rep[0] = sequence.offset;
|
rep[0] = sequence.offset;
|
||||||
/* Store the sequence */
|
/* Store the sequence */
|
||||||
ZSTD_storeSeq(seqStore, newLitLength, ip - newLitLength, iend,
|
ZSTD_storeSeq(seqStore, newLitLength, ip - newLitLength, iend,
|
||||||
sequence.offset + ZSTD_REP_MOVE,
|
OFFSET_TO_OFFBASE(sequence.offset),
|
||||||
sequence.matchLength - MINMATCH);
|
sequence.matchLength);
|
||||||
ip += sequence.matchLength;
|
ip += sequence.matchLength;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -595,3 +723,5 @@ size_t ZSTD_ldm_blockCompress(rawSeqStore_t* rawSeqStore,
|
|||||||
/* Compress the last literals */
|
/* Compress the last literals */
|
||||||
return blockCompressor(ms, seqStore, rep, ip, iend - ip);
|
return blockCompressor(ms, seqStore, rep, ip, iend - ip);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#endif /* USE_EXTERNAL_ZSTD */
|
||||||
|
|||||||
19
vendor/github.com/DataDog/zstd/zstd_ldm.h
generated
vendored
19
vendor/github.com/DataDog/zstd/zstd_ldm.h
generated
vendored
@@ -1,10 +1,12 @@
|
|||||||
|
#ifndef USE_EXTERNAL_ZSTD
|
||||||
/*
|
/*
|
||||||
* Copyright (c) 2016-present, Yann Collet, Facebook, Inc.
|
* Copyright (c) Meta Platforms, Inc. and affiliates.
|
||||||
* All rights reserved.
|
* All rights reserved.
|
||||||
*
|
*
|
||||||
* This source code is licensed under both the BSD-style license (found in the
|
* This source code is licensed under both the BSD-style license (found in the
|
||||||
* LICENSE file in the root directory of this source tree) and the GPLv2 (found
|
* LICENSE file in the root directory of this source tree) and the GPLv2 (found
|
||||||
* in the COPYING file in the root directory of this source tree).
|
* in the COPYING file in the root directory of this source tree).
|
||||||
|
* You may select, at your option, one of the above-listed licenses.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#ifndef ZSTD_LDM_H
|
#ifndef ZSTD_LDM_H
|
||||||
@@ -23,6 +25,10 @@ extern "C" {
|
|||||||
|
|
||||||
#define ZSTD_LDM_DEFAULT_WINDOW_LOG ZSTD_WINDOWLOG_LIMIT_DEFAULT
|
#define ZSTD_LDM_DEFAULT_WINDOW_LOG ZSTD_WINDOWLOG_LIMIT_DEFAULT
|
||||||
|
|
||||||
|
void ZSTD_ldm_fillHashTable(
|
||||||
|
ldmState_t* state, const BYTE* ip,
|
||||||
|
const BYTE* iend, ldmParams_t const* params);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* ZSTD_ldm_generateSequences():
|
* ZSTD_ldm_generateSequences():
|
||||||
*
|
*
|
||||||
@@ -61,6 +67,7 @@ size_t ZSTD_ldm_generateSequences(
|
|||||||
*/
|
*/
|
||||||
size_t ZSTD_ldm_blockCompress(rawSeqStore_t* rawSeqStore,
|
size_t ZSTD_ldm_blockCompress(rawSeqStore_t* rawSeqStore,
|
||||||
ZSTD_matchState_t* ms, seqStore_t* seqStore, U32 rep[ZSTD_REP_NUM],
|
ZSTD_matchState_t* ms, seqStore_t* seqStore, U32 rep[ZSTD_REP_NUM],
|
||||||
|
ZSTD_paramSwitch_e useRowMatchFinder,
|
||||||
void const* src, size_t srcSize);
|
void const* src, size_t srcSize);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -68,11 +75,17 @@ size_t ZSTD_ldm_blockCompress(rawSeqStore_t* rawSeqStore,
|
|||||||
*
|
*
|
||||||
* Skip past `srcSize` bytes worth of sequences in `rawSeqStore`.
|
* Skip past `srcSize` bytes worth of sequences in `rawSeqStore`.
|
||||||
* Avoids emitting matches less than `minMatch` bytes.
|
* Avoids emitting matches less than `minMatch` bytes.
|
||||||
* Must be called for data with is not passed to ZSTD_ldm_blockCompress().
|
* Must be called for data that is not passed to ZSTD_ldm_blockCompress().
|
||||||
*/
|
*/
|
||||||
void ZSTD_ldm_skipSequences(rawSeqStore_t* rawSeqStore, size_t srcSize,
|
void ZSTD_ldm_skipSequences(rawSeqStore_t* rawSeqStore, size_t srcSize,
|
||||||
U32 const minMatch);
|
U32 const minMatch);
|
||||||
|
|
||||||
|
/* ZSTD_ldm_skipRawSeqStoreBytes():
|
||||||
|
* Moves forward in rawSeqStore by nbBytes, updating fields 'pos' and 'posInSequence'.
|
||||||
|
* Not to be used in conjunction with ZSTD_ldm_skipSequences().
|
||||||
|
* Must be called for data with is not passed to ZSTD_ldm_blockCompress().
|
||||||
|
*/
|
||||||
|
void ZSTD_ldm_skipRawSeqStoreBytes(rawSeqStore_t* rawSeqStore, size_t nbBytes);
|
||||||
|
|
||||||
/** ZSTD_ldm_getTableSize() :
|
/** ZSTD_ldm_getTableSize() :
|
||||||
* Estimate the space needed for long distance matching tables or 0 if LDM is
|
* Estimate the space needed for long distance matching tables or 0 if LDM is
|
||||||
@@ -103,3 +116,5 @@ void ZSTD_ldm_adjustParameters(ldmParams_t* params,
|
|||||||
#endif
|
#endif
|
||||||
|
|
||||||
#endif /* ZSTD_FAST_H */
|
#endif /* ZSTD_FAST_H */
|
||||||
|
|
||||||
|
#endif /* USE_EXTERNAL_ZSTD */
|
||||||
|
|||||||
109
vendor/github.com/DataDog/zstd/zstd_ldm_geartab.h
generated
vendored
Normal file
109
vendor/github.com/DataDog/zstd/zstd_ldm_geartab.h
generated
vendored
Normal file
@@ -0,0 +1,109 @@
|
|||||||
|
#ifndef USE_EXTERNAL_ZSTD
|
||||||
|
/*
|
||||||
|
* Copyright (c) Meta Platforms, Inc. and affiliates.
|
||||||
|
* All rights reserved.
|
||||||
|
*
|
||||||
|
* This source code is licensed under both the BSD-style license (found in the
|
||||||
|
* LICENSE file in the root directory of this source tree) and the GPLv2 (found
|
||||||
|
* in the COPYING file in the root directory of this source tree).
|
||||||
|
* You may select, at your option, one of the above-listed licenses.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#ifndef ZSTD_LDM_GEARTAB_H
|
||||||
|
#define ZSTD_LDM_GEARTAB_H
|
||||||
|
|
||||||
|
#include "compiler.h" /* UNUSED_ATTR */
|
||||||
|
#include "mem.h" /* U64 */
|
||||||
|
|
||||||
|
static UNUSED_ATTR const U64 ZSTD_ldm_gearTab[256] = {
|
||||||
|
0xf5b8f72c5f77775c, 0x84935f266b7ac412, 0xb647ada9ca730ccc,
|
||||||
|
0xb065bb4b114fb1de, 0x34584e7e8c3a9fd0, 0x4e97e17c6ae26b05,
|
||||||
|
0x3a03d743bc99a604, 0xcecd042422c4044f, 0x76de76c58524259e,
|
||||||
|
0x9c8528f65badeaca, 0x86563706e2097529, 0x2902475fa375d889,
|
||||||
|
0xafb32a9739a5ebe6, 0xce2714da3883e639, 0x21eaf821722e69e,
|
||||||
|
0x37b628620b628, 0x49a8d455d88caf5, 0x8556d711e6958140,
|
||||||
|
0x4f7ae74fc605c1f, 0x829f0c3468bd3a20, 0x4ffdc885c625179e,
|
||||||
|
0x8473de048a3daf1b, 0x51008822b05646b2, 0x69d75d12b2d1cc5f,
|
||||||
|
0x8c9d4a19159154bc, 0xc3cc10f4abbd4003, 0xd06ddc1cecb97391,
|
||||||
|
0xbe48e6e7ed80302e, 0x3481db31cee03547, 0xacc3f67cdaa1d210,
|
||||||
|
0x65cb771d8c7f96cc, 0x8eb27177055723dd, 0xc789950d44cd94be,
|
||||||
|
0x934feadc3700b12b, 0x5e485f11edbdf182, 0x1e2e2a46fd64767a,
|
||||||
|
0x2969ca71d82efa7c, 0x9d46e9935ebbba2e, 0xe056b67e05e6822b,
|
||||||
|
0x94d73f55739d03a0, 0xcd7010bdb69b5a03, 0x455ef9fcd79b82f4,
|
||||||
|
0x869cb54a8749c161, 0x38d1a4fa6185d225, 0xb475166f94bbe9bb,
|
||||||
|
0xa4143548720959f1, 0x7aed4780ba6b26ba, 0xd0ce264439e02312,
|
||||||
|
0x84366d746078d508, 0xa8ce973c72ed17be, 0x21c323a29a430b01,
|
||||||
|
0x9962d617e3af80ee, 0xab0ce91d9c8cf75b, 0x530e8ee6d19a4dbc,
|
||||||
|
0x2ef68c0cf53f5d72, 0xc03a681640a85506, 0x496e4e9f9c310967,
|
||||||
|
0x78580472b59b14a0, 0x273824c23b388577, 0x66bf923ad45cb553,
|
||||||
|
0x47ae1a5a2492ba86, 0x35e304569e229659, 0x4765182a46870b6f,
|
||||||
|
0x6cbab625e9099412, 0xddac9a2e598522c1, 0x7172086e666624f2,
|
||||||
|
0xdf5003ca503b7837, 0x88c0c1db78563d09, 0x58d51865acfc289d,
|
||||||
|
0x177671aec65224f1, 0xfb79d8a241e967d7, 0x2be1e101cad9a49a,
|
||||||
|
0x6625682f6e29186b, 0x399553457ac06e50, 0x35dffb4c23abb74,
|
||||||
|
0x429db2591f54aade, 0xc52802a8037d1009, 0x6acb27381f0b25f3,
|
||||||
|
0xf45e2551ee4f823b, 0x8b0ea2d99580c2f7, 0x3bed519cbcb4e1e1,
|
||||||
|
0xff452823dbb010a, 0x9d42ed614f3dd267, 0x5b9313c06257c57b,
|
||||||
|
0xa114b8008b5e1442, 0xc1fe311c11c13d4b, 0x66e8763ea34c5568,
|
||||||
|
0x8b982af1c262f05d, 0xee8876faaa75fbb7, 0x8a62a4d0d172bb2a,
|
||||||
|
0xc13d94a3b7449a97, 0x6dbbba9dc15d037c, 0xc786101f1d92e0f1,
|
||||||
|
0xd78681a907a0b79b, 0xf61aaf2962c9abb9, 0x2cfd16fcd3cb7ad9,
|
||||||
|
0x868c5b6744624d21, 0x25e650899c74ddd7, 0xba042af4a7c37463,
|
||||||
|
0x4eb1a539465a3eca, 0xbe09dbf03b05d5ca, 0x774e5a362b5472ba,
|
||||||
|
0x47a1221229d183cd, 0x504b0ca18ef5a2df, 0xdffbdfbde2456eb9,
|
||||||
|
0x46cd2b2fbee34634, 0xf2aef8fe819d98c3, 0x357f5276d4599d61,
|
||||||
|
0x24a5483879c453e3, 0x88026889192b4b9, 0x28da96671782dbec,
|
||||||
|
0x4ef37c40588e9aaa, 0x8837b90651bc9fb3, 0xc164f741d3f0e5d6,
|
||||||
|
0xbc135a0a704b70ba, 0x69cd868f7622ada, 0xbc37ba89e0b9c0ab,
|
||||||
|
0x47c14a01323552f6, 0x4f00794bacee98bb, 0x7107de7d637a69d5,
|
||||||
|
0x88af793bb6f2255e, 0xf3c6466b8799b598, 0xc288c616aa7f3b59,
|
||||||
|
0x81ca63cf42fca3fd, 0x88d85ace36a2674b, 0xd056bd3792389e7,
|
||||||
|
0xe55c396c4e9dd32d, 0xbefb504571e6c0a6, 0x96ab32115e91e8cc,
|
||||||
|
0xbf8acb18de8f38d1, 0x66dae58801672606, 0x833b6017872317fb,
|
||||||
|
0xb87c16f2d1c92864, 0xdb766a74e58b669c, 0x89659f85c61417be,
|
||||||
|
0xc8daad856011ea0c, 0x76a4b565b6fe7eae, 0xa469d085f6237312,
|
||||||
|
0xaaf0365683a3e96c, 0x4dbb746f8424f7b8, 0x638755af4e4acc1,
|
||||||
|
0x3d7807f5bde64486, 0x17be6d8f5bbb7639, 0x903f0cd44dc35dc,
|
||||||
|
0x67b672eafdf1196c, 0xa676ff93ed4c82f1, 0x521d1004c5053d9d,
|
||||||
|
0x37ba9ad09ccc9202, 0x84e54d297aacfb51, 0xa0b4b776a143445,
|
||||||
|
0x820d471e20b348e, 0x1874383cb83d46dc, 0x97edeec7a1efe11c,
|
||||||
|
0xb330e50b1bdc42aa, 0x1dd91955ce70e032, 0xa514cdb88f2939d5,
|
||||||
|
0x2791233fd90db9d3, 0x7b670a4cc50f7a9b, 0x77c07d2a05c6dfa5,
|
||||||
|
0xe3778b6646d0a6fa, 0xb39c8eda47b56749, 0x933ed448addbef28,
|
||||||
|
0xaf846af6ab7d0bf4, 0xe5af208eb666e49, 0x5e6622f73534cd6a,
|
||||||
|
0x297daeca42ef5b6e, 0x862daef3d35539a6, 0xe68722498f8e1ea9,
|
||||||
|
0x981c53093dc0d572, 0xfa09b0bfbf86fbf5, 0x30b1e96166219f15,
|
||||||
|
0x70e7d466bdc4fb83, 0x5a66736e35f2a8e9, 0xcddb59d2b7c1baef,
|
||||||
|
0xd6c7d247d26d8996, 0xea4e39eac8de1ba3, 0x539c8bb19fa3aff2,
|
||||||
|
0x9f90e4c5fd508d8, 0xa34e5956fbaf3385, 0x2e2f8e151d3ef375,
|
||||||
|
0x173691e9b83faec1, 0xb85a8d56bf016379, 0x8382381267408ae3,
|
||||||
|
0xb90f901bbdc0096d, 0x7c6ad32933bcec65, 0x76bb5e2f2c8ad595,
|
||||||
|
0x390f851a6cf46d28, 0xc3e6064da1c2da72, 0xc52a0c101cfa5389,
|
||||||
|
0xd78eaf84a3fbc530, 0x3781b9e2288b997e, 0x73c2f6dea83d05c4,
|
||||||
|
0x4228e364c5b5ed7, 0x9d7a3edf0da43911, 0x8edcfeda24686756,
|
||||||
|
0x5e7667a7b7a9b3a1, 0x4c4f389fa143791d, 0xb08bc1023da7cddc,
|
||||||
|
0x7ab4be3ae529b1cc, 0x754e6132dbe74ff9, 0x71635442a839df45,
|
||||||
|
0x2f6fb1643fbe52de, 0x961e0a42cf7a8177, 0xf3b45d83d89ef2ea,
|
||||||
|
0xee3de4cf4a6e3e9b, 0xcd6848542c3295e7, 0xe4cee1664c78662f,
|
||||||
|
0x9947548b474c68c4, 0x25d73777a5ed8b0b, 0xc915b1d636b7fc,
|
||||||
|
0x21c2ba75d9b0d2da, 0x5f6b5dcf608a64a1, 0xdcf333255ff9570c,
|
||||||
|
0x633b922418ced4ee, 0xc136dde0b004b34a, 0x58cc83b05d4b2f5a,
|
||||||
|
0x5eb424dda28e42d2, 0x62df47369739cd98, 0xb4e0b42485e4ce17,
|
||||||
|
0x16e1f0c1f9a8d1e7, 0x8ec3916707560ebf, 0x62ba6e2df2cc9db3,
|
||||||
|
0xcbf9f4ff77d83a16, 0x78d9d7d07d2bbcc4, 0xef554ce1e02c41f4,
|
||||||
|
0x8d7581127eccf94d, 0xa9b53336cb3c8a05, 0x38c42c0bf45c4f91,
|
||||||
|
0x640893cdf4488863, 0x80ec34bc575ea568, 0x39f324f5b48eaa40,
|
||||||
|
0xe9d9ed1f8eff527f, 0x9224fc058cc5a214, 0xbaba00b04cfe7741,
|
||||||
|
0x309a9f120fcf52af, 0xa558f3ec65626212, 0x424bec8b7adabe2f,
|
||||||
|
0x41622513a6aea433, 0xb88da2d5324ca798, 0xd287733b245528a4,
|
||||||
|
0x9a44697e6d68aec3, 0x7b1093be2f49bb28, 0x50bbec632e3d8aad,
|
||||||
|
0x6cd90723e1ea8283, 0x897b9e7431b02bf3, 0x219efdcb338a7047,
|
||||||
|
0x3b0311f0a27c0656, 0xdb17bf91c0db96e7, 0x8cd4fd6b4e85a5b2,
|
||||||
|
0xfab071054ba6409d, 0x40d6fe831fa9dfd9, 0xaf358debad7d791e,
|
||||||
|
0xeb8d0e25a65e3e58, 0xbbcbd3df14e08580, 0xcf751f27ecdab2b,
|
||||||
|
0x2b4da14f2613d8f4
|
||||||
|
};
|
||||||
|
|
||||||
|
#endif /* ZSTD_LDM_GEARTAB_H */
|
||||||
|
|
||||||
|
#endif /* USE_EXTERNAL_ZSTD */
|
||||||
12
vendor/github.com/DataDog/zstd/zstd_legacy.h
generated
vendored
12
vendor/github.com/DataDog/zstd/zstd_legacy.h
generated
vendored
@@ -1,5 +1,6 @@
|
|||||||
|
#ifndef USE_EXTERNAL_ZSTD
|
||||||
/*
|
/*
|
||||||
* Copyright (c) 2016-present, Yann Collet, Facebook, Inc.
|
* Copyright (c) Meta Platforms, Inc. and affiliates.
|
||||||
* All rights reserved.
|
* All rights reserved.
|
||||||
*
|
*
|
||||||
* This source code is licensed under both the BSD-style license (found in the
|
* This source code is licensed under both the BSD-style license (found in the
|
||||||
@@ -242,6 +243,13 @@ MEM_STATIC ZSTD_frameSizeInfo ZSTD_findFrameSizeInfoLegacy(const void *src, size
|
|||||||
frameSizeInfo.compressedSize = ERROR(srcSize_wrong);
|
frameSizeInfo.compressedSize = ERROR(srcSize_wrong);
|
||||||
frameSizeInfo.decompressedBound = ZSTD_CONTENTSIZE_ERROR;
|
frameSizeInfo.decompressedBound = ZSTD_CONTENTSIZE_ERROR;
|
||||||
}
|
}
|
||||||
|
/* In all cases, decompressedBound == nbBlocks * ZSTD_BLOCKSIZE_MAX.
|
||||||
|
* So we can compute nbBlocks without having to change every function.
|
||||||
|
*/
|
||||||
|
if (frameSizeInfo.decompressedBound != ZSTD_CONTENTSIZE_ERROR) {
|
||||||
|
assert((frameSizeInfo.decompressedBound & (ZSTD_BLOCKSIZE_MAX - 1)) == 0);
|
||||||
|
frameSizeInfo.nbBlocks = (size_t)(frameSizeInfo.decompressedBound / ZSTD_BLOCKSIZE_MAX);
|
||||||
|
}
|
||||||
return frameSizeInfo;
|
return frameSizeInfo;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -413,3 +421,5 @@ MEM_STATIC size_t ZSTD_decompressLegacyStream(void* legacyContext, U32 version,
|
|||||||
#endif
|
#endif
|
||||||
|
|
||||||
#endif /* ZSTD_LEGACY_H */
|
#endif /* ZSTD_LEGACY_H */
|
||||||
|
|
||||||
|
#endif /* USE_EXTERNAL_ZSTD */
|
||||||
|
|||||||
787
vendor/github.com/DataDog/zstd/zstd_opt.c
generated
vendored
787
vendor/github.com/DataDog/zstd/zstd_opt.c
generated
vendored
File diff suppressed because it is too large
Load Diff
5
vendor/github.com/DataDog/zstd/zstd_opt.h
generated
vendored
5
vendor/github.com/DataDog/zstd/zstd_opt.h
generated
vendored
@@ -1,5 +1,6 @@
|
|||||||
|
#ifndef USE_EXTERNAL_ZSTD
|
||||||
/*
|
/*
|
||||||
* Copyright (c) 2016-present, Yann Collet, Facebook, Inc.
|
* Copyright (c) Meta Platforms, Inc. and affiliates.
|
||||||
* All rights reserved.
|
* All rights reserved.
|
||||||
*
|
*
|
||||||
* This source code is licensed under both the BSD-style license (found in the
|
* This source code is licensed under both the BSD-style license (found in the
|
||||||
@@ -54,3 +55,5 @@ size_t ZSTD_compressBlock_btultra_extDict(
|
|||||||
#endif
|
#endif
|
||||||
|
|
||||||
#endif /* ZSTD_OPT_H */
|
#endif /* ZSTD_OPT_H */
|
||||||
|
|
||||||
|
#endif /* USE_EXTERNAL_ZSTD */
|
||||||
|
|||||||
227
vendor/github.com/DataDog/zstd/zstd_stream.go
generated
vendored
227
vendor/github.com/DataDog/zstd/zstd_stream.go
generated
vendored
@@ -1,8 +1,6 @@
|
|||||||
package zstd
|
package zstd
|
||||||
|
|
||||||
/*
|
/*
|
||||||
#define ZSTD_STATIC_LINKING_ONLY
|
|
||||||
#include "stdint.h" // for uintptr_t
|
|
||||||
#include "zstd.h"
|
#include "zstd.h"
|
||||||
|
|
||||||
typedef struct compressStream2_result_s {
|
typedef struct compressStream2_result_s {
|
||||||
@@ -11,9 +9,10 @@ typedef struct compressStream2_result_s {
|
|||||||
size_t bytes_written;
|
size_t bytes_written;
|
||||||
} compressStream2_result;
|
} compressStream2_result;
|
||||||
|
|
||||||
static void ZSTD_compressStream2_wrapper(compressStream2_result* result, ZSTD_CCtx* ctx, uintptr_t dst, size_t maxDstSize, const uintptr_t src, size_t srcSize) {
|
static void ZSTD_compressStream2_wrapper(compressStream2_result* result, ZSTD_CCtx* ctx,
|
||||||
ZSTD_outBuffer outBuffer = { (void*)dst, maxDstSize, 0 };
|
void* dst, size_t maxDstSize, const void* src, size_t srcSize) {
|
||||||
ZSTD_inBuffer inBuffer = { (void*)src, srcSize, 0 };
|
ZSTD_outBuffer outBuffer = { dst, maxDstSize, 0 };
|
||||||
|
ZSTD_inBuffer inBuffer = { src, srcSize, 0 };
|
||||||
size_t retCode = ZSTD_compressStream2(ctx, &outBuffer, &inBuffer, ZSTD_e_continue);
|
size_t retCode = ZSTD_compressStream2(ctx, &outBuffer, &inBuffer, ZSTD_e_continue);
|
||||||
|
|
||||||
result->return_code = retCode;
|
result->return_code = retCode;
|
||||||
@@ -21,9 +20,21 @@ static void ZSTD_compressStream2_wrapper(compressStream2_result* result, ZSTD_CC
|
|||||||
result->bytes_written = outBuffer.pos;
|
result->bytes_written = outBuffer.pos;
|
||||||
}
|
}
|
||||||
|
|
||||||
static void ZSTD_compressStream2_finish(compressStream2_result* result, ZSTD_CCtx* ctx, uintptr_t dst, size_t maxDstSize, const uintptr_t src, size_t srcSize) {
|
static void ZSTD_compressStream2_flush(compressStream2_result* result, ZSTD_CCtx* ctx,
|
||||||
ZSTD_outBuffer outBuffer = { (void*)dst, maxDstSize, 0 };
|
void* dst, size_t maxDstSize, const void* src, size_t srcSize) {
|
||||||
ZSTD_inBuffer inBuffer = { (void*)src, srcSize, 0 };
|
ZSTD_outBuffer outBuffer = { dst, maxDstSize, 0 };
|
||||||
|
ZSTD_inBuffer inBuffer = { src, srcSize, 0 };
|
||||||
|
size_t retCode = ZSTD_compressStream2(ctx, &outBuffer, &inBuffer, ZSTD_e_flush);
|
||||||
|
|
||||||
|
result->return_code = retCode;
|
||||||
|
result->bytes_consumed = inBuffer.pos;
|
||||||
|
result->bytes_written = outBuffer.pos;
|
||||||
|
}
|
||||||
|
|
||||||
|
static void ZSTD_compressStream2_finish(compressStream2_result* result, ZSTD_CCtx* ctx,
|
||||||
|
void* dst, size_t maxDstSize, const void* src, size_t srcSize) {
|
||||||
|
ZSTD_outBuffer outBuffer = { dst, maxDstSize, 0 };
|
||||||
|
ZSTD_inBuffer inBuffer = { src, srcSize, 0 };
|
||||||
size_t retCode = ZSTD_compressStream2(ctx, &outBuffer, &inBuffer, ZSTD_e_end);
|
size_t retCode = ZSTD_compressStream2(ctx, &outBuffer, &inBuffer, ZSTD_e_end);
|
||||||
|
|
||||||
result->return_code = retCode;
|
result->return_code = retCode;
|
||||||
@@ -38,9 +49,10 @@ typedef struct decompressStream2_result_s {
|
|||||||
size_t bytes_written;
|
size_t bytes_written;
|
||||||
} decompressStream2_result;
|
} decompressStream2_result;
|
||||||
|
|
||||||
static void ZSTD_decompressStream_wrapper(decompressStream2_result* result, ZSTD_DCtx* ctx, uintptr_t dst, size_t maxDstSize, const uintptr_t src, size_t srcSize) {
|
static void ZSTD_decompressStream_wrapper(decompressStream2_result* result, ZSTD_DCtx* ctx,
|
||||||
ZSTD_outBuffer outBuffer = { (void*)dst, maxDstSize, 0 };
|
void* dst, size_t maxDstSize, const void* src, size_t srcSize) {
|
||||||
ZSTD_inBuffer inBuffer = { (void*)src, srcSize, 0 };
|
ZSTD_outBuffer outBuffer = { dst, maxDstSize, 0 };
|
||||||
|
ZSTD_inBuffer inBuffer = { src, srcSize, 0 };
|
||||||
size_t retCode = ZSTD_decompressStream(ctx, &outBuffer, &inBuffer);
|
size_t retCode = ZSTD_decompressStream(ctx, &outBuffer, &inBuffer);
|
||||||
|
|
||||||
result->return_code = retCode;
|
result->return_code = retCode;
|
||||||
@@ -60,6 +72,7 @@ import (
|
|||||||
|
|
||||||
var errShortRead = errors.New("short read")
|
var errShortRead = errors.New("short read")
|
||||||
var errReaderClosed = errors.New("Reader is closed")
|
var errReaderClosed = errors.New("Reader is closed")
|
||||||
|
var ErrNoParallelSupport = errors.New("No parallel support")
|
||||||
|
|
||||||
// Writer is an io.WriteCloser that zstd-compresses its input.
|
// Writer is an io.WriteCloser that zstd-compresses its input.
|
||||||
type Writer struct {
|
type Writer struct {
|
||||||
@@ -155,20 +168,19 @@ func (w *Writer) Write(p []byte) (int, error) {
|
|||||||
srcData = w.srcBuffer
|
srcData = w.srcBuffer
|
||||||
}
|
}
|
||||||
|
|
||||||
srcPtr := C.uintptr_t(uintptr(0)) // Do not point anywhere, if src is empty
|
if len(srcData) == 0 {
|
||||||
if len(srcData) > 0 {
|
// this is technically unnecessary: srcData is p or w.srcBuffer, and len() > 0 checked above
|
||||||
srcPtr = C.uintptr_t(uintptr(unsafe.Pointer(&srcData[0])))
|
// but this ensures the code can change without dereferencing an srcData[0]
|
||||||
|
return 0, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
C.ZSTD_compressStream2_wrapper(
|
C.ZSTD_compressStream2_wrapper(
|
||||||
w.resultBuffer,
|
w.resultBuffer,
|
||||||
w.ctx,
|
w.ctx,
|
||||||
C.uintptr_t(uintptr(unsafe.Pointer(&w.dstBuffer[0]))),
|
unsafe.Pointer(&w.dstBuffer[0]),
|
||||||
C.size_t(len(w.dstBuffer)),
|
C.size_t(len(w.dstBuffer)),
|
||||||
srcPtr,
|
unsafe.Pointer(&srcData[0]),
|
||||||
C.size_t(len(srcData)),
|
C.size_t(len(srcData)),
|
||||||
)
|
)
|
||||||
runtime.KeepAlive(p) // Ensure p is kept until here so pointer doesn't disappear during C call
|
|
||||||
ret := int(w.resultBuffer.return_code)
|
ret := int(w.resultBuffer.return_code)
|
||||||
if err := getError(ret); err != nil {
|
if err := getError(ret); err != nil {
|
||||||
return 0, err
|
return 0, err
|
||||||
@@ -203,6 +215,49 @@ func (w *Writer) Write(p []byte) (int, error) {
|
|||||||
return len(p), err
|
return len(p), err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Flush writes any unwritten data to the underlying io.Writer.
|
||||||
|
func (w *Writer) Flush() error {
|
||||||
|
if w.firstError != nil {
|
||||||
|
return w.firstError
|
||||||
|
}
|
||||||
|
|
||||||
|
ret := 1 // So we loop at least once
|
||||||
|
for ret > 0 {
|
||||||
|
var srcPtr *byte // Do not point anywhere, if src is empty
|
||||||
|
if len(w.srcBuffer) > 0 {
|
||||||
|
srcPtr = &w.srcBuffer[0]
|
||||||
|
}
|
||||||
|
|
||||||
|
C.ZSTD_compressStream2_flush(
|
||||||
|
w.resultBuffer,
|
||||||
|
w.ctx,
|
||||||
|
unsafe.Pointer(&w.dstBuffer[0]),
|
||||||
|
C.size_t(len(w.dstBuffer)),
|
||||||
|
unsafe.Pointer(srcPtr),
|
||||||
|
C.size_t(len(w.srcBuffer)),
|
||||||
|
)
|
||||||
|
ret = int(w.resultBuffer.return_code)
|
||||||
|
if err := getError(ret); err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
w.srcBuffer = w.srcBuffer[w.resultBuffer.bytes_consumed:]
|
||||||
|
written := int(w.resultBuffer.bytes_written)
|
||||||
|
_, err := w.underlyingWriter.Write(w.dstBuffer[:written])
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
if ret > 0 { // We have a hint if we need to resize the dstBuffer
|
||||||
|
w.dstBuffer = w.dstBuffer[:cap(w.dstBuffer)]
|
||||||
|
if len(w.dstBuffer) < ret {
|
||||||
|
w.dstBuffer = make([]byte, ret)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
// Close closes the Writer, flushing any unwritten data to the underlying
|
// Close closes the Writer, flushing any unwritten data to the underlying
|
||||||
// io.Writer and freeing objects, but does not close the underlying io.Writer.
|
// io.Writer and freeing objects, but does not close the underlying io.Writer.
|
||||||
func (w *Writer) Close() error {
|
func (w *Writer) Close() error {
|
||||||
@@ -212,17 +267,17 @@ func (w *Writer) Close() error {
|
|||||||
|
|
||||||
ret := 1 // So we loop at least once
|
ret := 1 // So we loop at least once
|
||||||
for ret > 0 {
|
for ret > 0 {
|
||||||
srcPtr := C.uintptr_t(uintptr(0)) // Do not point anywhere, if src is empty
|
var srcPtr *byte // Do not point anywhere, if src is empty
|
||||||
if len(w.srcBuffer) > 0 {
|
if len(w.srcBuffer) > 0 {
|
||||||
srcPtr = C.uintptr_t(uintptr(unsafe.Pointer(&w.srcBuffer[0])))
|
srcPtr = &w.srcBuffer[0]
|
||||||
}
|
}
|
||||||
|
|
||||||
C.ZSTD_compressStream2_finish(
|
C.ZSTD_compressStream2_finish(
|
||||||
w.resultBuffer,
|
w.resultBuffer,
|
||||||
w.ctx,
|
w.ctx,
|
||||||
C.uintptr_t(uintptr(unsafe.Pointer(&w.dstBuffer[0]))),
|
unsafe.Pointer(&w.dstBuffer[0]),
|
||||||
C.size_t(len(w.dstBuffer)),
|
C.size_t(len(w.dstBuffer)),
|
||||||
srcPtr,
|
unsafe.Pointer(srcPtr),
|
||||||
C.size_t(len(w.srcBuffer)),
|
C.size_t(len(w.srcBuffer)),
|
||||||
)
|
)
|
||||||
ret = int(w.resultBuffer.return_code)
|
ret = int(w.resultBuffer.return_code)
|
||||||
@@ -231,7 +286,11 @@ func (w *Writer) Close() error {
|
|||||||
}
|
}
|
||||||
w.srcBuffer = w.srcBuffer[w.resultBuffer.bytes_consumed:]
|
w.srcBuffer = w.srcBuffer[w.resultBuffer.bytes_consumed:]
|
||||||
written := int(w.resultBuffer.bytes_written)
|
written := int(w.resultBuffer.bytes_written)
|
||||||
w.underlyingWriter.Write(w.dstBuffer[:written])
|
_, err := w.underlyingWriter.Write(w.dstBuffer[:written])
|
||||||
|
if err != nil {
|
||||||
|
C.ZSTD_freeCStream(w.ctx)
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
if ret > 0 { // We have a hint if we need to resize the dstBuffer
|
if ret > 0 { // We have a hint if we need to resize the dstBuffer
|
||||||
w.dstBuffer = w.dstBuffer[:cap(w.dstBuffer)]
|
w.dstBuffer = w.dstBuffer[:cap(w.dstBuffer)]
|
||||||
@@ -244,6 +303,28 @@ func (w *Writer) Close() error {
|
|||||||
return getError(int(C.ZSTD_freeCStream(w.ctx)))
|
return getError(int(C.ZSTD_freeCStream(w.ctx)))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Set the number of workers to run the compression in parallel using multiple threads
|
||||||
|
// If > 1, the Write() call will become asynchronous. This means data will be buffered until processed.
|
||||||
|
// If you call Write() too fast, you might incur a memory buffer up to as large as your input.
|
||||||
|
// Consider calling Flush() periodically if you need to compress a very large file that would not fit all in memory.
|
||||||
|
// By default only one worker is used.
|
||||||
|
func (w *Writer) SetNbWorkers(n int) error {
|
||||||
|
if w.firstError != nil {
|
||||||
|
return w.firstError
|
||||||
|
}
|
||||||
|
if err := getError(int(C.ZSTD_CCtx_setParameter(w.ctx, C.ZSTD_c_nbWorkers, C.int(n)))); err != nil {
|
||||||
|
w.firstError = err
|
||||||
|
// First error case, a shared libary is used, and the library was compiled without parallel support
|
||||||
|
if err.Error() == "Unsupported parameter" {
|
||||||
|
return ErrNoParallelSupport
|
||||||
|
} else {
|
||||||
|
// This could happen if a very large number is passed in, and possibly zstd refuse to create as many threads, or the OS fails to do so
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
// cSize is the recommended size of reader.compressionBuffer. This func and
|
// cSize is the recommended size of reader.compressionBuffer. This func and
|
||||||
// invocation allow for a one-time check for validity.
|
// invocation allow for a one-time check for validity.
|
||||||
var cSize = func() int {
|
var cSize = func() int {
|
||||||
@@ -363,49 +444,86 @@ func (r *reader) Read(p []byte) (int, error) {
|
|||||||
return 0, r.firstError
|
return 0, r.firstError
|
||||||
}
|
}
|
||||||
|
|
||||||
// If we already have enough bytes, return
|
if len(p) == 0 {
|
||||||
if r.decompSize-r.decompOff >= len(p) {
|
return 0, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
// If we already have some uncompressed bytes, return without blocking
|
||||||
|
if r.decompSize > r.decompOff {
|
||||||
|
if r.decompSize-r.decompOff > len(p) {
|
||||||
copy(p, r.decompressionBuffer[r.decompOff:])
|
copy(p, r.decompressionBuffer[r.decompOff:])
|
||||||
r.decompOff += len(p)
|
r.decompOff += len(p)
|
||||||
return len(p), nil
|
return len(p), nil
|
||||||
}
|
}
|
||||||
|
// From https://golang.org/pkg/io/#Reader
|
||||||
|
// > Read conventionally returns what is available instead of waiting for more.
|
||||||
copy(p, r.decompressionBuffer[r.decompOff:r.decompSize])
|
copy(p, r.decompressionBuffer[r.decompOff:r.decompSize])
|
||||||
got := r.decompSize - r.decompOff
|
got := r.decompSize - r.decompOff
|
||||||
r.decompSize = 0
|
r.decompOff = r.decompSize
|
||||||
r.decompOff = 0
|
return got, nil
|
||||||
|
}
|
||||||
|
|
||||||
for got < len(p) {
|
// Repeatedly read from the underlying reader until we get
|
||||||
// Populate src
|
// at least one zstd block, so that we don't block if the
|
||||||
src := r.compressionBuffer
|
// other end has flushed a block.
|
||||||
reader := r.underlyingReader
|
for {
|
||||||
n, err := TryReadFull(reader, src[r.compressionLeft:])
|
// - If the last decompression didn't entirely fill the decompression buffer,
|
||||||
if err != nil && err != errShortRead { // Handle underlying reader errors first
|
// zstd flushed all it could, and needs new data. In that case, do 1 Read.
|
||||||
|
// - If the last decompression did entirely fill the decompression buffer,
|
||||||
|
// it might have needed more room to decompress the input. In that case,
|
||||||
|
// don't do any unnecessary Read that might block.
|
||||||
|
needsData := r.decompSize < len(r.decompressionBuffer)
|
||||||
|
|
||||||
|
var src []byte
|
||||||
|
if !needsData {
|
||||||
|
src = r.compressionBuffer[:r.compressionLeft]
|
||||||
|
} else {
|
||||||
|
src = r.compressionBuffer
|
||||||
|
var n int
|
||||||
|
var err error
|
||||||
|
// Read until data arrives or an error occurs.
|
||||||
|
for n == 0 && err == nil {
|
||||||
|
n, err = r.underlyingReader.Read(src[r.compressionLeft:])
|
||||||
|
}
|
||||||
|
if err != nil && err != io.EOF { // Handle underlying reader errors first
|
||||||
return 0, fmt.Errorf("failed to read from underlying reader: %s", err)
|
return 0, fmt.Errorf("failed to read from underlying reader: %s", err)
|
||||||
} else if n == 0 && r.compressionLeft == 0 {
|
}
|
||||||
return got, io.EOF
|
if n == 0 {
|
||||||
|
// Ideally, we'd return with ErrUnexpectedEOF in all cases where the stream was unexpectedly EOF'd
|
||||||
|
// during a block or frame, i.e. when there are incomplete, pending compression data.
|
||||||
|
// However, it's hard to detect those cases with zstd. Namely, there is no way to know the size of
|
||||||
|
// the current buffered compression data in the zstd stream internal buffers.
|
||||||
|
// Best effort: throw ErrUnexpectedEOF if we still have some pending buffered compression data that
|
||||||
|
// zstd doesn't want to accept.
|
||||||
|
// If we don't have any buffered compression data but zstd still has some in its internal buffers,
|
||||||
|
// we will return with EOF instead.
|
||||||
|
if r.compressionLeft > 0 {
|
||||||
|
return 0, io.ErrUnexpectedEOF
|
||||||
|
}
|
||||||
|
return 0, io.EOF
|
||||||
}
|
}
|
||||||
src = src[:r.compressionLeft+n]
|
src = src[:r.compressionLeft+n]
|
||||||
|
}
|
||||||
|
|
||||||
// C code
|
// C code
|
||||||
srcPtr := C.uintptr_t(uintptr(0)) // Do not point anywhere, if src is empty
|
var srcPtr *byte // Do not point anywhere, if src is empty
|
||||||
if len(src) > 0 {
|
if len(src) > 0 {
|
||||||
srcPtr = C.uintptr_t(uintptr(unsafe.Pointer(&src[0])))
|
srcPtr = &src[0]
|
||||||
}
|
}
|
||||||
|
|
||||||
C.ZSTD_decompressStream_wrapper(
|
C.ZSTD_decompressStream_wrapper(
|
||||||
r.resultBuffer,
|
r.resultBuffer,
|
||||||
r.ctx,
|
r.ctx,
|
||||||
C.uintptr_t(uintptr(unsafe.Pointer(&r.decompressionBuffer[0]))),
|
unsafe.Pointer(&r.decompressionBuffer[0]),
|
||||||
C.size_t(len(r.decompressionBuffer)),
|
C.size_t(len(r.decompressionBuffer)),
|
||||||
srcPtr,
|
unsafe.Pointer(srcPtr),
|
||||||
C.size_t(len(src)),
|
C.size_t(len(src)),
|
||||||
)
|
)
|
||||||
retCode := int(r.resultBuffer.return_code)
|
retCode := int(r.resultBuffer.return_code)
|
||||||
|
|
||||||
// Keep src here eventhough we reuse later, the code might be deleted at some point
|
// Keep src here even though we reuse later, the code might be deleted at some point
|
||||||
runtime.KeepAlive(src)
|
runtime.KeepAlive(src)
|
||||||
if err = getError(retCode); err != nil {
|
if err := getError(retCode); err != nil {
|
||||||
return 0, fmt.Errorf("failed to decompress: %s", err)
|
return 0, fmt.Errorf("failed to decompress: %s", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -415,10 +533,9 @@ func (r *reader) Read(p []byte) (int, error) {
|
|||||||
left := src[bytesConsumed:]
|
left := src[bytesConsumed:]
|
||||||
copy(r.compressionBuffer, left)
|
copy(r.compressionBuffer, left)
|
||||||
}
|
}
|
||||||
r.compressionLeft = len(src) - int(bytesConsumed)
|
r.compressionLeft = len(src) - bytesConsumed
|
||||||
r.decompSize = int(r.resultBuffer.bytes_written)
|
r.decompSize = int(r.resultBuffer.bytes_written)
|
||||||
r.decompOff = copy(p[got:], r.decompressionBuffer[:r.decompSize])
|
r.decompOff = copy(p, r.decompressionBuffer[:r.decompSize])
|
||||||
got += r.decompOff
|
|
||||||
|
|
||||||
// Resize buffers
|
// Resize buffers
|
||||||
nsize := retCode // Hint for next src buffer size
|
nsize := retCode // Hint for next src buffer size
|
||||||
@@ -430,25 +547,9 @@ func (r *reader) Read(p []byte) (int, error) {
|
|||||||
nsize = r.compressionLeft
|
nsize = r.compressionLeft
|
||||||
}
|
}
|
||||||
r.compressionBuffer = resize(r.compressionBuffer, nsize)
|
r.compressionBuffer = resize(r.compressionBuffer, nsize)
|
||||||
}
|
|
||||||
return got, nil
|
|
||||||
}
|
|
||||||
|
|
||||||
// TryReadFull reads buffer just as ReadFull does
|
if r.decompOff > 0 {
|
||||||
// Here we expect that buffer may end and we do not return ErrUnexpectedEOF as ReadAtLeast does.
|
return r.decompOff, nil
|
||||||
// We return errShortRead instead to distinguish short reads and failures.
|
|
||||||
// We cannot use ReadFull/ReadAtLeast because it masks Reader errors, such as network failures
|
|
||||||
// and causes panic instead of error.
|
|
||||||
func TryReadFull(r io.Reader, buf []byte) (n int, err error) {
|
|
||||||
for n < len(buf) && err == nil {
|
|
||||||
var nn int
|
|
||||||
nn, err = r.Read(buf[n:])
|
|
||||||
n += nn
|
|
||||||
}
|
}
|
||||||
if n == len(buf) && err == io.EOF {
|
|
||||||
err = nil // EOF at the end is somewhat expected
|
|
||||||
} else if err == io.EOF {
|
|
||||||
err = errShortRead
|
|
||||||
}
|
}
|
||||||
return
|
|
||||||
}
|
}
|
||||||
|
|||||||
166
vendor/github.com/DataDog/zstd/zstd_trace.h
generated
vendored
Normal file
166
vendor/github.com/DataDog/zstd/zstd_trace.h
generated
vendored
Normal file
@@ -0,0 +1,166 @@
|
|||||||
|
#ifndef USE_EXTERNAL_ZSTD
|
||||||
|
/*
|
||||||
|
* Copyright (c) Meta Platforms, Inc. and affiliates.
|
||||||
|
* All rights reserved.
|
||||||
|
*
|
||||||
|
* This source code is licensed under both the BSD-style license (found in the
|
||||||
|
* LICENSE file in the root directory of this source tree) and the GPLv2 (found
|
||||||
|
* in the COPYING file in the root directory of this source tree).
|
||||||
|
* You may select, at your option, one of the above-listed licenses.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#ifndef ZSTD_TRACE_H
|
||||||
|
#define ZSTD_TRACE_H
|
||||||
|
|
||||||
|
#if defined (__cplusplus)
|
||||||
|
extern "C" {
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#include <stddef.h>
|
||||||
|
|
||||||
|
/* weak symbol support
|
||||||
|
* For now, enable conservatively:
|
||||||
|
* - Only GNUC
|
||||||
|
* - Only ELF
|
||||||
|
* - Only x86-64, i386 and aarch64
|
||||||
|
* Also, explicitly disable on platforms known not to work so they aren't
|
||||||
|
* forgotten in the future.
|
||||||
|
*/
|
||||||
|
#if !defined(ZSTD_HAVE_WEAK_SYMBOLS) && \
|
||||||
|
defined(__GNUC__) && defined(__ELF__) && \
|
||||||
|
(defined(__x86_64__) || defined(_M_X64) || defined(__i386__) || defined(_M_IX86) || defined(__aarch64__)) && \
|
||||||
|
!defined(__APPLE__) && !defined(_WIN32) && !defined(__MINGW32__) && \
|
||||||
|
!defined(__CYGWIN__) && !defined(_AIX)
|
||||||
|
# define ZSTD_HAVE_WEAK_SYMBOLS 1
|
||||||
|
#else
|
||||||
|
# define ZSTD_HAVE_WEAK_SYMBOLS 0
|
||||||
|
#endif
|
||||||
|
#if ZSTD_HAVE_WEAK_SYMBOLS
|
||||||
|
# define ZSTD_WEAK_ATTR __attribute__((__weak__))
|
||||||
|
#else
|
||||||
|
# define ZSTD_WEAK_ATTR
|
||||||
|
#endif
|
||||||
|
|
||||||
|
/* Only enable tracing when weak symbols are available. */
|
||||||
|
#ifndef ZSTD_TRACE
|
||||||
|
# define ZSTD_TRACE ZSTD_HAVE_WEAK_SYMBOLS
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#if ZSTD_TRACE
|
||||||
|
|
||||||
|
struct ZSTD_CCtx_s;
|
||||||
|
struct ZSTD_DCtx_s;
|
||||||
|
struct ZSTD_CCtx_params_s;
|
||||||
|
|
||||||
|
typedef struct {
|
||||||
|
/**
|
||||||
|
* ZSTD_VERSION_NUMBER
|
||||||
|
*
|
||||||
|
* This is guaranteed to be the first member of ZSTD_trace.
|
||||||
|
* Otherwise, this struct is not stable between versions. If
|
||||||
|
* the version number does not match your expectation, you
|
||||||
|
* should not interpret the rest of the struct.
|
||||||
|
*/
|
||||||
|
unsigned version;
|
||||||
|
/**
|
||||||
|
* Non-zero if streaming (de)compression is used.
|
||||||
|
*/
|
||||||
|
unsigned streaming;
|
||||||
|
/**
|
||||||
|
* The dictionary ID.
|
||||||
|
*/
|
||||||
|
unsigned dictionaryID;
|
||||||
|
/**
|
||||||
|
* Is the dictionary cold?
|
||||||
|
* Only set on decompression.
|
||||||
|
*/
|
||||||
|
unsigned dictionaryIsCold;
|
||||||
|
/**
|
||||||
|
* The dictionary size or zero if no dictionary.
|
||||||
|
*/
|
||||||
|
size_t dictionarySize;
|
||||||
|
/**
|
||||||
|
* The uncompressed size of the data.
|
||||||
|
*/
|
||||||
|
size_t uncompressedSize;
|
||||||
|
/**
|
||||||
|
* The compressed size of the data.
|
||||||
|
*/
|
||||||
|
size_t compressedSize;
|
||||||
|
/**
|
||||||
|
* The fully resolved CCtx parameters (NULL on decompression).
|
||||||
|
*/
|
||||||
|
struct ZSTD_CCtx_params_s const* params;
|
||||||
|
/**
|
||||||
|
* The ZSTD_CCtx pointer (NULL on decompression).
|
||||||
|
*/
|
||||||
|
struct ZSTD_CCtx_s const* cctx;
|
||||||
|
/**
|
||||||
|
* The ZSTD_DCtx pointer (NULL on compression).
|
||||||
|
*/
|
||||||
|
struct ZSTD_DCtx_s const* dctx;
|
||||||
|
} ZSTD_Trace;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* A tracing context. It must be 0 when tracing is disabled.
|
||||||
|
* Otherwise, any non-zero value returned by a tracing begin()
|
||||||
|
* function is presented to any subsequent calls to end().
|
||||||
|
*
|
||||||
|
* Any non-zero value is treated as tracing is enabled and not
|
||||||
|
* interpreted by the library.
|
||||||
|
*
|
||||||
|
* Two possible uses are:
|
||||||
|
* * A timestamp for when the begin() function was called.
|
||||||
|
* * A unique key identifying the (de)compression, like the
|
||||||
|
* address of the [dc]ctx pointer if you need to track
|
||||||
|
* more information than just a timestamp.
|
||||||
|
*/
|
||||||
|
typedef unsigned long long ZSTD_TraceCtx;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Trace the beginning of a compression call.
|
||||||
|
* @param cctx The dctx pointer for the compression.
|
||||||
|
* It can be used as a key to map begin() to end().
|
||||||
|
* @returns Non-zero if tracing is enabled. The return value is
|
||||||
|
* passed to ZSTD_trace_compress_end().
|
||||||
|
*/
|
||||||
|
ZSTD_WEAK_ATTR ZSTD_TraceCtx ZSTD_trace_compress_begin(
|
||||||
|
struct ZSTD_CCtx_s const* cctx);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Trace the end of a compression call.
|
||||||
|
* @param ctx The return value of ZSTD_trace_compress_begin().
|
||||||
|
* @param trace The zstd tracing info.
|
||||||
|
*/
|
||||||
|
ZSTD_WEAK_ATTR void ZSTD_trace_compress_end(
|
||||||
|
ZSTD_TraceCtx ctx,
|
||||||
|
ZSTD_Trace const* trace);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Trace the beginning of a decompression call.
|
||||||
|
* @param dctx The dctx pointer for the decompression.
|
||||||
|
* It can be used as a key to map begin() to end().
|
||||||
|
* @returns Non-zero if tracing is enabled. The return value is
|
||||||
|
* passed to ZSTD_trace_compress_end().
|
||||||
|
*/
|
||||||
|
ZSTD_WEAK_ATTR ZSTD_TraceCtx ZSTD_trace_decompress_begin(
|
||||||
|
struct ZSTD_DCtx_s const* dctx);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Trace the end of a decompression call.
|
||||||
|
* @param ctx The return value of ZSTD_trace_decompress_begin().
|
||||||
|
* @param trace The zstd tracing info.
|
||||||
|
*/
|
||||||
|
ZSTD_WEAK_ATTR void ZSTD_trace_decompress_end(
|
||||||
|
ZSTD_TraceCtx ctx,
|
||||||
|
ZSTD_Trace const* trace);
|
||||||
|
|
||||||
|
#endif /* ZSTD_TRACE */
|
||||||
|
|
||||||
|
#if defined (__cplusplus)
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#endif /* ZSTD_TRACE_H */
|
||||||
|
|
||||||
|
#endif /* USE_EXTERNAL_ZSTD */
|
||||||
92
vendor/github.com/DataDog/zstd/zstd_v01.c
generated
vendored
92
vendor/github.com/DataDog/zstd/zstd_v01.c
generated
vendored
@@ -1,5 +1,6 @@
|
|||||||
|
#ifndef USE_EXTERNAL_ZSTD
|
||||||
/*
|
/*
|
||||||
* Copyright (c) 2016-present, Yann Collet, Facebook, Inc.
|
* Copyright (c) Yann Collet, Meta Platforms, Inc. and affiliates.
|
||||||
* All rights reserved.
|
* All rights reserved.
|
||||||
*
|
*
|
||||||
* This source code is licensed under both the BSD-style license (found in the
|
* This source code is licensed under both the BSD-style license (found in the
|
||||||
@@ -190,28 +191,6 @@ typedef signed long long S64;
|
|||||||
/****************************************************************
|
/****************************************************************
|
||||||
* Memory I/O
|
* Memory I/O
|
||||||
*****************************************************************/
|
*****************************************************************/
|
||||||
/* FSE_FORCE_MEMORY_ACCESS
|
|
||||||
* By default, access to unaligned memory is controlled by `memcpy()`, which is safe and portable.
|
|
||||||
* Unfortunately, on some target/compiler combinations, the generated assembly is sub-optimal.
|
|
||||||
* The below switch allow to select different access method for improved performance.
|
|
||||||
* Method 0 (default) : use `memcpy()`. Safe and portable.
|
|
||||||
* Method 1 : `__packed` statement. It depends on compiler extension (ie, not portable).
|
|
||||||
* This method is safe if your compiler supports it, and *generally* as fast or faster than `memcpy`.
|
|
||||||
* Method 2 : direct access. This method is portable but violate C standard.
|
|
||||||
* It can generate buggy code on targets generating assembly depending on alignment.
|
|
||||||
* But in some circumstances, it's the only known way to get the most performance (ie GCC + ARMv6)
|
|
||||||
* See http://fastcompression.blogspot.fr/2015/08/accessing-unaligned-memory.html for details.
|
|
||||||
* Prefer these methods in priority order (0 > 1 > 2)
|
|
||||||
*/
|
|
||||||
#ifndef FSE_FORCE_MEMORY_ACCESS /* can be defined externally, on command line for example */
|
|
||||||
# if defined(__GNUC__) && ( defined(__ARM_ARCH_6__) || defined(__ARM_ARCH_6J__) || defined(__ARM_ARCH_6K__) || defined(__ARM_ARCH_6Z__) || defined(__ARM_ARCH_6ZK__) || defined(__ARM_ARCH_6T2__) )
|
|
||||||
# define FSE_FORCE_MEMORY_ACCESS 2
|
|
||||||
# elif (defined(__INTEL_COMPILER) && !defined(WIN32)) || \
|
|
||||||
(defined(__GNUC__) && ( defined(__ARM_ARCH_7__) || defined(__ARM_ARCH_7A__) || defined(__ARM_ARCH_7R__) || defined(__ARM_ARCH_7M__) || defined(__ARM_ARCH_7S__) ))
|
|
||||||
# define FSE_FORCE_MEMORY_ACCESS 1
|
|
||||||
# endif
|
|
||||||
#endif
|
|
||||||
|
|
||||||
|
|
||||||
static unsigned FSE_32bits(void)
|
static unsigned FSE_32bits(void)
|
||||||
{
|
{
|
||||||
@@ -224,24 +203,6 @@ static unsigned FSE_isLittleEndian(void)
|
|||||||
return one.c[0];
|
return one.c[0];
|
||||||
}
|
}
|
||||||
|
|
||||||
#if defined(FSE_FORCE_MEMORY_ACCESS) && (FSE_FORCE_MEMORY_ACCESS==2)
|
|
||||||
|
|
||||||
static U16 FSE_read16(const void* memPtr) { return *(const U16*) memPtr; }
|
|
||||||
static U32 FSE_read32(const void* memPtr) { return *(const U32*) memPtr; }
|
|
||||||
static U64 FSE_read64(const void* memPtr) { return *(const U64*) memPtr; }
|
|
||||||
|
|
||||||
#elif defined(FSE_FORCE_MEMORY_ACCESS) && (FSE_FORCE_MEMORY_ACCESS==1)
|
|
||||||
|
|
||||||
/* __pack instructions are safer, but compiler specific, hence potentially problematic for some compilers */
|
|
||||||
/* currently only defined for gcc and icc */
|
|
||||||
typedef union { U16 u16; U32 u32; U64 u64; } __attribute__((packed)) unalign;
|
|
||||||
|
|
||||||
static U16 FSE_read16(const void* ptr) { return ((const unalign*)ptr)->u16; }
|
|
||||||
static U32 FSE_read32(const void* ptr) { return ((const unalign*)ptr)->u32; }
|
|
||||||
static U64 FSE_read64(const void* ptr) { return ((const unalign*)ptr)->u64; }
|
|
||||||
|
|
||||||
#else
|
|
||||||
|
|
||||||
static U16 FSE_read16(const void* memPtr)
|
static U16 FSE_read16(const void* memPtr)
|
||||||
{
|
{
|
||||||
U16 val; memcpy(&val, memPtr, sizeof(val)); return val;
|
U16 val; memcpy(&val, memPtr, sizeof(val)); return val;
|
||||||
@@ -257,8 +218,6 @@ static U64 FSE_read64(const void* memPtr)
|
|||||||
U64 val; memcpy(&val, memPtr, sizeof(val)); return val;
|
U64 val; memcpy(&val, memPtr, sizeof(val)); return val;
|
||||||
}
|
}
|
||||||
|
|
||||||
#endif // FSE_FORCE_MEMORY_ACCESS
|
|
||||||
|
|
||||||
static U16 FSE_readLE16(const void* memPtr)
|
static U16 FSE_readLE16(const void* memPtr)
|
||||||
{
|
{
|
||||||
if (FSE_isLittleEndian())
|
if (FSE_isLittleEndian())
|
||||||
@@ -343,8 +302,7 @@ FORCE_INLINE unsigned FSE_highbit32 (U32 val)
|
|||||||
{
|
{
|
||||||
# if defined(_MSC_VER) /* Visual */
|
# if defined(_MSC_VER) /* Visual */
|
||||||
unsigned long r;
|
unsigned long r;
|
||||||
_BitScanReverse ( &r, val );
|
return _BitScanReverse(&r, val) ? (unsigned)r : 0;
|
||||||
return (unsigned) r;
|
|
||||||
# elif defined(__GNUC__) && (GCC_VERSION >= 304) /* GCC Intrinsic */
|
# elif defined(__GNUC__) && (GCC_VERSION >= 304) /* GCC Intrinsic */
|
||||||
return __builtin_clz (val) ^ 31;
|
return __builtin_clz (val) ^ 31;
|
||||||
# else /* Software version */
|
# else /* Software version */
|
||||||
@@ -1078,7 +1036,7 @@ static size_t HUF_decompress_usingDTable( /* -3% slower when non static */
|
|||||||
BYTE* const ostart = (BYTE*) dst;
|
BYTE* const ostart = (BYTE*) dst;
|
||||||
BYTE* op = ostart;
|
BYTE* op = ostart;
|
||||||
BYTE* const omax = op + maxDstSize;
|
BYTE* const omax = op + maxDstSize;
|
||||||
BYTE* const olimit = omax-15;
|
BYTE* const olimit = maxDstSize < 15 ? op : omax-15;
|
||||||
|
|
||||||
const void* ptr = DTable;
|
const void* ptr = DTable;
|
||||||
const HUF_DElt* const dt = (const HUF_DElt*)(ptr)+1;
|
const HUF_DElt* const dt = (const HUF_DElt*)(ptr)+1;
|
||||||
@@ -1092,7 +1050,7 @@ static size_t HUF_decompress_usingDTable( /* -3% slower when non static */
|
|||||||
const size_t length1 = FSE_readLE16(jumpTable);
|
const size_t length1 = FSE_readLE16(jumpTable);
|
||||||
const size_t length2 = FSE_readLE16(jumpTable+1);
|
const size_t length2 = FSE_readLE16(jumpTable+1);
|
||||||
const size_t length3 = FSE_readLE16(jumpTable+2);
|
const size_t length3 = FSE_readLE16(jumpTable+2);
|
||||||
const size_t length4 = cSrcSize - 6 - length1 - length2 - length3; // check coherency !!
|
const size_t length4 = cSrcSize - 6 - length1 - length2 - length3; /* check coherency !! */
|
||||||
const char* const start1 = (const char*)(cSrc) + 6;
|
const char* const start1 = (const char*)(cSrc) + 6;
|
||||||
const char* const start2 = start1 + length1;
|
const char* const start2 = start1 + length1;
|
||||||
const char* const start3 = start2 + length2;
|
const char* const start3 = start2 + length2;
|
||||||
@@ -1150,11 +1108,11 @@ static size_t HUF_decompress_usingDTable( /* -3% slower when non static */
|
|||||||
|
|
||||||
/* tail */
|
/* tail */
|
||||||
{
|
{
|
||||||
// bitTail = bitD1; // *much* slower : -20% !??!
|
/* bitTail = bitD1; */ /* *much* slower : -20% !??! */
|
||||||
FSE_DStream_t bitTail;
|
FSE_DStream_t bitTail;
|
||||||
bitTail.ptr = bitD1.ptr;
|
bitTail.ptr = bitD1.ptr;
|
||||||
bitTail.bitsConsumed = bitD1.bitsConsumed;
|
bitTail.bitsConsumed = bitD1.bitsConsumed;
|
||||||
bitTail.bitContainer = bitD1.bitContainer; // required in case of FSE_DStream_endOfBuffer
|
bitTail.bitContainer = bitD1.bitContainer; /* required in case of FSE_DStream_endOfBuffer */
|
||||||
bitTail.start = start1;
|
bitTail.start = start1;
|
||||||
for ( ; (FSE_reloadDStream(&bitTail) < FSE_DStream_completed) && (op<omax) ; op++)
|
for ( ; (FSE_reloadDStream(&bitTail) < FSE_DStream_completed) && (op<omax) ; op++)
|
||||||
{
|
{
|
||||||
@@ -1194,7 +1152,7 @@ static size_t HUF_decompress (void* dst, size_t maxDstSize, const void* cSrc, si
|
|||||||
zstd - standard compression library
|
zstd - standard compression library
|
||||||
Copyright (C) 2014-2015, Yann Collet.
|
Copyright (C) 2014-2015, Yann Collet.
|
||||||
|
|
||||||
BSD 2-Clause License (http://www.opensource.org/licenses/bsd-license.php)
|
BSD 2-Clause License (https://opensource.org/licenses/bsd-license.php)
|
||||||
|
|
||||||
Redistribution and use in source and binary forms, with or without
|
Redistribution and use in source and binary forms, with or without
|
||||||
modification, are permitted provided that the following conditions are
|
modification, are permitted provided that the following conditions are
|
||||||
@@ -1280,7 +1238,11 @@ static size_t HUF_decompress (void* dst, size_t maxDstSize, const void* cSrc, si
|
|||||||
* Basic Types
|
* Basic Types
|
||||||
*********************************************************/
|
*********************************************************/
|
||||||
#if defined (__STDC_VERSION__) && __STDC_VERSION__ >= 199901L /* C99 */
|
#if defined (__STDC_VERSION__) && __STDC_VERSION__ >= 199901L /* C99 */
|
||||||
# include <stdint.h>
|
# if defined(_AIX)
|
||||||
|
# include <inttypes.h>
|
||||||
|
# else
|
||||||
|
# include <stdint.h> /* intptr_t */
|
||||||
|
# endif
|
||||||
typedef uint8_t BYTE;
|
typedef uint8_t BYTE;
|
||||||
typedef uint16_t U16;
|
typedef uint16_t U16;
|
||||||
typedef int16_t S16;
|
typedef int16_t S16;
|
||||||
@@ -1483,7 +1445,9 @@ static size_t ZSTDv01_getcBlockSize(const void* src, size_t srcSize, blockProper
|
|||||||
static size_t ZSTD_copyUncompressedBlock(void* dst, size_t maxDstSize, const void* src, size_t srcSize)
|
static size_t ZSTD_copyUncompressedBlock(void* dst, size_t maxDstSize, const void* src, size_t srcSize)
|
||||||
{
|
{
|
||||||
if (srcSize > maxDstSize) return ERROR(dstSize_tooSmall);
|
if (srcSize > maxDstSize) return ERROR(dstSize_tooSmall);
|
||||||
|
if (srcSize > 0) {
|
||||||
memcpy(dst, src, srcSize);
|
memcpy(dst, src, srcSize);
|
||||||
|
}
|
||||||
return srcSize;
|
return srcSize;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -1502,7 +1466,7 @@ static size_t ZSTD_decompressLiterals(void* ctx,
|
|||||||
if (srcSize <= 3) return ERROR(corruption_detected);
|
if (srcSize <= 3) return ERROR(corruption_detected);
|
||||||
|
|
||||||
litSize = ip[1] + (ip[0]<<8);
|
litSize = ip[1] + (ip[0]<<8);
|
||||||
litSize += ((ip[-3] >> 3) & 7) << 16; // mmmmh....
|
litSize += ((ip[-3] >> 3) & 7) << 16; /* mmmmh.... */
|
||||||
op = oend - litSize;
|
op = oend - litSize;
|
||||||
|
|
||||||
(void)ctx;
|
(void)ctx;
|
||||||
@@ -1541,7 +1505,9 @@ static size_t ZSTDv01_decodeLiteralsBlock(void* ctx,
|
|||||||
size_t rleSize = litbp.origSize;
|
size_t rleSize = litbp.origSize;
|
||||||
if (rleSize>maxDstSize) return ERROR(dstSize_tooSmall);
|
if (rleSize>maxDstSize) return ERROR(dstSize_tooSmall);
|
||||||
if (!srcSize) return ERROR(srcSize_wrong);
|
if (!srcSize) return ERROR(srcSize_wrong);
|
||||||
|
if (rleSize > 0) {
|
||||||
memset(oend - rleSize, *ip, rleSize);
|
memset(oend - rleSize, *ip, rleSize);
|
||||||
|
}
|
||||||
*litStart = oend - rleSize;
|
*litStart = oend - rleSize;
|
||||||
*litSize = rleSize;
|
*litSize = rleSize;
|
||||||
ip++;
|
ip++;
|
||||||
@@ -1755,20 +1721,26 @@ static size_t ZSTD_execSequence(BYTE* op,
|
|||||||
static const int dec32table[] = {0, 1, 2, 1, 4, 4, 4, 4}; /* added */
|
static const int dec32table[] = {0, 1, 2, 1, 4, 4, 4, 4}; /* added */
|
||||||
static const int dec64table[] = {8, 8, 8, 7, 8, 9,10,11}; /* subtracted */
|
static const int dec64table[] = {8, 8, 8, 7, 8, 9,10,11}; /* subtracted */
|
||||||
const BYTE* const ostart = op;
|
const BYTE* const ostart = op;
|
||||||
|
BYTE* const oLitEnd = op + sequence.litLength;
|
||||||
const size_t litLength = sequence.litLength;
|
const size_t litLength = sequence.litLength;
|
||||||
BYTE* const endMatch = op + litLength + sequence.matchLength; /* risk : address space overflow (32-bits) */
|
BYTE* const endMatch = op + litLength + sequence.matchLength; /* risk : address space overflow (32-bits) */
|
||||||
const BYTE* const litEnd = *litPtr + litLength;
|
const BYTE* const litEnd = *litPtr + litLength;
|
||||||
|
|
||||||
/* check */
|
/* checks */
|
||||||
|
size_t const seqLength = sequence.litLength + sequence.matchLength;
|
||||||
|
|
||||||
|
if (seqLength > (size_t)(oend - op)) return ERROR(dstSize_tooSmall);
|
||||||
|
if (sequence.litLength > (size_t)(litLimit - *litPtr)) return ERROR(corruption_detected);
|
||||||
|
/* Now we know there are no overflow in literal nor match lengths, can use pointer checks */
|
||||||
|
if (sequence.offset > (U32)(oLitEnd - base)) return ERROR(corruption_detected);
|
||||||
|
|
||||||
if (endMatch > oend) return ERROR(dstSize_tooSmall); /* overwrite beyond dst buffer */
|
if (endMatch > oend) return ERROR(dstSize_tooSmall); /* overwrite beyond dst buffer */
|
||||||
if (litEnd > litLimit) return ERROR(corruption_detected);
|
if (litEnd > litLimit) return ERROR(corruption_detected); /* overRead beyond lit buffer */
|
||||||
if (sequence.matchLength > (size_t)(*litPtr-op)) return ERROR(dstSize_tooSmall); /* overwrite literal segment */
|
if (sequence.matchLength > (size_t)(*litPtr-op)) return ERROR(dstSize_tooSmall); /* overwrite literal segment */
|
||||||
|
|
||||||
/* copy Literals */
|
/* copy Literals */
|
||||||
if (((size_t)(*litPtr - op) < 8) || ((size_t)(oend-litEnd) < 8) || (op+litLength > oend-8))
|
ZSTD_memmove(op, *litPtr, sequence.litLength); /* note : v0.1 seems to allow scenarios where output or input are close to end of buffer */
|
||||||
memmove(op, *litPtr, litLength); /* overwrite risk */
|
|
||||||
else
|
|
||||||
ZSTD_wildcopy(op, *litPtr, litLength);
|
|
||||||
op += litLength;
|
op += litLength;
|
||||||
*litPtr = litEnd; /* update for next sequence */
|
*litPtr = litEnd; /* update for next sequence */
|
||||||
|
|
||||||
@@ -1901,10 +1873,12 @@ static size_t ZSTD_decompressSequences(
|
|||||||
{
|
{
|
||||||
size_t lastLLSize = litEnd - litPtr;
|
size_t lastLLSize = litEnd - litPtr;
|
||||||
if (op+lastLLSize > oend) return ERROR(dstSize_tooSmall);
|
if (op+lastLLSize > oend) return ERROR(dstSize_tooSmall);
|
||||||
|
if (lastLLSize > 0) {
|
||||||
if (op != litPtr) memmove(op, litPtr, lastLLSize);
|
if (op != litPtr) memmove(op, litPtr, lastLLSize);
|
||||||
op += lastLLSize;
|
op += lastLLSize;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
return op-ostart;
|
return op-ostart;
|
||||||
}
|
}
|
||||||
@@ -2150,3 +2124,5 @@ size_t ZSTDv01_decompressContinue(ZSTDv01_Dctx* dctx, void* dst, size_t maxDstSi
|
|||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#endif /* USE_EXTERNAL_ZSTD */
|
||||||
|
|||||||
5
vendor/github.com/DataDog/zstd/zstd_v01.h
generated
vendored
5
vendor/github.com/DataDog/zstd/zstd_v01.h
generated
vendored
@@ -1,5 +1,6 @@
|
|||||||
|
#ifndef USE_EXTERNAL_ZSTD
|
||||||
/*
|
/*
|
||||||
* Copyright (c) 2016-present, Yann Collet, Facebook, Inc.
|
* Copyright (c) Yann Collet, Meta Platforms, Inc. and affiliates.
|
||||||
* All rights reserved.
|
* All rights reserved.
|
||||||
*
|
*
|
||||||
* This source code is licensed under both the BSD-style license (found in the
|
* This source code is licensed under both the BSD-style license (found in the
|
||||||
@@ -92,3 +93,5 @@ size_t ZSTDv01_decompressContinue(ZSTDv01_Dctx* dctx, void* dst, size_t maxDstSi
|
|||||||
#endif
|
#endif
|
||||||
|
|
||||||
#endif /* ZSTD_V01_H_28739879432 */
|
#endif /* ZSTD_V01_H_28739879432 */
|
||||||
|
|
||||||
|
#endif /* USE_EXTERNAL_ZSTD */
|
||||||
|
|||||||
106
vendor/github.com/DataDog/zstd/zstd_v02.c
generated
vendored
106
vendor/github.com/DataDog/zstd/zstd_v02.c
generated
vendored
@@ -1,5 +1,6 @@
|
|||||||
|
#ifndef USE_EXTERNAL_ZSTD
|
||||||
/*
|
/*
|
||||||
* Copyright (c) 2016-present, Yann Collet, Facebook, Inc.
|
* Copyright (c) Yann Collet, Meta Platforms, Inc. and affiliates.
|
||||||
* All rights reserved.
|
* All rights reserved.
|
||||||
*
|
*
|
||||||
* This source code is licensed under both the BSD-style license (found in the
|
* This source code is licensed under both the BSD-style license (found in the
|
||||||
@@ -28,7 +29,7 @@
|
|||||||
low-level memory access routines
|
low-level memory access routines
|
||||||
Copyright (C) 2013-2015, Yann Collet.
|
Copyright (C) 2013-2015, Yann Collet.
|
||||||
|
|
||||||
BSD 2-Clause License (http://www.opensource.org/licenses/bsd-license.php)
|
BSD 2-Clause License (https://opensource.org/licenses/bsd-license.php)
|
||||||
|
|
||||||
Redistribution and use in source and binary forms, with or without
|
Redistribution and use in source and binary forms, with or without
|
||||||
modification, are permitted provided that the following conditions are
|
modification, are permitted provided that the following conditions are
|
||||||
@@ -89,7 +90,11 @@ extern "C" {
|
|||||||
* Basic Types
|
* Basic Types
|
||||||
*****************************************************************/
|
*****************************************************************/
|
||||||
#if defined (__cplusplus) || (defined (__STDC_VERSION__) && (__STDC_VERSION__ >= 199901L) /* C99 */)
|
#if defined (__cplusplus) || (defined (__STDC_VERSION__) && (__STDC_VERSION__ >= 199901L) /* C99 */)
|
||||||
# include <stdint.h>
|
# if defined(_AIX)
|
||||||
|
# include <inttypes.h>
|
||||||
|
# else
|
||||||
|
# include <stdint.h> /* intptr_t */
|
||||||
|
# endif
|
||||||
typedef uint8_t BYTE;
|
typedef uint8_t BYTE;
|
||||||
typedef uint16_t U16;
|
typedef uint16_t U16;
|
||||||
typedef int16_t S16;
|
typedef int16_t S16;
|
||||||
@@ -111,27 +116,6 @@ extern "C" {
|
|||||||
/****************************************************************
|
/****************************************************************
|
||||||
* Memory I/O
|
* Memory I/O
|
||||||
*****************************************************************/
|
*****************************************************************/
|
||||||
/* MEM_FORCE_MEMORY_ACCESS
|
|
||||||
* By default, access to unaligned memory is controlled by `memcpy()`, which is safe and portable.
|
|
||||||
* Unfortunately, on some target/compiler combinations, the generated assembly is sub-optimal.
|
|
||||||
* The below switch allow to select different access method for improved performance.
|
|
||||||
* Method 0 (default) : use `memcpy()`. Safe and portable.
|
|
||||||
* Method 1 : `__packed` statement. It depends on compiler extension (ie, not portable).
|
|
||||||
* This method is safe if your compiler supports it, and *generally* as fast or faster than `memcpy`.
|
|
||||||
* Method 2 : direct access. This method is portable but violate C standard.
|
|
||||||
* It can generate buggy code on targets generating assembly depending on alignment.
|
|
||||||
* But in some circumstances, it's the only known way to get the most performance (ie GCC + ARMv6)
|
|
||||||
* See http://fastcompression.blogspot.fr/2015/08/accessing-unaligned-memory.html for details.
|
|
||||||
* Prefer these methods in priority order (0 > 1 > 2)
|
|
||||||
*/
|
|
||||||
#ifndef MEM_FORCE_MEMORY_ACCESS /* can be defined externally, on command line for example */
|
|
||||||
# if defined(__GNUC__) && ( defined(__ARM_ARCH_6__) || defined(__ARM_ARCH_6J__) || defined(__ARM_ARCH_6K__) || defined(__ARM_ARCH_6Z__) || defined(__ARM_ARCH_6ZK__) || defined(__ARM_ARCH_6T2__) )
|
|
||||||
# define MEM_FORCE_MEMORY_ACCESS 2
|
|
||||||
# elif (defined(__INTEL_COMPILER) && !defined(WIN32)) || \
|
|
||||||
(defined(__GNUC__) && ( defined(__ARM_ARCH_7__) || defined(__ARM_ARCH_7A__) || defined(__ARM_ARCH_7R__) || defined(__ARM_ARCH_7M__) || defined(__ARM_ARCH_7S__) ))
|
|
||||||
# define MEM_FORCE_MEMORY_ACCESS 1
|
|
||||||
# endif
|
|
||||||
#endif
|
|
||||||
|
|
||||||
MEM_STATIC unsigned MEM_32bits(void) { return sizeof(void*)==4; }
|
MEM_STATIC unsigned MEM_32bits(void) { return sizeof(void*)==4; }
|
||||||
MEM_STATIC unsigned MEM_64bits(void) { return sizeof(void*)==8; }
|
MEM_STATIC unsigned MEM_64bits(void) { return sizeof(void*)==8; }
|
||||||
@@ -142,33 +126,6 @@ MEM_STATIC unsigned MEM_isLittleEndian(void)
|
|||||||
return one.c[0];
|
return one.c[0];
|
||||||
}
|
}
|
||||||
|
|
||||||
#if defined(MEM_FORCE_MEMORY_ACCESS) && (MEM_FORCE_MEMORY_ACCESS==2)
|
|
||||||
|
|
||||||
/* violates C standard on structure alignment.
|
|
||||||
Only use if no other choice to achieve best performance on target platform */
|
|
||||||
MEM_STATIC U16 MEM_read16(const void* memPtr) { return *(const U16*) memPtr; }
|
|
||||||
MEM_STATIC U32 MEM_read32(const void* memPtr) { return *(const U32*) memPtr; }
|
|
||||||
MEM_STATIC U64 MEM_read64(const void* memPtr) { return *(const U64*) memPtr; }
|
|
||||||
|
|
||||||
MEM_STATIC void MEM_write16(void* memPtr, U16 value) { *(U16*)memPtr = value; }
|
|
||||||
|
|
||||||
#elif defined(MEM_FORCE_MEMORY_ACCESS) && (MEM_FORCE_MEMORY_ACCESS==1)
|
|
||||||
|
|
||||||
/* __pack instructions are safer, but compiler specific, hence potentially problematic for some compilers */
|
|
||||||
/* currently only defined for gcc and icc */
|
|
||||||
typedef union { U16 u16; U32 u32; U64 u64; } __attribute__((packed)) unalign;
|
|
||||||
|
|
||||||
MEM_STATIC U16 MEM_read16(const void* ptr) { return ((const unalign*)ptr)->u16; }
|
|
||||||
MEM_STATIC U32 MEM_read32(const void* ptr) { return ((const unalign*)ptr)->u32; }
|
|
||||||
MEM_STATIC U64 MEM_read64(const void* ptr) { return ((const unalign*)ptr)->u64; }
|
|
||||||
|
|
||||||
MEM_STATIC void MEM_write16(void* memPtr, U16 value) { ((unalign*)memPtr)->u16 = value; }
|
|
||||||
|
|
||||||
#else
|
|
||||||
|
|
||||||
/* default method, safe and standard.
|
|
||||||
can sometimes prove slower */
|
|
||||||
|
|
||||||
MEM_STATIC U16 MEM_read16(const void* memPtr)
|
MEM_STATIC U16 MEM_read16(const void* memPtr)
|
||||||
{
|
{
|
||||||
U16 val; memcpy(&val, memPtr, sizeof(val)); return val;
|
U16 val; memcpy(&val, memPtr, sizeof(val)); return val;
|
||||||
@@ -189,9 +146,6 @@ MEM_STATIC void MEM_write16(void* memPtr, U16 value)
|
|||||||
memcpy(memPtr, &value, sizeof(value));
|
memcpy(memPtr, &value, sizeof(value));
|
||||||
}
|
}
|
||||||
|
|
||||||
#endif // MEM_FORCE_MEMORY_ACCESS
|
|
||||||
|
|
||||||
|
|
||||||
MEM_STATIC U16 MEM_readLE16(const void* memPtr)
|
MEM_STATIC U16 MEM_readLE16(const void* memPtr)
|
||||||
{
|
{
|
||||||
if (MEM_isLittleEndian())
|
if (MEM_isLittleEndian())
|
||||||
@@ -268,7 +222,7 @@ MEM_STATIC size_t MEM_readLEST(const void* memPtr)
|
|||||||
header file (to include)
|
header file (to include)
|
||||||
Copyright (C) 2013-2015, Yann Collet.
|
Copyright (C) 2013-2015, Yann Collet.
|
||||||
|
|
||||||
BSD 2-Clause License (http://www.opensource.org/licenses/bsd-license.php)
|
BSD 2-Clause License (https://opensource.org/licenses/bsd-license.php)
|
||||||
|
|
||||||
Redistribution and use in source and binary forms, with or without
|
Redistribution and use in source and binary forms, with or without
|
||||||
modification, are permitted provided that the following conditions are
|
modification, are permitted provided that the following conditions are
|
||||||
@@ -349,9 +303,8 @@ MEM_STATIC size_t BIT_readBitsFast(BIT_DStream_t* bitD, unsigned nbBits);
|
|||||||
MEM_STATIC unsigned BIT_highbit32 (U32 val)
|
MEM_STATIC unsigned BIT_highbit32 (U32 val)
|
||||||
{
|
{
|
||||||
# if defined(_MSC_VER) /* Visual */
|
# if defined(_MSC_VER) /* Visual */
|
||||||
unsigned long r=0;
|
unsigned long r;
|
||||||
_BitScanReverse ( &r, val );
|
return _BitScanReverse(&r, val) ? (unsigned)r : 0;
|
||||||
return (unsigned) r;
|
|
||||||
# elif defined(__GNUC__) && (__GNUC__ >= 3) /* Use GCC Intrinsic */
|
# elif defined(__GNUC__) && (__GNUC__ >= 3) /* Use GCC Intrinsic */
|
||||||
return __builtin_clz (val) ^ 31;
|
return __builtin_clz (val) ^ 31;
|
||||||
# else /* Software version */
|
# else /* Software version */
|
||||||
@@ -433,7 +386,7 @@ MEM_STATIC size_t BIT_lookBits(BIT_DStream_t* bitD, U32 nbBits)
|
|||||||
}
|
}
|
||||||
|
|
||||||
/*! BIT_lookBitsFast :
|
/*! BIT_lookBitsFast :
|
||||||
* unsafe version; only works only if nbBits >= 1 */
|
* unsafe version; only works if nbBits >= 1 */
|
||||||
MEM_STATIC size_t BIT_lookBitsFast(BIT_DStream_t* bitD, U32 nbBits)
|
MEM_STATIC size_t BIT_lookBitsFast(BIT_DStream_t* bitD, U32 nbBits)
|
||||||
{
|
{
|
||||||
const U32 bitMask = sizeof(bitD->bitContainer)*8 - 1;
|
const U32 bitMask = sizeof(bitD->bitContainer)*8 - 1;
|
||||||
@@ -453,7 +406,7 @@ MEM_STATIC size_t BIT_readBits(BIT_DStream_t* bitD, U32 nbBits)
|
|||||||
}
|
}
|
||||||
|
|
||||||
/*!BIT_readBitsFast :
|
/*!BIT_readBitsFast :
|
||||||
* unsafe version; only works only if nbBits >= 1 */
|
* unsafe version; only works if nbBits >= 1 */
|
||||||
MEM_STATIC size_t BIT_readBitsFast(BIT_DStream_t* bitD, U32 nbBits)
|
MEM_STATIC size_t BIT_readBitsFast(BIT_DStream_t* bitD, U32 nbBits)
|
||||||
{
|
{
|
||||||
size_t value = BIT_lookBitsFast(bitD, nbBits);
|
size_t value = BIT_lookBitsFast(bitD, nbBits);
|
||||||
@@ -510,7 +463,7 @@ MEM_STATIC unsigned BIT_endOfDStream(const BIT_DStream_t* DStream)
|
|||||||
Error codes and messages
|
Error codes and messages
|
||||||
Copyright (C) 2013-2015, Yann Collet
|
Copyright (C) 2013-2015, Yann Collet
|
||||||
|
|
||||||
BSD 2-Clause License (http://www.opensource.org/licenses/bsd-license.php)
|
BSD 2-Clause License (https://opensource.org/licenses/bsd-license.php)
|
||||||
|
|
||||||
Redistribution and use in source and binary forms, with or without
|
Redistribution and use in source and binary forms, with or without
|
||||||
modification, are permitted provided that the following conditions are
|
modification, are permitted provided that the following conditions are
|
||||||
@@ -609,7 +562,7 @@ typedef unsigned FSE_DTable; /* don't allocate that. It's just a way to be mor
|
|||||||
header file for static linking (only)
|
header file for static linking (only)
|
||||||
Copyright (C) 2013-2015, Yann Collet
|
Copyright (C) 2013-2015, Yann Collet
|
||||||
|
|
||||||
BSD 2-Clause License (http://www.opensource.org/licenses/bsd-license.php)
|
BSD 2-Clause License (https://opensource.org/licenses/bsd-license.php)
|
||||||
|
|
||||||
Redistribution and use in source and binary forms, with or without
|
Redistribution and use in source and binary forms, with or without
|
||||||
modification, are permitted provided that the following conditions are
|
modification, are permitted provided that the following conditions are
|
||||||
@@ -753,7 +706,7 @@ MEM_STATIC unsigned FSE_endOfDState(const FSE_DState_t* DStatePtr)
|
|||||||
header file for static linking (only)
|
header file for static linking (only)
|
||||||
Copyright (C) 2013-2015, Yann Collet
|
Copyright (C) 2013-2015, Yann Collet
|
||||||
|
|
||||||
BSD 2-Clause License (http://www.opensource.org/licenses/bsd-license.php)
|
BSD 2-Clause License (https://opensource.org/licenses/bsd-license.php)
|
||||||
|
|
||||||
Redistribution and use in source and binary forms, with or without
|
Redistribution and use in source and binary forms, with or without
|
||||||
modification, are permitted provided that the following conditions are
|
modification, are permitted provided that the following conditions are
|
||||||
@@ -822,7 +775,7 @@ static size_t HUF_decompress4X6 (void* dst, size_t dstSize, const void* cSrc, si
|
|||||||
Header File
|
Header File
|
||||||
Copyright (C) 2014-2015, Yann Collet.
|
Copyright (C) 2014-2015, Yann Collet.
|
||||||
|
|
||||||
BSD 2-Clause License (http://www.opensource.org/licenses/bsd-license.php)
|
BSD 2-Clause License (https://opensource.org/licenses/bsd-license.php)
|
||||||
|
|
||||||
Redistribution and use in source and binary forms, with or without
|
Redistribution and use in source and binary forms, with or without
|
||||||
modification, are permitted provided that the following conditions are
|
modification, are permitted provided that the following conditions are
|
||||||
@@ -882,7 +835,7 @@ typedef struct ZSTD_CCtx_s ZSTD_CCtx; /* incomplete type */
|
|||||||
Header File for static linking only
|
Header File for static linking only
|
||||||
Copyright (C) 2014-2015, Yann Collet.
|
Copyright (C) 2014-2015, Yann Collet.
|
||||||
|
|
||||||
BSD 2-Clause License (http://www.opensource.org/licenses/bsd-license.php)
|
BSD 2-Clause License (https://opensource.org/licenses/bsd-license.php)
|
||||||
|
|
||||||
Redistribution and use in source and binary forms, with or without
|
Redistribution and use in source and binary forms, with or without
|
||||||
modification, are permitted provided that the following conditions are
|
modification, are permitted provided that the following conditions are
|
||||||
@@ -946,7 +899,7 @@ typedef struct ZSTD_DCtx_s ZSTD_DCtx;
|
|||||||
FSE : Finite State Entropy coder
|
FSE : Finite State Entropy coder
|
||||||
Copyright (C) 2013-2015, Yann Collet.
|
Copyright (C) 2013-2015, Yann Collet.
|
||||||
|
|
||||||
BSD 2-Clause License (http://www.opensource.org/licenses/bsd-license.php)
|
BSD 2-Clause License (https://opensource.org/licenses/bsd-license.php)
|
||||||
|
|
||||||
Redistribution and use in source and binary forms, with or without
|
Redistribution and use in source and binary forms, with or without
|
||||||
modification, are permitted provided that the following conditions are
|
modification, are permitted provided that the following conditions are
|
||||||
@@ -1450,7 +1403,7 @@ static size_t FSE_decompress(void* dst, size_t maxDstSize, const void* cSrc, siz
|
|||||||
Huff0 : Huffman coder, part of New Generation Entropy library
|
Huff0 : Huffman coder, part of New Generation Entropy library
|
||||||
Copyright (C) 2013-2015, Yann Collet.
|
Copyright (C) 2013-2015, Yann Collet.
|
||||||
|
|
||||||
BSD 2-Clause License (http://www.opensource.org/licenses/bsd-license.php)
|
BSD 2-Clause License (https://opensource.org/licenses/bsd-license.php)
|
||||||
|
|
||||||
Redistribution and use in source and binary forms, with or without
|
Redistribution and use in source and binary forms, with or without
|
||||||
modification, are permitted provided that the following conditions are
|
modification, are permitted provided that the following conditions are
|
||||||
@@ -2609,7 +2562,7 @@ static size_t HUF_decompress (void* dst, size_t dstSize, const void* cSrc, size_
|
|||||||
zstd - standard compression library
|
zstd - standard compression library
|
||||||
Copyright (C) 2014-2015, Yann Collet.
|
Copyright (C) 2014-2015, Yann Collet.
|
||||||
|
|
||||||
BSD 2-Clause License (http://www.opensource.org/licenses/bsd-license.php)
|
BSD 2-Clause License (https://opensource.org/licenses/bsd-license.php)
|
||||||
|
|
||||||
Redistribution and use in source and binary forms, with or without
|
Redistribution and use in source and binary forms, with or without
|
||||||
modification, are permitted provided that the following conditions are
|
modification, are permitted provided that the following conditions are
|
||||||
@@ -2836,7 +2789,9 @@ static size_t ZSTD_getcBlockSize(const void* src, size_t srcSize, blockPropertie
|
|||||||
static size_t ZSTD_copyUncompressedBlock(void* dst, size_t maxDstSize, const void* src, size_t srcSize)
|
static size_t ZSTD_copyUncompressedBlock(void* dst, size_t maxDstSize, const void* src, size_t srcSize)
|
||||||
{
|
{
|
||||||
if (srcSize > maxDstSize) return ERROR(dstSize_tooSmall);
|
if (srcSize > maxDstSize) return ERROR(dstSize_tooSmall);
|
||||||
|
if (srcSize > 0) {
|
||||||
memcpy(dst, src, srcSize);
|
memcpy(dst, src, srcSize);
|
||||||
|
}
|
||||||
return srcSize;
|
return srcSize;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -3112,12 +3067,19 @@ static size_t ZSTD_execSequence(BYTE* op,
|
|||||||
const BYTE* const litEnd = *litPtr + sequence.litLength;
|
const BYTE* const litEnd = *litPtr + sequence.litLength;
|
||||||
|
|
||||||
/* checks */
|
/* checks */
|
||||||
if (oLitEnd > oend_8) return ERROR(dstSize_tooSmall); /* last match must start at a minimum distance of 8 from oend */
|
size_t const seqLength = sequence.litLength + sequence.matchLength;
|
||||||
|
|
||||||
|
if (seqLength > (size_t)(oend - op)) return ERROR(dstSize_tooSmall);
|
||||||
|
if (sequence.litLength > (size_t)(litLimit - *litPtr)) return ERROR(corruption_detected);
|
||||||
|
/* Now we know there are no overflow in literal nor match lengths, can use the pointer check */
|
||||||
|
if (oLitEnd > oend_8) return ERROR(dstSize_tooSmall);
|
||||||
|
if (sequence.offset > (U32)(oLitEnd - base)) return ERROR(corruption_detected);
|
||||||
|
|
||||||
if (oMatchEnd > oend) return ERROR(dstSize_tooSmall); /* overwrite beyond dst buffer */
|
if (oMatchEnd > oend) return ERROR(dstSize_tooSmall); /* overwrite beyond dst buffer */
|
||||||
if (litEnd > litLimit) return ERROR(corruption_detected); /* overRead beyond lit buffer */
|
if (litEnd > litLimit) return ERROR(corruption_detected); /* overRead beyond lit buffer */
|
||||||
|
|
||||||
/* copy Literals */
|
/* copy Literals */
|
||||||
ZSTD_wildcopy(op, *litPtr, sequence.litLength); /* note : oLitEnd <= oend-8 : no risk of overwrite beyond oend */
|
ZSTD_wildcopy(op, *litPtr, (ptrdiff_t)sequence.litLength); /* note : oLitEnd <= oend-8 : no risk of overwrite beyond oend */
|
||||||
op = oLitEnd;
|
op = oLitEnd;
|
||||||
*litPtr = litEnd; /* update for next sequence */
|
*litPtr = litEnd; /* update for next sequence */
|
||||||
|
|
||||||
@@ -3229,10 +3191,12 @@ static size_t ZSTD_decompressSequences(
|
|||||||
size_t lastLLSize = litEnd - litPtr;
|
size_t lastLLSize = litEnd - litPtr;
|
||||||
if (litPtr > litEnd) return ERROR(corruption_detected);
|
if (litPtr > litEnd) return ERROR(corruption_detected);
|
||||||
if (op+lastLLSize > oend) return ERROR(dstSize_tooSmall);
|
if (op+lastLLSize > oend) return ERROR(dstSize_tooSmall);
|
||||||
|
if (lastLLSize > 0) {
|
||||||
if (op != litPtr) memmove(op, litPtr, lastLLSize);
|
if (op != litPtr) memmove(op, litPtr, lastLLSize);
|
||||||
op += lastLLSize;
|
op += lastLLSize;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
return op-ostart;
|
return op-ostart;
|
||||||
}
|
}
|
||||||
@@ -3512,3 +3476,5 @@ size_t ZSTDv02_decompressContinue(ZSTDv02_Dctx* dctx, void* dst, size_t maxDstSi
|
|||||||
{
|
{
|
||||||
return ZSTD_decompressContinue((ZSTD_DCtx*)dctx, dst, maxDstSize, src, srcSize);
|
return ZSTD_decompressContinue((ZSTD_DCtx*)dctx, dst, maxDstSize, src, srcSize);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#endif /* USE_EXTERNAL_ZSTD */
|
||||||
|
|||||||
5
vendor/github.com/DataDog/zstd/zstd_v02.h
generated
vendored
5
vendor/github.com/DataDog/zstd/zstd_v02.h
generated
vendored
@@ -1,5 +1,6 @@
|
|||||||
|
#ifndef USE_EXTERNAL_ZSTD
|
||||||
/*
|
/*
|
||||||
* Copyright (c) 2016-present, Yann Collet, Facebook, Inc.
|
* Copyright (c) Yann Collet, Meta Platforms, Inc. and affiliates.
|
||||||
* All rights reserved.
|
* All rights reserved.
|
||||||
*
|
*
|
||||||
* This source code is licensed under both the BSD-style license (found in the
|
* This source code is licensed under both the BSD-style license (found in the
|
||||||
@@ -91,3 +92,5 @@ size_t ZSTDv02_decompressContinue(ZSTDv02_Dctx* dctx, void* dst, size_t maxDstSi
|
|||||||
#endif
|
#endif
|
||||||
|
|
||||||
#endif /* ZSTD_V02_H_4174539423 */
|
#endif /* ZSTD_V02_H_4174539423 */
|
||||||
|
|
||||||
|
#endif /* USE_EXTERNAL_ZSTD */
|
||||||
|
|||||||
110
vendor/github.com/DataDog/zstd/zstd_v03.c
generated
vendored
110
vendor/github.com/DataDog/zstd/zstd_v03.c
generated
vendored
@@ -1,5 +1,6 @@
|
|||||||
|
#ifndef USE_EXTERNAL_ZSTD
|
||||||
/*
|
/*
|
||||||
* Copyright (c) 2016-present, Yann Collet, Facebook, Inc.
|
* Copyright (c) Yann Collet, Meta Platforms, Inc. and affiliates.
|
||||||
* All rights reserved.
|
* All rights reserved.
|
||||||
*
|
*
|
||||||
* This source code is licensed under both the BSD-style license (found in the
|
* This source code is licensed under both the BSD-style license (found in the
|
||||||
@@ -29,7 +30,7 @@
|
|||||||
low-level memory access routines
|
low-level memory access routines
|
||||||
Copyright (C) 2013-2015, Yann Collet.
|
Copyright (C) 2013-2015, Yann Collet.
|
||||||
|
|
||||||
BSD 2-Clause License (http://www.opensource.org/licenses/bsd-license.php)
|
BSD 2-Clause License (https://opensource.org/licenses/bsd-license.php)
|
||||||
|
|
||||||
Redistribution and use in source and binary forms, with or without
|
Redistribution and use in source and binary forms, with or without
|
||||||
modification, are permitted provided that the following conditions are
|
modification, are permitted provided that the following conditions are
|
||||||
@@ -90,7 +91,11 @@ extern "C" {
|
|||||||
* Basic Types
|
* Basic Types
|
||||||
*****************************************************************/
|
*****************************************************************/
|
||||||
#if defined (__cplusplus) || (defined (__STDC_VERSION__) && (__STDC_VERSION__ >= 199901L) /* C99 */)
|
#if defined (__cplusplus) || (defined (__STDC_VERSION__) && (__STDC_VERSION__ >= 199901L) /* C99 */)
|
||||||
# include <stdint.h>
|
# if defined(_AIX)
|
||||||
|
# include <inttypes.h>
|
||||||
|
# else
|
||||||
|
# include <stdint.h> /* intptr_t */
|
||||||
|
# endif
|
||||||
typedef uint8_t BYTE;
|
typedef uint8_t BYTE;
|
||||||
typedef uint16_t U16;
|
typedef uint16_t U16;
|
||||||
typedef int16_t S16;
|
typedef int16_t S16;
|
||||||
@@ -112,27 +117,6 @@ extern "C" {
|
|||||||
/****************************************************************
|
/****************************************************************
|
||||||
* Memory I/O
|
* Memory I/O
|
||||||
*****************************************************************/
|
*****************************************************************/
|
||||||
/* MEM_FORCE_MEMORY_ACCESS
|
|
||||||
* By default, access to unaligned memory is controlled by `memcpy()`, which is safe and portable.
|
|
||||||
* Unfortunately, on some target/compiler combinations, the generated assembly is sub-optimal.
|
|
||||||
* The below switch allow to select different access method for improved performance.
|
|
||||||
* Method 0 (default) : use `memcpy()`. Safe and portable.
|
|
||||||
* Method 1 : `__packed` statement. It depends on compiler extension (ie, not portable).
|
|
||||||
* This method is safe if your compiler supports it, and *generally* as fast or faster than `memcpy`.
|
|
||||||
* Method 2 : direct access. This method is portable but violate C standard.
|
|
||||||
* It can generate buggy code on targets generating assembly depending on alignment.
|
|
||||||
* But in some circumstances, it's the only known way to get the most performance (ie GCC + ARMv6)
|
|
||||||
* See http://fastcompression.blogspot.fr/2015/08/accessing-unaligned-memory.html for details.
|
|
||||||
* Prefer these methods in priority order (0 > 1 > 2)
|
|
||||||
*/
|
|
||||||
#ifndef MEM_FORCE_MEMORY_ACCESS /* can be defined externally, on command line for example */
|
|
||||||
# if defined(__GNUC__) && ( defined(__ARM_ARCH_6__) || defined(__ARM_ARCH_6J__) || defined(__ARM_ARCH_6K__) || defined(__ARM_ARCH_6Z__) || defined(__ARM_ARCH_6ZK__) || defined(__ARM_ARCH_6T2__) )
|
|
||||||
# define MEM_FORCE_MEMORY_ACCESS 2
|
|
||||||
# elif (defined(__INTEL_COMPILER) && !defined(WIN32)) || \
|
|
||||||
(defined(__GNUC__) && ( defined(__ARM_ARCH_7__) || defined(__ARM_ARCH_7A__) || defined(__ARM_ARCH_7R__) || defined(__ARM_ARCH_7M__) || defined(__ARM_ARCH_7S__) ))
|
|
||||||
# define MEM_FORCE_MEMORY_ACCESS 1
|
|
||||||
# endif
|
|
||||||
#endif
|
|
||||||
|
|
||||||
MEM_STATIC unsigned MEM_32bits(void) { return sizeof(void*)==4; }
|
MEM_STATIC unsigned MEM_32bits(void) { return sizeof(void*)==4; }
|
||||||
MEM_STATIC unsigned MEM_64bits(void) { return sizeof(void*)==8; }
|
MEM_STATIC unsigned MEM_64bits(void) { return sizeof(void*)==8; }
|
||||||
@@ -143,33 +127,6 @@ MEM_STATIC unsigned MEM_isLittleEndian(void)
|
|||||||
return one.c[0];
|
return one.c[0];
|
||||||
}
|
}
|
||||||
|
|
||||||
#if defined(MEM_FORCE_MEMORY_ACCESS) && (MEM_FORCE_MEMORY_ACCESS==2)
|
|
||||||
|
|
||||||
/* violates C standard on structure alignment.
|
|
||||||
Only use if no other choice to achieve best performance on target platform */
|
|
||||||
MEM_STATIC U16 MEM_read16(const void* memPtr) { return *(const U16*) memPtr; }
|
|
||||||
MEM_STATIC U32 MEM_read32(const void* memPtr) { return *(const U32*) memPtr; }
|
|
||||||
MEM_STATIC U64 MEM_read64(const void* memPtr) { return *(const U64*) memPtr; }
|
|
||||||
|
|
||||||
MEM_STATIC void MEM_write16(void* memPtr, U16 value) { *(U16*)memPtr = value; }
|
|
||||||
|
|
||||||
#elif defined(MEM_FORCE_MEMORY_ACCESS) && (MEM_FORCE_MEMORY_ACCESS==1)
|
|
||||||
|
|
||||||
/* __pack instructions are safer, but compiler specific, hence potentially problematic for some compilers */
|
|
||||||
/* currently only defined for gcc and icc */
|
|
||||||
typedef union { U16 u16; U32 u32; U64 u64; } __attribute__((packed)) unalign;
|
|
||||||
|
|
||||||
MEM_STATIC U16 MEM_read16(const void* ptr) { return ((const unalign*)ptr)->u16; }
|
|
||||||
MEM_STATIC U32 MEM_read32(const void* ptr) { return ((const unalign*)ptr)->u32; }
|
|
||||||
MEM_STATIC U64 MEM_read64(const void* ptr) { return ((const unalign*)ptr)->u64; }
|
|
||||||
|
|
||||||
MEM_STATIC void MEM_write16(void* memPtr, U16 value) { ((unalign*)memPtr)->u16 = value; }
|
|
||||||
|
|
||||||
#else
|
|
||||||
|
|
||||||
/* default method, safe and standard.
|
|
||||||
can sometimes prove slower */
|
|
||||||
|
|
||||||
MEM_STATIC U16 MEM_read16(const void* memPtr)
|
MEM_STATIC U16 MEM_read16(const void* memPtr)
|
||||||
{
|
{
|
||||||
U16 val; memcpy(&val, memPtr, sizeof(val)); return val;
|
U16 val; memcpy(&val, memPtr, sizeof(val)); return val;
|
||||||
@@ -190,10 +147,6 @@ MEM_STATIC void MEM_write16(void* memPtr, U16 value)
|
|||||||
memcpy(memPtr, &value, sizeof(value));
|
memcpy(memPtr, &value, sizeof(value));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
#endif // MEM_FORCE_MEMORY_ACCESS
|
|
||||||
|
|
||||||
|
|
||||||
MEM_STATIC U16 MEM_readLE16(const void* memPtr)
|
MEM_STATIC U16 MEM_readLE16(const void* memPtr)
|
||||||
{
|
{
|
||||||
if (MEM_isLittleEndian())
|
if (MEM_isLittleEndian())
|
||||||
@@ -270,7 +223,7 @@ MEM_STATIC size_t MEM_readLEST(const void* memPtr)
|
|||||||
header file (to include)
|
header file (to include)
|
||||||
Copyright (C) 2013-2015, Yann Collet.
|
Copyright (C) 2013-2015, Yann Collet.
|
||||||
|
|
||||||
BSD 2-Clause License (http://www.opensource.org/licenses/bsd-license.php)
|
BSD 2-Clause License (https://opensource.org/licenses/bsd-license.php)
|
||||||
|
|
||||||
Redistribution and use in source and binary forms, with or without
|
Redistribution and use in source and binary forms, with or without
|
||||||
modification, are permitted provided that the following conditions are
|
modification, are permitted provided that the following conditions are
|
||||||
@@ -352,9 +305,8 @@ MEM_STATIC size_t BIT_readBitsFast(BIT_DStream_t* bitD, unsigned nbBits);
|
|||||||
MEM_STATIC unsigned BIT_highbit32 (U32 val)
|
MEM_STATIC unsigned BIT_highbit32 (U32 val)
|
||||||
{
|
{
|
||||||
# if defined(_MSC_VER) /* Visual */
|
# if defined(_MSC_VER) /* Visual */
|
||||||
unsigned long r=0;
|
unsigned long r;
|
||||||
_BitScanReverse ( &r, val );
|
return _BitScanReverse(&r, val) ? (unsigned)r : 0;
|
||||||
return (unsigned) r;
|
|
||||||
# elif defined(__GNUC__) && (__GNUC__ >= 3) /* Use GCC Intrinsic */
|
# elif defined(__GNUC__) && (__GNUC__ >= 3) /* Use GCC Intrinsic */
|
||||||
return __builtin_clz (val) ^ 31;
|
return __builtin_clz (val) ^ 31;
|
||||||
# else /* Software version */
|
# else /* Software version */
|
||||||
@@ -435,7 +387,7 @@ MEM_STATIC size_t BIT_lookBits(BIT_DStream_t* bitD, U32 nbBits)
|
|||||||
}
|
}
|
||||||
|
|
||||||
/*! BIT_lookBitsFast :
|
/*! BIT_lookBitsFast :
|
||||||
* unsafe version; only works only if nbBits >= 1 */
|
* unsafe version; only works if nbBits >= 1 */
|
||||||
MEM_STATIC size_t BIT_lookBitsFast(BIT_DStream_t* bitD, U32 nbBits)
|
MEM_STATIC size_t BIT_lookBitsFast(BIT_DStream_t* bitD, U32 nbBits)
|
||||||
{
|
{
|
||||||
const U32 bitMask = sizeof(bitD->bitContainer)*8 - 1;
|
const U32 bitMask = sizeof(bitD->bitContainer)*8 - 1;
|
||||||
@@ -455,7 +407,7 @@ MEM_STATIC size_t BIT_readBits(BIT_DStream_t* bitD, U32 nbBits)
|
|||||||
}
|
}
|
||||||
|
|
||||||
/*!BIT_readBitsFast :
|
/*!BIT_readBitsFast :
|
||||||
* unsafe version; only works only if nbBits >= 1 */
|
* unsafe version; only works if nbBits >= 1 */
|
||||||
MEM_STATIC size_t BIT_readBitsFast(BIT_DStream_t* bitD, U32 nbBits)
|
MEM_STATIC size_t BIT_readBitsFast(BIT_DStream_t* bitD, U32 nbBits)
|
||||||
{
|
{
|
||||||
size_t value = BIT_lookBitsFast(bitD, nbBits);
|
size_t value = BIT_lookBitsFast(bitD, nbBits);
|
||||||
@@ -512,7 +464,7 @@ MEM_STATIC unsigned BIT_endOfDStream(const BIT_DStream_t* DStream)
|
|||||||
Error codes and messages
|
Error codes and messages
|
||||||
Copyright (C) 2013-2015, Yann Collet
|
Copyright (C) 2013-2015, Yann Collet
|
||||||
|
|
||||||
BSD 2-Clause License (http://www.opensource.org/licenses/bsd-license.php)
|
BSD 2-Clause License (https://opensource.org/licenses/bsd-license.php)
|
||||||
|
|
||||||
Redistribution and use in source and binary forms, with or without
|
Redistribution and use in source and binary forms, with or without
|
||||||
modification, are permitted provided that the following conditions are
|
modification, are permitted provided that the following conditions are
|
||||||
@@ -611,7 +563,7 @@ typedef unsigned FSE_DTable; /* don't allocate that. It's just a way to be mor
|
|||||||
header file for static linking (only)
|
header file for static linking (only)
|
||||||
Copyright (C) 2013-2015, Yann Collet
|
Copyright (C) 2013-2015, Yann Collet
|
||||||
|
|
||||||
BSD 2-Clause License (http://www.opensource.org/licenses/bsd-license.php)
|
BSD 2-Clause License (https://opensource.org/licenses/bsd-license.php)
|
||||||
|
|
||||||
Redistribution and use in source and binary forms, with or without
|
Redistribution and use in source and binary forms, with or without
|
||||||
modification, are permitted provided that the following conditions are
|
modification, are permitted provided that the following conditions are
|
||||||
@@ -755,7 +707,7 @@ MEM_STATIC unsigned FSE_endOfDState(const FSE_DState_t* DStatePtr)
|
|||||||
header file for static linking (only)
|
header file for static linking (only)
|
||||||
Copyright (C) 2013-2015, Yann Collet
|
Copyright (C) 2013-2015, Yann Collet
|
||||||
|
|
||||||
BSD 2-Clause License (http://www.opensource.org/licenses/bsd-license.php)
|
BSD 2-Clause License (https://opensource.org/licenses/bsd-license.php)
|
||||||
|
|
||||||
Redistribution and use in source and binary forms, with or without
|
Redistribution and use in source and binary forms, with or without
|
||||||
modification, are permitted provided that the following conditions are
|
modification, are permitted provided that the following conditions are
|
||||||
@@ -823,7 +775,7 @@ static size_t HUF_decompress4X4 (void* dst, size_t dstSize, const void* cSrc, si
|
|||||||
Header File
|
Header File
|
||||||
Copyright (C) 2014-2015, Yann Collet.
|
Copyright (C) 2014-2015, Yann Collet.
|
||||||
|
|
||||||
BSD 2-Clause License (http://www.opensource.org/licenses/bsd-license.php)
|
BSD 2-Clause License (https://opensource.org/licenses/bsd-license.php)
|
||||||
|
|
||||||
Redistribution and use in source and binary forms, with or without
|
Redistribution and use in source and binary forms, with or without
|
||||||
modification, are permitted provided that the following conditions are
|
modification, are permitted provided that the following conditions are
|
||||||
@@ -883,7 +835,7 @@ typedef struct ZSTD_CCtx_s ZSTD_CCtx; /* incomplete type */
|
|||||||
Header File for static linking only
|
Header File for static linking only
|
||||||
Copyright (C) 2014-2015, Yann Collet.
|
Copyright (C) 2014-2015, Yann Collet.
|
||||||
|
|
||||||
BSD 2-Clause License (http://www.opensource.org/licenses/bsd-license.php)
|
BSD 2-Clause License (https://opensource.org/licenses/bsd-license.php)
|
||||||
|
|
||||||
Redistribution and use in source and binary forms, with or without
|
Redistribution and use in source and binary forms, with or without
|
||||||
modification, are permitted provided that the following conditions are
|
modification, are permitted provided that the following conditions are
|
||||||
@@ -947,7 +899,7 @@ typedef struct ZSTD_DCtx_s ZSTD_DCtx;
|
|||||||
FSE : Finite State Entropy coder
|
FSE : Finite State Entropy coder
|
||||||
Copyright (C) 2013-2015, Yann Collet.
|
Copyright (C) 2013-2015, Yann Collet.
|
||||||
|
|
||||||
BSD 2-Clause License (http://www.opensource.org/licenses/bsd-license.php)
|
BSD 2-Clause License (https://opensource.org/licenses/bsd-license.php)
|
||||||
|
|
||||||
Redistribution and use in source and binary forms, with or without
|
Redistribution and use in source and binary forms, with or without
|
||||||
modification, are permitted provided that the following conditions are
|
modification, are permitted provided that the following conditions are
|
||||||
@@ -1451,7 +1403,7 @@ static size_t FSE_decompress(void* dst, size_t maxDstSize, const void* cSrc, siz
|
|||||||
Huff0 : Huffman coder, part of New Generation Entropy library
|
Huff0 : Huffman coder, part of New Generation Entropy library
|
||||||
Copyright (C) 2013-2015, Yann Collet.
|
Copyright (C) 2013-2015, Yann Collet.
|
||||||
|
|
||||||
BSD 2-Clause License (http://www.opensource.org/licenses/bsd-license.php)
|
BSD 2-Clause License (https://opensource.org/licenses/bsd-license.php)
|
||||||
|
|
||||||
Redistribution and use in source and binary forms, with or without
|
Redistribution and use in source and binary forms, with or without
|
||||||
modification, are permitted provided that the following conditions are
|
modification, are permitted provided that the following conditions are
|
||||||
@@ -2248,7 +2200,7 @@ static size_t HUF_decompress (void* dst, size_t dstSize, const void* cSrc, size_
|
|||||||
zstd - standard compression library
|
zstd - standard compression library
|
||||||
Copyright (C) 2014-2015, Yann Collet.
|
Copyright (C) 2014-2015, Yann Collet.
|
||||||
|
|
||||||
BSD 2-Clause License (http://www.opensource.org/licenses/bsd-license.php)
|
BSD 2-Clause License (https://opensource.org/licenses/bsd-license.php)
|
||||||
|
|
||||||
Redistribution and use in source and binary forms, with or without
|
Redistribution and use in source and binary forms, with or without
|
||||||
modification, are permitted provided that the following conditions are
|
modification, are permitted provided that the following conditions are
|
||||||
@@ -2477,7 +2429,9 @@ static size_t ZSTD_getcBlockSize(const void* src, size_t srcSize, blockPropertie
|
|||||||
static size_t ZSTD_copyUncompressedBlock(void* dst, size_t maxDstSize, const void* src, size_t srcSize)
|
static size_t ZSTD_copyUncompressedBlock(void* dst, size_t maxDstSize, const void* src, size_t srcSize)
|
||||||
{
|
{
|
||||||
if (srcSize > maxDstSize) return ERROR(dstSize_tooSmall);
|
if (srcSize > maxDstSize) return ERROR(dstSize_tooSmall);
|
||||||
|
if (srcSize > 0) {
|
||||||
memcpy(dst, src, srcSize);
|
memcpy(dst, src, srcSize);
|
||||||
|
}
|
||||||
return srcSize;
|
return srcSize;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -2753,18 +2707,24 @@ static size_t ZSTD_execSequence(BYTE* op,
|
|||||||
const BYTE* const litEnd = *litPtr + sequence.litLength;
|
const BYTE* const litEnd = *litPtr + sequence.litLength;
|
||||||
|
|
||||||
/* checks */
|
/* checks */
|
||||||
if (oLitEnd > oend_8) return ERROR(dstSize_tooSmall); /* last match must start at a minimum distance of 8 from oend */
|
size_t const seqLength = sequence.litLength + sequence.matchLength;
|
||||||
|
|
||||||
|
if (seqLength > (size_t)(oend - op)) return ERROR(dstSize_tooSmall);
|
||||||
|
if (sequence.litLength > (size_t)(litLimit - *litPtr)) return ERROR(corruption_detected);
|
||||||
|
/* Now we know there are no overflow in literal nor match lengths, can use pointer checks */
|
||||||
|
if (oLitEnd > oend_8) return ERROR(dstSize_tooSmall);
|
||||||
|
if (sequence.offset > (U32)(oLitEnd - base)) return ERROR(corruption_detected);
|
||||||
|
|
||||||
if (oMatchEnd > oend) return ERROR(dstSize_tooSmall); /* overwrite beyond dst buffer */
|
if (oMatchEnd > oend) return ERROR(dstSize_tooSmall); /* overwrite beyond dst buffer */
|
||||||
if (litEnd > litLimit) return ERROR(corruption_detected); /* overRead beyond lit buffer */
|
if (litEnd > litLimit) return ERROR(corruption_detected); /* overRead beyond lit buffer */
|
||||||
|
|
||||||
/* copy Literals */
|
/* copy Literals */
|
||||||
ZSTD_wildcopy(op, *litPtr, sequence.litLength); /* note : oLitEnd <= oend-8 : no risk of overwrite beyond oend */
|
ZSTD_wildcopy(op, *litPtr, (ptrdiff_t)sequence.litLength); /* note : oLitEnd <= oend-8 : no risk of overwrite beyond oend */
|
||||||
op = oLitEnd;
|
op = oLitEnd;
|
||||||
*litPtr = litEnd; /* update for next sequence */
|
*litPtr = litEnd; /* update for next sequence */
|
||||||
|
|
||||||
/* copy Match */
|
/* copy Match */
|
||||||
{
|
{ const BYTE* match = op - sequence.offset;
|
||||||
const BYTE* match = op - sequence.offset;
|
|
||||||
|
|
||||||
/* check */
|
/* check */
|
||||||
if (sequence.offset > (size_t)op) return ERROR(corruption_detected); /* address space overflow test (this test seems kept by clang optimizer) */
|
if (sequence.offset > (size_t)op) return ERROR(corruption_detected); /* address space overflow test (this test seems kept by clang optimizer) */
|
||||||
@@ -2870,10 +2830,12 @@ static size_t ZSTD_decompressSequences(
|
|||||||
size_t lastLLSize = litEnd - litPtr;
|
size_t lastLLSize = litEnd - litPtr;
|
||||||
if (litPtr > litEnd) return ERROR(corruption_detected);
|
if (litPtr > litEnd) return ERROR(corruption_detected);
|
||||||
if (op+lastLLSize > oend) return ERROR(dstSize_tooSmall);
|
if (op+lastLLSize > oend) return ERROR(dstSize_tooSmall);
|
||||||
|
if (lastLLSize > 0) {
|
||||||
if (op != litPtr) memmove(op, litPtr, lastLLSize);
|
if (op != litPtr) memmove(op, litPtr, lastLLSize);
|
||||||
op += lastLLSize;
|
op += lastLLSize;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
return op-ostart;
|
return op-ostart;
|
||||||
}
|
}
|
||||||
@@ -3154,3 +3116,5 @@ size_t ZSTDv03_decompressContinue(ZSTDv03_Dctx* dctx, void* dst, size_t maxDstSi
|
|||||||
{
|
{
|
||||||
return ZSTD_decompressContinue((ZSTD_DCtx*)dctx, dst, maxDstSize, src, srcSize);
|
return ZSTD_decompressContinue((ZSTD_DCtx*)dctx, dst, maxDstSize, src, srcSize);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#endif /* USE_EXTERNAL_ZSTD */
|
||||||
|
|||||||
5
vendor/github.com/DataDog/zstd/zstd_v03.h
generated
vendored
5
vendor/github.com/DataDog/zstd/zstd_v03.h
generated
vendored
@@ -1,5 +1,6 @@
|
|||||||
|
#ifndef USE_EXTERNAL_ZSTD
|
||||||
/*
|
/*
|
||||||
* Copyright (c) 2016-present, Yann Collet, Facebook, Inc.
|
* Copyright (c) Yann Collet, Meta Platforms, Inc. and affiliates.
|
||||||
* All rights reserved.
|
* All rights reserved.
|
||||||
*
|
*
|
||||||
* This source code is licensed under both the BSD-style license (found in the
|
* This source code is licensed under both the BSD-style license (found in the
|
||||||
@@ -91,3 +92,5 @@ size_t ZSTDv03_decompressContinue(ZSTDv03_Dctx* dctx, void* dst, size_t maxDstSi
|
|||||||
#endif
|
#endif
|
||||||
|
|
||||||
#endif /* ZSTD_V03_H_298734209782 */
|
#endif /* ZSTD_V03_H_298734209782 */
|
||||||
|
|
||||||
|
#endif /* USE_EXTERNAL_ZSTD */
|
||||||
|
|||||||
107
vendor/github.com/DataDog/zstd/zstd_v04.c
generated
vendored
107
vendor/github.com/DataDog/zstd/zstd_v04.c
generated
vendored
@@ -1,5 +1,6 @@
|
|||||||
|
#ifndef USE_EXTERNAL_ZSTD
|
||||||
/*
|
/*
|
||||||
* Copyright (c) 2016-present, Yann Collet, Facebook, Inc.
|
* Copyright (c) Yann Collet, Meta Platforms, Inc. and affiliates.
|
||||||
* All rights reserved.
|
* All rights reserved.
|
||||||
*
|
*
|
||||||
* This source code is licensed under both the BSD-style license (found in the
|
* This source code is licensed under both the BSD-style license (found in the
|
||||||
@@ -52,7 +53,11 @@ extern "C" {
|
|||||||
* Basic Types
|
* Basic Types
|
||||||
*****************************************************************/
|
*****************************************************************/
|
||||||
#if defined (__cplusplus) || (defined (__STDC_VERSION__) && (__STDC_VERSION__ >= 199901L) /* C99 */)
|
#if defined (__cplusplus) || (defined (__STDC_VERSION__) && (__STDC_VERSION__ >= 199901L) /* C99 */)
|
||||||
# include <stdint.h>
|
# if defined(_AIX)
|
||||||
|
# include <inttypes.h>
|
||||||
|
# else
|
||||||
|
# include <stdint.h> /* intptr_t */
|
||||||
|
# endif
|
||||||
typedef uint8_t BYTE;
|
typedef uint8_t BYTE;
|
||||||
typedef uint16_t U16;
|
typedef uint16_t U16;
|
||||||
typedef int16_t S16;
|
typedef int16_t S16;
|
||||||
@@ -83,27 +88,6 @@ extern "C" {
|
|||||||
/****************************************************************
|
/****************************************************************
|
||||||
* Memory I/O
|
* Memory I/O
|
||||||
*****************************************************************/
|
*****************************************************************/
|
||||||
/* MEM_FORCE_MEMORY_ACCESS
|
|
||||||
* By default, access to unaligned memory is controlled by `memcpy()`, which is safe and portable.
|
|
||||||
* Unfortunately, on some target/compiler combinations, the generated assembly is sub-optimal.
|
|
||||||
* The below switch allow to select different access method for improved performance.
|
|
||||||
* Method 0 (default) : use `memcpy()`. Safe and portable.
|
|
||||||
* Method 1 : `__packed` statement. It depends on compiler extension (ie, not portable).
|
|
||||||
* This method is safe if your compiler supports it, and *generally* as fast or faster than `memcpy`.
|
|
||||||
* Method 2 : direct access. This method is portable but violate C standard.
|
|
||||||
* It can generate buggy code on targets generating assembly depending on alignment.
|
|
||||||
* But in some circumstances, it's the only known way to get the most performance (ie GCC + ARMv6)
|
|
||||||
* See http://fastcompression.blogspot.fr/2015/08/accessing-unaligned-memory.html for details.
|
|
||||||
* Prefer these methods in priority order (0 > 1 > 2)
|
|
||||||
*/
|
|
||||||
#ifndef MEM_FORCE_MEMORY_ACCESS /* can be defined externally, on command line for example */
|
|
||||||
# if defined(__GNUC__) && ( defined(__ARM_ARCH_6__) || defined(__ARM_ARCH_6J__) || defined(__ARM_ARCH_6K__) || defined(__ARM_ARCH_6Z__) || defined(__ARM_ARCH_6ZK__) || defined(__ARM_ARCH_6T2__) )
|
|
||||||
# define MEM_FORCE_MEMORY_ACCESS 2
|
|
||||||
# elif (defined(__INTEL_COMPILER) && !defined(WIN32)) || \
|
|
||||||
(defined(__GNUC__) && ( defined(__ARM_ARCH_7__) || defined(__ARM_ARCH_7A__) || defined(__ARM_ARCH_7R__) || defined(__ARM_ARCH_7M__) || defined(__ARM_ARCH_7S__) ))
|
|
||||||
# define MEM_FORCE_MEMORY_ACCESS 1
|
|
||||||
# endif
|
|
||||||
#endif
|
|
||||||
|
|
||||||
MEM_STATIC unsigned MEM_32bits(void) { return sizeof(void*)==4; }
|
MEM_STATIC unsigned MEM_32bits(void) { return sizeof(void*)==4; }
|
||||||
MEM_STATIC unsigned MEM_64bits(void) { return sizeof(void*)==8; }
|
MEM_STATIC unsigned MEM_64bits(void) { return sizeof(void*)==8; }
|
||||||
@@ -114,33 +98,6 @@ MEM_STATIC unsigned MEM_isLittleEndian(void)
|
|||||||
return one.c[0];
|
return one.c[0];
|
||||||
}
|
}
|
||||||
|
|
||||||
#if defined(MEM_FORCE_MEMORY_ACCESS) && (MEM_FORCE_MEMORY_ACCESS==2)
|
|
||||||
|
|
||||||
/* violates C standard on structure alignment.
|
|
||||||
Only use if no other choice to achieve best performance on target platform */
|
|
||||||
MEM_STATIC U16 MEM_read16(const void* memPtr) { return *(const U16*) memPtr; }
|
|
||||||
MEM_STATIC U32 MEM_read32(const void* memPtr) { return *(const U32*) memPtr; }
|
|
||||||
MEM_STATIC U64 MEM_read64(const void* memPtr) { return *(const U64*) memPtr; }
|
|
||||||
|
|
||||||
MEM_STATIC void MEM_write16(void* memPtr, U16 value) { *(U16*)memPtr = value; }
|
|
||||||
|
|
||||||
#elif defined(MEM_FORCE_MEMORY_ACCESS) && (MEM_FORCE_MEMORY_ACCESS==1)
|
|
||||||
|
|
||||||
/* __pack instructions are safer, but compiler specific, hence potentially problematic for some compilers */
|
|
||||||
/* currently only defined for gcc and icc */
|
|
||||||
typedef union { U16 u16; U32 u32; U64 u64; } __attribute__((packed)) unalign;
|
|
||||||
|
|
||||||
MEM_STATIC U16 MEM_read16(const void* ptr) { return ((const unalign*)ptr)->u16; }
|
|
||||||
MEM_STATIC U32 MEM_read32(const void* ptr) { return ((const unalign*)ptr)->u32; }
|
|
||||||
MEM_STATIC U64 MEM_read64(const void* ptr) { return ((const unalign*)ptr)->u64; }
|
|
||||||
|
|
||||||
MEM_STATIC void MEM_write16(void* memPtr, U16 value) { ((unalign*)memPtr)->u16 = value; }
|
|
||||||
|
|
||||||
#else
|
|
||||||
|
|
||||||
/* default method, safe and standard.
|
|
||||||
can sometimes prove slower */
|
|
||||||
|
|
||||||
MEM_STATIC U16 MEM_read16(const void* memPtr)
|
MEM_STATIC U16 MEM_read16(const void* memPtr)
|
||||||
{
|
{
|
||||||
U16 val; memcpy(&val, memPtr, sizeof(val)); return val;
|
U16 val; memcpy(&val, memPtr, sizeof(val)); return val;
|
||||||
@@ -161,9 +118,6 @@ MEM_STATIC void MEM_write16(void* memPtr, U16 value)
|
|||||||
memcpy(memPtr, &value, sizeof(value));
|
memcpy(memPtr, &value, sizeof(value));
|
||||||
}
|
}
|
||||||
|
|
||||||
#endif // MEM_FORCE_MEMORY_ACCESS
|
|
||||||
|
|
||||||
|
|
||||||
MEM_STATIC U16 MEM_readLE16(const void* memPtr)
|
MEM_STATIC U16 MEM_readLE16(const void* memPtr)
|
||||||
{
|
{
|
||||||
if (MEM_isLittleEndian())
|
if (MEM_isLittleEndian())
|
||||||
@@ -541,7 +495,7 @@ If there is an error, the function will return an error code, which can be teste
|
|||||||
header file (to include)
|
header file (to include)
|
||||||
Copyright (C) 2013-2015, Yann Collet.
|
Copyright (C) 2013-2015, Yann Collet.
|
||||||
|
|
||||||
BSD 2-Clause License (http://www.opensource.org/licenses/bsd-license.php)
|
BSD 2-Clause License (https://opensource.org/licenses/bsd-license.php)
|
||||||
|
|
||||||
Redistribution and use in source and binary forms, with or without
|
Redistribution and use in source and binary forms, with or without
|
||||||
modification, are permitted provided that the following conditions are
|
modification, are permitted provided that the following conditions are
|
||||||
@@ -623,9 +577,8 @@ MEM_STATIC size_t BIT_readBitsFast(BIT_DStream_t* bitD, unsigned nbBits);
|
|||||||
MEM_STATIC unsigned BIT_highbit32 (U32 val)
|
MEM_STATIC unsigned BIT_highbit32 (U32 val)
|
||||||
{
|
{
|
||||||
# if defined(_MSC_VER) /* Visual */
|
# if defined(_MSC_VER) /* Visual */
|
||||||
unsigned long r=0;
|
unsigned long r;
|
||||||
_BitScanReverse ( &r, val );
|
return _BitScanReverse(&r, val) ? (unsigned)r : 0;
|
||||||
return (unsigned) r;
|
|
||||||
# elif defined(__GNUC__) && (__GNUC__ >= 3) /* Use GCC Intrinsic */
|
# elif defined(__GNUC__) && (__GNUC__ >= 3) /* Use GCC Intrinsic */
|
||||||
return __builtin_clz (val) ^ 31;
|
return __builtin_clz (val) ^ 31;
|
||||||
# else /* Software version */
|
# else /* Software version */
|
||||||
@@ -700,7 +653,7 @@ MEM_STATIC size_t BIT_lookBits(BIT_DStream_t* bitD, U32 nbBits)
|
|||||||
}
|
}
|
||||||
|
|
||||||
/*! BIT_lookBitsFast :
|
/*! BIT_lookBitsFast :
|
||||||
* unsafe version; only works only if nbBits >= 1 */
|
* unsafe version; only works if nbBits >= 1 */
|
||||||
MEM_STATIC size_t BIT_lookBitsFast(BIT_DStream_t* bitD, U32 nbBits)
|
MEM_STATIC size_t BIT_lookBitsFast(BIT_DStream_t* bitD, U32 nbBits)
|
||||||
{
|
{
|
||||||
const U32 bitMask = sizeof(bitD->bitContainer)*8 - 1;
|
const U32 bitMask = sizeof(bitD->bitContainer)*8 - 1;
|
||||||
@@ -720,7 +673,7 @@ MEM_STATIC size_t BIT_readBits(BIT_DStream_t* bitD, U32 nbBits)
|
|||||||
}
|
}
|
||||||
|
|
||||||
/*!BIT_readBitsFast :
|
/*!BIT_readBitsFast :
|
||||||
* unsafe version; only works only if nbBits >= 1 */
|
* unsafe version; only works if nbBits >= 1 */
|
||||||
MEM_STATIC size_t BIT_readBitsFast(BIT_DStream_t* bitD, U32 nbBits)
|
MEM_STATIC size_t BIT_readBitsFast(BIT_DStream_t* bitD, U32 nbBits)
|
||||||
{
|
{
|
||||||
size_t value = BIT_lookBitsFast(bitD, nbBits);
|
size_t value = BIT_lookBitsFast(bitD, nbBits);
|
||||||
@@ -781,7 +734,7 @@ MEM_STATIC unsigned BIT_endOfDStream(const BIT_DStream_t* DStream)
|
|||||||
header file for static linking (only)
|
header file for static linking (only)
|
||||||
Copyright (C) 2013-2015, Yann Collet
|
Copyright (C) 2013-2015, Yann Collet
|
||||||
|
|
||||||
BSD 2-Clause License (http://www.opensource.org/licenses/bsd-license.php)
|
BSD 2-Clause License (https://opensource.org/licenses/bsd-license.php)
|
||||||
|
|
||||||
Redistribution and use in source and binary forms, with or without
|
Redistribution and use in source and binary forms, with or without
|
||||||
modification, are permitted provided that the following conditions are
|
modification, are permitted provided that the following conditions are
|
||||||
@@ -930,7 +883,7 @@ MEM_STATIC unsigned FSE_endOfDState(const FSE_DState_t* DStatePtr)
|
|||||||
FSE : Finite State Entropy coder
|
FSE : Finite State Entropy coder
|
||||||
Copyright (C) 2013-2015, Yann Collet.
|
Copyright (C) 2013-2015, Yann Collet.
|
||||||
|
|
||||||
BSD 2-Clause License (http://www.opensource.org/licenses/bsd-license.php)
|
BSD 2-Clause License (https://opensource.org/licenses/bsd-license.php)
|
||||||
|
|
||||||
Redistribution and use in source and binary forms, with or without
|
Redistribution and use in source and binary forms, with or without
|
||||||
modification, are permitted provided that the following conditions are
|
modification, are permitted provided that the following conditions are
|
||||||
@@ -1436,7 +1389,7 @@ static size_t FSE_decompress(void* dst, size_t maxDstSize, const void* cSrc, siz
|
|||||||
header file
|
header file
|
||||||
Copyright (C) 2013-2015, Yann Collet.
|
Copyright (C) 2013-2015, Yann Collet.
|
||||||
|
|
||||||
BSD 2-Clause License (http://www.opensource.org/licenses/bsd-license.php)
|
BSD 2-Clause License (https://opensource.org/licenses/bsd-license.php)
|
||||||
|
|
||||||
Redistribution and use in source and binary forms, with or without
|
Redistribution and use in source and binary forms, with or without
|
||||||
modification, are permitted provided that the following conditions are
|
modification, are permitted provided that the following conditions are
|
||||||
@@ -1514,7 +1467,7 @@ static unsigned HUF_isError(size_t code); /* tells if a return value i
|
|||||||
header file for static linking (only)
|
header file for static linking (only)
|
||||||
Copyright (C) 2013-2015, Yann Collet
|
Copyright (C) 2013-2015, Yann Collet
|
||||||
|
|
||||||
BSD 2-Clause License (http://www.opensource.org/licenses/bsd-license.php)
|
BSD 2-Clause License (https://opensource.org/licenses/bsd-license.php)
|
||||||
|
|
||||||
Redistribution and use in source and binary forms, with or without
|
Redistribution and use in source and binary forms, with or without
|
||||||
modification, are permitted provided that the following conditions are
|
modification, are permitted provided that the following conditions are
|
||||||
@@ -1601,7 +1554,7 @@ static size_t HUF_decompress4X4_usingDTable(void* dst, size_t maxDstSize, const
|
|||||||
Huff0 : Huffman coder, part of New Generation Entropy library
|
Huff0 : Huffman coder, part of New Generation Entropy library
|
||||||
Copyright (C) 2013-2015, Yann Collet.
|
Copyright (C) 2013-2015, Yann Collet.
|
||||||
|
|
||||||
BSD 2-Clause License (http://www.opensource.org/licenses/bsd-license.php)
|
BSD 2-Clause License (https://opensource.org/licenses/bsd-license.php)
|
||||||
|
|
||||||
Redistribution and use in source and binary forms, with or without
|
Redistribution and use in source and binary forms, with or without
|
||||||
modification, are permitted provided that the following conditions are
|
modification, are permitted provided that the following conditions are
|
||||||
@@ -2401,7 +2354,7 @@ static size_t HUF_decompress (void* dst, size_t dstSize, const void* cSrc, size_
|
|||||||
zstd - decompression module fo v0.4 legacy format
|
zstd - decompression module fo v0.4 legacy format
|
||||||
Copyright (C) 2015-2016, Yann Collet.
|
Copyright (C) 2015-2016, Yann Collet.
|
||||||
|
|
||||||
BSD 2-Clause License (http://www.opensource.org/licenses/bsd-license.php)
|
BSD 2-Clause License (https://opensource.org/licenses/bsd-license.php)
|
||||||
|
|
||||||
Redistribution and use in source and binary forms, with or without
|
Redistribution and use in source and binary forms, with or without
|
||||||
modification, are permitted provided that the following conditions are
|
modification, are permitted provided that the following conditions are
|
||||||
@@ -2603,7 +2556,9 @@ static size_t ZSTD_getcBlockSize(const void* src, size_t srcSize, blockPropertie
|
|||||||
static size_t ZSTD_copyRawBlock(void* dst, size_t maxDstSize, const void* src, size_t srcSize)
|
static size_t ZSTD_copyRawBlock(void* dst, size_t maxDstSize, const void* src, size_t srcSize)
|
||||||
{
|
{
|
||||||
if (srcSize > maxDstSize) return ERROR(dstSize_tooSmall);
|
if (srcSize > maxDstSize) return ERROR(dstSize_tooSmall);
|
||||||
|
if (srcSize > 0) {
|
||||||
memcpy(dst, src, srcSize);
|
memcpy(dst, src, srcSize);
|
||||||
|
}
|
||||||
return srcSize;
|
return srcSize;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -2874,13 +2829,19 @@ static size_t ZSTD_execSequence(BYTE* op,
|
|||||||
const BYTE* const litEnd = *litPtr + sequence.litLength;
|
const BYTE* const litEnd = *litPtr + sequence.litLength;
|
||||||
const BYTE* match = oLitEnd - sequence.offset;
|
const BYTE* match = oLitEnd - sequence.offset;
|
||||||
|
|
||||||
/* check */
|
/* checks */
|
||||||
if (oLitEnd > oend_8) return ERROR(dstSize_tooSmall); /* last match must start at a minimum distance of 8 from oend */
|
size_t const seqLength = sequence.litLength + sequence.matchLength;
|
||||||
|
|
||||||
|
if (seqLength > (size_t)(oend - op)) return ERROR(dstSize_tooSmall);
|
||||||
|
if (sequence.litLength > (size_t)(litLimit - *litPtr)) return ERROR(corruption_detected);
|
||||||
|
/* Now we know there are no overflow in literal nor match lengths, can use pointer checks */
|
||||||
|
if (oLitEnd > oend_8) return ERROR(dstSize_tooSmall);
|
||||||
|
|
||||||
if (oMatchEnd > oend) return ERROR(dstSize_tooSmall); /* overwrite beyond dst buffer */
|
if (oMatchEnd > oend) return ERROR(dstSize_tooSmall); /* overwrite beyond dst buffer */
|
||||||
if (litEnd > litLimit) return ERROR(corruption_detected); /* risk read beyond lit buffer */
|
if (litEnd > litLimit) return ERROR(corruption_detected); /* overRead beyond lit buffer */
|
||||||
|
|
||||||
/* copy Literals */
|
/* copy Literals */
|
||||||
ZSTD_wildcopy(op, *litPtr, sequence.litLength); /* note : oLitEnd <= oend-8 : no risk of overwrite beyond oend */
|
ZSTD_wildcopy(op, *litPtr, (ptrdiff_t)sequence.litLength); /* note : oLitEnd <= oend-8 : no risk of overwrite beyond oend */
|
||||||
op = oLitEnd;
|
op = oLitEnd;
|
||||||
*litPtr = litEnd; /* update for next sequence */
|
*litPtr = litEnd; /* update for next sequence */
|
||||||
|
|
||||||
@@ -3008,10 +2969,12 @@ static size_t ZSTD_decompressSequences(
|
|||||||
size_t lastLLSize = litEnd - litPtr;
|
size_t lastLLSize = litEnd - litPtr;
|
||||||
if (litPtr > litEnd) return ERROR(corruption_detected);
|
if (litPtr > litEnd) return ERROR(corruption_detected);
|
||||||
if (op+lastLLSize > oend) return ERROR(dstSize_tooSmall);
|
if (op+lastLLSize > oend) return ERROR(dstSize_tooSmall);
|
||||||
|
if (lastLLSize > 0) {
|
||||||
if (op != litPtr) memcpy(op, litPtr, lastLLSize);
|
if (op != litPtr) memcpy(op, litPtr, lastLLSize);
|
||||||
op += lastLLSize;
|
op += lastLLSize;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
return op-ostart;
|
return op-ostart;
|
||||||
}
|
}
|
||||||
@@ -3279,7 +3242,7 @@ static void ZSTD_decompress_insertDictionary(ZSTD_DCtx* ctx, const void* dict, s
|
|||||||
Buffered version of Zstd compression library
|
Buffered version of Zstd compression library
|
||||||
Copyright (C) 2015, Yann Collet.
|
Copyright (C) 2015, Yann Collet.
|
||||||
|
|
||||||
BSD 2-Clause License (http://www.opensource.org/licenses/bsd-license.php)
|
BSD 2-Clause License (https://opensource.org/licenses/bsd-license.php)
|
||||||
|
|
||||||
Redistribution and use in source and binary forms, with or without
|
Redistribution and use in source and binary forms, with or without
|
||||||
modification, are permitted provided that the following conditions are
|
modification, are permitted provided that the following conditions are
|
||||||
@@ -3407,7 +3370,9 @@ static size_t ZBUFF_decompressWithDictionary(ZBUFF_DCtx* zbc, const void* src, s
|
|||||||
static size_t ZBUFF_limitCopy(void* dst, size_t maxDstSize, const void* src, size_t srcSize)
|
static size_t ZBUFF_limitCopy(void* dst, size_t maxDstSize, const void* src, size_t srcSize)
|
||||||
{
|
{
|
||||||
size_t length = MIN(maxDstSize, srcSize);
|
size_t length = MIN(maxDstSize, srcSize);
|
||||||
|
if (length > 0) {
|
||||||
memcpy(dst, src, length);
|
memcpy(dst, src, length);
|
||||||
|
}
|
||||||
return length;
|
return length;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -3639,3 +3604,5 @@ size_t ZBUFFv04_decompressContinue(ZBUFFv04_DCtx* dctx, void* dst, size_t* maxDs
|
|||||||
|
|
||||||
ZSTD_DCtx* ZSTDv04_createDCtx(void) { return ZSTD_createDCtx(); }
|
ZSTD_DCtx* ZSTDv04_createDCtx(void) { return ZSTD_createDCtx(); }
|
||||||
size_t ZSTDv04_freeDCtx(ZSTD_DCtx* dctx) { return ZSTD_freeDCtx(dctx); }
|
size_t ZSTDv04_freeDCtx(ZSTD_DCtx* dctx) { return ZSTD_freeDCtx(dctx); }
|
||||||
|
|
||||||
|
#endif /* USE_EXTERNAL_ZSTD */
|
||||||
|
|||||||
5
vendor/github.com/DataDog/zstd/zstd_v04.h
generated
vendored
5
vendor/github.com/DataDog/zstd/zstd_v04.h
generated
vendored
@@ -1,5 +1,6 @@
|
|||||||
|
#ifndef USE_EXTERNAL_ZSTD
|
||||||
/*
|
/*
|
||||||
* Copyright (c) 2016-present, Yann Collet, Facebook, Inc.
|
* Copyright (c) Yann Collet, Meta Platforms, Inc. and affiliates.
|
||||||
* All rights reserved.
|
* All rights reserved.
|
||||||
*
|
*
|
||||||
* This source code is licensed under both the BSD-style license (found in the
|
* This source code is licensed under both the BSD-style license (found in the
|
||||||
@@ -140,3 +141,5 @@ size_t ZBUFFv04_recommendedDOutSize(void);
|
|||||||
#endif
|
#endif
|
||||||
|
|
||||||
#endif /* ZSTD_V04_H_91868324769238 */
|
#endif /* ZSTD_V04_H_91868324769238 */
|
||||||
|
|
||||||
|
#endif /* USE_EXTERNAL_ZSTD */
|
||||||
|
|||||||
149
vendor/github.com/DataDog/zstd/zstd_v05.c
generated
vendored
149
vendor/github.com/DataDog/zstd/zstd_v05.c
generated
vendored
@@ -1,5 +1,6 @@
|
|||||||
|
#ifndef USE_EXTERNAL_ZSTD
|
||||||
/*
|
/*
|
||||||
* Copyright (c) 2016-present, Yann Collet, Facebook, Inc.
|
* Copyright (c) Yann Collet, Meta Platforms, Inc. and affiliates.
|
||||||
* All rights reserved.
|
* All rights reserved.
|
||||||
*
|
*
|
||||||
* This source code is licensed under both the BSD-style license (found in the
|
* This source code is licensed under both the BSD-style license (found in the
|
||||||
@@ -19,7 +20,7 @@
|
|||||||
low-level memory access routines
|
low-level memory access routines
|
||||||
Copyright (C) 2013-2015, Yann Collet.
|
Copyright (C) 2013-2015, Yann Collet.
|
||||||
|
|
||||||
BSD 2-Clause License (http://www.opensource.org/licenses/bsd-license.php)
|
BSD 2-Clause License (https://opensource.org/licenses/bsd-license.php)
|
||||||
|
|
||||||
Redistribution and use in source and binary forms, with or without
|
Redistribution and use in source and binary forms, with or without
|
||||||
modification, are permitted provided that the following conditions are
|
modification, are permitted provided that the following conditions are
|
||||||
@@ -80,7 +81,11 @@ extern "C" {
|
|||||||
* Basic Types
|
* Basic Types
|
||||||
*****************************************************************/
|
*****************************************************************/
|
||||||
#if defined (__cplusplus) || (defined (__STDC_VERSION__) && (__STDC_VERSION__ >= 199901L) /* C99 */)
|
#if defined (__cplusplus) || (defined (__STDC_VERSION__) && (__STDC_VERSION__ >= 199901L) /* C99 */)
|
||||||
# include <stdint.h>
|
# if defined(_AIX)
|
||||||
|
# include <inttypes.h>
|
||||||
|
# else
|
||||||
|
# include <stdint.h> /* intptr_t */
|
||||||
|
# endif
|
||||||
typedef uint8_t BYTE;
|
typedef uint8_t BYTE;
|
||||||
typedef uint16_t U16;
|
typedef uint16_t U16;
|
||||||
typedef int16_t S16;
|
typedef int16_t S16;
|
||||||
@@ -102,27 +107,6 @@ extern "C" {
|
|||||||
/*-**************************************************************
|
/*-**************************************************************
|
||||||
* Memory I/O
|
* Memory I/O
|
||||||
*****************************************************************/
|
*****************************************************************/
|
||||||
/* MEM_FORCE_MEMORY_ACCESS :
|
|
||||||
* By default, access to unaligned memory is controlled by `memcpy()`, which is safe and portable.
|
|
||||||
* Unfortunately, on some target/compiler combinations, the generated assembly is sub-optimal.
|
|
||||||
* The below switch allow to select different access method for improved performance.
|
|
||||||
* Method 0 (default) : use `memcpy()`. Safe and portable.
|
|
||||||
* Method 1 : `__packed` statement. It depends on compiler extension (ie, not portable).
|
|
||||||
* This method is safe if your compiler supports it, and *generally* as fast or faster than `memcpy`.
|
|
||||||
* Method 2 : direct access. This method is portable but violate C standard.
|
|
||||||
* It can generate buggy code on targets depending on alignment.
|
|
||||||
* In some circumstances, it's the only known way to get the most performance (ie GCC + ARMv6)
|
|
||||||
* See http://fastcompression.blogspot.fr/2015/08/accessing-unaligned-memory.html for details.
|
|
||||||
* Prefer these methods in priority order (0 > 1 > 2)
|
|
||||||
*/
|
|
||||||
#ifndef MEM_FORCE_MEMORY_ACCESS /* can be defined externally, on command line for example */
|
|
||||||
# if defined(__GNUC__) && ( defined(__ARM_ARCH_6__) || defined(__ARM_ARCH_6J__) || defined(__ARM_ARCH_6K__) || defined(__ARM_ARCH_6Z__) || defined(__ARM_ARCH_6ZK__) || defined(__ARM_ARCH_6T2__) )
|
|
||||||
# define MEM_FORCE_MEMORY_ACCESS 2
|
|
||||||
# elif (defined(__INTEL_COMPILER) && !defined(WIN32)) || \
|
|
||||||
(defined(__GNUC__) && ( defined(__ARM_ARCH_7__) || defined(__ARM_ARCH_7A__) || defined(__ARM_ARCH_7R__) || defined(__ARM_ARCH_7M__) || defined(__ARM_ARCH_7S__) ))
|
|
||||||
# define MEM_FORCE_MEMORY_ACCESS 1
|
|
||||||
# endif
|
|
||||||
#endif
|
|
||||||
|
|
||||||
MEM_STATIC unsigned MEM_32bits(void) { return sizeof(void*)==4; }
|
MEM_STATIC unsigned MEM_32bits(void) { return sizeof(void*)==4; }
|
||||||
MEM_STATIC unsigned MEM_64bits(void) { return sizeof(void*)==8; }
|
MEM_STATIC unsigned MEM_64bits(void) { return sizeof(void*)==8; }
|
||||||
@@ -133,37 +117,6 @@ MEM_STATIC unsigned MEM_isLittleEndian(void)
|
|||||||
return one.c[0];
|
return one.c[0];
|
||||||
}
|
}
|
||||||
|
|
||||||
#if defined(MEM_FORCE_MEMORY_ACCESS) && (MEM_FORCE_MEMORY_ACCESS==2)
|
|
||||||
|
|
||||||
/* violates C standard, by lying on structure alignment.
|
|
||||||
Only use if no other choice to achieve best performance on target platform */
|
|
||||||
MEM_STATIC U16 MEM_read16(const void* memPtr) { return *(const U16*) memPtr; }
|
|
||||||
MEM_STATIC U32 MEM_read32(const void* memPtr) { return *(const U32*) memPtr; }
|
|
||||||
MEM_STATIC U64 MEM_read64(const void* memPtr) { return *(const U64*) memPtr; }
|
|
||||||
|
|
||||||
MEM_STATIC void MEM_write16(void* memPtr, U16 value) { *(U16*)memPtr = value; }
|
|
||||||
MEM_STATIC void MEM_write32(void* memPtr, U32 value) { *(U32*)memPtr = value; }
|
|
||||||
MEM_STATIC void MEM_write64(void* memPtr, U64 value) { *(U64*)memPtr = value; }
|
|
||||||
|
|
||||||
#elif defined(MEM_FORCE_MEMORY_ACCESS) && (MEM_FORCE_MEMORY_ACCESS==1)
|
|
||||||
|
|
||||||
/* __pack instructions are safer, but compiler specific, hence potentially problematic for some compilers */
|
|
||||||
/* currently only defined for gcc and icc */
|
|
||||||
typedef union { U16 u16; U32 u32; U64 u64; size_t st; } __attribute__((packed)) unalign;
|
|
||||||
|
|
||||||
MEM_STATIC U16 MEM_read16(const void* ptr) { return ((const unalign*)ptr)->u16; }
|
|
||||||
MEM_STATIC U32 MEM_read32(const void* ptr) { return ((const unalign*)ptr)->u32; }
|
|
||||||
MEM_STATIC U64 MEM_read64(const void* ptr) { return ((const unalign*)ptr)->u64; }
|
|
||||||
|
|
||||||
MEM_STATIC void MEM_write16(void* memPtr, U16 value) { ((unalign*)memPtr)->u16 = value; }
|
|
||||||
MEM_STATIC void MEM_write32(void* memPtr, U32 value) { ((unalign*)memPtr)->u32 = value; }
|
|
||||||
MEM_STATIC void MEM_write64(void* memPtr, U64 value) { ((unalign*)memPtr)->u64 = value; }
|
|
||||||
|
|
||||||
#else
|
|
||||||
|
|
||||||
/* default method, safe and standard.
|
|
||||||
can sometimes prove slower */
|
|
||||||
|
|
||||||
MEM_STATIC U16 MEM_read16(const void* memPtr)
|
MEM_STATIC U16 MEM_read16(const void* memPtr)
|
||||||
{
|
{
|
||||||
U16 val; memcpy(&val, memPtr, sizeof(val)); return val;
|
U16 val; memcpy(&val, memPtr, sizeof(val)); return val;
|
||||||
@@ -194,9 +147,6 @@ MEM_STATIC void MEM_write64(void* memPtr, U64 value)
|
|||||||
memcpy(memPtr, &value, sizeof(value));
|
memcpy(memPtr, &value, sizeof(value));
|
||||||
}
|
}
|
||||||
|
|
||||||
#endif /* MEM_FORCE_MEMORY_ACCESS */
|
|
||||||
|
|
||||||
|
|
||||||
MEM_STATIC U16 MEM_readLE16(const void* memPtr)
|
MEM_STATIC U16 MEM_readLE16(const void* memPtr)
|
||||||
{
|
{
|
||||||
if (MEM_isLittleEndian())
|
if (MEM_isLittleEndian())
|
||||||
@@ -261,7 +211,7 @@ MEM_STATIC size_t MEM_readLEST(const void* memPtr)
|
|||||||
Header File for static linking only
|
Header File for static linking only
|
||||||
Copyright (C) 2014-2016, Yann Collet.
|
Copyright (C) 2014-2016, Yann Collet.
|
||||||
|
|
||||||
BSD 2-Clause License (http://www.opensource.org/licenses/bsd-license.php)
|
BSD 2-Clause License (https://opensource.org/licenses/bsd-license.php)
|
||||||
|
|
||||||
Redistribution and use in source and binary forms, with or without
|
Redistribution and use in source and binary forms, with or without
|
||||||
modification, are permitted provided that the following conditions are
|
modification, are permitted provided that the following conditions are
|
||||||
@@ -285,7 +235,7 @@ MEM_STATIC size_t MEM_readLEST(const void* memPtr)
|
|||||||
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||||
|
|
||||||
You can contact the author at :
|
You can contact the author at :
|
||||||
- zstd homepage : http://www.zstd.net
|
- zstd homepage : https://facebook.github.io/zstd
|
||||||
*/
|
*/
|
||||||
#ifndef ZSTD_STATIC_H
|
#ifndef ZSTD_STATIC_H
|
||||||
#define ZSTD_STATIC_H
|
#define ZSTD_STATIC_H
|
||||||
@@ -397,7 +347,7 @@ size_t ZSTDv05_decompressBlock(ZSTDv05_DCtx* dctx, void* dst, size_t dstCapacity
|
|||||||
Header File for include
|
Header File for include
|
||||||
Copyright (C) 2014-2016, Yann Collet.
|
Copyright (C) 2014-2016, Yann Collet.
|
||||||
|
|
||||||
BSD 2-Clause License (http://www.opensource.org/licenses/bsd-license.php)
|
BSD 2-Clause License (https://opensource.org/licenses/bsd-license.php)
|
||||||
|
|
||||||
Redistribution and use in source and binary forms, with or without
|
Redistribution and use in source and binary forms, with or without
|
||||||
modification, are permitted provided that the following conditions are
|
modification, are permitted provided that the following conditions are
|
||||||
@@ -484,7 +434,7 @@ static const size_t ZSTDv05_frameHeaderSize_min = 5;
|
|||||||
#define FSEv05_ENCODING_DYNAMIC 3
|
#define FSEv05_ENCODING_DYNAMIC 3
|
||||||
|
|
||||||
|
|
||||||
#define HufLog 12
|
#define ZSTD_HUFFDTABLE_CAPACITY_LOG 12
|
||||||
|
|
||||||
#define MIN_SEQUENCES_SIZE 1 /* nbSeq==0 */
|
#define MIN_SEQUENCES_SIZE 1 /* nbSeq==0 */
|
||||||
#define MIN_CBLOCK_SIZE (1 /*litCSize*/ + 1 /* RLE or RAW */ + MIN_SEQUENCES_SIZE /* nbSeq==0 */) /* for a non-null block */
|
#define MIN_CBLOCK_SIZE (1 /*litCSize*/ + 1 /* RLE or RAW */ + MIN_SEQUENCES_SIZE /* nbSeq==0 */) /* for a non-null block */
|
||||||
@@ -552,7 +502,7 @@ typedef struct {
|
|||||||
header file
|
header file
|
||||||
Copyright (C) 2013-2015, Yann Collet.
|
Copyright (C) 2013-2015, Yann Collet.
|
||||||
|
|
||||||
BSD 2-Clause License (http://www.opensource.org/licenses/bsd-license.php)
|
BSD 2-Clause License (https://opensource.org/licenses/bsd-license.php)
|
||||||
|
|
||||||
Redistribution and use in source and binary forms, with or without
|
Redistribution and use in source and binary forms, with or without
|
||||||
modification, are permitted provided that the following conditions are
|
modification, are permitted provided that the following conditions are
|
||||||
@@ -671,7 +621,7 @@ size_t FSEv05_decompress_usingDTable(void* dst, size_t dstCapacity, const void*
|
|||||||
header file (to include)
|
header file (to include)
|
||||||
Copyright (C) 2013-2016, Yann Collet.
|
Copyright (C) 2013-2016, Yann Collet.
|
||||||
|
|
||||||
BSD 2-Clause License (http://www.opensource.org/licenses/bsd-license.php)
|
BSD 2-Clause License (https://opensource.org/licenses/bsd-license.php)
|
||||||
|
|
||||||
Redistribution and use in source and binary forms, with or without
|
Redistribution and use in source and binary forms, with or without
|
||||||
modification, are permitted provided that the following conditions are
|
modification, are permitted provided that the following conditions are
|
||||||
@@ -752,9 +702,8 @@ MEM_STATIC size_t BITv05_readBitsFast(BITv05_DStream_t* bitD, unsigned nbBits);
|
|||||||
MEM_STATIC unsigned BITv05_highbit32 (U32 val)
|
MEM_STATIC unsigned BITv05_highbit32 (U32 val)
|
||||||
{
|
{
|
||||||
# if defined(_MSC_VER) /* Visual */
|
# if defined(_MSC_VER) /* Visual */
|
||||||
unsigned long r=0;
|
unsigned long r;
|
||||||
_BitScanReverse ( &r, val );
|
return _BitScanReverse(&r, val) ? (unsigned)r : 0;
|
||||||
return (unsigned) r;
|
|
||||||
# elif defined(__GNUC__) && (__GNUC__ >= 3) /* Use GCC Intrinsic */
|
# elif defined(__GNUC__) && (__GNUC__ >= 3) /* Use GCC Intrinsic */
|
||||||
return __builtin_clz (val) ^ 31;
|
return __builtin_clz (val) ^ 31;
|
||||||
# else /* Software version */
|
# else /* Software version */
|
||||||
@@ -826,7 +775,7 @@ MEM_STATIC size_t BITv05_lookBits(BITv05_DStream_t* bitD, U32 nbBits)
|
|||||||
}
|
}
|
||||||
|
|
||||||
/*! BITv05_lookBitsFast :
|
/*! BITv05_lookBitsFast :
|
||||||
* unsafe version; only works only if nbBits >= 1 */
|
* unsafe version; only works if nbBits >= 1 */
|
||||||
MEM_STATIC size_t BITv05_lookBitsFast(BITv05_DStream_t* bitD, U32 nbBits)
|
MEM_STATIC size_t BITv05_lookBitsFast(BITv05_DStream_t* bitD, U32 nbBits)
|
||||||
{
|
{
|
||||||
const U32 bitMask = sizeof(bitD->bitContainer)*8 - 1;
|
const U32 bitMask = sizeof(bitD->bitContainer)*8 - 1;
|
||||||
@@ -846,7 +795,7 @@ MEM_STATIC size_t BITv05_readBits(BITv05_DStream_t* bitD, unsigned nbBits)
|
|||||||
}
|
}
|
||||||
|
|
||||||
/*!BITv05_readBitsFast :
|
/*!BITv05_readBitsFast :
|
||||||
* unsafe version; only works only if nbBits >= 1 */
|
* unsafe version; only works if nbBits >= 1 */
|
||||||
MEM_STATIC size_t BITv05_readBitsFast(BITv05_DStream_t* bitD, unsigned nbBits)
|
MEM_STATIC size_t BITv05_readBitsFast(BITv05_DStream_t* bitD, unsigned nbBits)
|
||||||
{
|
{
|
||||||
size_t value = BITv05_lookBitsFast(bitD, nbBits);
|
size_t value = BITv05_lookBitsFast(bitD, nbBits);
|
||||||
@@ -901,7 +850,7 @@ MEM_STATIC unsigned BITv05_endOfDStream(const BITv05_DStream_t* DStream)
|
|||||||
header file for static linking (only)
|
header file for static linking (only)
|
||||||
Copyright (C) 2013-2015, Yann Collet
|
Copyright (C) 2013-2015, Yann Collet
|
||||||
|
|
||||||
BSD 2-Clause License (http://www.opensource.org/licenses/bsd-license.php)
|
BSD 2-Clause License (https://opensource.org/licenses/bsd-license.php)
|
||||||
|
|
||||||
Redistribution and use in source and binary forms, with or without
|
Redistribution and use in source and binary forms, with or without
|
||||||
modification, are permitted provided that the following conditions are
|
modification, are permitted provided that the following conditions are
|
||||||
@@ -1051,7 +1000,7 @@ MEM_STATIC unsigned FSEv05_endOfDState(const FSEv05_DState_t* DStatePtr)
|
|||||||
FSEv05 : Finite State Entropy coder
|
FSEv05 : Finite State Entropy coder
|
||||||
Copyright (C) 2013-2015, Yann Collet.
|
Copyright (C) 2013-2015, Yann Collet.
|
||||||
|
|
||||||
BSD 2-Clause License (http://www.opensource.org/licenses/bsd-license.php)
|
BSD 2-Clause License (https://opensource.org/licenses/bsd-license.php)
|
||||||
|
|
||||||
Redistribution and use in source and binary forms, with or without
|
Redistribution and use in source and binary forms, with or without
|
||||||
modification, are permitted provided that the following conditions are
|
modification, are permitted provided that the following conditions are
|
||||||
@@ -1537,7 +1486,7 @@ size_t FSEv05_decompress(void* dst, size_t maxDstSize, const void* cSrc, size_t
|
|||||||
header file
|
header file
|
||||||
Copyright (C) 2013-2016, Yann Collet.
|
Copyright (C) 2013-2016, Yann Collet.
|
||||||
|
|
||||||
BSD 2-Clause License (http://www.opensource.org/licenses/bsd-license.php)
|
BSD 2-Clause License (https://opensource.org/licenses/bsd-license.php)
|
||||||
|
|
||||||
Redistribution and use in source and binary forms, with or without
|
Redistribution and use in source and binary forms, with or without
|
||||||
modification, are permitted provided that the following conditions are
|
modification, are permitted provided that the following conditions are
|
||||||
@@ -1610,7 +1559,7 @@ const char* HUFv05_getErrorName(size_t code); /* provides error code string (u
|
|||||||
header file, for static linking only
|
header file, for static linking only
|
||||||
Copyright (C) 2013-2016, Yann Collet
|
Copyright (C) 2013-2016, Yann Collet
|
||||||
|
|
||||||
BSD 2-Clause License (http://www.opensource.org/licenses/bsd-license.php)
|
BSD 2-Clause License (https://opensource.org/licenses/bsd-license.php)
|
||||||
|
|
||||||
Redistribution and use in source and binary forms, with or without
|
Redistribution and use in source and binary forms, with or without
|
||||||
modification, are permitted provided that the following conditions are
|
modification, are permitted provided that the following conditions are
|
||||||
@@ -1702,7 +1651,7 @@ size_t HUFv05_decompress1X4_usingDTable(void* dst, size_t maxDstSize, const void
|
|||||||
Huff0 : Huffman coder, part of New Generation Entropy library
|
Huff0 : Huffman coder, part of New Generation Entropy library
|
||||||
Copyright (C) 2013-2015, Yann Collet.
|
Copyright (C) 2013-2015, Yann Collet.
|
||||||
|
|
||||||
BSD 2-Clause License (http://www.opensource.org/licenses/bsd-license.php)
|
BSD 2-Clause License (https://opensource.org/licenses/bsd-license.php)
|
||||||
|
|
||||||
Redistribution and use in source and binary forms, with or without
|
Redistribution and use in source and binary forms, with or without
|
||||||
modification, are permitted provided that the following conditions are
|
modification, are permitted provided that the following conditions are
|
||||||
@@ -1804,7 +1753,7 @@ static size_t HUFv05_readStats(BYTE* huffWeight, size_t hwSize, U32* rankStats,
|
|||||||
|
|
||||||
if (!srcSize) return ERROR(srcSize_wrong);
|
if (!srcSize) return ERROR(srcSize_wrong);
|
||||||
iSize = ip[0];
|
iSize = ip[0];
|
||||||
//memset(huffWeight, 0, hwSize); /* is not necessary, even though some analyzer complain ... */
|
/* memset(huffWeight, 0, hwSize); */ /* is not necessary, even though some analyzer complain ... */
|
||||||
|
|
||||||
if (iSize >= 128) { /* special header */
|
if (iSize >= 128) { /* special header */
|
||||||
if (iSize >= (242)) { /* RLE */
|
if (iSize >= (242)) { /* RLE */
|
||||||
@@ -1879,7 +1828,7 @@ size_t HUFv05_readDTableX2 (U16* DTable, const void* src, size_t srcSize)
|
|||||||
HUFv05_DEltX2* const dt = (HUFv05_DEltX2*)dtPtr;
|
HUFv05_DEltX2* const dt = (HUFv05_DEltX2*)dtPtr;
|
||||||
|
|
||||||
HUFv05_STATIC_ASSERT(sizeof(HUFv05_DEltX2) == sizeof(U16)); /* if compilation fails here, assertion is false */
|
HUFv05_STATIC_ASSERT(sizeof(HUFv05_DEltX2) == sizeof(U16)); /* if compilation fails here, assertion is false */
|
||||||
//memset(huffWeight, 0, sizeof(huffWeight)); /* is not necessary, even though some analyzer complain ... */
|
/* memset(huffWeight, 0, sizeof(huffWeight)); */ /* is not necessary, even though some analyzer complain ... */
|
||||||
|
|
||||||
iSize = HUFv05_readStats(huffWeight, HUFv05_MAX_SYMBOL_VALUE + 1, rankVal, &nbSymbols, &tableLog, src, srcSize);
|
iSize = HUFv05_readStats(huffWeight, HUFv05_MAX_SYMBOL_VALUE + 1, rankVal, &nbSymbols, &tableLog, src, srcSize);
|
||||||
if (HUFv05_isError(iSize)) return iSize;
|
if (HUFv05_isError(iSize)) return iSize;
|
||||||
@@ -2210,7 +2159,7 @@ size_t HUFv05_readDTableX4 (unsigned* DTable, const void* src, size_t srcSize)
|
|||||||
|
|
||||||
HUFv05_STATIC_ASSERT(sizeof(HUFv05_DEltX4) == sizeof(unsigned)); /* if compilation fails here, assertion is false */
|
HUFv05_STATIC_ASSERT(sizeof(HUFv05_DEltX4) == sizeof(unsigned)); /* if compilation fails here, assertion is false */
|
||||||
if (memLog > HUFv05_ABSOLUTEMAX_TABLELOG) return ERROR(tableLog_tooLarge);
|
if (memLog > HUFv05_ABSOLUTEMAX_TABLELOG) return ERROR(tableLog_tooLarge);
|
||||||
//memset(weightList, 0, sizeof(weightList)); /* is not necessary, even though some analyzer complain ... */
|
/* memset(weightList, 0, sizeof(weightList)); */ /* is not necessary, even though some analyzer complain ... */
|
||||||
|
|
||||||
iSize = HUFv05_readStats(weightList, HUFv05_MAX_SYMBOL_VALUE + 1, rankStats, &nbSymbols, &tableLog, src, srcSize);
|
iSize = HUFv05_readStats(weightList, HUFv05_MAX_SYMBOL_VALUE + 1, rankStats, &nbSymbols, &tableLog, src, srcSize);
|
||||||
if (HUFv05_isError(iSize)) return iSize;
|
if (HUFv05_isError(iSize)) return iSize;
|
||||||
@@ -2539,15 +2488,15 @@ size_t HUFv05_decompress (void* dst, size_t dstSize, const void* cSrc, size_t cS
|
|||||||
|
|
||||||
return decompress[algoNb](dst, dstSize, cSrc, cSrcSize);
|
return decompress[algoNb](dst, dstSize, cSrc, cSrcSize);
|
||||||
|
|
||||||
//return HUFv05_decompress4X2(dst, dstSize, cSrc, cSrcSize); /* multi-streams single-symbol decoding */
|
/* return HUFv05_decompress4X2(dst, dstSize, cSrc, cSrcSize); */ /* multi-streams single-symbol decoding */
|
||||||
//return HUFv05_decompress4X4(dst, dstSize, cSrc, cSrcSize); /* multi-streams double-symbols decoding */
|
/* return HUFv05_decompress4X4(dst, dstSize, cSrc, cSrcSize); */ /* multi-streams double-symbols decoding */
|
||||||
//return HUFv05_decompress4X6(dst, dstSize, cSrc, cSrcSize); /* multi-streams quad-symbols decoding */
|
/* return HUFv05_decompress4X6(dst, dstSize, cSrc, cSrcSize); */ /* multi-streams quad-symbols decoding */
|
||||||
}
|
}
|
||||||
/*
|
/*
|
||||||
zstd - standard compression library
|
zstd - standard compression library
|
||||||
Copyright (C) 2014-2016, Yann Collet.
|
Copyright (C) 2014-2016, Yann Collet.
|
||||||
|
|
||||||
BSD 2-Clause License (http://www.opensource.org/licenses/bsd-license.php)
|
BSD 2-Clause License (https://opensource.org/licenses/bsd-license.php)
|
||||||
|
|
||||||
Redistribution and use in source and binary forms, with or without
|
Redistribution and use in source and binary forms, with or without
|
||||||
modification, are permitted provided that the following conditions are
|
modification, are permitted provided that the following conditions are
|
||||||
@@ -2645,7 +2594,7 @@ struct ZSTDv05_DCtx_s
|
|||||||
FSEv05_DTable LLTable[FSEv05_DTABLE_SIZE_U32(LLFSEv05Log)];
|
FSEv05_DTable LLTable[FSEv05_DTABLE_SIZE_U32(LLFSEv05Log)];
|
||||||
FSEv05_DTable OffTable[FSEv05_DTABLE_SIZE_U32(OffFSEv05Log)];
|
FSEv05_DTable OffTable[FSEv05_DTABLE_SIZE_U32(OffFSEv05Log)];
|
||||||
FSEv05_DTable MLTable[FSEv05_DTABLE_SIZE_U32(MLFSEv05Log)];
|
FSEv05_DTable MLTable[FSEv05_DTABLE_SIZE_U32(MLFSEv05Log)];
|
||||||
unsigned hufTableX4[HUFv05_DTABLE_SIZE(HufLog)];
|
unsigned hufTableX4[HUFv05_DTABLE_SIZE(ZSTD_HUFFDTABLE_CAPACITY_LOG)];
|
||||||
const void* previousDstEnd;
|
const void* previousDstEnd;
|
||||||
const void* base;
|
const void* base;
|
||||||
const void* vBase;
|
const void* vBase;
|
||||||
@@ -2673,7 +2622,7 @@ size_t ZSTDv05_decompressBegin(ZSTDv05_DCtx* dctx)
|
|||||||
dctx->base = NULL;
|
dctx->base = NULL;
|
||||||
dctx->vBase = NULL;
|
dctx->vBase = NULL;
|
||||||
dctx->dictEnd = NULL;
|
dctx->dictEnd = NULL;
|
||||||
dctx->hufTableX4[0] = HufLog;
|
dctx->hufTableX4[0] = ZSTD_HUFFDTABLE_CAPACITY_LOG;
|
||||||
dctx->flagStaticTables = 0;
|
dctx->flagStaticTables = 0;
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
@@ -2829,7 +2778,7 @@ static size_t ZSTDv05_decodeFrameHeader_Part2(ZSTDv05_DCtx* zc, const void* src,
|
|||||||
|
|
||||||
static size_t ZSTDv05_getcBlockSize(const void* src, size_t srcSize, blockProperties_t* bpPtr)
|
static size_t ZSTDv05_getcBlockSize(const void* src, size_t srcSize, blockProperties_t* bpPtr)
|
||||||
{
|
{
|
||||||
const BYTE* const in = (const BYTE* const)src;
|
const BYTE* const in = (const BYTE*)src;
|
||||||
BYTE headerFlags;
|
BYTE headerFlags;
|
||||||
U32 cSize;
|
U32 cSize;
|
||||||
|
|
||||||
@@ -2998,7 +2947,7 @@ static size_t ZSTDv05_decodeSeqHeaders(int* nbSeq, const BYTE** dumpsPtr, size_t
|
|||||||
FSEv05_DTable* DTableLL, FSEv05_DTable* DTableML, FSEv05_DTable* DTableOffb,
|
FSEv05_DTable* DTableLL, FSEv05_DTable* DTableML, FSEv05_DTable* DTableOffb,
|
||||||
const void* src, size_t srcSize, U32 flagStaticTable)
|
const void* src, size_t srcSize, U32 flagStaticTable)
|
||||||
{
|
{
|
||||||
const BYTE* const istart = (const BYTE* const)src;
|
const BYTE* const istart = (const BYTE*)src;
|
||||||
const BYTE* ip = istart;
|
const BYTE* ip = istart;
|
||||||
const BYTE* const iend = istart + srcSize;
|
const BYTE* const iend = istart + srcSize;
|
||||||
U32 LLtype, Offtype, MLtype;
|
U32 LLtype, Offtype, MLtype;
|
||||||
@@ -3234,13 +3183,19 @@ static size_t ZSTDv05_execSequence(BYTE* op,
|
|||||||
const BYTE* const litEnd = *litPtr + sequence.litLength;
|
const BYTE* const litEnd = *litPtr + sequence.litLength;
|
||||||
const BYTE* match = oLitEnd - sequence.offset;
|
const BYTE* match = oLitEnd - sequence.offset;
|
||||||
|
|
||||||
/* check */
|
/* checks */
|
||||||
if (oLitEnd > oend_8) return ERROR(dstSize_tooSmall); /* last match must start at a minimum distance of 8 from oend */
|
size_t const seqLength = sequence.litLength + sequence.matchLength;
|
||||||
|
|
||||||
|
if (seqLength > (size_t)(oend - op)) return ERROR(dstSize_tooSmall);
|
||||||
|
if (sequence.litLength > (size_t)(litLimit - *litPtr)) return ERROR(corruption_detected);
|
||||||
|
/* Now we know there are no overflow in literal nor match lengths, can use pointer checks */
|
||||||
|
if (oLitEnd > oend_8) return ERROR(dstSize_tooSmall);
|
||||||
|
|
||||||
if (oMatchEnd > oend) return ERROR(dstSize_tooSmall); /* overwrite beyond dst buffer */
|
if (oMatchEnd > oend) return ERROR(dstSize_tooSmall); /* overwrite beyond dst buffer */
|
||||||
if (litEnd > litLimit) return ERROR(corruption_detected); /* risk read beyond lit buffer */
|
if (litEnd > litLimit) return ERROR(corruption_detected); /* overRead beyond lit buffer */
|
||||||
|
|
||||||
/* copy Literals */
|
/* copy Literals */
|
||||||
ZSTDv05_wildcopy(op, *litPtr, sequence.litLength); /* note : oLitEnd <= oend-8 : no risk of overwrite beyond oend */
|
ZSTDv05_wildcopy(op, *litPtr, (ptrdiff_t)sequence.litLength); /* note : oLitEnd <= oend-8 : no risk of overwrite beyond oend */
|
||||||
op = oLitEnd;
|
op = oLitEnd;
|
||||||
*litPtr = litEnd; /* update for next sequence */
|
*litPtr = litEnd; /* update for next sequence */
|
||||||
|
|
||||||
@@ -3306,7 +3261,7 @@ static size_t ZSTDv05_decompressSequences(
|
|||||||
{
|
{
|
||||||
const BYTE* ip = (const BYTE*)seqStart;
|
const BYTE* ip = (const BYTE*)seqStart;
|
||||||
const BYTE* const iend = ip + seqSize;
|
const BYTE* const iend = ip + seqSize;
|
||||||
BYTE* const ostart = (BYTE* const)dst;
|
BYTE* const ostart = (BYTE*)dst;
|
||||||
BYTE* op = ostart;
|
BYTE* op = ostart;
|
||||||
BYTE* const oend = ostart + maxDstSize;
|
BYTE* const oend = ostart + maxDstSize;
|
||||||
size_t errorCode, dumpsLength=0;
|
size_t errorCode, dumpsLength=0;
|
||||||
@@ -3362,9 +3317,11 @@ static size_t ZSTDv05_decompressSequences(
|
|||||||
size_t lastLLSize = litEnd - litPtr;
|
size_t lastLLSize = litEnd - litPtr;
|
||||||
if (litPtr > litEnd) return ERROR(corruption_detected); /* too many literals already used */
|
if (litPtr > litEnd) return ERROR(corruption_detected); /* too many literals already used */
|
||||||
if (op+lastLLSize > oend) return ERROR(dstSize_tooSmall);
|
if (op+lastLLSize > oend) return ERROR(dstSize_tooSmall);
|
||||||
|
if (lastLLSize > 0) {
|
||||||
memcpy(op, litPtr, lastLLSize);
|
memcpy(op, litPtr, lastLLSize);
|
||||||
op += lastLLSize;
|
op += lastLLSize;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
return op-ostart;
|
return op-ostart;
|
||||||
}
|
}
|
||||||
@@ -3417,7 +3374,7 @@ static size_t ZSTDv05_decompress_continueDCtx(ZSTDv05_DCtx* dctx,
|
|||||||
{
|
{
|
||||||
const BYTE* ip = (const BYTE*)src;
|
const BYTE* ip = (const BYTE*)src;
|
||||||
const BYTE* iend = ip + srcSize;
|
const BYTE* iend = ip + srcSize;
|
||||||
BYTE* const ostart = (BYTE* const)dst;
|
BYTE* const ostart = (BYTE*)dst;
|
||||||
BYTE* op = ostart;
|
BYTE* op = ostart;
|
||||||
BYTE* const oend = ostart + maxDstSize;
|
BYTE* const oend = ostart + maxDstSize;
|
||||||
size_t remainingSize = srcSize;
|
size_t remainingSize = srcSize;
|
||||||
@@ -3744,7 +3701,7 @@ size_t ZSTDv05_decompressBegin_usingDict(ZSTDv05_DCtx* dctx, const void* dict, s
|
|||||||
Buffered version of Zstd compression library
|
Buffered version of Zstd compression library
|
||||||
Copyright (C) 2015-2016, Yann Collet.
|
Copyright (C) 2015-2016, Yann Collet.
|
||||||
|
|
||||||
BSD 2-Clause License (http://www.opensource.org/licenses/bsd-license.php)
|
BSD 2-Clause License (https://opensource.org/licenses/bsd-license.php)
|
||||||
|
|
||||||
Redistribution and use in source and binary forms, with or without
|
Redistribution and use in source and binary forms, with or without
|
||||||
modification, are permitted provided that the following conditions are
|
modification, are permitted provided that the following conditions are
|
||||||
@@ -3791,7 +3748,9 @@ static size_t ZBUFFv05_blockHeaderSize = 3;
|
|||||||
static size_t ZBUFFv05_limitCopy(void* dst, size_t maxDstSize, const void* src, size_t srcSize)
|
static size_t ZBUFFv05_limitCopy(void* dst, size_t maxDstSize, const void* src, size_t srcSize)
|
||||||
{
|
{
|
||||||
size_t length = MIN(maxDstSize, srcSize);
|
size_t length = MIN(maxDstSize, srcSize);
|
||||||
|
if (length > 0) {
|
||||||
memcpy(dst, src, length);
|
memcpy(dst, src, length);
|
||||||
|
}
|
||||||
return length;
|
return length;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -3928,7 +3887,7 @@ size_t ZBUFFv05_decompressContinue(ZBUFFv05_DCtx* zbc, void* dst, size_t* maxDst
|
|||||||
*maxDstSizePtr = 0;
|
*maxDstSizePtr = 0;
|
||||||
return headerSize - zbc->hPos;
|
return headerSize - zbc->hPos;
|
||||||
}
|
}
|
||||||
// zbc->stage = ZBUFFv05ds_decodeHeader; break; /* useless : stage follows */
|
/* zbc->stage = ZBUFFv05ds_decodeHeader; break; */ /* useless : stage follows */
|
||||||
}
|
}
|
||||||
/* fall-through */
|
/* fall-through */
|
||||||
case ZBUFFv05ds_decodeHeader:
|
case ZBUFFv05ds_decodeHeader:
|
||||||
@@ -4001,7 +3960,7 @@ size_t ZBUFFv05_decompressContinue(ZBUFFv05_DCtx* zbc, void* dst, size_t* maxDst
|
|||||||
if (!decodedSize) { zbc->stage = ZBUFFv05ds_read; break; } /* this was just a header */
|
if (!decodedSize) { zbc->stage = ZBUFFv05ds_read; break; } /* this was just a header */
|
||||||
zbc->outEnd = zbc->outStart + decodedSize;
|
zbc->outEnd = zbc->outStart + decodedSize;
|
||||||
zbc->stage = ZBUFFv05ds_flush;
|
zbc->stage = ZBUFFv05ds_flush;
|
||||||
// break; /* ZBUFFv05ds_flush follows */
|
/* break; */ /* ZBUFFv05ds_flush follows */
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
/* fall-through */
|
/* fall-through */
|
||||||
@@ -4044,3 +4003,5 @@ const char* ZBUFFv05_getErrorName(size_t errorCode) { return ERR_getErrorName(er
|
|||||||
|
|
||||||
size_t ZBUFFv05_recommendedDInSize(void) { return BLOCKSIZE + ZBUFFv05_blockHeaderSize /* block header size*/ ; }
|
size_t ZBUFFv05_recommendedDInSize(void) { return BLOCKSIZE + ZBUFFv05_blockHeaderSize /* block header size*/ ; }
|
||||||
size_t ZBUFFv05_recommendedDOutSize(void) { return BLOCKSIZE; }
|
size_t ZBUFFv05_recommendedDOutSize(void) { return BLOCKSIZE; }
|
||||||
|
|
||||||
|
#endif /* USE_EXTERNAL_ZSTD */
|
||||||
|
|||||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user