| CARVIEW |
Select Language
HTTP/2 200
date: Tue, 30 Dec 2025 12:27:43 GMT
content-type: text/html; charset=utf-8
vary: X-PJAX, X-PJAX-Container, Turbo-Visit, Turbo-Frame, X-Requested-With,Accept-Encoding, Accept, X-Requested-With
etag: W/"f7fed2dc072b0b96cb3a3f9b6dfc9383"
cache-control: max-age=0, private, must-revalidate
strict-transport-security: max-age=31536000; includeSubdomains; preload
x-frame-options: deny
x-content-type-options: nosniff
x-xss-protection: 0
referrer-policy: no-referrer-when-downgrade
content-security-policy: default-src 'none'; base-uri 'self'; child-src github.githubassets.com github.com/assets-cdn/worker/ github.com/assets/ gist.github.com/assets-cdn/worker/; connect-src 'self' uploads.github.com www.githubstatus.com collector.github.com raw.githubusercontent.com api.github.com github-cloud.s3.amazonaws.com github-production-repository-file-5c1aeb.s3.amazonaws.com github-production-upload-manifest-file-7fdce7.s3.amazonaws.com github-production-user-asset-6210df.s3.amazonaws.com *.rel.tunnels.api.visualstudio.com wss://*.rel.tunnels.api.visualstudio.com github.githubassets.com objects-origin.githubusercontent.com copilot-proxy.githubusercontent.com proxy.individual.githubcopilot.com proxy.business.githubcopilot.com proxy.enterprise.githubcopilot.com *.actions.githubusercontent.com wss://*.actions.githubusercontent.com productionresultssa0.blob.core.windows.net/ productionresultssa1.blob.core.windows.net/ productionresultssa2.blob.core.windows.net/ productionresultssa3.blob.core.windows.net/ productionresultssa4.blob.core.windows.net/ productionresultssa5.blob.core.windows.net/ productionresultssa6.blob.core.windows.net/ productionresultssa7.blob.core.windows.net/ productionresultssa8.blob.core.windows.net/ productionresultssa9.blob.core.windows.net/ productionresultssa10.blob.core.windows.net/ productionresultssa11.blob.core.windows.net/ productionresultssa12.blob.core.windows.net/ productionresultssa13.blob.core.windows.net/ productionresultssa14.blob.core.windows.net/ productionresultssa15.blob.core.windows.net/ productionresultssa16.blob.core.windows.net/ productionresultssa17.blob.core.windows.net/ productionresultssa18.blob.core.windows.net/ productionresultssa19.blob.core.windows.net/ github-production-repository-image-32fea6.s3.amazonaws.com github-production-release-asset-2e65be.s3.amazonaws.com insights.github.com wss://alive.github.com wss://alive-staging.github.com api.githubcopilot.com api.individual.githubcopilot.com api.business.githubcopilot.com api.enterprise.githubcopilot.com; font-src github.githubassets.com; form-action 'self' github.com gist.github.com copilot-workspace.githubnext.com objects-origin.githubusercontent.com; frame-ancestors 'none'; frame-src viewscreen.githubusercontent.com notebooks.githubusercontent.com; img-src 'self' data: blob: github.githubassets.com media.githubusercontent.com camo.githubusercontent.com identicons.github.com avatars.githubusercontent.com private-avatars.githubusercontent.com github-cloud.s3.amazonaws.com objects.githubusercontent.com release-assets.githubusercontent.com secured-user-images.githubusercontent.com/ user-images.githubusercontent.com/ private-user-images.githubusercontent.com opengraph.githubassets.com marketplace-screenshots.githubusercontent.com/ copilotprodattachments.blob.core.windows.net/github-production-copilot-attachments/ github-production-user-asset-6210df.s3.amazonaws.com customer-stories-feed.github.com spotlights-feed.github.com objects-origin.githubusercontent.com *.githubusercontent.com; manifest-src 'self'; media-src github.com user-images.githubusercontent.com/ secured-user-images.githubusercontent.com/ private-user-images.githubusercontent.com github-production-user-asset-6210df.s3.amazonaws.com gist.github.com github.githubassets.com; script-src github.githubassets.com; style-src 'unsafe-inline' github.githubassets.com; upgrade-insecure-requests; worker-src github.githubassets.com github.com/assets-cdn/worker/ github.com/assets/ gist.github.com/assets-cdn/worker/
server: github.com
content-encoding: gzip
accept-ranges: bytes
set-cookie: _gh_sess=dB%2FsOmWkcUp5YUu4lUiRbxPxAo9wn%2Fhk9tw8jpC3PA5Iw0gjGTgFRC1Zf5We%2BJlE%2B6ugi7oZW%2F9SVe4DnS%2BbkRbRf0ky5MMegMBsYDPJiqPtP5GosUXd9nphVWt%2FyogxQWKvuFbK2gywuCNAZkydSlo7O%2FwH4doX4qIM6WKVLt%2BUh9aIzfdJa6ADUlJkoCFyrMCuzdGwJO3tWhMzSMM1KNnG9TvGQPOjK%2BPvJR6pdop5mVbLxZmDBuD9%2B1ATXwr81f1g%2FZNbO%2FWTB8WKoE2ZJg%3D%3D--JWElzZvplkuWc3Nz--ZrQdRhe9MIh35rjZq2jOjg%3D%3D; Path=/; HttpOnly; Secure; SameSite=Lax
set-cookie: _octo=GH1.1.1356903220.1767097663; Path=/; Domain=github.com; Expires=Wed, 30 Dec 2026 12:27:43 GMT; Secure; SameSite=Lax
set-cookie: logged_in=no; Path=/; Domain=github.com; Expires=Wed, 30 Dec 2026 12:27:43 GMT; HttpOnly; Secure; SameSite=Lax
x-github-request-id: 92F4:12330D:9A5AC9:A89246:6953C53F
GitHub - rygorous/ryg_rans: Simple rANS encoder/decoder (arithmetic coding-ish entropy coder).
Skip to content
Navigation Menu
{{ message }}
-
Notifications
You must be signed in to change notification settings - Fork 44
Simple rANS encoder/decoder (arithmetic coding-ish entropy coder).
License
rygorous/ryg_rans
Folders and files
| Name | Name | Last commit message | Last commit date | |
|---|---|---|---|---|
Repository files navigation
This is a public-domain implementation of several rANS variants. rANS is an entropy coder from the ANS family, as described in Jarek Duda's paper "Asymmetric numeral systems" (https://arxiv.org/abs/1311.2540). - "rans_byte.h" has a byte-aligned rANS encoder/decoder and some comments on how to use it. This implementation should work on all 32-bit architectures. "main.cpp" is an example program that shows how to use it. - "rans64.h" is a 64-bit version that emits entire 32-bit words at a time. It is (usually) a good deal faster than rans_byte on 64-bit architectures, and also makes for a very precise arithmetic coder (i.e. it gets quite close to entropy). The trade-off is that this version will be slower on 32-bit machines, and the output bitstream is not endian-neutral. "main64.cpp" is the corresponding example. - "rans_word_sse41.h" has a SIMD decoder (SSE 4.1 to be precise) that does IO in units of 16-bit words. It has less precision than either rans_byte or rans64 (meaning that it doesn't get as close to entropy) and requires at least 4 independent streams of data to be useful; however, it is also a good deal faster. "main_simd.cpp" shows how to use it. See my blog https://fgiesen.wordpress.com/ for some notes on the design. I've also written a paper on interleaving output streams from multiple entropy coders: https://arxiv.org/abs/1402.3392 this documents the underlying design for "rans_word_sse41", and also shows how the same approach generalizes to e.g. GPU implementations, provided there are enough independent contexts coded at the same time to fill up a warp/wavefront or whatever your favorite GPU's terminology for its native SIMD width is. Finally, there's also "main_alias.cpp", which shows how to combine rANS with the alias method to get O(1) symbol lookup with table size proportional to the number of symbols. I presented an overview of the underlying idea here: https://fgiesen.wordpress.com/2014/02/18/rans-with-static-probability-distributions/ Results on my machine (Sandy Bridge i7-2600K) with rans_byte in 64-bit mode: ---- rANS encode: 12896496 clocks, 16.8 clocks/symbol (192.8MiB/s) 12486912 clocks, 16.2 clocks/symbol (199.2MiB/s) 12511975 clocks, 16.3 clocks/symbol (198.8MiB/s) 12660765 clocks, 16.5 clocks/symbol (196.4MiB/s) 12550285 clocks, 16.3 clocks/symbol (198.2MiB/s) rANS: 435113 bytes 17023550 clocks, 22.1 clocks/symbol (146.1MiB/s) 18081509 clocks, 23.5 clocks/symbol (137.5MiB/s) 16901632 clocks, 22.0 clocks/symbol (147.1MiB/s) 17166188 clocks, 22.3 clocks/symbol (144.9MiB/s) 17235859 clocks, 22.4 clocks/symbol (144.3MiB/s) decode ok! interleaved rANS encode: 9618004 clocks, 12.5 clocks/symbol (258.6MiB/s) 9488277 clocks, 12.3 clocks/symbol (262.1MiB/s) 9460194 clocks, 12.3 clocks/symbol (262.9MiB/s) 9582025 clocks, 12.5 clocks/symbol (259.5MiB/s) 9332017 clocks, 12.1 clocks/symbol (266.5MiB/s) interleaved rANS: 435117 bytes 10687601 clocks, 13.9 clocks/symbol (232.7MB/s) 10637918 clocks, 13.8 clocks/symbol (233.8MB/s) 10909652 clocks, 14.2 clocks/symbol (227.9MB/s) 10947637 clocks, 14.2 clocks/symbol (227.2MB/s) 10529464 clocks, 13.7 clocks/symbol (236.2MB/s) decode ok! ---- And here's rans64 in 64-bit mode: ---- rANS encode: 10256075 clocks, 13.3 clocks/symbol (242.3MiB/s) 10620132 clocks, 13.8 clocks/symbol (234.1MiB/s) 10043080 clocks, 13.1 clocks/symbol (247.6MiB/s) 9878205 clocks, 12.8 clocks/symbol (251.8MiB/s) 10122645 clocks, 13.2 clocks/symbol (245.7MiB/s) rANS: 435116 bytes 14244155 clocks, 18.5 clocks/symbol (174.6MiB/s) 15072524 clocks, 19.6 clocks/symbol (165.0MiB/s) 14787604 clocks, 19.2 clocks/symbol (168.2MiB/s) 14736556 clocks, 19.2 clocks/symbol (168.8MiB/s) 14686129 clocks, 19.1 clocks/symbol (169.3MiB/s) decode ok! interleaved rANS encode: 7691159 clocks, 10.0 clocks/symbol (323.3MiB/s) 7182692 clocks, 9.3 clocks/symbol (346.2MiB/s) 7060804 clocks, 9.2 clocks/symbol (352.2MiB/s) 6949201 clocks, 9.0 clocks/symbol (357.9MiB/s) 6876415 clocks, 8.9 clocks/symbol (361.6MiB/s) interleaved rANS: 435120 bytes 8133574 clocks, 10.6 clocks/symbol (305.7MB/s) 8631618 clocks, 11.2 clocks/symbol (288.1MB/s) 8643790 clocks, 11.2 clocks/symbol (287.7MB/s) 8449364 clocks, 11.0 clocks/symbol (294.3MB/s) 8331444 clocks, 10.8 clocks/symbol (298.5MB/s) decode ok! ---- Finally, here's the rans_word_sse41 decoder on an 8-way interleaved stream: ---- SIMD rANS: 435626 bytes 4597641 clocks, 6.0 clocks/symbol (540.8MB/s) 4514356 clocks, 5.9 clocks/symbol (550.8MB/s) 4780918 clocks, 6.2 clocks/symbol (520.1MB/s) 4532913 clocks, 5.9 clocks/symbol (548.5MB/s) 4554527 clocks, 5.9 clocks/symbol (545.9MB/s) decode ok! ---- There's also an experimental 16-way interleaved AVX2 version that hits faster rates still, developed by my colleague Won Chun; I will post it soon. Note that this is running "book1" which is a relatively short test, and the measurement setup is not great, so take the results with a grain of salt. -Fabian "ryg" Giesen, Feb 2014.
About
Simple rANS encoder/decoder (arithmetic coding-ish entropy coder).
Resources
License
Stars
Watchers
Forks
Releases
No releases published
Packages 0
No packages published
You can’t perform that action at this time.