audio_convert.asm 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468
  1. ;******************************************************************************
  2. ;* Copyright (c) 2012 Michael Niedermayer
  3. ;*
  4. ;* This file is part of FFmpeg.
  5. ;*
  6. ;* FFmpeg is free software; you can redistribute it and/or
  7. ;* modify it under the terms of the GNU Lesser General Public
  8. ;* License as published by the Free Software Foundation; either
  9. ;* version 2.1 of the License, or (at your option) any later version.
  10. ;*
  11. ;* FFmpeg is distributed in the hope that it will be useful,
  12. ;* but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. ;* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  14. ;* Lesser General Public License for more details.
  15. ;*
  16. ;* You should have received a copy of the GNU Lesser General Public
  17. ;* License along with FFmpeg; if not, write to the Free Software
  18. ;* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
  19. ;******************************************************************************
  20. %include "libavutil/x86/x86inc.asm"
  21. %include "libavutil/x86/x86util.asm"
  22. SECTION_RODATA
  23. align 32
  24. flt2pm31: times 8 dd 4.6566129e-10
  25. flt2p31 : times 8 dd 2147483648.0
  26. flt2p15 : times 8 dd 32768.0
  27. word_unpack_shuf : db 0, 1, 4, 5, 8, 9,12,13, 2, 3, 6, 7,10,11,14,15
  28. SECTION .text
  29. ;to, from, a/u, log2_outsize, log_intsize, const
  30. %macro PACK_2CH 5-7
  31. cglobal pack_2ch_%2_to_%1_%3, 3, 4, 6, dst, src, len, src2
  32. mov src2q , [srcq+gprsize]
  33. mov srcq , [srcq]
  34. mov dstq , [dstq]
  35. %ifidn %3, a
  36. test dstq, mmsize-1
  37. jne pack_2ch_%2_to_%1_u_int %+ SUFFIX
  38. test srcq, mmsize-1
  39. jne pack_2ch_%2_to_%1_u_int %+ SUFFIX
  40. test src2q, mmsize-1
  41. jne pack_2ch_%2_to_%1_u_int %+ SUFFIX
  42. %else
  43. pack_2ch_%2_to_%1_u_int %+ SUFFIX
  44. %endif
  45. lea srcq , [srcq + (1<<%5)*lenq]
  46. lea src2q, [src2q + (1<<%5)*lenq]
  47. lea dstq , [dstq + (2<<%4)*lenq]
  48. neg lenq
  49. %7 m0,m1,m2,m3,m4,m5
  50. .next:
  51. %if %4 >= %5
  52. mov%3 m0, [ srcq +(1<<%5)*lenq]
  53. mova m1, m0
  54. mov%3 m2, [ src2q+(1<<%5)*lenq]
  55. %if %5 == 1
  56. punpcklwd m0, m2
  57. punpckhwd m1, m2
  58. %else
  59. punpckldq m0, m2
  60. punpckhdq m1, m2
  61. %endif
  62. %6 m0,m1,m2,m3,m4,m5
  63. %else
  64. mov%3 m0, [ srcq +(1<<%5)*lenq]
  65. mov%3 m1, [mmsize + srcq +(1<<%5)*lenq]
  66. mov%3 m2, [ src2q+(1<<%5)*lenq]
  67. mov%3 m3, [mmsize + src2q+(1<<%5)*lenq]
  68. %6 m0,m1,m2,m3,m4,m5
  69. mova m2, m0
  70. punpcklwd m0, m1
  71. punpckhwd m2, m1
  72. SWAP 1,2
  73. %endif
  74. mov%3 [ dstq+(2<<%4)*lenq], m0
  75. mov%3 [ mmsize + dstq+(2<<%4)*lenq], m1
  76. %if %4 > %5
  77. mov%3 [2*mmsize + dstq+(2<<%4)*lenq], m2
  78. mov%3 [3*mmsize + dstq+(2<<%4)*lenq], m3
  79. add lenq, 4*mmsize/(2<<%4)
  80. %else
  81. add lenq, 2*mmsize/(2<<%4)
  82. %endif
  83. jl .next
  84. REP_RET
  85. %endmacro
  86. %macro UNPACK_2CH 5-7
  87. cglobal unpack_2ch_%2_to_%1_%3, 3, 4, 7, dst, src, len, dst2
  88. mov dst2q , [dstq+gprsize]
  89. mov srcq , [srcq]
  90. mov dstq , [dstq]
  91. %ifidn %3, a
  92. test dstq, mmsize-1
  93. jne unpack_2ch_%2_to_%1_u_int %+ SUFFIX
  94. test srcq, mmsize-1
  95. jne unpack_2ch_%2_to_%1_u_int %+ SUFFIX
  96. test dst2q, mmsize-1
  97. jne unpack_2ch_%2_to_%1_u_int %+ SUFFIX
  98. %else
  99. unpack_2ch_%2_to_%1_u_int %+ SUFFIX
  100. %endif
  101. lea srcq , [srcq + (2<<%5)*lenq]
  102. lea dstq , [dstq + (1<<%4)*lenq]
  103. lea dst2q, [dst2q + (1<<%4)*lenq]
  104. neg lenq
  105. %7 m0,m1,m2,m3,m4,m5
  106. mova m6, [word_unpack_shuf]
  107. .next:
  108. mov%3 m0, [ srcq +(2<<%5)*lenq]
  109. mov%3 m2, [ mmsize + srcq +(2<<%5)*lenq]
  110. %if %5 == 1
  111. %ifidn SUFFIX, _ssse3
  112. pshufb m0, m6
  113. mova m1, m0
  114. pshufb m2, m6
  115. punpcklqdq m0,m2
  116. punpckhqdq m1,m2
  117. %else
  118. mova m1, m0
  119. punpcklwd m0,m2
  120. punpckhwd m1,m2
  121. mova m2, m0
  122. punpcklwd m0,m1
  123. punpckhwd m2,m1
  124. mova m1, m0
  125. punpcklwd m0,m2
  126. punpckhwd m1,m2
  127. %endif
  128. %else
  129. mova m1, m0
  130. shufps m0, m2, 10001000b
  131. shufps m1, m2, 11011101b
  132. %endif
  133. %if %4 < %5
  134. mov%3 m2, [2*mmsize + srcq +(2<<%5)*lenq]
  135. mova m3, m2
  136. mov%3 m4, [3*mmsize + srcq +(2<<%5)*lenq]
  137. shufps m2, m4, 10001000b
  138. shufps m3, m4, 11011101b
  139. SWAP 1,2
  140. %endif
  141. %6 m0,m1,m2,m3,m4,m5
  142. mov%3 [ dstq+(1<<%4)*lenq], m0
  143. %if %4 > %5
  144. mov%3 [ dst2q+(1<<%4)*lenq], m2
  145. mov%3 [ mmsize + dstq+(1<<%4)*lenq], m1
  146. mov%3 [ mmsize + dst2q+(1<<%4)*lenq], m3
  147. add lenq, 2*mmsize/(1<<%4)
  148. %else
  149. mov%3 [ dst2q+(1<<%4)*lenq], m1
  150. add lenq, mmsize/(1<<%4)
  151. %endif
  152. jl .next
  153. REP_RET
  154. %endmacro
  155. %macro CONV 5-7
  156. cglobal %2_to_%1_%3, 3, 3, 6, dst, src, len
  157. mov srcq , [srcq]
  158. mov dstq , [dstq]
  159. %ifidn %3, a
  160. test dstq, mmsize-1
  161. jne %2_to_%1_u_int %+ SUFFIX
  162. test srcq, mmsize-1
  163. jne %2_to_%1_u_int %+ SUFFIX
  164. %else
  165. %2_to_%1_u_int %+ SUFFIX
  166. %endif
  167. lea srcq , [srcq + (1<<%5)*lenq]
  168. lea dstq , [dstq + (1<<%4)*lenq]
  169. neg lenq
  170. %7 m0,m1,m2,m3,m4,m5
  171. .next:
  172. mov%3 m0, [ srcq +(1<<%5)*lenq]
  173. mov%3 m1, [ mmsize + srcq +(1<<%5)*lenq]
  174. %if %4 < %5
  175. mov%3 m2, [2*mmsize + srcq +(1<<%5)*lenq]
  176. mov%3 m3, [3*mmsize + srcq +(1<<%5)*lenq]
  177. %endif
  178. %6 m0,m1,m2,m3,m4,m5
  179. mov%3 [ dstq+(1<<%4)*lenq], m0
  180. mov%3 [ mmsize + dstq+(1<<%4)*lenq], m1
  181. %if %4 > %5
  182. mov%3 [2*mmsize + dstq+(1<<%4)*lenq], m2
  183. mov%3 [3*mmsize + dstq+(1<<%4)*lenq], m3
  184. add lenq, 4*mmsize/(1<<%4)
  185. %else
  186. add lenq, 2*mmsize/(1<<%4)
  187. %endif
  188. jl .next
  189. %if mmsize == 8
  190. emms
  191. RET
  192. %else
  193. REP_RET
  194. %endif
  195. %endmacro
  196. %macro PACK_6CH 5-7
  197. cglobal pack_6ch_%2_to_%1_%3, 2,8,7, dst, src, src1, src2, src3, src4, src5, len
  198. %if ARCH_X86_64
  199. mov lend, r2d
  200. %else
  201. %define lend dword r2m
  202. %endif
  203. mov src1q, [srcq+1*gprsize]
  204. mov src2q, [srcq+2*gprsize]
  205. mov src3q, [srcq+3*gprsize]
  206. mov src4q, [srcq+4*gprsize]
  207. mov src5q, [srcq+5*gprsize]
  208. mov srcq, [srcq]
  209. mov dstq, [dstq]
  210. %ifidn %3, a
  211. test dstq, mmsize-1
  212. jne pack_6ch_%2_to_%1_u_int %+ SUFFIX
  213. test srcq, mmsize-1
  214. jne pack_6ch_%2_to_%1_u_int %+ SUFFIX
  215. test src2q, mmsize-1
  216. jne pack_6ch_%2_to_%1_u_int %+ SUFFIX
  217. test src3q, mmsize-1
  218. jne pack_6ch_%2_to_%1_u_int %+ SUFFIX
  219. test src4q, mmsize-1
  220. jne pack_6ch_%2_to_%1_u_int %+ SUFFIX
  221. test src5q, mmsize-1
  222. jne pack_6ch_%2_to_%1_u_int %+ SUFFIX
  223. %else
  224. pack_6ch_%2_to_%1_u_int %+ SUFFIX
  225. %endif
  226. sub src1q, srcq
  227. sub src2q, srcq
  228. sub src3q, srcq
  229. sub src4q, srcq
  230. sub src5q, srcq
  231. .loop:
  232. mov%3 m0, [srcq ]
  233. mov%3 m1, [srcq+src1q]
  234. mov%3 m2, [srcq+src2q]
  235. mov%3 m3, [srcq+src3q]
  236. mov%3 m4, [srcq+src4q]
  237. mov%3 m5, [srcq+src5q]
  238. %7 x,x,x,x,m7,x
  239. %if cpuflag(sse4)
  240. SBUTTERFLYPS 0, 1, 6
  241. SBUTTERFLYPS 2, 3, 6
  242. SBUTTERFLYPS 4, 5, 6
  243. blendps m6, m4, m0, 1100b
  244. movlhps m0, m2
  245. movhlps m4, m2
  246. blendps m2, m5, m1, 1100b
  247. movlhps m1, m3
  248. movhlps m5, m3
  249. %6 m0,m6,x,x,m7,m3
  250. %6 m4,m1,x,x,m7,m3
  251. %6 m2,m5,x,x,m7,m3
  252. mov %+ %3 %+ ps [dstq ], m0
  253. mov %+ %3 %+ ps [dstq+16], m6
  254. mov %+ %3 %+ ps [dstq+32], m4
  255. mov %+ %3 %+ ps [dstq+48], m1
  256. mov %+ %3 %+ ps [dstq+64], m2
  257. mov %+ %3 %+ ps [dstq+80], m5
  258. %else ; mmx
  259. SBUTTERFLY dq, 0, 1, 6
  260. SBUTTERFLY dq, 2, 3, 6
  261. SBUTTERFLY dq, 4, 5, 6
  262. movq [dstq ], m0
  263. movq [dstq+ 8], m2
  264. movq [dstq+16], m4
  265. movq [dstq+24], m1
  266. movq [dstq+32], m3
  267. movq [dstq+40], m5
  268. %endif
  269. add srcq, mmsize
  270. add dstq, mmsize*6
  271. sub lend, mmsize/4
  272. jg .loop
  273. %if mmsize == 8
  274. emms
  275. RET
  276. %else
  277. REP_RET
  278. %endif
  279. %endmacro
  280. %macro INT16_TO_INT32_N 6
  281. pxor m2, m2
  282. pxor m3, m3
  283. punpcklwd m2, m1
  284. punpckhwd m3, m1
  285. SWAP 4,0
  286. pxor m0, m0
  287. pxor m1, m1
  288. punpcklwd m0, m4
  289. punpckhwd m1, m4
  290. %endmacro
  291. %macro INT32_TO_INT16_N 6
  292. psrad m0, 16
  293. psrad m1, 16
  294. psrad m2, 16
  295. psrad m3, 16
  296. packssdw m0, m1
  297. packssdw m2, m3
  298. SWAP 1,2
  299. %endmacro
  300. %macro INT32_TO_FLOAT_INIT 6
  301. mova %5, [flt2pm31]
  302. %endmacro
  303. %macro INT32_TO_FLOAT_N 6
  304. cvtdq2ps %1, %1
  305. cvtdq2ps %2, %2
  306. mulps %1, %1, %5
  307. mulps %2, %2, %5
  308. %endmacro
  309. %macro FLOAT_TO_INT32_INIT 6
  310. mova %5, [flt2p31]
  311. %endmacro
  312. %macro FLOAT_TO_INT32_N 6
  313. mulps %1, %5
  314. mulps %2, %5
  315. cvtps2dq %6, %1
  316. cmpnltps %1, %5
  317. paddd %1, %6
  318. cvtps2dq %6, %2
  319. cmpnltps %2, %5
  320. paddd %2, %6
  321. %endmacro
  322. %macro INT16_TO_FLOAT_INIT 6
  323. mova m5, [flt2pm31]
  324. %endmacro
  325. %macro INT16_TO_FLOAT_N 6
  326. INT16_TO_INT32_N %1,%2,%3,%4,%5,%6
  327. cvtdq2ps m0, m0
  328. cvtdq2ps m1, m1
  329. cvtdq2ps m2, m2
  330. cvtdq2ps m3, m3
  331. mulps m0, m0, m5
  332. mulps m1, m1, m5
  333. mulps m2, m2, m5
  334. mulps m3, m3, m5
  335. %endmacro
  336. %macro FLOAT_TO_INT16_INIT 6
  337. mova m5, [flt2p15]
  338. %endmacro
  339. %macro FLOAT_TO_INT16_N 6
  340. mulps m0, m5
  341. mulps m1, m5
  342. mulps m2, m5
  343. mulps m3, m5
  344. cvtps2dq m0, m0
  345. cvtps2dq m1, m1
  346. packssdw m0, m1
  347. cvtps2dq m1, m2
  348. cvtps2dq m3, m3
  349. packssdw m1, m3
  350. %endmacro
  351. %macro NOP_N 0-6
  352. %endmacro
  353. INIT_MMX mmx
  354. CONV int32, int16, u, 2, 1, INT16_TO_INT32_N, NOP_N
  355. CONV int32, int16, a, 2, 1, INT16_TO_INT32_N, NOP_N
  356. CONV int16, int32, u, 1, 2, INT32_TO_INT16_N, NOP_N
  357. CONV int16, int32, a, 1, 2, INT32_TO_INT16_N, NOP_N
  358. PACK_6CH float, float, u, 2, 2, NOP_N, NOP_N
  359. PACK_6CH float, float, a, 2, 2, NOP_N, NOP_N
  360. INIT_XMM sse
  361. CONV int32, int16, u, 2, 1, INT16_TO_INT32_N, NOP_N
  362. CONV int32, int16, a, 2, 1, INT16_TO_INT32_N, NOP_N
  363. CONV int16, int32, u, 1, 2, INT32_TO_INT16_N, NOP_N
  364. CONV int16, int32, a, 1, 2, INT32_TO_INT16_N, NOP_N
  365. PACK_2CH int16, int16, u, 1, 1, NOP_N, NOP_N
  366. PACK_2CH int16, int16, a, 1, 1, NOP_N, NOP_N
  367. PACK_2CH int32, int32, u, 2, 2, NOP_N, NOP_N
  368. PACK_2CH int32, int32, a, 2, 2, NOP_N, NOP_N
  369. PACK_2CH int32, int16, u, 2, 1, INT16_TO_INT32_N, NOP_N
  370. PACK_2CH int32, int16, a, 2, 1, INT16_TO_INT32_N, NOP_N
  371. PACK_2CH int16, int32, u, 1, 2, INT32_TO_INT16_N, NOP_N
  372. PACK_2CH int16, int32, a, 1, 2, INT32_TO_INT16_N, NOP_N
  373. UNPACK_2CH int16, int16, u, 1, 1, NOP_N, NOP_N
  374. UNPACK_2CH int16, int16, a, 1, 1, NOP_N, NOP_N
  375. UNPACK_2CH int32, int32, u, 2, 2, NOP_N, NOP_N
  376. UNPACK_2CH int32, int32, a, 2, 2, NOP_N, NOP_N
  377. UNPACK_2CH int32, int16, u, 2, 1, INT16_TO_INT32_N, NOP_N
  378. UNPACK_2CH int32, int16, a, 2, 1, INT16_TO_INT32_N, NOP_N
  379. UNPACK_2CH int16, int32, u, 1, 2, INT32_TO_INT16_N, NOP_N
  380. UNPACK_2CH int16, int32, a, 1, 2, INT32_TO_INT16_N, NOP_N
  381. INIT_XMM sse2
  382. CONV float, int32, u, 2, 2, INT32_TO_FLOAT_N, INT32_TO_FLOAT_INIT
  383. CONV float, int32, a, 2, 2, INT32_TO_FLOAT_N, INT32_TO_FLOAT_INIT
  384. CONV int32, float, u, 2, 2, FLOAT_TO_INT32_N, FLOAT_TO_INT32_INIT
  385. CONV int32, float, a, 2, 2, FLOAT_TO_INT32_N, FLOAT_TO_INT32_INIT
  386. CONV float, int16, u, 2, 1, INT16_TO_FLOAT_N, INT16_TO_FLOAT_INIT
  387. CONV float, int16, a, 2, 1, INT16_TO_FLOAT_N, INT16_TO_FLOAT_INIT
  388. CONV int16, float, u, 1, 2, FLOAT_TO_INT16_N, FLOAT_TO_INT16_INIT
  389. CONV int16, float, a, 1, 2, FLOAT_TO_INT16_N, FLOAT_TO_INT16_INIT
  390. PACK_2CH float, int32, u, 2, 2, INT32_TO_FLOAT_N, INT32_TO_FLOAT_INIT
  391. PACK_2CH float, int32, a, 2, 2, INT32_TO_FLOAT_N, INT32_TO_FLOAT_INIT
  392. PACK_2CH int32, float, u, 2, 2, FLOAT_TO_INT32_N, FLOAT_TO_INT32_INIT
  393. PACK_2CH int32, float, a, 2, 2, FLOAT_TO_INT32_N, FLOAT_TO_INT32_INIT
  394. PACK_2CH float, int16, u, 2, 1, INT16_TO_FLOAT_N, INT16_TO_FLOAT_INIT
  395. PACK_2CH float, int16, a, 2, 1, INT16_TO_FLOAT_N, INT16_TO_FLOAT_INIT
  396. PACK_2CH int16, float, u, 1, 2, FLOAT_TO_INT16_N, FLOAT_TO_INT16_INIT
  397. PACK_2CH int16, float, a, 1, 2, FLOAT_TO_INT16_N, FLOAT_TO_INT16_INIT
  398. UNPACK_2CH float, int32, u, 2, 2, INT32_TO_FLOAT_N, INT32_TO_FLOAT_INIT
  399. UNPACK_2CH float, int32, a, 2, 2, INT32_TO_FLOAT_N, INT32_TO_FLOAT_INIT
  400. UNPACK_2CH int32, float, u, 2, 2, FLOAT_TO_INT32_N, FLOAT_TO_INT32_INIT
  401. UNPACK_2CH int32, float, a, 2, 2, FLOAT_TO_INT32_N, FLOAT_TO_INT32_INIT
  402. UNPACK_2CH float, int16, u, 2, 1, INT16_TO_FLOAT_N, INT16_TO_FLOAT_INIT
  403. UNPACK_2CH float, int16, a, 2, 1, INT16_TO_FLOAT_N, INT16_TO_FLOAT_INIT
  404. UNPACK_2CH int16, float, u, 1, 2, FLOAT_TO_INT16_N, FLOAT_TO_INT16_INIT
  405. UNPACK_2CH int16, float, a, 1, 2, FLOAT_TO_INT16_N, FLOAT_TO_INT16_INIT
  406. INIT_XMM ssse3
  407. UNPACK_2CH int16, int16, u, 1, 1, NOP_N, NOP_N
  408. UNPACK_2CH int16, int16, a, 1, 1, NOP_N, NOP_N
  409. UNPACK_2CH int32, int16, u, 2, 1, INT16_TO_INT32_N, NOP_N
  410. UNPACK_2CH int32, int16, a, 2, 1, INT16_TO_INT32_N, NOP_N
  411. UNPACK_2CH float, int16, u, 2, 1, INT16_TO_FLOAT_N, INT16_TO_FLOAT_INIT
  412. UNPACK_2CH float, int16, a, 2, 1, INT16_TO_FLOAT_N, INT16_TO_FLOAT_INIT
  413. INIT_XMM sse4
  414. PACK_6CH float, float, u, 2, 2, NOP_N, NOP_N
  415. PACK_6CH float, float, a, 2, 2, NOP_N, NOP_N
  416. PACK_6CH float, int32, u, 2, 2, INT32_TO_FLOAT_N, INT32_TO_FLOAT_INIT
  417. PACK_6CH float, int32, a, 2, 2, INT32_TO_FLOAT_N, INT32_TO_FLOAT_INIT
  418. PACK_6CH int32, float, u, 2, 2, FLOAT_TO_INT32_N, FLOAT_TO_INT32_INIT
  419. PACK_6CH int32, float, a, 2, 2, FLOAT_TO_INT32_N, FLOAT_TO_INT32_INIT
  420. %if HAVE_AVX
  421. INIT_XMM avx
  422. PACK_6CH float, float, u, 2, 2, NOP_N, NOP_N
  423. PACK_6CH float, float, a, 2, 2, NOP_N, NOP_N
  424. PACK_6CH float, int32, u, 2, 2, INT32_TO_FLOAT_N, INT32_TO_FLOAT_INIT
  425. PACK_6CH float, int32, a, 2, 2, INT32_TO_FLOAT_N, INT32_TO_FLOAT_INIT
  426. PACK_6CH int32, float, u, 2, 2, FLOAT_TO_INT32_N, FLOAT_TO_INT32_INIT
  427. PACK_6CH int32, float, a, 2, 2, FLOAT_TO_INT32_N, FLOAT_TO_INT32_INIT
  428. INIT_YMM avx
  429. CONV float, int32, u, 2, 2, INT32_TO_FLOAT_N, INT32_TO_FLOAT_INIT
  430. CONV float, int32, a, 2, 2, INT32_TO_FLOAT_N, INT32_TO_FLOAT_INIT
  431. %endif