Advertisement
vladikcomper

DPCM Nibble Processing optimization (Explanation)

Aug 9th, 2013
161
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.53 KB | None | 0 0
  1. Let's represent DPCM byte format as follows: ABh. Let's also pretend you've read the byte already and you've come to the decoding step right now.
  2.  
  3. First off, we need to decode the high nibble. Normally, we would like to bitshift it by 4 and load corresponding index form a DPCM delta table. But we can optimize the decode process by avoiding bitshifting. Thus, we need a different data location on our DPCM data, like so:
  4.  
  5. Offset Decode table data
  6. 0000h 00 .. .. .. .. .. .. .. .. .. .. .. .. .. .. ..
  7. 0010h 01 .. .. .. .. .. .. .. .. .. .. .. .. .. .. ..
  8. 0020h 02 .. .. .. .. .. .. .. .. .. .. .. .. .. .. ..
  9. 0030h 04 .. .. .. .. .. .. .. .. .. .. .. .. .. .. ..
  10. 0040h 08 .. .. .. .. .. .. .. .. .. .. .. .. .. .. ..
  11. 0050h 10 .. .. .. .. .. .. .. .. .. .. .. .. .. .. ..
  12. ...
  13.  
  14. So, you may see how the offsets of the table listed corresond byte fetched, where the high nibble remains unshifted. So, if the high nibble is 1, the byte will have the form of 1Xh, and we would like to read table from offset 0010h to decode it correctly.
  15.  
  16. The table eventually takes 100h bytes, so you may think of a huge space loss here. Apparently, we can put every single byte of the table to a good use, something we'll need to pull off the next optimization.
  17.  
  18. Normally, a programmer wants to bitmask the currently processing nibble to filter out grabage (the other nibble we don't need at the moment), this to ensure we'll access the only correct and unique table entry to decode the nibble in the question. Apparently, as the table is 100h bytes now, we have nothing to loose, which means, we can see it to decode every of possible 256 byte values correctly. Like, if the byte read is 10h, we would like decode nibble 1 correctly, and load the value of 01 from the table. If we've read 11h, 12h etc, we basically need the same, as the low nibble doesn't count. All those offsets are free in our new DPCM table, so we can set any to return the right value despite the low nibble. Eventually, the new table will look like this:
  19.  
  20.  
  21. Offset Decode table data
  22. 0000h 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
  23. 0010h 01 01 01 01 01 01 01 01 01 01 01 01 01 01 01 01
  24. 0020h 02 02 02 02 02 02 02 02 02 02 02 02 02 02 02 02
  25. 0030h 04 04 04 04 04 04 04 04 04 04 04 04 04 04 04 04
  26. ...
  27.  
  28. Now we can instantly decode the first nibble no matter what the other nibble is. Now, I think you get the idea it figure out the table to support low nibble yourself. This way, you won't even have to apply AND or bitshifts operations to the DPCM byte read, this is the ultra fast decoding in its truly.
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement