Sorting using verilog
Yes, a radix sort would make a lot of sense for 8-bit data. It would operate in three phases and require two small blocks of memory.

The first block of memory would have 256 locations. It would be used to count how many times each data value appears in the group of pixels being sorted. If you're sorting 64 pixels at a time, then this memory would have to be 7 bits wide. (Actually, for continuous operation, you'll want this memory to be double-buffered, so 2&times;256 locations.)

The second block of memory is operated as a FIFO. Each entry in this FIFO is a value:count pair, where the value is 8 bits wide and the count is 7 bits wide, for a total width of 15 bits. This FIFO needs to be at least 64 words deep, in order to handle the case where each input value only appeared once.

Start by clearing the counters for the first group of pixels. After that, the three phases are:


As each pixel arrives, increment the corresponding counter.
Scan through the counters and whenever you have a nonzero count, transfer the value:count pair to the FIFO. Also, clear the counters at this time for the next pass. Note that this is where you choose the direction of the sort, by which way you scan through the counters.
Read the value:count pairs out of the FIFO, and generate count  copies of each value at the output.


I just realized that there's a problem here in terms of timing: the first and third phases require 64 clocks each, while the middle phase requires 256 clocks. This means that for continuous operation, the first memory will need to be 4 separate memories with 256 locations each, you'll need to have four interleaved copies of the middle phase, each feeding its own FIFO, and the third phase will have to switch sequentially among the FIFO outputs. (Note that this problem does not arise if the number of pixels in each group is at least as large as the number of values.)

This implementation would be able to process input and output pixels continuously, and the total latency from input to output would be 64 + 256 = 320 clocks.