x86p_i8.inc 5.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238
  1. {
  2. x86 format converters for HERMES
  3. Copyright (c) 1998 Christian Nentwich ([email protected])
  4. Some routines are (c) Glenn Fiedler ([email protected]), used with permission
  5. This library is free software; you can redistribute it and/or
  6. modify it under the terms of the GNU Lesser General Public
  7. License as published by the Free Software Foundation; either
  8. version 2.1 of the License, or (at your option) any later version
  9. with the following modification:
  10. As a special exception, the copyright holders of this library give you
  11. permission to link this library with independent modules to produce an
  12. executable, regardless of the license terms of these independent modules,and
  13. to copy and distribute the resulting executable under terms of your choice,
  14. provided that you also meet, for each linked independent module, the terms
  15. and conditions of the license of that module. An independent module is a
  16. module which is not derived from or based on this library. If you modify
  17. this library, you may extend this exception to your version of the library,
  18. but you are not obligated to do so. If you do not wish to do so, delete this
  19. exception statement from your version.
  20. This library is distributed in the hope that it will be useful,
  21. but WITHOUT ANY WARRANTY; without even the implied warranty of
  22. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  23. Lesser General Public License for more details.
  24. You should have received a copy of the GNU Lesser General Public
  25. License along with this library; if not, write to the Free Software
  26. Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
  27. }
  28. { Convert_*
  29. Paramters:
  30. ESI = source
  31. EDI = dest
  32. ECX = amount (NOT 0!!! (the ConvertX86 routine checks for that though))
  33. Destroys:
  34. EAX, EBX, EDX
  35. }
  36. procedure ConvertX86pI8_32(CONVERT_PARAMETERS); cdecl; nostackframe; assembler;
  37. asm
  38. xorl %ebx,%ebx
  39. movl 36(%ebp),%edx
  40. .L1:
  41. movb (%esi),%bl
  42. incl %esi
  43. movl (%edx,%ebx,4),%eax
  44. movl %eax,(%edi)
  45. addl $4,%edi
  46. decl %ecx
  47. jnz .L1
  48. jmp _X86RETURN
  49. end;
  50. procedure ConvertX86pI8_24(CONVERT_PARAMETERS); cdecl; nostackframe; assembler;
  51. asm
  52. movl 36(%ebp),%ebx
  53. xorl %edx,%edx
  54. // check short
  55. cmpl $32,%ecx
  56. ja .L3
  57. .L1: // short loop
  58. movb (%esi),%dl
  59. movl (%ebx,%edx,4),%eax
  60. movb %al,(%edi) // blue
  61. movb %ah,1(%edi) // green
  62. shrl $16,%eax
  63. movb %al,2(%edi) // red
  64. incl %esi
  65. addl $3,%edi
  66. decl %ecx
  67. jnz .L1
  68. .L2:
  69. jmp _X86RETURN
  70. .L3: // head
  71. movl %edi,%eax
  72. andl $0b11,%eax
  73. jz .L4
  74. movb (%esi),%dl
  75. movl (%ebx,%edx,4),%eax
  76. movb %al,(%edi) // blue
  77. movb %ah,1(%edi) // green
  78. shrl $16,%eax
  79. movb %al,2(%edi) // red
  80. incl %esi
  81. addl $3,%edi
  82. decl %ecx
  83. jmp .L3
  84. .L4: // save ebp
  85. pushl %ebp
  86. movl %ebx,%ebp
  87. // save count
  88. pushl %ecx
  89. // unroll 4 times
  90. shrl $2,%ecx
  91. .L5: pushl %ecx // save ecx
  92. movb (%esi),%dl // index to "A"
  93. movl (%ebp,%edx,4),%eax // eax = [xx][A2][A1][A0]
  94. shll $8,%eax // eax = [A2][A1][A0][xx]
  95. movb 1(%esi),%dl // index to "B"
  96. movb (%ebp,%edx,4),%al // eax = [A2][A1][A0][B0]
  97. rorl $8,%eax // eax = [B0][A2][A1][A0] (done)
  98. movl %eax,(%edi)
  99. movl (%ebp,%edx,4),%eax // eax = [xx][B2][B1][B0]
  100. shll $8,%eax // eax = [B2][B1][B0][xx]
  101. movb 3(%esi),%dl // index to "D"
  102. movl (%ebp,%edx,4),%ecx // ecx = [xx][D2][D1][D0]
  103. shll $8,%ecx // ecx = [D2][D1][D0][xx]
  104. movb 2(%esi),%dl // index to "C"
  105. movb 1(%ebp,%edx,4),%ah // eax = [B2][B1][C1][xx]
  106. movb (%ebp,%edx,4),%al // eax = [B2][B1][C1][C0]
  107. rorl $16,%eax // eax = [C1][C0][B2][B1] (done)
  108. movb 2(%ebp,%edx,4),%cl // ecx = [D2][D1][D0][C2] (done)
  109. movl %eax,4(%edi)
  110. movl %ecx,8(%edi)
  111. addl $4,%esi
  112. addl $3*4,%edi
  113. popl %ecx // restore ecx
  114. decl %ecx
  115. jnz .L5
  116. // tail
  117. popl %ecx
  118. andl $0b11,%ecx
  119. jz .L7
  120. .L6:
  121. movb (%esi),%dl
  122. movl (%ebx,%edx,4),%eax
  123. movb %al,(%edi) // blue
  124. movb %ah,1(%edi) // green
  125. shrl $16,%eax
  126. movb %al,2(%edi) // red
  127. incl %esi
  128. addl $3,%edi
  129. decl %ecx
  130. jnz .L6
  131. .L7: popl %ebp
  132. jmp _X86RETURN
  133. end;
  134. procedure ConvertX86pI8_16(CONVERT_PARAMETERS); cdecl; nostackframe; assembler;
  135. asm
  136. xorl %ebx,%ebx
  137. movl 36(%ebp),%edx
  138. testl $3,%edi
  139. jz .Laligned
  140. movb (%esi),%bl
  141. movl (%edx,%ebx,4),%eax
  142. incl %esi
  143. movw %ax,(%edi)
  144. addl $2,%edi
  145. decl %ecx
  146. jz .LOut
  147. .Laligned:
  148. pushl %ecx
  149. xorl %eax,%eax
  150. xorl %ebx,%ebx
  151. shrl $1,%ecx
  152. jz .Last_pixel
  153. .balign 8
  154. .Ly:
  155. movb 1(%esi),%bl
  156. movb (%esi),%al
  157. movl (%edx,%ebx,4),%ebx
  158. addl $2,%esi
  159. shll $16,%ebx
  160. movl (%edx,%eax,4),%eax
  161. orl %ebx,%eax
  162. xorl %ebx,%ebx
  163. movl %eax,(%edi)
  164. addl $4,%edi
  165. xorl %eax,%eax
  166. decl %ecx
  167. jnz .Ly
  168. .Last_pixel:
  169. popl %ecx
  170. testb $1,%cl
  171. jz .LOut
  172. movb (%esi),%bl
  173. movl (%edx,%ebx,4),%eax
  174. incl %esi
  175. movw %ax,(%edi)
  176. addl $2,%edi
  177. .LOut:
  178. jmp _X86RETURN
  179. end;