Mercurial > libavcodec.hg
annotate ppc/float_altivec.c @ 3654:565d9ddd8eb3 libavcodec
Motion compensation for luma always use halfpel precision.
author | kostya |
---|---|
date | Thu, 31 Aug 2006 04:39:27 +0000 |
parents | 562758eaf7bf |
children | ff6720290478 |
rev | line source |
---|---|
3581 | 1 /* |
2 * Copyright (c) 2006 Luca Barbato <lu_zero@gentoo.org> | |
3 * | |
4 * This library is free software; you can redistribute it and/or | |
5 * modify it under the terms of the GNU Lesser General Public | |
6 * License as published by the Free Software Foundation; either | |
7 * version 2 of the License, or (at your option) any later version. | |
8 * | |
9 * This library is distributed in the hope that it will be useful, | |
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of | |
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | |
12 * Lesser General Public License for more details. | |
13 * | |
14 * You should have received a copy of the GNU Lesser General Public | |
15 * License along with this library; if not, write to the Free Software | |
16 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA | |
17 */ | |
18 | |
19 #include "../dsputil.h" | |
20 | |
21 #include "gcc_fixes.h" | |
22 | |
23 #include "dsputil_altivec.h" | |
24 | |
25 static void vector_fmul_altivec(float *dst, const float *src, int len) | |
26 { | |
27 int i; | |
28 vector float d0, d1, s, zero = (vector float)vec_splat_u32(0); | |
29 for(i=0; i<len-7; i+=8) { | |
30 d0 = vec_ld(0, dst+i); | |
31 s = vec_ld(0, src+i); | |
32 d1 = vec_ld(16, dst+i); | |
33 d0 = vec_madd(d0, s, zero); | |
34 d1 = vec_madd(d1, vec_ld(16,src+i), zero); | |
35 vec_st(d0, 0, dst+i); | |
36 vec_st(d1, 16, dst+i); | |
37 } | |
38 } | |
39 | |
40 static void vector_fmul_reverse_altivec(float *dst, const float *src0, | |
41 const float *src1, int len) | |
42 { | |
43 int i; | |
44 vector float d, s0, s1, h0, l0, | |
45 s2, s3, zero = (vector float)vec_splat_u32(0); | |
46 src1 += len-4; | |
47 for(i=0; i<len-7; i+=8) { | |
48 s1 = vec_ld(0, src1-i); // [a,b,c,d] | |
49 s0 = vec_ld(0, src0+i); | |
50 l0 = vec_mergel(s1, s1); // [c,c,d,d] | |
51 s3 = vec_ld(-16, src1-i); | |
52 h0 = vec_mergeh(s1, s1); // [a,a,b,b] | |
53 s2 = vec_ld(16, src0+i); | |
54 s1 = vec_mergeh(vec_mergel(l0,h0), // [d,b,d,b] | |
55 vec_mergeh(l0,h0)); // [c,a,c,a] | |
56 // [d,c,b,a] | |
57 l0 = vec_mergel(s3, s3); | |
58 d = vec_madd(s0, s1, zero); | |
59 h0 = vec_mergeh(s3, s3); | |
60 vec_st(d, 0, dst+i); | |
61 s3 = vec_mergeh(vec_mergel(l0,h0), | |
62 vec_mergeh(l0,h0)); | |
63 d = vec_madd(s2, s3, zero); | |
64 vec_st(d, 16, dst+i); | |
65 } | |
66 } | |
67 | |
68 static void vector_fmul_add_add_altivec(float *dst, const float *src0, | |
69 const float *src1, const float *src2, | |
70 int src3, int len, int step) | |
71 { | |
72 int i; | |
73 vector float d, s0, s1, s2, t0, t1, edges; | |
74 vector unsigned char align = vec_lvsr(0,dst), | |
75 mask = vec_lvsl(0, dst); | |
76 | |
77 t0 = vec_ld(0, dst); | |
78 #if 0 //FIXME: there is still something wrong | |
79 if (step == 2) { | |
80 int y; | |
81 vector float d0, d1, s3, t2; | |
82 vector unsigned int sel = | |
83 vec_mergeh(vec_splat_u32(-1), vec_splat_u32(0)); | |
84 t1 = vec_ld(16, dst); | |
85 for (i=0,y=0; i<len-3; i+=4,y+=8) { | |
86 | |
87 s0 = vec_ld(0,src0+i); | |
88 s1 = vec_ld(0,src1+i); | |
89 s2 = vec_ld(0,src2+i); | |
90 | |
91 // t0 = vec_ld(0, dst+y); //[x x x|a] | |
92 // t1 = vec_ld(16, dst+y); //[b c d|e] | |
93 t2 = vec_ld(31, dst+y); //[f g h|x] | |
94 | |
95 d = vec_madd(s0,s1,s2); // [A B C D] | |
96 | |
97 // [A A B B] | |
98 | |
99 // [C C D D] | |
100 | |
101 d0 = vec_perm(t0, t1, mask); // [a b c d] | |
102 | |
103 d0 = vec_sel(vec_mergeh(d, d), d0, sel); // [A b B d] | |
104 | |
105 edges = vec_perm(t1, t0, mask); | |
106 | |
107 t0 = vec_perm(edges, d0, align); // [x x x|A] | |
108 | |
109 t1 = vec_perm(d0, edges, align); // [b B d|e] | |
110 | |
111 vec_stl(t0, 0, dst+y); | |
112 | |
113 d1 = vec_perm(t1, t2, mask); // [e f g h] | |
114 | |
115 d1 = vec_sel(vec_mergel(d, d), d1, sel); // [C f D h] | |
116 | |
117 edges = vec_perm(t2, t1, mask); | |
118 | |
119 t1 = vec_perm(edges, d1, align); // [b B d|C] | |
120 | |
121 t2 = vec_perm(d1, edges, align); // [f D h|x] | |
122 | |
123 vec_stl(t1, 16, dst+y); | |
124 | |
125 t0 = t1; | |
126 | |
127 vec_stl(t2, 31, dst+y); | |
128 | |
129 t1 = t2; | |
130 } | |
131 } else | |
132 #endif | |
133 if (step == 1 && src3 == 0) | |
134 for (i=0; i<len-3; i+=4) { | |
135 t1 = vec_ld(15, dst+i); | |
136 s0 = vec_ld(0, src0+i); | |
137 s1 = vec_ld(0, src1+i); | |
138 s2 = vec_ld(0, src2+i); | |
139 edges = vec_perm(t1 ,t0, mask); | |
140 d = vec_madd(s0,s1,s2); | |
3583
562758eaf7bf
10l, thanks to Emanuele Giaquinta <exg@gentoo.org> for testing and finding the issue
lu_zero
parents:
3581
diff
changeset
|
141 t0 = vec_perm(d, edges, align); |
562758eaf7bf
10l, thanks to Emanuele Giaquinta <exg@gentoo.org> for testing and finding the issue
lu_zero
parents:
3581
diff
changeset
|
142 t1 = vec_perm(edges, d, align); |
3581 | 143 vec_st(t0, 0, dst+i); |
144 vec_st(t1, 15, dst+i); | |
145 t0 = t1; | |
146 } | |
147 else | |
148 ff_vector_fmul_add_add_c(dst, src0, src1, src2, src3, len, step); | |
149 } | |
150 | |
151 void float_to_int16_altivec(int16_t *dst, const float *src, int len) | |
152 { | |
153 int i; | |
154 vector float s0, s1; | |
155 vector signed int t0, t1; | |
156 vector signed short d0, d1, d; | |
157 vector unsigned char align; | |
158 if(((long)dst)&15) //FIXME | |
159 for(i=0; i<len-7; i+=8) { | |
160 s0 = vec_ld(0, src+i); | |
161 s1 = vec_ld(16, src+i); | |
162 t0 = vec_cts(s0, 0); | |
163 d0 = vec_ld(0, dst+i); | |
164 t1 = vec_cts(s1, 0); | |
165 d1 = vec_ld(15, dst+i); | |
166 d = vec_packs(t0,t1); | |
167 d1 = vec_perm(d1, d0, vec_lvsl(0,dst+i)); | |
168 align = vec_lvsr(0, dst+i); | |
3583
562758eaf7bf
10l, thanks to Emanuele Giaquinta <exg@gentoo.org> for testing and finding the issue
lu_zero
parents:
3581
diff
changeset
|
169 d0 = vec_perm(d, d1, align); |
562758eaf7bf
10l, thanks to Emanuele Giaquinta <exg@gentoo.org> for testing and finding the issue
lu_zero
parents:
3581
diff
changeset
|
170 d1 = vec_perm(d1, d, align); |
3581 | 171 vec_st(d0, 0, dst+i); |
172 vec_st(d1,15, dst+i); | |
173 } | |
174 else | |
175 for(i=0; i<len-7; i+=8) { | |
176 s0 = vec_ld(0, src+i); | |
177 s1 = vec_ld(16, src+i); | |
178 t0 = vec_cts(s0, 0); | |
179 t1 = vec_cts(s1, 0); | |
180 d = vec_packs(t0,t1); | |
181 vec_st(d, 0, dst+i); | |
182 } | |
183 } | |
184 | |
185 void float_init_altivec(DSPContext* c, AVCodecContext *avctx) | |
186 { | |
187 c->vector_fmul = vector_fmul_altivec; | |
188 c->vector_fmul_reverse = vector_fmul_reverse_altivec; | |
189 c->vector_fmul_add_add = vector_fmul_add_add_altivec; | |
190 if(!(avctx->flags & CODEC_FLAG_BITEXACT)) | |
191 c->float_to_int16 = float_to_int16_altivec; | |
192 } |