dsputil_altivec.c 57 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455
  1. /*
  2. * Copyright (c) 2002 Brian Foley
  3. * Copyright (c) 2002 Dieter Shirley
  4. * Copyright (c) 2003-2004 Romain Dolbeau <romain@dolbeau.org>
  5. *
  6. * This file is part of FFmpeg.
  7. *
  8. * FFmpeg is free software; you can redistribute it and/or
  9. * modify it under the terms of the GNU Lesser General Public
  10. * License as published by the Free Software Foundation; either
  11. * version 2.1 of the License, or (at your option) any later version.
  12. *
  13. * FFmpeg is distributed in the hope that it will be useful,
  14. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  15. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  16. * Lesser General Public License for more details.
  17. *
  18. * You should have received a copy of the GNU Lesser General Public
  19. * License along with FFmpeg; if not, write to the Free Software
  20. * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
  21. */
  22. #include "libavcodec/dsputil.h"
  23. #include "gcc_fixes.h"
  24. #include "dsputil_ppc.h"
  25. #include "util_altivec.h"
  26. #include "types_altivec.h"
  27. int sad16_x2_altivec(void *v, uint8_t *pix1, uint8_t *pix2, int line_size, int h)
  28. {
  29. int i;
  30. DECLARE_ALIGNED_16(int, s);
  31. const vector unsigned char zero = (const vector unsigned char)vec_splat_u8(0);
  32. vector unsigned char *tv;
  33. vector unsigned char pix1v, pix2v, pix2iv, avgv, t5;
  34. vector unsigned int sad;
  35. vector signed int sumdiffs;
  36. s = 0;
  37. sad = (vector unsigned int)vec_splat_u32(0);
  38. for (i = 0; i < h; i++) {
  39. /* Read unaligned pixels into our vectors. The vectors are as follows:
  40. pix1v: pix1[0]-pix1[15]
  41. pix2v: pix2[0]-pix2[15] pix2iv: pix2[1]-pix2[16] */
  42. tv = (vector unsigned char *) pix1;
  43. pix1v = vec_perm(tv[0], tv[1], vec_lvsl(0, pix1));
  44. tv = (vector unsigned char *) &pix2[0];
  45. pix2v = vec_perm(tv[0], tv[1], vec_lvsl(0, &pix2[0]));
  46. tv = (vector unsigned char *) &pix2[1];
  47. pix2iv = vec_perm(tv[0], tv[1], vec_lvsl(0, &pix2[1]));
  48. /* Calculate the average vector */
  49. avgv = vec_avg(pix2v, pix2iv);
  50. /* Calculate a sum of abs differences vector */
  51. t5 = vec_sub(vec_max(pix1v, avgv), vec_min(pix1v, avgv));
  52. /* Add each 4 pixel group together and put 4 results into sad */
  53. sad = vec_sum4s(t5, sad);
  54. pix1 += line_size;
  55. pix2 += line_size;
  56. }
  57. /* Sum up the four partial sums, and put the result into s */
  58. sumdiffs = vec_sums((vector signed int) sad, (vector signed int) zero);
  59. sumdiffs = vec_splat(sumdiffs, 3);
  60. vec_ste(sumdiffs, 0, &s);
  61. return s;
  62. }
  63. int sad16_y2_altivec(void *v, uint8_t *pix1, uint8_t *pix2, int line_size, int h)
  64. {
  65. int i;
  66. DECLARE_ALIGNED_16(int, s);
  67. const vector unsigned char zero = (const vector unsigned char)vec_splat_u8(0);
  68. vector unsigned char *tv;
  69. vector unsigned char pix1v, pix2v, pix3v, avgv, t5;
  70. vector unsigned int sad;
  71. vector signed int sumdiffs;
  72. uint8_t *pix3 = pix2 + line_size;
  73. s = 0;
  74. sad = (vector unsigned int)vec_splat_u32(0);
  75. /* Due to the fact that pix3 = pix2 + line_size, the pix3 of one
  76. iteration becomes pix2 in the next iteration. We can use this
  77. fact to avoid a potentially expensive unaligned read, each
  78. time around the loop.
  79. Read unaligned pixels into our vectors. The vectors are as follows:
  80. pix2v: pix2[0]-pix2[15]
  81. Split the pixel vectors into shorts */
  82. tv = (vector unsigned char *) &pix2[0];
  83. pix2v = vec_perm(tv[0], tv[1], vec_lvsl(0, &pix2[0]));
  84. for (i = 0; i < h; i++) {
  85. /* Read unaligned pixels into our vectors. The vectors are as follows:
  86. pix1v: pix1[0]-pix1[15]
  87. pix3v: pix3[0]-pix3[15] */
  88. tv = (vector unsigned char *) pix1;
  89. pix1v = vec_perm(tv[0], tv[1], vec_lvsl(0, pix1));
  90. tv = (vector unsigned char *) &pix3[0];
  91. pix3v = vec_perm(tv[0], tv[1], vec_lvsl(0, &pix3[0]));
  92. /* Calculate the average vector */
  93. avgv = vec_avg(pix2v, pix3v);
  94. /* Calculate a sum of abs differences vector */
  95. t5 = vec_sub(vec_max(pix1v, avgv), vec_min(pix1v, avgv));
  96. /* Add each 4 pixel group together and put 4 results into sad */
  97. sad = vec_sum4s(t5, sad);
  98. pix1 += line_size;
  99. pix2v = pix3v;
  100. pix3 += line_size;
  101. }
  102. /* Sum up the four partial sums, and put the result into s */
  103. sumdiffs = vec_sums((vector signed int) sad, (vector signed int) zero);
  104. sumdiffs = vec_splat(sumdiffs, 3);
  105. vec_ste(sumdiffs, 0, &s);
  106. return s;
  107. }
  108. int sad16_xy2_altivec(void *v, uint8_t *pix1, uint8_t *pix2, int line_size, int h)
  109. {
  110. int i;
  111. DECLARE_ALIGNED_16(int, s);
  112. uint8_t *pix3 = pix2 + line_size;
  113. const vector unsigned char zero = (const vector unsigned char)vec_splat_u8(0);
  114. const vector unsigned short two = (const vector unsigned short)vec_splat_u16(2);
  115. vector unsigned char *tv, avgv, t5;
  116. vector unsigned char pix1v, pix2v, pix3v, pix2iv, pix3iv;
  117. vector unsigned short pix2lv, pix2hv, pix2ilv, pix2ihv;
  118. vector unsigned short pix3lv, pix3hv, pix3ilv, pix3ihv;
  119. vector unsigned short avghv, avglv;
  120. vector unsigned short t1, t2, t3, t4;
  121. vector unsigned int sad;
  122. vector signed int sumdiffs;
  123. sad = (vector unsigned int)vec_splat_u32(0);
  124. s = 0;
  125. /* Due to the fact that pix3 = pix2 + line_size, the pix3 of one
  126. iteration becomes pix2 in the next iteration. We can use this
  127. fact to avoid a potentially expensive unaligned read, as well
  128. as some splitting, and vector addition each time around the loop.
  129. Read unaligned pixels into our vectors. The vectors are as follows:
  130. pix2v: pix2[0]-pix2[15] pix2iv: pix2[1]-pix2[16]
  131. Split the pixel vectors into shorts */
  132. tv = (vector unsigned char *) &pix2[0];
  133. pix2v = vec_perm(tv[0], tv[1], vec_lvsl(0, &pix2[0]));
  134. tv = (vector unsigned char *) &pix2[1];
  135. pix2iv = vec_perm(tv[0], tv[1], vec_lvsl(0, &pix2[1]));
  136. pix2hv = (vector unsigned short) vec_mergeh(zero, pix2v);
  137. pix2lv = (vector unsigned short) vec_mergel(zero, pix2v);
  138. pix2ihv = (vector unsigned short) vec_mergeh(zero, pix2iv);
  139. pix2ilv = (vector unsigned short) vec_mergel(zero, pix2iv);
  140. t1 = vec_add(pix2hv, pix2ihv);
  141. t2 = vec_add(pix2lv, pix2ilv);
  142. for (i = 0; i < h; i++) {
  143. /* Read unaligned pixels into our vectors. The vectors are as follows:
  144. pix1v: pix1[0]-pix1[15]
  145. pix3v: pix3[0]-pix3[15] pix3iv: pix3[1]-pix3[16] */
  146. tv = (vector unsigned char *) pix1;
  147. pix1v = vec_perm(tv[0], tv[1], vec_lvsl(0, pix1));
  148. tv = (vector unsigned char *) &pix3[0];
  149. pix3v = vec_perm(tv[0], tv[1], vec_lvsl(0, &pix3[0]));
  150. tv = (vector unsigned char *) &pix3[1];
  151. pix3iv = vec_perm(tv[0], tv[1], vec_lvsl(0, &pix3[1]));
  152. /* Note that AltiVec does have vec_avg, but this works on vector pairs
  153. and rounds up. We could do avg(avg(a,b),avg(c,d)), but the rounding
  154. would mean that, for example, avg(3,0,0,1) = 2, when it should be 1.
  155. Instead, we have to split the pixel vectors into vectors of shorts,
  156. and do the averaging by hand. */
  157. /* Split the pixel vectors into shorts */
  158. pix3hv = (vector unsigned short) vec_mergeh(zero, pix3v);
  159. pix3lv = (vector unsigned short) vec_mergel(zero, pix3v);
  160. pix3ihv = (vector unsigned short) vec_mergeh(zero, pix3iv);
  161. pix3ilv = (vector unsigned short) vec_mergel(zero, pix3iv);
  162. /* Do the averaging on them */
  163. t3 = vec_add(pix3hv, pix3ihv);
  164. t4 = vec_add(pix3lv, pix3ilv);
  165. avghv = vec_sr(vec_add(vec_add(t1, t3), two), two);
  166. avglv = vec_sr(vec_add(vec_add(t2, t4), two), two);
  167. /* Pack the shorts back into a result */
  168. avgv = vec_pack(avghv, avglv);
  169. /* Calculate a sum of abs differences vector */
  170. t5 = vec_sub(vec_max(pix1v, avgv), vec_min(pix1v, avgv));
  171. /* Add each 4 pixel group together and put 4 results into sad */
  172. sad = vec_sum4s(t5, sad);
  173. pix1 += line_size;
  174. pix3 += line_size;
  175. /* Transfer the calculated values for pix3 into pix2 */
  176. t1 = t3;
  177. t2 = t4;
  178. }
  179. /* Sum up the four partial sums, and put the result into s */
  180. sumdiffs = vec_sums((vector signed int) sad, (vector signed int) zero);
  181. sumdiffs = vec_splat(sumdiffs, 3);
  182. vec_ste(sumdiffs, 0, &s);
  183. return s;
  184. }
  185. int sad16_altivec(void *v, uint8_t *pix1, uint8_t *pix2, int line_size, int h)
  186. {
  187. int i;
  188. DECLARE_ALIGNED_16(int, s);
  189. const vector unsigned int zero = (const vector unsigned int)vec_splat_u32(0);
  190. vector unsigned char perm1, perm2, *pix1v, *pix2v;
  191. vector unsigned char t1, t2, t3,t4, t5;
  192. vector unsigned int sad;
  193. vector signed int sumdiffs;
  194. sad = (vector unsigned int)vec_splat_u32(0);
  195. for (i = 0; i < h; i++) {
  196. /* Read potentially unaligned pixels into t1 and t2 */
  197. perm1 = vec_lvsl(0, pix1);
  198. pix1v = (vector unsigned char *) pix1;
  199. perm2 = vec_lvsl(0, pix2);
  200. pix2v = (vector unsigned char *) pix2;
  201. t1 = vec_perm(pix1v[0], pix1v[1], perm1);
  202. t2 = vec_perm(pix2v[0], pix2v[1], perm2);
  203. /* Calculate a sum of abs differences vector */
  204. t3 = vec_max(t1, t2);
  205. t4 = vec_min(t1, t2);
  206. t5 = vec_sub(t3, t4);
  207. /* Add each 4 pixel group together and put 4 results into sad */
  208. sad = vec_sum4s(t5, sad);
  209. pix1 += line_size;
  210. pix2 += line_size;
  211. }
  212. /* Sum up the four partial sums, and put the result into s */
  213. sumdiffs = vec_sums((vector signed int) sad, (vector signed int) zero);
  214. sumdiffs = vec_splat(sumdiffs, 3);
  215. vec_ste(sumdiffs, 0, &s);
  216. return s;
  217. }
  218. int sad8_altivec(void *v, uint8_t *pix1, uint8_t *pix2, int line_size, int h)
  219. {
  220. int i;
  221. DECLARE_ALIGNED_16(int, s);
  222. const vector unsigned int zero = (const vector unsigned int)vec_splat_u32(0);
  223. vector unsigned char perm1, perm2, permclear, *pix1v, *pix2v;
  224. vector unsigned char t1, t2, t3,t4, t5;
  225. vector unsigned int sad;
  226. vector signed int sumdiffs;
  227. sad = (vector unsigned int)vec_splat_u32(0);
  228. permclear = (vector unsigned char){255,255,255,255,255,255,255,255,0,0,0,0,0,0,0,0};
  229. for (i = 0; i < h; i++) {
  230. /* Read potentially unaligned pixels into t1 and t2
  231. Since we're reading 16 pixels, and actually only want 8,
  232. mask out the last 8 pixels. The 0s don't change the sum. */
  233. perm1 = vec_lvsl(0, pix1);
  234. pix1v = (vector unsigned char *) pix1;
  235. perm2 = vec_lvsl(0, pix2);
  236. pix2v = (vector unsigned char *) pix2;
  237. t1 = vec_and(vec_perm(pix1v[0], pix1v[1], perm1), permclear);
  238. t2 = vec_and(vec_perm(pix2v[0], pix2v[1], perm2), permclear);
  239. /* Calculate a sum of abs differences vector */
  240. t3 = vec_max(t1, t2);
  241. t4 = vec_min(t1, t2);
  242. t5 = vec_sub(t3, t4);
  243. /* Add each 4 pixel group together and put 4 results into sad */
  244. sad = vec_sum4s(t5, sad);
  245. pix1 += line_size;
  246. pix2 += line_size;
  247. }
  248. /* Sum up the four partial sums, and put the result into s */
  249. sumdiffs = vec_sums((vector signed int) sad, (vector signed int) zero);
  250. sumdiffs = vec_splat(sumdiffs, 3);
  251. vec_ste(sumdiffs, 0, &s);
  252. return s;
  253. }
  254. int pix_norm1_altivec(uint8_t *pix, int line_size)
  255. {
  256. int i;
  257. DECLARE_ALIGNED_16(int, s);
  258. const vector unsigned int zero = (const vector unsigned int)vec_splat_u32(0);
  259. vector unsigned char *tv;
  260. vector unsigned char pixv;
  261. vector unsigned int sv;
  262. vector signed int sum;
  263. sv = (vector unsigned int)vec_splat_u32(0);
  264. s = 0;
  265. for (i = 0; i < 16; i++) {
  266. /* Read in the potentially unaligned pixels */
  267. tv = (vector unsigned char *) pix;
  268. pixv = vec_perm(tv[0], tv[1], vec_lvsl(0, pix));
  269. /* Square the values, and add them to our sum */
  270. sv = vec_msum(pixv, pixv, sv);
  271. pix += line_size;
  272. }
  273. /* Sum up the four partial sums, and put the result into s */
  274. sum = vec_sums((vector signed int) sv, (vector signed int) zero);
  275. sum = vec_splat(sum, 3);
  276. vec_ste(sum, 0, &s);
  277. return s;
  278. }
  279. /**
  280. * Sum of Squared Errors for a 8x8 block.
  281. * AltiVec-enhanced.
  282. * It's the sad8_altivec code above w/ squaring added.
  283. */
  284. int sse8_altivec(void *v, uint8_t *pix1, uint8_t *pix2, int line_size, int h)
  285. {
  286. int i;
  287. DECLARE_ALIGNED_16(int, s);
  288. const vector unsigned int zero = (const vector unsigned int)vec_splat_u32(0);
  289. vector unsigned char perm1, perm2, permclear, *pix1v, *pix2v;
  290. vector unsigned char t1, t2, t3,t4, t5;
  291. vector unsigned int sum;
  292. vector signed int sumsqr;
  293. sum = (vector unsigned int)vec_splat_u32(0);
  294. permclear = (vector unsigned char){255,255,255,255,255,255,255,255,0,0,0,0,0,0,0,0};
  295. for (i = 0; i < h; i++) {
  296. /* Read potentially unaligned pixels into t1 and t2
  297. Since we're reading 16 pixels, and actually only want 8,
  298. mask out the last 8 pixels. The 0s don't change the sum. */
  299. perm1 = vec_lvsl(0, pix1);
  300. pix1v = (vector unsigned char *) pix1;
  301. perm2 = vec_lvsl(0, pix2);
  302. pix2v = (vector unsigned char *) pix2;
  303. t1 = vec_and(vec_perm(pix1v[0], pix1v[1], perm1), permclear);
  304. t2 = vec_and(vec_perm(pix2v[0], pix2v[1], perm2), permclear);
  305. /* Since we want to use unsigned chars, we can take advantage
  306. of the fact that abs(a-b)^2 = (a-b)^2. */
  307. /* Calculate abs differences vector */
  308. t3 = vec_max(t1, t2);
  309. t4 = vec_min(t1, t2);
  310. t5 = vec_sub(t3, t4);
  311. /* Square the values and add them to our sum */
  312. sum = vec_msum(t5, t5, sum);
  313. pix1 += line_size;
  314. pix2 += line_size;
  315. }
  316. /* Sum up the four partial sums, and put the result into s */
  317. sumsqr = vec_sums((vector signed int) sum, (vector signed int) zero);
  318. sumsqr = vec_splat(sumsqr, 3);
  319. vec_ste(sumsqr, 0, &s);
  320. return s;
  321. }
  322. /**
  323. * Sum of Squared Errors for a 16x16 block.
  324. * AltiVec-enhanced.
  325. * It's the sad16_altivec code above w/ squaring added.
  326. */
  327. int sse16_altivec(void *v, uint8_t *pix1, uint8_t *pix2, int line_size, int h)
  328. {
  329. int i;
  330. DECLARE_ALIGNED_16(int, s);
  331. const vector unsigned int zero = (const vector unsigned int)vec_splat_u32(0);
  332. vector unsigned char perm1, perm2, *pix1v, *pix2v;
  333. vector unsigned char t1, t2, t3,t4, t5;
  334. vector unsigned int sum;
  335. vector signed int sumsqr;
  336. sum = (vector unsigned int)vec_splat_u32(0);
  337. for (i = 0; i < h; i++) {
  338. /* Read potentially unaligned pixels into t1 and t2 */
  339. perm1 = vec_lvsl(0, pix1);
  340. pix1v = (vector unsigned char *) pix1;
  341. perm2 = vec_lvsl(0, pix2);
  342. pix2v = (vector unsigned char *) pix2;
  343. t1 = vec_perm(pix1v[0], pix1v[1], perm1);
  344. t2 = vec_perm(pix2v[0], pix2v[1], perm2);
  345. /* Since we want to use unsigned chars, we can take advantage
  346. of the fact that abs(a-b)^2 = (a-b)^2. */
  347. /* Calculate abs differences vector */
  348. t3 = vec_max(t1, t2);
  349. t4 = vec_min(t1, t2);
  350. t5 = vec_sub(t3, t4);
  351. /* Square the values and add them to our sum */
  352. sum = vec_msum(t5, t5, sum);
  353. pix1 += line_size;
  354. pix2 += line_size;
  355. }
  356. /* Sum up the four partial sums, and put the result into s */
  357. sumsqr = vec_sums((vector signed int) sum, (vector signed int) zero);
  358. sumsqr = vec_splat(sumsqr, 3);
  359. vec_ste(sumsqr, 0, &s);
  360. return s;
  361. }
  362. int pix_sum_altivec(uint8_t * pix, int line_size)
  363. {
  364. const vector unsigned int zero = (const vector unsigned int)vec_splat_u32(0);
  365. vector unsigned char perm, *pixv;
  366. vector unsigned char t1;
  367. vector unsigned int sad;
  368. vector signed int sumdiffs;
  369. int i;
  370. DECLARE_ALIGNED_16(int, s);
  371. sad = (vector unsigned int)vec_splat_u32(0);
  372. for (i = 0; i < 16; i++) {
  373. /* Read the potentially unaligned 16 pixels into t1 */
  374. perm = vec_lvsl(0, pix);
  375. pixv = (vector unsigned char *) pix;
  376. t1 = vec_perm(pixv[0], pixv[1], perm);
  377. /* Add each 4 pixel group together and put 4 results into sad */
  378. sad = vec_sum4s(t1, sad);
  379. pix += line_size;
  380. }
  381. /* Sum up the four partial sums, and put the result into s */
  382. sumdiffs = vec_sums((vector signed int) sad, (vector signed int) zero);
  383. sumdiffs = vec_splat(sumdiffs, 3);
  384. vec_ste(sumdiffs, 0, &s);
  385. return s;
  386. }
  387. void get_pixels_altivec(DCTELEM *restrict block, const uint8_t *pixels, int line_size)
  388. {
  389. int i;
  390. vector unsigned char perm, bytes, *pixv;
  391. const vector unsigned char zero = (const vector unsigned char)vec_splat_u8(0);
  392. vector signed short shorts;
  393. for (i = 0; i < 8; i++) {
  394. // Read potentially unaligned pixels.
  395. // We're reading 16 pixels, and actually only want 8,
  396. // but we simply ignore the extras.
  397. perm = vec_lvsl(0, pixels);
  398. pixv = (vector unsigned char *) pixels;
  399. bytes = vec_perm(pixv[0], pixv[1], perm);
  400. // convert the bytes into shorts
  401. shorts = (vector signed short)vec_mergeh(zero, bytes);
  402. // save the data to the block, we assume the block is 16-byte aligned
  403. vec_st(shorts, i*16, (vector signed short*)block);
  404. pixels += line_size;
  405. }
  406. }
  407. void diff_pixels_altivec(DCTELEM *restrict block, const uint8_t *s1,
  408. const uint8_t *s2, int stride)
  409. {
  410. int i;
  411. vector unsigned char perm, bytes, *pixv;
  412. const vector unsigned char zero = (const vector unsigned char)vec_splat_u8(0);
  413. vector signed short shorts1, shorts2;
  414. for (i = 0; i < 4; i++) {
  415. // Read potentially unaligned pixels
  416. // We're reading 16 pixels, and actually only want 8,
  417. // but we simply ignore the extras.
  418. perm = vec_lvsl(0, s1);
  419. pixv = (vector unsigned char *) s1;
  420. bytes = vec_perm(pixv[0], pixv[1], perm);
  421. // convert the bytes into shorts
  422. shorts1 = (vector signed short)vec_mergeh(zero, bytes);
  423. // Do the same for the second block of pixels
  424. perm = vec_lvsl(0, s2);
  425. pixv = (vector unsigned char *) s2;
  426. bytes = vec_perm(pixv[0], pixv[1], perm);
  427. // convert the bytes into shorts
  428. shorts2 = (vector signed short)vec_mergeh(zero, bytes);
  429. // Do the subtraction
  430. shorts1 = vec_sub(shorts1, shorts2);
  431. // save the data to the block, we assume the block is 16-byte aligned
  432. vec_st(shorts1, 0, (vector signed short*)block);
  433. s1 += stride;
  434. s2 += stride;
  435. block += 8;
  436. // The code below is a copy of the code above... This is a manual
  437. // unroll.
  438. // Read potentially unaligned pixels
  439. // We're reading 16 pixels, and actually only want 8,
  440. // but we simply ignore the extras.
  441. perm = vec_lvsl(0, s1);
  442. pixv = (vector unsigned char *) s1;
  443. bytes = vec_perm(pixv[0], pixv[1], perm);
  444. // convert the bytes into shorts
  445. shorts1 = (vector signed short)vec_mergeh(zero, bytes);
  446. // Do the same for the second block of pixels
  447. perm = vec_lvsl(0, s2);
  448. pixv = (vector unsigned char *) s2;
  449. bytes = vec_perm(pixv[0], pixv[1], perm);
  450. // convert the bytes into shorts
  451. shorts2 = (vector signed short)vec_mergeh(zero, bytes);
  452. // Do the subtraction
  453. shorts1 = vec_sub(shorts1, shorts2);
  454. // save the data to the block, we assume the block is 16-byte aligned
  455. vec_st(shorts1, 0, (vector signed short*)block);
  456. s1 += stride;
  457. s2 += stride;
  458. block += 8;
  459. }
  460. }
  461. static void clear_block_altivec(DCTELEM *block) {
  462. LOAD_ZERO;
  463. vec_st(zero_s16v, 0, block);
  464. vec_st(zero_s16v, 16, block);
  465. vec_st(zero_s16v, 32, block);
  466. vec_st(zero_s16v, 48, block);
  467. vec_st(zero_s16v, 64, block);
  468. vec_st(zero_s16v, 80, block);
  469. vec_st(zero_s16v, 96, block);
  470. vec_st(zero_s16v, 112, block);
  471. }
  472. void add_bytes_altivec(uint8_t *dst, uint8_t *src, int w) {
  473. register int i;
  474. register vector unsigned char vdst, vsrc;
  475. /* dst and src are 16 bytes-aligned (guaranteed) */
  476. for (i = 0 ; (i + 15) < w ; i+=16) {
  477. vdst = vec_ld(i, (unsigned char*)dst);
  478. vsrc = vec_ld(i, (unsigned char*)src);
  479. vdst = vec_add(vsrc, vdst);
  480. vec_st(vdst, i, (unsigned char*)dst);
  481. }
  482. /* if w is not a multiple of 16 */
  483. for (; (i < w) ; i++) {
  484. dst[i] = src[i];
  485. }
  486. }
  487. /* next one assumes that ((line_size % 16) == 0) */
  488. void put_pixels16_altivec(uint8_t *block, const uint8_t *pixels, int line_size, int h)
  489. {
  490. POWERPC_PERF_DECLARE(altivec_put_pixels16_num, 1);
  491. register vector unsigned char pixelsv1, pixelsv2;
  492. register vector unsigned char pixelsv1B, pixelsv2B;
  493. register vector unsigned char pixelsv1C, pixelsv2C;
  494. register vector unsigned char pixelsv1D, pixelsv2D;
  495. register vector unsigned char perm = vec_lvsl(0, pixels);
  496. int i;
  497. register int line_size_2 = line_size << 1;
  498. register int line_size_3 = line_size + line_size_2;
  499. register int line_size_4 = line_size << 2;
  500. POWERPC_PERF_START_COUNT(altivec_put_pixels16_num, 1);
  501. // hand-unrolling the loop by 4 gains about 15%
  502. // mininum execution time goes from 74 to 60 cycles
  503. // it's faster than -funroll-loops, but using
  504. // -funroll-loops w/ this is bad - 74 cycles again.
  505. // all this is on a 7450, tuning for the 7450
  506. #if 0
  507. for (i = 0; i < h; i++) {
  508. pixelsv1 = vec_ld(0, (unsigned char*)pixels);
  509. pixelsv2 = vec_ld(16, (unsigned char*)pixels);
  510. vec_st(vec_perm(pixelsv1, pixelsv2, perm),
  511. 0, (unsigned char*)block);
  512. pixels+=line_size;
  513. block +=line_size;
  514. }
  515. #else
  516. for (i = 0; i < h; i += 4) {
  517. pixelsv1 = vec_ld(0, (unsigned char*)pixels);
  518. pixelsv2 = vec_ld(15, (unsigned char*)pixels);
  519. pixelsv1B = vec_ld(line_size, (unsigned char*)pixels);
  520. pixelsv2B = vec_ld(15 + line_size, (unsigned char*)pixels);
  521. pixelsv1C = vec_ld(line_size_2, (unsigned char*)pixels);
  522. pixelsv2C = vec_ld(15 + line_size_2, (unsigned char*)pixels);
  523. pixelsv1D = vec_ld(line_size_3, (unsigned char*)pixels);
  524. pixelsv2D = vec_ld(15 + line_size_3, (unsigned char*)pixels);
  525. vec_st(vec_perm(pixelsv1, pixelsv2, perm),
  526. 0, (unsigned char*)block);
  527. vec_st(vec_perm(pixelsv1B, pixelsv2B, perm),
  528. line_size, (unsigned char*)block);
  529. vec_st(vec_perm(pixelsv1C, pixelsv2C, perm),
  530. line_size_2, (unsigned char*)block);
  531. vec_st(vec_perm(pixelsv1D, pixelsv2D, perm),
  532. line_size_3, (unsigned char*)block);
  533. pixels+=line_size_4;
  534. block +=line_size_4;
  535. }
  536. #endif
  537. POWERPC_PERF_STOP_COUNT(altivec_put_pixels16_num, 1);
  538. }
  539. /* next one assumes that ((line_size % 16) == 0) */
  540. #define op_avg(a,b) a = ( ((a)|(b)) - ((((a)^(b))&0xFEFEFEFEUL)>>1) )
  541. void avg_pixels16_altivec(uint8_t *block, const uint8_t *pixels, int line_size, int h)
  542. {
  543. POWERPC_PERF_DECLARE(altivec_avg_pixels16_num, 1);
  544. register vector unsigned char pixelsv1, pixelsv2, pixelsv, blockv;
  545. register vector unsigned char perm = vec_lvsl(0, pixels);
  546. int i;
  547. POWERPC_PERF_START_COUNT(altivec_avg_pixels16_num, 1);
  548. for (i = 0; i < h; i++) {
  549. pixelsv1 = vec_ld(0, (unsigned char*)pixels);
  550. pixelsv2 = vec_ld(16, (unsigned char*)pixels);
  551. blockv = vec_ld(0, block);
  552. pixelsv = vec_perm(pixelsv1, pixelsv2, perm);
  553. blockv = vec_avg(blockv,pixelsv);
  554. vec_st(blockv, 0, (unsigned char*)block);
  555. pixels+=line_size;
  556. block +=line_size;
  557. }
  558. POWERPC_PERF_STOP_COUNT(altivec_avg_pixels16_num, 1);
  559. }
  560. /* next one assumes that ((line_size % 8) == 0) */
  561. void avg_pixels8_altivec(uint8_t * block, const uint8_t * pixels, int line_size, int h)
  562. {
  563. POWERPC_PERF_DECLARE(altivec_avg_pixels8_num, 1);
  564. register vector unsigned char pixelsv1, pixelsv2, pixelsv, blockv;
  565. int i;
  566. POWERPC_PERF_START_COUNT(altivec_avg_pixels8_num, 1);
  567. for (i = 0; i < h; i++) {
  568. /* block is 8 bytes-aligned, so we're either in the
  569. left block (16 bytes-aligned) or in the right block (not) */
  570. int rightside = ((unsigned long)block & 0x0000000F);
  571. blockv = vec_ld(0, block);
  572. pixelsv1 = vec_ld(0, (unsigned char*)pixels);
  573. pixelsv2 = vec_ld(16, (unsigned char*)pixels);
  574. pixelsv = vec_perm(pixelsv1, pixelsv2, vec_lvsl(0, pixels));
  575. if (rightside) {
  576. pixelsv = vec_perm(blockv, pixelsv, vcprm(0,1,s0,s1));
  577. } else {
  578. pixelsv = vec_perm(blockv, pixelsv, vcprm(s0,s1,2,3));
  579. }
  580. blockv = vec_avg(blockv, pixelsv);
  581. vec_st(blockv, 0, block);
  582. pixels += line_size;
  583. block += line_size;
  584. }
  585. POWERPC_PERF_STOP_COUNT(altivec_avg_pixels8_num, 1);
  586. }
  587. /* next one assumes that ((line_size % 8) == 0) */
  588. void put_pixels8_xy2_altivec(uint8_t *block, const uint8_t *pixels, int line_size, int h)
  589. {
  590. POWERPC_PERF_DECLARE(altivec_put_pixels8_xy2_num, 1);
  591. register int i;
  592. register vector unsigned char pixelsv1, pixelsv2, pixelsavg;
  593. register vector unsigned char blockv, temp1, temp2;
  594. register vector unsigned short pixelssum1, pixelssum2, temp3;
  595. register const vector unsigned char vczero = (const vector unsigned char)vec_splat_u8(0);
  596. register const vector unsigned short vctwo = (const vector unsigned short)vec_splat_u16(2);
  597. temp1 = vec_ld(0, pixels);
  598. temp2 = vec_ld(16, pixels);
  599. pixelsv1 = vec_perm(temp1, temp2, vec_lvsl(0, pixels));
  600. if ((((unsigned long)pixels) & 0x0000000F) == 0x0000000F) {
  601. pixelsv2 = temp2;
  602. } else {
  603. pixelsv2 = vec_perm(temp1, temp2, vec_lvsl(1, pixels));
  604. }
  605. pixelsv1 = vec_mergeh(vczero, pixelsv1);
  606. pixelsv2 = vec_mergeh(vczero, pixelsv2);
  607. pixelssum1 = vec_add((vector unsigned short)pixelsv1,
  608. (vector unsigned short)pixelsv2);
  609. pixelssum1 = vec_add(pixelssum1, vctwo);
  610. POWERPC_PERF_START_COUNT(altivec_put_pixels8_xy2_num, 1);
  611. for (i = 0; i < h ; i++) {
  612. int rightside = ((unsigned long)block & 0x0000000F);
  613. blockv = vec_ld(0, block);
  614. temp1 = vec_ld(line_size, pixels);
  615. temp2 = vec_ld(line_size + 16, pixels);
  616. pixelsv1 = vec_perm(temp1, temp2, vec_lvsl(line_size, pixels));
  617. if (((((unsigned long)pixels) + line_size) & 0x0000000F) == 0x0000000F) {
  618. pixelsv2 = temp2;
  619. } else {
  620. pixelsv2 = vec_perm(temp1, temp2, vec_lvsl(line_size + 1, pixels));
  621. }
  622. pixelsv1 = vec_mergeh(vczero, pixelsv1);
  623. pixelsv2 = vec_mergeh(vczero, pixelsv2);
  624. pixelssum2 = vec_add((vector unsigned short)pixelsv1,
  625. (vector unsigned short)pixelsv2);
  626. temp3 = vec_add(pixelssum1, pixelssum2);
  627. temp3 = vec_sra(temp3, vctwo);
  628. pixelssum1 = vec_add(pixelssum2, vctwo);
  629. pixelsavg = vec_packsu(temp3, (vector unsigned short) vczero);
  630. if (rightside) {
  631. blockv = vec_perm(blockv, pixelsavg, vcprm(0, 1, s0, s1));
  632. } else {
  633. blockv = vec_perm(blockv, pixelsavg, vcprm(s0, s1, 2, 3));
  634. }
  635. vec_st(blockv, 0, block);
  636. block += line_size;
  637. pixels += line_size;
  638. }
  639. POWERPC_PERF_STOP_COUNT(altivec_put_pixels8_xy2_num, 1);
  640. }
  641. /* next one assumes that ((line_size % 8) == 0) */
  642. void put_no_rnd_pixels8_xy2_altivec(uint8_t *block, const uint8_t *pixels, int line_size, int h)
  643. {
  644. POWERPC_PERF_DECLARE(altivec_put_no_rnd_pixels8_xy2_num, 1);
  645. register int i;
  646. register vector unsigned char pixelsv1, pixelsv2, pixelsavg;
  647. register vector unsigned char blockv, temp1, temp2;
  648. register vector unsigned short pixelssum1, pixelssum2, temp3;
  649. register const vector unsigned char vczero = (const vector unsigned char)vec_splat_u8(0);
  650. register const vector unsigned short vcone = (const vector unsigned short)vec_splat_u16(1);
  651. register const vector unsigned short vctwo = (const vector unsigned short)vec_splat_u16(2);
  652. temp1 = vec_ld(0, pixels);
  653. temp2 = vec_ld(16, pixels);
  654. pixelsv1 = vec_perm(temp1, temp2, vec_lvsl(0, pixels));
  655. if ((((unsigned long)pixels) & 0x0000000F) == 0x0000000F) {
  656. pixelsv2 = temp2;
  657. } else {
  658. pixelsv2 = vec_perm(temp1, temp2, vec_lvsl(1, pixels));
  659. }
  660. pixelsv1 = vec_mergeh(vczero, pixelsv1);
  661. pixelsv2 = vec_mergeh(vczero, pixelsv2);
  662. pixelssum1 = vec_add((vector unsigned short)pixelsv1,
  663. (vector unsigned short)pixelsv2);
  664. pixelssum1 = vec_add(pixelssum1, vcone);
  665. POWERPC_PERF_START_COUNT(altivec_put_no_rnd_pixels8_xy2_num, 1);
  666. for (i = 0; i < h ; i++) {
  667. int rightside = ((unsigned long)block & 0x0000000F);
  668. blockv = vec_ld(0, block);
  669. temp1 = vec_ld(line_size, pixels);
  670. temp2 = vec_ld(line_size + 16, pixels);
  671. pixelsv1 = vec_perm(temp1, temp2, vec_lvsl(line_size, pixels));
  672. if (((((unsigned long)pixels) + line_size) & 0x0000000F) == 0x0000000F) {
  673. pixelsv2 = temp2;
  674. } else {
  675. pixelsv2 = vec_perm(temp1, temp2, vec_lvsl(line_size + 1, pixels));
  676. }
  677. pixelsv1 = vec_mergeh(vczero, pixelsv1);
  678. pixelsv2 = vec_mergeh(vczero, pixelsv2);
  679. pixelssum2 = vec_add((vector unsigned short)pixelsv1,
  680. (vector unsigned short)pixelsv2);
  681. temp3 = vec_add(pixelssum1, pixelssum2);
  682. temp3 = vec_sra(temp3, vctwo);
  683. pixelssum1 = vec_add(pixelssum2, vcone);
  684. pixelsavg = vec_packsu(temp3, (vector unsigned short) vczero);
  685. if (rightside) {
  686. blockv = vec_perm(blockv, pixelsavg, vcprm(0, 1, s0, s1));
  687. } else {
  688. blockv = vec_perm(blockv, pixelsavg, vcprm(s0, s1, 2, 3));
  689. }
  690. vec_st(blockv, 0, block);
  691. block += line_size;
  692. pixels += line_size;
  693. }
  694. POWERPC_PERF_STOP_COUNT(altivec_put_no_rnd_pixels8_xy2_num, 1);
  695. }
  696. /* next one assumes that ((line_size % 16) == 0) */
  697. void put_pixels16_xy2_altivec(uint8_t * block, const uint8_t * pixels, int line_size, int h)
  698. {
  699. POWERPC_PERF_DECLARE(altivec_put_pixels16_xy2_num, 1);
  700. register int i;
  701. register vector unsigned char pixelsv1, pixelsv2, pixelsv3, pixelsv4;
  702. register vector unsigned char blockv, temp1, temp2;
  703. register vector unsigned short temp3, temp4,
  704. pixelssum1, pixelssum2, pixelssum3, pixelssum4;
  705. register const vector unsigned char vczero = (const vector unsigned char)vec_splat_u8(0);
  706. register const vector unsigned short vctwo = (const vector unsigned short)vec_splat_u16(2);
  707. POWERPC_PERF_START_COUNT(altivec_put_pixels16_xy2_num, 1);
  708. temp1 = vec_ld(0, pixels);
  709. temp2 = vec_ld(16, pixels);
  710. pixelsv1 = vec_perm(temp1, temp2, vec_lvsl(0, pixels));
  711. if ((((unsigned long)pixels) & 0x0000000F) == 0x0000000F) {
  712. pixelsv2 = temp2;
  713. } else {
  714. pixelsv2 = vec_perm(temp1, temp2, vec_lvsl(1, pixels));
  715. }
  716. pixelsv3 = vec_mergel(vczero, pixelsv1);
  717. pixelsv4 = vec_mergel(vczero, pixelsv2);
  718. pixelsv1 = vec_mergeh(vczero, pixelsv1);
  719. pixelsv2 = vec_mergeh(vczero, pixelsv2);
  720. pixelssum3 = vec_add((vector unsigned short)pixelsv3,
  721. (vector unsigned short)pixelsv4);
  722. pixelssum3 = vec_add(pixelssum3, vctwo);
  723. pixelssum1 = vec_add((vector unsigned short)pixelsv1,
  724. (vector unsigned short)pixelsv2);
  725. pixelssum1 = vec_add(pixelssum1, vctwo);
  726. for (i = 0; i < h ; i++) {
  727. blockv = vec_ld(0, block);
  728. temp1 = vec_ld(line_size, pixels);
  729. temp2 = vec_ld(line_size + 16, pixels);
  730. pixelsv1 = vec_perm(temp1, temp2, vec_lvsl(line_size, pixels));
  731. if (((((unsigned long)pixels) + line_size) & 0x0000000F) == 0x0000000F) {
  732. pixelsv2 = temp2;
  733. } else {
  734. pixelsv2 = vec_perm(temp1, temp2, vec_lvsl(line_size + 1, pixels));
  735. }
  736. pixelsv3 = vec_mergel(vczero, pixelsv1);
  737. pixelsv4 = vec_mergel(vczero, pixelsv2);
  738. pixelsv1 = vec_mergeh(vczero, pixelsv1);
  739. pixelsv2 = vec_mergeh(vczero, pixelsv2);
  740. pixelssum4 = vec_add((vector unsigned short)pixelsv3,
  741. (vector unsigned short)pixelsv4);
  742. pixelssum2 = vec_add((vector unsigned short)pixelsv1,
  743. (vector unsigned short)pixelsv2);
  744. temp4 = vec_add(pixelssum3, pixelssum4);
  745. temp4 = vec_sra(temp4, vctwo);
  746. temp3 = vec_add(pixelssum1, pixelssum2);
  747. temp3 = vec_sra(temp3, vctwo);
  748. pixelssum3 = vec_add(pixelssum4, vctwo);
  749. pixelssum1 = vec_add(pixelssum2, vctwo);
  750. blockv = vec_packsu(temp3, temp4);
  751. vec_st(blockv, 0, block);
  752. block += line_size;
  753. pixels += line_size;
  754. }
  755. POWERPC_PERF_STOP_COUNT(altivec_put_pixels16_xy2_num, 1);
  756. }
  757. /* next one assumes that ((line_size % 16) == 0) */
  758. void put_no_rnd_pixels16_xy2_altivec(uint8_t * block, const uint8_t * pixels, int line_size, int h)
  759. {
  760. POWERPC_PERF_DECLARE(altivec_put_no_rnd_pixels16_xy2_num, 1);
  761. register int i;
  762. register vector unsigned char pixelsv1, pixelsv2, pixelsv3, pixelsv4;
  763. register vector unsigned char blockv, temp1, temp2;
  764. register vector unsigned short temp3, temp4,
  765. pixelssum1, pixelssum2, pixelssum3, pixelssum4;
  766. register const vector unsigned char vczero = (const vector unsigned char)vec_splat_u8(0);
  767. register const vector unsigned short vcone = (const vector unsigned short)vec_splat_u16(1);
  768. register const vector unsigned short vctwo = (const vector unsigned short)vec_splat_u16(2);
  769. POWERPC_PERF_START_COUNT(altivec_put_no_rnd_pixels16_xy2_num, 1);
  770. temp1 = vec_ld(0, pixels);
  771. temp2 = vec_ld(16, pixels);
  772. pixelsv1 = vec_perm(temp1, temp2, vec_lvsl(0, pixels));
  773. if ((((unsigned long)pixels) & 0x0000000F) == 0x0000000F) {
  774. pixelsv2 = temp2;
  775. } else {
  776. pixelsv2 = vec_perm(temp1, temp2, vec_lvsl(1, pixels));
  777. }
  778. pixelsv3 = vec_mergel(vczero, pixelsv1);
  779. pixelsv4 = vec_mergel(vczero, pixelsv2);
  780. pixelsv1 = vec_mergeh(vczero, pixelsv1);
  781. pixelsv2 = vec_mergeh(vczero, pixelsv2);
  782. pixelssum3 = vec_add((vector unsigned short)pixelsv3,
  783. (vector unsigned short)pixelsv4);
  784. pixelssum3 = vec_add(pixelssum3, vcone);
  785. pixelssum1 = vec_add((vector unsigned short)pixelsv1,
  786. (vector unsigned short)pixelsv2);
  787. pixelssum1 = vec_add(pixelssum1, vcone);
  788. for (i = 0; i < h ; i++) {
  789. blockv = vec_ld(0, block);
  790. temp1 = vec_ld(line_size, pixels);
  791. temp2 = vec_ld(line_size + 16, pixels);
  792. pixelsv1 = vec_perm(temp1, temp2, vec_lvsl(line_size, pixels));
  793. if (((((unsigned long)pixels) + line_size) & 0x0000000F) == 0x0000000F) {
  794. pixelsv2 = temp2;
  795. } else {
  796. pixelsv2 = vec_perm(temp1, temp2, vec_lvsl(line_size + 1, pixels));
  797. }
  798. pixelsv3 = vec_mergel(vczero, pixelsv1);
  799. pixelsv4 = vec_mergel(vczero, pixelsv2);
  800. pixelsv1 = vec_mergeh(vczero, pixelsv1);
  801. pixelsv2 = vec_mergeh(vczero, pixelsv2);
  802. pixelssum4 = vec_add((vector unsigned short)pixelsv3,
  803. (vector unsigned short)pixelsv4);
  804. pixelssum2 = vec_add((vector unsigned short)pixelsv1,
  805. (vector unsigned short)pixelsv2);
  806. temp4 = vec_add(pixelssum3, pixelssum4);
  807. temp4 = vec_sra(temp4, vctwo);
  808. temp3 = vec_add(pixelssum1, pixelssum2);
  809. temp3 = vec_sra(temp3, vctwo);
  810. pixelssum3 = vec_add(pixelssum4, vcone);
  811. pixelssum1 = vec_add(pixelssum2, vcone);
  812. blockv = vec_packsu(temp3, temp4);
  813. vec_st(blockv, 0, block);
  814. block += line_size;
  815. pixels += line_size;
  816. }
  817. POWERPC_PERF_STOP_COUNT(altivec_put_no_rnd_pixels16_xy2_num, 1);
  818. }
  819. int hadamard8_diff8x8_altivec(/*MpegEncContext*/ void *s, uint8_t *dst, uint8_t *src, int stride, int h){
  820. POWERPC_PERF_DECLARE(altivec_hadamard8_diff8x8_num, 1);
  821. int sum;
  822. register const vector unsigned char vzero =
  823. (const vector unsigned char)vec_splat_u8(0);
  824. register vector signed short temp0, temp1, temp2, temp3, temp4,
  825. temp5, temp6, temp7;
  826. POWERPC_PERF_START_COUNT(altivec_hadamard8_diff8x8_num, 1);
  827. {
  828. register const vector signed short vprod1 =(const vector signed short)
  829. { 1,-1, 1,-1, 1,-1, 1,-1 };
  830. register const vector signed short vprod2 =(const vector signed short)
  831. { 1, 1,-1,-1, 1, 1,-1,-1 };
  832. register const vector signed short vprod3 =(const vector signed short)
  833. { 1, 1, 1, 1,-1,-1,-1,-1 };
  834. register const vector unsigned char perm1 = (const vector unsigned char)
  835. {0x02, 0x03, 0x00, 0x01, 0x06, 0x07, 0x04, 0x05,
  836. 0x0A, 0x0B, 0x08, 0x09, 0x0E, 0x0F, 0x0C, 0x0D};
  837. register const vector unsigned char perm2 = (const vector unsigned char)
  838. {0x04, 0x05, 0x06, 0x07, 0x00, 0x01, 0x02, 0x03,
  839. 0x0C, 0x0D, 0x0E, 0x0F, 0x08, 0x09, 0x0A, 0x0B};
  840. register const vector unsigned char perm3 = (const vector unsigned char)
  841. {0x08, 0x09, 0x0A, 0x0B, 0x0C, 0x0D, 0x0E, 0x0F,
  842. 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07};
  843. #define ONEITERBUTTERFLY(i, res) \
  844. { \
  845. register vector unsigned char src1, src2, srcO; \
  846. register vector unsigned char dst1, dst2, dstO; \
  847. register vector signed short srcV, dstV; \
  848. register vector signed short but0, but1, but2, op1, op2, op3; \
  849. src1 = vec_ld(stride * i, src); \
  850. src2 = vec_ld((stride * i) + 15, src); \
  851. srcO = vec_perm(src1, src2, vec_lvsl(stride * i, src)); \
  852. dst1 = vec_ld(stride * i, dst); \
  853. dst2 = vec_ld((stride * i) + 15, dst); \
  854. dstO = vec_perm(dst1, dst2, vec_lvsl(stride * i, dst)); \
  855. /* promote the unsigned chars to signed shorts */ \
  856. /* we're in the 8x8 function, we only care for the first 8 */ \
  857. srcV = (vector signed short)vec_mergeh((vector signed char)vzero, \
  858. (vector signed char)srcO); \
  859. dstV = (vector signed short)vec_mergeh((vector signed char)vzero, \
  860. (vector signed char)dstO); \
  861. /* subtractions inside the first butterfly */ \
  862. but0 = vec_sub(srcV, dstV); \
  863. op1 = vec_perm(but0, but0, perm1); \
  864. but1 = vec_mladd(but0, vprod1, op1); \
  865. op2 = vec_perm(but1, but1, perm2); \
  866. but2 = vec_mladd(but1, vprod2, op2); \
  867. op3 = vec_perm(but2, but2, perm3); \
  868. res = vec_mladd(but2, vprod3, op3); \
  869. }
  870. ONEITERBUTTERFLY(0, temp0);
  871. ONEITERBUTTERFLY(1, temp1);
  872. ONEITERBUTTERFLY(2, temp2);
  873. ONEITERBUTTERFLY(3, temp3);
  874. ONEITERBUTTERFLY(4, temp4);
  875. ONEITERBUTTERFLY(5, temp5);
  876. ONEITERBUTTERFLY(6, temp6);
  877. ONEITERBUTTERFLY(7, temp7);
  878. }
  879. #undef ONEITERBUTTERFLY
  880. {
  881. register vector signed int vsum;
  882. register vector signed short line0 = vec_add(temp0, temp1);
  883. register vector signed short line1 = vec_sub(temp0, temp1);
  884. register vector signed short line2 = vec_add(temp2, temp3);
  885. register vector signed short line3 = vec_sub(temp2, temp3);
  886. register vector signed short line4 = vec_add(temp4, temp5);
  887. register vector signed short line5 = vec_sub(temp4, temp5);
  888. register vector signed short line6 = vec_add(temp6, temp7);
  889. register vector signed short line7 = vec_sub(temp6, temp7);
  890. register vector signed short line0B = vec_add(line0, line2);
  891. register vector signed short line2B = vec_sub(line0, line2);
  892. register vector signed short line1B = vec_add(line1, line3);
  893. register vector signed short line3B = vec_sub(line1, line3);
  894. register vector signed short line4B = vec_add(line4, line6);
  895. register vector signed short line6B = vec_sub(line4, line6);
  896. register vector signed short line5B = vec_add(line5, line7);
  897. register vector signed short line7B = vec_sub(line5, line7);
  898. register vector signed short line0C = vec_add(line0B, line4B);
  899. register vector signed short line4C = vec_sub(line0B, line4B);
  900. register vector signed short line1C = vec_add(line1B, line5B);
  901. register vector signed short line5C = vec_sub(line1B, line5B);
  902. register vector signed short line2C = vec_add(line2B, line6B);
  903. register vector signed short line6C = vec_sub(line2B, line6B);
  904. register vector signed short line3C = vec_add(line3B, line7B);
  905. register vector signed short line7C = vec_sub(line3B, line7B);
  906. vsum = vec_sum4s(vec_abs(line0C), vec_splat_s32(0));
  907. vsum = vec_sum4s(vec_abs(line1C), vsum);
  908. vsum = vec_sum4s(vec_abs(line2C), vsum);
  909. vsum = vec_sum4s(vec_abs(line3C), vsum);
  910. vsum = vec_sum4s(vec_abs(line4C), vsum);
  911. vsum = vec_sum4s(vec_abs(line5C), vsum);
  912. vsum = vec_sum4s(vec_abs(line6C), vsum);
  913. vsum = vec_sum4s(vec_abs(line7C), vsum);
  914. vsum = vec_sums(vsum, (vector signed int)vzero);
  915. vsum = vec_splat(vsum, 3);
  916. vec_ste(vsum, 0, &sum);
  917. }
  918. POWERPC_PERF_STOP_COUNT(altivec_hadamard8_diff8x8_num, 1);
  919. return sum;
  920. }
  921. /*
  922. 16x8 works with 16 elements; it allows to avoid replicating loads, and
  923. give the compiler more rooms for scheduling. It's only used from
  924. inside hadamard8_diff16_altivec.
  925. Unfortunately, it seems gcc-3.3 is a bit dumb, and the compiled code has a LOT
  926. of spill code, it seems gcc (unlike xlc) cannot keep everything in registers
  927. by itself. The following code include hand-made registers allocation. It's not
  928. clean, but on a 7450 the resulting code is much faster (best case fall from
  929. 700+ cycles to 550).
  930. xlc doesn't add spill code, but it doesn't know how to schedule for the 7450,
  931. and its code isn't much faster than gcc-3.3 on the 7450 (but uses 25% less
  932. instructions...)
  933. On the 970, the hand-made RA is still a win (around 690 vs. around 780), but
  934. xlc goes to around 660 on the regular C code...
  935. */
  936. static int hadamard8_diff16x8_altivec(/*MpegEncContext*/ void *s, uint8_t *dst, uint8_t *src, int stride, int h) {
  937. int sum;
  938. register vector signed short
  939. temp0 REG_v(v0),
  940. temp1 REG_v(v1),
  941. temp2 REG_v(v2),
  942. temp3 REG_v(v3),
  943. temp4 REG_v(v4),
  944. temp5 REG_v(v5),
  945. temp6 REG_v(v6),
  946. temp7 REG_v(v7);
  947. register vector signed short
  948. temp0S REG_v(v8),
  949. temp1S REG_v(v9),
  950. temp2S REG_v(v10),
  951. temp3S REG_v(v11),
  952. temp4S REG_v(v12),
  953. temp5S REG_v(v13),
  954. temp6S REG_v(v14),
  955. temp7S REG_v(v15);
  956. register const vector unsigned char vzero REG_v(v31)=
  957. (const vector unsigned char)vec_splat_u8(0);
  958. {
  959. register const vector signed short vprod1 REG_v(v16)=
  960. (const vector signed short){ 1,-1, 1,-1, 1,-1, 1,-1 };
  961. register const vector signed short vprod2 REG_v(v17)=
  962. (const vector signed short){ 1, 1,-1,-1, 1, 1,-1,-1 };
  963. register const vector signed short vprod3 REG_v(v18)=
  964. (const vector signed short){ 1, 1, 1, 1,-1,-1,-1,-1 };
  965. register const vector unsigned char perm1 REG_v(v19)=
  966. (const vector unsigned char)
  967. {0x02, 0x03, 0x00, 0x01, 0x06, 0x07, 0x04, 0x05,
  968. 0x0A, 0x0B, 0x08, 0x09, 0x0E, 0x0F, 0x0C, 0x0D};
  969. register const vector unsigned char perm2 REG_v(v20)=
  970. (const vector unsigned char)
  971. {0x04, 0x05, 0x06, 0x07, 0x00, 0x01, 0x02, 0x03,
  972. 0x0C, 0x0D, 0x0E, 0x0F, 0x08, 0x09, 0x0A, 0x0B};
  973. register const vector unsigned char perm3 REG_v(v21)=
  974. (const vector unsigned char)
  975. {0x08, 0x09, 0x0A, 0x0B, 0x0C, 0x0D, 0x0E, 0x0F,
  976. 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07};
  977. #define ONEITERBUTTERFLY(i, res1, res2) \
  978. { \
  979. register vector unsigned char src1 REG_v(v22), \
  980. src2 REG_v(v23), \
  981. dst1 REG_v(v24), \
  982. dst2 REG_v(v25), \
  983. srcO REG_v(v22), \
  984. dstO REG_v(v23); \
  985. \
  986. register vector signed short srcV REG_v(v24), \
  987. dstV REG_v(v25), \
  988. srcW REG_v(v26), \
  989. dstW REG_v(v27), \
  990. but0 REG_v(v28), \
  991. but0S REG_v(v29), \
  992. op1 REG_v(v30), \
  993. but1 REG_v(v22), \
  994. op1S REG_v(v23), \
  995. but1S REG_v(v24), \
  996. op2 REG_v(v25), \
  997. but2 REG_v(v26), \
  998. op2S REG_v(v27), \
  999. but2S REG_v(v28), \
  1000. op3 REG_v(v29), \
  1001. op3S REG_v(v30); \
  1002. \
  1003. src1 = vec_ld(stride * i, src); \
  1004. src2 = vec_ld((stride * i) + 16, src); \
  1005. srcO = vec_perm(src1, src2, vec_lvsl(stride * i, src)); \
  1006. dst1 = vec_ld(stride * i, dst); \
  1007. dst2 = vec_ld((stride * i) + 16, dst); \
  1008. dstO = vec_perm(dst1, dst2, vec_lvsl(stride * i, dst)); \
  1009. /* promote the unsigned chars to signed shorts */ \
  1010. srcV = (vector signed short)vec_mergeh((vector signed char)vzero, \
  1011. (vector signed char)srcO); \
  1012. dstV = (vector signed short)vec_mergeh((vector signed char)vzero, \
  1013. (vector signed char)dstO); \
  1014. srcW = (vector signed short)vec_mergel((vector signed char)vzero, \
  1015. (vector signed char)srcO); \
  1016. dstW = (vector signed short)vec_mergel((vector signed char)vzero, \
  1017. (vector signed char)dstO); \
  1018. /* subtractions inside the first butterfly */ \
  1019. but0 = vec_sub(srcV, dstV); \
  1020. but0S = vec_sub(srcW, dstW); \
  1021. op1 = vec_perm(but0, but0, perm1); \
  1022. but1 = vec_mladd(but0, vprod1, op1); \
  1023. op1S = vec_perm(but0S, but0S, perm1); \
  1024. but1S = vec_mladd(but0S, vprod1, op1S); \
  1025. op2 = vec_perm(but1, but1, perm2); \
  1026. but2 = vec_mladd(but1, vprod2, op2); \
  1027. op2S = vec_perm(but1S, but1S, perm2); \
  1028. but2S = vec_mladd(but1S, vprod2, op2S); \
  1029. op3 = vec_perm(but2, but2, perm3); \
  1030. res1 = vec_mladd(but2, vprod3, op3); \
  1031. op3S = vec_perm(but2S, but2S, perm3); \
  1032. res2 = vec_mladd(but2S, vprod3, op3S); \
  1033. }
  1034. ONEITERBUTTERFLY(0, temp0, temp0S);
  1035. ONEITERBUTTERFLY(1, temp1, temp1S);
  1036. ONEITERBUTTERFLY(2, temp2, temp2S);
  1037. ONEITERBUTTERFLY(3, temp3, temp3S);
  1038. ONEITERBUTTERFLY(4, temp4, temp4S);
  1039. ONEITERBUTTERFLY(5, temp5, temp5S);
  1040. ONEITERBUTTERFLY(6, temp6, temp6S);
  1041. ONEITERBUTTERFLY(7, temp7, temp7S);
  1042. }
  1043. #undef ONEITERBUTTERFLY
  1044. {
  1045. register vector signed int vsum;
  1046. register vector signed short line0S, line1S, line2S, line3S, line4S,
  1047. line5S, line6S, line7S, line0BS,line2BS,
  1048. line1BS,line3BS,line4BS,line6BS,line5BS,
  1049. line7BS,line0CS,line4CS,line1CS,line5CS,
  1050. line2CS,line6CS,line3CS,line7CS;
  1051. register vector signed short line0 = vec_add(temp0, temp1);
  1052. register vector signed short line1 = vec_sub(temp0, temp1);
  1053. register vector signed short line2 = vec_add(temp2, temp3);
  1054. register vector signed short line3 = vec_sub(temp2, temp3);
  1055. register vector signed short line4 = vec_add(temp4, temp5);
  1056. register vector signed short line5 = vec_sub(temp4, temp5);
  1057. register vector signed short line6 = vec_add(temp6, temp7);
  1058. register vector signed short line7 = vec_sub(temp6, temp7);
  1059. register vector signed short line0B = vec_add(line0, line2);
  1060. register vector signed short line2B = vec_sub(line0, line2);
  1061. register vector signed short line1B = vec_add(line1, line3);
  1062. register vector signed short line3B = vec_sub(line1, line3);
  1063. register vector signed short line4B = vec_add(line4, line6);
  1064. register vector signed short line6B = vec_sub(line4, line6);
  1065. register vector signed short line5B = vec_add(line5, line7);
  1066. register vector signed short line7B = vec_sub(line5, line7);
  1067. register vector signed short line0C = vec_add(line0B, line4B);
  1068. register vector signed short line4C = vec_sub(line0B, line4B);
  1069. register vector signed short line1C = vec_add(line1B, line5B);
  1070. register vector signed short line5C = vec_sub(line1B, line5B);
  1071. register vector signed short line2C = vec_add(line2B, line6B);
  1072. register vector signed short line6C = vec_sub(line2B, line6B);
  1073. register vector signed short line3C = vec_add(line3B, line7B);
  1074. register vector signed short line7C = vec_sub(line3B, line7B);
  1075. vsum = vec_sum4s(vec_abs(line0C), vec_splat_s32(0));
  1076. vsum = vec_sum4s(vec_abs(line1C), vsum);
  1077. vsum = vec_sum4s(vec_abs(line2C), vsum);
  1078. vsum = vec_sum4s(vec_abs(line3C), vsum);
  1079. vsum = vec_sum4s(vec_abs(line4C), vsum);
  1080. vsum = vec_sum4s(vec_abs(line5C), vsum);
  1081. vsum = vec_sum4s(vec_abs(line6C), vsum);
  1082. vsum = vec_sum4s(vec_abs(line7C), vsum);
  1083. line0S = vec_add(temp0S, temp1S);
  1084. line1S = vec_sub(temp0S, temp1S);
  1085. line2S = vec_add(temp2S, temp3S);
  1086. line3S = vec_sub(temp2S, temp3S);
  1087. line4S = vec_add(temp4S, temp5S);
  1088. line5S = vec_sub(temp4S, temp5S);
  1089. line6S = vec_add(temp6S, temp7S);
  1090. line7S = vec_sub(temp6S, temp7S);
  1091. line0BS = vec_add(line0S, line2S);
  1092. line2BS = vec_sub(line0S, line2S);
  1093. line1BS = vec_add(line1S, line3S);
  1094. line3BS = vec_sub(line1S, line3S);
  1095. line4BS = vec_add(line4S, line6S);
  1096. line6BS = vec_sub(line4S, line6S);
  1097. line5BS = vec_add(line5S, line7S);
  1098. line7BS = vec_sub(line5S, line7S);
  1099. line0CS = vec_add(line0BS, line4BS);
  1100. line4CS = vec_sub(line0BS, line4BS);
  1101. line1CS = vec_add(line1BS, line5BS);
  1102. line5CS = vec_sub(line1BS, line5BS);
  1103. line2CS = vec_add(line2BS, line6BS);
  1104. line6CS = vec_sub(line2BS, line6BS);
  1105. line3CS = vec_add(line3BS, line7BS);
  1106. line7CS = vec_sub(line3BS, line7BS);
  1107. vsum = vec_sum4s(vec_abs(line0CS), vsum);
  1108. vsum = vec_sum4s(vec_abs(line1CS), vsum);
  1109. vsum = vec_sum4s(vec_abs(line2CS), vsum);
  1110. vsum = vec_sum4s(vec_abs(line3CS), vsum);
  1111. vsum = vec_sum4s(vec_abs(line4CS), vsum);
  1112. vsum = vec_sum4s(vec_abs(line5CS), vsum);
  1113. vsum = vec_sum4s(vec_abs(line6CS), vsum);
  1114. vsum = vec_sum4s(vec_abs(line7CS), vsum);
  1115. vsum = vec_sums(vsum, (vector signed int)vzero);
  1116. vsum = vec_splat(vsum, 3);
  1117. vec_ste(vsum, 0, &sum);
  1118. }
  1119. return sum;
  1120. }
  1121. int hadamard8_diff16_altivec(/*MpegEncContext*/ void *s, uint8_t *dst, uint8_t *src, int stride, int h){
  1122. POWERPC_PERF_DECLARE(altivec_hadamard8_diff16_num, 1);
  1123. int score;
  1124. POWERPC_PERF_START_COUNT(altivec_hadamard8_diff16_num, 1);
  1125. score = hadamard8_diff16x8_altivec(s, dst, src, stride, 8);
  1126. if (h==16) {
  1127. dst += 8*stride;
  1128. src += 8*stride;
  1129. score += hadamard8_diff16x8_altivec(s, dst, src, stride, 8);
  1130. }
  1131. POWERPC_PERF_STOP_COUNT(altivec_hadamard8_diff16_num, 1);
  1132. return score;
  1133. }
  1134. static void vorbis_inverse_coupling_altivec(float *mag, float *ang,
  1135. int blocksize)
  1136. {
  1137. int i;
  1138. vector float m, a;
  1139. vector bool int t0, t1;
  1140. const vector unsigned int v_31 = //XXX
  1141. vec_add(vec_add(vec_splat_u32(15),vec_splat_u32(15)),vec_splat_u32(1));
  1142. for (i = 0; i < blocksize; i += 4) {
  1143. m = vec_ld(0, mag+i);
  1144. a = vec_ld(0, ang+i);
  1145. t0 = vec_cmple(m, (vector float)vec_splat_u32(0));
  1146. t1 = vec_cmple(a, (vector float)vec_splat_u32(0));
  1147. a = vec_xor(a, (vector float) vec_sl((vector unsigned int)t0, v_31));
  1148. t0 = (vector bool int)vec_and(a, t1);
  1149. t1 = (vector bool int)vec_andc(a, t1);
  1150. a = vec_sub(m, (vector float)t1);
  1151. m = vec_add(m, (vector float)t0);
  1152. vec_stl(a, 0, ang+i);
  1153. vec_stl(m, 0, mag+i);
  1154. }
  1155. }
  1156. /* next one assumes that ((line_size % 8) == 0) */
  1157. void avg_pixels8_xy2_altivec(uint8_t *block, const uint8_t *pixels, int line_size, int h)
  1158. {
  1159. POWERPC_PERF_DECLARE(altivec_avg_pixels8_xy2_num, 1);
  1160. register int i;
  1161. register vector unsigned char pixelsv1, pixelsv2, pixelsavg;
  1162. register vector unsigned char blockv, temp1, temp2, blocktemp;
  1163. register vector unsigned short pixelssum1, pixelssum2, temp3;
  1164. register const vector unsigned char vczero = (const vector unsigned char)
  1165. vec_splat_u8(0);
  1166. register const vector unsigned short vctwo = (const vector unsigned short)
  1167. vec_splat_u16(2);
  1168. temp1 = vec_ld(0, pixels);
  1169. temp2 = vec_ld(16, pixels);
  1170. pixelsv1 = vec_perm(temp1, temp2, vec_lvsl(0, pixels));
  1171. if ((((unsigned long)pixels) & 0x0000000F) == 0x0000000F) {
  1172. pixelsv2 = temp2;
  1173. } else {
  1174. pixelsv2 = vec_perm(temp1, temp2, vec_lvsl(1, pixels));
  1175. }
  1176. pixelsv1 = vec_mergeh(vczero, pixelsv1);
  1177. pixelsv2 = vec_mergeh(vczero, pixelsv2);
  1178. pixelssum1 = vec_add((vector unsigned short)pixelsv1,
  1179. (vector unsigned short)pixelsv2);
  1180. pixelssum1 = vec_add(pixelssum1, vctwo);
  1181. POWERPC_PERF_START_COUNT(altivec_avg_pixels8_xy2_num, 1);
  1182. for (i = 0; i < h ; i++) {
  1183. int rightside = ((unsigned long)block & 0x0000000F);
  1184. blockv = vec_ld(0, block);
  1185. temp1 = vec_ld(line_size, pixels);
  1186. temp2 = vec_ld(line_size + 16, pixels);
  1187. pixelsv1 = vec_perm(temp1, temp2, vec_lvsl(line_size, pixels));
  1188. if (((((unsigned long)pixels) + line_size) & 0x0000000F) == 0x0000000F) {
  1189. pixelsv2 = temp2;
  1190. } else {
  1191. pixelsv2 = vec_perm(temp1, temp2, vec_lvsl(line_size + 1, pixels));
  1192. }
  1193. pixelsv1 = vec_mergeh(vczero, pixelsv1);
  1194. pixelsv2 = vec_mergeh(vczero, pixelsv2);
  1195. pixelssum2 = vec_add((vector unsigned short)pixelsv1,
  1196. (vector unsigned short)pixelsv2);
  1197. temp3 = vec_add(pixelssum1, pixelssum2);
  1198. temp3 = vec_sra(temp3, vctwo);
  1199. pixelssum1 = vec_add(pixelssum2, vctwo);
  1200. pixelsavg = vec_packsu(temp3, (vector unsigned short) vczero);
  1201. if (rightside) {
  1202. blocktemp = vec_perm(blockv, pixelsavg, vcprm(0, 1, s0, s1));
  1203. } else {
  1204. blocktemp = vec_perm(blockv, pixelsavg, vcprm(s0, s1, 2, 3));
  1205. }
  1206. blockv = vec_avg(blocktemp, blockv);
  1207. vec_st(blockv, 0, block);
  1208. block += line_size;
  1209. pixels += line_size;
  1210. }
  1211. POWERPC_PERF_STOP_COUNT(altivec_avg_pixels8_xy2_num, 1);
  1212. }
  1213. void dsputil_init_altivec(DSPContext* c, AVCodecContext *avctx)
  1214. {
  1215. c->pix_abs[0][1] = sad16_x2_altivec;
  1216. c->pix_abs[0][2] = sad16_y2_altivec;
  1217. c->pix_abs[0][3] = sad16_xy2_altivec;
  1218. c->pix_abs[0][0] = sad16_altivec;
  1219. c->pix_abs[1][0] = sad8_altivec;
  1220. c->sad[0]= sad16_altivec;
  1221. c->sad[1]= sad8_altivec;
  1222. c->pix_norm1 = pix_norm1_altivec;
  1223. c->sse[1]= sse8_altivec;
  1224. c->sse[0]= sse16_altivec;
  1225. c->pix_sum = pix_sum_altivec;
  1226. c->diff_pixels = diff_pixels_altivec;
  1227. c->get_pixels = get_pixels_altivec;
  1228. c->clear_block = clear_block_altivec;
  1229. c->add_bytes= add_bytes_altivec;
  1230. c->put_pixels_tab[0][0] = put_pixels16_altivec;
  1231. /* the two functions do the same thing, so use the same code */
  1232. c->put_no_rnd_pixels_tab[0][0] = put_pixels16_altivec;
  1233. c->avg_pixels_tab[0][0] = avg_pixels16_altivec;
  1234. c->avg_pixels_tab[1][0] = avg_pixels8_altivec;
  1235. c->avg_pixels_tab[1][3] = avg_pixels8_xy2_altivec;
  1236. c->put_pixels_tab[1][3] = put_pixels8_xy2_altivec;
  1237. c->put_no_rnd_pixels_tab[1][3] = put_no_rnd_pixels8_xy2_altivec;
  1238. c->put_pixels_tab[0][3] = put_pixels16_xy2_altivec;
  1239. c->put_no_rnd_pixels_tab[0][3] = put_no_rnd_pixels16_xy2_altivec;
  1240. c->hadamard8_diff[0] = hadamard8_diff16_altivec;
  1241. c->hadamard8_diff[1] = hadamard8_diff8x8_altivec;
  1242. if (CONFIG_VORBIS_DECODER)
  1243. c->vorbis_inverse_coupling = vorbis_inverse_coupling_altivec;
  1244. }