jidctint-mmx.asm 33 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851
  1. ;
  2. ; jidctint.asm - accurate integer IDCT (MMX)
  3. ;
  4. ; Copyright 2009 Pierre Ossman <ossman@cendio.se> for Cendio AB
  5. ; Copyright (C) 2016, D. R. Commander.
  6. ;
  7. ; Based on the x86 SIMD extension for IJG JPEG library
  8. ; Copyright (C) 1999-2006, MIYASAKA Masaru.
  9. ; For conditions of distribution and use, see copyright notice in jsimdext.inc
  10. ;
  11. ; This file should be assembled with NASM (Netwide Assembler),
  12. ; can *not* be assembled with Microsoft's MASM or any compatible
  13. ; assembler (including Borland's Turbo Assembler).
  14. ; NASM is available from http://nasm.sourceforge.net/ or
  15. ; http://sourceforge.net/project/showfiles.php?group_id=6208
  16. ;
  17. ; This file contains a slow-but-accurate integer implementation of the
  18. ; inverse DCT (Discrete Cosine Transform). The following code is based
  19. ; directly on the IJG's original jidctint.c; see the jidctint.c for
  20. ; more details.
  21. %include "jsimdext.inc"
  22. %include "jdct.inc"
  23. ; --------------------------------------------------------------------------
  24. %define CONST_BITS 13
  25. %define PASS1_BITS 2
  26. %define DESCALE_P1 (CONST_BITS - PASS1_BITS)
  27. %define DESCALE_P2 (CONST_BITS + PASS1_BITS + 3)
  28. %if CONST_BITS == 13
  29. F_0_298 equ 2446 ; FIX(0.298631336)
  30. F_0_390 equ 3196 ; FIX(0.390180644)
  31. F_0_541 equ 4433 ; FIX(0.541196100)
  32. F_0_765 equ 6270 ; FIX(0.765366865)
  33. F_0_899 equ 7373 ; FIX(0.899976223)
  34. F_1_175 equ 9633 ; FIX(1.175875602)
  35. F_1_501 equ 12299 ; FIX(1.501321110)
  36. F_1_847 equ 15137 ; FIX(1.847759065)
  37. F_1_961 equ 16069 ; FIX(1.961570560)
  38. F_2_053 equ 16819 ; FIX(2.053119869)
  39. F_2_562 equ 20995 ; FIX(2.562915447)
  40. F_3_072 equ 25172 ; FIX(3.072711026)
  41. %else
  42. ; NASM cannot do compile-time arithmetic on floating-point constants.
  43. %define DESCALE(x, n) (((x) + (1 << ((n) - 1))) >> (n))
  44. F_0_298 equ DESCALE( 320652955, 30 - CONST_BITS) ; FIX(0.298631336)
  45. F_0_390 equ DESCALE( 418953276, 30 - CONST_BITS) ; FIX(0.390180644)
  46. F_0_541 equ DESCALE( 581104887, 30 - CONST_BITS) ; FIX(0.541196100)
  47. F_0_765 equ DESCALE( 821806413, 30 - CONST_BITS) ; FIX(0.765366865)
  48. F_0_899 equ DESCALE( 966342111, 30 - CONST_BITS) ; FIX(0.899976223)
  49. F_1_175 equ DESCALE(1262586813, 30 - CONST_BITS) ; FIX(1.175875602)
  50. F_1_501 equ DESCALE(1612031267, 30 - CONST_BITS) ; FIX(1.501321110)
  51. F_1_847 equ DESCALE(1984016188, 30 - CONST_BITS) ; FIX(1.847759065)
  52. F_1_961 equ DESCALE(2106220350, 30 - CONST_BITS) ; FIX(1.961570560)
  53. F_2_053 equ DESCALE(2204520673, 30 - CONST_BITS) ; FIX(2.053119869)
  54. F_2_562 equ DESCALE(2751909506, 30 - CONST_BITS) ; FIX(2.562915447)
  55. F_3_072 equ DESCALE(3299298341, 30 - CONST_BITS) ; FIX(3.072711026)
  56. %endif
  57. ; --------------------------------------------------------------------------
  58. SECTION SEG_CONST
  59. alignz 32
  60. GLOBAL_DATA(jconst_idct_islow_mmx)
  61. EXTN(jconst_idct_islow_mmx):
  62. PW_F130_F054 times 2 dw (F_0_541 + F_0_765), F_0_541
  63. PW_F054_MF130 times 2 dw F_0_541, (F_0_541 - F_1_847)
  64. PW_MF078_F117 times 2 dw (F_1_175 - F_1_961), F_1_175
  65. PW_F117_F078 times 2 dw F_1_175, (F_1_175 - F_0_390)
  66. PW_MF060_MF089 times 2 dw (F_0_298 - F_0_899), -F_0_899
  67. PW_MF089_F060 times 2 dw -F_0_899, (F_1_501 - F_0_899)
  68. PW_MF050_MF256 times 2 dw (F_2_053 - F_2_562), -F_2_562
  69. PW_MF256_F050 times 2 dw -F_2_562, (F_3_072 - F_2_562)
  70. PD_DESCALE_P1 times 2 dd 1 << (DESCALE_P1 - 1)
  71. PD_DESCALE_P2 times 2 dd 1 << (DESCALE_P2 - 1)
  72. PB_CENTERJSAMP times 8 db CENTERJSAMPLE
  73. alignz 32
  74. ; --------------------------------------------------------------------------
  75. SECTION SEG_TEXT
  76. BITS 32
  77. ;
  78. ; Perform dequantization and inverse DCT on one block of coefficients.
  79. ;
  80. ; GLOBAL(void)
  81. ; jsimd_idct_islow_mmx(void *dct_table, JCOEFPTR coef_block,
  82. ; JSAMPARRAY output_buf, JDIMENSION output_col)
  83. ;
  84. %define dct_table(b) (b) + 8 ; jpeg_component_info *compptr
  85. %define coef_block(b) (b) + 12 ; JCOEFPTR coef_block
  86. %define output_buf(b) (b) + 16 ; JSAMPARRAY output_buf
  87. %define output_col(b) (b) + 20 ; JDIMENSION output_col
  88. %define original_ebp ebp + 0
  89. %define wk(i) ebp - (WK_NUM - (i)) * SIZEOF_MMWORD
  90. ; mmword wk[WK_NUM]
  91. %define WK_NUM 12
  92. %define workspace wk(0) - DCTSIZE2 * SIZEOF_JCOEF
  93. ; JCOEF workspace[DCTSIZE2]
  94. align 32
  95. GLOBAL_FUNCTION(jsimd_idct_islow_mmx)
  96. EXTN(jsimd_idct_islow_mmx):
  97. push ebp
  98. mov eax, esp ; eax = original ebp
  99. sub esp, byte 4
  100. and esp, byte (-SIZEOF_MMWORD) ; align to 64 bits
  101. mov [esp], eax
  102. mov ebp, esp ; ebp = aligned ebp
  103. lea esp, [workspace]
  104. push ebx
  105. ; push ecx ; need not be preserved
  106. ; push edx ; need not be preserved
  107. push esi
  108. push edi
  109. get_GOT ebx ; get GOT address
  110. ; ---- Pass 1: process columns from input, store into work array.
  111. ; mov eax, [original_ebp]
  112. mov edx, POINTER [dct_table(eax)] ; quantptr
  113. mov esi, JCOEFPTR [coef_block(eax)] ; inptr
  114. lea edi, [workspace] ; JCOEF *wsptr
  115. mov ecx, DCTSIZE/4 ; ctr
  116. alignx 16, 7
  117. .columnloop:
  118. %ifndef NO_ZERO_COLUMN_TEST_ISLOW_MMX
  119. mov eax, dword [DWBLOCK(1,0,esi,SIZEOF_JCOEF)]
  120. or eax, dword [DWBLOCK(2,0,esi,SIZEOF_JCOEF)]
  121. jnz short .columnDCT
  122. movq mm0, MMWORD [MMBLOCK(1,0,esi,SIZEOF_JCOEF)]
  123. movq mm1, MMWORD [MMBLOCK(2,0,esi,SIZEOF_JCOEF)]
  124. por mm0, MMWORD [MMBLOCK(3,0,esi,SIZEOF_JCOEF)]
  125. por mm1, MMWORD [MMBLOCK(4,0,esi,SIZEOF_JCOEF)]
  126. por mm0, MMWORD [MMBLOCK(5,0,esi,SIZEOF_JCOEF)]
  127. por mm1, MMWORD [MMBLOCK(6,0,esi,SIZEOF_JCOEF)]
  128. por mm0, MMWORD [MMBLOCK(7,0,esi,SIZEOF_JCOEF)]
  129. por mm1, mm0
  130. packsswb mm1, mm1
  131. movd eax, mm1
  132. test eax, eax
  133. jnz short .columnDCT
  134. ; -- AC terms all zero
  135. movq mm0, MMWORD [MMBLOCK(0,0,esi,SIZEOF_JCOEF)]
  136. pmullw mm0, MMWORD [MMBLOCK(0,0,edx,SIZEOF_ISLOW_MULT_TYPE)]
  137. psllw mm0, PASS1_BITS
  138. movq mm2, mm0 ; mm0=in0=(00 01 02 03)
  139. punpcklwd mm0, mm0 ; mm0=(00 00 01 01)
  140. punpckhwd mm2, mm2 ; mm2=(02 02 03 03)
  141. movq mm1, mm0
  142. punpckldq mm0, mm0 ; mm0=(00 00 00 00)
  143. punpckhdq mm1, mm1 ; mm1=(01 01 01 01)
  144. movq mm3, mm2
  145. punpckldq mm2, mm2 ; mm2=(02 02 02 02)
  146. punpckhdq mm3, mm3 ; mm3=(03 03 03 03)
  147. movq MMWORD [MMBLOCK(0,0,edi,SIZEOF_JCOEF)], mm0
  148. movq MMWORD [MMBLOCK(0,1,edi,SIZEOF_JCOEF)], mm0
  149. movq MMWORD [MMBLOCK(1,0,edi,SIZEOF_JCOEF)], mm1
  150. movq MMWORD [MMBLOCK(1,1,edi,SIZEOF_JCOEF)], mm1
  151. movq MMWORD [MMBLOCK(2,0,edi,SIZEOF_JCOEF)], mm2
  152. movq MMWORD [MMBLOCK(2,1,edi,SIZEOF_JCOEF)], mm2
  153. movq MMWORD [MMBLOCK(3,0,edi,SIZEOF_JCOEF)], mm3
  154. movq MMWORD [MMBLOCK(3,1,edi,SIZEOF_JCOEF)], mm3
  155. jmp near .nextcolumn
  156. alignx 16, 7
  157. %endif
  158. .columnDCT:
  159. ; -- Even part
  160. movq mm0, MMWORD [MMBLOCK(0,0,esi,SIZEOF_JCOEF)]
  161. movq mm1, MMWORD [MMBLOCK(2,0,esi,SIZEOF_JCOEF)]
  162. pmullw mm0, MMWORD [MMBLOCK(0,0,edx,SIZEOF_ISLOW_MULT_TYPE)]
  163. pmullw mm1, MMWORD [MMBLOCK(2,0,edx,SIZEOF_ISLOW_MULT_TYPE)]
  164. movq mm2, MMWORD [MMBLOCK(4,0,esi,SIZEOF_JCOEF)]
  165. movq mm3, MMWORD [MMBLOCK(6,0,esi,SIZEOF_JCOEF)]
  166. pmullw mm2, MMWORD [MMBLOCK(4,0,edx,SIZEOF_ISLOW_MULT_TYPE)]
  167. pmullw mm3, MMWORD [MMBLOCK(6,0,edx,SIZEOF_ISLOW_MULT_TYPE)]
  168. ; (Original)
  169. ; z1 = (z2 + z3) * 0.541196100;
  170. ; tmp2 = z1 + z3 * -1.847759065;
  171. ; tmp3 = z1 + z2 * 0.765366865;
  172. ;
  173. ; (This implementation)
  174. ; tmp2 = z2 * 0.541196100 + z3 * (0.541196100 - 1.847759065);
  175. ; tmp3 = z2 * (0.541196100 + 0.765366865) + z3 * 0.541196100;
  176. movq mm4, mm1 ; mm1=in2=z2
  177. movq mm5, mm1
  178. punpcklwd mm4, mm3 ; mm3=in6=z3
  179. punpckhwd mm5, mm3
  180. movq mm1, mm4
  181. movq mm3, mm5
  182. pmaddwd mm4, [GOTOFF(ebx,PW_F130_F054)] ; mm4=tmp3L
  183. pmaddwd mm5, [GOTOFF(ebx,PW_F130_F054)] ; mm5=tmp3H
  184. pmaddwd mm1, [GOTOFF(ebx,PW_F054_MF130)] ; mm1=tmp2L
  185. pmaddwd mm3, [GOTOFF(ebx,PW_F054_MF130)] ; mm3=tmp2H
  186. movq mm6, mm0
  187. paddw mm0, mm2 ; mm0=in0+in4
  188. psubw mm6, mm2 ; mm6=in0-in4
  189. pxor mm7, mm7
  190. pxor mm2, mm2
  191. punpcklwd mm7, mm0 ; mm7=tmp0L
  192. punpckhwd mm2, mm0 ; mm2=tmp0H
  193. psrad mm7, (16-CONST_BITS) ; psrad mm7,16 & pslld mm7,CONST_BITS
  194. psrad mm2, (16-CONST_BITS) ; psrad mm2,16 & pslld mm2,CONST_BITS
  195. movq mm0, mm7
  196. paddd mm7, mm4 ; mm7=tmp10L
  197. psubd mm0, mm4 ; mm0=tmp13L
  198. movq mm4, mm2
  199. paddd mm2, mm5 ; mm2=tmp10H
  200. psubd mm4, mm5 ; mm4=tmp13H
  201. movq MMWORD [wk(0)], mm7 ; wk(0)=tmp10L
  202. movq MMWORD [wk(1)], mm2 ; wk(1)=tmp10H
  203. movq MMWORD [wk(2)], mm0 ; wk(2)=tmp13L
  204. movq MMWORD [wk(3)], mm4 ; wk(3)=tmp13H
  205. pxor mm5, mm5
  206. pxor mm7, mm7
  207. punpcklwd mm5, mm6 ; mm5=tmp1L
  208. punpckhwd mm7, mm6 ; mm7=tmp1H
  209. psrad mm5, (16-CONST_BITS) ; psrad mm5,16 & pslld mm5,CONST_BITS
  210. psrad mm7, (16-CONST_BITS) ; psrad mm7,16 & pslld mm7,CONST_BITS
  211. movq mm2, mm5
  212. paddd mm5, mm1 ; mm5=tmp11L
  213. psubd mm2, mm1 ; mm2=tmp12L
  214. movq mm0, mm7
  215. paddd mm7, mm3 ; mm7=tmp11H
  216. psubd mm0, mm3 ; mm0=tmp12H
  217. movq MMWORD [wk(4)], mm5 ; wk(4)=tmp11L
  218. movq MMWORD [wk(5)], mm7 ; wk(5)=tmp11H
  219. movq MMWORD [wk(6)], mm2 ; wk(6)=tmp12L
  220. movq MMWORD [wk(7)], mm0 ; wk(7)=tmp12H
  221. ; -- Odd part
  222. movq mm4, MMWORD [MMBLOCK(1,0,esi,SIZEOF_JCOEF)]
  223. movq mm6, MMWORD [MMBLOCK(3,0,esi,SIZEOF_JCOEF)]
  224. pmullw mm4, MMWORD [MMBLOCK(1,0,edx,SIZEOF_ISLOW_MULT_TYPE)]
  225. pmullw mm6, MMWORD [MMBLOCK(3,0,edx,SIZEOF_ISLOW_MULT_TYPE)]
  226. movq mm1, MMWORD [MMBLOCK(5,0,esi,SIZEOF_JCOEF)]
  227. movq mm3, MMWORD [MMBLOCK(7,0,esi,SIZEOF_JCOEF)]
  228. pmullw mm1, MMWORD [MMBLOCK(5,0,edx,SIZEOF_ISLOW_MULT_TYPE)]
  229. pmullw mm3, MMWORD [MMBLOCK(7,0,edx,SIZEOF_ISLOW_MULT_TYPE)]
  230. movq mm5, mm6
  231. movq mm7, mm4
  232. paddw mm5, mm3 ; mm5=z3
  233. paddw mm7, mm1 ; mm7=z4
  234. ; (Original)
  235. ; z5 = (z3 + z4) * 1.175875602;
  236. ; z3 = z3 * -1.961570560; z4 = z4 * -0.390180644;
  237. ; z3 += z5; z4 += z5;
  238. ;
  239. ; (This implementation)
  240. ; z3 = z3 * (1.175875602 - 1.961570560) + z4 * 1.175875602;
  241. ; z4 = z3 * 1.175875602 + z4 * (1.175875602 - 0.390180644);
  242. movq mm2, mm5
  243. movq mm0, mm5
  244. punpcklwd mm2, mm7
  245. punpckhwd mm0, mm7
  246. movq mm5, mm2
  247. movq mm7, mm0
  248. pmaddwd mm2, [GOTOFF(ebx,PW_MF078_F117)] ; mm2=z3L
  249. pmaddwd mm0, [GOTOFF(ebx,PW_MF078_F117)] ; mm0=z3H
  250. pmaddwd mm5, [GOTOFF(ebx,PW_F117_F078)] ; mm5=z4L
  251. pmaddwd mm7, [GOTOFF(ebx,PW_F117_F078)] ; mm7=z4H
  252. movq MMWORD [wk(10)], mm2 ; wk(10)=z3L
  253. movq MMWORD [wk(11)], mm0 ; wk(11)=z3H
  254. ; (Original)
  255. ; z1 = tmp0 + tmp3; z2 = tmp1 + tmp2;
  256. ; tmp0 = tmp0 * 0.298631336; tmp1 = tmp1 * 2.053119869;
  257. ; tmp2 = tmp2 * 3.072711026; tmp3 = tmp3 * 1.501321110;
  258. ; z1 = z1 * -0.899976223; z2 = z2 * -2.562915447;
  259. ; tmp0 += z1 + z3; tmp1 += z2 + z4;
  260. ; tmp2 += z2 + z3; tmp3 += z1 + z4;
  261. ;
  262. ; (This implementation)
  263. ; tmp0 = tmp0 * (0.298631336 - 0.899976223) + tmp3 * -0.899976223;
  264. ; tmp1 = tmp1 * (2.053119869 - 2.562915447) + tmp2 * -2.562915447;
  265. ; tmp2 = tmp1 * -2.562915447 + tmp2 * (3.072711026 - 2.562915447);
  266. ; tmp3 = tmp0 * -0.899976223 + tmp3 * (1.501321110 - 0.899976223);
  267. ; tmp0 += z3; tmp1 += z4;
  268. ; tmp2 += z3; tmp3 += z4;
  269. movq mm2, mm3
  270. movq mm0, mm3
  271. punpcklwd mm2, mm4
  272. punpckhwd mm0, mm4
  273. movq mm3, mm2
  274. movq mm4, mm0
  275. pmaddwd mm2, [GOTOFF(ebx,PW_MF060_MF089)] ; mm2=tmp0L
  276. pmaddwd mm0, [GOTOFF(ebx,PW_MF060_MF089)] ; mm0=tmp0H
  277. pmaddwd mm3, [GOTOFF(ebx,PW_MF089_F060)] ; mm3=tmp3L
  278. pmaddwd mm4, [GOTOFF(ebx,PW_MF089_F060)] ; mm4=tmp3H
  279. paddd mm2, MMWORD [wk(10)] ; mm2=tmp0L
  280. paddd mm0, MMWORD [wk(11)] ; mm0=tmp0H
  281. paddd mm3, mm5 ; mm3=tmp3L
  282. paddd mm4, mm7 ; mm4=tmp3H
  283. movq MMWORD [wk(8)], mm2 ; wk(8)=tmp0L
  284. movq MMWORD [wk(9)], mm0 ; wk(9)=tmp0H
  285. movq mm2, mm1
  286. movq mm0, mm1
  287. punpcklwd mm2, mm6
  288. punpckhwd mm0, mm6
  289. movq mm1, mm2
  290. movq mm6, mm0
  291. pmaddwd mm2, [GOTOFF(ebx,PW_MF050_MF256)] ; mm2=tmp1L
  292. pmaddwd mm0, [GOTOFF(ebx,PW_MF050_MF256)] ; mm0=tmp1H
  293. pmaddwd mm1, [GOTOFF(ebx,PW_MF256_F050)] ; mm1=tmp2L
  294. pmaddwd mm6, [GOTOFF(ebx,PW_MF256_F050)] ; mm6=tmp2H
  295. paddd mm2, mm5 ; mm2=tmp1L
  296. paddd mm0, mm7 ; mm0=tmp1H
  297. paddd mm1, MMWORD [wk(10)] ; mm1=tmp2L
  298. paddd mm6, MMWORD [wk(11)] ; mm6=tmp2H
  299. movq MMWORD [wk(10)], mm2 ; wk(10)=tmp1L
  300. movq MMWORD [wk(11)], mm0 ; wk(11)=tmp1H
  301. ; -- Final output stage
  302. movq mm5, MMWORD [wk(0)] ; mm5=tmp10L
  303. movq mm7, MMWORD [wk(1)] ; mm7=tmp10H
  304. movq mm2, mm5
  305. movq mm0, mm7
  306. paddd mm5, mm3 ; mm5=data0L
  307. paddd mm7, mm4 ; mm7=data0H
  308. psubd mm2, mm3 ; mm2=data7L
  309. psubd mm0, mm4 ; mm0=data7H
  310. movq mm3, [GOTOFF(ebx,PD_DESCALE_P1)] ; mm3=[PD_DESCALE_P1]
  311. paddd mm5, mm3
  312. paddd mm7, mm3
  313. psrad mm5, DESCALE_P1
  314. psrad mm7, DESCALE_P1
  315. paddd mm2, mm3
  316. paddd mm0, mm3
  317. psrad mm2, DESCALE_P1
  318. psrad mm0, DESCALE_P1
  319. packssdw mm5, mm7 ; mm5=data0=(00 01 02 03)
  320. packssdw mm2, mm0 ; mm2=data7=(70 71 72 73)
  321. movq mm4, MMWORD [wk(4)] ; mm4=tmp11L
  322. movq mm3, MMWORD [wk(5)] ; mm3=tmp11H
  323. movq mm7, mm4
  324. movq mm0, mm3
  325. paddd mm4, mm1 ; mm4=data1L
  326. paddd mm3, mm6 ; mm3=data1H
  327. psubd mm7, mm1 ; mm7=data6L
  328. psubd mm0, mm6 ; mm0=data6H
  329. movq mm1, [GOTOFF(ebx,PD_DESCALE_P1)] ; mm1=[PD_DESCALE_P1]
  330. paddd mm4, mm1
  331. paddd mm3, mm1
  332. psrad mm4, DESCALE_P1
  333. psrad mm3, DESCALE_P1
  334. paddd mm7, mm1
  335. paddd mm0, mm1
  336. psrad mm7, DESCALE_P1
  337. psrad mm0, DESCALE_P1
  338. packssdw mm4, mm3 ; mm4=data1=(10 11 12 13)
  339. packssdw mm7, mm0 ; mm7=data6=(60 61 62 63)
  340. movq mm6, mm5 ; transpose coefficients(phase 1)
  341. punpcklwd mm5, mm4 ; mm5=(00 10 01 11)
  342. punpckhwd mm6, mm4 ; mm6=(02 12 03 13)
  343. movq mm1, mm7 ; transpose coefficients(phase 1)
  344. punpcklwd mm7, mm2 ; mm7=(60 70 61 71)
  345. punpckhwd mm1, mm2 ; mm1=(62 72 63 73)
  346. movq mm3, MMWORD [wk(6)] ; mm3=tmp12L
  347. movq mm0, MMWORD [wk(7)] ; mm0=tmp12H
  348. movq mm4, MMWORD [wk(10)] ; mm4=tmp1L
  349. movq mm2, MMWORD [wk(11)] ; mm2=tmp1H
  350. movq MMWORD [wk(0)], mm5 ; wk(0)=(00 10 01 11)
  351. movq MMWORD [wk(1)], mm6 ; wk(1)=(02 12 03 13)
  352. movq MMWORD [wk(4)], mm7 ; wk(4)=(60 70 61 71)
  353. movq MMWORD [wk(5)], mm1 ; wk(5)=(62 72 63 73)
  354. movq mm5, mm3
  355. movq mm6, mm0
  356. paddd mm3, mm4 ; mm3=data2L
  357. paddd mm0, mm2 ; mm0=data2H
  358. psubd mm5, mm4 ; mm5=data5L
  359. psubd mm6, mm2 ; mm6=data5H
  360. movq mm7, [GOTOFF(ebx,PD_DESCALE_P1)] ; mm7=[PD_DESCALE_P1]
  361. paddd mm3, mm7
  362. paddd mm0, mm7
  363. psrad mm3, DESCALE_P1
  364. psrad mm0, DESCALE_P1
  365. paddd mm5, mm7
  366. paddd mm6, mm7
  367. psrad mm5, DESCALE_P1
  368. psrad mm6, DESCALE_P1
  369. packssdw mm3, mm0 ; mm3=data2=(20 21 22 23)
  370. packssdw mm5, mm6 ; mm5=data5=(50 51 52 53)
  371. movq mm1, MMWORD [wk(2)] ; mm1=tmp13L
  372. movq mm4, MMWORD [wk(3)] ; mm4=tmp13H
  373. movq mm2, MMWORD [wk(8)] ; mm2=tmp0L
  374. movq mm7, MMWORD [wk(9)] ; mm7=tmp0H
  375. movq mm0, mm1
  376. movq mm6, mm4
  377. paddd mm1, mm2 ; mm1=data3L
  378. paddd mm4, mm7 ; mm4=data3H
  379. psubd mm0, mm2 ; mm0=data4L
  380. psubd mm6, mm7 ; mm6=data4H
  381. movq mm2, [GOTOFF(ebx,PD_DESCALE_P1)] ; mm2=[PD_DESCALE_P1]
  382. paddd mm1, mm2
  383. paddd mm4, mm2
  384. psrad mm1, DESCALE_P1
  385. psrad mm4, DESCALE_P1
  386. paddd mm0, mm2
  387. paddd mm6, mm2
  388. psrad mm0, DESCALE_P1
  389. psrad mm6, DESCALE_P1
  390. packssdw mm1, mm4 ; mm1=data3=(30 31 32 33)
  391. packssdw mm0, mm6 ; mm0=data4=(40 41 42 43)
  392. movq mm7, MMWORD [wk(0)] ; mm7=(00 10 01 11)
  393. movq mm2, MMWORD [wk(1)] ; mm2=(02 12 03 13)
  394. movq mm4, mm3 ; transpose coefficients(phase 1)
  395. punpcklwd mm3, mm1 ; mm3=(20 30 21 31)
  396. punpckhwd mm4, mm1 ; mm4=(22 32 23 33)
  397. movq mm6, mm0 ; transpose coefficients(phase 1)
  398. punpcklwd mm0, mm5 ; mm0=(40 50 41 51)
  399. punpckhwd mm6, mm5 ; mm6=(42 52 43 53)
  400. movq mm1, mm7 ; transpose coefficients(phase 2)
  401. punpckldq mm7, mm3 ; mm7=(00 10 20 30)
  402. punpckhdq mm1, mm3 ; mm1=(01 11 21 31)
  403. movq mm5, mm2 ; transpose coefficients(phase 2)
  404. punpckldq mm2, mm4 ; mm2=(02 12 22 32)
  405. punpckhdq mm5, mm4 ; mm5=(03 13 23 33)
  406. movq mm3, MMWORD [wk(4)] ; mm3=(60 70 61 71)
  407. movq mm4, MMWORD [wk(5)] ; mm4=(62 72 63 73)
  408. movq MMWORD [MMBLOCK(0,0,edi,SIZEOF_JCOEF)], mm7
  409. movq MMWORD [MMBLOCK(1,0,edi,SIZEOF_JCOEF)], mm1
  410. movq MMWORD [MMBLOCK(2,0,edi,SIZEOF_JCOEF)], mm2
  411. movq MMWORD [MMBLOCK(3,0,edi,SIZEOF_JCOEF)], mm5
  412. movq mm7, mm0 ; transpose coefficients(phase 2)
  413. punpckldq mm0, mm3 ; mm0=(40 50 60 70)
  414. punpckhdq mm7, mm3 ; mm7=(41 51 61 71)
  415. movq mm1, mm6 ; transpose coefficients(phase 2)
  416. punpckldq mm6, mm4 ; mm6=(42 52 62 72)
  417. punpckhdq mm1, mm4 ; mm1=(43 53 63 73)
  418. movq MMWORD [MMBLOCK(0,1,edi,SIZEOF_JCOEF)], mm0
  419. movq MMWORD [MMBLOCK(1,1,edi,SIZEOF_JCOEF)], mm7
  420. movq MMWORD [MMBLOCK(2,1,edi,SIZEOF_JCOEF)], mm6
  421. movq MMWORD [MMBLOCK(3,1,edi,SIZEOF_JCOEF)], mm1
  422. .nextcolumn:
  423. add esi, byte 4*SIZEOF_JCOEF ; coef_block
  424. add edx, byte 4*SIZEOF_ISLOW_MULT_TYPE ; quantptr
  425. add edi, byte 4*DCTSIZE*SIZEOF_JCOEF ; wsptr
  426. dec ecx ; ctr
  427. jnz near .columnloop
  428. ; ---- Pass 2: process rows from work array, store into output array.
  429. mov eax, [original_ebp]
  430. lea esi, [workspace] ; JCOEF *wsptr
  431. mov edi, JSAMPARRAY [output_buf(eax)] ; (JSAMPROW *)
  432. mov eax, JDIMENSION [output_col(eax)]
  433. mov ecx, DCTSIZE/4 ; ctr
  434. alignx 16, 7
  435. .rowloop:
  436. ; -- Even part
  437. movq mm0, MMWORD [MMBLOCK(0,0,esi,SIZEOF_JCOEF)]
  438. movq mm1, MMWORD [MMBLOCK(2,0,esi,SIZEOF_JCOEF)]
  439. movq mm2, MMWORD [MMBLOCK(4,0,esi,SIZEOF_JCOEF)]
  440. movq mm3, MMWORD [MMBLOCK(6,0,esi,SIZEOF_JCOEF)]
  441. ; (Original)
  442. ; z1 = (z2 + z3) * 0.541196100;
  443. ; tmp2 = z1 + z3 * -1.847759065;
  444. ; tmp3 = z1 + z2 * 0.765366865;
  445. ;
  446. ; (This implementation)
  447. ; tmp2 = z2 * 0.541196100 + z3 * (0.541196100 - 1.847759065);
  448. ; tmp3 = z2 * (0.541196100 + 0.765366865) + z3 * 0.541196100;
  449. movq mm4, mm1 ; mm1=in2=z2
  450. movq mm5, mm1
  451. punpcklwd mm4, mm3 ; mm3=in6=z3
  452. punpckhwd mm5, mm3
  453. movq mm1, mm4
  454. movq mm3, mm5
  455. pmaddwd mm4, [GOTOFF(ebx,PW_F130_F054)] ; mm4=tmp3L
  456. pmaddwd mm5, [GOTOFF(ebx,PW_F130_F054)] ; mm5=tmp3H
  457. pmaddwd mm1, [GOTOFF(ebx,PW_F054_MF130)] ; mm1=tmp2L
  458. pmaddwd mm3, [GOTOFF(ebx,PW_F054_MF130)] ; mm3=tmp2H
  459. movq mm6, mm0
  460. paddw mm0, mm2 ; mm0=in0+in4
  461. psubw mm6, mm2 ; mm6=in0-in4
  462. pxor mm7, mm7
  463. pxor mm2, mm2
  464. punpcklwd mm7, mm0 ; mm7=tmp0L
  465. punpckhwd mm2, mm0 ; mm2=tmp0H
  466. psrad mm7, (16-CONST_BITS) ; psrad mm7,16 & pslld mm7,CONST_BITS
  467. psrad mm2, (16-CONST_BITS) ; psrad mm2,16 & pslld mm2,CONST_BITS
  468. movq mm0, mm7
  469. paddd mm7, mm4 ; mm7=tmp10L
  470. psubd mm0, mm4 ; mm0=tmp13L
  471. movq mm4, mm2
  472. paddd mm2, mm5 ; mm2=tmp10H
  473. psubd mm4, mm5 ; mm4=tmp13H
  474. movq MMWORD [wk(0)], mm7 ; wk(0)=tmp10L
  475. movq MMWORD [wk(1)], mm2 ; wk(1)=tmp10H
  476. movq MMWORD [wk(2)], mm0 ; wk(2)=tmp13L
  477. movq MMWORD [wk(3)], mm4 ; wk(3)=tmp13H
  478. pxor mm5, mm5
  479. pxor mm7, mm7
  480. punpcklwd mm5, mm6 ; mm5=tmp1L
  481. punpckhwd mm7, mm6 ; mm7=tmp1H
  482. psrad mm5, (16-CONST_BITS) ; psrad mm5,16 & pslld mm5,CONST_BITS
  483. psrad mm7, (16-CONST_BITS) ; psrad mm7,16 & pslld mm7,CONST_BITS
  484. movq mm2, mm5
  485. paddd mm5, mm1 ; mm5=tmp11L
  486. psubd mm2, mm1 ; mm2=tmp12L
  487. movq mm0, mm7
  488. paddd mm7, mm3 ; mm7=tmp11H
  489. psubd mm0, mm3 ; mm0=tmp12H
  490. movq MMWORD [wk(4)], mm5 ; wk(4)=tmp11L
  491. movq MMWORD [wk(5)], mm7 ; wk(5)=tmp11H
  492. movq MMWORD [wk(6)], mm2 ; wk(6)=tmp12L
  493. movq MMWORD [wk(7)], mm0 ; wk(7)=tmp12H
  494. ; -- Odd part
  495. movq mm4, MMWORD [MMBLOCK(1,0,esi,SIZEOF_JCOEF)]
  496. movq mm6, MMWORD [MMBLOCK(3,0,esi,SIZEOF_JCOEF)]
  497. movq mm1, MMWORD [MMBLOCK(5,0,esi,SIZEOF_JCOEF)]
  498. movq mm3, MMWORD [MMBLOCK(7,0,esi,SIZEOF_JCOEF)]
  499. movq mm5, mm6
  500. movq mm7, mm4
  501. paddw mm5, mm3 ; mm5=z3
  502. paddw mm7, mm1 ; mm7=z4
  503. ; (Original)
  504. ; z5 = (z3 + z4) * 1.175875602;
  505. ; z3 = z3 * -1.961570560; z4 = z4 * -0.390180644;
  506. ; z3 += z5; z4 += z5;
  507. ;
  508. ; (This implementation)
  509. ; z3 = z3 * (1.175875602 - 1.961570560) + z4 * 1.175875602;
  510. ; z4 = z3 * 1.175875602 + z4 * (1.175875602 - 0.390180644);
  511. movq mm2, mm5
  512. movq mm0, mm5
  513. punpcklwd mm2, mm7
  514. punpckhwd mm0, mm7
  515. movq mm5, mm2
  516. movq mm7, mm0
  517. pmaddwd mm2, [GOTOFF(ebx,PW_MF078_F117)] ; mm2=z3L
  518. pmaddwd mm0, [GOTOFF(ebx,PW_MF078_F117)] ; mm0=z3H
  519. pmaddwd mm5, [GOTOFF(ebx,PW_F117_F078)] ; mm5=z4L
  520. pmaddwd mm7, [GOTOFF(ebx,PW_F117_F078)] ; mm7=z4H
  521. movq MMWORD [wk(10)], mm2 ; wk(10)=z3L
  522. movq MMWORD [wk(11)], mm0 ; wk(11)=z3H
  523. ; (Original)
  524. ; z1 = tmp0 + tmp3; z2 = tmp1 + tmp2;
  525. ; tmp0 = tmp0 * 0.298631336; tmp1 = tmp1 * 2.053119869;
  526. ; tmp2 = tmp2 * 3.072711026; tmp3 = tmp3 * 1.501321110;
  527. ; z1 = z1 * -0.899976223; z2 = z2 * -2.562915447;
  528. ; tmp0 += z1 + z3; tmp1 += z2 + z4;
  529. ; tmp2 += z2 + z3; tmp3 += z1 + z4;
  530. ;
  531. ; (This implementation)
  532. ; tmp0 = tmp0 * (0.298631336 - 0.899976223) + tmp3 * -0.899976223;
  533. ; tmp1 = tmp1 * (2.053119869 - 2.562915447) + tmp2 * -2.562915447;
  534. ; tmp2 = tmp1 * -2.562915447 + tmp2 * (3.072711026 - 2.562915447);
  535. ; tmp3 = tmp0 * -0.899976223 + tmp3 * (1.501321110 - 0.899976223);
  536. ; tmp0 += z3; tmp1 += z4;
  537. ; tmp2 += z3; tmp3 += z4;
  538. movq mm2, mm3
  539. movq mm0, mm3
  540. punpcklwd mm2, mm4
  541. punpckhwd mm0, mm4
  542. movq mm3, mm2
  543. movq mm4, mm0
  544. pmaddwd mm2, [GOTOFF(ebx,PW_MF060_MF089)] ; mm2=tmp0L
  545. pmaddwd mm0, [GOTOFF(ebx,PW_MF060_MF089)] ; mm0=tmp0H
  546. pmaddwd mm3, [GOTOFF(ebx,PW_MF089_F060)] ; mm3=tmp3L
  547. pmaddwd mm4, [GOTOFF(ebx,PW_MF089_F060)] ; mm4=tmp3H
  548. paddd mm2, MMWORD [wk(10)] ; mm2=tmp0L
  549. paddd mm0, MMWORD [wk(11)] ; mm0=tmp0H
  550. paddd mm3, mm5 ; mm3=tmp3L
  551. paddd mm4, mm7 ; mm4=tmp3H
  552. movq MMWORD [wk(8)], mm2 ; wk(8)=tmp0L
  553. movq MMWORD [wk(9)], mm0 ; wk(9)=tmp0H
  554. movq mm2, mm1
  555. movq mm0, mm1
  556. punpcklwd mm2, mm6
  557. punpckhwd mm0, mm6
  558. movq mm1, mm2
  559. movq mm6, mm0
  560. pmaddwd mm2, [GOTOFF(ebx,PW_MF050_MF256)] ; mm2=tmp1L
  561. pmaddwd mm0, [GOTOFF(ebx,PW_MF050_MF256)] ; mm0=tmp1H
  562. pmaddwd mm1, [GOTOFF(ebx,PW_MF256_F050)] ; mm1=tmp2L
  563. pmaddwd mm6, [GOTOFF(ebx,PW_MF256_F050)] ; mm6=tmp2H
  564. paddd mm2, mm5 ; mm2=tmp1L
  565. paddd mm0, mm7 ; mm0=tmp1H
  566. paddd mm1, MMWORD [wk(10)] ; mm1=tmp2L
  567. paddd mm6, MMWORD [wk(11)] ; mm6=tmp2H
  568. movq MMWORD [wk(10)], mm2 ; wk(10)=tmp1L
  569. movq MMWORD [wk(11)], mm0 ; wk(11)=tmp1H
  570. ; -- Final output stage
  571. movq mm5, MMWORD [wk(0)] ; mm5=tmp10L
  572. movq mm7, MMWORD [wk(1)] ; mm7=tmp10H
  573. movq mm2, mm5
  574. movq mm0, mm7
  575. paddd mm5, mm3 ; mm5=data0L
  576. paddd mm7, mm4 ; mm7=data0H
  577. psubd mm2, mm3 ; mm2=data7L
  578. psubd mm0, mm4 ; mm0=data7H
  579. movq mm3, [GOTOFF(ebx,PD_DESCALE_P2)] ; mm3=[PD_DESCALE_P2]
  580. paddd mm5, mm3
  581. paddd mm7, mm3
  582. psrad mm5, DESCALE_P2
  583. psrad mm7, DESCALE_P2
  584. paddd mm2, mm3
  585. paddd mm0, mm3
  586. psrad mm2, DESCALE_P2
  587. psrad mm0, DESCALE_P2
  588. packssdw mm5, mm7 ; mm5=data0=(00 10 20 30)
  589. packssdw mm2, mm0 ; mm2=data7=(07 17 27 37)
  590. movq mm4, MMWORD [wk(4)] ; mm4=tmp11L
  591. movq mm3, MMWORD [wk(5)] ; mm3=tmp11H
  592. movq mm7, mm4
  593. movq mm0, mm3
  594. paddd mm4, mm1 ; mm4=data1L
  595. paddd mm3, mm6 ; mm3=data1H
  596. psubd mm7, mm1 ; mm7=data6L
  597. psubd mm0, mm6 ; mm0=data6H
  598. movq mm1, [GOTOFF(ebx,PD_DESCALE_P2)] ; mm1=[PD_DESCALE_P2]
  599. paddd mm4, mm1
  600. paddd mm3, mm1
  601. psrad mm4, DESCALE_P2
  602. psrad mm3, DESCALE_P2
  603. paddd mm7, mm1
  604. paddd mm0, mm1
  605. psrad mm7, DESCALE_P2
  606. psrad mm0, DESCALE_P2
  607. packssdw mm4, mm3 ; mm4=data1=(01 11 21 31)
  608. packssdw mm7, mm0 ; mm7=data6=(06 16 26 36)
  609. packsswb mm5, mm7 ; mm5=(00 10 20 30 06 16 26 36)
  610. packsswb mm4, mm2 ; mm4=(01 11 21 31 07 17 27 37)
  611. movq mm6, MMWORD [wk(6)] ; mm6=tmp12L
  612. movq mm1, MMWORD [wk(7)] ; mm1=tmp12H
  613. movq mm3, MMWORD [wk(10)] ; mm3=tmp1L
  614. movq mm0, MMWORD [wk(11)] ; mm0=tmp1H
  615. movq MMWORD [wk(0)], mm5 ; wk(0)=(00 10 20 30 06 16 26 36)
  616. movq MMWORD [wk(1)], mm4 ; wk(1)=(01 11 21 31 07 17 27 37)
  617. movq mm7, mm6
  618. movq mm2, mm1
  619. paddd mm6, mm3 ; mm6=data2L
  620. paddd mm1, mm0 ; mm1=data2H
  621. psubd mm7, mm3 ; mm7=data5L
  622. psubd mm2, mm0 ; mm2=data5H
  623. movq mm5, [GOTOFF(ebx,PD_DESCALE_P2)] ; mm5=[PD_DESCALE_P2]
  624. paddd mm6, mm5
  625. paddd mm1, mm5
  626. psrad mm6, DESCALE_P2
  627. psrad mm1, DESCALE_P2
  628. paddd mm7, mm5
  629. paddd mm2, mm5
  630. psrad mm7, DESCALE_P2
  631. psrad mm2, DESCALE_P2
  632. packssdw mm6, mm1 ; mm6=data2=(02 12 22 32)
  633. packssdw mm7, mm2 ; mm7=data5=(05 15 25 35)
  634. movq mm4, MMWORD [wk(2)] ; mm4=tmp13L
  635. movq mm3, MMWORD [wk(3)] ; mm3=tmp13H
  636. movq mm0, MMWORD [wk(8)] ; mm0=tmp0L
  637. movq mm5, MMWORD [wk(9)] ; mm5=tmp0H
  638. movq mm1, mm4
  639. movq mm2, mm3
  640. paddd mm4, mm0 ; mm4=data3L
  641. paddd mm3, mm5 ; mm3=data3H
  642. psubd mm1, mm0 ; mm1=data4L
  643. psubd mm2, mm5 ; mm2=data4H
  644. movq mm0, [GOTOFF(ebx,PD_DESCALE_P2)] ; mm0=[PD_DESCALE_P2]
  645. paddd mm4, mm0
  646. paddd mm3, mm0
  647. psrad mm4, DESCALE_P2
  648. psrad mm3, DESCALE_P2
  649. paddd mm1, mm0
  650. paddd mm2, mm0
  651. psrad mm1, DESCALE_P2
  652. psrad mm2, DESCALE_P2
  653. movq mm5, [GOTOFF(ebx,PB_CENTERJSAMP)] ; mm5=[PB_CENTERJSAMP]
  654. packssdw mm4, mm3 ; mm4=data3=(03 13 23 33)
  655. packssdw mm1, mm2 ; mm1=data4=(04 14 24 34)
  656. movq mm0, MMWORD [wk(0)] ; mm0=(00 10 20 30 06 16 26 36)
  657. movq mm3, MMWORD [wk(1)] ; mm3=(01 11 21 31 07 17 27 37)
  658. packsswb mm6, mm1 ; mm6=(02 12 22 32 04 14 24 34)
  659. packsswb mm4, mm7 ; mm4=(03 13 23 33 05 15 25 35)
  660. paddb mm0, mm5
  661. paddb mm3, mm5
  662. paddb mm6, mm5
  663. paddb mm4, mm5
  664. movq mm2, mm0 ; transpose coefficients(phase 1)
  665. punpcklbw mm0, mm3 ; mm0=(00 01 10 11 20 21 30 31)
  666. punpckhbw mm2, mm3 ; mm2=(06 07 16 17 26 27 36 37)
  667. movq mm1, mm6 ; transpose coefficients(phase 1)
  668. punpcklbw mm6, mm4 ; mm6=(02 03 12 13 22 23 32 33)
  669. punpckhbw mm1, mm4 ; mm1=(04 05 14 15 24 25 34 35)
  670. movq mm7, mm0 ; transpose coefficients(phase 2)
  671. punpcklwd mm0, mm6 ; mm0=(00 01 02 03 10 11 12 13)
  672. punpckhwd mm7, mm6 ; mm7=(20 21 22 23 30 31 32 33)
  673. movq mm5, mm1 ; transpose coefficients(phase 2)
  674. punpcklwd mm1, mm2 ; mm1=(04 05 06 07 14 15 16 17)
  675. punpckhwd mm5, mm2 ; mm5=(24 25 26 27 34 35 36 37)
  676. movq mm3, mm0 ; transpose coefficients(phase 3)
  677. punpckldq mm0, mm1 ; mm0=(00 01 02 03 04 05 06 07)
  678. punpckhdq mm3, mm1 ; mm3=(10 11 12 13 14 15 16 17)
  679. movq mm4, mm7 ; transpose coefficients(phase 3)
  680. punpckldq mm7, mm5 ; mm7=(20 21 22 23 24 25 26 27)
  681. punpckhdq mm4, mm5 ; mm4=(30 31 32 33 34 35 36 37)
  682. pushpic ebx ; save GOT address
  683. mov edx, JSAMPROW [edi+0*SIZEOF_JSAMPROW]
  684. mov ebx, JSAMPROW [edi+1*SIZEOF_JSAMPROW]
  685. movq MMWORD [edx+eax*SIZEOF_JSAMPLE], mm0
  686. movq MMWORD [ebx+eax*SIZEOF_JSAMPLE], mm3
  687. mov edx, JSAMPROW [edi+2*SIZEOF_JSAMPROW]
  688. mov ebx, JSAMPROW [edi+3*SIZEOF_JSAMPROW]
  689. movq MMWORD [edx+eax*SIZEOF_JSAMPLE], mm7
  690. movq MMWORD [ebx+eax*SIZEOF_JSAMPLE], mm4
  691. poppic ebx ; restore GOT address
  692. add esi, byte 4*SIZEOF_JCOEF ; wsptr
  693. add edi, byte 4*SIZEOF_JSAMPROW
  694. dec ecx ; ctr
  695. jnz near .rowloop
  696. emms ; empty MMX state
  697. pop edi
  698. pop esi
  699. ; pop edx ; need not be preserved
  700. ; pop ecx ; need not be preserved
  701. pop ebx
  702. mov esp, ebp ; esp <- aligned ebp
  703. pop esp ; esp <- original ebp
  704. pop ebp
  705. ret
  706. ; For some reason, the OS X linker does not honor the request to align the
  707. ; segment unless we do this.
  708. align 32