Nice optimization bitRAKE, I need the lower word P in table A also for checking if a code is valid, so I think it will be:

mov dx, [ebx]
; get code in eax and check if correct using dx
; then lookup:
neg ax
add ax, dx
add ax, [ebx + 2]
mov edx, [ebx + 2 * eax]
; or slightly different:
sub dx, ax
add dx, [ebx + 2]
mov edx, [ebx + 2 * edx]
(assuming the high word of edx is zero)

I tried this code and I was able to decode a huffman stream that used a fixed huffman table. I wrote an algorithm for creating table A and B, based on the code length for each symbol.

Posted on 2002-03-15 01:50:49 by Thomas

mov dx, [ebx]
; get code in eax and check if correct using dx
; then lookup:
sub ax, [ebx + 2]
mov edx, [ebx + 2 * eax + Const]
(assuming the high word of eax is 0FFFFh)
This should be possible with slight modification of the table. I will work more on this over the weekend - not any time to spare right now. :)

Const = size of second table.
= old( + + (following codes))
Posted on 2002-03-15 11:04:53 by bitRAKE
I'm mightly impressed!

You guys are onto what is known as "canonical Huffman coding". With no trees in the decode you eliminate all that pointer chasing and everything is down to a very cachable scan of your bit length starting entries & you calc the address of the uncode in one fell swoop.

Did you finish it off into a lib or DLL? No biggie if not, but I'm playing with writing a Burrows/Wheeler zip proggie that it might fit into.

big time:alright:
Posted on 2002-10-20 19:56:40 by rafe
Yeah, Thomas whipped up a great library!
PNGlib, go get it at his website.
Posted on 2002-10-20 20:19:52 by bitRAKE
Thanks! It looks like there may be a lot more than I really need for my purposes. If I actually get off my lazy ass & translate my lame-o c snippetts to assembly I'll post the results, fully crediting all those I stole from of course.

How's that quote go? "Fat dumb & lazy is no way to go thru life son." Maybe I should have listened.
Posted on 2002-10-20 22:32:45 by rafe