Googles appar
Huvudmeny

Post a Comment On: cbloom rants

"The Oodle LZNIB Algorithm"

2 Comments -

1 – 2 of 2
Blogger svpv said...

And how do you do nibble IO? Does that mean that, if you're unlucky, and a literal run doesn't start on a byte boundary, then you can't use memcpy, but need to reassemble each byte from two nibbles?

January 22, 2019 at 4:16 AM

Blogger cbloom said...

Literals are always byte aligned. You definitely need literal decoding to just be a byte copy.

The first check on LRL is whether more than the first control nibble is needed. With the default threshold (8), values 0-7 are for LRL 1-8 , and 8 means "need more". If you don't need more, then the literal copy is just a uint64 read and write.

There are two ways to do the nibble IO to make this work :

1. Just treat nibbles and bytes as two different streams. Fetch from either stream as needed.

2. What I did : when you need a nibble, always grab 2. One is used immediately and one is kept "in hand". Your read pointer always stays byte aligned. If you need a nibble and one is already "in hand", use it.

Naively you would need a branch to tell if you have a nibble "in hand" but this can be avoided by duplicating the decode loop, once to start without a nibble in hand, and once for starting with a nibble in hand. Then you can use the goto after-literal/after-match states to jump to the right variant. (there are now 4 starting pointers, AL and AM with and without nibble in hand).

To write the nibbles, you reserve the output pointer when you put the first nibble, then can continue putting bytes, and then put the second nibble to the same pointer you reserved earlier.

January 22, 2019 at 4:54 AM

You can use some HTML tags, such as <b>, <i>, <a>

This blog does not allow anonymous comments.

Comment moderation has been enabled. All comments must be approved by the blog author.

You will be asked to sign in after submitting your comment.