Home | Forums | What's new | Resources | |
Hex to Bin |
paul_met - Dec 25, 2018 |
antime | Dec 25, 2018 | |||
Use a look-up table? 4- or 8-bit, depending on what you want to optimize for. |
paul_met | Dec 25, 2018 | |||
To convert 1 bpp tiles to 4 bpp. |
antime | Dec 25, 2018 | |||||||
I'm still not sure I understand what you're asking, but this converts 1-4 ASCII hex digits to a number (uppercase assumed). Assembly output compiled with -Os.
Code:
Code:
|
paul_met | Dec 26, 2018 | |||
For example, there is a tile font in the format of 1 bit per pixel (monochrome). I need to convert it to 4 bits per pixel (16 colors). |
antime | Dec 26, 2018 | |||||||
So not at all what you originally asked about... Assuming the foregroung and background colors are constant, a pure C implementation is slightly longer. It might be possible to squeeze a couple of instructions out of the assembly by manual register allocation, but this is trivially unit-testable on the host.
Code:
Code:
|
paul_met | Dec 27, 2018 | ||||
Some strange syntax I do not understand. What does this mean?
Code:
|
antime | Dec 27, 2018 | |||
0x40-0x44 is the lookup table. |
paul_met | Jan 2, 2019 | ||||
Significant optimization, if you convert 1 bpp reverse-order to 4 bpp (-12 instructions and -2 registers).
Code:
|
antime | Jan 2, 2019 | ||||
Your "end of bit conversion" condition doesn't work. Depending on the MSB of the byte loaded from @r0, the cmp/pl is either always false, or always true (loads are sign-extending, and shar is sign-preserving, and the comparison is signed). Also, if any bit pattern is valid you can't early-out. Ignoring that, you could remove one register by using rotates instead of adds:
Code:
|
paul_met | Jan 2, 2019 | ||||
Yes, I forgot to add EXTU.B R1, R1. The code should look like this:
Code:
But your code gives the wrong result after second cycle. |
antime | Jan 4, 2019 | ||||
Because I was bored, here's another solution. With the table it's longer, but should run quicker. Obviously when optimizing for speed you can't beat a full 1K table, but I think this is a reasonable compromise.
Code:
|