You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

383 lines
12KB

  1. /*
  2. * Blackfin Pixel Operations
  3. * Copyright (C) 2007 Marc Hoffman <marc.hoffman@analog.com>
  4. *
  5. * This file is part of Libav.
  6. *
  7. * Libav 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. * Libav 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 Libav; if not, write to the Free Software
  19. * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
  20. */
  21. #include "libavutil/bfin/asm.h"
  22. DEFUN(put_pixels_clamped,mL1,
  23. (int16_t *block, uint8_t *dest, int line_size)):
  24. [--SP] = (R7:4);
  25. R4 = 0;
  26. R5.l = 0x00ff;
  27. R5.h = 0x00ff;
  28. I0 = R0; // block
  29. I1 = R1; // dest
  30. R2 += -4; // line_size
  31. M1 = R2;
  32. P0 = 8;
  33. R0 = [I0++];
  34. R1 = [I0++];
  35. R2 = MAX(R0, R4) (V);
  36. LSETUP (ppc$0,ppc$1) LC0=P0;
  37. ppc$0: R2 = MIN(R2, R5) (V);
  38. R3 = MAX(R1, R4) (V);
  39. R3 = MIN(R3, R5) (V) || R0 = [I0++];
  40. R6 = BYTEPACK (R2,R3) || R1 = [I0++];
  41. R2 = MAX(R0, R4) (V) || [I1++] = R6;
  42. R2 = MIN(R2, R5) (V);
  43. R3 = MAX(R1, R4) (V);
  44. R3 = MIN(R3, R5) (V) || R0 = [I0++];
  45. R6 = BYTEPACK (R2,R3) || R1 = [I0++];
  46. ppc$1: R2 = Max(R0, R4) (V) || [I1++M1] = R6;
  47. (R7:4) = [SP++];
  48. RTS;
  49. DEFUN_END(put_pixels_clamped)
  50. DEFUN(add_pixels_clamped,mL1,
  51. (int16_t *block, uint8_t *dest, int line_size)):
  52. [-- SP] = (R7:4);
  53. R4 = 0;
  54. I0 = 0;
  55. R2 += -4; // line_size
  56. M0 = R2;
  57. I1 = R1; // dest
  58. I3 = R0; // block
  59. I2 = R1; // dest
  60. P0 = 8;
  61. M3 = 2;
  62. R0 = [I3++] || R2 = [I1];
  63. R2 = R2 << 8 || R0.H = W[I3--] || R3 = [I1++];
  64. R3 = R3 >> 8 || R1.L = W[I3] || I3 += 4;
  65. R6 = BYTEOP3P(R1:0, R3:2) (LO) || R1.H = W[I3++] || R2 = [I1];
  66. LSETUP(apc$2,apc$3) LC1 = P0;
  67. apc$2: R7 = BYTEOP3P(R1:0, R3:2) (HI, R) || R0 = [I3++] || R3 = [I1++M0];
  68. R2 = R2 << 8 || R0.H = W[I3--];
  69. R3 = R3 >> 8 || R1.L = W[I3] || I3 += 4;
  70. R6 = R6 + R7 (S) || R1.H = W[I3];
  71. R6 = BYTEOP3P(R1:0, R3:2) (LO) || I3+=M3 || [I2++]=R6;
  72. R7 = BYTEOP3P(R1:0, R3:2) (HI, R) || R0 = [I3++] || R2 = [I1];
  73. R2 = R2 << 8 || R0.H = W[I3--] || R3 = [I1++];
  74. R3 = R3 >> 8 || R1.L = W[I3] || I3 += 4;
  75. R6 = R6 + R7 (S) || R1.H = W[I3++];
  76. apc$3: R6 = BYTEOP3P(R1:0, R3:2) (LO) || [I2++M0] = R6 || R2 = [I1];
  77. (R7:4) = [SP++];
  78. RTS;
  79. DEFUN_END(add_pixels_clamped)
  80. DEFUN(diff_pixels,mL1,
  81. (int16_t *block, uint8_t *s1, uint8_t *s2, int stride)):
  82. link 0;
  83. [--sp] = (r7:4);
  84. p0=8;
  85. i3=r0; // block
  86. i0=r1; // s1
  87. i1=r2; // s2
  88. r2=[fp+20]; // stride
  89. r2+=-8;
  90. m0=r2;
  91. LSETUP(.LS0,.LE0) LC0=P0;
  92. DISALGNEXCPT || R0 = [I0++] || R2 =[I1++];
  93. .LS0: DISALGNEXCPT || R1 = [I0++] || R3 = [I1++];
  94. (R5,R4) = BYTEOP16M (R1:0,R3:2) || R0 = [I0++M0] || R2 = [I1++M0];
  95. (R7,R6) = BYTEOP16M (R1:0,R3:2) (R)|| R0 = [I0++] || [I3++] = R4;
  96. DISALGNEXCPT || R2 = [I1++] || [I3++] = R5;
  97. [i3++]=r6;
  98. .LE0: [i3++]=r7;
  99. (r7:4) = [sp++];
  100. unlink;
  101. rts;
  102. DEFUN_END(diff_pixels)
  103. /*
  104. for (i = 0; i < 16; i++) {
  105. for (j = 0; j < 16; j++) {
  106. sum += pix[j];
  107. }
  108. pix += line_size;
  109. }
  110. */
  111. DEFUN(pix_sum,mL1,
  112. (uint8_t *p, int stride)):
  113. link 0;
  114. [--sp] = (r7:4);
  115. p0=8;
  116. i0=r0; // s1
  117. i1=r0;
  118. m1=r1;
  119. r1=r1+r1;
  120. r1+=-16; // stride
  121. m0=r1;
  122. i1+=m1;
  123. r6=0;
  124. LSETUP(LS$PS,LE$PS) LC0=P0;
  125. DISALGNEXCPT || R0 = [I0++] || R2 =[I1++];
  126. LS$PS: DISALGNEXCPT || R1 = [I0++] || R3 = [I1++];
  127. (R5,R4) = BYTEOP16P (R3:2,R1:0) || R0 = [I0++] || R2 = [I1++];
  128. r6=r6+|+r5;
  129. r6=r6+|+r4;
  130. (R5,R4) = BYTEOP16P (R3:2,R1:0) (R)|| R1 = [I0++] || R3 = [I1++];
  131. r6=r6+|+r5;
  132. r6=r6+|+r4;
  133. (R5,R4) = BYTEOP16P (R3:2,R1:0) || R0 = [I0++m0] || R2 = [I1++m0];
  134. r6=r6+|+r5;
  135. r6=r6+|+r4;
  136. (R5,R4) = BYTEOP16P (R3:2,R1:0) (R)|| R0 = [I0++] || R2 = [I1++];
  137. r6=r6+|+r5;
  138. LE$PS: r6=r6+|+r4;
  139. r0.l=r6.l+r6.h;
  140. r0.h=0;
  141. (r7:4) = [sp++];
  142. unlink;
  143. rts;
  144. DEFUN_END(pix_sum)
  145. DEFUN(get_pixels,mL1,
  146. (int16_t *restrict block, const uint8_t *pixels, int line_size)):
  147. [--sp] = (r7:4);
  148. i3=r0; // dest
  149. i0=r1; // src0
  150. p0=8;
  151. r2+=-8;
  152. m0=r2;
  153. LSETUP(gp8$0,gp8$1) LC0=P0;
  154. DISALGNEXCPT || R0 = [I0++];
  155. DISALGNEXCPT || R1 = [I0++];
  156. gp8$0: (R7,R6) = byteunpack R1:0 || R0 = [I0++M0];
  157. (R5,R4) = byteunpack R1:0 (R) || R0 = [I0++] || [I3++]=R6;
  158. DISALGNEXCPT || R1 = [I0++] || [I3++]=R7;
  159. [I3++]=R4;
  160. gp8$1: [I3++]=R5
  161. (r7:4) = [sp++];
  162. RTS;
  163. DEFUN_END(get_pixels)
  164. /* sad = sad16x16 (ubyte *mb, ubyte *refwin, srcwidth, refwinwidth, h) */
  165. /* 91 cycles */
  166. DEFUN(z_sad16x16,mL1,
  167. (uint8_t *blk1, uint8_t *blk2, int dsz, int line_size, int h)):
  168. link 0;
  169. I0 = R0;
  170. I1 = R1;
  171. A1 = A0 = 0;
  172. R0 = [sp+20]; // rwidth
  173. P2 = [sp+24]; // height
  174. R3 = 16;
  175. R0 = R0 - R3;
  176. R3 = R2 - R3;
  177. M1 = R0;
  178. M0 = R3;
  179. DISALGNEXCPT || R0 = [I0++] || R2 = [I1++];
  180. LSETUP (s$16, e$16) LC0=P2;
  181. s$16: DISALGNEXCPT || R1 = [I0++] || R3 = [I1++];
  182. SAA (R1:0,R3:2) || R0 = [I0++] || R2 = [I1++];
  183. SAA (R1:0,R3:2) (R) || R1 = [I0++] || R3 = [I1++];
  184. SAA (R1:0,R3:2) || R0 = [I0++M0] || R2 = [I1++M1];
  185. e$16: SAA (R1:0,R3:2) (R) || R0 = [I0++] || R2 = [I1++];
  186. R3=A1.L+A1.H, R2=A0.L+A0.H ;
  187. R0 = R2 + R3 ;
  188. unlink;
  189. RTS;
  190. DEFUN_END(z_sad16x16)
  191. /* sad = sad8x8 (ubyte *mb, ubyte *refwin, int srcwidth, int refwinwidth, int h) */
  192. /* 36 cycles */
  193. DEFUN(z_sad8x8,mL1,
  194. (uint8_t *blk1, uint8_t *blk2, int dsz, int line_size, int h)):
  195. I0 = R0;
  196. I1 = R1;
  197. A1 = A0 = 0;
  198. r0 = [sp+12]; // rwidth
  199. P2 = [sp+16]; //height
  200. R3 = 8;
  201. R0 = R0 - R3;
  202. R3 = R2 - R3;
  203. M0 = R3;
  204. M1 = R0;
  205. LSETUP (s$8, e$8) LC0=P2;
  206. DISALGNEXCPT || R0 = [I0++] || R2 = [I1++];
  207. DISALGNEXCPT || R1 = [I0++] || R3 = [I1++];
  208. s$8: SAA (R1:0,R3:2) || R0 = [I0++M0] || R2 = [I1++M1];
  209. SAA (R1:0,R3:2) (R) || R0 = [I0++] || R2 = [I1++];
  210. e$8: DISALGNEXCPT || R1 = [I0++] || R3 = [I1++];
  211. R3=A1.L+A1.H, R2=A0.L+A0.H ;
  212. R0 = R2 + R3 ;
  213. RTS;
  214. DEFUN_END(z_sad8x8)
  215. DEFUN(pix_norm1,mL1,
  216. (uint8_t * pix, int line_size)):
  217. [--SP]=(R7:4,P5:3);
  218. // Fetch the input arguments.
  219. P1 = R0; // pix
  220. P0 = R1; // line_size
  221. P5 = 16; // loop ctr.
  222. P0 -= P5;
  223. M0 = P0; // M0 = line_size-16;
  224. // Now for the real work.
  225. A1 = A0 = 0;
  226. lsetup(_pix_norm1_blkfn_loopStart, _pix_norm1_blkfn_loopEnd) LC1 = P5;
  227. I0 = P1;
  228. DISALGNEXCPT || r0 = [i0++];
  229. _pix_norm1_blkfn_loopStart:
  230. // following unpacks pix1[0..15] pix1+line_size[0..15]
  231. DISALGNEXCPT || r1 = [i0++];
  232. (r5, r4) = byteunpack r1:0 || r0 = [i0++];
  233. a1 += r5.h * r5.h, a0 += r5.l * r5.l (is);
  234. a1 += r4.h * r4.h, a0 += r4.l * r4.l (is);
  235. (r5, r4) = byteunpack r1:0(r) || r1 = [i0++];
  236. a1 += r5.h * r5.h, a0 += r5.l * r5.l (is);
  237. a1 += r4.h * r4.h, a0 += r4.l * r4.l (is);
  238. (r5, r4) = byteunpack r1:0 || r0 = [i0++M0];
  239. a1 += r5.h * r5.h, a0 += r5.l * r5.l (is);
  240. a1 += r4.h * r4.h, a0 += r4.l * r4.l (is);
  241. (r5, r4) = byteunpack r1:0(r) || r0 = [i0++];
  242. a1 += r5.h * r5.h, a0 += r5.l * r5.l (is);
  243. _pix_norm1_blkfn_loopEnd:
  244. a1 += r4.h * r4.h, a0 += r4.l * r4.l (is);
  245. // Clean up at the end:
  246. R2 = A0, R3 = A1;
  247. R0 = R2 + R3 (S);
  248. (R7:4,P5:3)=[SP++];
  249. RTS;
  250. DEFUN_END(pix_norm1)
  251. DEFUN(sse4,mL1,
  252. (void *v, uint8_t *pix1, uint8_t *pix2, int line_size, int h)):
  253. link 0;
  254. [--sp] = (r7:6);
  255. p0=[fp+24]; // h
  256. i0=r1; // pix1
  257. i1=r2; // pix2
  258. r2=[fp+20]; // line_size
  259. r2+=-4;
  260. m0=r2;
  261. a0=a1=0;
  262. LSETUP(.S40,.E40) LC0=P0;
  263. DISALGNEXCPT || R0 = [I0++] || R2 =[I1++];
  264. .S40: DISALGNEXCPT || R1 = [I0++M0] || R3 = [I1++M0];
  265. (R7,R6) = BYTEOP16M (R1:0,R3:2);
  266. a0 += r7.l * r7.l, a1 += r7.h * r7.h (is);
  267. .E40: a0 += r6.l * r6.l, a1 += r6.h * r6.h (is);
  268. a0 += a1;
  269. r0 = a0;
  270. (r7:6) = [sp++];
  271. unlink;
  272. rts;
  273. DEFUN_END(sse4)
  274. DEFUN(sse8,mL1,
  275. (void *v, uint8_t *pix1, uint8_t *pix2, int line_size, int h)):
  276. link 0;
  277. [--sp] = (r7:6);
  278. p0=[fp+24]; // h
  279. i0=r1; // pix1
  280. i1=r2; // pix2
  281. r2=[fp+20]; // line_size
  282. r2+=-8;
  283. m0=r2;
  284. a0=a1=0;
  285. LSETUP(.S80,.E80) LC0=P0;
  286. DISALGNEXCPT || R0 = [I0++] || R2 =[I1++];
  287. .S80: DISALGNEXCPT || R1 = [I0++] || R3 = [I1++];
  288. (R7,R6) = BYTEOP16M (R1:0,R3:2) || R0 = [I0++M0] || R2 = [I1++M0];
  289. a0 += r7.l * r7.l, a1 += r7.h * r7.h (is);
  290. a0 += r6.l * r6.l, a1 += r6.h * r6.h (is);
  291. (R7,R6) = BYTEOP16M (R1:0,R3:2) (R)|| R0 = [I0++] || R2 = [I1++];
  292. a0 += r7.l * r7.l, a1 += r7.h * r7.h (is);
  293. .E80: a0 += r6.l * r6.l, a1 += r6.h * r6.h (is);
  294. a0 += a1;
  295. r0 = a0;
  296. (r7:6) = [sp++];
  297. unlink;
  298. rts;
  299. DEFUN_END(sse8)
  300. DEFUN(sse16,mL1,
  301. (void *v, uint8_t *pix1, uint8_t *pix2, int line_size, int h)):
  302. link 0;
  303. [--sp] = (r7:6);
  304. p0=[fp+24]; // h
  305. i0=r1; // pix1
  306. i1=r2; // pix2
  307. r2=[fp+20]; // line_size
  308. r2+=-16;
  309. m0=r2;
  310. a0=a1=0;
  311. DISALGNEXCPT || R0 = [I0++] || R2 =[I1++];
  312. LSETUP(.S160,.E160) LC0=P0;
  313. .S160: DISALGNEXCPT || R1 = [I0++] || R3 = [I1++];
  314. (R7,R6) = BYTEOP16M (R1:0,R3:2) || R0 = [I0++] || R2 = [I1++];
  315. a0 += r7.l * r7.l, a1 += r7.h * r7.h (is);
  316. a0 += r6.l * r6.l, a1 += r6.h * r6.h (is);
  317. (R7,R6) = BYTEOP16M (R1:0,R3:2) (R)|| R1 = [I0++] || R3 = [I1++];
  318. a0 += r7.l * r7.l, a1 += r7.h * r7.h (is);
  319. a0 += r6.l * r6.l, a1 += r6.h * r6.h (is);
  320. (R7,R6) = BYTEOP16M (R1:0,R3:2) || R0 = [I0++M0] || R2 = [I1++M0];
  321. a0 += r7.l * r7.l, a1 += r7.h * r7.h (is);
  322. a0 += r6.l * r6.l, a1 += r6.h * r6.h (is);
  323. (R7,R6) = BYTEOP16M (R1:0,R3:2) (R)|| R0 = [I0++] || R2 = [I1++];
  324. a0 += r7.l * r7.l, a1 += r7.h * r7.h (is);
  325. .E160: a0 += r6.l * r6.l, a1 += r6.h * r6.h (is);
  326. a0 += a1;
  327. r0 = a0;
  328. (r7:6) = [sp++];
  329. unlink;
  330. rts;
  331. DEFUN_END(sse16)