Advertisement
cr88192

LZ4LLB Decoder (BJX2 ASM)

May 4th, 2021
255
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.58 KB | None | 0 0
  1. /*
  2. Decoder for LZ4LLB (LZ4 variant with lengths limited to a single byte), as implemented in BJX2 ASM.
  3. Relatively little bundling in this code, as for a lot of the cases where bundling could be used, interlock delays would have eaten any gains. Still, further improvements could be possible...
  4. */
  5.  
  6. byte *TKPE_UnpackL6(byte *ct, byte *ibuf, int isz);
  7.  
  8. __asm {
  9. TKPE_UnpackL6:
  10. WEXMD 2
  11. ADD R5, R6, R7
  12. .L0:
  13.  
  14. /* Fetch Token Byte */
  15. MOVU.B (R5, 0), R16
  16. MOVU.B (R5, 1), R17
  17. ADD 1, R5
  18. SHLD R16, -4, R18 | AND R16, 15, R19
  19. /* Fetch Extended Length */
  20. CMPEQ 15, R18
  21. ADD?T R17, R18 | ADD?T 1, R5
  22. ADD R5, R18, R22
  23. MOV R4, R20 | MOV R5, R21
  24. ADD R18, R4 | ADD R18, R5
  25. /* Copy Literal Bytes */
  26. .L1:
  27. MOV.Q (R21, 0), R16
  28. MOV.Q (R21, 8), R17
  29. ADD 16, R21
  30. MOV.Q R16, (R20, 0)
  31. MOV.Q R17, (R20, 8)
  32. ADD 16, R20
  33. CMPGT R21, R22
  34. BT .L1
  35.  
  36. MOVU.W (R5, 0), R18
  37. MOVU.B (R5, 2), R17
  38. ADD R5, 1, R23
  39. ADD 2, R5
  40.  
  41. /* Hit end of buffer yet? */
  42. CMPGT R23, R7
  43. BF .Done
  44. CMPEQ 15, R19
  45. ADD?T 1, R5 | ADD?T R17, R19
  46. ADD 4, R19
  47.  
  48. /* Zero-Distance Cases? */
  49. TEST R18, R18
  50. BF .Copy
  51. CMPEQ 5, R19
  52. BT .Cont
  53. BRA .Done
  54.  
  55. .Cont:
  56. CMPGT R5, R7
  57. BT .L0
  58.  
  59. .Done:
  60. MOV R4, R2
  61. RTS
  62.  
  63. /* Match Copy Stuff */
  64.  
  65. /* R4=Dest, R5=Source, R18=Dist, R19=Length */
  66. .Copy:
  67. ADD R4, R19, R22 | SUB R4, R18, R21
  68. MOV R4, R20
  69. ADD R19, R4
  70. CMPGE 8, R18
  71. BF .CopyRLE
  72. CMPGE 16, R18
  73. BF .CopyL1S
  74.  
  75. .CopyL1:
  76. MOV.Q (R21, 0), R16
  77. MOV.Q (R21, 8), R17
  78. ADD 16, R21
  79. MOV.Q R16, (R20, 0)
  80. MOV.Q R17, (R20, 8)
  81. ADD 16, R20
  82. CMPGT R20, R22
  83. BT .CopyL1
  84. BRA .Cont
  85.  
  86. .CopyL1S:
  87. MOV.Q (R21, 0), R16
  88. MOV.Q R16, (R20, 0)
  89. MOV.Q (R21, 8), R17
  90. MOV.Q R17, (R20, 8)
  91. ADD 16, R21
  92. ADD 16, R20
  93. CMPGT R20, R22
  94. BT .CopyL1S
  95. BRA .Cont
  96.  
  97. .CopyRLE:
  98.  
  99. CMPEQ 1, R18
  100. BT .CopyRLE1
  101. CMPEQ 2, R18
  102. BT .CopyRLE2
  103. CMPEQ 4, R18
  104. BT .CopyRLE4
  105. CMPEQ 3, R18
  106. BT .CopyRLE3
  107.  
  108. MOV.Q (R21), R16
  109. .CopyRLE_L1:
  110. MOV.Q R16, (R20, 0)
  111. ADD R18, R20
  112. CMPGT R20, R22
  113. BT .CopyRLE_L1
  114. BRA .Cont
  115.  
  116. .CopyRLE1:
  117. MOVU.B (R21), R16
  118. PSHUF.B R16, 0x00, R16
  119. PSHUF.W R16, 0x00, R16
  120. BRA .CopyRLEN_L1
  121. .CopyRLE2:
  122. MOVU.W (R21), R16
  123. PSHUF.W R16, 0x00, R16
  124. BRA .CopyRLEN_L1
  125. .CopyRLE4:
  126. MOVU.L (R21), R16
  127. MOVLLD R16, R16, R16
  128. BRA .CopyRLEN_L1
  129.  
  130. .CopyRLE3:
  131. MOVU.L (R21), R16
  132. MOV 6, R18
  133. SHLD R16, 8, R3 | SHLD R16, 24, R17
  134. SHLD R3, -8, R16
  135. OR R17, R16
  136. BRA .CopyRLE_L1
  137.  
  138. NOP
  139.  
  140. .CopyRLEN_L1:
  141. MOV.Q R16, (R20, 0)
  142. MOV.Q R16, (R20, 8)
  143. ADD 16, R20
  144. CMPGT R20, R22
  145. BT .CopyRLEN_L1
  146. BRA .Cont
  147. };
  148.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement