snow_altivec.c 23 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788
  1. /*
  2. * AltiVec-optimized snow DSP utils
  3. * Copyright (c) 2006 Luca Barbato <lu_zero@gentoo.org>
  4. *
  5. * This file is part of FFmpeg.
  6. *
  7. * FFmpeg is free software; you can redistribute it and/or
  8. * modify it under the terms of the GNU Lesser General Public
  9. * License as published by the Free Software Foundation; either
  10. * version 2.1 of the License, or (at your option) any later version.
  11. *
  12. * FFmpeg is distributed in the hope that it will be useful,
  13. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  14. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  15. * Lesser General Public License for more details.
  16. *
  17. * You should have received a copy of the GNU Lesser General Public
  18. * License along with FFmpeg; if not, write to the Free Software
  19. * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
  20. */
  21. #include "libavcodec/dsputil.h"
  22. #include "libavcodec/snow.h"
  23. #include "gcc_fixes.h"
  24. #include "dsputil_altivec.h"
  25. #undef NDEBUG
  26. #include <assert.h>
  27. //FIXME remove this replication
  28. #define slice_buffer_get_line(slice_buf, line_num) ((slice_buf)->line[line_num] ? (slice_buf)->line[line_num] : slice_buffer_load_line((slice_buf), (line_num)))
  29. static DWTELEM * slice_buffer_load_line(slice_buffer * buf, int line)
  30. {
  31. int offset;
  32. DWTELEM * buffer;
  33. // av_log(NULL, AV_LOG_DEBUG, "Cache hit: %d\n", line);
  34. assert(buf->data_stack_top >= 0);
  35. // assert(!buf->line[line]);
  36. if (buf->line[line])
  37. return buf->line[line];
  38. offset = buf->line_width * line;
  39. buffer = buf->data_stack[buf->data_stack_top];
  40. buf->data_stack_top--;
  41. buf->line[line] = buffer;
  42. // av_log(NULL, AV_LOG_DEBUG, "slice_buffer_load_line: line: %d remaining: %d\n", line, buf->data_stack_top + 1);
  43. return buffer;
  44. }
  45. //altivec code
  46. void ff_snow_horizontal_compose97i_altivec(IDWTELEM *b, int width)
  47. {
  48. #if 0
  49. const int w2= (width+1)>>1;
  50. DECLARE_ALIGNED_16(IDWTELEM, temp[(width>>1)]);
  51. const int w_l= (width>>1);
  52. const int w_r= w2 - 1;
  53. int i;
  54. vector signed short t1, t2, x, y, tmp1, tmp2;
  55. vector signed short *vbuf, *vtmp;
  56. vector unsigned char align;
  57. { // Lift 0
  58. IDWTELEM * const ref = b + w2 - 1;
  59. IDWTELEM b_0 = b[0];
  60. vector signed short v7 = vec_splat_s16(7);
  61. vbuf = (vector signed short *)b;
  62. tmp1 = vec_ld (0, ref);
  63. align = vec_lvsl (0, ref);
  64. tmp2 = vec_ld (15, ref);
  65. t1 = vec_perm(tmp1, tmp2, align);
  66. for (i=0; i<w_l-15; i+=16) {
  67. #if 0
  68. /* b[i+0] = b[i+0] - ((3 * (ref[i+0] + ref[i+1]) + 4) >> 3);
  69. b[i+1] = b[i+1] - ((3 * (ref[i+1] + ref[i+2]) + 4) >> 3);
  70. b[i+2] = b[i+2] - ((3 * (ref[i+2] + ref[i+3]) + 4) >> 3);
  71. b[i+3] = b[i+3] - ((3 * (ref[i+3] + ref[i+4]) + 4) >> 3);*/
  72. b[i+0] = b[i+0] + ((7 * (ref[i+0] + ref[i+1])-1) >> 8);
  73. #else
  74. tmp1 = vec_ld (0, ref+8+i);
  75. tmp2 = vec_ld (15, ref+8+i);
  76. t2 = vec_perm(tmp1, tmp2, align);
  77. y = vec_add(t1, vec_sld(t1,t2,2));
  78. // y = vec_add(vec_add(y,y),y);
  79. tmp1 = vec_ld (0, ref+12+i);
  80. y = vec_add(y, vec_splat_s32(4));
  81. y = vec_sra(y, vec_splat_u32(3));
  82. tmp2 = vec_ld (15, ref+12+i);
  83. *vbuf = vec_sub(*vbuf, y);
  84. t1 = t2;
  85. vbuf++;
  86. t2 = vec_perm(tmp1, tmp2, align);
  87. y = vec_add(t1,vec_sld(t1,t2,4));
  88. y = vec_add(vec_add(y,y),y);
  89. tmp1 = vec_ld (0, ref+12+i);
  90. y = vec_add(y, vec_splat_s32(4));
  91. y = vec_sra(y, vec_splat_u32(3));
  92. tmp2 = vec_ld (15, ref+12+i);
  93. *vbuf = vec_sub(*vbuf, y);
  94. t1=t2;
  95. vbuf++;
  96. t2 = vec_perm(tmp1, tmp2, align);
  97. y = vec_add(t1,vec_sld(t1,t2,4));
  98. y = vec_add(vec_add(y,y),y);
  99. tmp1 = vec_ld (0, ref+16+i);
  100. y = vec_add(y, vec_splat_s32(4));
  101. y = vec_sra(y, vec_splat_u32(3));
  102. tmp2 = vec_ld (15, ref+16+i);
  103. *vbuf = vec_sub(*vbuf, y);
  104. t1=t2;
  105. t2 = vec_perm(tmp1, tmp2, align);
  106. y = vec_add(t1,vec_sld(t1,t2,4));
  107. y = vec_add(vec_add(y,y),y);
  108. vbuf++;
  109. y = vec_add(y, vec_splat_s32(4));
  110. y = vec_sra(y, vec_splat_u32(3));
  111. *vbuf = vec_sub(*vbuf, y);
  112. t1=t2;
  113. vbuf++;
  114. #endif
  115. }
  116. snow_horizontal_compose_lift_lead_out(i, b, b, ref, width, w_l, 0, W_DM, W_DO, W_DS);
  117. b[0] = b_0 - ((W_DM * 2 * ref[1]+W_DO)>>W_DS);
  118. }
  119. { // Lift 1
  120. DWTELEM * const dst = b+w2;
  121. i = 0;
  122. for(; (((long)&dst[i]) & 0xF) && i<w_r; i++){
  123. dst[i] = dst[i] - (b[i] + b[i + 1]);
  124. }
  125. align = vec_lvsl(0, b+i);
  126. tmp1 = vec_ld(0, b+i);
  127. vbuf = (vector signed int*) (dst + i);
  128. tmp2 = vec_ld(15, b+i);
  129. t1 = vec_perm(tmp1, tmp2, align);
  130. for (; i<w_r-3; i+=4) {
  131. #if 0
  132. dst[i] = dst[i] - (b[i] + b[i + 1]);
  133. dst[i+1] = dst[i+1] - (b[i+1] + b[i + 2]);
  134. dst[i+2] = dst[i+2] - (b[i+2] + b[i + 3]);
  135. dst[i+3] = dst[i+3] - (b[i+3] + b[i + 4]);
  136. #else
  137. tmp1 = vec_ld(0, b+4+i);
  138. tmp2 = vec_ld(15, b+4+i);
  139. t2 = vec_perm(tmp1, tmp2, align);
  140. y = vec_add(t1, vec_sld(t1,t2,4));
  141. *vbuf = vec_sub (*vbuf, y);
  142. vbuf++;
  143. t1 = t2;
  144. #endif
  145. }
  146. snow_horizontal_compose_lift_lead_out(i, dst, dst, b, width, w_r, 1, W_CM, W_CO, W_CS);
  147. }
  148. { // Lift 2
  149. DWTELEM * const ref = b+w2 - 1;
  150. DWTELEM b_0 = b[0];
  151. vbuf= (vector signed int *) b;
  152. tmp1 = vec_ld (0, ref);
  153. align = vec_lvsl (0, ref);
  154. tmp2 = vec_ld (15, ref);
  155. t1= vec_perm(tmp1, tmp2, align);
  156. i = 0;
  157. for (; i<w_l-15; i+=16) {
  158. #if 0
  159. b[i] = b[i] - (((8 -(ref[i] + ref[i+1])) - (b[i] <<2)) >> 4);
  160. b[i+1] = b[i+1] - (((8 -(ref[i+1] + ref[i+2])) - (b[i+1]<<2)) >> 4);
  161. b[i+2] = b[i+2] - (((8 -(ref[i+2] + ref[i+3])) - (b[i+2]<<2)) >> 4);
  162. b[i+3] = b[i+3] - (((8 -(ref[i+3] + ref[i+4])) - (b[i+3]<<2)) >> 4);
  163. #else
  164. tmp1 = vec_ld (0, ref+4+i);
  165. tmp2 = vec_ld (15, ref+4+i);
  166. t2 = vec_perm(tmp1, tmp2, align);
  167. y = vec_add(t1,vec_sld(t1,t2,4));
  168. y = vec_sub(vec_splat_s32(8),y);
  169. tmp1 = vec_ld (0, ref+8+i);
  170. x = vec_sl(*vbuf,vec_splat_u32(2));
  171. y = vec_sra(vec_sub(y,x),vec_splat_u32(4));
  172. tmp2 = vec_ld (15, ref+8+i);
  173. *vbuf = vec_sub( *vbuf, y);
  174. t1 = t2;
  175. vbuf++;
  176. t2 = vec_perm(tmp1, tmp2, align);
  177. y = vec_add(t1,vec_sld(t1,t2,4));
  178. y = vec_sub(vec_splat_s32(8),y);
  179. tmp1 = vec_ld (0, ref+12+i);
  180. x = vec_sl(*vbuf,vec_splat_u32(2));
  181. y = vec_sra(vec_sub(y,x),vec_splat_u32(4));
  182. tmp2 = vec_ld (15, ref+12+i);
  183. *vbuf = vec_sub( *vbuf, y);
  184. t1 = t2;
  185. vbuf++;
  186. t2 = vec_perm(tmp1, tmp2, align);
  187. y = vec_add(t1,vec_sld(t1,t2,4));
  188. y = vec_sub(vec_splat_s32(8),y);
  189. tmp1 = vec_ld (0, ref+16+i);
  190. x = vec_sl(*vbuf,vec_splat_u32(2));
  191. y = vec_sra(vec_sub(y,x),vec_splat_u32(4));
  192. tmp2 = vec_ld (15, ref+16+i);
  193. *vbuf = vec_sub( *vbuf, y);
  194. t1 = t2;
  195. vbuf++;
  196. t2 = vec_perm(tmp1, tmp2, align);
  197. y = vec_add(t1,vec_sld(t1,t2,4));
  198. y = vec_sub(vec_splat_s32(8),y);
  199. t1 = t2;
  200. x = vec_sl(*vbuf,vec_splat_u32(2));
  201. y = vec_sra(vec_sub(y,x),vec_splat_u32(4));
  202. *vbuf = vec_sub( *vbuf, y);
  203. vbuf++;
  204. #endif
  205. }
  206. snow_horizontal_compose_liftS_lead_out(i, b, b, ref, width, w_l);
  207. b[0] = b_0 - (((-2 * ref[1] + W_BO) - 4 * b_0) >> W_BS);
  208. }
  209. { // Lift 3
  210. DWTELEM * const src = b+w2;
  211. vbuf = (vector signed int *)b;
  212. vtmp = (vector signed int *)temp;
  213. i = 0;
  214. align = vec_lvsl(0, src);
  215. for (; i<w_r-3; i+=4) {
  216. #if 0
  217. temp[i] = src[i] - ((-3*(b[i] + b[i+1]))>>1);
  218. temp[i+1] = src[i+1] - ((-3*(b[i+1] + b[i+2]))>>1);
  219. temp[i+2] = src[i+2] - ((-3*(b[i+2] + b[i+3]))>>1);
  220. temp[i+3] = src[i+3] - ((-3*(b[i+3] + b[i+4]))>>1);
  221. #else
  222. tmp1 = vec_ld(0,src+i);
  223. t1 = vec_add(vbuf[0],vec_sld(vbuf[0],vbuf[1],4));
  224. tmp2 = vec_ld(15,src+i);
  225. t1 = vec_sub(vec_splat_s32(0),t1); //bad!
  226. t1 = vec_add(t1,vec_add(t1,t1));
  227. t2 = vec_perm(tmp1 ,tmp2 ,align);
  228. t1 = vec_sra(t1,vec_splat_u32(1));
  229. vbuf++;
  230. *vtmp = vec_sub(t2,t1);
  231. vtmp++;
  232. #endif
  233. }
  234. snow_horizontal_compose_lift_lead_out(i, temp, src, b, width, w_r, 1, -3, 0, 1);
  235. }
  236. {
  237. //Interleave
  238. int a;
  239. vector signed int *t = (vector signed int *)temp,
  240. *v = (vector signed int *)b;
  241. snow_interleave_line_header(&i, width, b, temp);
  242. for (; (i & 0xE) != 0xE; i-=2){
  243. b[i+1] = temp[i>>1];
  244. b[i] = b[i>>1];
  245. }
  246. for (i-=14; i>=0; i-=16){
  247. a=i/4;
  248. v[a+3]=vec_mergel(v[(a>>1)+1],t[(a>>1)+1]);
  249. v[a+2]=vec_mergeh(v[(a>>1)+1],t[(a>>1)+1]);
  250. v[a+1]=vec_mergel(v[a>>1],t[a>>1]);
  251. v[a]=vec_mergeh(v[a>>1],t[a>>1]);
  252. }
  253. }
  254. #endif
  255. }
  256. void ff_snow_vertical_compose97i_altivec(DWTELEM *b0, DWTELEM *b1, DWTELEM *b2, DWTELEM *b3, DWTELEM *b4, DWTELEM *b5, int width)
  257. {
  258. int i, w4 = width/4;
  259. vector signed int *v0, *v1,*v2,*v3,*v4,*v5;
  260. vector signed int t1, t2;
  261. v0=(vector signed int *)b0;
  262. v1=(vector signed int *)b1;
  263. v2=(vector signed int *)b2;
  264. v3=(vector signed int *)b3;
  265. v4=(vector signed int *)b4;
  266. v5=(vector signed int *)b5;
  267. for (i=0; i< w4;i++) {
  268. #if 0
  269. b4[i] -= (3*(b3[i] + b5[i])+4)>>3;
  270. b3[i] -= ((b2[i] + b4[i]));
  271. b2[i] += ((b1[i] + b3[i])+4*b2[i]+8)>>4;
  272. b1[i] += (3*(b0[i] + b2[i]))>>1;
  273. #else
  274. t1 = vec_add(v3[i], v5[i]);
  275. t2 = vec_add(t1, vec_add(t1,t1));
  276. t1 = vec_add(t2, vec_splat_s32(4));
  277. v4[i] = vec_sub(v4[i], vec_sra(t1,vec_splat_u32(3)));
  278. v3[i] = vec_sub(v3[i], vec_add(v2[i], v4[i]));
  279. t1 = vec_add(vec_splat_s32(8), vec_add(v1[i], v3[i]));
  280. t2 = vec_sl(v2[i], vec_splat_u32(2));
  281. v2[i] = vec_add(v2[i], vec_sra(vec_add(t1,t2),vec_splat_u32(4)));
  282. t1 = vec_add(v0[i], v2[i]);
  283. t2 = vec_add(t1, vec_add(t1,t1));
  284. v1[i] = vec_add(v1[i], vec_sra(t2,vec_splat_u32(1)));
  285. #endif
  286. }
  287. for(i*=4; i < width; i++)
  288. {
  289. b4[i] -= (W_DM*(b3[i] + b5[i])+W_DO)>>W_DS;
  290. b3[i] -= (W_CM*(b2[i] + b4[i])+W_CO)>>W_CS;
  291. b2[i] += (W_BM*(b1[i] + b3[i])+4*b2[i]+W_BO)>>W_BS;
  292. b1[i] += (W_AM*(b0[i] + b2[i])+W_AO)>>W_AS;
  293. }
  294. }
  295. #define LOAD_BLOCKS \
  296. tmp1 = vec_ld(0, &block[3][y*src_stride]);\
  297. align = vec_lvsl(0, &block[3][y*src_stride]);\
  298. tmp2 = vec_ld(15, &block[3][y*src_stride]);\
  299. \
  300. b3 = vec_perm(tmp1,tmp2,align);\
  301. \
  302. tmp1 = vec_ld(0, &block[2][y*src_stride]);\
  303. align = vec_lvsl(0, &block[2][y*src_stride]);\
  304. tmp2 = vec_ld(15, &block[2][y*src_stride]);\
  305. \
  306. b2 = vec_perm(tmp1,tmp2,align);\
  307. \
  308. tmp1 = vec_ld(0, &block[1][y*src_stride]);\
  309. align = vec_lvsl(0, &block[1][y*src_stride]);\
  310. tmp2 = vec_ld(15, &block[1][y*src_stride]);\
  311. \
  312. b1 = vec_perm(tmp1,tmp2,align);\
  313. \
  314. tmp1 = vec_ld(0, &block[0][y*src_stride]);\
  315. align = vec_lvsl(0, &block[0][y*src_stride]);\
  316. tmp2 = vec_ld(15, &block[0][y*src_stride]);\
  317. \
  318. b0 = vec_perm(tmp1,tmp2,align);
  319. #define LOAD_OBMCS \
  320. tmp1 = vec_ld(0, obmc1);\
  321. align = vec_lvsl(0, obmc1);\
  322. tmp2 = vec_ld(15, obmc1);\
  323. \
  324. ob1 = vec_perm(tmp1,tmp2,align);\
  325. \
  326. tmp1 = vec_ld(0, obmc2);\
  327. align = vec_lvsl(0, obmc2);\
  328. tmp2 = vec_ld(15, obmc2);\
  329. \
  330. ob2 = vec_perm(tmp1,tmp2,align);\
  331. \
  332. tmp1 = vec_ld(0, obmc3);\
  333. align = vec_lvsl(0, obmc3);\
  334. tmp2 = vec_ld(15, obmc3);\
  335. \
  336. ob3 = vec_perm(tmp1,tmp2,align);\
  337. \
  338. tmp1 = vec_ld(0, obmc4);\
  339. align = vec_lvsl(0, obmc4);\
  340. tmp2 = vec_ld(15, obmc4);\
  341. \
  342. ob4 = vec_perm(tmp1,tmp2,align);
  343. /* interleave logic
  344. * h1 <- [ a,b,a,b, a,b,a,b, a,b,a,b, a,b,a,b ]
  345. * h2 <- [ c,d,c,d, c,d,c,d, c,d,c,d, c,d,c,d ]
  346. * h <- [ a,b,c,d, a,b,c,d, a,b,c,d, a,b,c,d ]
  347. */
  348. #define STEPS_0_1\
  349. h1 = (vector unsigned short)\
  350. vec_mergeh(ob1, ob2);\
  351. \
  352. h2 = (vector unsigned short)\
  353. vec_mergeh(ob3, ob4);\
  354. \
  355. ih = (vector unsigned char)\
  356. vec_mergeh(h1,h2);\
  357. \
  358. l1 = (vector unsigned short) vec_mergeh(b3, b2);\
  359. \
  360. ih1 = (vector unsigned char) vec_mergel(h1, h2);\
  361. \
  362. l2 = (vector unsigned short) vec_mergeh(b1, b0);\
  363. \
  364. il = (vector unsigned char) vec_mergeh(l1, l2);\
  365. \
  366. v[0] = (vector signed int) vec_msum(ih, il, vec_splat_u32(0));\
  367. \
  368. il1 = (vector unsigned char) vec_mergel(l1, l2);\
  369. \
  370. v[1] = (vector signed int) vec_msum(ih1, il1, vec_splat_u32(0));
  371. #define FINAL_STEP_SCALAR\
  372. for(x=0; x<b_w; x++)\
  373. if(add){\
  374. vbuf[x] += dst[x + src_x];\
  375. vbuf[x] = (vbuf[x] + (1<<(FRAC_BITS-1))) >> FRAC_BITS;\
  376. if(vbuf[x]&(~255)) vbuf[x]= ~(vbuf[x]>>31);\
  377. dst8[x + y*src_stride] = vbuf[x];\
  378. }else{\
  379. dst[x + src_x] -= vbuf[x];\
  380. }
  381. static void inner_add_yblock_bw_8_obmc_16_altivec(uint8_t *obmc,
  382. const int obmc_stride,
  383. uint8_t * * block, int b_w,
  384. int b_h, int src_x, int src_y,
  385. int src_stride, slice_buffer * sb,
  386. int add, uint8_t * dst8)
  387. {
  388. int y, x;
  389. DWTELEM * dst;
  390. vector unsigned short h1, h2, l1, l2;
  391. vector unsigned char ih, il, ih1, il1, tmp1, tmp2, align;
  392. vector unsigned char b0,b1,b2,b3;
  393. vector unsigned char ob1,ob2,ob3,ob4;
  394. DECLARE_ALIGNED_16(int, vbuf[16]);
  395. vector signed int *v = (vector signed int *)vbuf, *d;
  396. for(y=0; y<b_h; y++){
  397. //FIXME ugly misuse of obmc_stride
  398. uint8_t *obmc1= obmc + y*obmc_stride;
  399. uint8_t *obmc2= obmc1+ (obmc_stride>>1);
  400. uint8_t *obmc3= obmc1+ obmc_stride*(obmc_stride>>1);
  401. uint8_t *obmc4= obmc3+ (obmc_stride>>1);
  402. dst = slice_buffer_get_line(sb, src_y + y);
  403. d = (vector signed int *)(dst + src_x);
  404. //FIXME i could avoid some loads!
  405. // load blocks
  406. LOAD_BLOCKS
  407. // load obmcs
  408. LOAD_OBMCS
  409. // steps 0 1
  410. STEPS_0_1
  411. FINAL_STEP_SCALAR
  412. }
  413. }
  414. #define STEPS_2_3\
  415. h1 = (vector unsigned short) vec_mergel(ob1, ob2);\
  416. \
  417. h2 = (vector unsigned short) vec_mergel(ob3, ob4);\
  418. \
  419. ih = (vector unsigned char) vec_mergeh(h1,h2);\
  420. \
  421. l1 = (vector unsigned short) vec_mergel(b3, b2);\
  422. \
  423. l2 = (vector unsigned short) vec_mergel(b1, b0);\
  424. \
  425. ih1 = (vector unsigned char) vec_mergel(h1,h2);\
  426. \
  427. il = (vector unsigned char) vec_mergeh(l1,l2);\
  428. \
  429. v[2] = (vector signed int) vec_msum(ih, il, vec_splat_u32(0));\
  430. \
  431. il1 = (vector unsigned char) vec_mergel(l1,l2);\
  432. \
  433. v[3] = (vector signed int) vec_msum(ih1, il1, vec_splat_u32(0));
  434. static void inner_add_yblock_bw_16_obmc_32_altivec(uint8_t *obmc,
  435. const int obmc_stride,
  436. uint8_t * * block, int b_w,
  437. int b_h, int src_x, int src_y,
  438. int src_stride, slice_buffer * sb,
  439. int add, uint8_t * dst8)
  440. {
  441. int y, x;
  442. DWTELEM * dst;
  443. vector unsigned short h1, h2, l1, l2;
  444. vector unsigned char ih, il, ih1, il1, tmp1, tmp2, align;
  445. vector unsigned char b0,b1,b2,b3;
  446. vector unsigned char ob1,ob2,ob3,ob4;
  447. DECLARE_ALIGNED_16(int, vbuf[b_w]);
  448. vector signed int *v = (vector signed int *)vbuf, *d;
  449. for(y=0; y<b_h; y++){
  450. //FIXME ugly misuse of obmc_stride
  451. uint8_t *obmc1= obmc + y*obmc_stride;
  452. uint8_t *obmc2= obmc1+ (obmc_stride>>1);
  453. uint8_t *obmc3= obmc1+ obmc_stride*(obmc_stride>>1);
  454. uint8_t *obmc4= obmc3+ (obmc_stride>>1);
  455. dst = slice_buffer_get_line(sb, src_y + y);
  456. d = (vector signed int *)(dst + src_x);
  457. // load blocks
  458. LOAD_BLOCKS
  459. // load obmcs
  460. LOAD_OBMCS
  461. // steps 0 1 2 3
  462. STEPS_0_1
  463. STEPS_2_3
  464. FINAL_STEP_SCALAR
  465. }
  466. }
  467. #define FINAL_STEP_VEC \
  468. \
  469. if(add)\
  470. {\
  471. for(x=0; x<b_w/4; x++)\
  472. {\
  473. v[x] = vec_add(v[x], d[x]);\
  474. v[x] = vec_sra(vec_add(v[x],\
  475. vec_sl( vec_splat_s32(1),\
  476. vec_splat_u32(7))),\
  477. vec_splat_u32(8));\
  478. \
  479. mask = (vector bool int) vec_sl((vector signed int)\
  480. vec_cmpeq(v[x],v[x]),vec_splat_u32(8));\
  481. mask = (vector bool int) vec_and(v[x],vec_nor(mask,mask));\
  482. \
  483. mask = (vector bool int)\
  484. vec_cmpeq((vector signed int)mask,\
  485. (vector signed int)vec_splat_u32(0));\
  486. \
  487. vs = vec_sra(v[x],vec_splat_u32(8));\
  488. vs = vec_sra(v[x],vec_splat_u32(8));\
  489. vs = vec_sra(v[x],vec_splat_u32(15));\
  490. \
  491. vs = vec_nor(vs,vs);\
  492. \
  493. v[x]= vec_sel(v[x],vs,mask);\
  494. }\
  495. \
  496. for(x=0; x<b_w; x++)\
  497. dst8[x + y*src_stride] = vbuf[x];\
  498. \
  499. }\
  500. else\
  501. for(x=0; x<b_w/4; x++)\
  502. d[x] = vec_sub(d[x], v[x]);
  503. static void inner_add_yblock_a_bw_8_obmc_16_altivec(uint8_t *obmc,
  504. const int obmc_stride,
  505. uint8_t * * block, int b_w,
  506. int b_h, int src_x, int src_y,
  507. int src_stride, slice_buffer * sb,
  508. int add, uint8_t * dst8)
  509. {
  510. int y, x;
  511. DWTELEM * dst;
  512. vector bool int mask;
  513. vector signed int vs;
  514. vector unsigned short h1, h2, l1, l2;
  515. vector unsigned char ih, il, ih1, il1, tmp1, tmp2, align;
  516. vector unsigned char b0,b1,b2,b3;
  517. vector unsigned char ob1,ob2,ob3,ob4;
  518. DECLARE_ALIGNED_16(int, vbuf[16]);
  519. vector signed int *v = (vector signed int *)vbuf, *d;
  520. for(y=0; y<b_h; y++){
  521. //FIXME ugly misuse of obmc_stride
  522. uint8_t *obmc1= obmc + y*obmc_stride;
  523. uint8_t *obmc2= obmc1+ (obmc_stride>>1);
  524. uint8_t *obmc3= obmc1+ obmc_stride*(obmc_stride>>1);
  525. uint8_t *obmc4= obmc3+ (obmc_stride>>1);
  526. dst = slice_buffer_get_line(sb, src_y + y);
  527. d = (vector signed int *)(dst + src_x);
  528. //FIXME i could avoid some loads!
  529. // load blocks
  530. LOAD_BLOCKS
  531. // load obmcs
  532. LOAD_OBMCS
  533. // steps 0 1
  534. STEPS_0_1
  535. FINAL_STEP_VEC
  536. }
  537. }
  538. static void inner_add_yblock_a_bw_16_obmc_32_altivec(uint8_t *obmc,
  539. const int obmc_stride,
  540. uint8_t * * block, int b_w,
  541. int b_h, int src_x, int src_y,
  542. int src_stride, slice_buffer * sb,
  543. int add, uint8_t * dst8)
  544. {
  545. int y, x;
  546. DWTELEM * dst;
  547. vector bool int mask;
  548. vector signed int vs;
  549. vector unsigned short h1, h2, l1, l2;
  550. vector unsigned char ih, il, ih1, il1, tmp1, tmp2, align;
  551. vector unsigned char b0,b1,b2,b3;
  552. vector unsigned char ob1,ob2,ob3,ob4;
  553. DECLARE_ALIGNED_16(int, vbuf[b_w]);
  554. vector signed int *v = (vector signed int *)vbuf, *d;
  555. for(y=0; y<b_h; y++){
  556. //FIXME ugly misuse of obmc_stride
  557. uint8_t *obmc1= obmc + y*obmc_stride;
  558. uint8_t *obmc2= obmc1+ (obmc_stride>>1);
  559. uint8_t *obmc3= obmc1+ obmc_stride*(obmc_stride>>1);
  560. uint8_t *obmc4= obmc3+ (obmc_stride>>1);
  561. dst = slice_buffer_get_line(sb, src_y + y);
  562. d = (vector signed int *)(dst + src_x);
  563. // load blocks
  564. LOAD_BLOCKS
  565. // load obmcs
  566. LOAD_OBMCS
  567. // steps 0 1 2 3
  568. STEPS_0_1
  569. STEPS_2_3
  570. FINAL_STEP_VEC
  571. }
  572. }
  573. void ff_snow_inner_add_yblock_altivec(uint8_t *obmc, const int obmc_stride,
  574. uint8_t * * block, int b_w, int b_h,
  575. int src_x, int src_y, int src_stride,
  576. slice_buffer * sb, int add,
  577. uint8_t * dst8)
  578. {
  579. if (src_x&15) {
  580. if (b_w == 16)
  581. inner_add_yblock_bw_16_obmc_32_altivec(obmc, obmc_stride, block,
  582. b_w, b_h, src_x, src_y,
  583. src_stride, sb, add, dst8);
  584. else if (b_w == 8)
  585. inner_add_yblock_bw_8_obmc_16_altivec(obmc, obmc_stride, block,
  586. b_w, b_h, src_x, src_y,
  587. src_stride, sb, add, dst8);
  588. else
  589. ff_snow_inner_add_yblock(obmc, obmc_stride, block, b_w, b_h, src_x,
  590. src_y, src_stride, sb, add, dst8);
  591. } else {
  592. if (b_w == 16)
  593. inner_add_yblock_a_bw_16_obmc_32_altivec(obmc, obmc_stride, block,
  594. b_w, b_h, src_x, src_y,
  595. src_stride, sb, add, dst8);
  596. else if (b_w == 8)
  597. inner_add_yblock_a_bw_8_obmc_16_altivec(obmc, obmc_stride, block,
  598. b_w, b_h, src_x, src_y,
  599. src_stride, sb, add, dst8);
  600. else
  601. ff_snow_inner_add_yblock(obmc, obmc_stride, block, b_w, b_h, src_x,
  602. src_y, src_stride, sb, add, dst8);
  603. }
  604. }
  605. void snow_init_altivec(DSPContext* c, AVCodecContext *avctx)
  606. {
  607. #if 0
  608. c->horizontal_compose97i = ff_snow_horizontal_compose97i_altivec;
  609. c->vertical_compose97i = ff_snow_vertical_compose97i_altivec;
  610. c->inner_add_yblock = ff_snow_inner_add_yblock_altivec;
  611. #endif
  612. }