Skip to content
Branch: master
Find file History
Permalink
Type Name Latest commit message Commit time
..
Failed to load latest commit information.
.gitignore icecompr/.gitignore: add missing files Feb 12, 2017
Makefile Clean up Makefiles Feb 12, 2017
README Added icecompr Jan 8, 2017
example_1k.bin Added icecompr Jan 8, 2017
example_8k.bin Added icecompr Jan 8, 2017
icecompr.cc
icecompr.py Cleanup icecompr code Jan 15, 2017
iceuncompr.c Squelch trailing whitespace Aug 1, 2017

README

A simple compression algorithm for iCE40 bit-streams
====================================================

This directory contains tools for compressing and uncompressing
iCE40 bit-streams. The motivation is to reduce the bandwidth
requirements for bit-stream upload.

Note that iCE40 FPGAs can not uncompress this compressed bit-streams!
Uncompression must be performed by e.g. a uC on the FPGA board.

This compression algorithm uses the fact that most bits in an iCE40
bit-stream are cleared.

The bit-stream is encoded as the distances between set bits (i.e.
the length of runs of ZERO bits between two ONE bits). This sequence
of integers is stored using a simple prefix code to spend fewer bits
on smaller (more frequent) numbers.

The algorithm includes an escape-mechanism to mix uncompressed binary
data with compressed bit-streams. This is useful when the bit-stream
contains sections that do not compress well with this algorithm, for
example in BRAM initialization data.

The compressed bitstream starts with the ASCII string "ICECOMPR", i.e.
the hex values 0x49434543 and 0x4f4d5052 (stored as big-endian numbers).

After the 8 bytes magic the compressed bitstream is a stream of the
following opcodes that must be interpreted by the decompressor. The
notation ZERO and ONE is used for zero and one bits. The notation foo[N]
is used for an N bit value "foo", transmitted MSB first.

	ONE count[2]
	ZERO ONE count[5]
	ZERO ZERO ONE count[8]
	ZERO ZERO ZERO ZERO ONE count[23]
	  output count ZERO bits followed by a single ONE bit

	ZERO ZERO ZERO ONE count[6] data[count]
	  output the count data bits followed by a single ONE bit

	ZERO ZERO ZERO ZERO ZERO count[23]
	  output count ZERO bits and stop decompressing. (end of file)

The program "icecompr" (C++11, ISC license) contains an implementation of a
compressor and a decompressor. The decompressor in this program however is
only used for integrity checking the compressed bit-stream.

The program "iceuncompr" (plain C, public domain) contains an implementation
of a stand-alone decompressor. Simply copy&paste this implementation into
your uC firmware.

You can’t perform that action at this time.